]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Generate command line for sound devices with model 'virtio'
authorRayhan Faizel <rayhan.faizel@gmail.com>
Thu, 11 Apr 2024 20:12:44 +0000 (01:42 +0530)
committerJán Tomko <jtomko@redhat.com>
Thu, 2 May 2024 13:38:34 +0000 (15:38 +0200)
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>
src/qemu/qemu_command.c
tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.args
tests/qemuxmlconfdata/arm-vexpressa9-virtio.aarch64-latest.xml
tests/qemuxmlconfdata/arm-vexpressa9-virtio.xml
tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.args [new file with mode: 0644]
tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.xml [new file with mode: 0644]
tests/qemuxmlconfdata/sound-device-virtio.xml [new file with mode: 0644]
tests/qemuxmlconftest.c

index c32f5773397e909403cd14f6c9a8fb4fd8654a3d..9859ea67a40c4ee56d4f7a29c6c21c26a90acdcd 100644 (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;
 
index b4c295be6bac253fe82fbcd2941f1782dff4fb44..4ed442364c3658af4821188d5805f383bbcec85d 100644 (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"}' \
index 097525c6c86a6e8c673c5a3e330cdef7d6b55322..fd8cf9aa762f6482715bcc5533f9fb0f6690748e 100644 (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'/>
index 0c4b2b69542f2828d7f12a154699f1a378aa5a32..f9deadf2e896f1d62087d147a770accd30978ab3 100644 (file)
     <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>
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 (file)
index 0000000..cca0069
--- /dev/null
@@ -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 (file)
index 0000000..a125cb8
--- /dev/null
@@ -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>
diff --git a/tests/qemuxmlconfdata/sound-device-virtio.xml b/tests/qemuxmlconfdata/sound-device-virtio.xml
new file mode 100644 (file)
index 0000000..c8322d7
--- /dev/null
@@ -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>
index 619686b9a74b33b6dcb88fa178f4742778d70ac1..2842b44b3e1dfdf7695b33071cbf58040b980297 100644 (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)