[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 45/47] mirror: add buf-size argument to drive-mirror
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 45/47] mirror: add buf-size argument to drive-mirror |
Date: |
Tue, 24 Jul 2012 13:04:23 +0200 |
This makes sense when the next commit starts using the extra buffer space
to perform many I/O operations asynchronously.
Signed-off-by: Paolo Bonzini <address@hidden>
---
block/mirror.c | 6 +++---
block_int.h | 5 +++--
blockdev.c | 9 ++++++++-
hmp.c | 2 +-
qapi-schema.json | 5 ++++-
qmp-commands.hx | 4 +++-
tests/qemu-iotests/039 | 31 +++++++++++++++++++++++++++++++
7 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index 971c923..475a7e0 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -403,8 +403,8 @@ static BlockJobType mirror_job_type = {
};
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
- int64_t speed, int64_t granularity, MirrorSyncMode mode,
- BlockdevOnError on_source_error,
+ int64_t speed, int64_t granularity, int64_t buf_size,
+ MirrorSyncMode mode, BlockdevOnError on_source_error,
BlockdevOnError on_target_error,
BlockDriverCompletionFunc *cb,
void *opaque, Error **errp)
@@ -430,7 +430,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState
*target,
s->target = target;
s->mode = mode;
s->granularity = granularity;
- s->buf_size = granularity;
+ s->buf_size = MAX(buf_size, granularity);
bdrv_set_dirty_tracking(bs, granularity >> BDRV_SECTOR_BITS);
bdrv_set_on_error(s->target, on_target_error, on_target_error);
diff --git a/block_int.h b/block_int.h
index 69bb769..7f2b7f1 100644
--- a/block_int.h
+++ b/block_int.h
@@ -311,6 +311,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState
*base,
* @target: Block device to write to.
* @speed: The maximum speed, in bytes per second, or 0 for unlimited.
* @granularity: The chosen granularity for the dirty bitmap.
+ * @buf_size: The amount of data that can be in flight at one time.
* @mode: Whether to collapse all images in the chain to the target.
* @on_source_error: The action to take upon error reading from the source.
* @on_target_error: The action to take upon error writing to the target.
@@ -324,8 +325,8 @@ void stream_start(BlockDriverState *bs, BlockDriverState
*base,
* @bs will be switched to read from @target.
*/
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
- int64_t speed, int64_t granularity, MirrorSyncMode mode,
- BlockdevOnError on_source_error,
+ int64_t speed, int64_t granularity, int64_t buf_size,
+ MirrorSyncMode mode, BlockdevOnError on_source_error,
BlockdevOnError on_target_error,
BlockDriverCompletionFunc *cb,
void *opaque, Error **errp);
diff --git a/blockdev.c b/blockdev.c
index 13b6217..d617d02 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -827,12 +827,15 @@ exit:
return;
}
+#define DEFAULT_MIRROR_BUF_SIZE (10 << 20)
+
void qmp_drive_mirror(const char *device, const char *target,
bool has_format, const char *format,
enum MirrorSyncMode sync,
bool has_mode, enum NewImageMode mode,
bool has_speed, int64_t speed,
bool has_granularity, int64_t granularity,
+ bool has_buf_size, int64_t buf_size,
bool has_on_source_error, BlockdevOnError
on_source_error,
bool has_on_target_error, BlockdevOnError
on_target_error,
Error **errp)
@@ -861,6 +864,10 @@ void qmp_drive_mirror(const char *device, const char
*target,
if (!has_granularity) {
granularity = 65536;
}
+ if (!has_buf_size) {
+ buf_size = DEFAULT_MIRROR_BUF_SIZE;
+ }
+
if (granularity < 512 || granularity > 1048576 * 64) {
error_set(errp, QERR_INVALID_PARAMETER, device);
return;
@@ -948,7 +955,7 @@ void qmp_drive_mirror(const char *device, const char
*target,
return;
}
- mirror_start(bs, target_bs, speed, granularity, sync,
+ mirror_start(bs, target_bs, speed, granularity, buf_size, sync,
on_source_error, on_target_error,
block_job_cb, bs, &local_err);
if (local_err != NULL) {
diff --git a/hmp.c b/hmp.c
index 4f95096..85dcf7e 100644
--- a/hmp.c
+++ b/hmp.c
@@ -719,7 +719,7 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
qmp_drive_mirror(device, filename, !!format, format,
full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
- true, mode, false, 0, false, 0,
+ true, mode, false, 0, false, 0, false, 0,
false, 0, false, 0, &errp);
hmp_handle_error(mon, &errp);
}
diff --git a/qapi-schema.json b/qapi-schema.json
index fb0ccc7..8cfcd4d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1392,6 +1392,9 @@
# @granularity: #optional granularity of the dirty bitmap, default is 64K.
# Must be a power of 2 between 512 and 64M.
#
+# @buf-size: #optional maximum amount of data in flight from source to
+# target.
+#
# @on-source-error: #optional the action to take on an error on the source,
# default 'report'. 'stop' and 'enospc' can only be used
# if the block device supports io-status (see BlockInfo).
@@ -1413,7 +1416,7 @@
'data': { 'device': 'str', 'target': 'str', '*format': 'str',
'sync': 'MirrorSyncMode', '*mode': 'NewImageMode',
'*speed': 'int', '*granularity': 'int',
- '*on-source-error': 'BlockdevOnError',
+ '*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
'*on-target-error': 'BlockdevOnError' } }
##
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 89e12f5..1b9f5af 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -840,7 +840,7 @@ EQMP
.name = "drive-mirror",
.args_type = "sync:s,device:B,target:s,speed:i?,mode:s?,format:s?,"
"on-source-error:s?,on-target-error:s?,"
- "granularity:i?",
+ "buf-size:i?,granularity:i?",
.mhandler.cmd_new = qmp_marshal_input_drive_mirror,
},
@@ -866,6 +866,8 @@ Arguments:
(json-int)
- "granularity": granularity of the dirty bitmap (json-int, default 64k,
must be a power of two between 512 and 64M.
+- "buf_size": maximum amount of data in flight from source to target
+ (json-int, default 10M)
- "sync": what parts of the disk image should be copied to the destination;
possibilities include "full" for all the disk, "top" for only the sectors
allocated in the topmost image, or "none" to only replicate new I/O
diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039
index 17fa05f..a76766b 100755
--- a/tests/qemu-iotests/039
+++ b/tests/qemu-iotests/039
@@ -192,6 +192,37 @@ class TestSingleDrive(ImageMirroringTestCase):
self.assertTrue(self.compare_images(test_img, target_img),
'target image does not match source after mirroring')
+ def test_small_buffer(self):
+ self.assert_no_active_mirrors()
+
+ # A small buffer is rounded up automatically
+ result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+ buf_size=4096, target=target_img)
+ self.assert_qmp(result, 'return', {})
+
+ self.complete_and_wait()
+ result = self.vm.qmp('query-block')
+ self.assert_qmp(result, 'return[0]/inserted/file', target_img)
+ self.vm.shutdown()
+ self.assertTrue(self.compare_images(test_img, target_img),
+ 'target image does not match source after mirroring')
+
+ def test_small_buffer2(self):
+ self.assert_no_active_mirrors()
+
+ qemu_img('create', '-f', iotests.imgfmt, '-o',
'cluster_size=%d,size=%d'
+ % (TestSingleDrive.image_len,
TestSingleDrive.image_len), target_img)
+ result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+ buf_size=65536, mode='existing',
target=target_img)
+ self.assert_qmp(result, 'return', {})
+
+ self.complete_and_wait()
+ result = self.vm.qmp('query-block')
+ self.assert_qmp(result, 'return[0]/inserted/file', target_img)
+ self.vm.shutdown()
+ self.assertTrue(self.compare_images(test_img, target_img),
+ 'target image does not match source after mirroring')
+
def test_large_cluster(self):
self.assert_no_active_mirrors()
--
1.7.10.4
- [Qemu-devel] [PATCH 17/47] qemu-iotests: add tests for streaming error handling, (continued)
- [Qemu-devel] [PATCH 17/47] qemu-iotests: add tests for streaming error handling, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 18/47] block: live snapshot documentation tweaks, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 22/47] block: make device optional in BlockInfo, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 30/47] mirror: implement completion, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 28/47] qmp: add drive-mirror command, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 21/47] block: add bdrv_ensure_backing_file, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 35/47] qemu-iotests: add testcases for mirroring on-source-error/on-target-error, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 24/47] block: introduce new dirty bitmap functionality, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 45/47] mirror: add buf-size argument to drive-mirror,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 25/47] block: add block-job-complete, Paolo Bonzini, 2012/07/24
- [Qemu-devel] [PATCH 43/47] mirror: allow customizing the granularity, Paolo Bonzini, 2012/07/24
[Qemu-devel] [PATCH 44/47] mirror: switch mirror_iteration to AIO, Paolo Bonzini, 2012/07/24
[Qemu-devel] [PATCH 38/47] block: implement dirty bitmap using HBitmap, Paolo Bonzini, 2012/07/24