summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--block/mirror.c4
-rwxr-xr-xtests/qemu-iotests/0415
-rw-r--r--tests/qemu-iotests/041.out4
3 files changed, 10 insertions, 3 deletions
diff --git a/block/mirror.c b/block/mirror.c
index 21f2d8dcfd..6e502e3f21 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -259,9 +259,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
next_sector = sector_num;
while (nb_chunks-- > 0) {
MirrorBuffer *buf = QSIMPLEQ_FIRST(&s->buf_free);
+ size_t remaining = (nb_sectors * BDRV_SECTOR_SIZE) - op->qiov.size;
+
QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next);
s->buf_free_count--;
- qemu_iovec_add(&op->qiov, buf, s->granularity);
+ qemu_iovec_add(&op->qiov, buf, MIN(s->granularity, remaining));
/* Advance the HBitmapIter in parallel, so that we do not examine
* the same sector twice.
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index ef4f4657cc..ef74be63ec 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -211,6 +211,11 @@ class TestSingleDriveZeroLength(TestSingleDrive):
test_small_buffer2 = None
test_large_cluster = None
+class TestSingleDriveUnalignedLength(TestSingleDrive):
+ image_len = 1025 * 1024
+ test_small_buffer2 = None
+ test_large_cluster = None
+
class TestMirrorNoBacking(ImageMirroringTestCase):
image_len = 2 * 1024 * 1024 # MB
diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
index cfa5c0d0e6..802ffaa0c0 100644
--- a/tests/qemu-iotests/041.out
+++ b/tests/qemu-iotests/041.out
@@ -1,5 +1,5 @@
-...................................
+...........................................
----------------------------------------------------------------------
-Ran 35 tests
+Ran 43 tests
OK