Patchwork [11/21] qom: add plug_set QMP command

login
register
mail settings
Submitter Anthony Liguori
Date July 25, 2011, 1:44 a.m.
Message ID <1311558293-5855-12-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/106591/
State New
Headers show

Comments

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

Patch

diff --git a/monitor.c b/monitor.c
index 1937e9f..47011dd 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1129,6 +1129,39 @@  static int do_plug_get(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return 0;
 }
 
+static int do_plug_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    const char *id = qdict_get_str(qdict, "id");
+    const char *name = qdict_get_str(qdict, "name");
+    QObject *value = qdict_get(qdict, "value");
+    Error *local_err = NULL;
+    QmpInputVisitor *qiv;
+    TypeInstance *inst;
+    Plug *plug;
+    Visitor *v;
+
+    qiv = qmp_input_visitor_new(value);
+    v = qmp_input_get_visitor(qiv);
+
+    inst = type_find_by_id(id);
+    if (inst == NULL) {
+        return -1;
+    }
+
+    plug = PLUG(inst);
+
+    plug_set_property(plug, name, v, &local_err);
+    if (local_err) {
+        error_free(local_err);
+        qmp_input_visitor_cleanup(qiv);
+        return -1;
+    }
+
+    qmp_input_visitor_cleanup(qiv);
+
+    return 0;
+}
+
 #ifdef CONFIG_VNC
 static int change_vnc_password(const char *password)
 {
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 822d422..1d7e87b 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -130,6 +130,15 @@  EQMP
     },
 
     {
+        .name       = "plug_set",
+        .args_type  = "options:O",
+        .params     = "",
+        .help       = "set plug property",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_plug_set,
+    },
+
+    {
         .name       = "eject",
         .args_type  = "force:-f,device:B",
         .params     = "[-f] device",