[libvirt PATCH 6/6] qemu: wire up command line support for ACPI index

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

 



This makes it possible to enable stable NIC device names in most modern
Linux distos.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                       |  2 +
 src/qemu/qemu_validate.c                      | 35 +++++++++++
 .../devices-acpi-index.x86_64-latest.args     | 57 +++++++++++++++++
 tests/qemuxml2argvdata/devices-acpi-index.xml | 62 +++++++++++++++++++
 tests/qemuxml2argvtest.c                      |  2 +
 5 files changed, 158 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/devices-acpi-index.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/devices-acpi-index.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index bf60289786..a57028e42a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -420,6 +420,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
         virBufferAsprintf(buf, ",addr=0x%x", info->addr.pci.slot);
         if (info->addr.pci.function != 0)
             virBufferAsprintf(buf, ".0x%x", info->addr.pci.function);
+        if (info->acpiIndex != 0)
+            virBufferAsprintf(buf, ",acpi-index=%u", info->acpiIndex);
     } break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 09778085a8..27afcab9aa 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1069,6 +1069,32 @@ qemuValidateDomainDefPanic(const virDomainDef *def,
 }
 
 
+static int
+qemuValidateDomainDeviceInfo(virDomainDefPtr def G_GNUC_UNUSED,
+                             virDomainDeviceDefPtr dev G_GNUC_UNUSED,
+                             virDomainDeviceInfoPtr info,
+                             void *opaque)
+{
+    virQEMUCapsPtr qemuCaps = opaque;
+
+    if (info->acpiIndex) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_ACPI_INDEX)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("ACPI index is not supported with this QEMU"));
+            return -1;
+        }
+
+        if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+            info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("ACPI index is only supported for PCI devices"));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
 int
 qemuValidateDomainDef(const virDomainDef *def,
                       void *opaque,
@@ -1235,6 +1261,15 @@ qemuValidateDomainDef(const virDomainDef *def,
         return -1;
     }
 
+    /* Explicitly discarding 'const' from 'def' is ok because
+     * we know our callback qemuValidateDomainDeviceInfo will
+     * not modify it
+     */
+    if (virDomainDeviceInfoIterate((virDomainDefPtr)def,
+                                   qemuValidateDomainDeviceInfo,
+                                   qemuCaps) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/tests/qemuxml2argvdata/devices-acpi-index.x86_64-latest.args b/tests/qemuxml2argvdata/devices-acpi-index.x86_64-latest.args
new file mode 100644
index 0000000000..07a8b0d189
--- /dev/null
+++ b/tests/qemuxml2argvdata/devices-acpi-index.x86_64-latest.args
@@ -0,0 +1,57 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-fdr-br \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-fdr-br/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-fdr-br/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-fdr-br/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=fdr-br,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw",\
+"file":"/tmp/lib/domain--1-fdr-br/master-key.aes"}' \
+-machine pc-i440fx-5.0,accel=tcg,usb=off,dump-guest-core=off,\
+memory-backend=pc.ram \
+-cpu qemu64 \
+-m 2048 \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":2147483648}' \
+-overcommit mem-lock=off \
+-smp 2,sockets=2,cores=1,threads=1 \
+-uuid 3ec6cbe1-b5a2-4515-b800-31a61855df41 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/test.img",\
+"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw",\
+"file":"libvirt-2-storage"}' \
+-device virtio-blk-pci,bus=pci.0,addr=0x3,acpi-index=1,drive=libvirt-2-format,\
+id=virtio-disk0,bootindex=1 \
+-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/test1.img",\
+"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\
+"file":"libvirt-1-storage"}' \
+-device virtio-blk-pci,bus=pci.0,addr=0x4,acpi-index=42,drive=libvirt-1-format,\
+id=virtio-disk1 \
+-netdev user,id=hostnet0 \
+-device virtio-net-pci,netdev=hostnet0,id=net0,mac=00:11:22:33:44:55,bus=pci.0,\
+addr=0x5,acpi-index=100 \
+-netdev user,id=hostnet1 \
+-device virtio-net-pci,netdev=hostnet1,id=net1,mac=00:11:22:33:44:55,bus=pci.0,\
+addr=0x7,acpi-index=200 \
+-netdev user,id=hostnet2 \
+-device virtio-net-pci,netdev=hostnet2,id=net2,mac=00:11:22:33:44:55,bus=pci.0,\
+addr=0x8,acpi-index=300 \
+-audiodev id=audio1,driver=none \
+-device cirrus-vga,id=video0,bus=pci.0,addr=0x2,acpi-index=1729 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/devices-acpi-index.xml b/tests/qemuxml2argvdata/devices-acpi-index.xml
new file mode 100644
index 0000000000..5d0176e7fe
--- /dev/null
+++ b/tests/qemuxml2argvdata/devices-acpi-index.xml
@@ -0,0 +1,62 @@
+<domain type='qemu'>
+  <name>fdr-br</name>
+  <uuid>3ec6cbe1-b5a2-4515-b800-31a61855df41</uuid>
+  <memory unit='KiB'>2097152</memory>
+  <currentMemory unit='KiB'>2097152</currentMemory>
+  <vcpu placement='static' cpuset='0-1'>2</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc-i440fx-5.0'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source file='/var/lib/libvirt/images/test.img'/>
+      <target dev='vda' bus='virtio'/>
+      <acpi index='1'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source file='/var/lib/libvirt/images/test1.img'/>
+      <target dev='vdb' bus='virtio'/>
+      <acpi index='42'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </disk>
+    <interface type='user'>
+      <mac address='00:11:22:33:44:55'/>
+      <acpi index='100'/>
+      <model type='virtio'/>
+    </interface>
+    <interface type='user'>
+      <mac address='00:11:22:33:44:55'/>
+      <acpi index='200'/>
+      <model type='virtio'/>
+    </interface>
+    <interface type='user'>
+      <mac address='00:11:22:33:44:55'/>
+      <acpi index='300'/>
+      <model type='virtio'/>
+    </interface>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <video>
+      <model type='cirrus' vram='16384' heads='1'/>
+      <acpi index='1729'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </video>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ea98f0e6a8..83dd6a7756 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -3611,6 +3611,8 @@ mymain(void)
     DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
     DO_TEST_CAPS_LATEST("virtio-9p-createmode");
 
+    DO_TEST_CAPS_LATEST("devices-acpi-index");
+
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(fakerootdir);
 
-- 
2.30.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux