Skip to contentSkip to conversation

audio: make audiodev introspectable by mgmt apps

PATCH In review Daniel P. Berrangé 6 participants 23 messages Mar 2, 2021 – Dec 14, 2022

lore
Share & tools
lore
#0 lore raw

cover audio: make audiodev introspectable by mgmt apps

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

Even once that is fixed, the introspection lies about what is actually possible because nearly all the audio backends are compile time conditional, but the QAPI schema is fixed.

The last patch is a trivial addition that aided my debugging while investigating the problems and not directly related/dependant.

Daniel P. Berrangé (3):
qapi, audio: add query-audiodev command
qapi, audio: respect build time conditions in audio schema
qapi: provide a friendly string representation of QAPI classes

 audio/audio.c          | 35 ++++++++++++++++++++++++++
 audio/audio_legacy.c   | 41 +++++++++++++++++++++++++++++-
 audio/audio_template.h | 16 ++++++++++++
 qapi/audio.json        | 57 ++++++++++++++++++++++++++++++++++--------
 scripts/qapi/schema.py |  3 +++
 5 files changed, 141 insertions(+), 11 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

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

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 in turn makes Audiodev introspectable via 'query-qmp-schema'.

---
 audio/audio.c   | 19 +++++++++++++++++++
 qapi/audio.json | 13 +++++++++++++
 2 files changed, 32 insertions(+)
audio/audio.c +19 -0
index 6734c8af70..40a4bbd7ce 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 "sysemu/replay.h"
@@ -2201,3 +2203,20 @@ size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
     rate->bytes_sent += ret;
     return ret;
 }
+
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL, *prev = NULL, *curr;
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {
+        curr = g_new0(AudiodevList, 1);
+        curr->value = QAPI_CLONE(Audiodev, e->dev);
+        if (prev) {
+            prev->next = curr;
+            prev = curr;
+        } else {
+            ret = prev = curr;
+        }
+    }
+    return ret;
+}
qapi/audio.json +13 -0
index 9cba0df8a4..d7b91230d7 100644
@@ -419,3 +419,16 @@
     'sdl':       'AudiodevSdlOptions',
     'spice':     'AudiodevGenericOptions',
     'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev
+#
+# Since: 6.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }
Signature · 1 line
2.29.2
#2 lore raw

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

Quoted 10 lines · Daniel P. Berrangé

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 in turn makes Audiodev introspectable via 'query-qmp-schema'.

Even if we never call the query-audiodev command, its mere existence is useful ;)

Quoted 11 lines
---
 audio/audio.c   | 19 +++++++++++++++++++
 qapi/audio.json | 13 +++++++++++++
 2 files changed, 32 insertions(+)
audio/audio.c +3 -0
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL, *prev = NULL, *curr;

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

Quoted 10 lines
audio/audio.c +10 -0
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {
+        curr = g_new0(AudiodevList, 1);
+        curr->value = QAPI_CLONE(Audiodev, e->dev);
+        if (prev) {
+            prev->next = curr;
+            prev = curr;
+        } else {
+            ret = prev = curr;
+        }

Please use QAPI_LIST_PREPEND here instead of open-coding it.

Quoted 4 lines
qapi/audio.json +3 -0
+
+##
+# @query-audiodevs:

qapi/audio.json line 434

Quoted 10 lines
qapi/audio.json +10 -0
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev
+#
+# Since: 6.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }

Otherwise looks nice.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

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

In reply to Daniel P. Berrangé
Quoted 21 lines · Daniel P. Berrangé

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 in turn makes Audiodev introspectable via 'query-qmp-schema'.

---
 audio/audio.c   | 19 +++++++++++++++++++
 qapi/audio.json | 13 +++++++++++++
 2 files changed, 32 insertions(+)
qapi/audio.json +3 -0
+
+##
+# @query-audiodevs:

qapi/audio.json line 434

Quoted 10 lines
qapi/audio.json +10 -0
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev
+#
+# Since: 6.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }

Can we use 'query-audiodev-backends' similarly to
'query-chardev-backends'?

#4 lore raw

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

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Daniel P. Berrangé

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 in turn makes Audiodev introspectable via 'query-qmp-schema'.

---
 audio/audio.c   | 19 +++++++++++++++++++
 qapi/audio.json | 13 +++++++++++++
 2 files changed, 32 insertions(+)
Quoted 7 lines

qapi/audio.json line 428

Quoted 7 lines
qapi/audio.json +7 -0
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev

Also with chardev we return ChardevBackendInfo. I'm not sure if this is because I'm custom to read it, but it seems clearer. Can we return a AudiodevBackendInfo type?

Quoted 11 lines

qapi/audio.json line 434

Quoted 7 lines
qapi/audio.json +6 -0
+#
+# Since: 6.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }

Can we use 'query-audiodev-backends' similarly to
'query-chardev-backends'?

#5 lore raw

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

Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Daniel P. Berrangé

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 in turn makes Audiodev introspectable via 'query-qmp-schema'.

---
 audio/audio.c   | 19 +++++++++++++++++++
 qapi/audio.json | 13 +++++++++++++
 2 files changed, 32 insertions(+)
Quoted 11 lines
Quoted 7 lines

qapi/audio.json line 428

Quoted 7 lines
qapi/audio.json +7 -0
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev

Also with chardev we return ChardevBackendInfo. I'm not sure if this is because I'm custom to read it, but it seems clearer. Can we return a AudiodevBackendInfo type?

Chardevs are not a good guide as they have this wierd split betweeen manually written Chardev type and QAPI driven ChardeBackendInfo type.

With audio backends, we only have the Audiodev QAPI type. There is no AudiodevBackendInfo.

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 1/3] qapi, audio: add query-audiodev command

