All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/nvme: select first free NSID for legacy drive configuration
@ 2021-09-09  9:51 Hannes Reinecke
  2021-09-09 10:52 ` Klaus Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: Hannes Reinecke @ 2021-09-09  9:51 UTC (permalink / raw)
  To: Klaus Jensen; +Cc: qemu-devel, qemu-block, Hannes Reinecke

If a legacy 'drive' argument is passed to the controller we cannot
assume that '1' will be a free NSID, as the subsys might already
have attached a namespace to this NSID. So select the first free
one.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 hw/nvme/ctrl.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 757cdff038..2c69031ca9 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6546,8 +6546,15 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
 
     /* setup a namespace if the controller drive property was given */
     if (n->namespace.blkconf.blk) {
+        int i;
         ns = &n->namespace;
-        ns->params.nsid = 1;
+        for (i = 1; i <= NVME_MAX_NAMESPACES; i++) {
+            if (nvme_ns(n, i) || nvme_subsys_ns(n->subsys, i)) {
+                continue;
+            }
+            ns->params.nsid = i;
+            break;
+        }
 
         if (nvme_ns_setup(ns, errp)) {
             return;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-09 11:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  9:51 [PATCH] hw/nvme: select first free NSID for legacy drive configuration Hannes Reinecke
2021-09-09 10:52 ` Klaus Jensen
2021-09-09 11:38   ` Hannes Reinecke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.