qemu: use domain caps to validate video device model

As suggested by Cole, this patch uses the domain capabilities to
validate the supported video model types. This allows us to remove the
model type validation from qemu_process.c and qemu_domain.c and
consolidates it all in a single place that will automatically adjust
when new domain capabilities are added.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Jonathon Jongsma 2019-10-18 10:30:16 -05:00 committed by Cole Robinson
parent 42cc3eb912
commit c66f2be6f1
3 changed files with 19 additions and 65 deletions

View File

@ -711,6 +711,20 @@ virDomainCapsDeviceRNGDefValidate(const virDomainCaps *caps,
}
static int
virDomainCapsDeviceVideoDefValidate(const virDomainCaps *caps,
const virDomainVideoDef *dev)
{
if (ENUM_VALUE_MISSING(caps->video.modelType, dev->type)) {
ENUM_VALUE_ERROR("video model",
virDomainVideoTypeToString(dev->type));
return -1;
}
return 0;
}
int
virDomainCapsDeviceDefValidate(const virDomainCaps *caps,
const virDomainDeviceDef *dev,
@ -722,6 +736,9 @@ virDomainCapsDeviceDefValidate(const virDomainCaps *caps,
case VIR_DOMAIN_DEVICE_RNG:
ret = virDomainCapsDeviceRNGDefValidate(caps, dev->data.rng);
break;
case VIR_DOMAIN_DEVICE_VIDEO:
ret = virDomainCapsDeviceVideoDefValidate(caps, dev->data.video);
break;
case VIR_DOMAIN_DEVICE_DISK:
case VIR_DOMAIN_DEVICE_REDIRDEV:
@ -730,7 +747,6 @@ virDomainCapsDeviceDefValidate(const virDomainCaps *caps,
case VIR_DOMAIN_DEVICE_CHR:
case VIR_DOMAIN_DEVICE_SMARTCARD:
case VIR_DOMAIN_DEVICE_HOSTDEV:
case VIR_DOMAIN_DEVICE_VIDEO:
case VIR_DOMAIN_DEVICE_MEMORY:
case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_INPUT:

View File

@ -5710,28 +5710,9 @@ static int
qemuDomainDeviceDefValidateVideo(const virDomainVideoDef *video,
virQEMUCapsPtr qemuCaps)
{
switch ((virDomainVideoType) video->type) {
case VIR_DOMAIN_VIDEO_TYPE_NONE:
/* there's no properties to validate for NONE video devices */
if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE)
return 0;
case VIR_DOMAIN_VIDEO_TYPE_XEN:
case VIR_DOMAIN_VIDEO_TYPE_VBOX:
case VIR_DOMAIN_VIDEO_TYPE_PARALLELS:
case VIR_DOMAIN_VIDEO_TYPE_GOP:
case VIR_DOMAIN_VIDEO_TYPE_DEFAULT:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("video type '%s' is not supported with QEMU"),
virDomainVideoTypeToString(video->type));
return -1;
case VIR_DOMAIN_VIDEO_TYPE_VGA:
case VIR_DOMAIN_VIDEO_TYPE_CIRRUS:
case VIR_DOMAIN_VIDEO_TYPE_VMVGA:
case VIR_DOMAIN_VIDEO_TYPE_QXL:
case VIR_DOMAIN_VIDEO_TYPE_VIRTIO:
case VIR_DOMAIN_VIDEO_TYPE_BOCHS:
case VIR_DOMAIN_VIDEO_TYPE_RAMFB:
case VIR_DOMAIN_VIDEO_TYPE_LAST:
break;
}
if (!video->primary &&
video->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&

View File

@ -5209,46 +5209,6 @@ qemuProcessStartValidateGraphics(virDomainObjPtr vm)
}
static int
qemuProcessStartValidateVideo(virDomainObjPtr vm,
virQEMUCapsPtr qemuCaps)
{
size_t i;
virDomainVideoDefPtr video;
for (i = 0; i < vm->def->nvideos; i++) {
video = vm->def->videos[i];
if (video->backend != VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
if ((video->type == VIR_DOMAIN_VIDEO_TYPE_VGA &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VGA)) ||
(video->type == VIR_DOMAIN_VIDEO_TYPE_CIRRUS &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_CIRRUS_VGA)) ||
(video->type == VIR_DOMAIN_VIDEO_TYPE_VMVGA &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMWARE_SVGA)) ||
(video->type == VIR_DOMAIN_VIDEO_TYPE_QXL &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QXL)) ||
(video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_GPU)) ||
(video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
video->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_GPU_CCW)) ||
(video->type == VIR_DOMAIN_VIDEO_TYPE_BOCHS &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_BOCHS_DISPLAY)) ||
(video->type == VIR_DOMAIN_VIDEO_TYPE_RAMFB &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_RAMFB))) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("this QEMU does not support '%s' video device"),
virDomainVideoTypeToString(video->type));
return -1;
}
}
}
return 0;
}
static int
qemuProcessStartValidateIOThreads(virDomainObjPtr vm,
virQEMUCapsPtr qemuCaps)
@ -5433,9 +5393,6 @@ qemuProcessStartValidate(virQEMUDriverPtr driver,
if (qemuProcessStartValidateGraphics(vm) < 0)
return -1;
if (qemuProcessStartValidateVideo(vm, qemuCaps) < 0)
return -1;
if (qemuProcessStartValidateIOThreads(vm, qemuCaps) < 0)
return -1;