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