target: make location of /var/targets configurable
Subsystems (2)
v3 cover target: make location of /var/targets configurable
These patches make the location of "/var/target" configurable, though it still defauls to "/var/target".
This "target database directory" can only be changed after the target_core_mod loads but before any fabric drivers are loaded, and must be the pathname of an existing directory.
This configuration is accomplished via the configfs top-level target attribute "dbroot", i.e. dumping out "/sys/kernel/config/target/dbroot" will normally return "/var/target". Writing to this attribute changes the loation where the kernel looks for the target database.
The first patch creates this configurable value for the "dbroot", and the second patch modifies users of this directory to use this new attribute.
Changes from v2:
* Add locking around access to target driver list
Changes from v1:
* Only allow changing target DB root before it can be used by others
* Validate that new DB root is a valid directory
Lee Duncan (2):
target: make target db location configurable
target: use new "dbroot" target attribute
drivers/target/target_core_alua.c | 6 ++-- drivers/target/target_core_configfs.c | 62 +++++++++++++++++++++++++++++++++++ drivers/target/target_core_internal.h | 6 ++++ drivers/target/target_core_pr.c | 2 +- 4 files changed, 72 insertions(+), 4 deletions(-)
Signature · 1 line
2.1.4
PATCH v3 1/2 target: make target db location configurable
This commit adds the read-write attribute "dbroot", in the top-level CONFIGFS (core) target directory, normally /sys/kernel/config/target. This attribute defaults to "/var/target" but can be changed by writing a new pathname string to it. Changing this attribute is only allowed when no fabric drivers are loaded and the supplied value specifies an existing directory.
Target modules that care about the target database root directory will be modified to use this attribute in a future commit.
--- drivers/target/target_core_configfs.c | 62 +++++++++++++++++++++++++++++++++++ drivers/target/target_core_internal.h | 6 ++++ 2 files changed, 68 insertions(+)
drivers/target/target_core_configfs.c +62 -0
@@ -99,6 +99,67 @@ static ssize_t target_core_item_version_show(struct config_item *item,CONFIGFS_ATTR_RO (target_core_item_, version); +char db_root[DB_ROOT_LEN ] =DB_ROOT_DEFAULT ; +static char db_root_stage[DB_ROOT_LEN ]; + +static ssize_t target_core_item_dbroot_show (struct config_item *item, +char *page) +{ +return sprintf (page,"%s\n" , db_root); +} + +static ssize_t target_core_item_dbroot_store (struct config_item *item, +const char *page,size_t count) +{ +ssize_t read_bytes; +struct file *fp; + +mutex_lock (&g_tf_lock); +if (!list_empty (&g_tf_list)) { +mutex_unlock (&g_tf_lock); +pr_err ("db_root: cannot be changed: target drivers registered" ); +return -EINVAL ; + } + +if (count > (DB_ROOT_LEN -1 )) { +mutex_unlock (&g_tf_lock); +pr_err ("db_root: count %d exceeds DB_ROOT_LEN-1: %u\n" , + (int )count,DB_ROOT_LEN -1 ); +return -EINVAL ; + } + + read_bytes =snprintf (db_root_stage,DB_ROOT_LEN ,"%s" , page); +if (!read_bytes) { +mutex_unlock (&g_tf_lock); +return -EINVAL ; + } +if (db_root_stage[read_bytes -1 ] =='\n' ) + db_root_stage[read_bytes -1 ] ='\0' ; + +/* validate new db root before accepting it */ + fp =filp_open (db_root_stage,O_RDONLY ,0 ); +if (IS_ERR (fp)) { +mutex_unlock (&g_tf_lock); +pr_err ("db_root: cannot open: %s\n" , db_root_stage); +return -EINVAL ; + } +if (!S_ISDIR (fp->f_inode->i_mode)) { +filp_close (fp,0 ); +mutex_unlock (&g_tf_lock); +pr_err ("db_root: not a directory: %s\n" , db_root_stage); +return -EINVAL ; + } +filp_close (fp,0 ); + +strncpy (db_root, db_root_stage, read_bytes); + +mutex_unlock (&g_tf_lock); + +return read_bytes; +} + +CONFIGFS_ATTR (target_core_item_, dbroot); +static struct target_fabric_configfs *target_core_get_fabric (const char *name) {
@@ -249,6 +310,7 @@ static struct configfs_group_operations target_core_fabric_group_ops = {*/ static struct configfs_attribute *target_core_fabric_item_attrs[] = { &target_core_item_attr_version, + &target_core_item_attr_dbroot,NULL , };
drivers/target/target_core_internal.h +6 -0
@@ -156,4 +156,10 @@ void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *);/* target_core_xcopy.c */ extern struct se_portal_group xcopy_pt_tpg; +/* target_core_configfs.c */ +#define DB_ROOT_LEN 4096 +#define DB_ROOT_DEFAULT "/var/target" + +extern char db_root[]; +#endif /* TARGET_CORE_INTERNAL_H */
Signature · 1 line
2.1.4
PATCH v3 2/2 target: use new "dbroot" target attribute
In reply to Lee DuncanThis commit updates the target core ALUA and PR modules to use the new "dbroot" attribute instead of assuming the target database is in "/var/target".
--- drivers/target/target_core_alua.c | 6 +++--- drivers/target/target_core_pr.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/target/target_core_alua.c +3 -3
@@ -932,7 +932,7 @@ static int core_alua_update_tpg_primary_metadata( tg_pt_gp->tg_pt_gp_alua_access_status);snprintf (path,ALUA_METADATA_PATH_LEN , -"/var/target/alua/tpgs_%s/%s" , &wwn->unit_serial[0 ], +"%s/alua/tpgs_%s/%s" , db_root, &wwn->unit_serial[0 ],config_item_name (&tg_pt_gp->tg_pt_gp_group.cg_item)); rc =core_alua_write_tpg_metadata (path, md_buf, len);
@@ -1275,8 +1275,8 @@ static int core_alua_update_tpg_secondary_metadata(struct se_lun *lun)atomic_read (&lun->lun_tg_pt_secondary_offline), lun->lun_tg_pt_secondary_stat); -snprintf (path,ALUA_METADATA_PATH_LEN ,"/var/target/alua/%s/%s/lun_%llu" , - se_tpg->se_tpg_tfo->get_fabric_name (), wwn, +snprintf (path,ALUA_METADATA_PATH_LEN ,"%s/alua/%s/%s/lun_%llu" , + db_root, se_tpg->se_tpg_tfo->get_fabric_name (), wwn, lun->unpacked_lun); rc =core_alua_write_tpg_metadata (path, md_buf, len);
drivers/target/target_core_pr.c +1 -1
@@ -1985,7 +1985,7 @@ static int __core_scsi3_write_aptpl_to_file(return -EMSGSIZE ; } -snprintf (path,512 ,"/var/target/pr/aptpl_%s" , &wwn->unit_serial[0 ]); +snprintf (path,512 ,"%s/pr/aptpl_%s" , db_root, &wwn->unit_serial[0 ]); file =filp_open (path, flags,0600 );if (IS_ERR (file)) { pr_err("filp_open(%s) for APTPL metadata"
Signature · 1 line
2.1.4
Quoted 31 lines · Lee Duncan
These patches make the location of "
/var/target" configurable, though it still defauls to "/var/target".This "target database directory" can only be changed after the
target_core_modloads but before any fabric drivers are loaded, and must be the pathname of an existing directory.This configuration is accomplished via the configfs top-level target attribute "dbroot", i.e. dumping out "
/sys/kernel/config/target/dbroot" will normally return "/var/target". Writing to this attribute changes the loation where the kernel looks for the target database.The first patch creates this configurable value for the "dbroot", and the second patch modifies users of this directory to use this new attribute.
Changes from v2:
* Add locking around access to target driver listChanges from v1:
* Only allow changing target DB root before it can be used by others
* Validate that new DB root is a valid directoryLee Duncan (2):
target: make target db location configurable
target: use new "dbroot" target attribute
Quoted 6 lines
drivers/target/target_core_alua.c | 6 ++-- drivers/target/target_core_configfs.c | 62 +++++++++++++++++++++++++++++++++++ drivers/target/target_core_internal.h | 6 ++++ drivers/target/target_core_pr.c | 2 +- 4 files changed, 72 insertions(+), 4 deletions(-)
Ping?
Signature · 1 line
Lee Duncan
Hi experts,
I think these patches are great, and I am ready to help in user space.
Thanks,
BR
Zhu Lingshan
Quoted 39 lines · Lee Duncan
Quoted 31 lines · Lee Duncan
These patches make the location of "
/var/target" configurable, though it still defauls to "/var/target".This "target database directory" can only be changed after the
target_core_modloads but before any fabric drivers are loaded, and must be the pathname of an existing directory.This configuration is accomplished via the configfs top-level target attribute "dbroot", i.e. dumping out "
/sys/kernel/config/target/dbroot" will normally return "/var/target". Writing to this attribute changes the loation where the kernel looks for the target database.The first patch creates this configurable value for the "dbroot", and the second patch modifies users of this directory to use this new attribute.
Changes from v2:
* Add locking around access to target driver listChanges from v1:
* Only allow changing target DB root before it can be used by others
* Validate that new DB root is a valid directoryLee Duncan (2):
target: make target db location configurable
target: use new "dbroot" target attributeQuoted 6 lines
drivers/target/target_core_alua.c | 6 ++-- drivers/target/target_core_configfs.c | 62 +++++++++++++++++++++++++++++++++++ drivers/target/target_core_internal.h | 6 ++++ drivers/target/target_core_pr.c | 2 +- 4 files changed, 72 insertions(+), 4 deletions(-)Ping?
Ping?
We really need to move the target database out of /var/target
Quoted 37 lines · Lee Duncan
These patches make the location of "
/var/target" configurable, though it still defauls to "/var/target".This "target database directory" can only be changed after the
target_core_modloads but before any fabric drivers are loaded, and must be the pathname of an existing directory.This configuration is accomplished via the configfs top-level target attribute "dbroot", i.e. dumping out "
/sys/kernel/config/target/dbroot" will normally return "/var/target". Writing to this attribute changes the loation where the kernel looks for the target database.The first patch creates this configurable value for the "dbroot", and the second patch modifies users of this directory to use this new attribute.
Changes from v2:
* Add locking around access to target driver listChanges from v1:
* Only allow changing target DB root before it can be used by others
* Validate that new DB root is a valid directoryLee Duncan (2):
target: make target db location configurable
target: use new "dbroot" target attributedrivers/target/target_core_alua.c | 6 ++-- drivers/target/target_core_configfs.c | 62 +++++++++++++++++++++++++++++++++++ drivers/target/target_core_internal.h | 6 ++++ drivers/target/target_core_pr.c | 2 +- 4 files changed, 72 insertions(+), 4 deletions(-)
Signature · 2 lines
Lee Duncan SUSE Labs
Quoted 4 lines · Lee Duncan
Ping?
We really need to move the target database out of
/var/target
This series has already merged up for v4.7-rc1.