Move QEMU caps validation of qemuBuildHostdevCommandLine() to
qemuDomainDeviceDefValidateHostdev() and qemuDomainMdevDefValidate(),
allowing them to be validated at domain define time.
Tests were adapted to consider the new caps being needed in
this earlier stage.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_command.c | 32 ------------------------------
src/qemu/qemu_domain.c | 42 +++++++++++++++++++++++++++++++++++++---
tests/qemumemlocktest.c | 16 +++++++++++----
tests/qemuxml2argvtest.c | 6 +++---
tests/qemuxml2xmltest.c | 12 +++++++-----
5 files changed, 61 insertions(+), 47 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 58409a85d9..9431efa384 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5321,17 +5321,6 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
/* PCI */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
- int backend = subsys->u.pci.backend;
-
- if (backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("VFIO PCI device assignment is not "
- "supported by this version of qemu"));
- return -1;
- }
- }
-
unsigned int bootIndex = hostdev->info->bootIndex;
/* bootNet will be non-0 if boot order was set and no other
@@ -5414,29 +5403,8 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
switch ((virMediatedDeviceModelType) mdevsrc->model) {
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("VFIO PCI device assignment is not "
- "supported by this version of QEMU"));
- return -1;
- }
-
- break;
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_CCW)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("VFIO CCW device assignment is not "
- "supported by this version of QEMU"));
- return -1;
- }
- break;
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_AP)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("VFIO AP device assignment is not "
- "supported by this version of QEMU"));
- return -1;
- }
break;
case VIR_MDEV_MODEL_TYPE_LAST:
default:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2b97b5f1bd..b39942c49f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6042,6 +6042,13 @@ qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevDef
*hostdev,
{
const virDomainHostdevSubsysMediatedDev *dev;
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("VFIO PCI device assignment is not "
+ "supported by this version of QEMU"));
+ return -1;
+ }
+
/* VFIO-PCI does not support boot */
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -6085,11 +6092,19 @@ qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevDef
*hostdev,
static int
qemuDomainMdevDefVFIOAPValidate(const virDomainHostdevDef *hostdev,
- const virDomainDef *def)
+ const virDomainDef *def,
+ virQEMUCapsPtr qemuCaps)
{
size_t i;
bool vfioap_found = false;
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_AP)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("VFIO AP device assignment is not "
+ "supported by this version of QEMU"));
+ return -1;
+ }
+
/* VFIO-AP does not support boot */
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -6131,8 +6146,14 @@ qemuDomainMdevDefValidate(const virDomainHostdevDef *hostdev,
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
return qemuDomainMdevDefVFIOPCIValidate(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
- return qemuDomainMdevDefVFIOAPValidate(hostdev, def);
+ return qemuDomainMdevDefVFIOAPValidate(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_CCW)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("VFIO CCW device assignment is not "
+ "supported by this version of QEMU"));
+ return -1;
+ }
break;
case VIR_MDEV_MODEL_TYPE_LAST:
default:
@@ -6150,6 +6171,8 @@ qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef
*hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
+ int backend;
+
/* forbid capabilities mode hostdev in this kind of hypervisor */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -6162,9 +6185,22 @@ qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef
*hostdev,
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
- case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
break;
+
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
+ backend = hostdev->source.subsys.u.pci.backend;
+
+ if (backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("VFIO PCI device assignment is not "
+ "supported by this version of qemu"));
+ return -1;
+ }
+ }
+ break;
+
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
index 986dfb77bd..c70a426c16 100644
--- a/tests/qemumemlocktest.c
+++ b/tests/qemumemlocktest.c
@@ -106,6 +106,18 @@ mymain(void)
DO_TEST("pc-kvm", 0);
DO_TEST("pc-tcg", 0);
+ if (!(qemuCaps = virQEMUCapsNew())) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI);
+
+ if (qemuTestCapsCacheInsert(driver.qemuCapsCache, qemuCaps) < 0) {
+ ret = -1;
+ goto cleanup;
+ };
+
DO_TEST("pc-hardlimit", 2147483648);
DO_TEST("pc-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
DO_TEST("pc-hostdev", 2147483648);
@@ -116,10 +128,6 @@ mymain(void)
DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
qemuTestSetHostArch(&driver, VIR_ARCH_PPC64);
- if (!(qemuCaps = virQEMUCapsNew())) {
- ret = -1;
- goto cleanup;
- }
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, qemuCaps) < 0) {
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 3c081651cf..8a5524c3fb 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1638,9 +1638,9 @@ mymain(void)
QEMU_CAPS_DEVICE_VFIO_CCW);
DO_TEST_CAPS_ARCH_LATEST("hostdev-subsys-mdev-vfio-ccw-boot",
"s390x");
- DO_TEST_FAILURE("hostdev-subsys-mdev-vfio-ccw",
- QEMU_CAPS_CCW,
- QEMU_CAPS_CCW_CSSID_UNRESTRICTED);
+ DO_TEST_PARSE_ERROR("hostdev-subsys-mdev-vfio-ccw",
+ QEMU_CAPS_CCW,
+ QEMU_CAPS_CCW_CSSID_UNRESTRICTED);
DO_TEST_PARSE_ERROR("hostdev-subsys-mdev-vfio-ccw-duplicate-address",
QEMU_CAPS_CCW,
QEMU_CAPS_CCW_CSSID_UNRESTRICTED,
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 0145970774..bd505ff157 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -405,7 +405,7 @@ mymain(void)
DO_TEST("net-virtio-rxtxqueuesize", NONE);
DO_TEST("net-hostdev", NONE);
DO_TEST("net-hostdev-bootorder", NONE);
- DO_TEST("net-hostdev-vfio", NONE);
+ DO_TEST("net-hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI);
DO_TEST("net-midonet", NONE);
DO_TEST("net-openvswitch", NONE);
DO_TEST("sound", NONE);
@@ -437,9 +437,10 @@ mymain(void)
DO_TEST("hostdev-usb-address", NONE);
DO_TEST("hostdev-pci-address", NONE);
- DO_TEST("hostdev-pci-multifunction", NONE);
- DO_TEST("hostdev-vfio", NONE);
+ DO_TEST("hostdev-pci-multifunction", QEMU_CAPS_DEVICE_VFIO_PCI);
+ DO_TEST("hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI);
DO_TEST("hostdev-vfio-zpci",
+ QEMU_CAPS_DEVICE_VFIO_PCI,
QEMU_CAPS_DEVICE_ZPCI,
QEMU_CAPS_CCW);
DO_TEST("hostdev-vfio-zpci-multidomain-many",
@@ -453,10 +454,11 @@ mymain(void)
QEMU_CAPS_DEVICE_VFIO_PCI,
QEMU_CAPS_DEVICE_PCI_BRIDGE,
QEMU_CAPS_DEVICE_ZPCI);
- DO_TEST("hostdev-mdev-precreated", NONE);
+ DO_TEST("hostdev-mdev-precreated", QEMU_CAPS_DEVICE_VFIO_PCI);
DO_TEST("hostdev-mdev-display",
QEMU_CAPS_DEVICE_QXL,
- QEMU_CAPS_VFIO_PCI_DISPLAY);
+ QEMU_CAPS_VFIO_PCI_DISPLAY,
+ QEMU_CAPS_DEVICE_VFIO_PCI);
DO_TEST("pci-rom", NONE);
DO_TEST("pci-rom-disabled", NONE);
DO_TEST("pci-rom-disabled-invalid", NONE);
--
2.23.0