In reply to Philippe Mathieu-Daudé
Quoted 27 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Daniel P. Berrangé

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 in turn makes Audiodev introspectable via 'query-qmp-schema'.

---
 audio/audio.c   | 19 +++++++++++++++++++
 qapi/audio.json | 13 +++++++++++++
 2 files changed, 32 insertions(+)
qapi/audio.json +9 -0
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev
+#
+# Since: 6.0
Quoted 8 lines

qapi/audio.json line 434

Quoted 5 lines
qapi/audio.json +4 -0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }

Can we use 'query-audiodev-backends' similarly to
'query-chardev-backends'?

IMHO adding "-backends" is redundant, because audiodev and chardev objects are always backends.

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 :|
#7 lore raw

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

In reply to Daniel P. Berrangé
Quoted 6 lines · Daniel P. Berrangé

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 is a gap that will only widen.

By design, query-qmp-schema covers just QMP. It doesn't cover the QAPIfied parts of the CLI. They have been growing slowly, and this trend will continue. We need schema introspection to cover the CLI, too. Observation, not demand.

Work-arounds:

1. When a QMP command equivalent to a QAPIfied CLI option exists, introspect that. Involves hardcoding the connection between the two.
Example: -blockdev and blockdev-add.

2. When a QMP query exists that returns the CLI option argument, introspect that. Involves hardcoding the connection between the two.
Example: -display and query-display-options.

3. When neither exists, create a suitable query just to enable introspection. Example: query-display-options. Commit e1ca8f7e19 "qapi: add query-display-options command" explains this clearly:

Add query-display-options command, which allows querying the qemu display configuration. This isn't particularly useful, except it exposes QAPI type DisplayOptions in query-qmp-schema, so that libvirt can discover recently added -display parameter rendernode (commit d4dc4ab133b). Works around lack of sufficiently powerful command line introspection.

Quoted 3 lines

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This in turn makes Audiodev introspectable via 'query-qmp-schema'.

Is the query just for enabling introspection, or does it have other uses?

If the former, please steal from Gerd's explanation for your commit message.

Quoted 30 lines
---
 audio/audio.c   | 19 +++++++++++++++++++
 qapi/audio.json | 13 +++++++++++++
 2 files changed, 32 insertions(+)
audio/audio.c +6 -0
index 6734c8af70..40a4bbd7ce 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 "sysemu/replay.h"
@@ -2201,3 +2203,20 @@ size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
     rate->bytes_sent += ret;
     return ret;
 }
+
+AudiodevList *qmp_query_audiodevs(Error **errp)
+{
+    AudiodevList *ret = NULL, *prev = NULL, *curr;

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

Quoted 10 lines
audio/audio.c +10 -0
+    AudiodevListEntry *e;
+    QSIMPLEQ_FOREACH(e, &audiodevs, next) {
+        curr = g_new0(AudiodevList, 1);
+        curr->value = QAPI_CLONE(Audiodev, e->dev);
+        if (prev) {
+            prev->next = curr;
+            prev = curr;
+        } else {
+            ret = prev = curr;
+        }

Please use QAPI_LIST_APPEND().

Quoted 24 lines
audio/audio.c +3 -0
+    }
+    return ret;
+}
qapi/audio.json +13 -0
index 9cba0df8a4..d7b91230d7 100644
@@ -419,3 +419,16 @@
     'sdl':       'AudiodevSdlOptions',
     'spice':     'AudiodevGenericOptions',
     'wav':       'AudiodevWavOptions' } }
+
+##
+# @query-audiodevs:
+#
+# Returns information about audiodev configuration
+#
+# Returns: array of @Audiodev
+#
+# Since: 6.0
+#
+##
+{ 'command': 'query-audiodevs',
+  'returns': ['Audiodev'] }
#8 lore raw

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

Quoted 16 lines · Markus Armbruster
Quoted 6 lines · Daniel P. Berrangé

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 is a gap that will only widen.

By design, query-qmp-schema covers just QMP. It doesn't cover the QAPIfied parts of the CLI. They have been growing slowly, and this trend will continue. We need schema introspection to cover the CLI, too. Observation, not demand.

