* [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