]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
hw/xen: automatically assign device index to console devices
authorDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 16 Oct 2023 11:30:39 +0000 (12:30 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 16 Oct 2023 15:09:35 +0000 (16:09 +0100)
Now that we can reliably tell whether a given device already exists, we
can allow the user to add console devices on the command line with just
'-device xen-console,chardev=foo'.

Start at 1, because we can't add the *primary* console; that's special
because the toolstack has to set up the guest end of that.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
hw/char/xen_console.c

index 2825b8c511a8f1c1d9fb7237ae9a440a4c57c246..1a0f5ed3e1fd26ab6004b75485b6507610bfae0e 100644 (file)
@@ -333,6 +333,22 @@ static char *xen_console_get_name(XenDevice *xendev, Error **errp)
 {
     XenConsole *con = XEN_CONSOLE_DEVICE(xendev);
 
+    if (con->dev == -1) {
+        char name[11];
+        int idx = 1;
+
+        /* Theoretically we could go up to INT_MAX here but that's overkill */
+        while (idx < 100) {
+            snprintf(name, sizeof(name), "%u", idx);
+            if (!xen_backend_exists("console", name)) {
+                con->dev = idx;
+                return g_strdup(name);
+            }
+            idx++;
+        }
+        error_setg(errp, "cannot find device index for console device");
+        return NULL;
+    }
     return g_strdup_printf("%u", con->dev);
 }