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,
CONFIGFS_ATTR(nvmet_, addr_traddr);
static ssize_t nvmet_addr_treq_show(struct config_item *item,
char *page)
static const struct nvmet_type_name_map nvmet_addr_treq[] = {
{ 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 &
NVME_TREQ_SECURE_CHANNEL_MASK) {
case NVMF_TREQ_NOT_SPECIFIED:
return sprintf(page, "not specified\n");
case NVMF_TREQ_REQUIRED:
return sprintf(page, "required\n");
case NVMF_TREQ_NOT_REQUIRED:
return sprintf(page, "not required\n");
default:
return sprintf(page, "\n");
u8 treq = to_nvmet_port(item)->disc_addr.treq &
NVME_TREQ_SECURE_CHANNEL_MASK;
int i;
for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
if (treq == nvmet_addr_treq[i].type)
return sprintf(page, "%s\n", nvmet_addr_treq[i].name);
}
return sprintf(page, "\n");
}
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);
u8 treq = port->disc_addr.treq & ~NVME_TREQ_SECURE_CHANNEL_MASK;
int i;
if (port->enabled) {
pr_err("Cannot modify address while enabled\n");
......@@ -175,18 +180,17 @@ static ssize_t nvmet_addr_treq_store(struct config_item *item,
return -EACCES;
}
if (sysfs_streq(page, "not specified")) {
treq |= NVMF_TREQ_NOT_SPECIFIED;
} else if (sysfs_streq(page, "required")) {
treq |= NVMF_TREQ_REQUIRED;
} else if (sysfs_streq(page, "not required")) {
treq |= NVMF_TREQ_NOT_REQUIRED;
} else {
for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
if (sysfs_streq(page, nvmet_addr_treq[i].name))
goto found;
}
pr_err("Invalid value '%s' for treq\n", page);
return -EINVAL;
}
port->disc_addr.treq = treq;
found:
treq |= nvmet_addr_treq[i].type;
port->disc_addr.treq = treq;
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