qemu: Generate command line for sound devices with model 'virtio'

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 <rayhan.faizel@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Rayhan Faizel 2024-04-12 01:42:44 +05:30 committed by Ján Tomko
parent bb593e3743
commit a1a3da94f5
8 changed files with 137 additions and 3 deletions

View File

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

View File

@ -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"}' \

View File

@ -44,6 +44,9 @@
<console type='pty'>
<target type='virtio' port='1'/>
</console>
<sound model='virtio' streams='2'>
<address type='virtio-mmio'/>
</sound>
<audio id='1' type='none'/>
<memballoon model='virtio'>
<address type='virtio-mmio'/>

View File

@ -32,9 +32,10 @@
<memballoon model='virtio'/>
<!--
This actually doesn't work in practice because vexpress only has
4 virtio slots available, rng makes 5 -->
4 virtio slots available, rng and sound makes 6 -->
<rng model='virtio'>
<backend model='random'>/dev/random</backend>
</rng>
<sound model='virtio'/>
</devices>
</domain>

View File

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

View File

@ -0,0 +1,44 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219100</memory>
<currentMemory unit='KiB'>219100</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<sound model='virtio' streams='2'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</sound>
<sound model='virtio' streams='4'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</sound>
<sound model='virtio' streams='2'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
<driver iommu='on' packed='on'/>
</sound>
<audio id='1' type='none'/>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</memballoon>
</devices>
</domain>

View File

@ -0,0 +1,28 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219100</memory>
<currentMemory unit='KiB'>219100</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<controller type='usb' index='0'/>
<controller type='ide' index='0'/>
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<sound model='virtio'/>
<sound model='virtio' streams='4'/>
<sound model='virtio'>
<driver iommu='on' packed='on'/>
</sound>
<memballoon model='virtio'/>
</devices>
</domain>

View File

@ -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)