a3fa63d
From: Stefan Hajnoczi <stefanha@redhat.com>
a3fa63d
Date: Wed, 1 Jul 2015 15:45:50 +0100
a3fa63d
Subject: [PATCH] block/mirror: limit qiov to IOV_MAX elements
a3fa63d
a3fa63d
If mirror has more free buffers than IOV_MAX, preadv(2)/pwritev(2)
a3fa63d
EINVAL failures may be encountered.
a3fa63d
a3fa63d
It is possible to trigger this by setting granularity to a low value
a3fa63d
like 8192.
a3fa63d
a3fa63d
This patch stops appending chunks once IOV_MAX is reached.
a3fa63d
a3fa63d
The spurious EINVAL failure can be reproduced with a qcow2 image file
a3fa63d
and the following QMP invocation:
a3fa63d
a3fa63d
  qmp.command('drive-mirror', device='virtio0', target='/tmp/r7.s1',
a3fa63d
              granularity=8192, sync='full', mode='absolute-paths',
a3fa63d
              format='raw')
a3fa63d
a3fa63d
While the guest is running dd if=/dev/zero of=/var/tmp/foo oflag=direct
a3fa63d
bs=4k.
a3fa63d
a3fa63d
Cc: Jeff Cody <jcody@redhat.com>
a3fa63d
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
a3fa63d
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
a3fa63d
Message-id: 1435761950-26714-1-git-send-email-stefanha@redhat.com
a3fa63d
Signed-off-by: Jeff Cody <jcody@redhat.com>
a3fa63d
(cherry picked from commit cae98cb87d269c33d23b2bccd79bb8d99a60d811)
a3fa63d
---
a3fa63d
 block/mirror.c | 4 ++++
a3fa63d
 trace-events   | 1 +
a3fa63d
 2 files changed, 5 insertions(+)
a3fa63d
a3fa63d
diff --git a/block/mirror.c b/block/mirror.c
a3fa63d
index bd079a4..9407287 100644
a3fa63d
--- a/block/mirror.c
a3fa63d
+++ b/block/mirror.c
a3fa63d
@@ -248,6 +248,10 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
a3fa63d
             trace_mirror_break_buf_busy(s, nb_chunks, s->in_flight);
a3fa63d
             break;
a3fa63d
         }
a3fa63d
+        if (IOV_MAX < nb_chunks + added_chunks) {
a3fa63d
+            trace_mirror_break_iov_max(s, nb_chunks, added_chunks);
a3fa63d
+            break;
a3fa63d
+        }
a3fa63d
 
a3fa63d
         /* We have enough free space to copy these sectors.  */
a3fa63d
         bitmap_set(s->in_flight_bitmap, next_chunk, added_chunks);
a3fa63d
diff --git a/trace-events b/trace-events
a3fa63d
index 30eba92..6f992c4 100644
a3fa63d
--- a/trace-events
a3fa63d
+++ b/trace-events
a3fa63d
@@ -94,6 +94,7 @@ mirror_yield(void *s, int64_t cnt, int buf_free_count, int in_flight) "s %p dirt
a3fa63d
 mirror_yield_in_flight(void *s, int64_t sector_num, int in_flight) "s %p sector_num %"PRId64" in_flight %d"
a3fa63d
 mirror_yield_buf_busy(void *s, int nb_chunks, int in_flight) "s %p requested chunks %d in_flight %d"
a3fa63d
 mirror_break_buf_busy(void *s, int nb_chunks, int in_flight) "s %p requested chunks %d in_flight %d"
a3fa63d
+mirror_break_iov_max(void *s, int nb_chunks, int added_chunks) "s %p requested chunks %d added_chunks %d"
a3fa63d
 
a3fa63d
 # block/backup.c
a3fa63d
 backup_do_cow_enter(void *job, int64_t start, int64_t sector_num, int nb_sectors) "job %p start %"PRId64" sector_num %"PRId64" nb_sectors %d"