Patchwork [2/2] monitor info qtree: add optional bus id

login
register
mail settings
Submitter Alon Levy
Date Oct. 21, 2010, 6:37 a.m.
Message ID <1287643040-21200-3-git-send-email-alevy@redhat.com>
Download mbox | patch
Permalink /patch/68526/
State New
Headers show

Comments

Alon Levy - Oct. 21, 2010, 6:37 a.m.
---
 hw/qdev.c |   17 ++++++++++++++---
 hw/qdev.h |    2 +-
 monitor.c |   34 +++++++++++++++++++++++++++++-----
 3 files changed, 44 insertions(+), 9 deletions(-)

Patch

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