Skip to contentSkip to conversation

audio: make audiodev introspectable by management apps

PATCH In review Thomas Huth 3 participants 11 messages Jan 23, 2023 – Jan 31, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover audio: make audiodev introspectable by management apps

Here's a respin from Daniel's audiodev introspection patches from 2021. I've rebased them to the current master branch and addressed the review comments from v1.

The Audiodev QAPI type is not introspectable via query-qmp-schema as nothing in QMP uses it. "-audiodev" is not introspectable via query-command-line-options because it avoided legacy QemuOpts.

To fix it, introduce a tiny "query-audiodev" QMP command that uses the "Audiodev" QAPI structure, so that it shows up in the schema. Then mark the various backend types with conditionals so that only the ones that were available at compile time show up in the schema.

Daniel P. Berrangé (2):
qapi, audio: add query-audiodev command
qapi, audio: Make introspection reflect build configuration more
closely

 qapi/audio.json        | 57 +++++++++++++++++++++++++++++++++---------
 audio/audio_template.h | 20 +++++++++++++++
 audio/audio.c          | 32 ++++++++++++++++++++++++
 audio/audio_legacy.c   | 41 +++++++++++++++++++++++++++++-
 4 files changed, 137 insertions(+), 13 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/2 qapi, audio: add query-audiodev command

From: Daniel P. Berrangé <[email protected]>

Way back in QEMU 4.0, the -audiodev command line option was introduced for configuring audio backends. This CLI option does not use QemuOpts so it is not visible for introspection in 'query-command-line-options', instead using the QAPI Audiodev type. Unfortunately there is also no QMP command that uses the Audiodev type, so it is not introspectable with 'query-qmp-schema' either.

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This alone is maybe not very useful by itself, but it makes Audiodev introspectable via 'query-qmp-schema', so that libvirt (and other upper layer tools) can discover the available audiodevs.

[thuth: Update for upcoming QEMU v8.0, and use QAPI_LIST_PREPEND]
---
 qapi/audio.json | 13 +++++++++++++
 audio/audio.c   | 12 ++++++++++++
 2 files changed, 25 insertions(+)
qapi/audio.json +13 -0
index 1e0a24bdfc..c7aafa2763 100644
@@ -443,3 +443,16 @@
     'sndio':     'AudiodevSndioOptions',
     'spice':     'AudiodevGenericOptions',
     'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev
+#
+# Since: 8.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }
audio/audio.c +12 -0
index d849a94a81..6f270c07b7 100644
@@ -28,8 +28,10 @@
 #include "monitor/monitor.h"
 #include "qemu/timer.h"
 #include "qapi/error.h"
+#include "qapi/clone-visitor.h"
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/qapi-visit-audio.h"
+#include "qapi/qapi-commands-audio.h"
 #include "qemu/cutils.h"
 #include "qemu/module.h"
 #include "qemu/help_option.h"
@@ -2311,3 +2313,13 @@ size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info,
 
     return bytes;
 }
+
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL;
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {
+        QAPI_LIST_PREPEND(ret, QAPI_CLONE(Audiodev, e->dev));
+    }
+    return ret;
+}
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH v2 1/2] qapi, audio: add query-audiodev command

Quoted 28 lines · Thomas Huth

From: Daniel P. Berrangé <[email protected]>

Way back in QEMU 4.0, the -audiodev command line option was introduced for configuring audio backends. This CLI option does not use QemuOpts so it is not visible for introspection in 'query-command-line-options', instead using the QAPI Audiodev type. Unfortunately there is also no QMP command that uses the Audiodev type, so it is not introspectable with 'query-qmp-schema' either.

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This alone is maybe not very useful by itself, but it makes Audiodev introspectable via 'query-qmp-schema', so that libvirt (and other upper layer tools) can discover the available audiodevs.

[thuth: Update for upcoming QEMU v8.0, and use QAPI_LIST_PREPEND]
---
  qapi/audio.json | 13 +++++++++++++
  audio/audio.c   | 12 ++++++++++++
  2 files changed, 25 insertions(+)
