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 @@
+
+
+
diff --git a/tests/qemuxmlconfdata/arm-vexpressa9-virtio.xml b/tests/qemuxmlconfdata/arm-vexpressa9-virtio.xml
index 0c4b2b6954..f9deadf2e8 100644
--- a/tests/qemuxmlconfdata/arm-vexpressa9-virtio.xml
+++ b/tests/qemuxmlconfdata/arm-vexpressa9-virtio.xml
@@ -32,9 +32,10 @@
+ 4 virtio slots available, rng and sound makes 6 -->
/dev/random
+
diff --git a/tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.args b/tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.args
new file mode 100644
index 0000000000..cca0069c64
--- /dev/null
+++ b/tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.args
@@ -0,0 +1,36 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \
+-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=off \
+-accel tcg \
+-cpu qemu64 \
+-m size=219136k \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-device '{"driver":"virtio-sound-pci","id":"sound0","audiodev":"audio1","streams":2,"bus":"pci.0","addr":"0x2"}' \
+-device '{"driver":"virtio-sound-pci","id":"sound1","audiodev":"audio1","streams":4,"bus":"pci.0","addr":"0x3"}' \
+-device '{"driver":"virtio-sound-pci","iommu_platform":true,"packed":true,"id":"sound2","audiodev":"audio1","streams":2,"bus":"pci.0","addr":"0x4"}' \
+-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x5"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.xml b/tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.xml
new file mode 100644
index 0000000000..a125cb8df8
--- /dev/null
+++ b/tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.xml
@@ -0,0 +1,44 @@
+
+ QEMUGuest1
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 219100
+ 219100
+ 1
+
+ hvm
+
+
+
+ qemu64
+
+
+ destroy
+ restart
+ destroy
+
+ /usr/bin/qemu-system-x86_64
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/qemuxmlconfdata/sound-device-virtio.xml b/tests/qemuxmlconfdata/sound-device-virtio.xml
new file mode 100644
index 0000000000..c8322d7e5b
--- /dev/null
+++ b/tests/qemuxmlconfdata/sound-device-virtio.xml
@@ -0,0 +1,28 @@
+
+ QEMUGuest1
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 219100
+ 219100
+ 1
+
+ hvm
+
+
+ destroy
+ restart
+ destroy
+
+ /usr/bin/qemu-system-x86_64
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c
index 619686b9a7..2842b44b3e 100644
--- a/tests/qemuxmlconftest.c
+++ b/tests/qemuxmlconftest.c
@@ -2985,6 +2985,7 @@ mymain(void)
DO_TEST_CAPS_LATEST("mtp-usb-device")
DO_TEST_CAPS_LATEST("net-usb")
+ DO_TEST_CAPS_LATEST("sound-device-virtio")
/* check that all input files were actually used here */
if (testConfXMLCheck(existingTestCases) < 0)