qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v6 4/4] hmp: add monitor command to add/remove a chi


From: Wen Congyang
Subject: [Qemu-devel] [PATCH v6 4/4] hmp: add monitor command to add/remove a child
Date: Fri, 16 Oct 2015 16:57:46 +0800

The new command is blockdev_change. It does the same
thing as the QMP command x-blockdev-change.

Signed-off-by: Wen Congyang <address@hidden>
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Gonglei <address@hidden>
Cc: Luiz Capitulino <address@hidden>
---
 hmp-commands.hx | 17 +++++++++++++++++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 3 files changed, 56 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 3a4ae39..57475cc 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -193,6 +193,23 @@ actions (drive options rerror, werror).
 ETEXI
 
     {
+        .name       = "blockdev_change",
+        .args_type  = "op:s,parent:B,child:B?,node:?",
+        .params     = "operation parent [child] [node]",
+        .help       = "Dynamic reconfigure the block driver state graph",
+        .mhandler.cmd = hmp_blockdev_change,
+    },
+
+STEXI
address@hidden blockdev_change @var{operation} @var{parent} address@hidden 
address@hidden
address@hidden blockdev_change
+Dynamic reconfigure the block driver state graph. It can be used to
+add, remove, insert, replace a block driver state. Currently only
+the Quorum driver implements this feature to add and remove its child.
+This is useful to fix a broken quorum child.
+ETEXI
+
+    {
         .name       = "change",
         .args_type  = "device:B,target:F,arg:s?",
         .params     = "device filename [format]",
diff --git a/hmp.c b/hmp.c
index 5048eee..fc58ae2 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2346,3 +2346,41 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict 
*qdict)
 
     qapi_free_RockerOfDpaGroupList(list);
 }
+
+void hmp_blockdev_change(Monitor *mon, const QDict *qdict)
+{
+    const char *operation = qdict_get_str(qdict, "op");
+    const char *parent = qdict_get_str(qdict, "parent");
+    const char *child = qdict_get_try_str(qdict, "child");
+    const char *node = qdict_get_try_str(qdict, "node");
+    ChangeOperation op = CHANGE_OPERATION_ADD;
+    Error *local_err = NULL;
+    bool has_child = !!child;
+    bool has_node = !!node;
+
+    while (ChangeOperation_lookup[op] != NULL) {
+        if (strcmp(ChangeOperation_lookup[op], operation) == 0) {
+            break;
+        }
+        op++;
+    }
+
+    if (ChangeOperation_lookup[op] == NULL) {
+        error_setg(&local_err, "Invalid parameter '%s'", "operation");
+        goto out;
+    }
+
+    /*
+     * FIXME: we must specify the parameter child, otherwise,
+     * we can't specify the parameter node.
+     */
+    if (op == CHANGE_OPERATION_ADD) {
+        has_child = false;
+    }
+
+    qmp_x_blockdev_change(op, parent, has_child, child,
+                          has_node, node, &local_err);
+
+out:
+    hmp_handle_error(mon, &local_err);
+}
diff --git a/hmp.h b/hmp.h
index 81656c3..80a1faf 100644
--- a/hmp.h
+++ b/hmp.h
@@ -130,5 +130,6 @@ void hmp_rocker(Monitor *mon, const QDict *qdict);
 void hmp_rocker_ports(Monitor *mon, const QDict *qdict);
 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict);
 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict);
+void hmp_blockdev_change(Monitor *mon, const QDict *qdict);
 
 #endif
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]