qapi/audio.json +0 -0
index 1e0a24bdfc..c7aafa2763 100644

qapi/audio.json line 450

Quoted 8 lines
qapi/audio.json +5 -0
@@ -443,3 +443,16 @@
      'sndio':     'AudiodevSndioOptions',
      'spice':     'AudiodevGenericOptions',
      'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration

Maybe clearer as 'audio backends'?

So similarly, wouldn't be clearer to name this command 'query-audio-backends'? Otherwise we need to go read QEMU source to understand what is 'audiodevs'.

Quoted 24 lines
qapi/audio.json +8 -0
+#
+# Returns: array of @Audiodev
+#
+# Since: 8.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }
audio/audio.c +2 -0
index d849a94a81..6f270c07b7 100644
@@ -28,8 +28,10 @@
  #include "monitor/monitor.h"
  #include "qemu/timer.h"
  #include "qapi/error.h"
+#include "qapi/clone-visitor.h"
  #include "qapi/qobject-input-visitor.h"
  #include "qapi/qapi-visit-audio.h"
+#include "qapi/qapi-commands-audio.h"
  #include "qemu/cutils.h"
  #include "qemu/module.h"
  #include "qemu/help_option.h"

audio/audio.c size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info, · line 2321

Quoted 9 lines
audio/audio.c +6 -0
@@ -2311,3 +2313,13 @@ size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info,
 
      return bytes;
  }
+
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL;
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {

I am a bit confused here, isn't &audiodevs containing what the user provided from CLI? How is that useful to libvirt? Maybe the corner case of a user hand-modifying the QEMU launch arguments from a XML config?

Wouldn't a list of linked in AudiodevDriver be more useful to libvirt so it could pick the best available backend to start a VM?

Quoted 4 lines
audio/audio.c +4 -0
+        QAPI_LIST_PREPEND(ret, QAPI_CLONE(Audiodev, e->dev));
+    }
+    return ret;
+}
#3 lore raw

Re: [PATCH v2 1/2] qapi, audio: add query-audiodev command

Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Thomas Huth

From: Daniel P. Berrangé <[email protected]>

Way back in QEMU 4.0, the -audiodev command line option was introduced for configuring audio backends. This CLI option does not use QemuOpts so it is not visible for introspection in 'query-command-line-options', instead using the QAPI Audiodev type. Unfortunately there is also no QMP command that uses the Audiodev type, so it is not introspectable with 'query-qmp-schema' either.

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This alone is maybe not very useful by itself, but it makes Audiodev introspectable via 'query-qmp-schema', so that libvirt (and other upper layer tools) can discover the available audiodevs.

[thuth: Update for upcoming QEMU v8.0, and use QAPI_LIST_PREPEND]
---
  qapi/audio.json | 13 +++++++++++++
  audio/audio.c   | 12 ++++++++++++
  2 files changed, 25 insertions(+)
qapi/audio.json +0 -0
index 1e0a24bdfc..c7aafa2763 100644

qapi/audio.json line 450

Quoted 8 lines
qapi/audio.json +5 -0
@@ -443,3 +443,16 @@
      'sndio':     'AudiodevSndioOptions',
      'spice':     'AudiodevGenericOptions',
      'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration

Maybe clearer as 'audio backends'?

Quoted 3 lines

So similarly, wouldn't be clearer to name this command 'query-audio-backends'? Otherwise we need to go read QEMU source to understand what is 'audiodevs'.

The command line parameter is called '-audiodev' and this query-audiodevs command reports the same data, so that looks easy enough to understand IMHO.

Quoted 37 lines
Quoted 24 lines
qapi/audio.json +8 -0
+#
+# Returns: array of @Audiodev
+#
+# Since: 8.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }
audio/audio.c +2 -0
index d849a94a81..6f270c07b7 100644
@@ -28,8 +28,10 @@
  #include "monitor/monitor.h"
  #include "qemu/timer.h"
  #include "qapi/error.h"
+#include "qapi/clone-visitor.h"
  #include "qapi/qobject-input-visitor.h"
  #include "qapi/qapi-visit-audio.h"
