From nobody Mon Feb 9 02:47:01 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.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153682750303879.62174578736028; Thu, 13 Sep 2018 01:31:43 -0700 (PDT) Received: from localhost ([::1]:41098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0N2G-0007wf-P2 for importer@patchew.org; Thu, 13 Sep 2018 04:31:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0N0u-0007Fg-6l for qemu-devel@nongnu.org; Thu, 13 Sep 2018 04:30:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0N0t-00082D-C7 for qemu-devel@nongnu.org; Thu, 13 Sep 2018 04:30:12 -0400 Received: from synology.com ([59.124.61.242]:44905) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0N0m-0007hI-SM; Thu, 13 Sep 2018 04:30:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1536827399; bh=YdLEJWys6PWY+nd3i16/825eMuI2U1SRL3r4DlwdgVs=; h=From:To:Cc:Subject:Date; b=swW+QQq4XvtWM+Jm53QpnFrm/YlDiROAQVv/PDIwxUI+5nGuTombqA1uSuw2lAQMm CHM2iLgsnzpJW6n8cxC+lkMeeMkUqr0zUKDFLHqA/GtFK/Z5tgXMRrN+WAtBdcn7wk 4iB42Yrf7APfNjjllh8RzGrfllZfaFoWA61E0/S4= To: qemu-devel@nongnu.org Date: Thu, 13 Sep 2018 16:29:52 +0800 Message-Id: <20180913082952.3675-1-yuchenlin@synology.com> X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 59.124.61.242 Subject: [Qemu-devel] [PATCH v3] vmdk: align end of file to a sector boundary 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: , From: yuchenlin--- via Qemu-devel Reply-To: yuchenlin@synology.com Cc: yuchenlin , famz@redhat.com, qemu-block@nongnu.org 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" From: yuchenlin There is a rare case which the size of last compressed cluster is larger than the cluster size, which will cause the file is not aligned at the sector boundary. There are three reasons to do it. First, if vmdk doesn't align at the sector boundary, there may be many undefined behaviors, such as, in vbox it will show VMDK: Compressed image is corrupted 'syno-vm-disk1.vmdk' (VERR_ZIP_CORRUPTED) when we try to import an ova with unaligned vmdk. Second, all the cluster_sector is aligned to sector, the last one should be like this, too. Third, it ease reading with sector based I/Os. Signed-off-by: yuchenlin Reviewed-by: Fam Zheng --- v2 -> v3: * Update commit message thanks block/vmdk.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/block/vmdk.c b/block/vmdk.c index a9d0084e36..2c9e86d98f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1698,6 +1698,27 @@ static int coroutine_fn vmdk_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov) { + if (bytes =3D=3D 0) { + /* The caller will write bytes 0 to signal EOF. + * When receive it, we align EOF to a sector boundary. */ + BDRVVmdkState *s =3D bs->opaque; + int i, ret; + int64_t length; + + for (i =3D 0; i < s->num_extents; i++) { + length =3D bdrv_getlength(s->extents[i].file->bs); + if (length < 0) { + return length; + } + length =3D QEMU_ALIGN_UP(length, BDRV_SECTOR_SIZE); + ret =3D bdrv_truncate(s->extents[i].file, length, + PREALLOC_MODE_OFF, NULL); + if (ret < 0) { + return ret; + } + } + return 0; + } return vmdk_co_pwritev(bs, offset, bytes, qiov, 0); } =20 --=20 2.18.0