Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1378276 > unrolled thread
| Started by | Lee Duncan <lduncan@suse.com> |
|---|---|
| First post | 2016-04-13 22:40 +0200 |
| Last post | 2016-04-15 02:10 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCHv2 0/2] target: make location of /var/targets configurable Lee Duncan <lduncan@suse.com> - 2016-04-13 22:40 +0200
[PATCHv2 1/2] target: make target db location configurable Lee Duncan <lduncan@suse.com> - 2016-04-13 22:40 +0200
Re: [PATCHv2 1/2] target: make target db location configurable Hannes Reinecke <hare@suse.de> - 2016-04-14 08:20 +0200
Re: [PATCHv2 1/2] target: make target db location configurable Lee Duncan <lduncan@suse.com> - 2016-04-15 02:10 +0200
| From | Lee Duncan <lduncan@suse.com> |
|---|---|
| Date | 2016-04-13 22:40 +0200 |
| Subject | [PATCHv2 0/2] target: make location of /var/targets configurable |
| Message-ID | <rnzJU-74K-5@gated-at.bofh.it> |
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 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 | 51 +++++++++++++++++++++++++++++++++++ drivers/target/target_core_internal.h | 6 +++++ drivers/target/target_core_pr.c | 2 +- 4 files changed, 61 insertions(+), 4 deletions(-) -- 2.1.4
[toc] | [next] | [standalone]
| From | Lee Duncan <lduncan@suse.com> |
|---|---|
| Date | 2016-04-13 22:40 +0200 |
| Subject | [PATCHv2 1/2] target: make target db location configurable |
| Message-ID | <rnzJW-74K-57@gated-at.bofh.it> |
| In reply to | #1378276 |
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.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/target/target_core_configfs.c | 51 +++++++++++++++++++++++++++++++++++
drivers/target/target_core_internal.h | 6 +++++
2 files changed, 57 insertions(+)
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 713c63d9681b..bfedbd92b77f 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -99,6 +99,56 @@ 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;
+
+ if (!list_empty(&g_tf_list)) {
+ pr_err("db_root: cannot be changed: target drivers registered");
+ return -EINVAL;
+ }
+ if (count > (DB_ROOT_LEN - 1)) {
+ 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)
+ 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)) {
+ pr_err("db_root: cannot open: %s\n", db_root_stage);
+ return -EINVAL;
+ }
+ if (!S_ISDIR(fp->f_inode->i_mode)) {
+ pr_err("db_root: not a directory: %s\n", db_root_stage);
+ filp_close(fp, 0);
+ return -EINVAL;
+ }
+ filp_close(fp, 0);
+ strncpy(db_root, db_root_stage, read_bytes);
+
+ return read_bytes;
+}
+
+CONFIGFS_ATTR(target_core_item_, dbroot);
+
static struct target_fabric_configfs *target_core_get_fabric(
const char *name)
{
@@ -249,6 +299,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,
};
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index 040cf5202e54..c2a18b960c5d 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -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 */
--
2.1.4
[toc] | [prev] | [next] | [standalone]
| From | Hannes Reinecke <hare@suse.de> |
|---|---|
| Date | 2016-04-14 08:20 +0200 |
| Subject | Re: [PATCHv2 1/2] target: make target db location configurable |
| Message-ID | <rnINc-5LS-9@gated-at.bofh.it> |
| In reply to | #1378282 |
On 04/13/2016 10:25 PM, Lee Duncan wrote:
> 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.
>
> Signed-off-by: Lee Duncan <lduncan@suse.com>
> ---
> drivers/target/target_core_configfs.c | 51 +++++++++++++++++++++++++++++++++++
> drivers/target/target_core_internal.h | 6 +++++
> 2 files changed, 57 insertions(+)
>
> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
> index 713c63d9681b..bfedbd92b77f 100644
> --- a/drivers/target/target_core_configfs.c
> +++ b/drivers/target/target_core_configfs.c
> @@ -99,6 +99,56 @@ 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;
> +
> + if (!list_empty(&g_tf_list)) {
> + pr_err("db_root: cannot be changed: target drivers registered");
> + return -EINVAL;
> + }
Locking?
Cheers,
Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare@suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
[toc] | [prev] | [next] | [standalone]
| From | Lee Duncan <lduncan@suse.com> |
|---|---|
| Date | 2016-04-15 02:10 +0200 |
| Subject | Re: [PATCHv2 1/2] target: make target db location configurable |
| Message-ID | <rnZuG-2eS-17@gated-at.bofh.it> |
| In reply to | #1378507 |
On 04/13/2016 11:10 PM, Hannes Reinecke wrote:
> On 04/13/2016 10:25 PM, Lee Duncan wrote:
>> 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.
>>
>> Signed-off-by: Lee Duncan <lduncan@suse.com>
>> ---
>> drivers/target/target_core_configfs.c | 51 +++++++++++++++++++++++++++++++++++
>> drivers/target/target_core_internal.h | 6 +++++
>> 2 files changed, 57 insertions(+)
>>
>> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
>> index 713c63d9681b..bfedbd92b77f 100644
>> --- a/drivers/target/target_core_configfs.c
>> +++ b/drivers/target/target_core_configfs.c
>> @@ -99,6 +99,56 @@ 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;
>> +
>> + if (!list_empty(&g_tf_list)) {
>> + pr_err("db_root: cannot be changed: target drivers registered");
>> + return -EINVAL;
>> + }
> Locking?
Doh. I will resubmit with locking shortly.
>
> Cheers,
>
> Hannes
>
--
Lee Duncan
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web