+#include "qapi/qapi-commands-audio.h"
  #include "qemu/cutils.h"
  #include "qemu/module.h"
  #include "qemu/help_option.h"

audio/audio.c size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info, · line 2320

Quoted 8 lines
audio/audio.c +6 -0
@@ -2311,3 +2313,13 @@ size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info,
      return bytes;
  }
+
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL;
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {

I am a bit confused here, isn't &audiodevs containing what the user provided from CLI? How is that useful to libvirt? Maybe the corner case of a user hand-modifying the QEMU launch arguments from a XML config?

Quoted 2 lines

Wouldn't a list of linked in AudiodevDriver be more useful to libvirt so it could pick the best available backend to start a VM?

On the libvirt side we're never going to need to actually call the query-audiodevs commands. The mere existance of the command, means that the QMP schema now exposes information about what audio backends have been compiled into the binary. This is the same trick we've used for other aspects of QMP. IOW we don't need a separate command just for the purpose of listing AudiodevDrivers.

The idea of a query-audiodevs command is useful in general. When we later gain support for hotplug/unplug of audio, the set of audiodevs will no longer be guaranteed to match the original CLI args.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw

Re: [PATCH v2 1/2] qapi, audio: add query-audiodev command

Quoted 89 lines · Daniel P. Berrangé
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Thomas Huth

From: Daniel P. Berrangé <[email protected]>

Way back in QEMU 4.0, the -audiodev command line option was introduced for configuring audio backends. This CLI option does not use QemuOpts so it is not visible for introspection in 'query-command-line-options', instead using the QAPI Audiodev type. Unfortunately there is also no QMP command that uses the Audiodev type, so it is not introspectable with 'query-qmp-schema' either.

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This alone is maybe not very useful by itself, but it makes Audiodev introspectable via 'query-qmp-schema', so that libvirt (and other upper layer tools) can discover the available audiodevs.

[thuth: Update for upcoming QEMU v8.0, and use QAPI_LIST_PREPEND]
---
   qapi/audio.json | 13 +++++++++++++
   audio/audio.c   | 12 ++++++++++++
   2 files changed, 25 insertions(+)
qapi/audio.json +0 -0
index 1e0a24bdfc..c7aafa2763 100644

qapi/audio.json line 450

Quoted 8 lines
qapi/audio.json +5 -0
@@ -443,3 +443,16 @@
       'sndio':     'AudiodevSndioOptions',
       'spice':     'AudiodevGenericOptions',
       'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration

Maybe clearer as 'audio backends'?

Quoted 3 lines

So similarly, wouldn't be clearer to name this command 'query-audio-backends'? Otherwise we need to go read QEMU source to understand what is 'audiodevs'.

The command line parameter is called '-audiodev' and this query-audiodevs command reports the same data, so that looks easy enough to understand IMHO.

Quoted 37 lines
Quoted 24 lines
qapi/audio.json +8 -0
+#
+# Returns: array of @Audiodev
+#
+# Since: 8.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }
audio/audio.c +2 -0
index d849a94a81..6f270c07b7 100644
@@ -28,8 +28,10 @@
   #include "monitor/monitor.h"
   #include "qemu/timer.h"
   #include "qapi/error.h"
+#include "qapi/clone-visitor.h"
   #include "qapi/qobject-input-visitor.h"
   #include "qapi/qapi-visit-audio.h"
+#include "qapi/qapi-commands-audio.h"
   #include "qemu/cutils.h"
   #include "qemu/module.h"
   #include "qemu/help_option.h"

audio/audio.c size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info, · line 2320

Quoted 8 lines
audio/audio.c +6 -0
@@ -2311,3 +2313,13 @@ size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info,
       return bytes;
   }
