From nobody Fri Nov 7 04:04:22 2025 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545534210047383.4180147590222; Sat, 22 Dec 2018 19:03:30 -0800 (PST) Received: from localhost ([::1]:55585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gau36-0005wH-Kz for importer@patchew.org; Sat, 22 Dec 2018 22:03:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gau0x-00050g-MV for qemu-devel@nongnu.org; Sat, 22 Dec 2018 22:01:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gau0w-0005kj-Km for qemu-devel@nongnu.org; Sat, 22 Dec 2018 22:01:15 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:46261) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gau0u-0005gU-K6; Sat, 22 Dec 2018 22:01:14 -0500 Received: by mail-pl1-x644.google.com with SMTP id t13so4235295ply.13; Sat, 22 Dec 2018 19:01:10 -0800 (PST) Received: from localhost.localdomain (114-136-27-106.emome-ip.hinet.net. [114.136.27.106]) by smtp.gmail.com with ESMTPSA id g190sm32610180pgc.28.2018.12.22.19.01.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Dec 2018 19:01:09 -0800 (PST) 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=MShGp47QRiQwWuK+yf1CJXsrfpB6HDhws8Iyenae/sE=; b=XPYYsGkqDyOj6a/onq5TSGLpYMDOOa9oVXI29V1d2e8ADZkLY/NFae2DNXikIR/fSc oTn33PfG7wOPaOfHKB8MaKVXiQxxRBVWIpxbL7Ehc3Q8amkZHIMZUljLAVKurWiSO9IB KvR8MMO/zwl4IefQ6dGZ/oOMoislqsEXuiBZjneGnAEap5+kFSJJgUShDxP4Mx1Z+g0T IAQkPSBDbC/t69pohNhGIbTbyNJ7yN2NKjXX8pnV5CBV2e/pO29xdul+jo4PgyrgmPXZ UzXM+4k6YZl99/RJKSeqENYlHT/h7BibpLCIwXUoqhfIOO8DZH4kn1/UTdgrW3Q7r9HP cWiw== 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=MShGp47QRiQwWuK+yf1CJXsrfpB6HDhws8Iyenae/sE=; b=IVmNrSauNaaZbCnMQxtwgiA9BYJu5AzoCprLBYns0yfJv+Wi4PQAQe1kpGqUJ76bRe WeJqh1R5dYlgkQ+QXhypJm/GHL8J4KiTRPHo/YyJ90+drRI90PleTh/d3/B+6BcEBX6U 0SbAYBvGy1i7chfBEu7zYkQgT+FdlCYWlxCXN3ZOyuZ6E+nnRQUExeOuLddVO3BQXT0a b+lYT2opdXcOfO+fPO8tNpe33LYpbN4S2gJPWr+ZkRB+NqjLh4KCmEeJ/isHMO3Sb0Wp k4BPimtehGDtd4U984/CDxUqIOslVNE6l4Grcp9QHAdtmmD4mDl9jgXTkLVlPfdBZ8hi pE8g== X-Gm-Message-State: AJcUukfN7rtwEQgfemY4t3F9vhX+iRIazqIEL68lWMapnJxjwI/XYnCU 40BWrJQnTHHhbGofQZ1S7DF6E4zVm0E= X-Google-Smtp-Source: ALg8bN7sOCMr/rXvmIt061/HLRGgMnKD0ZqKW/GjPZTBCz3L3Zo7udXpU8s0MSb20iaWOH+wjH9jFg== X-Received: by 2002:a17:902:aa8c:: with SMTP id d12mr8587783plr.25.1545534069828; Sat, 22 Dec 2018 19:01:09 -0800 (PST) From: yuchenlin To: qemu-devel@nongnu.org Date: Sun, 23 Dec 2018 10:59:39 +0800 Message-Id: <20181223025939.15775-4-npes87184@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181223025939.15775-1-npes87184@gmail.com> References: <20181223025939.15775-1-npes87184@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v2 3/3] dmg: don't skip zero chunk 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: yuchenlin , qemu-block@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The dmg file has many tables which describe: "start from sector XXX to sector XXX, the compression method is XXX and where the compressed data resides on". Each sector in the expanded file should be covered by a table. The table will describe the offset of compressed data (or raw depends on the type) in the dmg. For example: [-----------The expanded file------------] [---bzip table ---]/* zeros */[---zlib---] ^ | if we want to read this sector. we will find bzip table which contains this sector, and get the compressed data offset, read it from dmg, uncompress it, finally write to expanded file. If we skip zero chunk (table), some sector cannot find the table which will cause search_chunk() return s->n_chunks, dmg_read_chunk() return -1 and finally causing dmg_co_preadv() return EIO. See: [-----------The expanded file------------] [---bzip table ---]/* zeros */[---zlib---] ^ | if we want to read this sector. Oops, we cannot find the table contains it... In the original implementation, we don't have zero table. When we try to read sector inside the zero chunk. We will get EIO, and skip reading. After this patch, we treat zero chunk the same as ignore chunk, it will directly write zero and avoid some sector may not find the table. After this patch: [-----------The expanded file------------] [---bzip table ---][--zeros--][---zlib---] Signed-off-by: yuchenlin Reviewed-by: Julio Faracco Reviewed-by: Stefan Hajnoczi --- block/dmg.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index 6b0a057bf8..137fe9c1ff 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -130,7 +130,8 @@ static void update_max_chunk_size(BDRVDMGState *s, uint= 32_t chunk, case UDRW: /* copy */ uncompressed_sectors =3D DIV_ROUND_UP(s->lengths[chunk], 512); break; - case UDIG: /* zero */ + case UDZE: /* zero */ + case UDIG: /* ignore */ /* as the all-zeroes block may be large, it is treated specially: = the * sector is not copied from a large buffer, a simple memset is us= ed * instead. Therefore uncompressed_sectors does not need to be set= . */ @@ -199,8 +200,9 @@ typedef struct DmgHeaderState { static bool dmg_is_known_block_type(uint32_t entry_type) { switch (entry_type) { + case UDZE: /* zeros */ case UDRW: /* uncompressed */ - case UDIG: /* zeroes */ + case UDIG: /* ignore */ case UDZO: /* zlib */ return true; case UDBZ: /* bzip2 */ @@ -265,9 +267,10 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHea= derState *ds, /* sector count */ s->sectorcounts[i] =3D buff_read_uint64(buffer, offset + 0x10); =20 - /* all-zeroes sector (type 2) does not need to be "uncompressed" a= nd can - * therefore be unbounded. */ - if (s->types[i] !=3D UDIG && s->sectorcounts[i] > DMG_SECTORCOUNTS= _MAX) { + /* all-zeroes sector (type UDZE and UDIG) does not need to be + * "uncompressed" and can therefore be unbounded. */ + if (s->types[i] !=3D UDZE && s->types[i] !=3D UDIG + && s->sectorcounts[i] > DMG_SECTORCOUNTS_MAX) { error_report("sector count %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX); @@ -671,7 +674,8 @@ static inline int dmg_read_chunk(BlockDriverState *bs, = uint64_t sector_num) return -1; } break; - case UDIG: /* zero */ + case UDZE: /* zeros */ + case UDIG: /* ignore */ /* see dmg_read, it is treated specially. No buffer needs to be * pre-filled, the zeroes can be set directly. */ break; @@ -706,7 +710,8 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, ui= nt64_t bytes, /* Special case: current chunk is all zeroes. Do not perform a mem= cpy as * s->uncompressed_chunk may be too small to cover the large all-z= eroes * section. dmg_read_chunk is called to find s->current_chunk */ - if (s->types[s->current_chunk] =3D=3D UDIG) { /* all zeroes block = entry */ + if (s->types[s->current_chunk] =3D=3D UDZE + || s->types[s->current_chunk] =3D=3D UDIG) { /* all zeroes blo= ck entry */ qemu_iovec_memset(qiov, i * 512, 0, 512); continue; } --=20 2.17.1