[libvirt] [PATCH] qemu: add bootindex for usb-host and usb-redir devices

Ján Tomko jtomko at redhat.com
Wed Nov 14 14:51:30 UTC 2012


Allow bootindex to be specified for redirected USB devices and host USB
devices.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=805414

---
Bootindex for these devices is supported since QEMU 1.1.0 (or commit 65bb3a5c)
but the actual booting from usb-host devices is broken since a844ed84
(before 1.2.0).
I haven't tested it with usb-redir yet.
---
 docs/schemas/domaincommon.rng |    3 +++
 src/conf/domain_conf.h        |    4 ++--
 src/qemu/qemu_capabilities.c  |   10 ++++++++++
 src/qemu/qemu_capabilities.h  |    2 ++
 src/qemu/qemu_command.c       |   37 ++++++++++++++++++++++++++++++-------
 5 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2beb035..02ad477 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2779,6 +2779,9 @@
       <optional>
         <ref name="address"/>
       </optional>
+      <optional>
+        <ref name="deviceBoot"/>
+      </optional>
     </element>
   </define>
   <define name="redirfilter">
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6539281..091879e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -279,8 +279,8 @@ struct _virDomainDeviceInfo {
      * devices. */
     int rombar;         /* enum virDomainPciRombarMode */
     char *romfile;
-    /* bootIndex is only user for disk, network interface, and
-     * hostdev devices. */
+    /* bootIndex is only used for disk, network interface, hostdev
+     * and redirdev devices */
     int bootIndex;
 };
 
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 5ce93f2..6ce2638 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -191,6 +191,8 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
               "vnc",
 
               "drive-mirror", /* 115 */
+              "usb-redir.bootindex",
+              "usb-host.bootindex",
     );
 
 struct _qemuCaps {
@@ -1325,6 +1327,11 @@ static struct qemuCapsStringFlags qemuCapsObjectPropsPixx4PM[] = {
 
 static struct qemuCapsStringFlags qemuCapsObjectPropsUsbRedir[] = {
     { "filter", QEMU_CAPS_USB_REDIR_FILTER },
+    { "bootindex", QEMU_CAPS_USB_REDIR_BOOTINDEX },
+};
+
+static struct qemuCapsStringFlags qemuCapsObjectPropsUsbHost[] = {
+    { "bootindex", QEMU_CAPS_USB_HOST_BOOTINDEX },
 };
 
 struct qemuCapsObjectTypeProps {
@@ -1350,6 +1357,8 @@ static struct qemuCapsObjectTypeProps qemuCapsObjectProps[] = {
       ARRAY_CARDINALITY(qemuCapsObjectPropsPixx4PM) },
     { "usb-redir", qemuCapsObjectPropsUsbRedir,
       ARRAY_CARDINALITY(qemuCapsObjectPropsUsbRedir) },
+    { "usb-host", qemuCapsObjectPropsUsbHost,
+      ARRAY_CARDINALITY(qemuCapsObjectPropsUsbHost) },
 };
 
 
@@ -1545,6 +1554,7 @@ qemuCapsExtractDeviceStr(const char *qemu,
                          "-device", "PIIX4_PM,?",
                          "-device", "usb-redir,?",
                          "-device", "ide-drive,?",
+                         "-device", "usb-host,?",
                          NULL);
     /* qemu -help goes to stdout, but qemu -device ? goes to stderr.  */
     virCommandSetErrorBuffer(cmd, &output);
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index fb88aa1..751b3ec 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -153,6 +153,8 @@ enum qemuCapsFlags {
     QEMU_CAPS_BLOCK_COMMIT       = 113, /* block-commit */
     QEMU_CAPS_VNC                = 114, /* Is -vnc available? */
     QEMU_CAPS_DRIVE_MIRROR       = 115, /* drive-mirror monitor command */
+    QEMU_CAPS_USB_REDIR_BOOTINDEX = 116, /* usb-redir.bootindex */
+    QEMU_CAPS_USB_HOST_BOOTINDEX = 117, /* usb-host.bootindex */
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 440fd62..93079f3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3504,6 +3504,16 @@ qemuBuildRedirdevDevStr(virDomainDefPtr def,
         }
     }
 
+    if (dev->info.bootIndex) {
+        if (!qemuCapsGet(caps, QEMU_CAPS_USB_REDIR_BOOTINDEX)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("USB redirection booting is not "
+                             "supported by this version of QEMU"));
+            goto error;
+        }
+        virBufferAsprintf(&buf, ",bootindex=%d", dev->info.bootIndex);
+    }
+
     if (qemuBuildDeviceAddressStr(&buf, &dev->info, caps) < 0)
         goto error;
 
@@ -3540,6 +3550,8 @@ qemuBuildUSBHostdevDevStr(virDomainHostdevDefPtr dev,
                           dev->source.subsys.u.usb.device);
     }
     virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
+    if (dev->info->bootIndex)
+        virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex);
 
     if (qemuBuildDeviceAddressStr(&buf, dev->info, caps) < 0)
         goto error;
@@ -6439,16 +6451,27 @@ qemuBuildCommandLine(virConnectPtr conn,
 
         if (hostdev->info->bootIndex) {
             if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-                hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
+                (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+                hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("booting from assigned devices is only"
-                                 " supported for PCI devices"));
-                goto error;
-            } else if (!qemuCapsGet(caps, QEMU_CAPS_PCI_BOOTINDEX)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("booting from assigned PCI devices is not"
-                                 " supported with this version of qemu"));
+                                 " supported for PCI and USB devices"));
                 goto error;
+            } else {
+                if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+                    !qemuCapsGet(caps, QEMU_CAPS_PCI_BOOTINDEX)) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                   _("booting from assigned PCI devices is not"
+                                     " supported with this version of qemu"));
+                    goto error;
+                }
+                if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
+                    !qemuCapsGet(caps, QEMU_CAPS_USB_HOST_BOOTINDEX)) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                   _("booting from assigned USB devices is not"
+                                     " supported with this version of qemu"));
+                    goto error;
+                }
             }
         }
 
-- 
1.7.8.6




More information about the libvir-list mailing list