+
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL;
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {

I am a bit confused here, isn't &audiodevs containing what the user provided from CLI? How is that useful to libvirt? Maybe the corner case of a user hand-modifying the QEMU launch arguments from a XML config?

Quoted 2 lines

Wouldn't a list of linked in AudiodevDriver be more useful to libvirt so it could pick the best available backend to start a VM?

Quoted 6 lines

On the libvirt side we're never going to need to actually call the query-audiodevs commands. The mere existance of the command, means that the QMP schema now exposes information about what audio backends have been compiled into the binary. This is the same trick we've used for other aspects of QMP. IOW we don't need a separate command just for the purpose of listing AudiodevDrivers.

I understand having "what audio backends have been compiled into the binary" is useful, but I am missing how you get that from &audiodevs.

AFAICT &audiodevs is for the CLI parsed backends, not all the backends linked within a binary. I probably need sugar / coffee and will revisit after lunch.

Quoted 6 lines

The idea of a query-audiodevs command is useful in general. When we later gain support for hotplug/unplug of audio, the set of audiodevs will no longer be guaranteed to match the original CLI args.

With regards,
Daniel

#5 lore raw

Re: [PATCH v2 1/2] qapi, audio: add query-audiodev command

Quoted 97 lines · Philippe Mathieu-Daudé
Quoted 89 lines · Daniel P. Berrangé
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Thomas Huth

From: Daniel P. Berrangé <[email protected]>

Way back in QEMU 4.0, the -audiodev command line option was introduced for configuring audio backends. This CLI option does not use QemuOpts so it is not visible for introspection in 'query-command-line-options', instead using the QAPI Audiodev type. Unfortunately there is also no QMP command that uses the Audiodev type, so it is not introspectable with 'query-qmp-schema' either.

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This alone is maybe not very useful by itself, but it makes Audiodev introspectable via 'query-qmp-schema', so that libvirt (and other upper layer tools) can discover the available audiodevs.

[thuth: Update for upcoming QEMU v8.0, and use QAPI_LIST_PREPEND]
---
   qapi/audio.json | 13 +++++++++++++
   audio/audio.c   | 12 ++++++++++++
   2 files changed, 25 insertions(+)
qapi/audio.json +0 -0
index 1e0a24bdfc..c7aafa2763 100644

qapi/audio.json line 450

Quoted 8 lines
qapi/audio.json +5 -0
@@ -443,3 +443,16 @@
       'sndio':     'AudiodevSndioOptions',
       'spice':     'AudiodevGenericOptions',
       'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration

Maybe clearer as 'audio backends'?

Quoted 3 lines

So similarly, wouldn't be clearer to name this command 'query-audio-backends'? Otherwise we need to go read QEMU source to understand what is 'audiodevs'.

The command line parameter is called '-audiodev' and this query-audiodevs command reports the same data, so that looks easy enough to understand IMHO.

Quoted 37 lines
Quoted 24 lines
qapi/audio.json +8 -0
+#
+# Returns: array of @Audiodev
+#
+# Since: 8.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }
audio/audio.c +2 -0
index d849a94a81..6f270c07b7 100644
@@ -28,8 +28,10 @@
   #include "monitor/monitor.h"
   #include "qemu/timer.h"
   #include "qapi/error.h"
+#include "qapi/clone-visitor.h"
   #include "qapi/qobject-input-visitor.h"
   #include "qapi/qapi-visit-audio.h"
+#include "qapi/qapi-commands-audio.h"
   #include "qemu/cutils.h"
   #include "qemu/module.h"
   #include "qemu/help_option.h"

audio/audio.c size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info, · line 2320

Quoted 8 lines
audio/audio.c +6 -0
@@ -2311,3 +2313,13 @@ size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info,
       return bytes;
   }
