Преглед на файлове

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

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Lee Duncan преди 7 години
родител
ревизия
78a6295c71
променени са 2 файла, в които са добавени 26 реда и са изтрити 0 реда
  1. 25 0
      drivers/target/target_core_configfs.c
  2. 1 0
      drivers/target/target_core_internal.h

+ 25 - 0
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);
 	mutex_unlock(&g_tf_lock);
 
 
+	pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root);
+
 	return read_bytes;
 	return read_bytes;
 }
 }
 
 
@@ -3213,6 +3215,27 @@ void target_setup_backend_cits(struct target_backend *tb)
 	target_core_setup_dev_stat_cit(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)
 static int __init target_core_init_configfs(void)
 {
 {
 	struct configfs_subsystem *subsys = &target_core_fabrics;
 	struct configfs_subsystem *subsys = &target_core_fabrics;
@@ -3293,6 +3316,8 @@ static int __init target_core_init_configfs(void)
 	if (ret < 0)
 	if (ret < 0)
 		goto out;
 		goto out;
 
 
+	target_init_dbroot();
+
 	return 0;
 	return 0;
 
 
 out:
 out:

+ 1 - 0
drivers/target/target_core_internal.h

@@ -166,6 +166,7 @@ extern struct se_portal_group xcopy_pt_tpg;
 /* target_core_configfs.c */
 /* target_core_configfs.c */
 #define DB_ROOT_LEN		4096
 #define DB_ROOT_LEN		4096
 #define	DB_ROOT_DEFAULT		"/var/target"
 #define	DB_ROOT_DEFAULT		"/var/target"
+#define	DB_ROOT_PREFERRED	"/etc/target"
 
 
 extern char db_root[];
 extern char db_root[];