Skip to contentSkip to conversation

nvme: avoid creating multipath sysfs group under namespace path devices

PATCH In review Nilay Shroff 2 participants 3 messages May 21, 2025 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: avoid creating multipath sysfs group under namespace path devices

Commit 4dbd2b2ebe4c ("nvme-multipath: Add visibility for round-robin io-policy") introduced the creation of the multipath sysfs group under the NVMe head gendisk device node. However, it also inadvertently added the same sysfs group under each namespace path device which head node refers to and that is incorrect.

The multipath sysfs group should only be exposed through the namespace head gendisk node. This is sufficient, as the head device already provides symbolic links to the individual namespace paths it manages.

This patch fixes the issue by preventing the creation of the multipath sysfs group under namespace path devices, ensuring it only appears under the head disk node.

Fixes 4dbd2b2ebe4c ("nvme-multipath: Add visibility for round-robin io-policy")
---
 drivers/nvme/host/sysfs.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/nvme/host/sysfs.c +31 -0
index a48d30c31d51..222e7448f0f0 100644
@@ -313,13 +313,44 @@ static const struct attribute_group nvme_ns_attr_group = {
 };
 
 #ifdef CONFIG_NVME_MULTIPATH
+/*
+ * NOTE: The dummy attribute does not appear in sysfs. It exists solely to allow
+ * control over the visibility of the multipath sysfs node. Without at least one
+ * attribute defined in nvme_ns_mpath_attrs[], the sysfs implementation does not
+ * invoke the multipath_sysfs_group_visible() method. As a result, we would not
+ * be able to control the visibility of the multipath sysfs node.
+ */
+static struct attribute dummy_attr = {
+		.name = "dummy",
+};
+
 static struct attribute *nvme_ns_mpath_attrs[] = {
+	&dummy_attr,
 	NULL,
 };
 
+static bool multipath_sysfs_group_visible(struct kobject *kobj)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+
+	if (!nvme_disk_is_ns_head(dev_to_disk(dev)))
+		return false;
+
+	return true;
+}
+
+static bool multipath_sysfs_attr_visible(struct kobject *kobj,
+		struct attribute *attr, int n)
+{
+	return false;
+}
+
+DEFINE_SYSFS_GROUP_VISIBLE(multipath_sysfs)
+
 const struct attribute_group nvme_ns_mpath_attr_group = {
 	.name           = "multipath",
 	.attrs		= nvme_ns_mpath_attrs,
+	.is_visible     = SYSFS_GROUP_VISIBLE(multipath_sysfs),
 };
 #endif
 
Signature · 1 line
2.49.0
#1 lore raw
Quoted 7 lines · Nilay Shroff

The multipath sysfs group should only be exposed through the namespace head gendisk node. This is sufficient, as the head device already provides symbolic links to the individual namespace paths it manages.

This patch fixes the issue by preventing the creation of the multipath sysfs group under namespace path devices, ensuring it only appears under the head disk node.

Yeah. Looks like we should still try to rush this into 6.15? I'll tentatively queued it up because the pull request needs to got to Jens tomorrow for that. Any expedited reviews would be appreciated.

drivers/nvme/host/sysfs.c static const struct attribute_group nvme_ns_attr_group = { · line 325

Quoted 3 lines
drivers/nvme/host/sysfs.c +3 -0
+static struct attribute dummy_attr = {
+		.name = "dummy",
+};

The double tab here looks wrong. I'll fix it up.

#2 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Nilay Shroff

The multipath sysfs group should only be exposed through the namespace head gendisk node. This is sufficient, as the head device already provides symbolic links to the individual namespace paths it manages.

Quoted 8 lines
Quoted 3 lines

This patch fixes the issue by preventing the creation of the multipath sysfs group under namespace path devices, ensuring it only appears under the head disk node.

Yeah. Looks like we should still try to rush this into 6.15? I'll tentatively queued it up because the pull request needs to got to Jens tomorrow for that. Any expedited reviews would be appreciated.

Yeah it'd be good if we can push this one into 6.15.

Quoted 6 lines

drivers/nvme/host/sysfs.c static const struct attribute_group nvme_ns_attr_group = { · line 325

Quoted 3 lines
drivers/nvme/host/sysfs.c +3 -0
+static struct attribute dummy_attr = {
+		.name = "dummy",
+};

The double tab here looks wrong. I'll fix it up.

Thanks!

--Nilay