[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/15] block: add bdrv_replace_node_common()
From: |
Max Reitz |
Subject: |
[PULL 14/15] block: add bdrv_replace_node_common() |
Date: |
Mon, 9 Nov 2020 18:38:38 +0100 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Add new parameter to bdrv_replace_node(): auto_skip. With
auto_skip=false we'll have stricter behavior: update _all_ from
parents or fail. New behaviour will be used in the following commit in
block.c, so keep original function name as public interface.
Note: new error message is a bit funny in contrast with further
"Cannot" in case of frozen child, but we'd better keep some difference
to make it possible to distinguish one from another on failure. Still,
actually we'd better refactor should_update_child() call to distinguish
also different kinds of "should not". Let's do it later.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20201106124241.16950-3-vsementsov@virtuozzo.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/block.c b/block.c
index 1e68bd2f5f..9a945a058d 100644
--- a/block.c
+++ b/block.c
@@ -4563,8 +4563,16 @@ static bool should_update_child(BdrvChild *c,
BlockDriverState *to)
return ret;
}
-void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
- Error **errp)
+/*
+ * With auto_skip=true bdrv_replace_node_common skips updating from parents
+ * if it creates a parent-child relation loop or if parent is block-job.
+ *
+ * With auto_skip=false the error is returned if from has a parent which should
+ * not be updated.
+ */
+static void bdrv_replace_node_common(BlockDriverState *from,
+ BlockDriverState *to,
+ bool auto_skip, Error **errp)
{
BdrvChild *c, *next;
GSList *list = NULL, *p;
@@ -4583,7 +4591,12 @@ void bdrv_replace_node(BlockDriverState *from,
BlockDriverState *to,
QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
assert(c->bs == from);
if (!should_update_child(c, to)) {
- continue;
+ if (auto_skip) {
+ continue;
+ }
+ error_setg(errp, "Should not change '%s' link to '%s'",
+ c->name, from->node_name);
+ goto out;
}
if (c->frozen) {
error_setg(errp, "Cannot change '%s' link to '%s'",
@@ -4623,6 +4636,12 @@ out:
bdrv_unref(from);
}
+void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
+ Error **errp)
+{
+ return bdrv_replace_node_common(from, to, true, errp);
+}
+
/*
* Add new bs contents at the top of an image chain while the chain is
* live, while keeping required fields on the top layer.
--
2.28.0
- [PULL 03/15] qcow2: Document and enforce the QCowL2Meta invariants, (continued)
- [PULL 03/15] qcow2: Document and enforce the QCowL2Meta invariants, Max Reitz, 2020/11/09
- [PULL 05/15] hw/block/nvme: fix uint16_t use of uint32_t sgls member, Max Reitz, 2020/11/09
- [PULL 04/15] hw/block/nvme: fix null ns in register namespace, Max Reitz, 2020/11/09
- [PULL 06/15] hw/block/nvme: fix free of array-typed value, Max Reitz, 2020/11/09
- [PULL 10/15] block: enable libnfs on msys2/mingw in cirrus.yml, Max Reitz, 2020/11/09
- [PULL 07/15] iotests: add filter_qmp_virtio_scsi function, Max Reitz, 2020/11/09
- [PULL 08/15] iotests: rewrite iotest 240 in python, Max Reitz, 2020/11/09
- [PULL 11/15] block: Fix integer promotion error in bdrv_getlength(), Max Reitz, 2020/11/09
- [PULL 12/15] block: Fix some code style problems, "foo* bar" should be "foo *bar", Max Reitz, 2020/11/09
- [PULL 13/15] block: add forgotten bdrv_abort_perm_update() to bdrv_co_invalidate_cache(), Max Reitz, 2020/11/09
- [PULL 14/15] block: add bdrv_replace_node_common(),
Max Reitz <=
- [PULL 09/15] block: Fixes nfs compiling error on msys2/mingw, Max Reitz, 2020/11/09
- [PULL 15/15] block: make bdrv_drop_intermediate() less wrong, Max Reitz, 2020/11/09
- Re: [PULL 00/15] Block patches for 5.2.0-rc1, Max Reitz, 2020/11/09