From nobody Sun Feb 8 20:52:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493280474182758.5806871641846; Thu, 27 Apr 2017 01:07:54 -0700 (PDT) Received: from localhost ([::1]:59292 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3eSu-0004mc-Mj for importer@patchew.org; Thu, 27 Apr 2017 04:07:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3eRT-0003Oa-8W for qemu-devel@nongnu.org; Thu, 27 Apr 2017 04:06:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3eRS-0008On-6t for qemu-devel@nongnu.org; Thu, 27 Apr 2017 04:06:23 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:35614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d3eRS-0008Nt-0G; Thu, 27 Apr 2017 04:06:22 -0400 Received: by mail-pf0-x241.google.com with SMTP id a188so7473429pfa.2; Thu, 27 Apr 2017 01:06:21 -0700 (PDT) Received: from linux.local ([157.51.104.251]) by smtp.gmail.com with ESMTPSA id 12sm3295277pgb.35.2017.04.27.01.06.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Apr 2017 01:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VpBxeQqhMPqGtrAXYs1LE5RxBfl20UsTTF4j9evfuAY=; b=fXrcF6WDjlv3fCktR0mJNH/r5YstBjsTqU2a5udDHw1fIHBcS3RwPtyQD5ONKlZW8S ak/5Rh40veUXqf6mXk5z2PrSsxNVBF3ILwcNOIE6P2zmm9rAQ2ALONesftToAIGny1cT pp0cXDEqv2nNhpVzBQu6yL2AlOwYuenUEWFvZKx3HCbju7JlxsliH7zhJ5YyImQOOpUw 8sMGHrhB0m9Ss2fhTCXIHMyt1aY09CGvkpkMAiKeK9MZDe2ZyGxm8ioeq8AL/zYKg0y+ K67x7JnpWK/1RV3PuVbtDAjQ9/y4beH6i8BY7qSqbwbo04Nwh9if9zriscVU+GgQV6u+ u1gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VpBxeQqhMPqGtrAXYs1LE5RxBfl20UsTTF4j9evfuAY=; b=V9eudIaULp6JYNsyDC+89YJbZ82KbBtVD3N04Qwz2FgFnf0Qr/rsnxwAgPGvrgwti9 RhbWFAWe4fSjryLiCnDNzpQiJo+SPvtw6J0AqHwhqrShwtsuefZW5eVqmQDcVjkU3U4k /WpRUGgrulRHR1hPYXrDjpj2yCLFTVmADDPwYfjgMh9JPn3P0EJ0w+Vt6ar5he/HNGDw XHViS2UwmxB83HfUQKHmuIqCuLgsWk2yyMdy7UfoY9w79OeIz7La0KzKPxxaeCxsW4Zl Rc7Kce3MR/K1yOeAhpFchY4AGRe1ky4UdUjK80Ziz4gfHlitT/cKsgyFi720qbHDoT22 CTJg== X-Gm-Message-State: AN3rC/5+EEuqbTr8hGGfK/go7S6QLtB3YrjqNwWPbVAB5R6IGa+8/zFl Q+wv+vZs/lU38g== X-Received: by 10.99.125.18 with SMTP id y18mr4444850pgc.32.1493280381107; Thu, 27 Apr 2017 01:06:21 -0700 (PDT) From: Ashijeet Acharya To: stefanha@gmail.com Date: Thu, 27 Apr 2017 13:36:34 +0530 Message-Id: <1493280397-9622-5-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1493280397-9622-1-git-send-email-ashijeetacharya@gmail.com> References: <1493280397-9622-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH v2 4/7] dmg: Handle zlib compressed chunks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com, peter@lekensteyn.nl, Ashijeet Acharya , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Set the output buffer size to be equal to the size of number of sectors stored in @sectors_read. Start inflating to a max output buffer size of 2MB and cache our access point to aid random access later if required. Signed-off-by: Ashijeet Acharya --- block/dmg.c | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index 32623e2..073e864 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -621,27 +621,47 @@ static inline int dmg_read_chunk(BlockDriverState *bs= , uint64_t sector_num, =20 switch (s->types[chunk]) { /* block entry type */ case 0x80000005: { /* zlib compressed */ - /* we need to buffer, because only the chunk as whole can be - * inflated. */ - ret =3D bdrv_pread(bs->file, s->offsets[chunk], - s->compressed_chunk, s->lengths[chunk]); - if (ret !=3D s->lengths[chunk]) { - return -1; + /* check for cached random access point */ + if (drs->saved_next_in =3D=3D NULL) { + /* we need to buffer, because only the chunk as whole can be + * inflated. */ + ret =3D bdrv_pread(bs->file, s->offsets[chunk], + s->compressed_chunk, s->lengths[chunk]); + if (ret !=3D s->lengths[chunk]) { + return -1; + } + + s->zstream.next_in =3D s->compressed_chunk; + s->zstream.avail_in =3D s->lengths[chunk]; + } else { + s->zstream.next_in =3D drs->saved_next_in; + s->zstream.avail_in =3D drs->saved_avail_in; } =20 - s->zstream.next_in =3D s->compressed_chunk; - s->zstream.avail_in =3D s->lengths[chunk]; s->zstream.next_out =3D s->uncompressed_chunk; - s->zstream.avail_out =3D 512 * s->sectorcounts[chunk]; - ret =3D inflateReset(&s->zstream); - if (ret !=3D Z_OK) { - return -1; + + s->zstream.avail_out =3D sectors_read * BDRV_SECTOR_SIZE; + + if (drs->saved_next_in =3D=3D NULL) { + ret =3D inflateReset(&s->zstream); + if (ret !=3D Z_OK) { + return -1; + } + } + /* reset total_out for each successive call */ + s->zstream.total_out =3D 0; + ret =3D inflate(&s->zstream, Z_SYNC_FLUSH); + if (ret =3D=3D Z_OK && + s->zstream.total_out =3D=3D 512 * sectors_read) { + goto update; } - ret =3D inflate(&s->zstream, Z_FINISH); if (ret !=3D Z_STREAM_END || - s->zstream.total_out !=3D 512 * s->sectorcounts[chunk]) { + s->zstream.total_out !=3D 512 * sectors_read) { return -1; } +update: + cache_access_point(drs, s->zstream.next_in, s->zstream.avail_in, + chunk, sectors_read, sector_offset); break; } case 0x80000006: /* bzip2 compressed */ if (!dmg_uncompress_bz2) { --=20 2.6.2