Skip to contentSkip to conversation

blockdev-replace

RFC PATCH Superseded Vladimir Sementsov-Ogievskiy 1 participant 5 messages Dec 22, 2021 Block layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover blockdev-replace

Hi all!

v2:

1. Let's start with minimal functionality: replace only one specific child.

2. Explicit type of parent: qdev / export / driver

Hmm, 'driver' is for BlockDriverState.. Any better idea? I don't want to call it "node" or even "block-node", as finally, devices and exports are kind of nodes too in the whole block graph..

3. I think it's better to start with x- prefix

Plans for v3:

- add tests of filter insertion and removing
- add qmp transaction support

Vladimir Sementsov-Ogievskiy (4):
block-backend: blk_root(): drop const specifier on return type block/export: add blk_by_export_id()
block: make bdrv_find_child() function public
qapi: add blockdev-replace command

 qapi/block.json                | 61 ++++++++++++++++++++++++++++++++++
 include/block/block_int.h      |  1 +
 include/sysemu/block-backend.h |  3 +-
 block.c                        | 13 ++++++++
 block/block-backend.c          |  2 +-
 block/export/export.c          | 18 ++++++++++
 block/qapi-sysemu.c            | 56 +++++++++++++++++++++++++++++++
 blockdev.c                     | 14 --------
 8 files changed, 152 insertions(+), 16 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/4 block-backend: blk_root(): drop const specifier on return type

We'll need get non-const child pointer for graph modifications in further commits.

---
 include/sysemu/block-backend.h | 2 +-
 block/block-backend.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/sysemu/block-backend.h +1 -1
index e5e1524f06..904d70f49c 100644
@@ -277,7 +277,7 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
                                    int64_t bytes, BdrvRequestFlags read_flags,
                                    BdrvRequestFlags write_flags);
 
-const BdrvChild *blk_root(BlockBackend *blk);
+BdrvChild *blk_root(BlockBackend *blk);
 
 int blk_make_empty(BlockBackend *blk, Error **errp);
 
block/block-backend.c +1 -1
index 12ef80ea17..d994a0f096 100644
@@ -2438,7 +2438,7 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
                               bytes, read_flags, write_flags);
 }
 
-const BdrvChild *blk_root(BlockBackend *blk)
+BdrvChild *blk_root(BlockBackend *blk)
 {
     return blk->root;
 }
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/4 block/export: add blk_by_export_id()

In reply to Vladimir Sementsov-Ogievskiy
---
 include/sysemu/block-backend.h |  1 +
 block/export/export.c          | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)
include/sysemu/block-backend.h +1 -0
index 904d70f49c..250c7465a5 100644
@@ -124,6 +124,7 @@ DeviceState *blk_get_attached_dev(BlockBackend *blk);
 char *blk_get_attached_dev_id(BlockBackend *blk);
 BlockBackend *blk_by_dev(void *dev);
 BlockBackend *blk_by_qdev_id(const char *id, Error **errp);
+BlockBackend *blk_by_export_id(const char *id, Error **errp);
 void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
 int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
                                int64_t bytes, QEMUIOVector *qiov,
block/export/export.c +18 -0
index 6d3b9964c8..613b5bc1d5 100644
@@ -362,3 +362,21 @@ BlockExportInfoList *qmp_query_block_exports(Error **errp)
 
     return head;
 }
+
+BlockBackend *blk_by_export_id(const char *id, Error **errp)
+{
+    BlockExport *exp;
+
+    exp = blk_exp_find(id);
+    if (exp == NULL) {
+        error_setg(errp, "Export '%s' not found", id);
+        return NULL;
+    }
+
+    if (!exp->blk) {
+        error_setg(errp, "Export '%s' is empty", id);
+        return NULL;
+    }
+
+    return exp->blk;
+}
Signature · 1 line
2.31.1
#3 lore raw

PATCH v2 3/4 block: make bdrv_find_child() function public

In reply to Vladimir Sementsov-Ogievskiy

To be reused soon.

---
 include/block/block_int.h |  1 +
 block.c                   | 13 +++++++++++++
 blockdev.c                | 14 --------------
 3 files changed, 14 insertions(+), 14 deletions(-)
include/block/block_int.h +1 -0
index f4c75e8ba9..79bdde8bf4 100644
@@ -1433,6 +1433,7 @@ BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,
                                            BlockDriverState **bitmap_bs,
                                            Error **errp);
 
