9ae3a8
From 332e8935dd300a4c6f77407e281fe339759bc505 Mon Sep 17 00:00:00 2001
9ae3a8
From: Eric Blake <eblake@redhat.com>
9ae3a8
Date: Wed, 20 Aug 2014 16:40:14 +0200
9ae3a8
Subject: [PATCH 11/11] mirror: Fix qiov size for short requests
9ae3a8
9ae3a8
Message-id: <1408552814-23031-8-git-send-email-eblake@redhat.com>
9ae3a8
Patchwork-id: 60650
9ae3a8
O-Subject: [qemu-kvm-rhev 7.0.z PATCH 7/7] mirror: Fix qiov size for short requests
9ae3a8
Bugzilla: 1130603
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
When mirroring an image of a size that is not a multiple of the
9ae3a8
mirror job granularity, the last request would have the right nb_sectors
9ae3a8
argument, but a qiov that is rounded up to the next multiple of the
9ae3a8
granularity. Don't do this.
9ae3a8
9ae3a8
This fixes a segfault that is caused by raw-posix being confused by this
9ae3a8
and allocating a buffer with request length, but operating on it with
9ae3a8
qiov length.
9ae3a8
9ae3a8
[s/Driver/Drive/ in qemu-iotests 041 as suggested by Eric
9ae3a8
--Stefan]
9ae3a8
9ae3a8
Reported-by: Eric Blake <eblake@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Tested-by: Eric Blake <eblake@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 5a0f6fd5c84573387056e0464a7fc0c6fb70b2dc)
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	tests/qemu-iotests/041.out - context with fewer tests run downstream
9ae3a8
9ae3a8
Signed-off-by: Eric Blake <eblake@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/mirror.c             |    4 +++-
9ae3a8
 tests/qemu-iotests/041     |    5 +++++
9ae3a8
 tests/qemu-iotests/041.out |    4 ++--
9ae3a8
 3 files changed, 10 insertions(+), 3 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/mirror.c b/block/mirror.c
9ae3a8
index cdc0268..b7cf4ab 100644
9ae3a8
--- a/block/mirror.c
9ae3a8
+++ b/block/mirror.c
9ae3a8
@@ -243,9 +243,11 @@ static void coroutine_fn mirror_iteration(MirrorBlockJob *s)
9ae3a8
     next_sector = sector_num;
9ae3a8
     while (nb_chunks-- > 0) {
9ae3a8
         MirrorBuffer *buf = QSIMPLEQ_FIRST(&s->buf_free);
9ae3a8
+        size_t remaining = (nb_sectors * BDRV_SECTOR_SIZE) - op->qiov.size;
9ae3a8
+
9ae3a8
         QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next);
9ae3a8
         s->buf_free_count--;
9ae3a8
-        qemu_iovec_add(&op->qiov, buf, s->granularity);
9ae3a8
+        qemu_iovec_add(&op->qiov, buf, MIN(s->granularity, remaining));
9ae3a8
 
9ae3a8
         /* Advance the HBitmapIter in parallel, so that we do not examine
9ae3a8
          * the same sector twice.
9ae3a8
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
9ae3a8
index 912e499..b654081 100755
9ae3a8
--- a/tests/qemu-iotests/041
9ae3a8
+++ b/tests/qemu-iotests/041
9ae3a8
@@ -270,6 +270,11 @@ class TestSingleDriveZeroLength(TestSingleDrive):
9ae3a8
     test_small_buffer2 = None
9ae3a8
     test_large_cluster = None
9ae3a8
 
9ae3a8
+class TestSingleDriveUnalignedLength(TestSingleDrive):
9ae3a8
+    image_len = 1025 * 1024
9ae3a8
+    test_small_buffer2 = None
9ae3a8
+    test_large_cluster = None
9ae3a8
+
9ae3a8
 class TestMirrorNoBacking(ImageMirroringTestCase):
9ae3a8
     image_len = 2 * 1024 * 1024 # MB
9ae3a8
 
9ae3a8
diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
9ae3a8
index cfa5c0d..802ffaa 100644
9ae3a8
--- a/tests/qemu-iotests/041.out
9ae3a8
+++ b/tests/qemu-iotests/041.out
9ae3a8
@@ -1,5 +1,5 @@
9ae3a8
-...................................
9ae3a8
+...........................................
9ae3a8
 ----------------------------------------------------------------------
9ae3a8
-Ran 35 tests
9ae3a8
+Ran 43 tests
9ae3a8
 
9ae3a8
 OK
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8