+
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL;
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {

I am a bit confused here, isn't &audiodevs containing what the user provided from CLI? How is that useful to libvirt? Maybe the corner case of a user hand-modifying the QEMU launch arguments from a XML config?

Quoted 2 lines

Wouldn't a list of linked in AudiodevDriver be more useful to libvirt so it could pick the best available backend to start a VM?

Quoted 6 lines

On the libvirt side we're never going to need to actually call the query-audiodevs commands. The mere existance of the command, means that the QMP schema now exposes information about what audio backends have been compiled into the binary. This is the same trick we've used for other aspects of QMP. IOW we don't need a separate command just for the purpose of listing AudiodevDrivers.

Quoted 6 lines

I understand having "what audio backends have been compiled into the binary" is useful, but I am missing how you get that from &audiodevs.

AFAICT &audiodevs is for the CLI parsed backends, not all the backends linked within a binary. I probably need sugar / coffee and will revisit after lunch.

It ties into the 'query-qmp-schema' command, along with patch #2 in this series.

The query-audiodevs command will cause the 'AudiodevDriver' enum to be reported in the 'query-qmp-schema' response. Patch #2, makes all the AudiodevDriver enum entries conditional on CONFIG_XXXX.

IOW now query-qmp-schema data will tell you what AudiodevDriver backends are compiled into the binary you're talking to.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw

Re: [PATCH v2 1/2] qapi, audio: add query-audiodev command

Quoted 43 lines · Daniel P. Berrangé
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 41 lines · Daniel P. Berrangé
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Thomas Huth

From: Daniel P. Berrangé <[email protected]>

Way back in QEMU 4.0, the -audiodev command line option was introduced for configuring audio backends. This CLI option does not use QemuOpts so it is not visible for introspection in 'query-command-line-options', instead using the QAPI Audiodev type. Unfortunately there is also no QMP command that uses the Audiodev type, so it is not introspectable with 'query-qmp-schema' either.

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This alone is maybe not very useful by itself, but it makes Audiodev introspectable via 'query-qmp-schema', so that libvirt (and other upper layer tools) can discover the available audiodevs.

[thuth: Update for upcoming QEMU v8.0, and use QAPI_LIST_PREPEND]
---
    qapi/audio.json | 13 +++++++++++++
    audio/audio.c   | 12 ++++++++++++
    2 files changed, 25 insertions(+)
qapi/audio.json +0 -0
index 1e0a24bdfc..c7aafa2763 100644

qapi/audio.json line 450

Quoted 8 lines
qapi/audio.json +5 -0
@@ -443,3 +443,16 @@
        'sndio':     'AudiodevSndioOptions',
        'spice':     'AudiodevGenericOptions',
        'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration

Maybe clearer as 'audio backends'?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

So similarly, wouldn't be clearer to name this command 'query-audio-backends'? Otherwise we need to go read QEMU source to understand what is 'audiodevs'.

The command line parameter is called '-audiodev' and this query-audiodevs command reports the same data, so that looks easy enough to understand IMHO.

Should we maybe use a "x-" prefix here if we feel not certain enough about this command yet? ... that would still enable the Audiodev part in the qapi schema, but give us the flexibility to rename or drop it later in case there is some better way to enable the Audiodevs in the schema?

Thomas

#7 lore raw

Re: [PATCH v2 1/2] qapi, audio: add query-audiodev command

Quoted 48 lines · Thomas Huth
Quoted 47 lines · Daniel P. Berrangé
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 45 lines · Daniel P. Berrangé
Quoted 43 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Thomas Huth

From: Daniel P. Berrangé <[email protected]>

Way back in QEMU 4.0, the -audiodev command line option was introduced for configuring audio backends. This CLI option does not use QemuOpts so it is not visible for introspection in 'query-command-line-options', instead using the QAPI Audiodev type. Unfortunately there is also no QMP command that uses the Audiodev type, so it is not introspectable with 'query-qmp-schema' either.

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This alone is maybe not very useful by itself, but it makes Audiodev introspectable via 'query-qmp-schema', so that libvirt (and other upper layer tools) can discover the available audiodevs.

[thuth: Update for upcoming QEMU v8.0, and use QAPI_LIST_PREPEND]
---
    qapi/audio.json | 13 +++++++++++++
    audio/audio.c   | 12 ++++++++++++
    2 files changed, 25 insertions(+)
qapi/audio.json +0 -0
index 1e0a24bdfc..c7aafa2763 100644

qapi/audio.json line 450

Quoted 8 lines
qapi/audio.json +5 -0
@@ -443,3 +443,16 @@
        'sndio':     'AudiodevSndioOptions',
        'spice':     'AudiodevGenericOptions',
        'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration

Maybe clearer as 'audio backends'?

So similarly, wouldn't be clearer to name this command 'query-audio-backends'? Otherwise we need to go read QEMU source to understand what is 'audiodevs'.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The command line parameter is called '-audiodev' and this query-audiodevs command reports the same data, so that looks easy enough to understand IMHO.

Should we maybe use a "x-" prefix here if we feel not certain enough about this command yet? ... that would still enable the Audiodev part in the qapi schema, but give us the flexibility to rename or drop it later in case there is some better way to enable the Audiodevs in the schema?

IMHO there's no reason to add an 'x-' prefix. Even if we found a better way to detect existance of Audiodev backend types, I think query-audiodev is still conceptually a useful command for interogating QEMU's config. To get to our goal of a 100% QMP based replacement for the CLI, we want to have QMP commands for adding, removing and querying every backend config (audiodev, device, object, chardev, netdev, etc). This command addresses one of those gaps for audiodevs

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw

Re: [PATCH v2 1/2] qapi, audio: add query-audiodev command

In reply to Daniel P. Berrangé
Quoted 36 lines · Daniel P. Berrangé
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Daniel P. Berrangé
Quoted 13 lines · Philippe Mathieu-Daudé

audio/audio.c size_t audio_rate_get_bytes(RateCtl *rate, struct audio_pcm_info *info, · line 2321

Quoted 7 lines · Thomas Huth

From: Daniel P. Berrangé <[email protected]>

audio/audio.c +5 -0
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL;
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {

I am a bit confused here, isn't &audiodevs containing what the user provided from CLI? How is that useful to libvirt? Maybe the corner case of a user hand-modifying the QEMU launch arguments from a XML config?

Quoted 2 lines

Wouldn't a list of linked in AudiodevDriver be more useful to libvirt so it could pick the best available backend to start a VM?

Quoted 6 lines

On the libvirt side we're never going to need to actually call the query-audiodevs commands. The mere existance of the command, means that the QMP schema now exposes information about what audio backends have been compiled into the binary. This is the same trick we've used for other aspects of QMP. IOW we don't need a separate command just for the purpose of listing AudiodevDrivers.

Quoted 6 lines

I understand having "what audio backends have been compiled into the binary" is useful, but I am missing how you get that from &audiodevs.

AFAICT &audiodevs is for the CLI parsed backends, not all the backends linked within a binary. I probably need sugar / coffee and will revisit after lunch.

It ties into the 'query-qmp-schema' command, along with patch #2 in this series.

Quoted 6 lines

The query-audiodevs command will cause the 'AudiodevDriver' enum to be reported in the 'query-qmp-schema' response. Patch #2, makes all the AudiodevDriver enum entries conditional on CONFIG_XXXX.

IOW now query-qmp-schema data will tell you what AudiodevDriver backends are compiled into the binary you're talking to.

Thanks for the explanation Daniel.

Just FTR, while I'm not confident enough to add a R-b tag, I am not opposed to it.

Regards,

Phil.

#9 lore raw

PATCH v2 2/2 qapi, audio: Make introspection reflect build configuration more closely

In reply to Thomas Huth

From: Daniel P. Berrangé <[email protected]>

Currently the -audiodev accepts any audiodev type regardless of what is built in to QEMU. An error only occurs later at runtime when a sound device tries to use the audio backend.

With this change QEMU will immediately reject -audiodev args that are not compiled into the binary. The QMP schema will also be introspectable to identify what is compiled in.

This also helps to avoid compiling code that is not required in the binary. Note: When building the audiodevs as modules, the patch only compiles out code for modules that we don't build at all.

[thuth: Rebase, take sndio and dbus devices into account]
---
 qapi/audio.json        | 44 ++++++++++++++++++++++++++++++------------
 audio/audio_template.h | 20 +++++++++++++++++++
 audio/audio.c          | 20 +++++++++++++++++++
 audio/audio_legacy.c   | 41 ++++++++++++++++++++++++++++++++++++++-
 4 files changed, 112 insertions(+), 13 deletions(-)
qapi/audio.json +32 -12
index c7aafa2763..4e54c00f51 100644
@@ -408,8 +408,18 @@
 # Since: 4.0
 ##
 { 'enum': 'AudiodevDriver',
-  'data': [ 'none', 'alsa', 'coreaudio', 'dbus', 'dsound', 'jack', 'oss', 'pa',
-            'sdl', 'sndio', 'spice', 'wav' ] }
+  'data': [ 'none',
+            { 'name': 'alsa', 'if': 'CONFIG_AUDIO_ALSA' },
+            { 'name': 'coreaudio', 'if': 'CONFIG_AUDIO_COREAUDIO' },
+            { 'name': 'dbus', 'if': 'CONFIG_DBUS_DISPLAY' },
+            { 'name': 'dsound', 'if': 'CONFIG_AUDIO_DSOUND' },
+            { 'name': 'jack', 'if': 'CONFIG_AUDIO_JACK' },
+            { 'name': 'oss', 'if': 'CONFIG_AUDIO_OSS' },
+            { 'name': 'pa', 'if': 'CONFIG_AUDIO_PA' },
+            { 'name': 'sdl', 'if': 'CONFIG_AUDIO_SDL' },
+            { 'name': 'sndio', 'if': 'CONFIG_AUDIO_SNDIO' },
+            { 'name': 'spice', 'if': 'CONFIG_SPICE' },
+            'wav' ] }
 
 ##
 # @Audiodev:
@@ -432,16 +442,26 @@
   'discriminator': 'driver',
   'data': {
     'none':      'AudiodevGenericOptions',
-    'alsa':      'AudiodevAlsaOptions',
-    'coreaudio': 'AudiodevCoreaudioOptions',
-    'dbus':      'AudiodevGenericOptions',
-    'dsound':    'AudiodevDsoundOptions',
-    'jack':      'AudiodevJackOptions',
-    'oss':       'AudiodevOssOptions',
-    'pa':        'AudiodevPaOptions',
-    'sdl':       'AudiodevSdlOptions',
-    'sndio':     'AudiodevSndioOptions',
-    'spice':     'AudiodevGenericOptions',
+    'alsa':      { 'type': 'AudiodevAlsaOptions',
+                   'if': 'CONFIG_AUDIO_ALSA' },
+    'coreaudio': { 'type': 'AudiodevCoreaudioOptions',
+                   'if': 'CONFIG_AUDIO_COREAUDIO' },
+    'dbus':      { 'type': 'AudiodevGenericOptions',
+                   'if': 'CONFIG_DBUS_DISPLAY' },
+    'dsound':    { 'type': 'AudiodevDsoundOptions',
+                   'if': 'CONFIG_AUDIO_DSOUND' },
+    'jack':      { 'type': 'AudiodevJackOptions',
+                   'if': 'CONFIG_AUDIO_JACK' },
+    'oss':       { 'type': 'AudiodevOssOptions',
+                   'if': 'CONFIG_AUDIO_OSS' },
+    'pa':        { 'type': 'AudiodevPaOptions',
+                   'if': 'CONFIG_AUDIO_PA' },
+    'sdl':       { 'type': 'AudiodevSdlOptions',
+                   'if': 'CONFIG_AUDIO_SDL' },
+    'sndio':     { 'type': 'AudiodevSndioOptions',
+                   'if': 'CONFIG_AUDIO_SNDIO' },
+    'spice':     { 'type': 'AudiodevGenericOptions',
+                   'if': 'CONFIG_SPICE' },
     'wav':       'AudiodevWavOptions' } }
 
 ##
audio/audio_template.h +20 -0
index 720a32e57e..42b4712acb 100644
@@ -326,27 +326,47 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
     switch (dev->driver) {
     case AUDIODEV_DRIVER_NONE:
         return dev->u.none.TYPE;
+#ifdef CONFIG_AUDIO_ALSA
     case AUDIODEV_DRIVER_ALSA:
         return qapi_AudiodevAlsaPerDirectionOptions_base(dev->u.alsa.TYPE);
+#endif
+#ifdef CONFIG_AUDIO_COREAUDIO
     case AUDIODEV_DRIVER_COREAUDIO:
         return qapi_AudiodevCoreaudioPerDirectionOptions_base(
             dev->u.coreaudio.TYPE);
+#endif
+#ifdef CONFIG_DBUS_DISPLAY
     case AUDIODEV_DRIVER_DBUS:
         return dev->u.dbus.TYPE;
+#endif
+#ifdef CONFIG_AUDIO_DSOUND
     case AUDIODEV_DRIVER_DSOUND:
         return dev->u.dsound.TYPE;
+#endif
+#ifdef CONFIG_AUDIO_JACK
     case AUDIODEV_DRIVER_JACK:
         return qapi_AudiodevJackPerDirectionOptions_base(dev->u.jack.TYPE);
+#endif
+#ifdef CONFIG_AUDIO_OSS
     case AUDIODEV_DRIVER_OSS:
         return qapi_AudiodevOssPerDirectionOptions_base(dev->u.oss.TYPE);
+#endif
+#ifdef CONFIG_AUDIO_PA
     case AUDIODEV_DRIVER_PA:
         return qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.TYPE);
+#endif
+#ifdef CONFIG_AUDIO_SDL
     case AUDIODEV_DRIVER_SDL:
         return qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.TYPE);
