render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
6ae9ed
From 986f039eddce59d25fb4060e3f12d2960c6ba100 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <986f039eddce59d25fb4060e3f12d2960c6ba100@dist-git>
6ae9ed
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
6ae9ed
Date: Thu, 21 Jul 2016 15:57:48 +0200
6ae9ed
Subject: [PATCH] Allow omitting USB port
6ae9ed
MIME-Version: 1.0
6ae9ed
Content-Type: text/plain; charset=UTF-8
6ae9ed
Content-Transfer-Encoding: 8bit
6ae9ed
6ae9ed
We were requiring a USB port path in the schema, but not enforcing it.
6ae9ed
Omitting the USB port would lead to libvirt formatting it as (null).
6ae9ed
Such domain cannot be started and will disappear after libvirtd restart
6ae9ed
(since it cannot parse back the XML).
6ae9ed
6ae9ed
Only format the port if it has been specified and mark it as optional
6ae9ed
in the XML schema.
6ae9ed
6ae9ed
(cherry picked from commit 4f903643186d0a59c4590fc8a6e8d9493c4d3d6b)
6ae9ed
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1215968
6ae9ed
6ae9ed
Conflicts:
6ae9ed
  downstream does not assume QEMU_CAPS_SMP_TOPOLOGY
6ae9ed
---
6ae9ed
 docs/schemas/domaincommon.rng                      |  8 +++--
6ae9ed
 src/conf/domain_conf.c                             |  5 ++-
6ae9ed
 src/qemu/qemu_command.c                            |  3 +-
6ae9ed
 .../qemuxml2argv-usb-port-missing.args             | 26 ++++++++++++++++
6ae9ed
 .../qemuxml2argv-usb-port-missing.xml              | 25 +++++++++++++++
6ae9ed
 tests/qemuxml2argvtest.c                           |  3 ++
6ae9ed
 .../qemuxml2xmlout-usb-port-missing.xml            | 36 ++++++++++++++++++++++
6ae9ed
 tests/qemuxml2xmltest.c                            |  1 +
6ae9ed
 8 files changed, 100 insertions(+), 7 deletions(-)
6ae9ed
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args
6ae9ed
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml
6ae9ed
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml
6ae9ed
6ae9ed
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
6ae9ed
index 563cb3c..0876daa 100644
6ae9ed
--- a/docs/schemas/domaincommon.rng
6ae9ed
+++ b/docs/schemas/domaincommon.rng
6ae9ed
@@ -4055,9 +4055,11 @@
6ae9ed
     <attribute name="bus">
6ae9ed
       <ref name="usbAddr"/>
6ae9ed
     </attribute>
6ae9ed
-    <attribute name="port">
6ae9ed
-      <ref name="usbPort"/>
6ae9ed
-    </attribute>
6ae9ed
+    <optional>
6ae9ed
+      <attribute name="port">
6ae9ed
+        <ref name="usbPort"/>
6ae9ed
+      </attribute>
6ae9ed
+    </optional>
6ae9ed
   </define>
6ae9ed
   <define name="spaprvioaddress">
6ae9ed
     <optional>
6ae9ed
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
6ae9ed
index e6dc23d..0bd8a30 100644
6ae9ed
--- a/src/conf/domain_conf.c
6ae9ed
+++ b/src/conf/domain_conf.c
6ae9ed
@@ -4859,9 +4859,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
6ae9ed
         break;
6ae9ed
 
6ae9ed
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
6ae9ed
-        virBufferAsprintf(buf, " bus='%d' port='%s'",
6ae9ed
-                          info->addr.usb.bus,
6ae9ed
-                          info->addr.usb.port);
6ae9ed
+        virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
6ae9ed
+        virBufferEscapeString(buf, " port='%s'", info->addr.usb.port);
6ae9ed
         break;
6ae9ed
 
6ae9ed
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
6ae9ed
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
6ae9ed
index 49412c0..af6146f 100644
6ae9ed
--- a/src/qemu/qemu_command.c
6ae9ed
+++ b/src/qemu/qemu_command.c
6ae9ed
@@ -375,7 +375,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
6ae9ed
                                                        VIR_DOMAIN_CONTROLLER_TYPE_USB,
6ae9ed
                                                        info->addr.usb.bus)))
6ae9ed
             goto cleanup;