Quoted 5 lines

Work-arounds:

1. When a QMP command equivalent to a QAPIfied CLI option exists, introspect that. Involves hardcoding the connection between the two.
Example: -blockdev and blockdev-add.

I'd say this is the scenario that wil lapply long term. As we aim for a world where you can run "qemu -qmp unix:/tmp/sock,server" and then configure everything over QMP, we should cease to have any scenarios where stuff is missing from query-qmp-schemas, as we'll have a QMP command that covers everything.

IOW, in this case we really ought to have a 'audiodev-add' command as a counterpart to -audiodev CLI. Not sure if there

are any dragons wrt to creating audio backends on the fly.

Quoted 8 lines

2. When a QMP query exists that returns the CLI option argument, introspect that. Involves hardcoding the connection between the two.
Example: -display and query-display-options.

3. When neither exists, create a suitable query just to enable introspection. Example: query-display-options. Commit e1ca8f7e19 "qapi: add query-display-options command" explains this clearly:

Quoted 6 lines

Add query-display-options command, which allows querying the qemu display configuration. This isn't particularly useful, except it exposes QAPI type DisplayOptions in query-qmp-schema, so that libvirt can discover recently added -display parameter rendernode (commit d4dc4ab133b). Works around lack of sufficiently powerful command line introspection.

I figure having a 'query-foo' QMP corresponding to any 'foo-add' QMP is useful as a general rule to allow mgmt (or human support engineers) to inspect an running instance and understand its configuration, especially since it won't be visible in CLI args if we move to 100% QMP based config.

Quoted 6 lines
Quoted 3 lines

This introduces a 'query-audiodev' command that simply reflects back the list of configured -audiodev command line options. This in turn makes Audiodev introspectable via 'query-qmp-schema'.

Is the query just for enabling introspection, or does it have other uses?

On the libvirt side we only need it for enabling introspection.

As a general rule, being able to inspect any aspect of configuration via QMP is useful for support purposes if nothing else.

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 :|
#9 lore raw

PATCH 2/3 qapi, audio: respect build time conditions in audio schema

In reply to Daniel P. Berrangé

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.

---
 audio/audio.c          | 16 +++++++++++++++
 audio/audio_legacy.c   | 41 ++++++++++++++++++++++++++++++++++++++-
 audio/audio_template.h | 16 +++++++++++++++
 qapi/audio.json        | 44 ++++++++++++++++++++++++++++++++----------
 4 files changed, 106 insertions(+), 11 deletions(-)
audio/audio.c +16 -0
index 40a4bbd7ce..53434fc674 100644
@@ -1989,14 +1989,30 @@ 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_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_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

audio/audio_template.h +16 -0
index c6714946aa..0847b643be 100644
@@ -322,23 +322,39 @@ 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_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_SPICE
     case AUDIODEV_DRIVER_SPICE:
         return dev->u.spice.TYPE;
+#endif
     case AUDIODEV_DRIVER_WAV:
         return dev->u.wav.TYPE;
 
qapi/audio.json +34 -10

56 lines not on this page · raw message

Signature · 1 line
2.29.2
Reviewed-by on v1 2/3
#10 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

Quoted 7 lines · Daniel P. Berrangé

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.

Nice!

Quoted 25 lines
---
 audio/audio.c          | 16 +++++++++++++++
 audio/audio_legacy.c   | 41 ++++++++++++++++++++++++++++++++++++++-
 audio/audio_template.h | 16 +++++++++++++++
 qapi/audio.json        | 44 ++++++++++++++++++++++++++++++++----------
 4 files changed, 106 insertions(+), 11 deletions(-)

+++ b/qapi/audio.json

qapi/audio.json +8 -2
@@ -386,8 +386,24 @@
 # Since: 4.0
 ##
 { 'enum': 'AudiodevDriver',
-  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa',
-            'sdl', 'spice', 'wav' ] }
+  'data': [ 'none',
+            { 'name': 'alsa',
+              'if': 'defined(CONFIG_AUDIO_ALSA)' },
+            { 'name': 'coreaudio',
+              'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
+            { 'name': 'dsound',
+              'if': 'defined(CONFIG_AUDIO_DSOUND)' },
+            { 'name': 'jack',

qapi/audio.json line 406

Quoted 10 lines
qapi/audio.json +10 -0
+              'if': 'defined(CONFIG_AUDIO_JACK)' },
+            { 'name': 'oss',
+              'if': 'defined(CONFIG_AUDIO_OSS)' },
+            { 'name': 'pa',
+              'if': 'defined(CONFIG_AUDIO_PA)' },
+            { 'name': 'sdl',
+              'if': 'defined(CONFIG_AUDIO_SDL)' },
+            { 'name': 'spice',
+              'if': 'defined(CONFIG_SPICE)' },
+            'wav' ] }

I'll trust that you compiled multiple times to test the various interplays between options.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#11 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

Quoted 41 lines · Eric Blake
Quoted 7 lines · Daniel P. Berrangé

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.

Nice!

Quoted 30 lines
---
 audio/audio.c          | 16 +++++++++++++++
 audio/audio_legacy.c   | 41 ++++++++++++++++++++++++++++++++++++++-
 audio/audio_template.h | 16 +++++++++++++++
 qapi/audio.json        | 44 ++++++++++++++++++++++++++++++++----------
 4 files changed, 106 insertions(+), 11 deletions(-)

+++ b/qapi/audio.json

qapi/audio.json +13 -2
@@ -386,8 +386,24 @@
 # Since: 4.0
 ##
 { 'enum': 'AudiodevDriver',
-  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa',
-            'sdl', 'spice', 'wav' ] }
+  'data': [ 'none',
+            { 'name': 'alsa',
+              'if': 'defined(CONFIG_AUDIO_ALSA)' },
+            { 'name': 'coreaudio',
+              'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
+            { 'name': 'dsound',
+              'if': 'defined(CONFIG_AUDIO_DSOUND)' },
+            { 'name': 'jack',
+              'if': 'defined(CONFIG_AUDIO_JACK)' },
+            { 'name': 'oss',
+              'if': 'defined(CONFIG_AUDIO_OSS)' },
+            { 'name': 'pa',
+              'if': 'defined(CONFIG_AUDIO_PA)' },
Quoted 8 lines

qapi/audio.json line 406

Quoted 5 lines
qapi/audio.json +5 -0
+            { 'name': 'sdl',
+              'if': 'defined(CONFIG_AUDIO_SDL)' },
+            { 'name': 'spice',
+              'if': 'defined(CONFIG_SPICE)' },
+            'wav' ] }

I'll trust that you compiled multiple times to test the various interplays between options.

No, just sent it through gitlab CI which I assumed would cover it

Quoted 2 lines

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 :|
#12 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

In reply to Daniel P. Berrangé
Quoted 7 lines · Daniel P. Berrangé

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.

Note that audio backends are modularized, so "compiled with CONFIG_AUDIO_ALSA" doesn't imply "alsa support is available".

take care,
Gerd

#13 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

Quoted 11 lines · Gerd Hoffmann
Quoted 7 lines · Daniel P. Berrangé

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.

Note that audio backends are modularized, so "compiled with CONFIG_AUDIO_ALSA" doesn't imply "alsa support is available".

AFAIK, there's no way to handle this with QAPI schema reporting. We can only conditionalize based on what's available at compile time, not what's installed at runtime.

To get runtime info, we would have to introduce an explicit "query-audiodev-types" command where just report the backends that have been installed.

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 :|
#14 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

Quoted 10 lines · Daniel P. Berrangé
Quoted 9 lines · Gerd Hoffmann
Quoted 7 lines · Daniel P. Berrangé

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.

Quoted 6 lines
Quoted 2 lines

Note that audio backends are modularized, so "compiled with CONFIG_AUDIO_ALSA" doesn't imply "alsa support is available".

AFAIK, there's no way to handle this with QAPI schema reporting. We can only conditionalize based on what's available at compile time, not what's installed at runtime.

Correct. The schema is fixed at compile-time. query-qmp-schema reflects what we compiled into the binary or modules we built along with the binary. It cannot tell which of the modules the binary can load.

I'd like the commit message to discuss how the patch interacts with modules, because my own memory of the details is rather uncertain :)

I guess we can configure which audio backends to build, and whether to build them as modules.

When not building them as modules, the patch compiles out some useless code. Correct?

When building them as modules, the patch compiles out code for modules we don't build. Correct?

Such code is useless, unless you somehow manage to supply the resulting binary with working modules from another build. Which is probably a bad idea. Compiling out the code stops this (questionable) usage cold. No objection, but the commit message should at least hint at it.

Quoted 3 lines

To get runtime info, we would have to introduce an explicit "query-audiodev-types" command where just report the backends that have been installed.

TTOCTOU. Harmless one. Still, the robust check for "can module M be loaded?" is to try loading it.

#15 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

Quoted 23 lines · Markus Armbruster
Quoted 10 lines · Daniel P. Berrangé
Quoted 9 lines · Gerd Hoffmann
Quoted 7 lines · Daniel P. Berrangé

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.

Quoted 6 lines
Quoted 2 lines

Note that audio backends are modularized, so "compiled with CONFIG_AUDIO_ALSA" doesn't imply "alsa support is available".

AFAIK, there's no way to handle this with QAPI schema reporting. We can only conditionalize based on what's available at compile time, not what's installed at runtime.

Correct. The schema is fixed at compile-time. query-qmp-schema reflects what we compiled into the binary or modules we built along with the binary. It cannot tell which of the modules the binary can load.

Quoted 8 lines

I'd like the commit message to discuss how the patch interacts with modules, because my own memory of the details is rather uncertain :)

I guess we can configure which audio backends to build, and whether to build them as modules.

