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.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
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 58d7aa697e..ef5f9c0582 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 35ef2ae47d..0db96da3c2 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5224,6 +5224,45 @@ qemuDomainDeviceDefValidateNVRAM(virDomainNVRAMDefPtr nvram,
}
+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)
@@ -7669,8 +7708,11 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
ret = qemuDomainDeviceDefValidateNVRAM(dev->data.nvram, def, 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_HUB:
case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_MEMORY:
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 3d4959a05c..2200d4a652 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -409,7 +409,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);
DO_TEST("net-bandwidth2", QEMU_CAPS_DEVICE_VGA);
--
2.23.0