aboutsummaryrefslogtreecommitdiff
path: root/block/block-backend.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-10-07 13:59:08 +0200
committerKevin Wolf <kwolf@redhat.com>2014-10-20 13:41:26 +0200
commit9ba10c95a4a63ef453893ba16bf1c8e11a1d3c39 (patch)
treeeffe1e5953818f0965be290de0748b5516e7015a /block/block-backend.c
parent8fb3c76c949f34f29c5252ee339fbe1cbfcc3234 (diff)
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 <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/block-backend.c')
-rw-r--r--block/block-backend.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index d4bdd48e03..6236b5b96d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -54,8 +54,6 @@ BlockBackend *blk_new(const char *name, Error **errp)
/*
* Create a new BlockBackend with a new BlockDriverState attached.
- * Both have a reference count of one. Caller owns *both* references.
- * TODO Let caller own only the BlockBackend reference
* Otherwise just like blk_new(), which see.
*/
BlockBackend *blk_new_with_bs(const char *name, Error **errp)
@@ -83,7 +81,9 @@ static void blk_delete(BlockBackend *blk)
{
assert(!blk->refcnt);
if (blk->bs) {
+ assert(blk->bs->blk == blk);
blk->bs->blk = NULL;
+ bdrv_unref(blk->bs);
blk->bs = NULL;
}
/* Avoid double-remove after blk_hide_on_behalf_of_do_drive_del() */
@@ -119,8 +119,6 @@ void blk_ref(BlockBackend *blk)
* Decrement @blk's reference count.
* If this drops it to zero, destroy @blk.
* For convenience, do nothing if @blk is null.
- * Does *not* touch the attached BlockDriverState's reference count.
- * TODO Decrement it!
*/
void blk_unref(BlockBackend *blk)
{