diff --git a/block/block-backend.c b/block/block-backend.c index 19fdaaec1a..878c448855 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -333,6 +333,18 @@ void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk) } } +/* + * Disassociates the currently associated BlockDriverState from @blk. + */ +void blk_remove_bs(BlockBackend *blk) +{ + blk_update_root_state(blk); + + blk->bs->blk = NULL; + bdrv_unref(blk->bs); + blk->bs = NULL; +} + /* * Associates a new BlockDriverState with @blk. */ diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 9306a527bb..14a6d32bb2 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -72,6 +72,7 @@ BlockBackend *blk_by_name(const char *name); BlockBackend *blk_next(BlockBackend *blk); BlockDriverState *blk_bs(BlockBackend *blk); +void blk_remove_bs(BlockBackend *blk); void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk);