[PATCH v3 4/6] bhyve: allow to specify host sound device

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

 



Allow to map sound playback and recording devices to host devices
using "<audio type='oss'/>" OSS audio backend.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@xxxxxxxxx>
---
 src/bhyve/bhyve_command.c                     | 26 ++++++++++++++++---
 src/conf/domain_conf.c                        | 13 ++++++++++
 src/conf/domain_conf.h                        |  4 +++
 src/libvirt_private.syms                      |  1 +
 .../bhyvexml2argv-sound.args                  |  2 +-
 .../bhyvexml2argvdata/bhyvexml2argv-sound.xml |  8 +++++-
 .../bhyvexml2xmlout-sound.xml                 |  5 ++++
 7 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 1f42f71347..8e7907b882 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -478,9 +478,12 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 static int
 bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
                       virDomainSoundDefPtr sound,
+                      virDomainAudioDefPtr audio,
                       bhyveConnPtr driver,
                       virCommandPtr cmd)
 {
+    g_auto(virBuffer) params = VIR_BUFFER_INITIALIZER;
+
     if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_SOUND_HDA)) {
         /* Currently, bhyve only supports "hda" sound devices, so
            if it's not supported, sound devices are not supported at all */
@@ -497,9 +500,24 @@ bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
     }
 
     virCommandAddArg(cmd, "-s");
-    virCommandAddArgFormat(cmd, "%d:%d,hda,play=/dev/dsp0",
+
+    if (audio) {
+        if (audio->type == VIR_DOMAIN_AUDIO_TYPE_OSS) {
+            if (audio->backend.oss.inputDev)
+                virBufferAsprintf(&params, ",play=%s",
+                                  audio->backend.oss.inputDev);
+
+            if (audio->backend.oss.outputDev)
+                virBufferAsprintf(&params, ",rec=%s",
+                                  audio->backend.oss.outputDev);
+        }
+    }
+
+    virCommandAddArgFormat(cmd, "%d:%d,hda%s",
                            sound->info.addr.pci.slot,
-                           sound->info.addr.pci.function);
+                           sound->info.addr.pci.function,
+                           virBufferCurrentContent(&params));
+
     return 0;
 }
 
@@ -648,7 +666,9 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def,
     }
 
     for (i = 0; i < def->nsounds; i++) {
-        if (bhyveBuildSoundArgStr(def, def->sounds[i], driver, cmd) < 0)
+        if (bhyveBuildSoundArgStr(def, def->sounds[i],
+                                  virDomainDefFindAudioForSound(def, def->sounds[i]),
+                                  driver, cmd) < 0)
             goto error;
     }
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 165d5d5f7a..28ff4d3994 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31499,6 +31499,19 @@ virDomainDefFindDevice(virDomainDefPtr def,
 }
 
 
+virDomainAudioDefPtr
+virDomainDefFindAudioForSound(virDomainDefPtr def,
+                              virDomainSoundDefPtr sound)
+{
+    size_t i;
+    for (i = 0; i < def->naudios; i++)
+        if (def->audios[i]->id == sound->audioId)
+            return def->audios[i];
+
+    return NULL;
+}
+
+
 char *
 virDomainObjGetMetadata(virDomainObjPtr vm,
                         int type,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fdf706a7e0..d9d7b094ac 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3712,6 +3712,10 @@ int virDomainDefFindDevice(virDomainDefPtr def,
                            virDomainDeviceDefPtr dev,
                            bool reportError);
 
+virDomainAudioDefPtr
+virDomainDefFindAudioForSound(virDomainDefPtr def,
+                              virDomainSoundDefPtr sound);
+
 const char *virDomainChrSourceDefGetPath(virDomainChrSourceDefPtr chr);
 
 void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 35bf9f08ef..f950a68179 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -298,6 +298,7 @@ virDomainDefCheckABIStability;
 virDomainDefCheckABIStabilityFlags;
 virDomainDefCompatibleDevice;
 virDomainDefCopy;
+virDomainDefFindAudioForSound;
 virDomainDefFindDevice;
 virDomainDefFormat;
 virDomainDefFormatConvertXMLFlags;
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args
index c242708ff1..05ff4965dd 100644
--- a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args
@@ -7,4 +7,4 @@
 -s 0:0,hostbridge \
 -s 2:0,ahci,hd:/tmp/freebsd.img \
 -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
--s 4:0,hda,play=/dev/dsp0 bhyve
+-s 4:0,hda,play=/dev/dsp0,rec=/dev/dsp0 bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml
index 8e799301fb..831e8670e7 100644
--- a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml
@@ -19,6 +19,12 @@
       <source bridge="virbr0"/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </interface>
-    <sound model='ich7'/>
+    <sound model='ich7'>
+      <audio id="1"/>
+    </sound>
+    <audio type="oss" id="1">
+      <input dev="/dev/dsp0"/>
+      <output dev="/dev/dsp0"/>
+    </audio>
   </devices>
 </domain>
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml
index a64c5da27a..c23892eec9 100644
--- a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml
+++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml
@@ -30,7 +30,12 @@
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </interface>
     <sound model='ich7'>
+      <audio id='1'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </sound>
+    <audio id='1' type='oss'>
+      <input dev='/dev/dsp0'/>
+      <output dev='/dev/dsp0'/>
+    </audio>
   </devices>
 </domain>
-- 
2.27.0




[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