Skip to contentSkip to conversation

nvme-multipath: sysfs links may not be created for devices

PATCH Applied Hannes Reinecke 4 participants 4 messages Apr 15, 2025 – Apr 16, 2025 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvme-multipath: sysfs links may not be created for devices

When rapidly rescanning for new namespaces nvme_mpath_add_sysfs_link() may be called for a block device not added to sysfs. But NVME_NS_SYSFS_ATTR_LINK had already been set, so when checking this device a second time we will fail to create the link.

Fix this by exchanging the order of the block device check and the NVME_NS_SYSFS_ATTR_LINK bit check.

Fixes 4dbd2b2ebe4c ("nvme-multipath: Add visibility for round-robin io-policy")
---
 drivers/nvme/host/multipath.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/nvme/host/multipath.c +7 -7
index 05eccd96d34a..250f3da67cc9 100644
@@ -1050,6 +1050,13 @@ void nvme_mpath_add_sysfs_link(struct nvme_ns_head *head)
 	srcu_idx = srcu_read_lock(&head->srcu);
 
 	list_for_each_entry_rcu(ns, &head->list, siblings) {
+		/*
+		 * Ensure that ns path disk node is already added otherwise we
+		 * may get invalid kobj name for target
+		 */
+		if (!test_bit(GD_ADDED, &ns->disk->state))
+			continue;
+
 		/*
 		 * Avoid creating link if it already exists for the given path.
 		 * When path ana state transitions from optimized to non-
@@ -1065,13 +1072,6 @@ void nvme_mpath_add_sysfs_link(struct nvme_ns_head *head)
 		if (test_and_set_bit(NVME_NS_SYSFS_ATTR_LINK, &ns->flags))
 			continue;
 
-		/*
-		 * Ensure that ns path disk node is already added otherwise we
-		 * may get invalid kobj name for target
-		 */
-		if (!test_bit(GD_ADDED, &ns->disk->state))
-			continue;
-
 		target = disk_to_dev(ns->disk);
 		/*
 		 * Create sysfs link from head gendisk kobject @kobj to the
Signature · 1 line
2.35.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Hannes Reinecke

When rapidly rescanning for new namespaces nvme_mpath_add_sysfs_link() may be called for a block device not added to sysfs. But NVME_NS_SYSFS_ATTR_LINK had already been set, so when checking this device a second time we will fail to create the link.

Quoted 7 lines

Fix this by exchanging the order of the block device check and the NVME_NS_SYSFS_ATTR_LINK bit check.

Fixes 4dbd2b2ebe4c ("nvme-multipath: Add visibility for round-robin io-policy")

Looks good to me: