diff options
author | Kevin Wolf <kwolf@redhat.com> | 2015-09-17 13:01:50 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2015-10-16 15:34:29 +0200 |
commit | a2d6190048d01c7012ab4fd6a2558f435b7b2fe8 (patch) | |
tree | c6caee1d5c509be15b11eb031694f198aca809dc /block/block-backend.c | |
parent | 439db28cf9d4c29c9a97040bc8e08f047ba7e0af (diff) | |
download | qemu-a2d6190048d01c7012ab4fd6a2558f435b7b2fe8.zip |
block-backend: Add blk_set_bs()
It allows changing the BlockDriverState that a BlockBackend points to.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block/block-backend.c')
-rw-r--r-- | block/block-backend.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index c2e873292a..225655126e 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) |