6ae9ed
-        virBufferAsprintf(buf, ",bus=%s.0,port=%s", contAlias, info->addr.usb.port);
6ae9ed
+        virBufferAsprintf(buf, ",bus=%s.0", contAlias);
6ae9ed
+        virBufferEscapeString(buf, ",port=%s", info->addr.usb.port);
6ae9ed
     } else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) {
6ae9ed
         if (info->addr.spaprvio.has_reg)
6ae9ed
             virBufferAsprintf(buf, ",reg=0x%llx", info->addr.spaprvio.reg);
6ae9ed
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args
6ae9ed
new file mode 100644
6ae9ed
index 0000000..d43c58d
6ae9ed
--- /dev/null
6ae9ed
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args
6ae9ed
@@ -0,0 +1,26 @@
6ae9ed
+LC_ALL=C \
6ae9ed
+PATH=/bin \
6ae9ed
+HOME=/home/test \
6ae9ed
+USER=test \
6ae9ed
+LOGNAME=test \
6ae9ed
+QEMU_AUDIO_DRV=none \
6ae9ed
+/usr/bin/qemu \
6ae9ed
+-name QEMUGuest1 \
6ae9ed
+-S \
6ae9ed
+-M pc \
6ae9ed
+-m 214 \
6ae9ed
+-smp 1 \
6ae9ed
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
6ae9ed
+-nographic \
6ae9ed
+-nodefconfig \
6ae9ed
+-nodefaults \
6ae9ed
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
6ae9ed
+server,nowait \
6ae9ed
+-mon chardev=charmonitor,id=monitor,mode=readline \
6ae9ed
+-no-acpi \
6ae9ed
+-boot c \
6ae9ed
+-usb \
6ae9ed
+-device usb-hub,id=hub0,bus=usb.0 \
6ae9ed
+-device usb-hub,id=hub1,bus=usb.0 \
6ae9ed
+-device usb-mouse,id=input0,bus=usb.0 \
6ae9ed
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
6ae9ed
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml
6ae9ed
new file mode 100644
6ae9ed
index 0000000..593fcd1
6ae9ed
--- /dev/null
6ae9ed
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml
6ae9ed
@@ -0,0 +1,25 @@
6ae9ed
+<domain type='qemu'>
6ae9ed
+  <name>QEMUGuest1</name>
6ae9ed
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
6ae9ed
+  <memory unit='KiB'>219136</memory>
6ae9ed
+  <currentMemory unit='KiB'>219136</currentMemory>
6ae9ed
+  <vcpu placement='static'>1</vcpu>
6ae9ed
+  <os>
6ae9ed
+    <type arch='i686' machine='pc'>hvm</type>
6ae9ed
+    <boot dev='hd'/>
6ae9ed
+  </os>
6ae9ed
+  <devices>
6ae9ed
+    <emulator>/usr/bin/qemu</emulator>
6ae9ed
+    <controller type='usb' index='0'/>
6ae9ed
+    <memballoon model='virtio'/>
6ae9ed
+    <input type='mouse' bus='usb'>
6ae9ed
+      <address type='usb' bus='0'/>
6ae9ed
+    </input>
6ae9ed
+    <hub type='usb'>
6ae9ed
+      <address type='usb' bus='0'/>
6ae9ed
+    </hub>
6ae9ed
+    <hub type='usb'>
6ae9ed
+      <address type='usb' bus='0'/>
6ae9ed
+    </hub>
6ae9ed
+  </devices>
6ae9ed
+</domain>
6ae9ed
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
6ae9ed
index a73db5e..4389e24 100644
6ae9ed
--- a/tests/qemuxml2argvtest.c
6ae9ed
+++ b/tests/qemuxml2argvtest.c
6ae9ed
@@ -1159,6 +1159,9 @@ mymain(void)
6ae9ed
     DO_TEST("usb-hub",
6ae9ed
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
6ae9ed
             QEMU_CAPS_NODEFCONFIG);
6ae9ed
+    DO_TEST("usb-port-missing",
6ae9ed
+            QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
6ae9ed
+            QEMU_CAPS_NODEFCONFIG);
6ae9ed
     DO_TEST("usb-ports",
6ae9ed
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
6ae9ed
             QEMU_CAPS_NODEFCONFIG);
6ae9ed
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml
6ae9ed
new file mode 100644
6ae9ed
index 0000000..2e29cbd
6ae9ed
--- /dev/null
6ae9ed
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml
6ae9ed
@@ -0,0 +1,36 @@
6ae9ed
+<domain type='qemu'>
6ae9ed
+  <name>QEMUGuest1</name>
6ae9ed
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
6ae9ed
+  <memory unit='KiB'>219136</memory>
6ae9ed
+  <currentMemory unit='KiB'>219136</currentMemory>
6ae9ed
+  <vcpu placement='static'>1</vcpu>
6ae9ed
+  <os>
6ae9ed
+    <type arch='i686' machine='pc'>hvm</type>
6ae9ed
+    <boot dev='hd'/>
6ae9ed
+  </os>
6ae9ed
+  <clock offset='utc'/>
6ae9ed
+  <on_poweroff>destroy</on_poweroff>
6ae9ed
+  <on_reboot>restart</on_reboot>
6ae9ed
+  <on_crash>destroy</on_crash>
6ae9ed
+  <devices>
6ae9ed
+    <emulator>/usr/bin/qemu</emulator>
6ae9ed
+    <controller type='usb' index='0'>
6ae9ed
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
6ae9ed
+    </controller>
6ae9ed
+    <controller type='pci' index='0' model='pci-root'/>
6ae9ed
+    <input type='mouse' bus='usb'>
6ae9ed
+      <address type='usb' bus='0'/>
6ae9ed
+    </input>
6ae9ed
+    <input type='mouse' bus='ps2'/>
6ae9ed
+    <input type='keyboard' bus='ps2'/>
6ae9ed
+    <hub type='usb'>
6ae9ed
+      <address type='usb' bus='0'/>
6ae9ed
+    </hub>
6ae9ed
+    <hub type='usb'>
6ae9ed
+      <address type='usb' bus='0'/>
6ae9ed
+    </hub>
6ae9ed
+    <memballoon model='virtio'>
6ae9ed
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
6ae9ed
+    </memballoon>
6ae9ed
+  </devices>
6ae9ed
+</domain>
6ae9ed
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
6ae9ed
index 7db9cb7..c6ef28c 100644
6ae9ed
--- a/tests/qemuxml2xmltest.c
6ae9ed
+++ b/tests/qemuxml2xmltest.c
6ae9ed
@@ -535,6 +535,7 @@ mymain(void)
6ae9ed
     DO_TEST("interface-server");
6ae9ed
     DO_TEST("virtio-lun");
6ae9ed
 
6ae9ed
+    DO_TEST("usb-port-missing");
6ae9ed
     DO_TEST("usb-redir");
6ae9ed
     DO_TEST("usb-redir-filter");
6ae9ed
     DO_TEST("usb-redir-filter-version");
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed