]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Allow omitting USB port
authorJán Tomko <jtomko@redhat.com>
Fri, 1 Jul 2016 12:20:44 +0000 (14:20 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 18 Jul 2016 08:55:35 +0000 (10:55 +0200)
We were requiring a USB port path in the schema, but not enforcing it.
Omitting the USB port would lead to libvirt formatting it as (null).
Such domain cannot be started and will disappear after libvirtd restart
(since it cannot parse back the XML).

Only format the port if it has been specified and mark it as optional
in the XML schema.

docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c

index 348dbfe6b1f6ddb325259fdf65c9bb6f55618e18..741f2689f30f8c5714273cb03830c273ae6991d3 100644 (file)
     <attribute name="bus">
       <ref name="usbAddr"/>
     </attribute>
-    <attribute name="port">
-      <ref name="usbPort"/>
-    </attribute>
+    <optional>
+      <attribute name="port">
+        <ref name="usbPort"/>
+      </attribute>
+    </optional>
   </define>
   <define name="spaprvioaddress">
     <optional>
index 13a059e21ddad236944bb166b292d8c39bbc962b..44d98579413f8e89a4c69b854bfcaa078fa6045f 100644 (file)
@@ -4839,9 +4839,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
-        virBufferAsprintf(buf, " bus='%d' port='%s'",
-                          info->addr.usb.bus,
-                          info->addr.usb.port);
+        virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
+        virBufferEscapeString(buf, " port='%s'", info->addr.usb.port);
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
index fe4bb88f9fa63bb9d4eb16deda9fb39e5344d2c6..7a3ee8151497a39c58f2a1872b07b2e2124a20d8 100644 (file)
@@ -375,7 +375,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
                                                        VIR_DOMAIN_CONTROLLER_TYPE_USB,
                                                        info->addr.usb.bus)))
             goto cleanup;
-        virBufferAsprintf(buf, ",bus=%s.0,port=%s", contAlias, info->addr.usb.port);
+        virBufferAsprintf(buf, ",bus=%s.0", contAlias);
+        virBufferEscapeString(buf, ",port=%s", info->addr.usb.port);
     } else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) {
         if (info->addr.spaprvio.has_reg)
             virBufferAsprintf(buf, ",reg=0x%llx", info->addr.spaprvio.reg);
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args
new file mode 100644 (file)
index 0000000..3b9d9df
--- /dev/null
@@ -0,0 +1,26 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest1 \
+-S \
+-M pc \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefconfig \
+-nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
+server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=readline \
+-no-acpi \
+-boot c \
+-usb \
+-device usb-hub,id=hub0,bus=usb.0 \
+-device usb-hub,id=hub1,bus=usb.0 \
+-device usb-mouse,id=input0,bus=usb.0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml
new file mode 100644 (file)
index 0000000..593fcd1
--- /dev/null
@@ -0,0 +1,25 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <controller type='usb' index='0'/>
+    <memballoon model='virtio'/>
+    <input type='mouse' bus='usb'>
+      <address type='usb' bus='0'/>
+    </input>
+    <hub type='usb'>
+      <address type='usb' bus='0'/>
+    </hub>
+    <hub type='usb'>
+      <address type='usb' bus='0'/>
+    </hub>
+  </devices>
+</domain>
index e0d07e80a640f3299794bbb1d382a4f2c64bca80..8abc4b050b38aa8f3e7104da09e88ee4eb385b9b 100644 (file)
@@ -1163,6 +1163,9 @@ mymain(void)
     DO_TEST("usb-hub",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
             QEMU_CAPS_NODEFCONFIG);
+    DO_TEST("usb-port-missing",
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
+            QEMU_CAPS_NODEFCONFIG);
     DO_TEST("usb-ports",
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
             QEMU_CAPS_NODEFCONFIG);
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml
new file mode 100644 (file)
index 0000000..2e29cbd
--- /dev/null
@@ -0,0 +1,36 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>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>
+    <controller type='usb' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='usb'>
+      <address type='usb' bus='0'/>
+    </input>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <hub type='usb'>
+      <address type='usb' bus='0'/>
+    </hub>
+    <hub type='usb'>
+      <address type='usb' bus='0'/>
+    </hub>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
index 86408bf9fa62787166fb9ab9b0e2ec84416f9aa4..8a184d271fea4b2cd1c60560bdcde884ab05df43 100644 (file)
@@ -591,6 +591,7 @@ mymain(void)
     DO_TEST("interface-server");
     DO_TEST("virtio-lun");
 
+    DO_TEST("usb-port-missing");
     DO_TEST("usb-redir");
     DO_TEST("usb-redir-filter");
     DO_TEST("usb-redir-filter-version");