nvmet: centralize port enable access for configfs
The configfs attributes which are supposed to set when port is disable such as addr[addrfam|portid|traddr|treq|trsvcid|inline_data_size|trtype] has repetitive check and generic error message printing. This patch creates centralize helper to check and print an error message that also accepts caller as a parameter. This makes error message easy to parse for the user, removes the duplicate code and makes it available for futures such scenarios. Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
87628e2851
commit
3ecb5faa07
|
@ -40,6 +40,14 @@ static const struct nvmet_type_name_map nvmet_addr_family[] = {
|
||||||
{ NVMF_ADDR_FAMILY_FC, "fc" },
|
{ NVMF_ADDR_FAMILY_FC, "fc" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool nvmet_is_port_enabled(struct nvmet_port *p, const char *caller)
|
||||||
|
{
|
||||||
|
if (p->enabled)
|
||||||
|
pr_err("Disable port '%u' before changing attribute in %s\n",
|
||||||
|
le16_to_cpu(p->disc_addr.portid), caller);
|
||||||
|
return p->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nvmet_port Generic ConfigFS definitions.
|
* nvmet_port Generic ConfigFS definitions.
|
||||||
* Used in any place in the ConfigFS tree that refers to an address.
|
* Used in any place in the ConfigFS tree that refers to an address.
|
||||||
|
@ -63,11 +71,8 @@ static ssize_t nvmet_addr_adrfam_store(struct config_item *item,
|
||||||
struct nvmet_port *port = to_nvmet_port(item);
|
struct nvmet_port *port = to_nvmet_port(item);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (port->enabled) {
|
if (nvmet_is_port_enabled(port, __func__))
|
||||||
pr_err("Cannot modify address while enabled\n");
|
|
||||||
pr_err("Disable the address before modifying\n");
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < ARRAY_SIZE(nvmet_addr_family); i++) {
|
for (i = 1; i < ARRAY_SIZE(nvmet_addr_family); i++) {
|
||||||
if (sysfs_streq(page, nvmet_addr_family[i].name))
|
if (sysfs_streq(page, nvmet_addr_family[i].name))
|
||||||
|
@ -104,11 +109,9 @@ static ssize_t nvmet_addr_portid_store(struct config_item *item,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port->enabled) {
|
if (nvmet_is_port_enabled(port, __func__))
|
||||||
pr_err("Cannot modify address while enabled\n");
|
|
||||||
pr_err("Disable the address before modifying\n");
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
port->disc_addr.portid = cpu_to_le16(portid);
|
port->disc_addr.portid = cpu_to_le16(portid);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -134,11 +137,8 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port->enabled) {
|
if (nvmet_is_port_enabled(port, __func__))
|
||||||
pr_err("Cannot modify address while enabled\n");
|
|
||||||
pr_err("Disable the address before modifying\n");
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
|
|
||||||
if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1)
|
if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -174,11 +174,8 @@ static ssize_t nvmet_addr_treq_store(struct config_item *item,
|
||||||
u8 treq = port->disc_addr.treq & ~NVME_TREQ_SECURE_CHANNEL_MASK;
|
u8 treq = port->disc_addr.treq & ~NVME_TREQ_SECURE_CHANNEL_MASK;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (port->enabled) {
|
if (nvmet_is_port_enabled(port, __func__))
|
||||||
pr_err("Cannot modify address while enabled\n");
|
|
||||||
pr_err("Disable the address before modifying\n");
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
|
for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
|
||||||
if (sysfs_streq(page, nvmet_addr_treq[i].name))
|
if (sysfs_streq(page, nvmet_addr_treq[i].name))
|
||||||
|
@ -214,11 +211,8 @@ static ssize_t nvmet_addr_trsvcid_store(struct config_item *item,
|
||||||
pr_err("Invalid value '%s' for trsvcid\n", page);
|
pr_err("Invalid value '%s' for trsvcid\n", page);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (port->enabled) {
|
if (nvmet_is_port_enabled(port, __func__))
|
||||||
pr_err("Cannot modify address while enabled\n");
|
|
||||||
pr_err("Disable the address before modifying\n");
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
|
|
||||||
if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1)
|
if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -241,11 +235,8 @@ static ssize_t nvmet_param_inline_data_size_store(struct config_item *item,
|
||||||
struct nvmet_port *port = to_nvmet_port(item);
|
struct nvmet_port *port = to_nvmet_port(item);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (port->enabled) {
|
if (nvmet_is_port_enabled(port, __func__))
|
||||||
pr_err("Cannot modify inline_data_size while port enabled\n");
|
|
||||||
pr_err("Disable the port before modifying\n");
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
ret = kstrtoint(page, 0, &port->inline_data_size);
|
ret = kstrtoint(page, 0, &port->inline_data_size);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("Invalid value '%s' for inline_data_size\n", page);
|
pr_err("Invalid value '%s' for inline_data_size\n", page);
|
||||||
|
@ -283,11 +274,8 @@ static ssize_t nvmet_addr_trtype_store(struct config_item *item,
|
||||||
struct nvmet_port *port = to_nvmet_port(item);
|
struct nvmet_port *port = to_nvmet_port(item);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (port->enabled) {
|
if (nvmet_is_port_enabled(port, __func__))
|
||||||
pr_err("Cannot modify address while enabled\n");
|
|
||||||
pr_err("Disable the address before modifying\n");
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(nvmet_transport); i++) {
|
for (i = 0; i < ARRAY_SIZE(nvmet_transport); i++) {
|
||||||
if (sysfs_streq(page, nvmet_transport[i].name))
|
if (sysfs_streq(page, nvmet_transport[i].name))
|
||||||
|
|
Loading…
Reference in New Issue