qemu: command: move sound codec validation to qemu_domain.c

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.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2019-12-09 20:15:15 -03:00 committed by Cole Robinson
parent 0115d0130d
commit 6f894a29d8
4 changed files with 45 additions and 33 deletions

View File

@ -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;
}

View File

@ -41,6 +41,7 @@
#define QEMU_BLOCK_IOTUNE_MAX 1000000000000000LL
VIR_ENUM_DECL(qemuVideo);
VIR_ENUM_DECL(qemuSoundCodec);
virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
virLogManagerPtr logManager,

View File

@ -5563,10 +5563,28 @@ qemuDomainDefValidateConsole(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 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)) {
@ -5598,6 +5616,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;
}

View File

@ -458,7 +458,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, QEMU_CAPS_VNC);
DO_TEST("net-bandwidth2", QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_VNC);