From 48ac0a4df84662f23da25262443e1810b70c2228 Mon Sep 17 00:00:00 2001 From: Wen Congyang Date: Fri, 15 May 2015 15:51:36 +0800 Subject: mirror: correct buf_size If bus_size is less than 0, the command fails. If buf_size is 0, use DEFAULT_MIRROR_BUF_SIZE. If buf_size % granularity is not 0, mirror_free_init() will do dangerous things. Signed-off-by: Wen Congyang Reviewed-by: Fam Zheng Message-id: 5555A588.3080907@cn.fujitsu.com Signed-off-by: Jeff Cody --- block/mirror.c | 11 ++++++++++- blockdev.c | 4 +--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index a2700ca154..323f747c75 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -20,6 +20,7 @@ #define SLICE_TIME 100000000ULL /* ns */ #define MAX_IN_FLIGHT 16 +#define DEFAULT_MIRROR_BUF_SIZE (10 << 20) /* The mirroring buffer is a list of granularity-sized chunks. * Free chunks are organized in a list. @@ -701,6 +702,14 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, return; } + if (buf_size < 0) { + error_setg(errp, "Invalid parameter 'buf-size'"); + return; + } + + if (buf_size == 0) { + buf_size = DEFAULT_MIRROR_BUF_SIZE; + } s = block_job_create(driver, bs, speed, cb, opaque, errp); if (!s) { @@ -714,7 +723,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, s->is_none_mode = is_none_mode; s->base = base; s->granularity = granularity; - s->buf_size = MAX(buf_size, granularity); + s->buf_size = ROUND_UP(buf_size, granularity); s->unmap = unmap; s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp); diff --git a/blockdev.c b/blockdev.c index 50421c8b98..62a4586cd6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2639,8 +2639,6 @@ out: aio_context_release(aio_context); } -#define DEFAULT_MIRROR_BUF_SIZE (10 << 20) - void qmp_drive_mirror(const char *device, const char *target, bool has_format, const char *format, bool has_node_name, const char *node_name, @@ -2682,7 +2680,7 @@ void qmp_drive_mirror(const char *device, const char *target, granularity = 0; } if (!has_buf_size) { - buf_size = DEFAULT_MIRROR_BUF_SIZE; + buf_size = 0; } if (!has_unmap) { unmap = true; -- cgit v1.2.3