Skip to contentSkip to conversation

qapi: child add/delete support

PATCH Superseded Wen Congyang 2 participants 8 messages Sep 18, 2015 Block layer

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover qapi: child add/delete support

If quorum's child is broken, we can use mirror job to replace it. But sometimes, the user only need to remove the broken child, and add it later when the problem is fixed.

It is based on the following patch:
http://lists.nongnu.org/archive/html/qemu-devel/2015-09/msg04579.html

ChangLog:
v4:
1. drop nbd driver's implementation. We can use human-monitor-command to do it.
2. Rename the command name.
v3:
1. Don't open BDS in bdrv_add_child(). Use the existing BDS which is created by the QMP command blockdev-add.
2. The driver NBD can support filename, path, host:port now. v2:
1. Use bdrv_get_device_or_node_name() instead of new function bdrv_get_id_or_node_name()
2. Update the error message
3. Update the documents in block-core.json

Wen Congyang (4):
Add new block driver interface to add/delete a BDS's child
quorum: implement bdrv_add_child() and bdrv_del_child()
qmp: add monitor command to add/remove a child
hmp: add monitor command to add/remove a child

 block.c                   | 56 ++++++++++++++++++++++++++++++++++--
 block/quorum.c            | 72 +++++++++++++++++++++++++++++++++++++++++++++--
 blockdev.c                | 48 +++++++++++++++++++++++++++++++
 hmp-commands.hx           | 28 ++++++++++++++++++
 hmp.c                     | 20 +++++++++++++
 hmp.h                     |  2 ++
 include/block/block.h     |  8 ++++++
 include/block/block_int.h |  5 ++++
 qapi/block-core.json      | 34 ++++++++++++++++++++++
 qmp-commands.hx           | 54 +++++++++++++++++++++++++++++++++++
 10 files changed, 322 insertions(+), 5 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v4 1/4 Add new block driver interface to add/delete a BDS's child

In some cases, we want to take a quorum child offline, and take another child online.

---
 block.c                   | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 include/block/block.h     |  5 +++++
 include/block/block_int.h |  5 +++++
 3 files changed, 60 insertions(+)
block.c +50 -0
index e815d73..bb7657b 100644
@@ -4265,3 +4265,53 @@ BlockAcctStats *bdrv_get_stats(BlockDriverState *bs)
 {
     return &bs->stats;
 }
+
+/*
+ * Hot add/remove a BDS's child. So the user can take a child offline when
+ * it is broken and take a new child online
+ */
+void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,
+                    Error **errp)
+{
+
+    if (!parent_bs->drv || !parent_bs->drv->bdrv_add_child) {
+        error_setg(errp, "The BDS %s doesn't support adding a child",
+                   bdrv_get_device_or_node_name(parent_bs));
+        return;
+    }
+
+    if (!QLIST_EMPTY(&child_bs->parents)) {
+        error_setg(errp, "The BDS %s already has parent",
+                   child_bs->node_name);
+        return;
+    }
+
+    parent_bs->drv->bdrv_add_child(parent_bs, child_bs, errp);
+}
+
+void bdrv_del_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,
+                    Error **errp)
+{
+    BdrvChild *child;
+
+    if (!parent_bs->drv || !parent_bs->drv->bdrv_del_child) {
+        error_setg(errp, "The BDS %s doesn't support removing a child",
+                   bdrv_get_device_or_node_name(parent_bs));
+        return;
+    }
+
+    QLIST_FOREACH(child, &parent_bs->children, next) {
+        if (child->bs == child_bs) {
+            break;
+        }
+    }
+
+    if (!child) {
+        error_setg(errp, "The BDS %s is not the BDS %s's child",
+                   bdrv_get_device_or_node_name(child_bs),
+                   bdrv_get_device_or_node_name(parent_bs));
+        return;
+    }
+
+    parent_bs->drv->bdrv_del_child(parent_bs, child_bs, errp);
+}
include/block/block.h +5 -0
index ef67353..665c56f 100644
@@ -616,4 +616,9 @@ void bdrv_flush_io_queue(BlockDriverState *bs);
 
 BlockAcctStats *bdrv_get_stats(BlockDriverState *bs);
 
+void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child,
+                    Error **errp);
+void bdrv_del_child(BlockDriverState *parent, BlockDriverState *child,
+                    Error **errp);
+
 #endif
include/block/block_int.h +5 -0
index 2f2c47b..64cbc55 100644
@@ -288,6 +288,11 @@ struct BlockDriver {
      */
     int (*bdrv_probe_geometry)(BlockDriverState *bs, HDGeometry *geo);
 
+    void (*bdrv_add_child)(BlockDriverState *parent, BlockDriverState *child,
+                           Error **errp);
+    void (*bdrv_del_child)(BlockDriverState *parent, BlockDriverState *child,
+                           Error **errp);
+
     QLIST_ENTRY(BlockDriver) list;
 };
 
Signature · 1 line
2.4.3
#3 lore raw

PATCH v4 2/4 quorum: implement bdrv_add_child() and bdrv_del_child()

