diff mbox

target: prefer dbroot of /etc/target over /var/target

Message ID 20180406153717.7523-1-lduncan@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lee Duncan April 6, 2018, 3:37 p.m. UTC
The target database root directory, dbroot, has
defaulted to /var/target for a while, but its
main client, targetcli-fb, has been moving it
to /etc/target for quite some time. With the
plethora of target drivers now appearing, it has
become more difficult to initialize this attribute
before use by any child drivers.

If the directory /etc/target exists, use that as
the DB root. Otherwise, fall back to using
/var/target.

The ability to override this dbroot attribute
still exists via sysfs.

Signed-off-by: Lee Duncan <lduncan@suse.com>
---
 drivers/target/target_core_configfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

kernel test robot April 6, 2018, 4:34 p.m. UTC | #1
Hi Lee,

I love your patch! Yet something to improve:

[auto build test ERROR on target/for-next]
[also build test ERROR on v4.16 next-20180406]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Lee-Duncan/target-prefer-dbroot-of-etc-target-over-var-target/20180406-234105
base:   https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git for-next
config: i386-randconfig-x016-201813 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/target/target_core_configfs.c: In function 'target_init_dbroot':
>> drivers/target/target_core_configfs.c:3222:39: error: 'DB_ROOT_PREFERRED' undeclared (first use in this function); did you mean 'DB_ROOT_DEFAULT'?
     snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED);
                                          ^~~~~~~~~~~~~~~~~
                                          DB_ROOT_DEFAULT
   drivers/target/target_core_configfs.c:3222:39: note: each undeclared identifier is reported only once for each function it appears in

vim +3222 drivers/target/target_core_configfs.c

  3217	
  3218	static void target_init_dbroot(void)
  3219	{
  3220		struct file *fp;
  3221	
> 3222		snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED);
  3223		fp = filp_open(db_root_stage, O_RDONLY, 0);
  3224		if (IS_ERR(fp)) {
  3225			pr_err("db_root: cannot open: %s\n", db_root_stage);
  3226			return;
  3227		}
  3228		if (!S_ISDIR(file_inode(fp)->i_mode)) {
  3229			filp_close(fp, NULL);
  3230			pr_err("db_root: not a valid directory: %s\n", db_root_stage);
  3231			return;
  3232		}
  3233		filp_close(fp, NULL);
  3234	
  3235		strncpy(db_root, db_root_stage, DB_ROOT_LEN);
  3236		pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root);
  3237	}
  3238	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Lee Duncan April 6, 2018, 5:31 p.m. UTC | #2
I will be re-sending this, as this version somehow missed
a change to an include file.