When not building them as modules, the patch compiles out some useless code. Correct?

Yes.

Quoted 2 lines

When building them as modules, the patch compiles out code for modules we don't build. Correct?

Yes.

Quoted 11 lines

Such code is useless, unless you somehow manage to supply the resulting binary with working modules from another build. Which is probably a bad idea. Compiling out the code stops this (questionable) usage cold. No objection, but the commit message should at least hint at it.

Quoted 3 lines

To get runtime info, we would have to introduce an explicit "query-audiodev-types" command where just report the backends that have been installed.

TTOCTOU. Harmless one. Still, the robust check for "can module M be loaded?" is to try loading it.

Ultimately from libvirt's POV, the introspection is merely used to let libvirt report errors about unsupported configurations earlier. So if we don't deal with compiled-but-not-installed modules, then the effect is that libvirt won't report errors if user requests 'alsa', but QEMU will eventually report such an error when it starts. So I'm not too worried about optimizing to cope with modules.

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 :|
Acked-by on v1 2/3
#16 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

In reply to Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé

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.

Subject "qapi, audio: respect build time conditions in audio schema" feels too narrow. The patch goes beyond the schema, because it has to:
guarding QAPI schema parts with 'if' requires guarding use of C code generated for it with #if.

An easy way out is perhaps stating just the aim:

audio: Make introspection reflect build configuration

This assumes the patch does a complete job. If there's more audio build configuration to reflect, add a suitable qualifier like "more closely".

Fun: before the patch, the CONFIG_AUDIO_ conditionals are effectively applied just to output of -help.

[...]

Quoted 52 lines
qapi/audio.json +27 -10
index d7b91230d7..9af1b8140c 100644
@@ -386,8 +386,24 @@
 # Since: 4.0
 ##
 { 'enum': 'AudiodevDriver',
-  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa',
-            'sdl', 'spice', 'wav' ] }
+  'data': [ 'none',
+            { 'name': 'alsa',
+              'if': 'defined(CONFIG_AUDIO_ALSA)' },
+            { 'name': 'coreaudio',
+              'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
+            { 'name': 'dsound',
+              'if': 'defined(CONFIG_AUDIO_DSOUND)' },
+            { 'name': 'jack',
+              'if': 'defined(CONFIG_AUDIO_JACK)' },
+            { 'name': 'oss',
+              'if': 'defined(CONFIG_AUDIO_OSS)' },
+            { 'name': 'pa',
+              'if': 'defined(CONFIG_AUDIO_PA)' },
+            { 'name': 'sdl',
+              'if': 'defined(CONFIG_AUDIO_SDL)' },
+            { 'name': 'spice',
+              'if': 'defined(CONFIG_SPICE)' },
+            'wav' ] }
 
 ##
 # @Audiodev:
@@ -410,14 +426,22 @@
   'discriminator': 'driver',
   'data': {
     'none':      'AudiodevGenericOptions',
-    'alsa':      'AudiodevAlsaOptions',
-    'coreaudio': 'AudiodevCoreaudioOptions',
-    'dsound':    'AudiodevDsoundOptions',
-    'jack':      'AudiodevJackOptions',
-    'oss':       'AudiodevOssOptions',
-    'pa':        'AudiodevPaOptions',
-    'sdl':       'AudiodevSdlOptions',
-    'spice':     'AudiodevGenericOptions',
+    'alsa':      { 'type': 'AudiodevAlsaOptions',
+                   'if': 'defined(CONFIG_AUDIO_ALSA)' },
+    'coreaudio': { 'type': 'AudiodevCoreaudioOptions',
+                   'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
+    'dsound':    { 'type': 'AudiodevDsoundOptions',
+                   'if': 'defined(CONFIG_AUDIO_DSOUND)' },
+    'jack':      { 'type': 'AudiodevJackOptions',
+                   'if': 'defined(CONFIG_AUDIO_JACK)' },
+    'oss':       { 'type': 'AudiodevOssOptions',

qapi/audio.json line 447

Quoted 10 lines
qapi/audio.json +7 -0
+                   'if': 'defined(CONFIG_AUDIO_OSS)' },
+    'pa':        { 'type': 'AudiodevPaOptions',
+                   'if': 'defined(CONFIG_AUDIO_PA)' },
+    'sdl':       { 'type': 'AudiodevSdlOptions',
+                   'if': 'defined(CONFIG_AUDIO_SDL)' },
+    'spice':     { 'type': 'AudiodevGenericOptions',
+                   'if': 'defined(CONFIG_SPICE)' },
     'wav':       'AudiodevWavOptions' } }
 
 ##

For the QAPI schema part:

#17 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

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.

Quoted 7 lines
---
  audio/audio.c          | 16 +++++++++++++++
  audio/audio_legacy.c   | 41 ++++++++++++++++++++++++++++++++++++++-
  audio/audio_template.h | 16 +++++++++++++++
  qapi/audio.json        | 44 ++++++++++++++++++++++++++++++++----------
  4 files changed, 106 insertions(+), 11 deletions(-)

