From 0115d0130d6b93cab48418da4fef63c0d2ad0e93 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Mon, 9 Dec 2019 20:15:14 -0300 Subject: [PATCH] qemu: command: move qemuBuildSoundDevStr caps validation to qemu_domain Move QEMU caps validation of QEMU_CAPS_OBJECT_USB_AUDIO and QEMU_CAPS_DEVICE_ICH9_INTEL_HDA to a new function in qemu_domain.c, qemuDomainDeviceDefValidateSound(). This function is called by qemuDomainDeviceDefValidate() to validate the sound device in domain define time. qemuxml2xmltest.c was adjusted to add the now required caps for domain definition. Reviewed-by: Cole Robinson Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_command.c | 15 -------------- src/qemu/qemu_domain.c | 44 ++++++++++++++++++++++++++++++++++++++++- tests/qemuxml2xmltest.c | 4 +++- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 72d65b6445..0d9dd66c33 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4280,30 +4280,15 @@ qemuBuildSoundDevStr(const virDomainDef *def, break; case VIR_DOMAIN_SOUND_MODEL_USB: model = "usb-audio"; - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_USB_AUDIO)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("usb-audio controller is not supported " - "by this QEMU binary")); - return NULL; - } break; case VIR_DOMAIN_SOUND_MODEL_ICH9: model = "ich9-intel-hda"; - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ICH9_INTEL_HDA)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("The ich9-intel-hda audio controller " - "is not supported in this QEMU binary")); - return NULL; - } break; case VIR_DOMAIN_SOUND_MODEL_SB16: model = "sb16"; break; case VIR_DOMAIN_SOUND_MODEL_PCSPK: /* pc-speaker is handled separately */ case VIR_DOMAIN_SOUND_MODEL_LAST: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("sound card model '%s' is not supported by qemu"), - virDomainSoundModelTypeToString(sound->model)); return NULL; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a8dc178761..db423b62d0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5563,6 +5563,45 @@ qemuDomainDefValidateConsole(const virDomainDef *def, } +static int +qemuDomainDeviceDefValidateSound(virDomainSoundDefPtr sound, + virQEMUCapsPtr qemuCaps) +{ + switch ((virDomainSoundModel) sound->model) { + case VIR_DOMAIN_SOUND_MODEL_USB: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_USB_AUDIO)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("usb-audio controller is not supported " + "by this QEMU binary")); + return -1; + } + break; + case VIR_DOMAIN_SOUND_MODEL_ICH9: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ICH9_INTEL_HDA)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("The ich9-intel-hda audio controller " + "is not supported in this QEMU binary")); + return -1; + } + break; + + case VIR_DOMAIN_SOUND_MODEL_ES1370: + case VIR_DOMAIN_SOUND_MODEL_AC97: + case VIR_DOMAIN_SOUND_MODEL_ICH6: + case VIR_DOMAIN_SOUND_MODEL_SB16: + case VIR_DOMAIN_SOUND_MODEL_PCSPK: + break; + case VIR_DOMAIN_SOUND_MODEL_LAST: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("sound card model '%s' is not supported by qemu"), + virDomainSoundModelTypeToString(sound->model)); + return -1; + } + + return 0; +} + + static int qemuDomainDefValidate(const virDomainDef *def, void *opaque) @@ -8286,8 +8325,11 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, ret = qemuDomainDeviceDefValidateHub(dev->data.hub, qemuCaps); break; - case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_SOUND: + ret = qemuDomainDeviceDefValidateSound(dev->data.sound, qemuCaps); + break; + + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_PANIC: diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index ac259320bc..1f08e303b6 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -456,7 +456,9 @@ mymain(void) DO_TEST("net-midonet", NONE); DO_TEST("net-openvswitch", NONE); DO_TEST("sound", NONE); - DO_TEST("sound-device", NONE); + DO_TEST("sound-device", + QEMU_CAPS_DEVICE_ICH9_INTEL_HDA, + QEMU_CAPS_OBJECT_USB_AUDIO); DO_TEST("watchdog", NONE); DO_TEST("net-bandwidth", QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_VNC); DO_TEST("net-bandwidth2", QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_VNC);