On 04/06/2018 08:37 AM, Lee Duncan wrote:
> The target database root directory, dbroot, has
> defaulted to /var/target for a while, but its
> main client, targetcli-fb, has been moving it
> to /etc/target for quite some time. With the
> plethora of target drivers now appearing, it has
> become more difficult to initialize this attribute
> before use by any child drivers.
> 
> If the directory /etc/target exists, use that as
> the DB root. Otherwise, fall back to using
> /var/target.
> 
> The ability to override this dbroot attribute
> still exists via sysfs.
> 
> Signed-off-by: Lee Duncan <lduncan@suse.com>
> ---
>  drivers/target/target_core_configfs.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
> index 3f4bf126eed0..5ccef7d597fa 100644
> --- a/drivers/target/target_core_configfs.c
> +++ b/drivers/target/target_core_configfs.c
> @@ -155,6 +155,8 @@ static ssize_t target_core_item_dbroot_store(struct config_item *item,
>  
>  	mutex_unlock(&g_tf_lock);
>  
> +	pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root);
> +
>  	return read_bytes;
>  }
>  
> @@ -3213,6 +3215,27 @@ void target_setup_backend_cits(struct target_backend *tb)
>  	target_core_setup_dev_stat_cit(tb);
>  }
>  
> +static void target_init_dbroot(void)
> +{
> +	struct file *fp;
> +
> +	snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED);
> +	fp = filp_open(db_root_stage, O_RDONLY, 0);
> +	if (IS_ERR(fp)) {
> +		pr_err("db_root: cannot open: %s\n", db_root_stage);
> +		return;
> +	}
> +	if (!S_ISDIR(file_inode(fp)->i_mode)) {
> +		filp_close(fp, NULL);
> +		pr_err("db_root: not a valid directory: %s\n", db_root_stage);
> +		return;
> +	}
> +	filp_close(fp, NULL);
> +
> +	strncpy(db_root, db_root_stage, DB_ROOT_LEN);
> +	pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root);
> +}
> +
>  static int __init target_core_init_configfs(void)
>  {
>  	struct configfs_subsystem *subsys = &target_core_fabrics;
> @@ -3293,6 +3316,8 @@ static int __init target_core_init_configfs(void)
>  	if (ret < 0)
>  		goto out;
>  
> +	target_init_dbroot();
> +
>  	return 0;
>  
>  out:
>
kernel test robot April 6, 2018, 7:10 p.m. UTC | #3
Hi Lee,

I love your patch! Yet something to improve:

[auto build test ERROR on target/for-next]
[also build test ERROR on v4.16 next-20180406]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Lee-Duncan/target-prefer-dbroot-of-etc-target-over-var-target/20180406-234105
base:   https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git for-next
config: i386-randconfig-a0-201813 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/target/target_core_configfs.c: In function 'target_init_dbroot':
>> drivers/target/target_core_configfs.c:3222:39: error: 'DB_ROOT_PREFERRED' undeclared (first use in this function)
     snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED);
                                          ^
   drivers/target/target_core_configfs.c:3222:39: note: each undeclared identifier is reported only once for each function it appears in

vim +/DB_ROOT_PREFERRED +3222 drivers/target/target_core_configfs.c

  3217	
  3218	static void target_init_dbroot(void)
  3219	{
  3220		struct file *fp;
  3221	
> 3222		snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED);
  3223		fp = filp_open(db_root_stage, O_RDONLY, 0);
  3224		if (IS_ERR(fp)) {
  3225			pr_err("db_root: cannot open: %s\n", db_root_stage);
  3226			return;
  3227		}
  3228		if (!S_ISDIR(file_inode(fp)->i_mode)) {
  3229			filp_close(fp, NULL);
  3230			pr_err("db_root: not a valid directory: %s\n", db_root_stage);
  3231			return;
  3232		}
  3233		filp_close(fp, NULL);
  3234	
  3235		strncpy(db_root, db_root_stage, DB_ROOT_LEN);
  3236		pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root);
  3237	}
  3238	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 3f4bf126eed0..5ccef7d597fa 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -155,6 +155,8 @@  static ssize_t target_core_item_dbroot_store(struct config_item *item,
 
 	mutex_unlock(&g_tf_lock);
 
+	pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root);
+
 	return read_bytes;
 }
 
@@ -3213,6 +3215,27 @@  void target_setup_backend_cits(struct target_backend *tb)
 	target_core_setup_dev_stat_cit(tb);
 }
 
+static void target_init_dbroot(void)
+{
+	struct file *fp;
+
+	snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED);
+	fp = filp_open(db_root_stage, O_RDONLY, 0);
+	if (IS_ERR(fp)) {
+		pr_err("db_root: cannot open: %s\n", db_root_stage);
+		return;
+	}
+	if (!S_ISDIR(file_inode(fp)->i_mode)) {
+		filp_close(fp, NULL);
+		pr_err("db_root: not a valid directory: %s\n", db_root_stage);
+		return;
+	}
+	filp_close(fp, NULL);
+
+	strncpy(db_root, db_root_stage, DB_ROOT_LEN);
+	pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root);
+}
+
 static int __init target_core_init_configfs(void)
 {
 	struct configfs_subsystem *subsys = &target_core_fabrics;
@@ -3293,6 +3316,8 @@  static int __init target_core_init_configfs(void)
 	if (ret < 0)
 		goto out;
 
+	target_init_dbroot();
+
 	return 0;
 
 out: