summaryrefslogtreecommitdiffstats
path: root/blockdev.c
diff options
context:
space:
mode:
authorMax Reitz2019-07-24 19:12:30 +0200
committerMax Reitz2019-08-19 17:13:26 +0200
commitcdf3bc934ad1e5319b03f2c85f381f5ffd2f8ca8 (patch)
tree2e8dc4f2b68d10a6439335c1f733e563aaf71ec6 /blockdev.c
parentqemu-img: Fix bdrv_has_zero_init() use in convert (diff)
downloadqemu-cdf3bc934ad1e5319b03f2c85f381f5ffd2f8ca8.tar.gz
qemu-cdf3bc934ad1e5319b03f2c85f381f5ffd2f8ca8.tar.xz
qemu-cdf3bc934ad1e5319b03f2c85f381f5ffd2f8ca8.zip
mirror: Fix bdrv_has_zero_init() use
bdrv_has_zero_init() only has meaning for newly created images or image areas. If the mirror job itself did not create the image, it cannot rely on bdrv_has_zero_init()'s result to carry any meaning. This is the case for drive-mirror with mode=existing and always for blockdev-mirror. Note that we only have to zero-initialize the target with sync=full, because other modes actually do not promise that the target will contain the same data as the source after the job -- sync=top only promises to copy anything allocated in the top layer, and sync=none will only copy new I/O. (Which is how mirror has always handled it.) Signed-off-by: Max Reitz <mreitz@redhat.com> Message-id: 20190724171239.8764-3-mreitz@redhat.com Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/blockdev.c b/blockdev.c
index 2e536dde3e..fbef6845c8 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3782,6 +3782,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
bool has_replaces, const char *replaces,
enum MirrorSyncMode sync,
BlockMirrorBackingMode backing_mode,
+ bool zero_target,
bool has_speed, int64_t speed,
bool has_granularity, uint32_t granularity,
bool has_buf_size, int64_t buf_size,
@@ -3890,7 +3891,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
*/
mirror_start(job_id, bs, target,
has_replaces ? replaces : NULL, job_flags,
- speed, granularity, buf_size, sync, backing_mode,
+ speed, granularity, buf_size, sync, backing_mode, zero_target,
on_source_error, on_target_error, unmap, filter_node_name,
copy_mode, errp);
}
@@ -3906,6 +3907,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
int flags;
int64_t size;
const char *format = arg->format;
+ bool zero_target;
int ret;
bs = qmp_get_root_bs(arg->device, errp);
@@ -4007,6 +4009,10 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
goto out;
}
+ zero_target = (arg->sync == MIRROR_SYNC_MODE_FULL &&
+ (arg->mode == NEW_IMAGE_MODE_EXISTING ||
+ !bdrv_has_zero_init(target_bs)));
+
ret = bdrv_try_set_aio_context(target_bs, aio_context, errp);
if (ret < 0) {
bdrv_unref(target_bs);
@@ -4015,7 +4021,8 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs,
arg->has_replaces, arg->replaces, arg->sync,
- backing_mode, arg->has_speed, arg->speed,
+ backing_mode, zero_target,
+ arg->has_speed, arg->speed,
arg->has_granularity, arg->granularity,
arg->has_buf_size, arg->buf_size,
arg->has_on_source_error, arg->on_source_error,
@@ -4055,6 +4062,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
AioContext *aio_context;
BlockMirrorBackingMode backing_mode = MIRROR_LEAVE_BACKING_CHAIN;
Error *local_err = NULL;
+ bool zero_target;
int ret;
bs = qmp_get_root_bs(device, errp);
@@ -4067,6 +4075,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
return;
}
+ zero_target = (sync == MIRROR_SYNC_MODE_FULL);
+
aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context);
@@ -4077,7 +4087,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs,
has_replaces, replaces, sync, backing_mode,
- has_speed, speed,
+ zero_target, has_speed, speed,
has_granularity, granularity,
has_buf_size, buf_size,
has_on_source_error, on_source_error,