qemu: Introduce qemuDomainDeviceDefValidateIOMMU()
Device validation should not have to wait until command line generation time. Moving the code to a separate function also allows us to avoid some unnecessary repetition. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
b00f32c34d
commit
a7a78c273e
@ -6935,60 +6935,11 @@ qemuBuildIOMMUCommandLine(virCommandPtr cmd,
|
|||||||
if (!iommu)
|
if (!iommu)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (iommu->model) {
|
|
||||||
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
|
|
||||||
if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT &&
|
|
||||||
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_INTREMAP)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("iommu: interrupt remapping is not supported "
|
|
||||||
"with this QEMU binary"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT &&
|
|
||||||
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_CACHING_MODE)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("iommu: caching mode is not supported "
|
|
||||||
"with this QEMU binary"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (iommu->eim != VIR_TRISTATE_SWITCH_ABSENT &&
|
|
||||||
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_EIM)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("iommu: eim is not supported "
|
|
||||||
"with this QEMU binary"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT &&
|
|
||||||
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_DEVICE_IOTLB)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("iommu: device IOTLB is not supported "
|
|
||||||
"with this QEMU binary"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VIR_DOMAIN_IOMMU_MODEL_LAST:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU))
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU))
|
||||||
return 0; /* Already handled via -machine */
|
return 0; /* Already handled via -machine */
|
||||||
|
|
||||||
switch (iommu->model) {
|
switch (iommu->model) {
|
||||||
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
|
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
|
||||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
||||||
_("IOMMU device: '%s' is not supported with "
|
|
||||||
"this QEMU binary"),
|
|
||||||
virDomainIOMMUModelTypeToString(iommu->model));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!qemuDomainIsQ35(def)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
||||||
_("IOMMU device: '%s' is only supported with "
|
|
||||||
"Q35 machines"),
|
|
||||||
virDomainIOMMUModelTypeToString(iommu->model));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
virBufferAddLit(&opts, "intel-iommu");
|
virBufferAddLit(&opts, "intel-iommu");
|
||||||
if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) {
|
if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) {
|
||||||
virBufferAsprintf(&opts, ",intremap=%s",
|
virBufferAsprintf(&opts, ",intremap=%s",
|
||||||
@ -7648,13 +7599,6 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
|
|||||||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU)) {
|
virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU)) {
|
||||||
switch (def->iommu->model) {
|
switch (def->iommu->model) {
|
||||||
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
|
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
|
||||||
if (!qemuDomainIsQ35(def)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
||||||
_("IOMMU device: '%s' is only supported with "
|
|
||||||
"Q35 machines"),
|
|
||||||
virDomainIOMMUModelTypeToString(def->iommu->model));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
virBufferAddLit(&buf, ",iommu=on");
|
virBufferAddLit(&buf, ",iommu=on");
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_IOMMU_MODEL_LAST:
|
case VIR_DOMAIN_IOMMU_MODEL_LAST:
|
||||||
|
@ -6083,6 +6083,67 @@ qemuDomainDeviceDefValidateMemballoon(const virDomainMemballoonDef *memballoon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainDeviceDefValidateIOMMU(const virDomainIOMMUDef *iommu,
|
||||||
|
const virDomainDef *def,
|
||||||
|
virQEMUCapsPtr qemuCaps)
|
||||||
|
{
|
||||||
|
switch (iommu->model) {
|
||||||
|
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
|
||||||
|
if (!qemuDomainIsQ35(def)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("IOMMU device: '%s' is only supported with "
|
||||||
|
"Q35 machines"),
|
||||||
|
virDomainIOMMUModelTypeToString(iommu->model));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU) &&
|
||||||
|
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("IOMMU device: '%s' is not supported with "
|
||||||
|
"this QEMU binary"),
|
||||||
|
virDomainIOMMUModelTypeToString(iommu->model));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT &&
|
||||||
|
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_INTREMAP)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("iommu: interrupt remapping is not supported "
|
||||||
|
"with this QEMU binary"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT &&
|
||||||
|
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_CACHING_MODE)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("iommu: caching mode is not supported "
|
||||||
|
"with this QEMU binary"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (iommu->eim != VIR_TRISTATE_SWITCH_ABSENT &&
|
||||||
|
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_EIM)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("iommu: eim is not supported "
|
||||||
|
"with this QEMU binary"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT &&
|
||||||
|
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_DEVICE_IOTLB)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("iommu: device IOTLB is not supported "
|
||||||
|
"with this QEMU binary"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_IOMMU_MODEL_LAST:
|
||||||
|
default:
|
||||||
|
virReportEnumRangeError(virDomainIOMMUModel, iommu->model);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info,
|
qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info,
|
||||||
virQEMUCapsPtr qemuCaps)
|
virQEMUCapsPtr qemuCaps)
|
||||||
@ -6195,6 +6256,10 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
|||||||
ret = qemuDomainDeviceDefValidateMemballoon(dev->data.memballoon, qemuCaps);
|
ret = qemuDomainDeviceDefValidateMemballoon(dev->data.memballoon, qemuCaps);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_DEVICE_IOMMU:
|
||||||
|
ret = qemuDomainDeviceDefValidateIOMMU(dev->data.iommu, def, qemuCaps);
|
||||||
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_LEASE:
|
case VIR_DOMAIN_DEVICE_LEASE:
|
||||||
case VIR_DOMAIN_DEVICE_FS:
|
case VIR_DOMAIN_DEVICE_FS:
|
||||||
case VIR_DOMAIN_DEVICE_SOUND:
|
case VIR_DOMAIN_DEVICE_SOUND:
|
||||||
@ -6203,7 +6268,6 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
|||||||
case VIR_DOMAIN_DEVICE_SHMEM:
|
case VIR_DOMAIN_DEVICE_SHMEM:
|
||||||
case VIR_DOMAIN_DEVICE_MEMORY:
|
case VIR_DOMAIN_DEVICE_MEMORY:
|
||||||
case VIR_DOMAIN_DEVICE_PANIC:
|
case VIR_DOMAIN_DEVICE_PANIC:
|
||||||
case VIR_DOMAIN_DEVICE_IOMMU:
|
|
||||||
case VIR_DOMAIN_DEVICE_NONE:
|
case VIR_DOMAIN_DEVICE_NONE:
|
||||||
case VIR_DOMAIN_DEVICE_LAST:
|
case VIR_DOMAIN_DEVICE_LAST:
|
||||||
break;
|
break;
|
||||||
|
@ -2812,7 +2812,7 @@ mymain(void)
|
|||||||
DO_TEST_CAPS_LATEST("intel-iommu-caching-mode");
|
DO_TEST_CAPS_LATEST("intel-iommu-caching-mode");
|
||||||
DO_TEST_CAPS_LATEST("intel-iommu-eim");
|
DO_TEST_CAPS_LATEST("intel-iommu-eim");
|
||||||
DO_TEST_CAPS_LATEST("intel-iommu-device-iotlb");
|
DO_TEST_CAPS_LATEST("intel-iommu-device-iotlb");
|
||||||
DO_TEST_FAILURE("intel-iommu-wrong-machine", NONE);
|
DO_TEST_PARSE_ERROR("intel-iommu-wrong-machine", NONE);
|
||||||
|
|
||||||
DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
|
DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
|
||||||
DO_TEST_PARSE_ERROR("cpu-hotplug-granularity",
|
DO_TEST_PARSE_ERROR("cpu-hotplug-granularity",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user