diff mbox

[09/21] qom: add plug_list QMP command

Message ID 1311558293-5855-10-git-send-email-aliguori@us.ibm.com
State New
Headers show

Commit Message

Anthony Liguori July 25, 2011, 1:44 a.m. UTC
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 monitor.c       |   25 +++++++++++++++++++++++++
 qmp-commands.hx |    9 +++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 8406b5b..f17eb3a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1069,6 +1069,31 @@  static int do_plug_create(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return 0;
 }
 
+static int do_plug_list(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    QList *qlist = qlist_new();
+    const char *type = qdict_get_try_str(qdict, "type");
+    GSList *i;
+
+    for (i = global_plug_list; i; i = i->next) {
+        TypeInstance *obj = i->data;
+        QDict *item = qdict_new();
+
+        if (type && !type_is_type(obj, type)) {
+            continue;
+        }
+
+        qdict_put(item, "id", qstring_from_str(type_get_id(obj)));
+        qdict_put(item, "type", qstring_from_str(type_get_type(obj)));
+
+        qlist_append(qlist, item);
+    }
+
+    *ret_data = QOBJECT(qlist);
+
+    return 0;
+}
+
 #ifdef CONFIG_VNC
 static int change_vnc_password(const char *password)
 {
diff --git a/qmp-commands.hx b/qmp-commands.hx
index c86d396..16f3f4d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -112,6 +112,15 @@  Notes:
 EQMP
 
     {
+        .name       = "plug_list",
+        .args_type  = "type:s?",
+        .params     = "",
+        .help       = "list plugs",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_plug_list,
+    },
+
+    {
         .name       = "eject",
         .args_type  = "force:-f,device:B",
         .params     = "[-f] device",