9ae3a8
From 35538bdb46122fdf90ca869df29869b8aeaefa09 Mon Sep 17 00:00:00 2001
9ae3a8
From: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
Date: Tue, 25 Mar 2014 14:23:42 +0100
9ae3a8
Subject: [PATCH 35/49] dmg: drop broken bdrv_pread() loop
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1395753835-7591-36-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: n/a
9ae3a8
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 35/48] dmg: drop broken bdrv_pread() loop
9ae3a8
Bugzilla: 1066691
9ae3a8
RH-Acked-by: Jeff Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
From: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1066691
9ae3a8
Upstream status: Series embargoed
9ae3a8
9ae3a8
It is not necessary to check errno for EINTR and the block layer does
9ae3a8
not produce short reads. Therefore we can drop the loop that attempts
9ae3a8
to read a compressed chunk.
9ae3a8
9ae3a8
The loop is buggy because it incorrectly adds the transferred bytes
9ae3a8
twice:
9ae3a8
9ae3a8
do {
9ae3a8
ret = bdrv_pread(...);
9ae3a8
i += ret;
9ae3a8
} while (ret >= 0 && ret + i < s->lengths[chunk]);
9ae3a8
9ae3a8
Luckily we can drop the loop completely and perform a single
9ae3a8
bdrv_pread().
9ae3a8
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block/dmg.c |   15 ++-------------
9ae3a8
 1 files changed, 2 insertions(+), 13 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/dmg.c b/block/dmg.c
9ae3a8
index f4f3e8e..1cc5426 100644
9ae3a8
--- a/block/dmg.c
9ae3a8
+++ b/block/dmg.c
9ae3a8
@@ -298,21 +298,10 @@ static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num)
9ae3a8
         s->current_chunk = s->n_chunks;
9ae3a8
         switch (s->types[chunk]) {
9ae3a8
         case 0x80000005: { /* zlib compressed */
9ae3a8
-            int i;
9ae3a8
-
9ae3a8
             /* we need to buffer, because only the chunk as whole can be
9ae3a8
              * inflated. */
9ae3a8
-            i = 0;
9ae3a8
-            do {
9ae3a8
-                ret = bdrv_pread(bs->file, s->offsets[chunk] + i,
9ae3a8
-                                 s->compressed_chunk + i,
9ae3a8
-                                 s->lengths[chunk] - i);
9ae3a8
-                if (ret < 0 && errno == EINTR) {
9ae3a8
-                    ret = 0;
9ae3a8
-                }
9ae3a8
-                i += ret;
9ae3a8
-            } while (ret >= 0 && ret + i < s->lengths[chunk]);
9ae3a8
-
9ae3a8
+            ret = bdrv_pread(bs->file, s->offsets[chunk],
9ae3a8
+                             s->compressed_chunk, s->lengths[chunk]);
9ae3a8
             if (ret != s->lengths[chunk]) {
9ae3a8
                 return -1;
9ae3a8
             }
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8