From nobody Tue Apr 15 03:54:46 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589547257; cv=none; d=zohomail.com; s=zohoarc; b=gIzFBlz6LsuQAs6sIOTkZU7538sfZrbephjOBLgbzdc/9KvVzB15/94O8VL57DKOFecvFUCFkQ/9QiJSzW6FyQKxSEDxGv0btRddo3WTDKSaM/RcVtKT4MdUL5TW1AczPViw5GozukT6Gz038dk0lmx99moJrSFR/T4Q9mHN3H0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589547257; h=Content-Type: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; bh=gLP1vSf5gjXtk+qahPllKtJXXNWmS0u8AqefUbRbHVY=; b=L4Nkb787yvqCNQEeHSglA7z0JF8+Z2k5F2HaqSNUnDJ0IN4BCDpCz+oalyoxbPT1VgkvTNRlaZHPFg0fnKx4/inDCXES3QbftJTQMJb5PMrLHL9pOYGt/LPDfG14thNPES+o23WocdgQPZQY35rR1j3q8fwEuSbotY19UYF2Lv8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1589547257439822.2749952390332; Fri, 15 May 2020 05:54:17 -0700 (PDT) Received: from localhost ([::1]:43078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZZqy-0000YB-2H for importer@patchew.org; Fri, 15 May 2020 08:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZZip-0002Xc-Vx for qemu-devel@nongnu.org; Fri, 15 May 2020 08:45:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:53011 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZZim-00029J-FU for qemu-devel@nongnu.org; Fri, 15 May 2020 08:45:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-9SQ6hxL7N0qNk5AK1D8naA-1; Fri, 15 May 2020 08:45:43 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADD8019200C2; Fri, 15 May 2020 12:45:42 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-110.ams2.redhat.com [10.36.113.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2CBB2E16F; Fri, 15 May 2020 12:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589546747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gLP1vSf5gjXtk+qahPllKtJXXNWmS0u8AqefUbRbHVY=; b=HkiO9jDSzUeH7YK1eXexSbCGst6Qb+dl6k47YOoapblJGUj2GiB6tDRkvUPknk08KYmiEd 54K23/IwDMbiJKPr6mzGYPmjsafIQSd5zCsSvFfR4/E5B2sKFekaa2twFO6FqeQC5wU+c3 l7wIOeQxpS70kR2Sx7bHp/8H5ptD21w= X-MC-Unique: 9SQ6hxL7N0qNk5AK1D8naA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 10/51] block: Use blk_make_empty() after commits Date: Fri, 15 May 2020 14:44:40 +0200 Message-Id: <20200515124521.335403-11-kwolf@redhat.com> In-Reply-To: <20200515124521.335403-1-kwolf@redhat.com> References: <20200515124521.335403-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/14 22:56:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz bdrv_commit() already has a BlockBackend pointing to the BDS that we want to empty, it just has the wrong permissions. qemu-img commit has no BlockBackend pointing to the old backing file yet, but introducing one is simple. After this commit, bdrv_make_empty() is the only remaining caller of BlockDriver.bdrv_make_empty(). Signed-off-by: Max Reitz Message-Id: <20200429141126.85159-5-mreitz@redhat.com> Reviewed-by: Eric Blake [kwolf: Fixed up reference output for 098] Signed-off-by: Kevin Wolf --- block/commit.c | 16 +++++++++------- qemu-img.c | 19 ++++++++++++++----- tests/qemu-iotests/098.out | 8 ++++---- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/block/commit.c b/block/commit.c index 87f6096d90..ba60fb7955 100644 --- a/block/commit.c +++ b/block/commit.c @@ -414,7 +414,9 @@ int bdrv_commit(BlockDriverState *bs) } =20 ctx =3D bdrv_get_aio_context(bs); - src =3D blk_new(ctx, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); + /* WRITE_UNCHANGED is required for bdrv_make_empty() */ + src =3D blk_new(ctx, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED, + BLK_PERM_ALL); backing =3D blk_new(ctx, BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_AL= L); =20 ret =3D blk_insert_bs(src, bs, &local_err); @@ -492,14 +494,14 @@ int bdrv_commit(BlockDriverState *bs) } } =20 - if (drv->bdrv_make_empty) { - ret =3D drv->bdrv_make_empty(bs); - if (ret < 0) { - goto ro_cleanup; - } - blk_flush(src); + ret =3D blk_make_empty(src, NULL); + /* Ignore -ENOTSUP */ + if (ret < 0 && ret !=3D -ENOTSUP) { + goto ro_cleanup; } =20 + blk_flush(src); + /* * Make sure all data we wrote to the backing device is actually * stable on disk. diff --git a/qemu-img.c b/qemu-img.c index 6a4327aaba..f1795c788c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1104,11 +1104,20 @@ static int img_commit(int argc, char **argv) goto unref_backing; } =20 - if (!drop && bs->drv->bdrv_make_empty) { - ret =3D bs->drv->bdrv_make_empty(bs); - if (ret) { - error_setg_errno(&local_err, -ret, "Could not empty %s", - filename); + if (!drop) { + BlockBackend *old_backing_blk; + + old_backing_blk =3D blk_new_with_bs(bs, BLK_PERM_WRITE, BLK_PERM_A= LL, + &local_err); + if (!old_backing_blk) { + goto unref_backing; + } + ret =3D blk_make_empty(old_backing_blk, &local_err); + blk_unref(old_backing_blk); + if (ret =3D=3D -ENOTSUP) { + error_free(local_err); + local_err =3D NULL; + } else if (ret < 0) { goto unref_backing; } } diff --git a/tests/qemu-iotests/098.out b/tests/qemu-iotests/098.out index 7634d0e8b0..23cf371f53 100644 --- a/tests/qemu-iotests/098.out +++ b/tests/qemu-iotests/098.out @@ -6,7 +6,7 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D67= 108864 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error No errors were found on the image. =20 =3D=3D=3D empty_image_prepare =3D=3D=3D @@ -15,7 +15,7 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D= 67108864 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error Leaked cluster 4 refcount=3D1 reference=3D0 Leaked cluster 5 refcount=3D1 reference=3D0 Repairing cluster 4 refcount=3D1 reference=3D0 @@ -28,7 +28,7 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D= 67108864 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error ERROR cluster 0 refcount=3D0 reference=3D1 ERROR cluster 1 refcount=3D0 reference=3D1 ERROR cluster 3 refcount=3D0 reference=3D1 @@ -42,7 +42,7 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D= 67108864 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -qemu-img: Could not empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error +qemu-img: Failed to empty blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFM= T: Input/output error ERROR cluster 0 refcount=3D0 reference=3D1 ERROR cluster 1 refcount=3D0 reference=3D1 ERROR cluster 3 refcount=3D0 reference=3D1 --=20 2.25.4