]> git.proxmox.com Git - mirror_qemu.git/commitdiff
mirror: Fix qiov size for short requests
authorKevin Wolf <kwolf@redhat.com>
Tue, 1 Jul 2014 14:52:21 +0000 (16:52 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Mon, 7 Jul 2014 07:15:29 +0000 (09:15 +0200)
When mirroring an image of a size that is not a multiple of the
mirror job granularity, the last request would have the right nb_sectors
argument, but a qiov that is rounded up to the next multiple of the
granularity. Don't do this.

This fixes a segfault that is caused by raw-posix being confused by this
and allocating a buffer with request length, but operating on it with
qiov length.

[s/Driver/Drive/ in qemu-iotests 041 as suggested by Eric
--Stefan]

Reported-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Tested-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/mirror.c
tests/qemu-iotests/041
tests/qemu-iotests/041.out

index 6c3ee7041c8234952daf8025830df06a73ed3135..c7a655fc585b2bcd4bc8e6abb27fad9c212ecdc9 100644 (file)
@@ -265,9 +265,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.
index 0815e192740b804db31082ee79c912d728a40677..005090ecc2321eb5dd8a2d4331988ade482d8aef 100755 (executable)
@@ -217,6 +217,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
 
index 42147c0b581f82d5dcf1ace68b29a0a64cc88d6e..24093bc63129cc04d4efb2a35af99d5abb472225 100644 (file)
@@ -1,5 +1,5 @@
-..............................................
+......................................................
 ----------------------------------------------------------------------
-Ran 46 tests
+Ran 54 tests
 
 OK