9c6c51
From b56deb73400af9518bdc86802b8ac8da0670d806 Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <b56deb73400af9518bdc86802b8ac8da0670d806@dist-git>
9c6c51
From: Laine Stump <laine@laine.org>
9c6c51
Date: Thu, 10 Jan 2019 09:44:45 -0500
9c6c51
Subject: [PATCH] conf: correct false boot order error during domain parse
9c6c51
9c6c51
virDomainDefCollectBootOrder() is called for every item on the list
9c6c51
for each type of device. One of the checks it makes is to gather the
9c6c51
order attributes from the <boot> element of all devices, and assure
9c6c51
that no two devices have been given the same order.
9c6c51
9c6c51
Since (internally to libvirt, *not* in the domain XML) an 
9c6c51
type='hostdev'> is on both the list of hostdev devices and the list of
9c6c51
network devices, it will be counted twice, and the code that checks
9c6c51
for multiple devices with the same boot order will give a false
9c6c51
positive.
9c6c51
9c6c51
To remedy this, we make sure to return early for hostdev devices that
9c6c51
have a parent.type != NONE.
9c6c51
9c6c51
This was introduced in commit 5b75a4, which was first in libvirt-4.4.0.
9c6c51
9c6c51
Resolves: https://bugzilla.redhat.com/1630393 (RHEL8)
9c6c51
Resolves: https://bugzilla.redhat.com/1601318 (RHEL7)
9c6c51
9c6c51
Change from upstream: upstream has eliminated QEMU_CAPS_BOOTINDEX and
9c6c51
QEMU_CAPS_PCI_BOOTINDEX so they're no longer necessary in test cases.
9c6c51
9c6c51
Signed-off-by: Laine Stump <laine@laine.org>
9c6c51
(cherry picked from commit 7ea7342996d74591e00bcbf14b1eb3995f77a199)
9c6c51
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
---
9c6c51
 src/conf/domain_conf.c                        |  8 ++++
9c6c51
 .../net-hostdev-bootorder.args                | 27 ++++++++++++
9c6c51
 .../net-hostdev-bootorder.xml                 | 36 ++++++++++++++++
9c6c51
 tests/qemuxml2argvtest.c                      |  3 ++
9c6c51
 .../net-hostdev-bootorder.xml                 | 42 +++++++++++++++++++
9c6c51
 tests/qemuxml2xmltest.c                       |  1 +
9c6c51
 6 files changed, 117 insertions(+)
9c6c51
 create mode 100644 tests/qemuxml2argvdata/net-hostdev-bootorder.args
9c6c51
 create mode 100644 tests/qemuxml2argvdata/net-hostdev-bootorder.xml
9c6c51
 create mode 100644 tests/qemuxml2xmloutdata/net-hostdev-bootorder.xml
9c6c51
9c6c51
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
9c6c51
index 660e1523fe..d431441f62 100644
9c6c51
--- a/src/conf/domain_conf.c
9c6c51
+++ b/src/conf/domain_conf.c
9c6c51
@@ -5076,6 +5076,14 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED,
9c6c51
     if (info->bootIndex == 0)
9c6c51
         return 0;
9c6c51
 
9c6c51
+    if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
9c6c51
+        dev->data.hostdev->parent.type != VIR_DOMAIN_DEVICE_NONE) {
9c6c51
+        /* This hostdev is a child of a higher level device
9c6c51
+         * (e.g. interface), and thus already being counted on the
9c6c51
+         * list for the other device type.
9c6c51
+         */
9c6c51
+        return 0;
9c6c51
+    }
9c6c51
     if (virAsprintf(&order, "%u", info->bootIndex) < 0)
9c6c51
         goto cleanup;
9c6c51
 
