diff mbox

[v6,4/4] hmp: add monitor command to add/remove a child

Message ID 1444985866-12969-5-git-send-email-wency@cn.fujitsu.com
State New
Headers show

Commit Message

Wen Congyang Oct. 16, 2015, 8:57 a.m. UTC
The new command is blockdev_change. It does the same
thing as the QMP command x-blockdev-change.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp-commands.hx | 17 +++++++++++++++++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 3 files changed, 56 insertions(+)

Comments

Alberto Garcia Nov. 9, 2015, 2:54 p.m. UTC | #1
On Fri 16 Oct 2015 10:57:46 AM CEST, Wen Congyang wrote:

> +        .name       = "blockdev_change",
> +        .args_type  = "op:s,parent:B,child:B?,node:?",
> +        .params     = "operation parent [child] [node]",
  [...]
> +    /*
> +     * FIXME: we must specify the parameter child, otherwise,
> +     * we can't specify the parameter node.
> +     */
> +    if (op == CHANGE_OPERATION_ADD) {
> +        has_child = false;
> +    }

So if you want to perform the 'add' operation you must pass both 'child'
and 'node' but the former will be discarded.

I don't think you really need to do this for the HMP interface, but it's
anyway one more good reason to merge 'child' and 'node'.

Berto
Wen Congyang Nov. 10, 2015, 8:44 a.m. UTC | #2
On 11/09/2015 10:54 PM, Alberto Garcia wrote:
> On Fri 16 Oct 2015 10:57:46 AM CEST, Wen Congyang wrote:
> 
>> +        .name       = "blockdev_change",
>> +        .args_type  = "op:s,parent:B,child:B?,node:?",
>> +        .params     = "operation parent [child] [node]",
>   [...]
>> +    /*
>> +     * FIXME: we must specify the parameter child, otherwise,
>> +     * we can't specify the parameter node.
>> +     */
>> +    if (op == CHANGE_OPERATION_ADD) {
>> +        has_child = false;
>> +    }
> 
> So if you want to perform the 'add' operation you must pass both 'child'
> and 'node' but the former will be discarded.
> 
> I don't think you really need to do this for the HMP interface, but it's
> anyway one more good reason to merge 'child' and 'node'.

Do you mean there is no need to implement the HMP interface?

Thanks
Wen Congyang

> 
> Berto
> .
>
diff mbox

Patch

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
+@item blockdev_change @var{operation} @var{parent} [@var{child}] [@var{node}]
+@findex 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