From: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, lcapitulino@redhat.com,
Miguel Di Ciurcio Filho <miguel.filho@gmail.com>,
avi@redhat.com
Subject: [Qemu-devel] [PATCH 2/2] monitor: Convert 'info qdm' to QMP
Date: Fri, 2 Jul 2010 18:27:03 -0300 [thread overview]
Message-ID: <1278106023-9966-3-git-send-email-miguel.filho@gmail.com> (raw)
In-Reply-To: <1278106023-9966-1-git-send-email-miguel.filho@gmail.com>
Converts the 'info qdm' command to QMP, allowing the discovery of all devices
known to the QEMU binary without relying on command line paramaters like
-device ? and -device devtype,?
This change does not modify the output of the 'info qdm' monitor command.
Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
hw/qdev.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
hw/qdev.h | 3 +-
monitor.c | 3 +-
3 files changed, 120 insertions(+), 4 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 61f999c..23f0540 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -29,6 +29,7 @@
#include "qdev.h"
#include "sysemu.h"
#include "monitor.h"
+#include "qjson.h"
static int qdev_hotplug = 0;
@@ -777,13 +778,126 @@ void do_info_qtree(Monitor *mon)
qbus_print(mon, main_system_bus, 0);
}
-void do_info_qdm(Monitor *mon)
+static void qdm_list_iter(QObject *obj, void *opaque)
+{
+
+ Monitor *mon = opaque;
+ QDict *dev = qobject_to_qdict(obj);
+
+ monitor_printf(mon, "name \"%s\", bus %s", qdict_get_str(dev, "name"),
+ qdict_get_str(dev, "bus"));
+
+ if (qdict_haskey(dev, "alias")) {
+ monitor_printf(mon, ", alias \"%s\"", qdict_get_str(dev, "alias"));
+ }
+
+ if (qdict_haskey(dev, "description")) {
+ monitor_printf(mon, ", desc \"%s\"", qdict_get_str(dev, "description"));
+ }
+
+ if (!qdict_get_bool(dev, "creatable")) {
+ monitor_printf(mon, ", no-user");
+ }
+
+ monitor_printf(mon, "\n");
+}
+
+void do_info_qdm_print(Monitor *mon, const QObject *ret_data)
+{
+ QList *devs;
+
+ devs = qobject_to_qlist(ret_data);
+ qlist_iter(devs, qdm_list_iter, mon);
+}
+
+static const char *qdev_property_type_to_string(int type) {
+ switch (type) {
+ case PROP_TYPE_UNSPEC:
+ return "unknown";
+ case PROP_TYPE_UINT8:
+ return "uint8";
+ case PROP_TYPE_UINT16:
+ return "uint16";
+ case PROP_TYPE_UINT32:
+ return "uint32";
+ case PROP_TYPE_INT32:
+ return "int32";
+ case PROP_TYPE_UINT64:
+ return "uint64";
+ case PROP_TYPE_TADDR:
+ return "taddr";
+ case PROP_TYPE_MACADDR:
+ return "macaddr";
+ case PROP_TYPE_DRIVE:
+ return "drive";
+ case PROP_TYPE_CHR:
+ return "chr";
+ case PROP_TYPE_STRING:
+ return "string";
+ case PROP_TYPE_NETDEV:
+ return "netdev";
+ case PROP_TYPE_VLAN:
+ return "vlan";
+ case PROP_TYPE_PTR:
+ return "pointer";
+ case PROP_TYPE_BIT:
+ return "bit";
+ }
+
+ return NULL;
+}
+
+void do_info_qdm(Monitor *mon, QObject **ret_data)
{
DeviceInfo *info;
+ QList *devs = qlist_new();
for (info = device_info_list; info != NULL; info = info->next) {
- qdev_print_devinfo(info);
+ QObject *obj;
+ QDict *dev;
+ QList *props = qlist_new();
+ Property *prop;
+
+ for (prop = info->props; prop && prop->name; prop++) {
+ QObject *entry;
+ /*
+ * TODO Properties without a parser are just for dirty hacks.
+ * qdev_prop_ptr is the only such PropertyInfo. It's marked
+ * for removal. This conditional should be removed along with
+ * it.
+ */
+ if (!prop->info->parse) {
+ continue; /* no way to set it, don't show */
+ }
+
+ const char *type = qdev_property_type_to_string(prop->info->type);
+
+ entry = qobject_from_jsonf("{ 'name': %s, 'info': %s, 'type': %s }",
+ prop->name, prop->info->name, type);
+
+ qlist_append_obj(props, entry);
+ }
+
+ obj = qobject_from_jsonf("{ 'name': %s, 'bus': %s, 'props': %p, 'creatable': %i }",
+ info->name,
+ info->bus_info->name,
+ props,
+ info->no_user ? 0 : 1);
+
+ dev = qobject_to_qdict(obj);
+
+ if (info->alias) {
+ qdict_put(dev, "alias", qstring_from_str(info->alias));
+ }
+
+ if (info->desc) {
+ qdict_put(dev, "description", qstring_from_str(info->desc));
+ }
+
+ qlist_append(devs, dev);
}
+
+ *ret_data = QOBJECT(devs);
}
int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
diff --git a/hw/qdev.h b/hw/qdev.h
index be5ad67..f44e4a2 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -181,7 +181,8 @@ void qbus_free(BusState *bus);
/*** monitor commands ***/
void do_info_qtree(Monitor *mon);
-void do_info_qdm(Monitor *mon);
+void do_info_qdm_print(Monitor *mon, const QObject *ret_data);
+void do_info_qdm(Monitor *mon, QObject **ret_data);
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 170b269..91b87f9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2550,7 +2550,8 @@ static const mon_cmd_t info_cmds[] = {
.args_type = "",
.params = "",
.help = "show qdev device model list",
- .mhandler.info = do_info_qdm,
+ .user_print = do_info_qdm_print,
+ .mhandler.info_new = do_info_qdm,
},
{
.name = "roms",
--
1.7.1
prev parent reply other threads:[~2010-07-02 21:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-02 21:27 [Qemu-devel] [PATCH 0/2] QMP: Introduce query-qdm Miguel Di Ciurcio Filho
2010-07-02 21:27 ` [Qemu-devel] [PATCH 1/2] QMP: Introduce the documentation for query-qdm Miguel Di Ciurcio Filho
2010-07-04 5:14 ` [Qemu-devel] " Avi Kivity
2010-07-05 13:20 ` Miguel Di Ciurcio Filho
2010-07-05 15:22 ` Luiz Capitulino
2010-07-05 19:34 ` Miguel Di Ciurcio Filho
2010-07-07 13:07 ` Luiz Capitulino
2010-07-07 13:39 ` Daniel P. Berrange
2010-07-02 21:27 ` Miguel Di Ciurcio Filho [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1278106023-9966-3-git-send-email-miguel.filho@gmail.com \
--to=miguel.filho@gmail.com \
--cc=armbru@redhat.com \
--cc=avi@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).