Skip to contentSkip to conversation

hw/nvme: reattach subsystem namespaces on hotplug

PATCH New Hannes Reinecke 1 participant 1 message Sep 9, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/nvme: reattach subsystem namespaces on hotplug

With commit 5ffbaeed16 ("hw/nvme: fix controller hot unplugging") namespaces get moved from the controller to the subsystem if one is specified.
That keeps the namespaces alive after a controller hot-unplug, but after a controller hotplug we have to reconnect the namespaces from the subsystem to the controller.

Fixes 5ffbaeed16 ("hw/nvme: fix controller hot unplugging")
Cc Klaus Jensen <[email protected]>
---
 hw/nvme/subsys.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/nvme/subsys.c +7 -1
index 93c35950d6..a9404f2b5e 100644
@@ -14,7 +14,7 @@
 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
 {
     NvmeSubsystem *subsys = n->subsys;
-    int cntlid;
+    int cntlid, nsid;
 
     for (cntlid = 0; cntlid < ARRAY_SIZE(subsys->ctrls); cntlid++) {
         if (!subsys->ctrls[cntlid]) {
@@ -29,12 +29,18 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
 
     subsys->ctrls[cntlid] = n;
 
+    for (nsid = 0; nsid < ARRAY_SIZE(subsys->namespaces); nsid++) {
+        if (subsys->namespaces[nsid]) {
+            nvme_attach_ns(n, subsys->namespaces[nsid]);
+        }
+    }
     return cntlid;
 }
 
 void nvme_subsys_unregister_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n)
 {
     subsys->ctrls[n->cntlid] = NULL;
+    n->cntlid = -1;
 }
 
 static void nvme_subsys_setup(NvmeSubsystem *subsys)
Signature · 1 line
2.26.2