[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 14/21] block: Use bdrv_unref_child() for all children
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 14/21] block: Use bdrv_unref_child() for all children in bdrv_close() |
Date: |
Tue, 28 May 2019 21:28:40 +0200 |
From: Alberto Garcia <address@hidden>
bdrv_unref_child() does the following things:
- Updates the child->bs->inherits_from pointer.
- Calls bdrv_detach_child() to remove the BdrvChild from bs->children.
- Calls bdrv_unref() to unref the child BlockDriverState.
When bdrv_unref_child() was introduced in commit 33a604075c it was not
used in bdrv_close() because the drivers that had additional children
(like quorum or blkverify) had already called bdrv_unref() on their
children during their own close functions.
This was changed later (in 0bd6e91a7e for quorum, in 3e586be0b2 for
blkverify) so there's no reason not to use bdrv_unref_child() in
bdrv_close() anymore.
After this there's also no need to remove bs->backing and bs->file
separately from the rest of the children, so bdrv_close() can be
simplified.
Now bdrv_close() unrefs all children (before this patch it was only
bs->file and bs->backing). As a result, none of the callers of
brvd_attach_child() should remove their reference to child_bs (because
this function effectively steals that reference). This patch updates a
couple of tests that were doing their own bdrv_unref().
Signed-off-by: Alberto Garcia <address@hidden>
Message-id: address@hidden
[mreitz: s/where/were/]
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 16 +++-------------
tests/test-bdrv-drain.c | 6 ------
tests/test-bdrv-graph-mod.c | 1 -
3 files changed, 3 insertions(+), 20 deletions(-)
diff --git a/block.c b/block.c
index cb11537029..be37280dc7 100644
--- a/block.c
+++ b/block.c
@@ -3877,22 +3877,12 @@ static void bdrv_close(BlockDriverState *bs)
bs->drv = NULL;
}
- bdrv_set_backing_hd(bs, NULL, &error_abort);
-
- if (bs->file != NULL) {
- bdrv_unref_child(bs, bs->file);
- bs->file = NULL;
- }
-
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
- /* TODO Remove bdrv_unref() from drivers' close function and use
- * bdrv_unref_child() here */
- if (child->bs->inherits_from == bs) {
- child->bs->inherits_from = NULL;
- }
- bdrv_detach_child(child);
+ bdrv_unref_child(bs, child);
}
+ bs->backing = NULL;
+ bs->file = NULL;
g_free(bs->opaque);
bs->opaque = NULL;
atomic_set(&bs->copy_on_read, 0);
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
index eda90750eb..5534c2adf9 100644
--- a/tests/test-bdrv-drain.c
+++ b/tests/test-bdrv-drain.c
@@ -1436,12 +1436,6 @@ static void test_detach_indirect(bool by_parent_cb)
bdrv_unref(parent_b);
blk_unref(blk);
- /* XXX Once bdrv_close() unref's children instead of just detaching them,
- * this won't be necessary any more. */
- bdrv_unref(a);
- bdrv_unref(a);
- bdrv_unref(c);
-
g_assert_cmpint(a->refcnt, ==, 1);
g_assert_cmpint(b->refcnt, ==, 1);
g_assert_cmpint(c->refcnt, ==, 1);
diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c
index 283dc84869..747c0bf8fc 100644
--- a/tests/test-bdrv-graph-mod.c
+++ b/tests/test-bdrv-graph-mod.c
@@ -116,7 +116,6 @@ static void test_update_perm_tree(void)
g_assert_nonnull(local_err);
error_free(local_err);
- bdrv_unref(bs);
blk_unref(root);
}
--
2.21.0
- [Qemu-block] [PULL 00/21] Block patches, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 01/21] qcow2.h: add missing include, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 04/21] qcow2-threads: qcow2_co_do_compress: protect queuing by mutex, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 03/21] qcow2-threads: use thread_pool_submit_co, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 05/21] qcow2-threads: split out generic path, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 02/21] qcow2: add separate file for threaded data processing functions, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 13/21] block/backup: refactor: split out backup_calculate_cluster_size, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 16/21] qemu-img: rebase: Reuse parent BlockDriverState, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 07/21] qcow2: bdrv_co_pwritev: move encryption code out of the lock, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 06/21] qcow2: qcow2_co_preadv: improve locking, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 14/21] block: Use bdrv_unref_child() for all children in bdrv_close(),
Max Reitz <=
- [Qemu-block] [PULL 10/21] block/backup: move to copy_bitmap with granularity, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 15/21] block: Make bdrv_root_attach_child() unref child_bs on failure, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 09/21] block/backup: simplify backup_incremental_init_copy_bitmap, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 08/21] qcow2: do encryption in threads, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 21/21] blockdev: loosen restrictions on drive-backup source node, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 18/21] qemu-img: rebase: Reuse in-chain BlockDriverState, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 17/21] qemu-img: rebase: Reduce reads on in-chain rebase, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 11/21] block/backup: refactor and tolerate unallocated cluster skipping, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 20/21] qcow2-bitmap: initialize bitmap directory alignment, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 12/21] block/backup: unify different modes code path, Max Reitz, 2019/05/28