hmp: info spice: Show string channel name
PATCH v2 1/1 hmp: info spice: Show string channel name
Useful for debugging.
https://bugzilla.redhat.com/show_bug.cgi?id=822418
---
v2:
Explicitly list spice channel mappings
Use ARRAY_SIZE macro
hmp.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
hmp.c +26 -0
@@ -29,6 +29,10 @@#include "block/qapi.h" #include "qemu-io.h" +#ifdef CONFIG_SPICE +#include <spice/enums.h> +#endif +static void hmp_handle_error (Monitor *mon,Error **errp) {assert (errp);
@@ -545,6 +549,20 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict) {SpiceChannelList *chan;SpiceInfo *info; +const char *channel_name; +const char *const channel_names[] = { + [SPICE_CHANNEL_MAIN ] ="main" , + [SPICE_CHANNEL_DISPLAY ] ="display" , + [SPICE_CHANNEL_INPUTS ] ="input" , + [SPICE_CHANNEL_CURSOR ] ="cursor" , + [SPICE_CHANNEL_PLAYBACK ] ="playback" , + [SPICE_CHANNEL_RECORD ] ="record" , + [SPICE_CHANNEL_TUNNEL ] ="tunnel" , + [SPICE_CHANNEL_SMARTCARD ] ="smartcard" , + [SPICE_CHANNEL_USBREDIR ] ="usbredir" , + [SPICE_CHANNEL_PORT ] ="port" , + [SPICE_CHANNEL_WEBDAV ] ="webdav" , + }; info =qmp_query_spice (NULL );
@@ -581,6 +599,14 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict) chan->value->connection_id);monitor_printf (mon," channel: %" PRId64":%" PRId64"\n" , chan->value->channel_type, chan->value->channel_id); + + channel_name ="unknown" ; +if (chan->value->channel_type >0 && + chan->value->channel_type <ARRAY_SIZE (channel_names)) { + channel_name = channel_names[chan->value->channel_type]; + } + +monitor_printf (mon," channel name: %s\n" , channel_name); } }
Signature · 1 line
2.1.0
Quoted 13 lines · Cole Robinson
Useful for debugging.
https://bugzilla.redhat.com/show_bug.cgi?id=822418
Signed-off-by Cole Robinson <[email protected]>---
v2:
Explicitly list spice channel mappings
UseARRAY_SIZEmacrohmp.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
hmp.c void hmp_info_spice(Monitor *mon, const QDict *qdict) · line 556
Quoted 5 lines
hmp.c +5
-0+const char *channel_name; +const char *const channel_names[] = { + [SPICE_CHANNEL_MAIN ] ="main" , + [SPICE_CHANNEL_DISPLAY ] ="display" , + [SPICE_CHANNEL_INPUTS ] ="input" ,
Why 'input' instead of 'inputs'?
hmp.c void hmp_info_spice(Monitor *mon, const QDict *qdict) · line 565
Quoted 9 lines
hmp.c +9
-0+ [ SPICE_CHANNEL_CURSOR ] = "cursor", + [ SPICE_CHANNEL_PLAYBACK ] = "playback", + [ SPICE_CHANNEL_RECORD ] = "record", + [ SPICE_CHANNEL_TUNNEL ] = "tunnel", + [ SPICE_CHANNEL_SMARTCARD ] = "smartcard", + [ SPICE_CHANNEL_USBREDIR ] = "usbredir", + [ SPICE_CHANNEL_PORT ] = "port", + [ SPICE_CHANNEL_WEBDAV ] = "webdav", + };
Are we guaranteed that this array is never sparse?
hmp.c void hmp_info_spice(Monitor *mon, const QDict *qdict) · line 606
Quoted 4 lines
hmp.c +4
-0+ channel_name ="unknown" ; +if (chan->value->channel_type >0 && + chan->value->channel_type <ARRAY_SIZE (channel_names)) { + channel_name = channel_names[chan->value->channel_type];
If it could be sparse, you might need an additional '&& channel_names[chan->value->channel_type]' in the conditional. Otherwise,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 39 lines · Eric Blake
Quoted 13 lines · Cole Robinson
Useful for debugging.
https://bugzilla.redhat.com/show_bug.cgi?id=822418
Signed-off-by Cole Robinson <[email protected]>---
v2:
Explicitly list spice channel mappings
UseARRAY_SIZEmacrohmp.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)hmp.c void hmp_info_spice(Monitor *mon, const QDict *qdict) · line 556
Quoted 5 lines
hmp.c +5
-0+const char *channel_name; +const char *const channel_names[] = { + [SPICE_CHANNEL_MAIN ] ="main" , + [SPICE_CHANNEL_DISPLAY ] ="display" , + [SPICE_CHANNEL_INPUTS ] ="input" ,Why 'input' instead of 'inputs'?
hmp.c void hmp_info_spice(Monitor *mon, const QDict *qdict) · line 565
Quoted 9 lines
hmp.c +9
-0+ [ SPICE_CHANNEL_CURSOR ] = "cursor", + [ SPICE_CHANNEL_PLAYBACK ] = "playback", + [ SPICE_CHANNEL_RECORD ] = "record", + [ SPICE_CHANNEL_TUNNEL ] = "tunnel", + [ SPICE_CHANNEL_SMARTCARD ] = "smartcard", + [ SPICE_CHANNEL_USBREDIR ] = "usbredir", + [ SPICE_CHANNEL_PORT ] = "port", + [ SPICE_CHANNEL_WEBDAV ] = "webdav", + };Are we guaranteed that this array is never sparse?
hmp.c void hmp_info_spice(Monitor *mon, const QDict *qdict) · line 606
Quoted 4 lines
hmp.c +4
-0+ channel_name ="unknown" ; +if (chan->value->channel_type >0 && + chan->value->channel_type <ARRAY_SIZE (channel_names)) { + channel_name = channel_names[chan->value->channel_type];
Quoted 5 lines
If it could be sparse, you might need an additional '&& channel_names[chan->value->channel_type]' in the conditional. Otherwise,
Reviewed-by Eric Blake <[email protected]>
I've sent v3 with those bits fixed (and some checkpatch warnings :/ )
Thanks,
Cole