Signed-off-by: Wen Congyang <we...@cn.fujitsu.com> Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> Signed-off-by: Gonglei <arei.gong...@huawei.com> --- block.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/block.c b/block.c index 220ba9a..1b362ba 100644 --- a/block.c +++ b/block.c @@ -1206,6 +1206,14 @@ static int bdrv_open_backing_reference_file(BlockDriverState *bs, } backing_hd = blk_bs(backing_blk); + /* Don't allow a disk use backing reference target */ + ret = blk_attach_dev(backing_hd->blk, bs); + if (ret < 0) { + error_setg(errp, "backing_hd %s is used by the other device model", + backing_name); + goto free_exit; + } + /* Backing reference itself? */ if (backing_hd == bs || bdrv_find_overlay(backing_hd, bs)) { error_setg(errp, "Backing reference itself"); @@ -1889,6 +1897,7 @@ void bdrv_close(BlockDriverState *bs) if (backing_hd->backing_hd->job) { block_job_cancel(backing_hd->backing_hd->job); } + blk_detach_dev(backing_hd->backing_hd->blk, bs); bdrv_set_backing_hd(backing_hd, NULL); bdrv_unref(backing_hd->backing_hd); } -- 2.1.0