mirror: Move base to MirrorBlockJob

This allows setting the base before entering mirror_run, commit will
make use of it.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Fam Zheng 2013-12-16 14:45:29 +08:00 committed by Stefan Hajnoczi
parent f95c625ce4
commit 5bc361b813
1 changed files with 10 additions and 2 deletions

View File

@ -31,6 +31,7 @@ typedef struct MirrorBlockJob {
BlockJob common; BlockJob common;
RateLimit limit; RateLimit limit;
BlockDriverState *target; BlockDriverState *target;
BlockDriverState *base;
MirrorSyncMode mode; MirrorSyncMode mode;
BlockdevOnError on_source_error, on_target_error; BlockdevOnError on_source_error, on_target_error;
bool synced; bool synced;
@ -337,8 +338,7 @@ static void coroutine_fn mirror_run(void *opaque)
if (s->mode != MIRROR_SYNC_MODE_NONE) { if (s->mode != MIRROR_SYNC_MODE_NONE) {
/* First part, loop on the sectors and initialize the dirty bitmap. */ /* First part, loop on the sectors and initialize the dirty bitmap. */
BlockDriverState *base; BlockDriverState *base = s->base;
base = s->mode == MIRROR_SYNC_MODE_FULL ? NULL : bs->backing_hd;
for (sector_num = 0; sector_num < end; ) { for (sector_num = 0; sector_num < end; ) {
int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1; int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1;
ret = bdrv_is_allocated_above(bs, base, ret = bdrv_is_allocated_above(bs, base,
@ -543,6 +543,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
void *opaque, Error **errp) void *opaque, Error **errp)
{ {
MirrorBlockJob *s; MirrorBlockJob *s;
BlockDriverState *base = NULL;
if (granularity == 0) { if (granularity == 0) {
/* Choose the default granularity based on the target file's cluster /* Choose the default granularity based on the target file's cluster
@ -565,6 +566,12 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
return; return;
} }
if (mode == MIRROR_SYNC_MODE_TOP) {
base = bs->backing_hd;
} else {
base = NULL;
}
s = block_job_create(&mirror_job_driver, bs, speed, cb, opaque, errp); s = block_job_create(&mirror_job_driver, bs, speed, cb, opaque, errp);
if (!s) { if (!s) {
return; return;
@ -574,6 +581,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
s->on_target_error = on_target_error; s->on_target_error = on_target_error;
s->target = target; s->target = target;
s->mode = mode; s->mode = mode;
s->base = base;
s->granularity = granularity; s->granularity = granularity;
s->buf_size = MAX(buf_size, granularity); s->buf_size = MAX(buf_size, granularity);