From nobody Wed Nov 5 14:59:51 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535426378193782.0112126140555; Mon, 27 Aug 2018 20:19:38 -0700 (PDT) Received: from localhost ([::1]:36023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuUXP-0002fG-QV for importer@patchew.org; Mon, 27 Aug 2018 23:19:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuUWS-0002Lg-Gv for qemu-devel@nongnu.org; Mon, 27 Aug 2018 23:18:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuUWR-0005lz-B2 for qemu-devel@nongnu.org; Mon, 27 Aug 2018 23:18:28 -0400 Received: from synology.com ([59.124.61.242]:52063) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fuUWM-0005hW-P1; Mon, 27 Aug 2018 23:18:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1535426290; bh=3IbTMVSWNZjsuUgkhwDf38Y2ruIzUGZ8ythNGTUZ9PE=; h=From:To:Cc:Subject:Date; b=PMp+TPkYfoP5JLWUG7YiICnZmkjs+LQ4ttCNRrE475hIFb0UnJGX5UvTZ/Gn4sydT dh41WjvinKd4SrsVWpr14xAY05pqvJTBGDaKrKYm2LeCfleN7riZlRXlq3N4jBkguS /SVzSs5Fqq9PWwFs3quW4Q0+1qjW/7Q1sEWEEZdI= To: qemu-devel@nongnu.org Date: Tue, 28 Aug 2018 11:17:51 +0800 Message-Id: <20180828031751.29507-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] 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. Signed-off-by: yuchenlin --- block/vmdk.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/vmdk.c b/block/vmdk.c index a9d0084e36..a8ae7c65d2 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1698,6 +1698,24 @@ static int coroutine_fn vmdk_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov) { + if (bytes =3D=3D 0) { + /* align end of file 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; + } + ret =3D bdrv_truncate(s->extents[i].file, length, PREALLOC_MOD= E_OFF, NULL); + if (ret < 0) { + return ret; + } + } + return 0; + } return vmdk_co_pwritev(bs, offset, bytes, qiov, 0); } =20 --=20 2.17.0