qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] hmp: info spice: Show string channel name
@ 2015-02-27 15:36 Cole Robinson
  2015-02-27 18:26 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: Cole Robinson @ 2015-02-27 15:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: Cole Robinson, Gerd Hoffmann, Markus Armbruster, Luiz Capitulino

Useful for debugging.

https://bugzilla.redhat.com/show_bug.cgi?id=822418
Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
v2:
    Explicitly list spice channel mappings
    Use ARRAY_SIZE macro

 hmp.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/hmp.c b/hmp.c
index 735097c..9e76368 100644
--- a/hmp.c
+++ b/hmp.c
@@ -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);
         }
     }
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] hmp: info spice: Show string channel name
  2015-02-27 15:36 [Qemu-devel] [PATCH v2] hmp: info spice: Show string channel name Cole Robinson
@ 2015-02-27 18:26 ` Eric Blake
  2015-03-01 14:29   ` Cole Robinson
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2015-02-27 18:26 UTC (permalink / raw)
  To: Cole Robinson, qemu-devel
  Cc: Gerd Hoffmann, Markus Armbruster, Luiz Capitulino

[-- Attachment #1: Type: text/plain, Size: 1632 bytes --]

On 02/27/2015 08:36 AM, Cole Robinson wrote:
> Useful for debugging.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=822418
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
> v2:
>     Explicitly list spice channel mappings
>     Use ARRAY_SIZE macro
> 
>  hmp.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 

> +    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'?

> +        [ 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?

> +            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,

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] hmp: info spice: Show string channel name
  2015-02-27 18:26 ` Eric Blake
@ 2015-03-01 14:29   ` Cole Robinson
  0 siblings, 0 replies; 3+ messages in thread
From: Cole Robinson @ 2015-03-01 14:29 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: Luiz Capitulino, Gerd Hoffmann, Markus Armbruster

On 02/27/2015 01:26 PM, Eric Blake wrote:
> On 02/27/2015 08:36 AM, Cole Robinson wrote:
>> Useful for debugging.
>>
>> https://bugzilla.redhat.com/show_bug.cgi?id=822418
>> Signed-off-by: Cole Robinson <crobinso@redhat.com>
>> ---
>> v2:
>>     Explicitly list spice channel mappings
>>     Use ARRAY_SIZE macro
>>
>>  hmp.c | 26 ++++++++++++++++++++++++++
>>  1 file changed, 26 insertions(+)
>>
> 
>> +    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'?
> 
>> +        [ 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?
> 
>> +            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,
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 

I've sent v3 with those bits fixed (and some checkpatch warnings :/ )

Thanks,
Cole

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-01 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-27 15:36 [Qemu-devel] [PATCH v2] hmp: info spice: Show string channel name Cole Robinson
2015-02-27 18:26 ` Eric Blake
2015-03-01 14:29   ` Cole Robinson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).