Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Chaitanya Kulkarni and committed by
Jens Axboe
3ecb5faa 87628e28

+16 -28
+16 -28
drivers/nvme/target/configfs.c
··· 40 40 { NVMF_ADDR_FAMILY_FC, "fc" }, 41 41 }; 42 42 43 + static bool nvmet_is_port_enabled(struct nvmet_port *p, const char *caller) 44 + { 45 + if (p->enabled) 46 + pr_err("Disable port '%u' before changing attribute in %s\n", 47 + le16_to_cpu(p->disc_addr.portid), caller); 48 + return p->enabled; 49 + } 50 + 43 51 /* 44 52 * nvmet_port Generic ConfigFS definitions. 45 53 * Used in any place in the ConfigFS tree that refers to an address. ··· 71 63 struct nvmet_port *port = to_nvmet_port(item); 72 64 int i; 73 65 74 - if (port->enabled) { 75 - pr_err("Cannot modify address while enabled\n"); 76 - pr_err("Disable the address before modifying\n"); 66 + if (nvmet_is_port_enabled(port, __func__)) 77 67 return -EACCES; 78 - } 79 68 80 69 for (i = 1; i < ARRAY_SIZE(nvmet_addr_family); i++) { 81 70 if (sysfs_streq(page, nvmet_addr_family[i].name)) ··· 109 104 return -EINVAL; 110 105 } 111 106 112 - if (port->enabled) { 113 - pr_err("Cannot modify address while enabled\n"); 114 - pr_err("Disable the address before modifying\n"); 107 + if (nvmet_is_port_enabled(port, __func__)) 115 108 return -EACCES; 116 - } 109 + 117 110 port->disc_addr.portid = cpu_to_le16(portid); 118 111 return count; 119 112 } ··· 137 134 return -EINVAL; 138 135 } 139 136 140 - if (port->enabled) { 141 - pr_err("Cannot modify address while enabled\n"); 142 - pr_err("Disable the address before modifying\n"); 137 + if (nvmet_is_port_enabled(port, __func__)) 143 138 return -EACCES; 144 - } 145 139 146 140 if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1) 147 141 return -EINVAL; ··· 174 174 u8 treq = port->disc_addr.treq & ~NVME_TREQ_SECURE_CHANNEL_MASK; 175 175 int i; 176 176 177 - if (port->enabled) { 178 - pr_err("Cannot modify address while enabled\n"); 179 - pr_err("Disable the address before modifying\n"); 177 + if (nvmet_is_port_enabled(port, __func__)) 180 178 return -EACCES; 181 - } 182 179 183 180 for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) { 184 181 if (sysfs_streq(page, nvmet_addr_treq[i].name)) ··· 211 214 pr_err("Invalid value '%s' for trsvcid\n", page); 212 215 return -EINVAL; 213 216 } 214 - if (port->enabled) { 215 - pr_err("Cannot modify address while enabled\n"); 216 - pr_err("Disable the address before modifying\n"); 217 + if (nvmet_is_port_enabled(port, __func__)) 217 218 return -EACCES; 218 - } 219 219 220 220 if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1) 221 221 return -EINVAL; ··· 235 241 struct nvmet_port *port = to_nvmet_port(item); 236 242 int ret; 237 243 238 - if (port->enabled) { 239 - pr_err("Cannot modify inline_data_size while port enabled\n"); 240 - pr_err("Disable the port before modifying\n"); 244 + if (nvmet_is_port_enabled(port, __func__)) 241 245 return -EACCES; 242 - } 243 246 ret = kstrtoint(page, 0, &port->inline_data_size); 244 247 if (ret) { 245 248 pr_err("Invalid value '%s' for inline_data_size\n", page); ··· 274 283 struct nvmet_port *port = to_nvmet_port(item); 275 284 int i; 276 285 277 - if (port->enabled) { 278 - pr_err("Cannot modify address while enabled\n"); 279 - pr_err("Disable the address before modifying\n"); 286 + if (nvmet_is_port_enabled(port, __func__)) 280 287 return -EACCES; 281 - } 282 288 283 289 for (i = 0; i < ARRAY_SIZE(nvmet_transport); i++) { 284 290 if (sysfs_streq(page, nvmet_transport[i].name))