[PATCH] nvmet: fix port check in nvmet_subsys_attr_qid_max_show

Daniel Wagner dwagner at suse.de
Mon Sep 12 23:42:03 PDT 2022


The item passed into nvmet_subsys_attr_qid_max_show is not a member of
struct nvmet_port, it is part of nvmet_subsys. Because we don't a link
from the subsystem to a port we have to iterate over all ports and see
if any of the ports are linked to the subsystem to figure out if the
subsystem is in use.

Fixes: 2c4282742d04 ("nvmet: Expose max queues to configfs")
Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki at wdc.com>
Signed-off-by: Daniel Wagner <dwagner at suse.de>
---
 drivers/nvme/target/configfs.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index e34a2896fedb..e3711b1331ee 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -1290,11 +1290,21 @@ static ssize_t nvmet_subsys_attr_qid_max_show(struct config_item *item,
 static ssize_t nvmet_subsys_attr_qid_max_store(struct config_item *item,
 					       const char *page, size_t cnt)
 {
-	struct nvmet_port *port = to_nvmet_port(item);
+	struct nvmet_subsys *subsys = to_subsys(item);
+	struct nvmet_subsys_link *s;
+	struct nvmet_port *port;
 	u16 qid_max;
 
-	if (nvmet_is_port_enabled(port, __func__))
-		return -EACCES;
+	down_write(&nvmet_config_sem);
+	list_for_each_entry(port, nvmet_ports, global_entry) {
+		list_for_each_entry(s, &port->subsystems, entry) {
+			if (s->subsys != subsys)
+				continue;
+			up_write(&nvmet_config_sem);
+			return -EACCES;
+		}
+	}
+	up_write(&nvmet_config_sem);
 
 	if (sscanf(page, "%hu\n", &qid_max) != 1)
 		return -EINVAL;
@@ -1303,7 +1313,7 @@ static ssize_t nvmet_subsys_attr_qid_max_store(struct config_item *item,
 		return -EINVAL;
 
 	down_write(&nvmet_config_sem);
-	to_subsys(item)->max_qid = qid_max;
+	subsys->max_qid = qid_max;
 	up_write(&nvmet_config_sem);
 	return cnt;
 }
-- 
2.35.3




More information about the Linux-nvme mailing list