From nobody Mon Feb 9 12:26:34 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 1493150620073449.20887086626067; Tue, 25 Apr 2017 13:03:40 -0700 (PDT) Received: from localhost ([::1]:51202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d36gU-0001ri-PA for importer@patchew.org; Tue, 25 Apr 2017 16:03:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d36cM-000760-4Y for qemu-devel@nongnu.org; Tue, 25 Apr 2017 15:59:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d36cK-00042Y-5C for qemu-devel@nongnu.org; Tue, 25 Apr 2017 15:59:22 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:33564) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d36cJ-00042Q-Vf; Tue, 25 Apr 2017 15:59:20 -0400 Received: by mail-pg0-x242.google.com with SMTP id 63so13417586pgh.0; Tue, 25 Apr 2017 12:59:19 -0700 (PDT) Received: from linux.local ([157.51.23.94]) by smtp.gmail.com with ESMTPSA id y187sm37931530pfy.67.2017.04.25.12.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Apr 2017 12:59:18 -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=bqGQX1E5k8JUNKPIqlPZOjNOiilxec2eu4nbVmEO90U=; b=MBcgwWCDylCk6/tUTVaOq4RSW9qd+X/Avm0d+VL8fmEIev25Oi2vsJO54AKXcTKoII mHLjc2phzNGNodUZeHZQoAGobDLoEYIteoUc0aITTvQ4YBtlskmu89aeez32Cr2WPogb iD5grQa5iytoYSJQuF+eyG4PTrwjbtHPQMsigiNkN0opJslQVrAliuJdwEh45DsfEzO8 oOb3i0Hr4n3hC5K67R3UyoAokW57W56Y097rVGp3GjZf6Pczprdr8Kg8u71I8dIghlNB R9keTpuCCyTK0LwjP7pY7gjsD1er0a2oaYgMYJ9hsvtn4qdragfks0aKqXG3fhiv7Iu7 4bzw== 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=bqGQX1E5k8JUNKPIqlPZOjNOiilxec2eu4nbVmEO90U=; b=lb62NuMbpm7FdmbPM/e63MwZdwrvsSZ0AXw9GTX0stAk0CZlIdJS1DZQ4GH1PL2FO/ AdL0AoRXNQxtBDnJu7uUKkfemMJylaV755LHudr4wYl+A3/KhGpwkcohYCd6oYzQF4f3 M4K1kyd06bEhNOU8n/CZuAObgE+IN/kGLL0+Nhj4hGg9oBMzxmEQO7T9mBwJyAQXClK/ jrpIkI47BIb/GL85A5BLaXvZdIqxOhs4RutHWQdM0Mn7wW5W2vvttwe4yiei1uG25O51 TXVYFfgbCVUPiD4AEMknruKI4Cofhf+rI7wPzR7npfztzQV7AvztpcfW8S67/OP7oyn6 nQiw== X-Gm-Message-State: AN3rC/4QaZ/DdaMNWnepktN7BoehyrdhrteLLWB1M8W9YekLevyMyyfQ 9kd4eKhh0a2gwQ== X-Received: by 10.98.150.78 with SMTP id c75mr27991240pfe.206.1493150358954; Tue, 25 Apr 2017 12:59:18 -0700 (PDT) From: Ashijeet Acharya To: stefanha@gmail.com Date: Wed, 26 Apr 2017 01:29:08 +0530 Message-Id: <1493150351-28918-6-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1493150351-28918-1-git-send-email-ashijeetacharya@gmail.com> References: <1493150351-28918-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v1 5/8] 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 dc356b0..749c151 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