From 20a63d2cec838c2dde4d246c4d7abe747d9b7a11 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 16 Dec 2013 14:45:31 +0800 Subject: commit: Support commit active layer If active is top, it will be mirrored to base, (with block/mirror.c code), then the image is switched when user completes the block job. QMP documentation is updated. Signed-off-by: Fam Zheng Signed-off-by: Stefan Hajnoczi --- block/mirror.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'block') diff --git a/block/mirror.c b/block/mirror.c index 04af341be6..2932bab27a 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -481,6 +481,13 @@ immediate_exit: bdrv_reopen(s->target, bdrv_get_flags(s->common.bs), NULL); } bdrv_swap(s->target, s->common.bs); + if (s->common.driver->job_type == BLOCK_JOB_TYPE_COMMIT) { + /* drop the bs loop chain formed by the swap: break the loop then + * trigger the unref from the top one */ + BlockDriverState *p = s->base->backing_hd; + s->base->backing_hd = NULL; + bdrv_unref(p); + } } bdrv_unref(s->target); block_job_completed(&s->common, ret); @@ -623,6 +630,10 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base, BlockDriverCompletionFunc *cb, void *opaque, Error **errp) { + if (bdrv_reopen(base, bs->open_flags, errp)) { + return; + } + bdrv_ref(base); mirror_start_job(bs, base, speed, 0, 0, on_error, on_error, cb, opaque, errp, &commit_active_job_driver, false, base); -- cgit v1.2.3