qemuBuildSoundCodecStr() validates if a given QEMU binary
supports the sound codec. This validation can be moved to
qemu_domain.c to be executed in domain define time.
The codec validation was moved to the existing
qemuDomainDeviceDefValidateSound() function.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_command.c | 36 ++++--------------------------------
src/qemu/qemu_command.h | 1 +
src/qemu/qemu_domain.c | 36 ++++++++++++++++++++++++++++++++++++
tests/qemuxml2xmltest.c | 5 ++++-
4 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ef5f9c0582..3b4fae740c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -155,8 +155,6 @@ VIR_ENUM_IMPL(qemuDeviceVideoSecondary,
"" /* no secondary device for ramfb */,
);
-VIR_ENUM_DECL(qemuSoundCodec);
-
VIR_ENUM_IMPL(qemuSoundCodec,
VIR_DOMAIN_SOUND_CODEC_TYPE_LAST,
"hda-duplex",
@@ -4300,40 +4298,16 @@ qemuBuildSoundDevStr(const virDomainDef *def,
}
-static int
-qemuSoundCodecTypeToCaps(int type)
-{
- switch (type) {
- case VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX:
- return QEMU_CAPS_HDA_DUPLEX;
- case VIR_DOMAIN_SOUND_CODEC_TYPE_MICRO:
- return QEMU_CAPS_HDA_MICRO;
- case VIR_DOMAIN_SOUND_CODEC_TYPE_OUTPUT:
- return QEMU_CAPS_HDA_OUTPUT;
- default:
- return -1;
- }
-}
-
-
static char *
qemuBuildSoundCodecStr(virDomainSoundDefPtr sound,
- virDomainSoundCodecDefPtr codec,
- virQEMUCapsPtr qemuCaps)
+ virDomainSoundCodecDefPtr codec)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const char *stype;
- int type, flags;
+ int type;
type = codec->type;
stype = qemuSoundCodecTypeToString(type);
- flags = qemuSoundCodecTypeToCaps(type);
-
- if (flags == -1 || !virQEMUCapsGet(qemuCaps, flags)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("%s not supported in this QEMU binary"), stype);
- return NULL;
- }
virBufferAsprintf(&buf, "%s,id=%s-codec%d,bus=%s.0,cad=%d",
stype, sound->info.alias, codec->cad, sound->info.alias,
codec->cad);
@@ -4374,8 +4348,7 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
g_autofree char *codecstr = NULL;
virCommandAddArg(cmd, "-device");
if (!(codecstr =
- qemuBuildSoundCodecStr(sound, sound->codecs[j],
- qemuCaps))) {
+ qemuBuildSoundCodecStr(sound, sound->codecs[j]))) {
return -1;
}
@@ -4389,8 +4362,7 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
};
virCommandAddArg(cmd, "-device");
if (!(codecstr =
- qemuBuildSoundCodecStr(sound, &codec,
- qemuCaps))) {
+ qemuBuildSoundCodecStr(sound, &codec))) {
return -1;
}
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index f945b2d6d4..786991fd3d 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -41,6 +41,7 @@
#define QEMU_BLOCK_IOTUNE_MAX 1000000000000000LL
VIR_ENUM_DECL(qemuVideo);
+VIR_ENUM_DECL(qemuSoundCodec);
virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
virLogManagerPtr logManager,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0db96da3c2..ee9de98df1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5224,10 +5224,28 @@ qemuDomainDeviceDefValidateNVRAM(virDomainNVRAMDefPtr nvram,
}
+static int
+qemuSoundCodecTypeToCaps(int type)
+{
+ switch (type) {
+ case VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX:
+ return QEMU_CAPS_HDA_DUPLEX;
+ case VIR_DOMAIN_SOUND_CODEC_TYPE_MICRO:
+ return QEMU_CAPS_HDA_MICRO;
+ case VIR_DOMAIN_SOUND_CODEC_TYPE_OUTPUT:
+ return QEMU_CAPS_HDA_OUTPUT;
+ default:
+ return -1;
+ }
+}
+
+
static int
qemuDomainDeviceDefValidateSound(virDomainSoundDefPtr sound,
virQEMUCapsPtr qemuCaps)
{
+ size_t i;
+
switch ((virDomainSoundModel) sound->model) {
case VIR_DOMAIN_SOUND_MODEL_USB:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_USB_AUDIO)) {
@@ -5259,6 +5277,24 @@ qemuDomainDeviceDefValidateSound(virDomainSoundDefPtr sound,
return -1;
}
+ if (sound->model == VIR_DOMAIN_SOUND_MODEL_ICH6 ||
+ sound->model == VIR_DOMAIN_SOUND_MODEL_ICH9) {
+ for (i = 0; i < sound->ncodecs; i++) {
+ const char *stype;
+ int type, flags;
+
+ type = sound->codecs[i]->type;
+ stype = qemuSoundCodecTypeToString(type);
+ flags = qemuSoundCodecTypeToCaps(type);
+
+ if (flags == -1 || !virQEMUCapsGet(qemuCaps, flags)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("%s not supported in this QEMU binary"),
stype);
+ return -1;
+ }
+ }
+ }
+
return 0;
}
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 2200d4a652..f3fec5ee19 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -411,7 +411,10 @@ mymain(void)
DO_TEST("sound", NONE);
DO_TEST("sound-device",
QEMU_CAPS_DEVICE_ICH9_INTEL_HDA,
- QEMU_CAPS_OBJECT_USB_AUDIO);
+ QEMU_CAPS_OBJECT_USB_AUDIO,
+ QEMU_CAPS_HDA_MICRO,
+ QEMU_CAPS_HDA_DUPLEX,
+ QEMU_CAPS_HDA_OUTPUT);
DO_TEST("watchdog", NONE);
DO_TEST("net-bandwidth", QEMU_CAPS_DEVICE_VGA);
DO_TEST("net-bandwidth2", QEMU_CAPS_DEVICE_VGA);
--
2.23.0