Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1687291 > unrolled thread

[PATCH v2 2/2] nvmet: preserve controller serial number between reboots

Started byJohannes Thumshirn <jthumshirn@suse.de>
First post2017-07-14 14:10 +0200
Last post2017-07-14 14:50 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2 2/2] nvmet: preserve controller serial number between reboots Johannes Thumshirn <jthumshirn@suse.de> - 2017-07-14 14:10 +0200
    Re: [PATCH v2 2/2] nvmet: preserve controller serial number         between reboots Christoph Hellwig <hch@lst.de> - 2017-07-14 14:40 +0200
      Re: [PATCH v2 2/2] nvmet: preserve controller serial number         between reboots Christoph Hellwig <hch@lst.de> - 2017-07-14 14:50 +0200
      Re: [PATCH v2 2/2] nvmet: preserve controller serial number between  reboots Johannes Thumshirn <jthumshirn@suse.de> - 2017-07-14 14:50 +0200

#1687291 — [PATCH v2 2/2] nvmet: preserve controller serial number between reboots

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-07-14 14:10 +0200
Subject[PATCH v2 2/2] nvmet: preserve controller serial number between reboots
Message-ID<u37zY-3en-19@gated-at.bofh.it>
The NVMe target has no way to preserve controller serial
IDs across reboots which breaks udev scripts doing
SYMLINK+="dev/disk/by-id/nvme-$env{ID_SERIAL}-part%n.

Export the randomly generated serial number via configfs and allow
setting of a serial via configfs to mitigate this breakage.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/nvme/target/configfs.c | 22 ++++++++++++++++++++++
 drivers/nvme/target/core.c     |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index a358ecd93e11..9f19f0bde8f2 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -686,9 +686,31 @@ static ssize_t nvmet_subsys_version_store(struct config_item *item,
 }
 CONFIGFS_ATTR(nvmet_subsys_, version);
 
+static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item,
+					     char *page)
+{
+	struct nvmet_subsys *subsys = to_subsys(item);
+
+	return snprintf(page, PAGE_SIZE, "%llx\n", subsys->serial);
+}
+
+static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
+					      const char *page, size_t count)
+{
+	struct nvmet_subsys *subsys = to_subsys(item);
+
+	down_write(&nvmet_config_sem);
+	sscanf(page, "%llx\n", &subsys->serial);
+	up_write(&nvmet_config_sem);
+
+	return count;
+}
+CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
+
 static struct configfs_attribute *nvmet_subsys_attrs[] = {
 	&nvmet_subsys_attr_attr_allow_any_host,
 	&nvmet_subsys_attr_version,
+	&nvmet_subsys_attr_attr_serial,
 	NULL,
 };
 
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 02efa7113d23..8feeed8c709c 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -924,8 +924,10 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
 	if (!subsys)
 		return NULL;
 
+	down_write(&nvmet_config_sem);
 	subsys->ver = NVME_VS(1, 3, 0); /* NVMe 1.3.0 */
 	get_random_bytes(&subsys->serial, sizeof(subsys->serial));
+	up_write(&nvmet_config_sem);
 
 	switch (type) {
 	case NVME_NQN_NVME:
-- 
2.12.3

[toc] | [next] | [standalone]


#1687342 — Re: [PATCH v2 2/2] nvmet: preserve controller serial number between reboots

FromChristoph Hellwig <hch@lst.de>
Date2017-07-14 14:40 +0200
SubjectRe: [PATCH v2 2/2] nvmet: preserve controller serial number between reboots
Message-ID<u3830-3qu-21@gated-at.bofh.it>
In reply to#1687291
This patch itself looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

>  static struct configfs_attribute *nvmet_subsys_attrs[] = {
>  	&nvmet_subsys_attr_attr_allow_any_host,
>  	&nvmet_subsys_attr_version,
> +	&nvmet_subsys_attr_attr_serial,

but the new version attribute really needs the attr prefix so that
nvmetcli can pick it up.  And we should also add nvmetcli support
for it.  Can you do the rename before your series to ease backporting
as that should go into 3.12 (just like your serial number fix).

[toc] | [prev] | [next] | [standalone]


#1687359 — Re: [PATCH v2 2/2] nvmet: preserve controller serial number between reboots

FromChristoph Hellwig <hch@lst.de>
Date2017-07-14 14:50 +0200
SubjectRe: [PATCH v2 2/2] nvmet: preserve controller serial number between reboots
Message-ID<u38cI-3uL-35@gated-at.bofh.it>
In reply to#1687342
On Fri, Jul 14, 2017 at 02:46:32PM +0200, Johannes Thumshirn wrote:
> On Fri, Jul 14, 2017 at 02:32:08PM +0200, Christoph Hellwig wrote:
> > This patch itself looks good:
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > 
> > >  static struct configfs_attribute *nvmet_subsys_attrs[] = {
> > >  	&nvmet_subsys_attr_attr_allow_any_host,
> > >  	&nvmet_subsys_attr_version,
> > > +	&nvmet_subsys_attr_attr_serial,
> > 
> > but the new version attribute really needs the attr prefix so that
> > nvmetcli can pick it up.  And we should also add nvmetcli support
> > for it.  Can you do the rename before your series to ease backporting
> > as that should go into 3.12 (just like your serial number fix).
> > 
> 
> Is it OK if I send the patches in the same series? 

Yes.  Just move the version fix to the beginning, please.

[toc] | [prev] | [next] | [standalone]


#1687364 — Re: [PATCH v2 2/2] nvmet: preserve controller serial number between reboots

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-07-14 14:50 +0200
SubjectRe: [PATCH v2 2/2] nvmet: preserve controller serial number between reboots
Message-ID<u38cI-3uL-37@gated-at.bofh.it>
In reply to#1687342
On Fri, Jul 14, 2017 at 02:32:08PM +0200, Christoph Hellwig wrote:
> This patch itself looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> >  static struct configfs_attribute *nvmet_subsys_attrs[] = {
> >  	&nvmet_subsys_attr_attr_allow_any_host,
> >  	&nvmet_subsys_attr_version,
> > +	&nvmet_subsys_attr_attr_serial,
> 
> but the new version attribute really needs the attr prefix so that
> nvmetcli can pick it up.  And we should also add nvmetcli support
> for it.  Can you do the rename before your series to ease backporting
> as that should go into 3.12 (just like your serial number fix).
> 

Is it OK if I send the patches in the same series? 

-- 
Johannes Thumshirn                                          Storage
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web