Received: from eggs.gnu.org ([2001:4830:134:3::10]:41480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4Z6j-0004ja-MG for qemu-devel@nongnu.org; Tue, 08 Jul 2014 13:24:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4Z6A-0000lw-AM for qemu-devel@nongnu.org; Tue, 08 Jul 2014 13:23:09 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:49938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4Z69-0000jF-Ud for qemu-devel@nongnu.org; Tue, 08 Jul 2014 13:22:34 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 8 Jul 2014 13:22:33 -0400 From: Michael Roth Date: Tue, 8 Jul 2014 12:18:15 -0500 Message-Id: <1404839947-1086-105-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1404839947-1086-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1404839947-1086-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 104/156] dmg: drop broken bdrv_pread() loop List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org From: Stefan Hajnoczi 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 Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Signed-off-by: Stefan Hajnoczi (cherry picked from commit b404bf854217dbe8a5649449eb3ad33777f7d900) Signed-off-by: Michael Roth --- block/dmg.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index f4f3e8e..1cc5426 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; } -- 1.9.1