From nobody Wed Nov 12 07:09:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568801030; cv=none; d=zoho.com; s=zohoarc; b=l0JHOXIeFJA+lOpOlmcEE+rCMmRi2BgrL35+4utjsMLv5mOEN3FZZP0Lf2PYigejsm4STvfrv7ieatj2VD3kjBCTjt4mhtStk+tkHeFwMm6EbST64HXPOXAelUQoatmFIRFvbL3Gpf8QpW2FxnzPZaMP3IPlD3o6Cq90YZpkwao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568801030; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=wbrLCQhTIFPkm2Dars0mVp/B/DM6RexfBrXYldtmaM4=; b=msccPjbaROssjKE8LGbXfxCgSKLCWnR4+Tlp61SuctNKIEtXE8qyd2TfLwDkLWtJ7ZuL4+JnwPY1iq40iPJf1llbOZnQpNVI8WalZsVWGb2LDN7f5NUy1/ZkDmtUCe4YKJzN7MsptKpv6lamgMNsOe4Yd612y/P7jkPRYJz2dbI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568801030648463.3554374900118; Wed, 18 Sep 2019 03:03:50 -0700 (PDT) Received: from localhost ([::1]:56840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAWoM-0002xQ-P8 for importer@patchew.org; Wed, 18 Sep 2019 06:03:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59397) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAWdM-0001PQ-KI for qemu-devel@nongnu.org; Wed, 18 Sep 2019 05:52:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAWdL-0005tH-7m for qemu-devel@nongnu.org; Wed, 18 Sep 2019 05:52:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAWdI-0005nU-El; Wed, 18 Sep 2019 05:52:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4C82A3D394; Wed, 18 Sep 2019 09:52:19 +0000 (UTC) Received: from localhost (ovpn-116-168.ams2.redhat.com [10.36.116.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 430835C219; Wed, 18 Sep 2019 09:52:19 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 18 Sep 2019 11:51:43 +0200 Message-Id: <20190918095144.955-8-mreitz@redhat.com> In-Reply-To: <20190918095144.955-1-mreitz@redhat.com> References: <20190918095144.955-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Wed, 18 Sep 2019 09:52:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 7/8] block: Pass truncate exact=true where reasonable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Maxim Levitsky , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is a change in behavior, so all instances need a good justification. The comments added here should explain my reasoning. qed already had a comment that suggests it always expected bdrv_truncate()/blk_truncate() to behave as if exact=3Dtrue were passed (c743849bee7 came eight months before 55b949c8476), so it was simply broken until now. Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block/parallels.c | 11 +++++++++-- block/qcow2.c | 6 +++++- block/qed.c | 2 +- qemu-img.c | 7 ++++++- qemu-io-cmds.c | 7 ++++++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index a1a92c97a4..603211f83c 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -487,7 +487,12 @@ static int coroutine_fn parallels_co_check(BlockDriver= State *bs, res->leaks +=3D count; if (fix & BDRV_FIX_LEAKS) { Error *local_err =3D NULL; - ret =3D bdrv_truncate(bs->file, res->image_end_offset, false, + + /* + * In order to really repair the image, we must shrink it. + * That means we have to pass exact=3Dtrue. + */ + ret =3D bdrv_truncate(bs->file, res->image_end_offset, true, PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); @@ -880,7 +885,9 @@ static void parallels_close(BlockDriverState *bs) if ((bs->open_flags & BDRV_O_RDWR) && !(bs->open_flags & BDRV_O_INACTI= VE)) { s->header->inuse =3D 0; parallels_update_header(bs); - bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, false, + + /* errors are ignored, so we might as well pass exact=3Dtrue */ + bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, true, PREALLOC_MODE_OFF, NULL); } =20 diff --git a/block/qcow2.c b/block/qcow2.c index 4ef19dd29a..eba165de7f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5057,7 +5057,11 @@ static int qcow2_amend_options(BlockDriverState *bs,= QemuOpts *opts, return ret; } =20 - ret =3D blk_truncate(blk, new_size, false, PREALLOC_MODE_OFF, errp= ); + /* + * Amending image options should ensure that the image has + * exactly the given new values, so pass exact=3Dtrue here. + */ + ret =3D blk_truncate(blk, new_size, true, PREALLOC_MODE_OFF, errp); blk_unref(blk); if (ret < 0) { return ret; diff --git a/block/qed.c b/block/qed.c index 7c2a65af40..8005cfc305 100644 --- a/block/qed.c +++ b/block/qed.c @@ -674,7 +674,7 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCrea= teOptions *opts, l1_size =3D header.cluster_size * header.table_size; =20 /* File must start empty and grow, check truncate is supported */ - ret =3D blk_truncate(blk, 0, false, PREALLOC_MODE_OFF, errp); + ret =3D blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, errp); if (ret < 0) { goto out; } diff --git a/qemu-img.c b/qemu-img.c index f8694f4f72..a3169b6113 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3823,7 +3823,12 @@ static int img_resize(int argc, char **argv) } } =20 - ret =3D blk_truncate(blk, total_size, false, prealloc, &err); + /* + * The user expects the image to have the desired size after + * resizing, so pass @exact=3Dtrue. It is of no use to report + * success when the image has not actually been resized. + */ + ret =3D blk_truncate(blk, total_size, true, prealloc, &err); if (ret < 0) { error_report_err(err); goto out; diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 5e9017c979..1b7e700020 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1710,7 +1710,12 @@ static int truncate_f(BlockBackend *blk, int argc, c= har **argv) return offset; } =20 - ret =3D blk_truncate(blk, offset, false, PREALLOC_MODE_OFF, &local_err= ); + /* + * qemu-io is a debugging tool, so let us be strict here and pass + * exact=3Dtrue. It is better to err on the "emit more errors" side + * than to be overly permissive. + */ + ret =3D blk_truncate(blk, offset, true, PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); return ret; --=20 2.21.0