9c6c51
diff --git a/tests/qemuxml2argvdata/net-hostdev-bootorder.args b/tests/qemuxml2argvdata/net-hostdev-bootorder.args
9c6c51
new file mode 100644
9c6c51
index 0000000000..e632d9b195
9c6c51
--- /dev/null
9c6c51
+++ b/tests/qemuxml2argvdata/net-hostdev-bootorder.args
9c6c51
@@ -0,0 +1,27 @@
9c6c51
+LC_ALL=C \
9c6c51
+PATH=/bin \
9c6c51
+HOME=/home/test \
9c6c51
+USER=test \
9c6c51
+LOGNAME=test \
9c6c51
+QEMU_AUDIO_DRV=none \
9c6c51
+/usr/bin/qemu-system-i686 \
9c6c51
+-name QEMUGuest1 \
9c6c51
+-S \
9c6c51
+-machine pc,accel=tcg,usb=off,dump-guest-core=off \
9c6c51
+-m 214 \
9c6c51
+-smp 1,sockets=1,cores=1,threads=1 \
9c6c51
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
9c6c51
+-display none \
9c6c51
+-no-user-config \
9c6c51
+-nodefaults \
9c6c51
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
9c6c51
+server,nowait \
9c6c51
+-mon chardev=charmonitor,id=monitor,mode=control \
9c6c51
+-rtc base=utc \
9c6c51
+-no-shutdown \
9c6c51
+-no-acpi \
9c6c51
+-usb \
9c6c51
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
9c6c51
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,\
9c6c51
+bootindex=2 \
9c6c51
+-device pci-assign,host=03:07.1,id=hostdev0,bootindex=1,bus=pci.0,addr=0x3
9c6c51
diff --git a/tests/qemuxml2argvdata/net-hostdev-bootorder.xml b/tests/qemuxml2argvdata/net-hostdev-bootorder.xml
9c6c51
new file mode 100644
9c6c51
index 0000000000..cd9f32b2f3
9c6c51
--- /dev/null
9c6c51
+++ b/tests/qemuxml2argvdata/net-hostdev-bootorder.xml
9c6c51
@@ -0,0 +1,36 @@
9c6c51
+<domain type='qemu'>
9c6c51
+  <name>QEMUGuest1</name>
9c6c51
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
9c6c51
+  <memory unit='KiB'>219136</memory>
9c6c51
+  <currentMemory unit='KiB'>219136</currentMemory>
9c6c51
+  <vcpu placement='static'>1</vcpu>
9c6c51
+  <os>
9c6c51
+    <type arch='i686' machine='pc'>hvm</type>
9c6c51
+  </os>
9c6c51
+  <clock offset='utc'/>
9c6c51
+  <on_poweroff>destroy</on_poweroff>
9c6c51
+  <on_reboot>restart</on_reboot>
9c6c51
+  <on_crash>destroy</on_crash>
9c6c51
+  <devices>
9c6c51
+    <emulator>/usr/bin/qemu-system-i686</emulator>
9c6c51
+    <disk type='block' device='disk'>
9c6c51
+      <source dev='/dev/HostVG/QEMUGuest1'/>
9c6c51
+      <target dev='hda' bus='ide'/>
9c6c51
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
9c6c51
+      <boot order='2'/>
9c6c51
+    </disk>
9c6c51
+    <controller type='usb' index='0'/>
9c6c51
+    <controller type='ide' index='0'/>
9c6c51
+    <controller type='pci' index='0' model='pci-root'/>
9c6c51
+    <interface type='hostdev' managed='yes'>
9c6c51
+      <mac address='00:11:22:33:44:55'/>
9c6c51
+      <source>
9c6c51
+        <address type='pci' domain='0x0000' bus='0x03' slot='0x07' function='0x1'/>
9c6c51
+      </source>
9c6c51
+      <boot order='1'/>
9c6c51
+    </interface>
9c6c51
+    <input type='mouse' bus='ps2'/>
9c6c51
+    <input type='keyboard' bus='ps2'/>
9c6c51
+    <memballoon model='none'/>
9c6c51
+  </devices>
9c6c51
+</domain>
9c6c51
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
9c6c51
index bd4aa1266d..690a39054e 100644
9c6c51
--- a/tests/qemuxml2argvtest.c
9c6c51
+++ b/tests/qemuxml2argvtest.c
9c6c51
@@ -1324,6 +1324,9 @@ mymain(void)
9c6c51
     DO_TEST("net-mcast", NONE);
