From a2d6190048d01c7012ab4fd6a2558f435b7b2fe8 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 17 Sep 2015 13:01:50 +0200 Subject: block-backend: Add blk_set_bs() It allows changing the BlockDriverState that a BlockBackend points to. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- block/block-backend.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'block') diff --git a/block/block-backend.c b/block/block-backend.c index c2e8732..2256551 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -239,6 +239,23 @@ BlockDriverState *blk_bs(BlockBackend *blk) } /* + * Changes the BlockDriverState attached to @blk + */ +void blk_set_bs(BlockBackend *blk, BlockDriverState *bs) +{ + bdrv_ref(bs); + + if (blk->bs) { + blk->bs->blk = NULL; + bdrv_unref(blk->bs); + } + assert(bs->blk == NULL); + + blk->bs = bs; + bs->blk = blk; +} + +/* * Return @blk's DriveInfo if any, else null. */ DriveInfo *blk_legacy_dinfo(BlockBackend *blk) -- cgit v1.1