Commit 87628e28 authored by Chaitanya Kulkarni's avatar Chaitanya Kulkarni Committed by Jens Axboe

nvmet: use type-name map for address treq

Currently nvmet_addr_treq_[store|show]() uses switch and if else
ladder for address transport requirements to string and reverse
mapping. With addtion of the generic nvmet_type_name_map structure
we can get rid of the switch and if else ladder with string
duplication.
Signed-off-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 84b8d0d7
...@@ -147,20 +147,24 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item, ...@@ -147,20 +147,24 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item,
CONFIGFS_ATTR(nvmet_, addr_traddr); CONFIGFS_ATTR(nvmet_, addr_traddr);
static ssize_t nvmet_addr_treq_show(struct config_item *item, static const struct nvmet_type_name_map nvmet_addr_treq[] = {
char *page) { NVMF_TREQ_NOT_SPECIFIED, "not specified" },
{ NVMF_TREQ_REQUIRED, "required" },
{ NVMF_TREQ_NOT_REQUIRED, "not required" },
};
static ssize_t nvmet_addr_treq_show(struct config_item *item, char *page)
{ {
switch (to_nvmet_port(item)->disc_addr.treq & u8 treq = to_nvmet_port(item)->disc_addr.treq &
NVME_TREQ_SECURE_CHANNEL_MASK) { NVME_TREQ_SECURE_CHANNEL_MASK;
case NVMF_TREQ_NOT_SPECIFIED: int i;
return sprintf(page, "not specified\n");
case NVMF_TREQ_REQUIRED: for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
return sprintf(page, "required\n"); if (treq == nvmet_addr_treq[i].type)
case NVMF_TREQ_NOT_REQUIRED: return sprintf(page, "%s\n", nvmet_addr_treq[i].name);
return sprintf(page, "not required\n");
default:
return sprintf(page, "\n");
} }
return sprintf(page, "\n");
} }
static ssize_t nvmet_addr_treq_store(struct config_item *item, static ssize_t nvmet_addr_treq_store(struct config_item *item,
...@@ -168,6 +172,7 @@ static ssize_t nvmet_addr_treq_store(struct config_item *item, ...@@ -168,6 +172,7 @@ static ssize_t nvmet_addr_treq_store(struct config_item *item,
{ {
struct nvmet_port *port = to_nvmet_port(item); struct nvmet_port *port = to_nvmet_port(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;
if (port->enabled) { if (port->enabled) {
pr_err("Cannot modify address while enabled\n"); pr_err("Cannot modify address while enabled\n");
...@@ -175,18 +180,17 @@ static ssize_t nvmet_addr_treq_store(struct config_item *item, ...@@ -175,18 +180,17 @@ static ssize_t nvmet_addr_treq_store(struct config_item *item,
return -EACCES; return -EACCES;
} }
if (sysfs_streq(page, "not specified")) { for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
treq |= NVMF_TREQ_NOT_SPECIFIED; if (sysfs_streq(page, nvmet_addr_treq[i].name))
} else if (sysfs_streq(page, "required")) { goto found;
treq |= NVMF_TREQ_REQUIRED;
} else if (sysfs_streq(page, "not required")) {
treq |= NVMF_TREQ_NOT_REQUIRED;
} else {
pr_err("Invalid value '%s' for treq\n", page);
return -EINVAL;
} }
port->disc_addr.treq = treq;
pr_err("Invalid value '%s' for treq\n", page);
return -EINVAL;
found:
treq |= nvmet_addr_treq[i].type;
port->disc_addr.treq = treq;
return count; return count;
} }
......
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