Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1687251 > unrolled thread
| Started by | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| First post | 2017-07-14 13:10 +0200 |
| Last post | 2017-07-14 13:10 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 0/2] Provide a stable serial number Johannes Thumshirn <jthumshirn@suse.de> - 2017-07-14 13:10 +0200
[PATCH 2/2] nvmet: preserve controller serial number between reboots Johannes Thumshirn <jthumshirn@suse.de> - 2017-07-14 13:10 +0200
Re: [PATCH 1/2] nvmet: Move serial number from controller to subsystem Christoph Hellwig <hch@lst.de> - 2017-07-14 13:10 +0200
[PATCH 1/2] nvmet: Move serial number from controller to subsystem Johannes Thumshirn <jthumshirn@suse.de> - 2017-07-14 13:10 +0200
| From | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| Date | 2017-07-14 13:10 +0200 |
| Subject | [PATCH 0/2] Provide a stable serial number |
| Message-ID | <u36DT-2z6-13@gated-at.bofh.it> |
This pathset is a follow up to http://lists.infradead.org/pipermail/linux-nvme/2017-July/011934.html. The 1st patch moves the serial attribute from the contrller to the subsystem, while the 2nd patch makes it configurable via configfs. Johannes Thumshirn (2): nvmet: Move serial number from controller to subsystem nvmet: preserve controller serial number between reboots drivers/nvme/target/admin-cmd.c | 2 +- drivers/nvme/target/configfs.c | 22 ++++++++++++++++++++++ drivers/nvme/target/core.c | 6 ++++-- drivers/nvme/target/nvmet.h | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) -- 2.12.3
[toc] | [next] | [standalone]
| From | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| Date | 2017-07-14 13:10 +0200 |
| Subject | [PATCH 2/2] nvmet: preserve controller serial number between reboots |
| Message-ID | <u36DU-2z6-17@gated-at.bofh.it> |
| In reply to | #1687251 |
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 e3ceff3d2d17..d38f4b9861c1 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -767,8 +767,10 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE);
+ down_read(&nvmet_config_sem);
if (!subsys->serial)
get_random_bytes(&subsys->serial, sizeof(subsys->serial));
+ up_read(&nvmet_config_sem);
kref_init(&ctrl->ref);
ctrl->subsys = subsys;
--
2.12.3
[toc] | [prev] | [next] | [standalone]
| From | Christoph Hellwig <hch@lst.de> |
|---|---|
| Date | 2017-07-14 13:10 +0200 |
| Subject | Re: [PATCH 1/2] nvmet: Move serial number from controller to subsystem |
| Message-ID | <u36DU-2z6-23@gated-at.bofh.it> |
| In reply to | #1687251 |
> + if (!subsys->serial) > + get_random_bytes(&subsys->serial, sizeof(subsys->serial)); This should move to nvmet_subsys_alloc instead.
[toc] | [prev] | [next] | [standalone]
| From | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| Date | 2017-07-14 13:10 +0200 |
| Subject | [PATCH 1/2] nvmet: Move serial number from controller to subsystem |
| Message-ID | <u36DU-2z6-25@gated-at.bofh.it> |
| In reply to | #1687251 |
The NVMe specification defines the serial number as:
"Serial Number (SN): Contains the serial number for the NVM subsystem
that is assigned by the vendor as an ASCII string. Refer to section
7.10 for unique identifier requirements. Refer to section 1.5 for ASCII
string requirements"
So move it from the controller to the subsystem, where it belongs.
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
drivers/nvme/target/admin-cmd.c | 2 +-
drivers/nvme/target/core.c | 4 ++--
drivers/nvme/target/nvmet.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 35f930db3c02..f7ba006d6a65 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -185,7 +185,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
id->ssvid = 0;
memset(id->sn, ' ', sizeof(id->sn));
- snprintf(id->sn, sizeof(id->sn), "%llx", ctrl->serial);
+ snprintf(id->sn, sizeof(id->sn), "%llx", ctrl->subsys->serial);
memset(id->mn, ' ', sizeof(id->mn));
strncpy((char *)id->mn, "Linux", sizeof(id->mn));
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index b5b4ac103748..e3ceff3d2d17 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -767,8 +767,8 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE);
- /* generate a random serial number as our controllers are ephemeral: */
- get_random_bytes(&ctrl->serial, sizeof(ctrl->serial));
+ if (!subsys->serial)
+ get_random_bytes(&subsys->serial, sizeof(subsys->serial));
kref_init(&ctrl->ref);
ctrl->subsys = subsys;
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 747bbdb4f9c6..e3b244c7e443 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -112,7 +112,6 @@ struct nvmet_ctrl {
struct mutex lock;
u64 cap;
- u64 serial;
u32 cc;
u32 csts;
@@ -152,6 +151,7 @@ struct nvmet_subsys {
u16 max_qid;
u64 ver;
+ u64 serial;
char *subsysnqn;
struct config_group group;
--
2.12.3
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web