Hi Daniel!

Would you have time to respin this patch for QEMU 8.0 ?

Thomas

Quoted 317 lines
audio/audio.c +16 -0
index 40a4bbd7ce..53434fc674 100644
@@ -1989,14 +1989,30 @@ 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_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_SPICE
          CASE(SPICE, spice, );
+#endif
          CASE(WAV, wav, );
 
      case AUDIODEV_DRIVER__MAX:
audio/audio_legacy.c +40 -1
index 0fe827b057..bb2268f2b2 100644
@@ -93,6 +93,7 @@ static void get_fmt(const char *env, AudioFormat *dst, bool *has_dst)
  }
 
 
+#if defined(CONFIG_AUDIO_ALSA) || defined(CONFIG_AUDIO_DSOUND)
  static void get_millis_to_usecs(const char *env, uint32_t *dst, bool *has_dst)
  {
      const char *val = getenv(env);
@@ -101,15 +102,20 @@ static void get_millis_to_usecs(const char *env, uint32_t *dst, bool *has_dst)
          *has_dst = true;
      }
  }
+#endif
 
+#if defined(CONFIG_AUDIO_ALSA) || defined(CONFIG_AUDIO_COREAUDIO) || \
+    defined(CONFIG_AUDIO_PA) || defined(CONFIG_AUDIO_SDL) || \
+    defined(CONFIG_AUDIO_DSOUND) || defined(CONFIG_AUDIO_OSS)
  static uint32_t frames_to_usecs(uint32_t frames,
                                  AudiodevPerDirectionOptions *pdo)
  {
      uint32_t freq = pdo->has_frequency ? pdo->frequency : 44100;
      return (frames * 1000000 + freq / 2) / freq;
  }
+#endif
 
-
+#ifdef CONFIG_AUDIO_COREAUDIO
  static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
                                  AudiodevPerDirectionOptions *pdo)
  {
@@ -119,14 +125,19 @@ static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
          *has_dst = true;
      }
  }
+#endif
 
+#if defined(CONFIG_AUDIO_PA) || defined(CONFIG_AUDIO_SDL) || \
+    defined(CONFIG_AUDIO_DSOUND) || defined(CONFIG_AUDIO_OSS)
  static uint32_t samples_to_usecs(uint32_t samples,
                                   AudiodevPerDirectionOptions *pdo)
  {
      uint32_t channels = pdo->has_channels ? pdo->channels : 2;
      return frames_to_usecs(samples / channels, pdo);
  }
+#endif
 
+#if defined(CONFIG_AUDIO_PA) || defined(CONFIG_AUDIO_SDL)
  static void get_samples_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
                                   AudiodevPerDirectionOptions *pdo)
  {
@@ -136,7 +147,9 @@ static void get_samples_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
          *has_dst = true;
      }
  }
+#endif
 
+#if defined(CONFIG_AUDIO_DSOUND) || defined(CONFIG_AUDIO_OSS)
  static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions *pdo)
  {
      AudioFormat fmt = pdo->has_format ? pdo->format : AUDIO_FORMAT_S16;
@@ -153,8 +166,11 @@ static void get_bytes_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
          *has_dst = true;
      }
  }
+#endif
 
  /* backend specific functions */
+
+#ifdef CONFIG_AUDIO_ALSA
  /* ALSA */
  static void handle_alsa_per_direction(
      AudiodevAlsaPerDirectionOptions *apdo, const char *prefix)
@@ -200,7 +216,9 @@ static void handle_alsa(Audiodev *dev)
      get_millis_to_usecs("QEMU_ALSA_THRESHOLD",
                          &aopt->threshold, &aopt->has_threshold);
  }
+#endif
 
+#ifdef CONFIG_AUDIO_COREAUDIO
  /* coreaudio */
  static void handle_coreaudio(Audiodev *dev)
  {
@@ -213,7 +231,9 @@ static void handle_coreaudio(Audiodev *dev)
              &dev->u.coreaudio.out->buffer_count,
              &dev->u.coreaudio.out->has_buffer_count);
  }
+#endif
 
+#ifdef CONFIG_AUDIO_DSOUND
  /* dsound */
  static void handle_dsound(Audiodev *dev)
  {
@@ -228,7 +248,9 @@ static void handle_dsound(Audiodev *dev)
                         &dev->u.dsound.in->has_buffer_length,
                         dev->u.dsound.in);
  }
+#endif
 
+#ifdef CONFIG_AUDIO_OSS
  /* OSS */
  static void handle_oss_per_direction(
      AudiodevOssPerDirectionOptions *opdo, const char *try_poll_env,
@@ -256,7 +278,9 @@ static void handle_oss(Audiodev *dev)
      get_bool("QEMU_OSS_EXCLUSIVE", &oopt->exclusive, &oopt->has_exclusive);
      get_int("QEMU_OSS_POLICY", &oopt->dsp_policy, &oopt->has_dsp_policy);
  }
