[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 27/34] Convert USB hostdevices over to -device



The old syntax was

   -usbdevice host:PRODUCT:VENDOR

Or

   -usbdevice host:BUS.DEV

The new syntax is

   -device usb-host,product=PRODUCT,vendor=VENDOR

Or

   -device usb-host,hostbus=BUS,hostaddr=DEV
---
 src/qemu/qemu_conf.c                               |   32 ++++++++++++++-----
 .../qemuxml2argv-hostdev-usb-address-device.args   |    1 +
 .../qemuxml2argv-hostdev-usb-address-device.xml    |   27 ++++++++++++++++
 tests/qemuxml2argvtest.c                           |    1 +
 4 files changed, 52 insertions(+), 9 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.xml

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 53866eb..1ea61a9 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -3510,22 +3510,36 @@ int qemudBuildCommandLine(virConnectPtr conn,
         /* USB */
         if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
-            if(hostdev->source.subsys.u.usb.vendor) {
-                    ret = virAsprintf(&usbdev, "host:%.4x:%.4x",
-                               hostdev->source.subsys.u.usb.vendor,
-                               hostdev->source.subsys.u.usb.product);
 
+            if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
+                ADD_ARG_LIT("-device");
+                if (hostdev->source.subsys.u.usb.vendor) {
+                    ret = virAsprintf(&usbdev, "usb-host,vendor=%.4x,product=%.4x,id=%s",
+                                      hostdev->source.subsys.u.usb.vendor,
+                                      hostdev->source.subsys.u.usb.product,
+                                      hostdev->info.alias);
+                } else {
+                    ret = virAsprintf(&usbdev, "usb-host,hostbus=%.3d,hostaddr=%.3d,id=%s",
+                                      hostdev->source.subsys.u.usb.bus,
+                                      hostdev->source.subsys.u.usb.device,
+                                      hostdev->info.alias);
+                }
             } else {
+                ADD_ARG_LIT("-usbdevice");
+                if (hostdev->source.subsys.u.usb.vendor) {
+                    ret = virAsprintf(&usbdev, "host:%.4x:%.4x",
+                                      hostdev->source.subsys.u.usb.vendor,
+                                      hostdev->source.subsys.u.usb.product);
+                } else {
                     ret = virAsprintf(&usbdev, "host:%.3d.%.3d",
-                               hostdev->source.subsys.u.usb.bus,
-                               hostdev->source.subsys.u.usb.device);
+                                      hostdev->source.subsys.u.usb.bus,
+                                      hostdev->source.subsys.u.usb.device);
+                }
             }
             if (ret < 0)
                 goto error;
 
-            ADD_ARG_LIT("-usbdevice");
-            ADD_ARG_LIT(usbdev);
-            VIR_FREE(usbdev);
+            ADD_ARG(usbdev);
         }
 
         /* PCI */
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args
new file mode 100644
index 0000000..70f48c4
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -usb -device usb-host,hostbus=014,hostaddr=006,id=hostusb0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.xml
new file mode 100644
index 0000000..61bb2a2
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.xml
@@ -0,0 +1,27 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219200</memory>
+  <currentMemory>219200</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+    <hostdev mode='subsystem' type='usb' managed='no'>
+      <source>
+        <address bus='14' device='6'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 8c88a79..2042e2a 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -299,6 +299,7 @@ mymain(int argc, char **argv)
 
     DO_TEST("hostdev-usb-product", 0);
     DO_TEST("hostdev-usb-address", 0);
+    DO_TEST("hostdev-usb-address-device", QEMUD_CMD_FLAG_DEVICE);
     DO_TEST("hostdev-pci-address", QEMUD_CMD_FLAG_PCIDEVICE);
 
     DO_TEST_FULL("restore-v1", QEMUD_CMD_FLAG_MIGRATE_KVM_STDIO, "stdio");
-- 
1.6.5.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]