Skip to contentSkip to conversation

nvmet: send namespace changed event after namespace is fully initialized

PATCH In review Nilay Shroff 2 participants 2 messages Oct 2 – Oct 13

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet: send namespace changed event after namespace is fully initialized

nvmet_ns_enable() queues the asynchronous namespace change event before the namespace is enabled and the corresponding xarray entry is marked with NVMET_NS_ENABLED. This may create a narrow race if the host receives the namespace change event before the namespace is fully initialized on the target. In that case, scanning the active namespace list on the host may fail to find the namespace that is being enabled on the target.

The blktests nvme/052 failure was reported[1] due to this race.

Fix the race by moving nvmet_ns_changed() in nvmet_ns_enable() after the namespace is enabled, the xarray entry is marked with NVMET_NS_ENABLED, and the NVMET_NS_IO_LIVE flag is set.

---
 drivers/nvme/target/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/core.c +1 -1
index 8eea0a504308..da98e5cae7f6 100644
@@ -626,11 +626,11 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
 	if (ret)
 		goto out_pr_exit;
 
-	nvmet_ns_changed(subsys, ns->nsid);
 	ns->enabled = true;
 	xa_set_mark(&subsys->namespaces, ns->nsid, NVMET_NS_ENABLED);
 	nvmet_debugfs_ns_setup(ns);
 	set_bit(NVMET_NS_IO_LIVE, &ns->flags);
+	nvmet_ns_changed(subsys, ns->nsid);
 	ret = 0;
 out_unlock:
 	mutex_unlock(&subsys->lock);
Signature · 1 line
2.53.0