+#endif
 
+#ifdef CONFIG_AUDIO_PA
  /* pulseaudio */
  static void handle_pa_per_direction(
      AudiodevPaPerDirectionOptions *ppdo, const char *env)
@@ -280,7 +304,9 @@ static void handle_pa(Audiodev *dev)
 
      get_str("QEMU_PA_SERVER", &dev->u.pa.server, &dev->u.pa.has_server);
  }
+#endif
 
+#ifdef CONFIG_AUDIO_SDL
  /* SDL */
  static void handle_sdl(Audiodev *dev)
  {
@@ -289,6 +315,7 @@ static void handle_sdl(Audiodev *dev)
          &dev->u.sdl.out->has_buffer_length,
          qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.out));
  }
+#endif
 
  /* wav */
  static void handle_wav(Audiodev *dev)
@@ -348,29 +375,41 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
      }
 
      switch (e->dev->driver) {
+#ifdef CONFIG_AUDIO_ALSA
      case AUDIODEV_DRIVER_ALSA:
          handle_alsa(e->dev);
          break;
+#endif
 
+#ifdef CONFIG_AUDIO_COREAUDIO
      case AUDIODEV_DRIVER_COREAUDIO:
          handle_coreaudio(e->dev);
          break;
+#endif
 
+#ifdef CONFIG_AUDIO_DSOUND
      case AUDIODEV_DRIVER_DSOUND:
          handle_dsound(e->dev);
          break;
+#endif
 
+#ifdef CONFIG_AUDIO_OSS
      case AUDIODEV_DRIVER_OSS:
          handle_oss(e->dev);
          break;
+#endif
 
+#ifdef CONFIG_AUDIO_PA
      case AUDIODEV_DRIVER_PA:
          handle_pa(e->dev);
          break;
+#endif
 
+#ifdef CONFIG_AUDIO_SDL
      case AUDIODEV_DRIVER_SDL:
          handle_sdl(e->dev);
          break;
+#endif
 
      case AUDIODEV_DRIVER_WAV:
          handle_wav(e->dev);
audio/audio_template.h +16 -0
index c6714946aa..0847b643be 100644
@@ -322,23 +322,39 @@ 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_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_SPICE
      case AUDIODEV_DRIVER_SPICE:
          return dev->u.spice.TYPE;
+#endif
      case AUDIODEV_DRIVER_WAV:
          return dev->u.wav.TYPE;
 
qapi/audio.json +34 -10
index d7b91230d7..9af1b8140c 100644
@@ -386,8 +386,24 @@
  # Since: 4.0
  ##
  { 'enum': 'AudiodevDriver',
-  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa',
-            'sdl', 'spice', 'wav' ] }
+  'data': [ 'none',
+            { 'name': 'alsa',
+              'if': 'defined(CONFIG_AUDIO_ALSA)' },
+            { 'name': 'coreaudio',
+              'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
+            { 'name': 'dsound',
+              'if': 'defined(CONFIG_AUDIO_DSOUND)' },
+            { 'name': 'jack',
+              'if': 'defined(CONFIG_AUDIO_JACK)' },
+            { 'name': 'oss',
+              'if': 'defined(CONFIG_AUDIO_OSS)' },
+            { 'name': 'pa',
+              'if': 'defined(CONFIG_AUDIO_PA)' },
+            { 'name': 'sdl',
+              'if': 'defined(CONFIG_AUDIO_SDL)' },
+            { 'name': 'spice',
+              'if': 'defined(CONFIG_SPICE)' },
+            'wav' ] }
 
  ##
  # @Audiodev:
@@ -410,14 +426,22 @@
    'discriminator': 'driver',
    'data': {
      'none':      'AudiodevGenericOptions',
-    'alsa':      'AudiodevAlsaOptions',
-    'coreaudio': 'AudiodevCoreaudioOptions',
-    'dsound':    'AudiodevDsoundOptions',
-    'jack':      'AudiodevJackOptions',
-    'oss':       'AudiodevOssOptions',
-    'pa':        'AudiodevPaOptions',
-    'sdl':       'AudiodevSdlOptions',
-    'spice':     'AudiodevGenericOptions',
+    'alsa':      { 'type': 'AudiodevAlsaOptions',
+                   'if': 'defined(CONFIG_AUDIO_ALSA)' },
+    'coreaudio': { 'type': 'AudiodevCoreaudioOptions',
+                   'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
+    'dsound':    { 'type': 'AudiodevDsoundOptions',
+                   'if': 'defined(CONFIG_AUDIO_DSOUND)' },
+    'jack':      { 'type': 'AudiodevJackOptions',
+                   'if': 'defined(CONFIG_AUDIO_JACK)' },
+    'oss':       { 'type': 'AudiodevOssOptions',
+                   'if': 'defined(CONFIG_AUDIO_OSS)' },
+    'pa':        { 'type': 'AudiodevPaOptions',
+                   'if': 'defined(CONFIG_AUDIO_PA)' },
+    'sdl':       { 'type': 'AudiodevSdlOptions',
+                   'if': 'defined(CONFIG_AUDIO_SDL)' },
+    'spice':     { 'type': 'AudiodevGenericOptions',
+                   'if': 'defined(CONFIG_SPICE)' },
      'wav':       'AudiodevWavOptions' } }
 
  ##
