aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2015-06-16 10:58:20 +0200
committerKevin Wolf <kwolf@redhat.com>2015-07-14 17:15:23 +0200
commit9a7dedbc43c7c400663d2876a8ccb6d942a1429a (patch)
tree5bddec89d59df8211f438fa49ef2256bd617d423 /block.c
parent33a604075c51e5528eed970eeaeefe609ea2337d (diff)
downloadqemu-arm-9a7dedbc43c7c400663d2876a8ccb6d942a1429a.tar.gz
block: Reorder cleanups in bdrv_close()
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 <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/block.c b/block.c
index b723cf2858..d5c9f032aa 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;