From 83d7dadc48f3f619a7096242cdf74f3ba18911b3 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Mon, 9 Dec 2019 20:15:24 -0300 Subject: [PATCH] qemu: command: move pcihole64 validation to qemu_domain.c Move the pcihole64 validation being done by qemuBuildGlobalControllerCommandLine() to the existing function qemuDomainDeviceDefValidateControllerPCI(), which provides domain define time validation. The existing pcihole64 validations in qemu_domain.c were replaced by the ones moved from qemu_command.c. The reason is that they are more specific, allowing VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT and VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT to have distinct validation, with exclusive QEMU caps and machine types. Tests were adapted to consider the new caps being needed in this earlier stage. Reviewed-by: Cole Robinson Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_command.c | 24 ++---------------------- src/qemu/qemu_domain.c | 37 +++++++++++++++++++++++++++++++------ tests/qemuxml2argvtest.c | 2 +- tests/qemuxml2xmltest.c | 6 +++--- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c60953c68e..e547474f9a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6435,8 +6435,7 @@ qemuBuildIOMMUCommandLine(virCommandPtr cmd, static int qemuBuildGlobalControllerCommandLine(virCommandPtr cmd, - const virDomainDef *def, - virQEMUCapsPtr qemuCaps) + const virDomainDef *def) { size_t i; @@ -6445,20 +6444,14 @@ qemuBuildGlobalControllerCommandLine(virCommandPtr cmd, if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI && cont->opts.pciopts.pcihole64) { const char *hoststr = NULL; - bool cap = false; - bool machine = false; switch (cont->model) { case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT: hoststr = "i440FX-pcihost"; - cap = virQEMUCapsGet(qemuCaps, QEMU_CAPS_I440FX_PCI_HOLE64_SIZE); - machine = qemuDomainIsI440FX(def); break; case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT: hoststr = "q35-pcihost"; - cap = virQEMUCapsGet(qemuCaps, QEMU_CAPS_Q35_PCI_HOLE64_SIZE); - machine = qemuDomainIsQ35(def); break; default: @@ -6468,19 +6461,6 @@ qemuBuildGlobalControllerCommandLine(virCommandPtr cmd, return -1; } - if (!machine) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Setting the 64-bit PCI hole size is not " - "supported for machine '%s'"), def->os.machine); - return -1; - } - if (!cap) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("64-bit PCI hole size setting is not supported " - "with this QEMU binary")); - return -1; - } - virCommandAddArg(cmd, "-global"); virCommandAddArgFormat(cmd, "%s.pci-hole64-size=%luK", hoststr, cont->opts.pciopts.pcihole64size); @@ -10043,7 +10023,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, if (qemuBuildIOMMUCommandLine(cmd, def, qemuCaps) < 0) return NULL; - if (qemuBuildGlobalControllerCommandLine(cmd, def, qemuCaps) < 0) + if (qemuBuildGlobalControllerCommandLine(cmd, def) < 0) return NULL; if (qemuBuildControllersCommandLine(cmd, def, qemuCaps) < 0) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9840bee324..058c75d587 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7255,13 +7255,38 @@ qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *cont, /* pcihole64 */ switch ((virDomainControllerModelPCI) cont->model) { case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT: + if (pciopts->pcihole64 || pciopts->pcihole64size != 0) { + if (!qemuDomainIsI440FX(def)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Setting the 64-bit PCI hole size is not " + "supported for machine '%s'"), def->os.machine); + return -1; + } + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_I440FX_PCI_HOLE64_SIZE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("64-bit PCI hole size setting is not supported " + "with this QEMU binary")); + return -1; + } + } + break; + case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT: - /* The pcihole64 option only applies to x86 guests */ - if ((pciopts->pcihole64 || - pciopts->pcihole64size != 0) && - !ARCH_IS_X86(def->os.arch)) { - virReportControllerInvalidOption(cont, model, modelName, "pcihole64"); - return -1; + if (pciopts->pcihole64 || pciopts->pcihole64size != 0) { + if (!qemuDomainIsQ35(def)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Setting the 64-bit PCI hole size is not " + "supported for machine '%s'"), def->os.machine); + return -1; + } + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_Q35_PCI_HOLE64_SIZE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("64-bit PCI hole size setting is not supported " + "with this QEMU binary")); + return -1; + } } break; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 0db4160a77..4227737bc7 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2526,7 +2526,7 @@ mymain(void) QEMU_CAPS_KVM, QEMU_CAPS_VIRTIO_SCSI); DO_TEST("pcihole64", QEMU_CAPS_I440FX_PCI_HOLE64_SIZE); - DO_TEST_FAILURE("pcihole64-none", NONE); + DO_TEST_PARSE_ERROR("pcihole64-none", NONE); DO_TEST("pcihole64-q35", QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_ICH9_AHCI, diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index ca993c35b2..d1eee0f00f 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -991,9 +991,9 @@ mymain(void) DO_TEST("s390-serial-console", QEMU_CAPS_CCW, QEMU_CAPS_VIRTIO_S390); - DO_TEST("pcihole64", NONE); - DO_TEST("pcihole64-gib", NONE); - DO_TEST("pcihole64-none", NONE); + DO_TEST("pcihole64", QEMU_CAPS_I440FX_PCI_HOLE64_SIZE); + DO_TEST("pcihole64-gib", QEMU_CAPS_I440FX_PCI_HOLE64_SIZE); + DO_TEST("pcihole64-none", QEMU_CAPS_I440FX_PCI_HOLE64_SIZE); DO_TEST("pcihole64-q35", QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_ICH9_AHCI, -- GitLab