From 9ba10c95a4a63ef453893ba16bf1c8e11a1d3c39 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 7 Oct 2014 13:59:08 +0200 Subject: block: Make BlockBackend own its BlockDriverState On BlockBackend destruction, unref its BlockDriverState. Replaces the callers' unrefs. This turns the pointer from BlockBackend to BlockDriverState into a strong reference, managed with bdrv_ref() / bdrv_unref(). The back-pointer remains weak. Signed-off-by: Markus Armbruster Reviewed-by: Max Reitz Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- hw/block/xen_disk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'hw/block') diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 0022083..feb227f 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -872,7 +872,6 @@ static int blk_connect(struct XenDevice *xendev) xen_be_printf(&blkdev->xendev, 0, "error: %s\n", error_get_pretty(local_err)); error_free(local_err); - bdrv_unref(blkdev->bs); blk_unref(blk); blkdev->bs = NULL; return -1; @@ -888,7 +887,9 @@ static int blk_connect(struct XenDevice *xendev) } /* blkdev->bs is not create by us, we get a reference * so we can bdrv_unref() unconditionally */ - bdrv_ref(blkdev->bs); + /* Except we don't bdrv_unref() anymore, we blk_unref(). + * Conditionally, because we can't easily blk_ref() here. + * TODO Clean this up! */ } bdrv_attach_dev_nofail(blkdev->bs, blkdev); blkdev->file_size = bdrv_getlength(blkdev->bs); @@ -988,7 +989,6 @@ static void blk_disconnect(struct XenDevice *xendev) if (blkdev->bs) { bdrv_detach_dev(blkdev->bs, blkdev); - bdrv_unref(blkdev->bs); if (!blkdev->dinfo) { blk_unref(blk_by_name(blkdev->dev)); } -- cgit v1.1