From 9aef6ea4b1d8a79e353bb34ab5559c698cad1eb1 Mon Sep 17 00:00:00 2001 Message-Id: <9aef6ea4b1d8a79e353bb34ab5559c698cad1eb1@dist-git> From: Yi Min Zhao Date: Mon, 8 Apr 2019 10:57:26 +0200 Subject: [PATCH] qemu: Add zPCI address definition check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should ensure that QEMU supports zPCI when a zPCI address is defined in XML and otherwise report an error. This patch introduces a generic validation function qemuDomainDeviceDefValidateAddress() which calls qemuDomainDeviceDefValidateZPCIAddress() if address type is PCI address. Signed-off-by: Yi Min Zhao Reviewed-by: Boris Fiuczynski Reviewed-by: Andrea Bolognani (cherry picked from commit e6565d54db3d52ae38b5934877be4d004c2d5f35) https://bugzilla.redhat.com/show_bug.cgi?id=1508149 Conflicts: * src/qemu/qemu_domain.c + context - missing 709f57c25be8 Signed-off-by: Andrea Bolognani Message-Id: <20190408085732.28684-10-abologna@redhat.com> Reviewed-by: Laine Stump Reviewed-by: Ján Tomko --- src/qemu/qemu_domain.c | 36 +++++++++++++++++++ .../hostdev-vfio-zpci-wrong-arch.xml | 34 ++++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ 3 files changed, 72 insertions(+) create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index da961f0de9..8604385aa2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5681,6 +5681,38 @@ qemuDomainDeviceDefValidateGraphics(const virDomainGraphicsDef *graphics, } +static int +qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info, + virQEMUCapsPtr qemuCaps) +{ + if (!virZPCIDeviceAddressIsEmpty(&info->addr.pci.zpci) && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", + _("This QEMU binary doesn't support zPCI")); + return -1; + } + + return 0; +} + + +static int +qemuDomainDeviceDefValidateAddress(const virDomainDeviceDef *dev, + virQEMUCapsPtr qemuCaps) +{ + virDomainDeviceInfoPtr info; + + if (!(info = virDomainDeviceGetInfo((virDomainDeviceDef *)dev))) + return 0; + + if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) + return qemuDomainDeviceDefValidateZPCIAddress(info, qemuCaps); + + return 0; +} + + static int qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, const virDomainDef *def, @@ -5694,6 +5726,9 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, def->emulator))) return -1; + if ((ret = qemuDomainDeviceDefValidateAddress(dev, qemuCaps)) < 0) + goto cleanup; + switch ((virDomainDeviceType)dev->type) { case VIR_DOMAIN_DEVICE_NET: ret = qemuDomainDeviceDefValidateNetwork(dev->data.net); @@ -5769,6 +5804,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, break; } + cleanup: virObjectUnref(qemuCaps); return ret; } diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml b/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml new file mode 100644 index 0000000000..bfb2f83a3b --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml @@ -0,0 +1,34 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9466-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + +
+ + + + + +
+ +
+ +
+ + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 2eb2505971..1066de8bc4 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1632,6 +1632,8 @@ mymain(void) DO_TEST_PARSE_ERROR("hostdev-mdev-display-missing-graphics", QEMU_CAPS_DEVICE_VFIO_PCI, QEMU_CAPS_VFIO_PCI_DISPLAY); + DO_TEST_PARSE_ERROR("hostdev-vfio-zpci-wrong-arch", + QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("hostdev-vfio-zpci", QEMU_CAPS_DEVICE_VFIO_PCI, QEMU_CAPS_DEVICE_ZPCI); -- 2.22.0