+#endif
+#ifdef CONFIG_AUDIO_SNDIO
     case AUDIODEV_DRIVER_SNDIO:
         return dev->u.sndio.TYPE;
+#endif
+#ifdef CONFIG_SPICE
     case AUDIODEV_DRIVER_SPICE:
         return dev->u.spice.TYPE;
+#endif
     case AUDIODEV_DRIVER_WAV:
         return dev->u.wav.TYPE;
 
audio/audio.c +20 -0
index 6f270c07b7..4290309d18 100644
@@ -2048,16 +2048,36 @@ void audio_create_pdos(Audiodev *dev)
         break
 
         CASE(NONE, none, );
+#ifdef CONFIG_AUDIO_ALSA
         CASE(ALSA, alsa, Alsa);
+#endif
+#ifdef CONFIG_AUDIO_COREAUDIO
         CASE(COREAUDIO, coreaudio, Coreaudio);
+#endif
+#ifdef CONFIG_DBUS_DISPLAY
         CASE(DBUS, dbus, );
+#endif
+#ifdef CONFIG_AUDIO_DSOUND
         CASE(DSOUND, dsound, );
+#endif
+#ifdef CONFIG_AUDIO_JACK
         CASE(JACK, jack, Jack);
+#endif
+#ifdef CONFIG_AUDIO_OSS
         CASE(OSS, oss, Oss);