In reply to Wen Congyang
---
 block.c               |  6 ++---
 block/quorum.c        | 72 +++++++++++++++++++++++++++++++++++++++++++++++++--
 include/block/block.h |  3 +++
 3 files changed, 76 insertions(+), 5 deletions(-)
block.c +3 -3
index bb7657b..4dc0e29 100644
@@ -1079,9 +1079,9 @@ static int bdrv_fill_options(QDict **options, const char **pfilename,
     return 0;
 }
 
-static BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
-                                    BlockDriverState *child_bs,
-                                    const BdrvChildRole *child_role)
+BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
+                             BlockDriverState *child_bs,
+                             const BdrvChildRole *child_role)
 {
     BdrvChild *child = g_new(BdrvChild, 1);
     *child = (BdrvChild) {
block/quorum.c +70 -2

103 lines not on this page · raw message

include/block/block.h +3 -0
index 665c56f..bd97399 100644
@@ -514,6 +514,9 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);
 void bdrv_ref(BlockDriverState *bs);
 void bdrv_unref(BlockDriverState *bs);
 void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);
+BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
+                             BlockDriverState *child_bs,
+                             const BdrvChildRole *child_role);
 
 bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
 void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
Signature · 1 line
2.4.3
#6 lore raw

PATCH v4 4/4 hmp: add monitor command to add/remove a child

In reply to Wen Congyang
---
 hmp-commands.hx | 28 ++++++++++++++++++++++++++++
 hmp.c           | 20 ++++++++++++++++++++
 hmp.h           |  2 ++
 3 files changed, 50 insertions(+)
hmp-commands.hx +28 -0
index a511004..6c5fe82 100644
@@ -193,6 +193,34 @@ actions (drive options rerror, werror).
 ETEXI
 
     {
+        .name       = "blockdev_child_add",
+        .args_type  = "id:B,child:B",
+        .params     = "parent child",
+        .help       = "add a child to a BDS",
+        .mhandler.cmd = hmp_blockdev_child_add,
+    },
+
+STEXI
+@item blockdev_child_add @var{parent device} @var{child device}
+@findex blockdev_child_add
+Add a child to the block device.
+ETEXI
+
+    {
+        .name       = "blockdev_child_del",
+        .args_type  = "id:B,child:B",
+        .params     = "parent child",
+        .help       = "remove a child from a BDS",
+        .mhandler.cmd = hmp_blockdev_child_del,
+    },
+
+STEXI
+@item blockdev_child_del @var{parent device} @var{child device}
+@findex blockdev_child_del
+Remove a child from the parent device.
+ETEXI
+
+    {
         .name       = "change",
         .args_type  = "device:B,target:F,arg:s?",
         .params     = "device filename [format]",
hmp.c +20 -0
index 3f807b7..1dc1bed 100644
@@ -2325,3 +2325,23 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
 
     qapi_free_RockerOfDpaGroupList(list);
 }
+
+void hmp_blockdev_child_add(Monitor *mon, const QDict *qdict)
+{
+    const char *id = qdict_get_str(qdict, "id");
+    const char *child_id = qdict_get_str(qdict, "child");
+    Error *local_err = NULL;
+
+    qmp_x_blockdev_child_add(id, child_id, &local_err);
+    hmp_handle_error(mon, &local_err);
+}
+
+void hmp_blockdev_child_del(Monitor *mon, const QDict *qdict)
+{
+    const char *id = qdict_get_str(qdict, "id");
+    const char *child_id = qdict_get_str(qdict, "child");
+    Error *local_err = NULL;
+
+    qmp_x_blockdev_child_del(id, child_id, &local_err);
+    hmp_handle_error(mon, &local_err);
+}
hmp.h +2 -0
index 81656c3..3033648 100644
@@ -130,5 +130,7 @@ 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_child_add(Monitor *mon, const QDict *qdict);
+void hmp_blockdev_child_del(Monitor *mon, const QDict *qdict);
 
 #endif
Signature · 1 line
2.4.3
#4 lore raw

PATCH v4 3/4 qmp: add monitor command to add/remove a child

In reply to Wen Congyang
---
 blockdev.c           | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 qapi/block-core.json | 34 +++++++++++++++++++++++++++++++++
 qmp-commands.hx      | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
blockdev.c +48 -0
index 32b04b4..8da0ffb 100644
@@ -3086,6 +3086,54 @@ fail:
     qmp_output_visitor_cleanup(ov);
 }
 
