[PATCH 3/3] qemu: Generate command line for sound devices with model 'virtio'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 src/qemu/qemu_command.c                       | 23 +++++++++-
 .../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, 136 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 5e69e71c6f..b5537d1e8f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -952,8 +952,12 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device,
             break;
         }
 
+        case VIR_DOMAIN_DEVICE_SOUND: {
+            *baseName = "virtio-sound";
+            *virtioOptions = device->data.sound->virtio;
+        }
+
         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:
@@ -4458,6 +4462,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:
@@ -4480,6 +4486,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:
@@ -4491,11 +4500,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 @@
     <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'/>
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 @@
     <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
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 @@
+<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
index 0000000000..c8322d7e5b
--- /dev/null
+++ b/tests/qemuxmlconfdata/sound-device-virtio.xml
@@ -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>
diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c
index 1f9e8edef9..c41bd7f792 100644
--- a/tests/qemuxmlconftest.c
+++ b/tests/qemuxmlconftest.c
@@ -2980,6 +2980,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)
-- 
2.34.1
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux