提交 3d21545f 编写于 作者: D Daniel Henrique Barboza 提交者: Cole Robinson

qemu: command: move qemuBuildHostdevCommandLine caps validation to qemu_domain

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.
Reviewed-by: NCole Robinson <crobinso@redhat.com>
Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
上级 8ed79ecc
...@@ -5364,17 +5364,6 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, ...@@ -5364,17 +5364,6 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
/* PCI */ /* PCI */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) { 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; unsigned int bootIndex = hostdev->info->bootIndex;
/* bootNet will be non-0 if boot order was set and no other /* bootNet will be non-0 if boot order was set and no other
...@@ -5457,29 +5446,8 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, ...@@ -5457,29 +5446,8 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
switch ((virMediatedDeviceModelType) mdevsrc->model) { switch ((virMediatedDeviceModelType) mdevsrc->model) {
case VIR_MDEV_MODEL_TYPE_VFIO_PCI: 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: 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: 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; break;
case VIR_MDEV_MODEL_TYPE_LAST: case VIR_MDEV_MODEL_TYPE_LAST:
default: default:
......
...@@ -6109,6 +6109,13 @@ qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevDef *hostdev, ...@@ -6109,6 +6109,13 @@ qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevDef *hostdev,
{ {
const virDomainHostdevSubsysMediatedDev *dev; 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 */ /* VFIO-PCI does not support boot */
if (hostdev->info->bootIndex) { if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
...@@ -6152,11 +6159,19 @@ qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevDef *hostdev, ...@@ -6152,11 +6159,19 @@ qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevDef *hostdev,
static int static int
qemuDomainMdevDefVFIOAPValidate(const virDomainHostdevDef *hostdev, qemuDomainMdevDefVFIOAPValidate(const virDomainHostdevDef *hostdev,
const virDomainDef *def) const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{ {
size_t i; size_t i;
bool vfioap_found = false; 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 */ /* VFIO-AP does not support boot */
if (hostdev->info->bootIndex) { if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
...@@ -6198,8 +6213,14 @@ qemuDomainMdevDefValidate(const virDomainHostdevDef *hostdev, ...@@ -6198,8 +6213,14 @@ qemuDomainMdevDefValidate(const virDomainHostdevDef *hostdev,
case VIR_MDEV_MODEL_TYPE_VFIO_PCI: case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
return qemuDomainMdevDefVFIOPCIValidate(hostdev, def, qemuCaps); return qemuDomainMdevDefVFIOPCIValidate(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_AP: case VIR_MDEV_MODEL_TYPE_VFIO_AP:
return qemuDomainMdevDefVFIOAPValidate(hostdev, def); return qemuDomainMdevDefVFIOAPValidate(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_CCW: 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; break;
case VIR_MDEV_MODEL_TYPE_LAST: case VIR_MDEV_MODEL_TYPE_LAST:
default: default:
...@@ -6217,6 +6238,8 @@ qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev, ...@@ -6217,6 +6238,8 @@ qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev,
const virDomainDef *def, const virDomainDef *def,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
int backend;
/* forbid capabilities mode hostdev in this kind of hypervisor */ /* forbid capabilities mode hostdev in this kind of hypervisor */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
...@@ -6229,9 +6252,22 @@ qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev, ...@@ -6229,9 +6252,22 @@ qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev,
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
break; 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: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
if (hostdev->info->bootIndex) { if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
......
...@@ -106,6 +106,18 @@ mymain(void) ...@@ -106,6 +106,18 @@ mymain(void)
DO_TEST("pc-kvm", 0); DO_TEST("pc-kvm", 0);
DO_TEST("pc-tcg", 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-hardlimit", 2147483648);
DO_TEST("pc-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED); DO_TEST("pc-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
DO_TEST("pc-hostdev", 2147483648); DO_TEST("pc-hostdev", 2147483648);
...@@ -116,10 +128,6 @@ mymain(void) ...@@ -116,10 +128,6 @@ mymain(void)
DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED); DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
qemuTestSetHostArch(&driver, VIR_ARCH_PPC64); qemuTestSetHostArch(&driver, VIR_ARCH_PPC64);
if (!(qemuCaps = virQEMUCapsNew())) {
ret = -1;
goto cleanup;
}
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE); virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, qemuCaps) < 0) { if (qemuTestCapsCacheInsert(driver.qemuCapsCache, qemuCaps) < 0) {
......
...@@ -1638,7 +1638,7 @@ mymain(void) ...@@ -1638,7 +1638,7 @@ mymain(void)
QEMU_CAPS_DEVICE_VFIO_CCW); QEMU_CAPS_DEVICE_VFIO_CCW);
DO_TEST_CAPS_ARCH_LATEST("hostdev-subsys-mdev-vfio-ccw-boot", DO_TEST_CAPS_ARCH_LATEST("hostdev-subsys-mdev-vfio-ccw-boot",
"s390x"); "s390x");
DO_TEST_FAILURE("hostdev-subsys-mdev-vfio-ccw", DO_TEST_PARSE_ERROR("hostdev-subsys-mdev-vfio-ccw",
QEMU_CAPS_CCW, QEMU_CAPS_CCW,
QEMU_CAPS_CCW_CSSID_UNRESTRICTED); QEMU_CAPS_CCW_CSSID_UNRESTRICTED);
DO_TEST_PARSE_ERROR("hostdev-subsys-mdev-vfio-ccw-duplicate-address", DO_TEST_PARSE_ERROR("hostdev-subsys-mdev-vfio-ccw-duplicate-address",
......
...@@ -405,7 +405,7 @@ mymain(void) ...@@ -405,7 +405,7 @@ mymain(void)
DO_TEST("net-virtio-rxtxqueuesize", NONE); DO_TEST("net-virtio-rxtxqueuesize", NONE);
DO_TEST("net-hostdev", NONE); DO_TEST("net-hostdev", NONE);
DO_TEST("net-hostdev-bootorder", 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-midonet", NONE);
DO_TEST("net-openvswitch", NONE); DO_TEST("net-openvswitch", NONE);
DO_TEST("sound", NONE); DO_TEST("sound", NONE);
...@@ -432,9 +432,10 @@ mymain(void) ...@@ -432,9 +432,10 @@ mymain(void)
DO_TEST("hostdev-usb-address", NONE); DO_TEST("hostdev-usb-address", NONE);
DO_TEST("hostdev-pci-address", NONE); DO_TEST("hostdev-pci-address", NONE);
DO_TEST("hostdev-pci-multifunction", NONE); DO_TEST("hostdev-pci-multifunction", QEMU_CAPS_DEVICE_VFIO_PCI);
DO_TEST("hostdev-vfio", NONE); DO_TEST("hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI);
DO_TEST("hostdev-vfio-zpci", DO_TEST("hostdev-vfio-zpci",
QEMU_CAPS_DEVICE_VFIO_PCI,
QEMU_CAPS_DEVICE_ZPCI, QEMU_CAPS_DEVICE_ZPCI,
QEMU_CAPS_CCW); QEMU_CAPS_CCW);
DO_TEST("hostdev-vfio-zpci-multidomain-many", DO_TEST("hostdev-vfio-zpci-multidomain-many",
...@@ -448,10 +449,11 @@ mymain(void) ...@@ -448,10 +449,11 @@ mymain(void)
QEMU_CAPS_DEVICE_VFIO_PCI, QEMU_CAPS_DEVICE_VFIO_PCI,
QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_DEVICE_PCI_BRIDGE,
QEMU_CAPS_DEVICE_ZPCI); 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", DO_TEST("hostdev-mdev-display",
QEMU_CAPS_DEVICE_QXL, 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", NONE);
DO_TEST("pci-rom-disabled", NONE); DO_TEST("pci-rom-disabled", NONE);
DO_TEST("pci-rom-disabled-invalid", NONE); DO_TEST("pci-rom-disabled-invalid", NONE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册