Patchwork [13/21] qom: add plug_destroy command

login
register
mail settings
Submitter Anthony Liguori
Date July 25, 2011, 1:44 a.m.
Message ID <1311558293-5855-14-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/106598/
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       |   20 ++++++++++++++++++++
 qmp-commands.hx |    9 +++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

Patch

diff --git a/monitor.c b/monitor.c
index e53808a..549251a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1069,6 +1069,26 @@  static int do_plug_create(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return 0;
 }
 
+static int do_plug_destroy(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    const char *id = qdict_get_str(qdict, "id");
+    TypeInstance *inst;
+    Plug *plug;
+
+    inst = type_find_by_id(id);
+    if (inst == NULL) {
+        return -1;
+    }
+
+    plug = PLUG(inst);
+
+    global_plug_list = g_slist_remove(global_plug_list, plug);
+
+    type_delete(inst);
+
+    return 0;
+}
+
 static int do_plug_list(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     QList *qlist = qlist_new();
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 6f1091b..8203371 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -112,6 +112,15 @@  Notes:
 EQMP
 
     {
+        .name       = "plug_destroy",
+        .args_type  = "type:s",
+        .params     = "type=value",
+        .help       = "destroy a plug",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_plug_destroy,
+    },
+
+    {
         .name       = "plug_list",
         .args_type  = "type:s?",
         .params     = "",