diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2014-03-26 13:05:56 +0100 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2014-07-03 16:18:13 -0500 |
commit | 4ee5b9c8cbe05d1865924dce226b4c3aedc4dae6 (patch) | |
tree | 0e29cdccd81dc68a0d2fcc10983eddb892554b66 /block | |
parent | ad08cae75c444366ad7a5222c6b7867f31a338f7 (diff) | |
download | qemu-4ee5b9c8cbe05d1865924dce226b4c3aedc4dae6.tar.gz |
dmg: drop broken bdrv_pread() loop
It is not necessary to check errno for EINTR and the block layer does
not produce short reads. Therefore we can drop the loop that attempts
to read a compressed chunk.
The loop is buggy because it incorrectly adds the transferred bytes
twice:
do {
ret = bdrv_pread(...);
i += ret;
} while (ret >= 0 && ret + i < s->lengths[chunk]);
Luckily we can drop the loop completely and perform a single
bdrv_pread().
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit b404bf854217dbe8a5649449eb3ad33777f7d900)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/dmg.c | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/block/dmg.c b/block/dmg.c index f4f3e8e9f2..1cc5426d8c 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -298,21 +298,10 @@ static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num) s->current_chunk = s->n_chunks; switch (s->types[chunk]) { case 0x80000005: { /* zlib compressed */ - int i; - /* we need to buffer, because only the chunk as whole can be * inflated. */ - i = 0; - do { - ret = bdrv_pread(bs->file, s->offsets[chunk] + i, - s->compressed_chunk + i, - s->lengths[chunk] - i); - if (ret < 0 && errno == EINTR) { - ret = 0; - } - i += ret; - } while (ret >= 0 && ret + i < s->lengths[chunk]); - + ret = bdrv_pread(bs->file, s->offsets[chunk], + s->compressed_chunk, s->lengths[chunk]); if (ret != s->lengths[chunk]) { return -1; } |