9c6c51
     DO_TEST("net-udp", NONE);
9c6c51
     DO_TEST("net-hostdev", NONE);
9c6c51
+    DO_TEST("net-hostdev-bootorder",
9c6c51
+            QEMU_CAPS_BOOTINDEX,
9c6c51
+            QEMU_CAPS_PCI_BOOTINDEX);
9c6c51
     DO_TEST("net-hostdev-multidomain", NONE);
9c6c51
     DO_TEST("net-hostdev-vfio",
9c6c51
             QEMU_CAPS_DEVICE_VFIO_PCI);
9c6c51
diff --git a/tests/qemuxml2xmloutdata/net-hostdev-bootorder.xml b/tests/qemuxml2xmloutdata/net-hostdev-bootorder.xml
9c6c51
new file mode 100644
9c6c51
index 0000000000..d9ecf40cf0
9c6c51
--- /dev/null
9c6c51
+++ b/tests/qemuxml2xmloutdata/net-hostdev-bootorder.xml
9c6c51
@@ -0,0 +1,42 @@
9c6c51
+<domain type='qemu'>
9c6c51
+  <name>QEMUGuest1</name>
9c6c51
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
9c6c51
+  <memory unit='KiB'>219136</memory>
9c6c51
+  <currentMemory unit='KiB'>219136</currentMemory>
9c6c51
+  <vcpu placement='static'>1</vcpu>
9c6c51
+  <os>
9c6c51
+    <type arch='i686' machine='pc'>hvm</type>
9c6c51
+  </os>
9c6c51
+  <clock offset='utc'/>
9c6c51
+  <on_poweroff>destroy</on_poweroff>
9c6c51
+  <on_reboot>restart</on_reboot>
9c6c51
+  <on_crash>destroy</on_crash>
9c6c51
+  <devices>
9c6c51
+    <emulator>/usr/bin/qemu-system-i686</emulator>
9c6c51
+    <disk type='block' device='disk'>
9c6c51
+      <driver name='qemu' type='raw'/>
9c6c51
+      <source dev='/dev/HostVG/QEMUGuest1'/>
9c6c51
+      <target dev='hda' bus='ide'/>
9c6c51
+      <boot order='2'/>
9c6c51
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
9c6c51
+    </disk>
9c6c51
+    <controller type='usb' index='0'>
9c6c51
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
9c6c51
+    </controller>
9c6c51
+    <controller type='ide' index='0'>
9c6c51
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
9c6c51
+    </controller>
9c6c51
+    <controller type='pci' index='0' model='pci-root'/>
9c6c51
+    <interface type='hostdev' managed='yes'>
9c6c51
+      <mac address='00:11:22:33:44:55'/>
9c6c51
+      <source>
9c6c51
+        <address type='pci' domain='0x0000' bus='0x03' slot='0x07' function='0x1'/>
9c6c51
+      </source>
9c6c51
+      <boot order='1'/>
9c6c51
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
9c6c51
+    </interface>
9c6c51
+    <input type='mouse' bus='ps2'/>
9c6c51
+    <input type='keyboard' bus='ps2'/>
9c6c51
+    <memballoon model='none'/>
9c6c51
+  </devices>
9c6c51
+</domain>
9c6c51
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
9c6c51
index db088fff6b..dbac863239 100644
9c6c51
--- a/tests/qemuxml2xmltest.c
9c6c51
+++ b/tests/qemuxml2xmltest.c
9c6c51
@@ -454,6 +454,7 @@ mymain(void)
9c6c51
     DO_TEST("net-virtio-network-portgroup", NONE);
9c6c51
     DO_TEST("net-virtio-rxtxqueuesize", NONE);
9c6c51
     DO_TEST("net-hostdev", NONE);
9c6c51
+    DO_TEST("net-hostdev-bootorder", NONE);
9c6c51
     DO_TEST("net-hostdev-vfio", NONE);
9c6c51
     DO_TEST("net-midonet", NONE);
9c6c51
     DO_TEST("net-openvswitch", NONE);
9c6c51
-- 
9c6c51
2.20.1
9c6c51