aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Thumshirn <jthumshirn@suse.de>2017-07-14 09:36:56 -0400
committerJens Axboe <axboe@kernel.dk>2017-07-20 10:41:56 -0400
commitfcbc545959676282e7f46be5c8d8aea26a89ea47 (patch)
tree9011c59df16121778a017dc6bef86e38c94d2201
parent2e7f5d2af2155084c6f7c86328d36e698cd84954 (diff)
nvmet: preserve controller serial number between reboots
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> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--drivers/nvme/target/configfs.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index ceee57bb0c24..0a0067e771f5 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -686,9 +686,31 @@ static ssize_t nvmet_subsys_attr_version_store(struct config_item *item,
686} 686}
687CONFIGFS_ATTR(nvmet_subsys_, attr_version); 687CONFIGFS_ATTR(nvmet_subsys_, attr_version);
688 688
689static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item,
690 char *page)
691{
692 struct nvmet_subsys *subsys = to_subsys(item);
693
694 return snprintf(page, PAGE_SIZE, "%llx\n", subsys->serial);
695}
696
697static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
698 const char *page, size_t count)
699{
700 struct nvmet_subsys *subsys = to_subsys(item);
701
702 down_write(&nvmet_config_sem);
703 sscanf(page, "%llx\n", &subsys->serial);
704 up_write(&nvmet_config_sem);
705
706 return count;
707}
708CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
709
689static struct configfs_attribute *nvmet_subsys_attrs[] = { 710static struct configfs_attribute *nvmet_subsys_attrs[] = {
690 &nvmet_subsys_attr_attr_allow_any_host, 711 &nvmet_subsys_attr_attr_allow_any_host,
691 &nvmet_subsys_attr_attr_version, 712 &nvmet_subsys_attr_attr_version,
713 &nvmet_subsys_attr_attr_serial,
692 NULL, 714 NULL,
693}; 715};
694 716