Commit 87fd4cc1 authored by Noam Gottlieb's avatar Noam Gottlieb Committed by Christoph Hellwig

nvmet: make ver stable once connection established

Once some host has connected to the nvmf target, make sure that the
version number is stable and cannot be changed.
Signed-off-by: default avatarMax Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: default avatarNoam Gottlieb <ngottlieb@nvidia.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 0d148efd
...@@ -1007,13 +1007,26 @@ static ssize_t nvmet_subsys_attr_version_show(struct config_item *item, ...@@ -1007,13 +1007,26 @@ static ssize_t nvmet_subsys_attr_version_show(struct config_item *item,
NVME_MINOR(subsys->ver)); NVME_MINOR(subsys->ver));
} }
static ssize_t nvmet_subsys_attr_version_store(struct config_item *item, static ssize_t
nvmet_subsys_attr_version_store_locked(struct nvmet_subsys *subsys,
const char *page, size_t count) const char *page, size_t count)
{ {
struct nvmet_subsys *subsys = to_subsys(item);
int major, minor, tertiary = 0; int major, minor, tertiary = 0;
int ret; int ret;
if (subsys->subsys_discovered) {
if (NVME_TERTIARY(subsys->ver))
pr_err("Can't set version number. %llu.%llu.%llu is already assigned\n",
NVME_MAJOR(subsys->ver),
NVME_MINOR(subsys->ver),
NVME_TERTIARY(subsys->ver));
else
pr_err("Can't set version number. %llu.%llu is already assigned\n",
NVME_MAJOR(subsys->ver),
NVME_MINOR(subsys->ver));
return -EINVAL;
}
/* passthru subsystems use the underlying controller's version */ /* passthru subsystems use the underlying controller's version */
if (nvmet_passthru_ctrl(subsys)) if (nvmet_passthru_ctrl(subsys))
return -EINVAL; return -EINVAL;
...@@ -1022,12 +1035,25 @@ static ssize_t nvmet_subsys_attr_version_store(struct config_item *item, ...@@ -1022,12 +1035,25 @@ static ssize_t nvmet_subsys_attr_version_store(struct config_item *item,
if (ret != 2 && ret != 3) if (ret != 2 && ret != 3)
return -EINVAL; return -EINVAL;
down_write(&nvmet_config_sem);
subsys->ver = NVME_VS(major, minor, tertiary); subsys->ver = NVME_VS(major, minor, tertiary);
up_write(&nvmet_config_sem);
return count; return count;
} }
static ssize_t nvmet_subsys_attr_version_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);
ret = nvmet_subsys_attr_version_store_locked(subsys, page, count);
mutex_unlock(&subsys->lock);
up_write(&nvmet_config_sem);
return ret;
}
CONFIGFS_ATTR(nvmet_subsys_, attr_version); CONFIGFS_ATTR(nvmet_subsys_, attr_version);
/* See Section 1.5 of NVMe 1.4 */ /* See Section 1.5 of NVMe 1.4 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment