From c66f2be6f107da98a329e2e03c783b6c14d5694b Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Fri, 18 Oct 2019 10:30:16 -0500 Subject: [PATCH] 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 Signed-off-by: Jonathon Jongsma --- src/conf/domain_capabilities.c | 18 +++++++++++++- src/qemu/qemu_domain.c | 23 ++---------------- src/qemu/qemu_process.c | 43 ---------------------------------- 3 files changed, 19 insertions(+), 65 deletions(-) diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index e76036fe58..573107df68 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -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: diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6b9bd96ec9..ace3761e20 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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 && diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 72e9965109..1192b4447d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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; -- GitLab