+void qmp_x_blockdev_child_add(const char *parent, const char *child,
+                              Error **errp)
+{
+    BlockDriverState *parent_bs, *child_bs;
+    Error *local_err = NULL;
+
+    parent_bs = bdrv_lookup_bs(parent, parent, &local_err);
+    if (!parent_bs) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    child_bs = bdrv_find_node(child);
+    if (!child_bs) {
+        error_setg(errp, "Node '%s' not found", child);
+        return;
+    }
+
+    bdrv_add_child(parent_bs, child_bs, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+
+void qmp_x_blockdev_child_del(const char *parent, const char *child,
+                              Error **errp)
+{
+    BlockDriverState *parent_bs, *child_bs;
+    Error *local_err = NULL;
+
+    parent_bs = bdrv_lookup_bs(parent, parent, &local_err);
+    if (!parent_bs) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    child_bs = bdrv_find_node(child);
+    if (!child_bs) {
+        error_setg(errp, "Node '%s' not found", child);
+        return;
+    }
+
+    bdrv_del_child(parent_bs, child_bs, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+
 BlockJobInfoList *qmp_query_block_jobs(Error **errp)
 {
     BlockJobInfoList *head = NULL, **p_next = &head;
qapi/block-core.json +34 -0
index bb2189e..9418f05 100644
@@ -2114,3 +2114,37 @@
 ##
 { 'command': 'block-set-write-threshold',
   'data': { 'node-name': 'str', 'write-threshold': 'uint64' } }
+
+##
+# @x-blockdev-child-add
+#
+# Add a new child to the parent BDS. Currently only the Quorum driver
+# implements this feature. This is useful to fix a broken quorum child.
+#
+# @parent: graph node name or id which the child will be added to.
+#
+# @child: graph node name that will be added.
+#
+# Note: this command is experimental, and not a stable API.
+#
+# Since: 2.5
+##
+{ 'command': 'x-blockdev-child-add',
+  'data' : { 'parent': 'str', 'child': 'str' } }
+
+##
+# @x-blockdev-child-del
+#
+# Remove a child from the parent BDS. Currently only the Quorum driver
+# implements this feature. This is useful to fix a broken quorum child.
+# Note, you can't remove a child if it would bring the quorum below its
+# threshold.
+#
+# @parent: graph node name or id from which the child will removed.
+#
+# @child: graph node name that will be removed.
+#
+# Since: 2.5
+##
+{ 'command': 'x-blockdev-child-del',
+  'data' : { 'parent': 'str', 'child': 'str' } }
qmp-commands.hx +54 -0

60 lines not on this page · raw message

Signature · 1 line
2.4.3
Reviewed-by on v4 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH v4 1/4] Add new block driver interface to add/delete a BDS's child

In reply to Wen Congyang
Quoted 13 lines · Wen Congyang

In some cases, we want to take a quorum child offline, and take another child online.

---
 block.c                   | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 include/block/block.h     |  5 +++++
 include/block/block_int.h |  5 +++++
 3 files changed, 60 insertions(+)

block.c BlockAcctStats *bdrv_get_stats(BlockDriverState *bs) · line 4312

Quoted 9 lines
block.c +8 -0
+void bdrv_del_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,
+                    Error **errp)
+{
+    BdrvChild *child;
 
+    if (!child) {
+        error_setg(errp, "The BDS %s is not the BDS %s's child",
+                   bdrv_get_device_or_node_name(child_bs),
+                   bdrv_get_device_or_node_name(parent_bs));

Better would be:

"BDS %s is not a child of %s"

With that,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH v4 3/4] qmp: add monitor command to add/remove a child

In reply to Wen Congyang
Quoted 3 lines · Wen Congyang

Commit message should probably mention the name of the new commands.

Also, if you still want the command to be experimental, it would be nice to explain in the commit message why you have chosen that, and what might change in the future to make us either commit to the interface or replace it with a better one.

Quoted 10 lines
---
 blockdev.c           | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 qapi/block-core.json | 34 +++++++++++++++++++++++++++++++++
 qmp-commands.hx      | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
qmp-commands.hx +3 -0
+SQMP
+x-blockdev-child-add
+------------

qmp-commands.hx Example (2): · line 3917

Quoted 10 lines
qmp-commands.hx +10 -0
+
+Add a child to a quorum node.
+
+Arguments:
+
+- "parent": the quorum's id or node name
+- "child": the child node-name which will be added
+
+Note: this command is experimental, and not a stable API. It doesn't
+support all kinds of child, and not support all block drivers.

s/of child/of children/
s/and not support/nor/

qmp-commands.hx Example (2): · line 3923

Quoted 6 lines
qmp-commands.hx +6 -0
+
+Example:
+
+-> { "execute": "x-blockdev-child-add",
+    "arguments": { "parent": "disk1", "child": "new_node" } }
+<- { "return": {} }

Might be nice to extend the example to show the blockdev-add that created "new_node" before this command plugs it in.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw

Re: [Qemu-devel] [PATCH v4 4/4] hmp: add monitor command to add/remove a child

In reply to Wen Congyang
Quoted 11 lines · Wen Congyang
---
 hmp-commands.hx | 28 ++++++++++++++++++++++++++++
 hmp.c           | 20 ++++++++++++++++++++
 hmp.h           |  2 ++
 3 files changed, 50 insertions(+)

hmp-commands.hx actions (drive options rerror, werror). · line 204

Quoted 3 lines
hmp-commands.hx +3 -0
+
+STEXI
+@item blockdev_child_add @var{parent device} @var{child device}

This produces poor-looking info that makes it appear that the command takes 4 parameters, with two of those parameters both named 'device'. I'd use just:

@item blockdev_child_add @var{parent} @var{child}

Quoted 2 lines

+STEXI
+@item blockdev_child_del @var{parent device} @var{child device}

Likewise.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org