linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Mark Ruijter <MRuijter@onestopsystems.com>
To: Christoph Hellwig <hch@infradead.org>,
	Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Cc: "hch@lst.de" <hch@lst.de>,
	"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
	"sagi@grimberg.me" <sagi@grimberg.me>
Subject: Re: [PATCH] nvmet: make ctrl model configurable
Date: Mon, 11 Nov 2019 13:31:39 +0000	[thread overview]
Message-ID: <829AB08E-457F-4E8E-8964-DD3ADF9140BD@onestopsystems.com> (raw)
In-Reply-To: <20191111103421.GB6127@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 3539 bytes --]


Hi Chaitanya & Christoph,

I changed the patch I posted this morning and added the changes suggested.

I also wrote a patch for nvmetcli and verified that nvmetcli can set and save the model description:

dev:/usr/src/nvmetcli # ./nvmetcli save /tmp/test.json
dev:/usr/src/nvmetcli # cat /sys/kernel/config/nvmet/subsystems/loop/attr_model 
mark
dev:/usr/src/nvmetcli # grep model /tmp/test.json
        "model": "mark", 

dev:/usr/src/nvmetcli # ./nvmetcli 
/subsystems/loop> ls  
o- loop ............................................................ [version=1.3, allow_any=1, serial=198f07c757eb114d, model=mark]
  o- allowed_hosts ........................................................................................................... [...]
  o- namespaces .............................................................................................................. [...]
    o- 1 ............................................ [path=/dev/loop0, uuid=d808c1db-3507-40cf-8ade-aa4b1a3b290b, grpid=1, enabled]
/subsystems/loop> set attr model=coolmodel
Parameter model is now 'coolmodel'.
/subsystems/loop> ls
o- loop ....................................................... [version=1.3, allow_any=1, serial=198f07c757eb114d, model=coolmodel]
  o- allowed_hosts ........................................................................................................... [...]
  o- namespaces .............................................................................................................. [...]
    o- 1 ............................................ [path=/dev/loop0, uuid=d808c1db-3507-40cf-8ade-aa4b1a3b290b, grpid=1, enabled]
/subsystems/loop> exit
dev:/usr/src/nvmetcli # ./nvmetcli save /tmp/testcool.jsonl 
dev:/usr/src/nvmetcli # grep model /tmp/testcool.json
        "model": "coolmodel", 
dev:/usr/src/nvmetcli #

I also verified that writing illegal characters in the model fails and that the initiator sees the model description that was set:
 echo -e "\t failit" > attr_model 
-bash: echo: write error: Invalid argument

echo this~works > attr_model

# nvme list
Node             SN                   Model                                    Namespace Usage                      Format           FW Rev  
---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1     4d11eb57c7078f19     this~works                               1         104,86  MB / 104,86  MB    512   B +  0 B   5.3.5   

Thanks,

Mark Ruijter
 

Op 11-11-19 11:35 heeft Linux-nvme namens Christoph Hellwig <linux-nvme-bounces@lists.infradead.org namens hch@infradead.org> geschreven:

    > +	const char *model = ctrl->subsys->model;
    
    Can we have a little nvme_controller_mode() helper that uses
    subsystem->model if it is set, and otherwise the default?  That saves
    memory by not duplicating the default name for every subsystem.
    
    > +	kfree(subsys->model);
    > +	subsys->model = kstrndup(page, len, GFP_KERNEL);
    > +	if (!subsys->model)
    > +		ret = -ENOMEM;
    
    I don't think we should free the old model until the new one
    is allocated.
    
    Otherwise this looks good to me, but can someone also prepare a
    nvmetcli patch as well?
    
    _______________________________________________
    Linux-nvme mailing list
    Linux-nvme@lists.infradead.org
    http://lists.infradead.org/mailman/listinfo/linux-nvme
    


[-- Attachment #2: model_patch_patched2.diff --]
[-- Type: application/octet-stream, Size: 4022 bytes --]

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 51800a9..8f9366e 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -284,12 +284,19 @@ out:
 	nvmet_req_complete(req, status);
 }
 
+const char *nvme_controller_model(char *model)
+{
+	if (!model)
+		return NVMET_DEFAULT_CTRL_MODEL;
+	return model;
+}
+
 static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
 {
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
+	const char *model = nvme_controller_model(ctrl->subsys->model);
 	struct nvme_id_ctrl *id;
 	u16 status = 0;
-	const char model[] = "Linux";
 
 	id = kzalloc(sizeof(*id), GFP_KERNEL);
 	if (!id) {
@@ -304,7 +311,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 98613a4..18a3f4d 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -862,10 +862,57 @@ 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", subsys->model);
+}
+
+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);
+	char *tmp;
+	int ret = -EINVAL, pos, len;
+	char c;
+
+	down_write(&nvmet_config_sem);
+	len = strcspn(page, "\n");
+	if (!len)
+		goto out_unlock;
+
+	/* Only 20h (space) until 7eh (~) is allowed */
+	for (pos = 0; pos < len; pos++) {
+		c = page[pos];
+		if (c < 0x20 || c > 0x7e)
+			goto out_unlock;
+	}
+
+	tmp = kstrndup(page, len, GFP_KERNEL);
+	if (!tmp) {
+		ret = -ENOMEM;
+		goto out_unlock;
+	}
+
+	ret = count;
+	if (subsys->model)
+		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,
 };
 
@@ -901,6 +948,7 @@ static struct config_group *nvmet_subsys_make(struct config_group *group,
 	}
 
 	subsys = nvmet_subsys_alloc(name, NVME_NQN_NVME);
+	subsys->model = kstrdup(NVMET_DEFAULT_CTRL_MODEL, GFP_KERNEL);
 	if (IS_ERR(subsys))
 		return ERR_CAST(subsys);
 
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 3a67e24..25ca3cd 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1418,6 +1418,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
 		kfree(subsys);
 		return ERR_PTR(-ENOMEM);
 	}
+	subsys->model = 0;
 
 	kref_init(&subsys->ref);
 
@@ -1437,6 +1438,8 @@ static void nvmet_subsys_free(struct kref *ref)
 	WARN_ON_ONCE(!list_empty(&subsys->namespaces));
 
 	kfree(subsys->subsysnqn);
+	if (subsys->model)
+		kfree(subsys->model);
 	kfree(subsys);
 }
 
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index c51f8dd..fd0d89a 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;
 

[-- Attachment #3: nvmetcli.patch --]
[-- Type: application/octet-stream, Size: 785 bytes --]

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)
 
 

[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  reply	other threads:[~2019-11-11 13:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01  8:08 [PATCH] nvmet: make ctrl model configurable Chaitanya Kulkarni
2019-11-11 10:34 ` Christoph Hellwig
2019-11-11 13:31   ` Mark Ruijter [this message]
2019-11-12  7:07     ` Chaitanya Kulkarni
2019-11-12  7:06   ` Chaitanya Kulkarni
2019-11-11 11:09 ` Mark Ruijter
  -- strict thread matches above, loose matches on Subject: below --
2019-10-30 19:48 Chaitanya Kulkarni
2019-10-30 20:08 ` Mark Ruijter
2019-10-30 20:09   ` Chaitanya Kulkarni
2019-10-30 21:43   ` Chaitanya Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=829AB08E-457F-4E8E-8964-DD3ADF9140BD@onestopsystems.com \
    --to=mruijter@onestopsystems.com \
    --cc=chaitanya.kulkarni@wdc.com \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).