[PATCH] nvme: add nvme_is_disc_subsys() helper
Martin George
martinus.gpy at gmail.com
Thu Oct 22 00:31:44 PDT 2026
Mirror the target's nvmet_is_disc_subsys() with a host-side
nvme_is_disc_subsys() helper, and use it for the open-coded
subtype == NVME_NQN_DISC checks in the host code to help
maintain consistency and improve code readability.
And while here, fix an error message to refer to the subsystem
rather than the controller.
Signed-off-by: Martin George <marting at netapp.com>
---
drivers/nvme/host/core.c | 4 ++--
drivers/nvme/host/multipath.c | 6 +++---
drivers/nvme/host/nvme.h | 5 +++++
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 531f9bb14bab..96b1dddf439b 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3329,9 +3329,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
else
subsys->subtype = NVME_NQN_NVME;
- if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) {
+ if (nvme_discovery_ctrl(ctrl) && !nvme_is_disc_subsys(subsys)) {
dev_err(ctrl->device,
- "Subsystem %s is not a discovery controller",
+ "Subsystem %s is not a discovery subsystem",
subsys->subnqn);
kfree(subsys);
return -EINVAL;
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 87b934b46b85..1140491d58dd 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -1072,7 +1072,7 @@ static ssize_t nvme_subsys_iopolicy_show(struct device *dev,
container_of(dev, struct nvme_subsystem, dev);
/* A discovery subsystem has no namespaces and hence no I/O paths */
- if (subsys->subtype == NVME_NQN_DISC)
+ if (nvme_is_disc_subsys(subsys))
return sysfs_emit(buf, "none\n");
return sysfs_emit(buf, "%s\n",
@@ -1109,7 +1109,7 @@ static ssize_t nvme_subsys_iopolicy_store(struct device *dev,
container_of(dev, struct nvme_subsystem, dev);
int policy;
- if (subsys->subtype == NVME_NQN_DISC)
+ if (nvme_is_disc_subsys(subsys))
return -EOPNOTSUPP;
policy = nvme_iopolicy_parse(buf);
@@ -1129,7 +1129,7 @@ static ssize_t iopolicies_show(struct device *dev,
container_of(dev, struct nvme_subsystem, dev);
int i, len = 0;
- if (subsys->subtype == NVME_NQN_DISC)
+ if (nvme_is_disc_subsys(subsys))
return sysfs_emit(buf, "none\n");
for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++)
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index a8ef62b8e34b..ace9119d0c09 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -522,6 +522,11 @@ struct nvme_subsystem {
#endif
};
+static inline bool nvme_is_disc_subsys(struct nvme_subsystem *subsys)
+{
+ return subsys->subtype != NVME_NQN_NVME;
+}
+
/*
* Container structure for uniqueue namespace identifiers.
*/
--
2.43.0
More information about the Linux-nvme
mailing list