+#endif
+#ifdef CONFIG_AUDIO_PA
         CASE(PA, pa, Pa);
+#endif
+#ifdef CONFIG_AUDIO_SDL
         CASE(SDL, sdl, Sdl);
+#endif
+#ifdef CONFIG_AUDIO_SNDIO
         CASE(SNDIO, sndio, );
+#endif
+#ifdef CONFIG_SPICE
         CASE(SPICE, spice, );
+#endif
         CASE(WAV, wav, );
 
     case AUDIODEV_DRIVER__MAX:
audio/audio_legacy.c +40 -1

160 lines not on this page · raw message

Signature · 1 line
2.31.1
#10 lore raw
In reply to Thomas Huth
Quoted 13 lines · Thomas Huth

Here's a respin from Daniel's audiodev introspection patches from 2021. I've rebased them to the current master branch and addressed the review comments from v1.

The Audiodev QAPI type is not introspectable via query-qmp-schema as nothing in QMP uses it. "-audiodev" is not introspectable via query-command-line-options because it avoided legacy QemuOpts.

To fix it, introduce a tiny "query-audiodev" QMP command that uses the "Audiodev" QAPI structure, so that it shows up in the schema. Then mark the various backend types with conditionals so that only the ones that were available at compile time show up in the schema.

Quoted 4 lines

Daniel P. Berrangé (2):
qapi, audio: add query-audiodev command
qapi, audio: Make introspection reflect build configuration more
closely

Since there were no objections and since Gerd seems to be pretty busy with other stuff recently, I'll dare to pick these up for my next pull request.

Thomas