#18 lore raw

Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema

Quoted 17 lines · Thomas Huth
Quoted 8 lines · Daniel P. Berrangé

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.

Quoted 7 lines
---
  audio/audio.c          | 16 +++++++++++++++
  audio/audio_legacy.c   | 41 ++++++++++++++++++++++++++++++++++++++-
  audio/audio_template.h | 16 +++++++++++++++
  qapi/audio.json        | 44 ++++++++++++++++++++++++++++++++----------
  4 files changed, 106 insertions(+), 11 deletions(-)
Quoted 3 lines

Hi Daniel!

Would you have time to respin this patch for QEMU 8.0 ?

Realistically I'm not going to get it soon. If you want to take over feel free.

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 :|
#19 lore raw

PATCH 3/3 qapi: provide a friendly string representation of QAPI classes

In reply to Daniel P. Berrangé

If printing a QAPI schema object for debugging we get the classname and a hex value for the instance. With this change we instead get the classname and the human friendly name of the QAPI type instance.

---
 scripts/qapi/schema.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/qapi/schema.py +3 -0
index ff16578f6d..800bc5994b 100644
@@ -46,6 +46,9 @@ def __init__(self, name: str, info, doc, ifcond=None, features=None):
         self.features = features or []
         self._checked = False
 
+    def __repr__(self):
+        return "%s<%s>" % (type(self).__name__, self.name)
+
     def c_name(self):
         return c_name(self.name)
 
Signature · 1 line
2.29.2
Reviewed-by on v1 3/3
#20 lore raw

Re: [PATCH 3/3] qapi: provide a friendly string representation of QAPI classes

Quoted 8 lines · Daniel P. Berrangé

If printing a QAPI schema object for debugging we get the classname and a hex value for the instance. With this change we instead get the classname and the human friendly name of the QAPI type instance.

---
 scripts/qapi/schema.py | 3 +++
 1 file changed, 3 insertions(+)
Quoted 16 lines
scripts/qapi/schema.py +3 -0
index ff16578f6d..800bc5994b 100644
@@ -46,6 +46,9 @@ def __init__(self, name: str, info, doc, ifcond=None, features=None):
         self.features = features or []
         self._checked = False
 
+    def __repr__(self):
+        return "%s<%s>" % (type(self).__name__, self.name)
+
     def c_name(self):
         return c_name(self.name)
 
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 3/3
#21 lore raw

Re: [PATCH 3/3] qapi: provide a friendly string representation of QAPI classes

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

If printing a QAPI schema object for debugging we get the classname and a hex value for the instance. With this change we instead get the classname and the human friendly name of the QAPI type instance.

---
 scripts/qapi/schema.py | 3 +++
 1 file changed, 3 insertions(+)
#22 lore raw

Re: [PATCH 3/3] qapi: provide a friendly string representation of QAPI classes

In reply to Daniel P. Berrangé
Quoted 14 lines · Daniel P. Berrangé

If printing a QAPI schema object for debugging we get the classname and a hex value for the instance. With this change we instead get the classname and the human friendly name of the QAPI type instance.

---
 scripts/qapi/schema.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/qapi/schema.py +0 -0
index ff16578f6d..800bc5994b 100644

scripts/qapi/schema.py def __init__(self, name: str, info, doc, ifcond=None, features=None): · line 53

Quoted 8 lines
scripts/qapi/schema.py +3 -0
@@ -46,6 +46,9 @@ def __init__(self, name: str, info, doc, ifcond=None, features=None):
         self.features = features or []
         self._checked = False
 
+    def __repr__(self):
+        return "%s<%s>" % (type(self).__name__, self.name)
+
     def c_name(self):
         return c_name(self.name)

https://docs.python.org/3.6/reference/datamodel.html#object.__repr__

Called by the repr() built-in function to compute the “official” string representation of an object. If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment).

Making QAPISchemaEntity.__repr__() return "a valid Python expression that could be used to recreate an object with the same value" is probably more trouble than it's worth.

If this is not possible, a string of the form <...some useful description...> should be returned.

I'm afraid your .__repr__() has the < in the wrong place.

The return value must be a
__repr__() is also used when an “informal” string representation of instances of that class is required.

This is typically used for debugging, so it is important that the representation is information-rich and unambiguous.

I guess your .__repr__() is unambiguous enough for practical purposes, as entity names are typically unique within a schema. *Except* for QAPISchemaInclude, where self.name is always None.

What about self.name or id(self)?