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 | 37 +++++++++++++++++-- .../bhyvexml2argv-sound.args | 2 +- .../bhyvexml2argvdata/bhyvexml2argv-sound.xml | 8 +++- .../bhyvexml2xmlout-sound.xml | 5 +++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 64af0b3598..9c48c31066 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -478,9 +478,13 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def, static int bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED, virDomainSoundDefPtr sound, + virHashTablePtr audios, bhyveConnPtr driver, virCommandPtr cmd) { + g_auto(virBuffer) params = VIR_BUFFER_INITIALIZER; + virDomainAudioDefPtr audio; + 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 +501,25 @@ bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED, } virCommandAddArg(cmd, "-s"); - virCommandAddArgFormat(cmd, "%d:%d,hda,play=/dev/dsp0", + + if (audios) { + audio = virHashLookup(audios, sound->audioId); + + if (audio) { + if (audio->type == VIR_DOMAIN_AUDIO_TYPE_OSS) { + if (audio->inputDev) + virBufferAsprintf(¶ms, ",play=%s", audio->inputDev); + + if (audio->outputDev) + virBufferAsprintf(¶ms, ",rec=%s", audio->outputDev); + } + } + } + virCommandAddArgFormat(cmd, "%d:%d,hda%s", sound->info.addr.pci.slot, - sound->info.addr.pci.function); + sound->info.addr.pci.function, + virBufferCurrentContent(¶ms)); + return 0; } @@ -519,6 +539,7 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def, size_t i; unsigned nusbcontrollers = 0; unsigned nvcpus = virDomainDefGetVcpus(def); + virHashTablePtr audios = NULL; /* CPUs */ virCommandAddArg(cmd, "-c"); @@ -647,11 +668,20 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def, } } + if (def->naudios > 0) { + audios = virHashCreate(def->naudios, NULL); + + for (i = 0; i < def->naudios; i++) + virHashAddEntry(audios, def->audios[i]->id, def->audios[i]); + } + for (i = 0; i < def->nsounds; i++) { - if (bhyveBuildSoundArgStr(def, def->sounds[i], driver, cmd) < 0) + if (bhyveBuildSoundArgStr(def, def->sounds[i], audios, driver, cmd) < 0) goto error; } + virHashFree(audios); + if (bhyveDomainDefNeedsISAController(def)) bhyveBuildLPCArgStr(def, cmd); @@ -675,6 +705,7 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def, return cmd; error: + virHashFree(audios); virCommandFree(cmd); return NULL; } 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 dd4f0491a2..f622208b79 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='ich6'/> + <sound model='ich6'> + <audio id="audio0"/> + </sound> + <audio type="oss" id="audio0"> + <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 f5da7c23c8..529629f165 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='ich6'> + <audio id='audio0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </sound> + <audio id='audio0' type='oss'> + <input dev='/dev/dsp0'/> + <output dev='/dev/dsp0'/> + </audio> </devices> </domain> -- 2.27.0