[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/11] block: Reorder cleanups in bdrv_close()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 06/11] block: Reorder cleanups in bdrv_close() |
Date: |
Tue, 14 Jul 2015 17:39:27 +0200 |
Block drivers may still want to access their child nodes in their
.bdrv_close handler. If they unref and/or detach a child by themselves,
this should not result in a double free.
There is additional code for backing files, which are just a special
case of child nodes. The same applies for them.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index b723cf2..d5c9f03 100644
--- a/block.c
+++ b/block.c
@@ -1901,6 +1901,14 @@ void bdrv_close(BlockDriverState *bs)
if (bs->drv) {
BdrvChild *child, *next;
+ bs->drv->bdrv_close(bs);
+
+ if (bs->backing_hd) {
+ BlockDriverState *backing_hd = bs->backing_hd;
+ bdrv_set_backing_hd(bs, NULL);
+ bdrv_unref(backing_hd);
+ }
+
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
/* TODO Remove bdrv_unref() from drivers' close function and use
* bdrv_unref_child() here */
@@ -1910,12 +1918,6 @@ void bdrv_close(BlockDriverState *bs)
bdrv_detach_child(child);
}
- if (bs->backing_hd) {
- BlockDriverState *backing_hd = bs->backing_hd;
- bdrv_set_backing_hd(bs, NULL);
- bdrv_unref(backing_hd);
- }
- bs->drv->bdrv_close(bs);
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
--
1.8.3.1
- [Qemu-devel] [PULL 00/11] Block layer patches for 2.4.0-rc1, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 02/11] nvme: properly report volatile write caches, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 03/11] block: Move bdrv_attach_child() calls up the call chain, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 01/11] nvme: implement the Flush command, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 05/11] block: Introduce bdrv_unref_child(), Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 04/11] block: Introduce bdrv_open_child(), Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 06/11] block: Reorder cleanups in bdrv_close(),
Kevin Wolf <=
- [Qemu-devel] [PULL 08/11] rbd: remove unused constants and fields, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 09/11] MAINTAINERS: update email address, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 07/11] block: Fix backing file child when modifying graph, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 11/11] rbd: fix ceph settings precedence, Kevin Wolf, 2015/07/14
- [Qemu-devel] [PULL 10/11] rbd: make qemu's cache setting override any ceph setting, Kevin Wolf, 2015/07/14
- Re: [Qemu-devel] [PULL 00/11] Block layer patches for 2.4.0-rc1, Peter Maydell, 2015/07/14