qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] add optional root to info qtree
@ 2010-10-21  6:37 Alon Levy
  2010-10-21  6:37 ` [Qemu-devel] [PATCH 1/2] monitor: add sub_args_type for second level parameters Alon Levy
  2010-10-21  6:37 ` [Qemu-devel] [PATCH 2/2] monitor info qtree: add optional bus id Alon Levy
  0 siblings, 2 replies; 4+ messages in thread
From: Alon Levy @ 2010-10-21  6:37 UTC (permalink / raw)
  To: qemu-devel

Allow viewing of a part of the large qdev tree. The optional argument
is first looked for as a bus id, if that fails a device id is found and
it's parent bus is the root for printing.

Adds sub_args_type callback for each monitor mon_cmd_t to fascilitate the
existing info_cmds args_type and params strings, so monitor_parse_command
will check the arguments for the do_info sub command do_info_qtree.

Alon Levy (2):
  monitor: add sub_args_type for second level parameters
  monitor info qtree: add optional bus id

 hmp-commands.hx |    1 +
 hw/qdev.c       |   17 ++++++++++++++---
 hw/qdev.h       |    2 +-
 monitor.c       |   47 +++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 57 insertions(+), 10 deletions(-)

-- 
1.7.3.1

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

* [Qemu-devel] [PATCH 1/2] monitor: add sub_args_type for second level parameters
  2010-10-21  6:37 [Qemu-devel] [PATCH 0/2] add optional root to info qtree Alon Levy
@ 2010-10-21  6:37 ` Alon Levy
  2010-11-04 17:53   ` Luiz Capitulino
  2010-10-21  6:37 ` [Qemu-devel] [PATCH 2/2] monitor info qtree: add optional bus id Alon Levy
  1 sibling, 1 reply; 4+ messages in thread
From: Alon Levy @ 2010-10-21  6:37 UTC (permalink / raw)
  To: qemu-devel

---
 hmp-commands.hx |    1 +
 monitor.c       |   13 ++++++++++++-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 3014b17..289fbcb 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1158,6 +1158,7 @@ ETEXI
         .args_type  = "item:s?",
         .params     = "[subcommand]",
         .help       = "show various information about the system state",
+        .sub_args_type = do_info_sub_args_type,
         .mhandler.cmd = do_info,
     },
 
diff --git a/monitor.c b/monitor.c
index 260cc02..7d1d3b1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -107,6 +107,7 @@ typedef struct mon_cmd_t {
     const char *params;
     const char *help;
     void (*user_print)(Monitor *mon, const QObject *data);
+    const char *(*sub_args_type)(const QDict *qdict);
     union {
         void (*info)(Monitor *mon);
         void (*info_new)(Monitor *mon, QObject **ret_data);
@@ -3500,6 +3501,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
     char cmdname[256];
     char buf[1024];
     char *key;
+    int did_sub_args_type = 0;
 
 #ifdef DEBUG
     monitor_printf(mon, "command='%s'\n", cmdline);
@@ -3520,8 +3522,17 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
     typestr = cmd->args_type;
     for(;;) {
         typestr = key_get_info(typestr, &key);
-        if (!typestr)
+        /* Allow for two level parameters definition. Call sub_args_type only
+         * after finished parsing existing args */
+        if (!typestr && cmd->sub_args_type != NULL && !did_sub_args_type) {
+            if ((typestr = cmd->sub_args_type(qdict)) != NULL) {
+                typestr = key_get_info(typestr, &key);
+            }
+            did_sub_args_type = 1;
+        }
+        if (!typestr) {
             break;
+        }
         c = *typestr;
         typestr++;
         switch(c) {
-- 
1.7.3.1

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

* [Qemu-devel] [PATCH 2/2] monitor info qtree: add optional bus id
  2010-10-21  6:37 [Qemu-devel] [PATCH 0/2] add optional root to info qtree Alon Levy
  2010-10-21  6:37 ` [Qemu-devel] [PATCH 1/2] monitor: add sub_args_type for second level parameters Alon Levy
@ 2010-10-21  6:37 ` Alon Levy
  1 sibling, 0 replies; 4+ messages in thread
From: Alon Levy @ 2010-10-21  6:37 UTC (permalink / raw)
  To: qemu-devel

---
 hw/qdev.c |   17 ++++++++++++++---
 hw/qdev.h |    2 +-
 monitor.c |   34 +++++++++++++++++++++++++++++-----
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index d669a9d..e6cf7af 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -774,10 +774,21 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent)
 }
 #undef qdev_printf
 
-void do_info_qtree(Monitor *mon)
+void do_info_qtree(Monitor *mon, const QDict *qdict)
 {
-    if (main_system_bus)
-        qbus_print(mon, main_system_bus, 0);
+    const char *id;
+    BusState *bus = main_system_bus;
+    DeviceState *dev;
+
+    if (qdict != NULL && (id = qdict_get_try_str(qdict, "id")) != NULL) {
+        bus = qbus_find_recursive(main_system_bus, id, NULL);
+        if (bus == NULL && (dev = qdev_find_recursive(main_system_bus, id)) != NULL) {
+            bus = dev->parent_bus;
+        }
+    }
+    if (bus) {
+        qbus_print(mon, bus, 0);
+    }
 }
 
 void do_info_qdm(Monitor *mon)
diff --git a/hw/qdev.h b/hw/qdev.h
index 214066e..c08a525 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -183,7 +183,7 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id);
 
 /*** monitor commands ***/
 
-void do_info_qtree(Monitor *mon);
+void do_info_qtree(Monitor *mon, const QDict *qdict);
 void do_info_qdm(Monitor *mon);
 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
diff --git a/monitor.c b/monitor.c
index 7d1d3b1..69ec651 100644
--- a/monitor.c
+++ b/monitor.c
@@ -640,6 +640,26 @@ static void user_async_info_handler(Monitor *mon, const mon_cmd_t *cmd)
     }
 }
 
+static const char* do_info_sub_args_type(const QDict *qdict)
+{
+    const mon_cmd_t *cmd;
+    const char *item = qdict_get_try_str(qdict, "item");
+
+    if (!item) {
+        return NULL;
+    }
+    for (cmd = info_cmds; cmd->name != NULL; cmd++) {
+        if (compare_cmd(item, cmd->name)) {
+            break;
+        }
+    }
+
+    if (cmd->name == NULL) {
+        return NULL;
+    }
+    return cmd->args_type;
+}
+
 static void do_info(Monitor *mon, const QDict *qdict)
 {
     const mon_cmd_t *cmd;
@@ -669,7 +689,11 @@ static void do_info(Monitor *mon, const QDict *qdict)
             qobject_decref(info_data);
         }
     } else {
-        cmd->mhandler.info(mon);
+        if (cmd->params != NULL && cmd->params[0] != 0) {
+            cmd->mhandler.cmd(mon, qdict);
+        } else {
+            cmd->mhandler.info(mon);
+        }
     }
 
     return;
@@ -2586,10 +2610,10 @@ static const mon_cmd_t info_cmds[] = {
     },
     {
         .name       = "qtree",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show device tree",
-        .mhandler.info = do_info_qtree,
+        .args_type  = "id:s?",
+        .params     = "device",
+        .help       = "show device tree (optional root bus/device)",
+        .mhandler.cmd = do_info_qtree,
     },
     {
         .name       = "qdm",
-- 
1.7.3.1

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

* Re: [Qemu-devel] [PATCH 1/2] monitor: add sub_args_type for second level parameters
  2010-10-21  6:37 ` [Qemu-devel] [PATCH 1/2] monitor: add sub_args_type for second level parameters Alon Levy
@ 2010-11-04 17:53   ` Luiz Capitulino
  0 siblings, 0 replies; 4+ messages in thread
From: Luiz Capitulino @ 2010-11-04 17:53 UTC (permalink / raw)
  To: Alon Levy; +Cc: qemu-devel

On Thu, 21 Oct 2010 08:37:19 +0200
Alon Levy <alevy@redhat.com> wrote:

> ---
>  hmp-commands.hx |    1 +
>  monitor.c       |   13 ++++++++++++-
>  2 files changed, 13 insertions(+), 1 deletions(-)
> 
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 3014b17..289fbcb 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1158,6 +1158,7 @@ ETEXI
>          .args_type  = "item:s?",
>          .params     = "[subcommand]",
>          .help       = "show various information about the system state",
> +        .sub_args_type = do_info_sub_args_type,
>          .mhandler.cmd = do_info,
>      },
>  
> diff --git a/monitor.c b/monitor.c
> index 260cc02..7d1d3b1 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -107,6 +107,7 @@ typedef struct mon_cmd_t {
>      const char *params;
>      const char *help;
>      void (*user_print)(Monitor *mon, const QObject *data);
> +    const char *(*sub_args_type)(const QDict *qdict);
>      union {
>          void (*info)(Monitor *mon);
>          void (*info_new)(Monitor *mon, QObject **ret_data);
> @@ -3500,6 +3501,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
>      char cmdname[256];
>      char buf[1024];
>      char *key;
> +    int did_sub_args_type = 0;
>  
>  #ifdef DEBUG
>      monitor_printf(mon, "command='%s'\n", cmdline);
> @@ -3520,8 +3522,17 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
>      typestr = cmd->args_type;
>      for(;;) {
>          typestr = key_get_info(typestr, &key);
> -        if (!typestr)
> +        /* Allow for two level parameters definition. Call sub_args_type only
> +         * after finished parsing existing args */
> +        if (!typestr && cmd->sub_args_type != NULL && !did_sub_args_type) {
> +            if ((typestr = cmd->sub_args_type(qdict)) != NULL) {
> +                typestr = key_get_info(typestr, &key);
> +            }
> +            did_sub_args_type = 1;
> +        }
> +        if (!typestr) {
>              break;
> +        }

Unfortunately, the args_type thing is a bad interface and very hacked
already. I think we're adding more to the pile.

What I'm going to do for QMP is to convert all info_new() into cmd_new(),
this way query- commands can have their arguments just like any command.

I'm wondering if we can do the same for HMP, that's turn all info() into
cmd(). But I'm not sure if this can get tricky, as info commands have
special handling in a few different places.

Care to check?

>          c = *typestr;
>          typestr++;
>          switch(c) {

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

end of thread, other threads:[~2010-11-04 17:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-21  6:37 [Qemu-devel] [PATCH 0/2] add optional root to info qtree Alon Levy
2010-10-21  6:37 ` [Qemu-devel] [PATCH 1/2] monitor: add sub_args_type for second level parameters Alon Levy
2010-11-04 17:53   ` Luiz Capitulino
2010-10-21  6:37 ` [Qemu-devel] [PATCH 2/2] monitor info qtree: add optional bus id Alon Levy

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).