Skip to contentSkip to conversation

nvme: add nvme_is_disc_subsys() helper

PATCH In review Martin George 2 participants 4 messages Oct 22 – Oct 28 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: add nvme_is_disc_subsys() helper

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.

---
 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(-)
drivers/nvme/host/core.c +2 -2
index 531f9bb14bab..96b1dddf439b 100644
@@ -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;
drivers/nvme/host/multipath.c +3 -3
index 87b934b46b85..1140491d58dd 100644
@@ -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++)
drivers/nvme/host/nvme.h +5 -0
index a8ef62b8e34b..ace9119d0c09 100644
@@ -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.
  */
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Martin George

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.

Not going to NAK it, but the helper feels a bit pointless to me. Do you have any bigger plans with it?

#2 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Martin George

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.

Quoted 6 lines
Quoted 2 lines

And while here, fix an error message to refer to the subsystem rather than the controller.

Not going to NAK it, but the helper feels a bit pointless to me. Do you have any bigger plans with it?

No bigger plans - it's just a small cleanup. Mainly two things:

- Consistency with the target, which already has something similar
- It folds the open-coded discovery subtype checks into one self- documenting helper for current & future use.

So a minor net improvement rather than a prerequisite for anything.

-Martin

#3 lore raw
Quoted 7 lines · Martin George

No bigger plans - it's just a small cleanup. Mainly two things:

- Consistency with the target, which already has something similar
- It folds the open-coded discovery subtype checks into one self- documenting helper for current & future use.

So a minor net improvement rather than a prerequisite for anything.

Not sure a helper is more self-documenting than a field check.

I don't really care strongly, but this feels a bit like churn without a real purpose to me.