From a1a3da94f5ef087834afcdfe7c9db5b3a0b1ad82 Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Fri, 12 Apr 2024 01:42:44 +0530 Subject: [PATCH] qemu: Generate command line for sound devices with model 'virtio' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow generation of command line for virtio-sound-pci and virtio-sound-device devices along with additional virtio options. A new testcase is added to test virtio-sound-pci. The arm-vexpressa9-virtio testcase is also extended to test virtio-sound-device. Signed-off-by: Rayhan Faizel Reviewed-by: Ján Tomko --- src/qemu/qemu_command.c | 24 +++++++++- .../arm-vexpressa9-virtio.aarch64-latest.args | 1 + .../arm-vexpressa9-virtio.aarch64-latest.xml | 3 ++ .../qemuxmlconfdata/arm-vexpressa9-virtio.xml | 3 +- .../sound-device-virtio.x86_64-latest.args | 36 +++++++++++++++ .../sound-device-virtio.x86_64-latest.xml | 44 +++++++++++++++++++ tests/qemuxmlconfdata/sound-device-virtio.xml | 28 ++++++++++++ tests/qemuxmlconftest.c | 1 + 8 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.args create mode 100644 tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.xml create mode 100644 tests/qemuxmlconfdata/sound-device-virtio.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c32f577339..9859ea67a4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -952,8 +952,13 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device, break; } + case VIR_DOMAIN_DEVICE_SOUND: { + *baseName = "virtio-sound"; + *virtioOptions = device->data.sound->virtio; + break; + } + case VIR_DOMAIN_DEVICE_LEASE: - case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_WATCHDOG: case VIR_DOMAIN_DEVICE_GRAPHICS: case VIR_DOMAIN_DEVICE_HUB: @@ -4461,6 +4466,8 @@ qemuBuildSoundDevCmd(virCommand *cmd, const char *model = NULL; g_autofree char *audioid = NULL; virTristateBool multichannel = VIR_TRISTATE_BOOL_ABSENT; + unsigned int streams = 0; + bool virtio = false; switch (sound->model) { case VIR_DOMAIN_SOUND_MODEL_ES1370: @@ -4483,6 +4490,9 @@ qemuBuildSoundDevCmd(virCommand *cmd, model = "sb16"; break; case VIR_DOMAIN_SOUND_MODEL_VIRTIO: + virtio = true; + streams = sound->streams; + break; case VIR_DOMAIN_SOUND_MODEL_PCSPK: /* pc-speaker is handled separately */ case VIR_DOMAIN_SOUND_MODEL_ICH7: case VIR_DOMAIN_SOUND_MODEL_LAST: @@ -4494,11 +4504,21 @@ qemuBuildSoundDevCmd(virCommand *cmd, return -1; } + if (!virtio) { + if (virJSONValueObjectAdd(&props, + "s:driver", model, + NULL) < 0) + return -1; + } else { + if (!(props = qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_SOUND, sound, qemuCaps))) + return -1; + } + if (virJSONValueObjectAdd(&props, - "s:driver", model, "s:id", sound->info.alias, "S:audiodev", audioid, "T:multi", multichannel, + "p:streams", streams, NULL) < 0) return -1; diff --git a/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.args b/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.args index b4c295be6b..4ed442364c 100644 --- a/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.args +++ b/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.args @@ -41,6 +41,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-armtest/.config \ -chardev pty,id=charconsole1 \ -device '{"driver":"virtconsole","chardev":"charconsole1","id":"console1"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"virtio-sound-device","id":"sound0","audiodev":"audio1","streams":2}' \ -device '{"driver":"virtio-balloon-device","id":"balloon0"}' \ -object '{"qom-type":"rng-random","id":"objrng0","filename":"/dev/random"}' \ -device '{"driver":"virtio-rng-device","rng":"objrng0","id":"rng0"}' \ diff --git a/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.xml b/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.xml index 097525c6c8..fd8cf9aa76 100644 --- a/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.xml +++ b/tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.xml @@ -44,6 +44,9 @@ + +
+