* [PATCH V2] nvmet: make ctrl model configurable
@ 2019-11-13 21:58 Chaitanya Kulkarni
2019-11-13 21:58 ` [PATCH] nvmetcli: allow setting of the subsystem model Chaitanya Kulkarni
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2019-11-13 21:58 UTC (permalink / raw)
To: linux-nvme; +Cc: MRuijter, hch, Chaitanya Kulkarni
From: Mark Ruijter <MRuijter@onestopsystems.com>
This patch adds a new target subsys attribute which allows user to
optionally specify model name which then used in the
nvmet_execute_identify_ctrl() to fill up the nvme_id_ctrl structure.
The default value for the model is set to "Linux" for backward
compatibility.
Signed-off-by: Mark Ruijter <MRuijter@onestopsystems.com>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
Changes from V1:-
1. Don't allocate memory for default subsys model,
2. Use helper to get the default model string from ctrl->subsys in the
nvmet_execute_identify_ctrl() and nvmet_subsys_attr_model()_show.
Later is needed so that nvmetcli can display default value Linux
when the model is not set from the user.
3. Get rid of the extra variable c in the nvmet_subsys_attr_model_store()
and replace for with while loop without loosing the code redability.
---
drivers/nvme/target/admin-cmd.c | 9 +++++--
drivers/nvme/target/configfs.c | 44 +++++++++++++++++++++++++++++++++
drivers/nvme/target/core.c | 2 ++
drivers/nvme/target/nvmet.h | 4 +++
4 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 56c21b501185..81374507099f 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -312,12 +312,17 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)
nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR);
}
+const char *nvmet_subsys_model(struct nvmet_subsys *subsys)
+{
+ return subsys->model ? subsys->model : NVMET_DEFAULT_CTRL_MODEL;
+}
+
static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
{
+ const char *model = nvmet_subsys_model(req->sq->ctrl->subsys);
struct nvmet_ctrl *ctrl = req->sq->ctrl;
struct nvme_id_ctrl *id;
u16 status = 0;
- const char model[] = "Linux";
id = kzalloc(sizeof(*id), GFP_KERNEL);
if (!id) {
@@ -332,7 +337,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
memset(id->sn, ' ', sizeof(id->sn));
bin2hex(id->sn, &ctrl->subsys->serial,
min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2));
- memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' ');
+ memcpy_and_pad(id->mn, sizeof(id->mn), model, strlen(model), ' ');
memcpy_and_pad(id->fr, sizeof(id->fr),
UTS_RELEASE, strlen(UTS_RELEASE), ' ');
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 98613a45bd3b..4580f9d9b07f 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -862,10 +862,54 @@ static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
}
CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
+static ssize_t nvmet_subsys_attr_model_show(struct config_item *item,
+ char *page)
+{
+ struct nvmet_subsys *subsys = to_subsys(item);
+
+ return snprintf(page, PAGE_SIZE, "%s\n", nvmet_subsys_model(subsys));
+}
+
+static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
+ const char *page, size_t count)
+{
+ struct nvmet_subsys *subsys = to_subsys(item);
+ int ret = -EINVAL, pos = 0, len;
+ char *tmp;
+
+ down_write(&nvmet_config_sem);
+ len = strcspn(page, "\n");
+ if (!len)
+ goto out_unlock;
+
+ /* Only 20h (space) until 7eh (~) is allowed */
+ while (pos < len && (page[pos] >= 0x20 && page[pos] <= 0x7e) && ++pos)
+ ;
+ if (pos != len)
+ goto out_unlock;
+
+ tmp = kstrndup(page, len, GFP_KERNEL);
+ if (!tmp) {
+ ret = -ENOMEM;
+ goto out_unlock;
+ }
+
+ ret = count;
+ kfree(subsys->model);
+ subsys->model = tmp;
+
+out_unlock:
+ up_write(&nvmet_config_sem);
+ return ret;
+}
+
+CONFIGFS_ATTR(nvmet_subsys_, attr_model);
+
static struct configfs_attribute *nvmet_subsys_attrs[] = {
&nvmet_subsys_attr_attr_allow_any_host,
&nvmet_subsys_attr_attr_version,
&nvmet_subsys_attr_attr_serial,
+ &nvmet_subsys_attr_attr_model,
NULL,
};
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 28438b833c1b..1d17638bbc45 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1416,6 +1416,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
kfree(subsys);
return ERR_PTR(-ENOMEM);
}
+ subsys->model = NULL;
kref_init(&subsys->ref);
@@ -1435,6 +1436,7 @@ static void nvmet_subsys_free(struct kref *ref)
WARN_ON_ONCE(!list_empty(&subsys->namespaces));
kfree(subsys->subsysnqn);
+ kfree(subsys->model);
kfree(subsys);
}
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 46df45e837c9..7fafb5171037 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -23,6 +23,7 @@
#define NVMET_ASYNC_EVENTS 4
#define NVMET_ERROR_LOG_SLOTS 128
#define NVMET_NO_ERROR_LOC ((u16)-1)
+#define NVMET_DEFAULT_CTRL_MODEL "Linux"
/*
* Supported optional AENs:
@@ -222,6 +223,7 @@ struct nvmet_subsys {
u64 ver;
u64 serial;
char *subsysnqn;
+ char *model;
struct config_group group;
@@ -487,6 +489,8 @@ u16 nvmet_bdev_flush(struct nvmet_req *req);
u16 nvmet_file_flush(struct nvmet_req *req);
void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid);
+const char *nvmet_subsys_model(struct nvmet_subsys *subsys);
+
static inline u32 nvmet_rw_len(struct nvmet_req *req)
{
return ((u32)le16_to_cpu(req->cmd->rw.length) + 1) <<
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] nvmetcli: allow setting of the subsystem model
2019-11-13 21:58 [PATCH V2] nvmet: make ctrl model configurable Chaitanya Kulkarni
@ 2019-11-13 21:58 ` Chaitanya Kulkarni
2019-11-20 4:38 ` Chaitanya Kulkarni
2019-11-20 4:38 ` [PATCH V2] nvmet: make ctrl model configurable Chaitanya Kulkarni
2019-11-20 18:41 ` Christoph Hellwig
2 siblings, 1 reply; 5+ messages in thread
From: Chaitanya Kulkarni @ 2019-11-13 21:58 UTC (permalink / raw)
To: linux-nvme; +Cc: MRuijter, hch, Chaitanya Kulkarni
From: Mark Ruijter <MRuijter@onestopsystems.com>
This patch allows users to set the subsystem's model.
Signed-off-by: Mark Ruijter <MRuijter@onestopsystems.com>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
In case anyone is intrested here is the test report:-
1. Try input empty string to model attr, should get Linux in nvme list and
in nvmetcli :-
1.1 # nvme list | tr -s ' ' ' ' | grep -v "\-\-"
Node SN Model Namespace Usage Format FW Rev
/dev/nvme0n1 foo QEMU NVMe Ctrl 1 2.10 MB / 2.10 MB 1 B + 9 B 1.0
/dev/nvme1n1 8c2f4de7cc2d177b Linux 1 524.29 MB / 524.29 MB 1 B + 9 B 5.4.0-rc
nvmetcli should show Linux as default model :-
1.2 # ./nvmetcli/nvmetcli
/subsystems/fs> ls
o- fs ................................ [version=1.3, allow_any=1, \
serial=a222fc0cd4e5859a, model=Linux]
2, Try and set the model, change from default, new value should reflect
in nvme list and nvmetcli :-
2.1 # echo "testmodel" > /sys/kernel/config/nvmet/subsystems/fs/attr_model
2.2# nvme list | tr -s ' ' ' ' | grep -v "\-\-"
Node SN Model Namespace Usage Format FW Rev
/dev/nvme0n1 foo QEMU NVMe Ctrl 1 2.10 MB / 2.10 MB 1 B + 9 B 1.0
/dev/nvme1n1 8c2f4de7cc2d177b testmodel 1 524.29 MB / 524.29 MB 1 B + 9 B 5.4.0-rc
2.3. # ./nvmetcli/nvmetcli
/subsystems/fs> ls
o- fs ............................ [version=1.3, allow_any=1, \
serial=a222fc0cd4e5859a, model=testmodel]
3. Change model value from nvmetcli and check nvme list should be the same :-
3.1 # ./nvmetcli
/subsystems/fs> set attr model=cool~model
Parameter model is now 'cool~model'.
3.2# nvme list | tr -s ' ' ' ' | grep -v "\-\-"
Node SN Model Namespace Usage Format FW Rev
/dev/nvme0n1 foo QEMU NVMe Ctrl 1 2.10 MB / 2.10 MB 1 B + 9 B 1.0
/dev/nvme1n1 9a85e5d40cfc22a2 cool~model 1 524.29 MB / 524.29 MB 1 B + 9 B 5.4.0-rc
4. Initialize subsys with model name bdefore we link the subsys to port,
nvmecli and nvmetcli should display new model name and not the default :-
4.1 # nvme list | tr -s ' ' ' ' | grep -v "\-\-"
Node SN Model Namespace Usage Format FW Rev
/dev/nvme0n1 foo QEMU NVMe Ctrl 1 2.10 MB / 2.10 MB 1 B + 9 B 1.0
/dev/nvme1n1 5033aba0a518cf48 new-model 1 524.29 MB / 524.29 MB 1 B + 9 B 5.4.0-rc
4.2 # ./nvmetcli/nvmetcli
/subsystems/fs> get attr model
model=new-model
---
nvmetcli | 2 ++
1 file changed, 2 insertions(+)
diff --git a/nvmetcli b/nvmetcli
index 3d8c16e..7347fbb 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -155,6 +155,7 @@ class UISubsystemNode(UINode):
ui_desc_attr = {
'allow_any_host': ('string', 'Allow access by any host if set to 1'),
'serial': ('string', 'Export serial number to hosts'),
+ 'model': ('string', 'Set a model description'),
'version': ('string', 'Export version number to hosts'),
}
@@ -172,6 +173,7 @@ class UISubsystemNode(UINode):
info.append("allow_any=" +
self.cfnode.get_attr("attr", "allow_any_host"))
info.append("serial=" + self.cfnode.get_attr("attr", "serial"))
+ info.append("model=" + self.cfnode.get_attr("attr", "model"))
return (", ".join(info), True)
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2] nvmet: make ctrl model configurable
2019-11-13 21:58 [PATCH V2] nvmet: make ctrl model configurable Chaitanya Kulkarni
2019-11-13 21:58 ` [PATCH] nvmetcli: allow setting of the subsystem model Chaitanya Kulkarni
@ 2019-11-20 4:38 ` Chaitanya Kulkarni
2019-11-20 18:41 ` Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2019-11-20 4:38 UTC (permalink / raw)
To: linux-nvme; +Cc: MRuijter, hch
Ping ?
On 11/13/2019 01:58 PM, Chaitanya Kulkarni wrote:
> From: Mark Ruijter <MRuijter@onestopsystems.com>
>
> This patch adds a new target subsys attribute which allows user to
> optionally specify model name which then used in the
> nvmet_execute_identify_ctrl() to fill up the nvme_id_ctrl structure.
>
> The default value for the model is set to "Linux" for backward
> compatibility.
>
> Signed-off-by: Mark Ruijter <MRuijter@onestopsystems.com>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
> Changes from V1:-
>
> 1. Don't allocate memory for default subsys model,
> 2. Use helper to get the default model string from ctrl->subsys in the
> nvmet_execute_identify_ctrl() and nvmet_subsys_attr_model()_show.
> Later is needed so that nvmetcli can display default value Linux
> when the model is not set from the user.
> 3. Get rid of the extra variable c in the nvmet_subsys_attr_model_store()
> and replace for with while loop without loosing the code redability.
> ---
> drivers/nvme/target/admin-cmd.c | 9 +++++--
> drivers/nvme/target/configfs.c | 44 +++++++++++++++++++++++++++++++++
> drivers/nvme/target/core.c | 2 ++
> drivers/nvme/target/nvmet.h | 4 +++
> 4 files changed, 57 insertions(+), 2 deletions(-)
>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] nvmet: make ctrl model configurable
2019-11-13 21:58 [PATCH V2] nvmet: make ctrl model configurable Chaitanya Kulkarni
2019-11-13 21:58 ` [PATCH] nvmetcli: allow setting of the subsystem model Chaitanya Kulkarni
2019-11-20 4:38 ` [PATCH V2] nvmet: make ctrl model configurable Chaitanya Kulkarni
@ 2019-11-20 18:41 ` Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2019-11-20 18:41 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: MRuijter, hch, linux-nvme
On Wed, Nov 13, 2019 at 01:58:45PM -0800, Chaitanya Kulkarni wrote:
> From: Mark Ruijter <MRuijter@onestopsystems.com>
>
> This patch adds a new target subsys attribute which allows user to
> optionally specify model name which then used in the
> nvmet_execute_identify_ctrl() to fill up the nvme_id_ctrl structure.
>
> The default value for the model is set to "Linux" for backward
> compatibility.
>
> Signed-off-by: Mark Ruijter <MRuijter@onestopsystems.com>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
> Changes from V1:-
>
> 1. Don't allocate memory for default subsys model,
> 2. Use helper to get the default model string from ctrl->subsys in the
> nvmet_execute_identify_ctrl() and nvmet_subsys_attr_model()_show.
> Later is needed so that nvmetcli can display default value Linux
> when the model is not set from the user.
> 3. Get rid of the extra variable c in the nvmet_subsys_attr_model_store()
> and replace for with while loop without loosing the code redability.
> ---
> drivers/nvme/target/admin-cmd.c | 9 +++++--
> drivers/nvme/target/configfs.c | 44 +++++++++++++++++++++++++++++++++
> drivers/nvme/target/core.c | 2 ++
> drivers/nvme/target/nvmet.h | 4 +++
> 4 files changed, 57 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
> index 56c21b501185..81374507099f 100644
> --- a/drivers/nvme/target/admin-cmd.c
> +++ b/drivers/nvme/target/admin-cmd.c
> @@ -312,12 +312,17 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)
> nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR);
> }
>
> +const char *nvmet_subsys_model(struct nvmet_subsys *subsys)
> +{
> + return subsys->model ? subsys->model : NVMET_DEFAULT_CTRL_MODEL;
Nit: I always prefer good old if statements except when passing
arguments or a few commonly used idioms as it just reads much more
easily.
> + /* Only 20h (space) until 7eh (~) is allowed */
> + while (pos < len && (page[pos] >= 0x20 && page[pos] <= 0x7e) && ++pos)
No nee for the inner braces here, but I wonder If this whole thing
could be reshuffled somehow to be a bit more readable. Something like:
/* See Section 1.5 of NVMe 1.4 */
static bool nvmet_is_ascii(const char c)
{
return c >= 0x20 && c <= 0x7e;
}
for (pos = 0; pos < len; pos++) {
if (!nvmet_is_ascii(page[pos]))
goto out_unlock;
}
> + tmp = kstrndup(page, len, GFP_KERNEL);
> + if (!tmp) {
Maybe name tmp model?
> +const char *nvmet_subsys_model(struct nvmet_subsys *subsys);
Maybe just call this nvmet_model_number to match the field name?
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-11-20 18:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13 21:58 [PATCH V2] nvmet: make ctrl model configurable Chaitanya Kulkarni
2019-11-13 21:58 ` [PATCH] nvmetcli: allow setting of the subsystem model Chaitanya Kulkarni
2019-11-20 4:38 ` Chaitanya Kulkarni
2019-11-20 4:38 ` [PATCH V2] nvmet: make ctrl model configurable Chaitanya Kulkarni
2019-11-20 18:41 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).