summaryrefslogtreecommitdiffstats
path: root/drivers/nvme/target/configfs.c
diff options
context:
space:
mode:
authorNoam Gottlieb <ngottlieb@nvidia.com>2021-06-07 12:23:22 +0300
committerChristoph Hellwig <hch@lst.de>2021-06-17 15:51:19 +0200
commit7ae023c5aa644211bde26db11018fe08b8408bd5 (patch)
treed0b33f08cfd31fe77c429d2b1050148efa6779e2 /drivers/nvme/target/configfs.c
parente13b061589ace0aee18bdbf86f3ddb2b6b5b5ab8 (diff)
downloadlinux-7ae023c5aa644211bde26db11018fe08b8408bd5.tar.gz
linux-7ae023c5aa644211bde26db11018fe08b8408bd5.tar.bz2
linux-7ae023c5aa644211bde26db11018fe08b8408bd5.zip
nvmet: make sn stable once connection was established
Once some host has connected to the target, make sure that the serial number is stable and cannot be changed. Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com> Signed-off-by: Noam Gottlieb <ngottlieb@nvidia.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/nvme/target/configfs.c')
-rw-r--r--drivers/nvme/target/configfs.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 027b28aaf7cd..a13da86fb374 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -1044,12 +1044,18 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item,
return snprintf(page, PAGE_SIZE, "%s\n", subsys->serial);
}
-static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
- const char *page, size_t count)
+static ssize_t
+nvmet_subsys_attr_serial_store_locked(struct nvmet_subsys *subsys,
+ const char *page, size_t count)
{
- struct nvmet_subsys *subsys = to_subsys(item);
int pos, len = strcspn(page, "\n");
+ if (subsys->subsys_discovered) {
+ pr_err("Can't set serial number. %s is already assigned\n",
+ subsys->serial);
+ return -EINVAL;
+ }
+
if (!len || len > NVMET_SN_MAX_SIZE) {
pr_err("Serial Number can not be empty or exceed %d Bytes\n",
NVMET_SN_MAX_SIZE);
@@ -1063,13 +1069,24 @@ static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
}
}
+ memcpy_and_pad(subsys->serial, NVMET_SN_MAX_SIZE, page, len, ' ');
+
+ return count;
+}
+
+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);
+ ssize_t ret;
+
down_write(&nvmet_config_sem);
mutex_lock(&subsys->lock);
- memcpy_and_pad(subsys->serial, NVMET_SN_MAX_SIZE, page, len, ' ');
+ ret = nvmet_subsys_attr_serial_store_locked(subsys, page, count);
mutex_unlock(&subsys->lock);
up_write(&nvmet_config_sem);
- return count;
+ return ret;
}
CONFIGFS_ATTR(nvmet_subsys_, attr_serial);