+BdrvChild *bdrv_find_child(BlockDriverState *parent_bs, const char *child_name);
 BdrvChild *bdrv_cow_child(BlockDriverState *bs);
 BdrvChild *bdrv_filter_child(BlockDriverState *bs);
 BdrvChild *bdrv_filter_or_cow_child(BlockDriverState *bs);
block.c +13 -0
index 0ac5b163d2..840d52e7c8 100644
@@ -7727,6 +7727,19 @@ int bdrv_make_empty(BdrvChild *c, Error **errp)
     return 0;
 }
 
+BdrvChild *bdrv_find_child(BlockDriverState *parent_bs, const char *child_name)
+{
+    BdrvChild *child;
+
+    QLIST_FOREACH(child, &parent_bs->children, next) {
+        if (strcmp(child->name, child_name) == 0) {
+            return child;
+        }
+    }
+
+    return NULL;
+}
+
 /*
  * Return the child that @bs acts as an overlay for, and from which data may be
  * copied in COW or COR operations.  Usually this is the backing file.
blockdev.c +0 -14
index 0eb2823b1b..ce23059d5e 100644
@@ -3644,20 +3644,6 @@ out:
     aio_context_release(aio_context);
 }
 
-static BdrvChild *bdrv_find_child(BlockDriverState *parent_bs,
-                                  const char *child_name)
-{
-    BdrvChild *child;
-
-    QLIST_FOREACH(child, &parent_bs->children, next) {
-        if (strcmp(child->name, child_name) == 0) {
-            return child;
-        }
-    }
-
-    return NULL;
-}
-
 void qmp_x_blockdev_change(const char *parent, bool has_child,
                            const char *child, bool has_node,
                            const char *node, Error **errp)
Signature · 1 line
2.31.1
#4 lore raw

PATCH v2 4/4 qapi: add blockdev-replace command

In reply to Vladimir Sementsov-Ogievskiy

Add a command that can replace bs in following BdrvChild structures:

- qdev blk root child
- block-export blk root child
- any child BlockDriverState selected by child-name

---
 qapi/block.json     | 61 +++++++++++++++++++++++++++++++++++++++++++++
 block/qapi-sysemu.c | 56 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
qapi/block.json +61 -0
index 82fcf2c914..a4dd1e34d4 100644
@@ -570,3 +570,64 @@
            '*boundaries-read': ['uint64'],
            '*boundaries-write': ['uint64'],
            '*boundaries-flush': ['uint64'] } }
+##
+# @BlockParentType:
+#
+# Since 7.0
+##
+{ 'enum': 'BlockParentType',
+  'data': ['qdev', 'driver', 'export'] }
+
+##
+# @BdrvChildRefQdev:
+#
+# Since 7.0
+##
+{ 'struct': 'BdrvChildRefQdev',
+  'data': { 'qdev-id': 'str' } }
+
+##
+# @BdrvChildRefExport:
+#
+# Since 7.0
+##
+{ 'struct': 'BdrvChildRefExport',
+  'data': { 'export-id': 'str' } }
+
+##
+# @BdrvChildRefDriver:
+#
+# Since 7.0
+##
+{ 'struct': 'BdrvChildRefDriver',
+  'data': { 'node-name': 'str', 'child': 'str' } }
+
+##
+# @BlockdevReplace:
+#
+# Since 7.0
+##
+{ 'union': 'BlockdevReplace',
+  'base': {
+      'parent-type': 'BlockParentType',
+      'new-child': 'str'
+  },
+  'discriminator': 'parent-type',
+  'data': {
+      'qdev': 'BdrvChildRefQdev',
+      'export': 'BdrvChildRefExport',
+      'driver': 'BdrvChildRefDriver'
+  } }
+
+##
+# @x-blockdev-replace:
+#
+# Replace a block-node associated with device (selected by
+# @qdev-id) or with block-export (selected by @export-id) or
+# any child of block-node (selected by @node-name and @child)
+# with @new-child block-node.
+#
+# Since 7.0
+##
+{ 'command': 'x-blockdev-replace', 'boxed': true,
+  'data': 'BlockdevReplace' }
block/qapi-sysemu.c +56 -0

59 lines not on this page · raw message

Signature · 1 line
2.31.1