From nobody Wed Nov 5 18:24:24 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536805985020615.4914163517632; Wed, 12 Sep 2018 19:33:05 -0700 (PDT) Received: from localhost ([::1]:39437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0HRH-0008Lr-FF for importer@patchew.org; Wed, 12 Sep 2018 22:33:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0HQG-0007vf-JU for qemu-devel@nongnu.org; Wed, 12 Sep 2018 22:32:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0HQG-0005eX-02 for qemu-devel@nongnu.org; Wed, 12 Sep 2018 22:32:00 -0400 Received: from synology.com ([59.124.61.242]:52662) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0HQA-0005UI-NN; Wed, 12 Sep 2018 22:31:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1536805909; bh=Ihn/8pplUjLf9T0Mzt/ZYdQrlN90/gfoX42gt64emlc=; h=From:To:Cc:Subject:Date; b=OZL+Fib4TjNZ4Mp007T2jmrU7Jq0dCrY1JelGLZcFgXUldnW3GvXyZD/0fsHmRbqU H6dUSmjEUA+YwREBCqt3w77NNdQeZG+R2+ov3ZfX2ApJg87QlUphiYVK1GR3GzExBg OOqcDz9Y7ldHGlRtis1g8ki3u/os+7m688iGYyvs= To: qemu-devel@nongnu.org Date: Thu, 13 Sep 2018 10:31:34 +0800 Message-Id: <20180913023134.3853-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 v2] 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 --- v1 -> v2: * Add more detail comment. * Add QEMU_ALIGN_UP to show the intention more clearly. * Add newline in the end of bdrv_truncate. 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