From nobody Sun May 19 00:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588080471; cv=none; d=zohomail.com; s=zohoarc; b=ctFAtr/Pan248bAZ7DkaC84CN/m/4fz6nHx2i64LgRjUL/R5jWrJ5uz8TU8aOMkB4R4XmWNMmiP8i0eZ47EpqAgBkIYYbegSv2IVw4vd+3lSaMlG0fDtpciv3RQg46h4I/b7FBgPJYlrO0CbYcIc9wwSy+T12khwNPYtUOIvmeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588080471; 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=3OWL5LjDCx7y5IeGJUkDregA90v3xX3dRAsB1yU3tXA=; b=RaEUmFxEvTynD36Bz10O3VlJCcd4owB9DznKPLZ4SGLOvv2OOz68B5Vi4+M22JbjDGF0VIHzkGCvFQ/9+xIjXhsHA+j98i7WWT6b90uBTrTQDnKbx0XBOE/wTLoKOuAFsbc/psnlbkZ5Gq6EFEfc97Z88VSbIffQqKd9X/xh+YY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1588080471554562.2072637512139; Tue, 28 Apr 2020 06:27:51 -0700 (PDT) Received: from localhost ([::1]:57574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQH7-0005GQ-V1 for importer@patchew.org; Tue, 28 Apr 2020 09:27:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35160) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQFz-0003A6-BF for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTQFy-0001n0-0A for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:39 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30219 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 1jTQFx-0001mZ-Fm for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:37 -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-11-MlxHMeRQOlO4P4rBVSfP8Q-1; Tue, 28 Apr 2020 09:26:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D410462; Tue, 28 Apr 2020 13:26:33 +0000 (UTC) Received: from localhost (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC6E460C81; Tue, 28 Apr 2020 13:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588080395; 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=3OWL5LjDCx7y5IeGJUkDregA90v3xX3dRAsB1yU3tXA=; b=fD8dYbEUCyktAWsQhlNc7zKaJPS8PlXo2XY6GmSXJp3S7r9f5DyuheIHRvbEM5vwX1B9ro lLuGlrPmAVTUwtjAKD1NYe4FuX5rPVL8DqpPsDtkgWVeEYPz/byEMRbfM+k11YInZOdLsh 4NFAbO+HAmFJjWR8/VfVIXrwX1adoQk= X-MC-Unique: MlxHMeRQOlO4P4rBVSfP8Q-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 1/4] block: Add bdrv_make_empty() Date: Tue, 28 Apr 2020 15:26:26 +0200 Message-Id: <20200428132629.796753-2-mreitz@redhat.com> In-Reply-To: <20200428132629.796753-1-mreitz@redhat.com> References: <20200428132629.796753-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/28 04:15:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Right now, all users of bdrv_make_empty() call the BlockDriver method directly. That is not only bad style, it is also wrong, unless the caller has a BdrvChild with a WRITE permission. Introduce bdrv_make_empty() that verifies that it does. Signed-off-by: Max Reitz --- include/block/block.h | 1 + block.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index b05995fe9c..d947fb4080 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -351,6 +351,7 @@ BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOp= ts *opts, void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); void bdrv_refresh_limits(BlockDriverState *bs, Error **errp); int bdrv_commit(BlockDriverState *bs); +int bdrv_make_empty(BdrvChild *c, Error **errp); int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt); void bdrv_register(BlockDriver *bdrv); diff --git a/block.c b/block.c index 2e3905c99e..b0d5b98617 100644 --- a/block.c +++ b/block.c @@ -6791,3 +6791,26 @@ void bdrv_del_child(BlockDriverState *parent_bs, Bdr= vChild *child, Error **errp) =20 parent_bs->drv->bdrv_del_child(parent_bs, child, errp); } + +int bdrv_make_empty(BdrvChild *c, Error **errp) +{ + BlockDriver *drv =3D c->bs->drv; + int ret; + + assert(c->perm & BLK_PERM_WRITE); + + if (!drv->bdrv_make_empty) { + error_setg(errp, "%s does not support emptying nodes", + drv->format_name); + return -ENOTSUP; + } + + ret =3D drv->bdrv_make_empty(c->bs); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to empty %s", + c->bs->filename); + return ret; + } + + return 0; +} --=20 2.25.4 From nobody Sun May 19 00:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588080480; cv=none; d=zohomail.com; s=zohoarc; b=N3VJxdgFNNjcjWzgXK4/ynHRUqHsBPZXGcuzPLvTS6o43PpD48HqUHoFGQdto8aEvFCMhELfa/QHP7n756TCOQ7+Bh90uC0HjfQ7fObWpvGwhbmXhbEjhVKz5efXjj1L/FHXegR6lkOpNLDFiunheyKWi824aAx6Z5XbpHg0GRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588080480; 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=cZLAHpoF0nFbu2Hs47YYpAqe/b62f83BB8uxlXC1y4A=; b=kRsc+KYzuVrYuVcaMR8IERoSH9yjdRREpF+lCOZeNr64d/YeJfMsRSp92lY/Qwut63yvCI/UxBZOyYh6/hAxh8CcDIHffaxgNCdByYjUrStLXWrs7fxElHy31yqNr/KyJcWqdUMCrQQqms3vLOnwcT/sJyeZkK5QNRBIcrvE0qU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1588080480970690.011147912644; Tue, 28 Apr 2020 06:28:00 -0700 (PDT) Received: from localhost ([::1]:57582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQHH-0005OA-44 for importer@patchew.org; Tue, 28 Apr 2020 09:27:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35176) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQG1-0003BV-6e for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTQFz-0001nI-1t for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:40 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:27022 helo=us-smtp-delivery-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 1jTQFy-0001mt-LY for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:38 -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-350-wSI-PD4IOpuqWo5doSgm0w-1; Tue, 28 Apr 2020 09:26:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3D352835B41; Tue, 28 Apr 2020 13:26:35 +0000 (UTC) Received: from localhost (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0BA9579A9; Tue, 28 Apr 2020 13:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588080397; 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=cZLAHpoF0nFbu2Hs47YYpAqe/b62f83BB8uxlXC1y4A=; b=XTyj37/alB5vXrPuIlgx7/drnr5+OVT0joBuv2wEDwCk+fC4Soi3QIaeW/6z8kfFsX5yUh kcoUwU5rp/qxHDLJnEm80d19KqLrvRz4ymnRgUWbmEi3pOeMs6RbCOPpbluM/pBPtkxBG2 qeB/spnBFr2aD5leagrKyYQlKcG5QaQ= X-MC-Unique: wSI-PD4IOpuqWo5doSgm0w-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 2/4] block: Use bdrv_make_empty() where possible Date: Tue, 28 Apr 2020 15:26:27 +0200 Message-Id: <20200428132629.796753-3-mreitz@redhat.com> In-Reply-To: <20200428132629.796753-1-mreitz@redhat.com> References: <20200428132629.796753-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/28 02:06:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- block/replication.c | 6 ++---- block/vvfat.c | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/block/replication.c b/block/replication.c index da013c2041..cc6a40d577 100644 --- a/block/replication.c +++ b/block/replication.c @@ -331,9 +331,8 @@ static void secondary_do_checkpoint(BDRVReplicationStat= e *s, Error **errp) return; } =20 - ret =3D s->active_disk->bs->drv->bdrv_make_empty(s->active_disk->bs); + ret =3D bdrv_make_empty(s->active_disk, errp); if (ret < 0) { - error_setg(errp, "Cannot make active disk empty"); return; } =20 @@ -343,9 +342,8 @@ static void secondary_do_checkpoint(BDRVReplicationStat= e *s, Error **errp) return; } =20 - ret =3D s->hidden_disk->bs->drv->bdrv_make_empty(s->hidden_disk->bs); + ret =3D bdrv_make_empty(s->hidden_disk, errp); if (ret < 0) { - error_setg(errp, "Cannot make hidden disk empty"); return; } } diff --git a/block/vvfat.c b/block/vvfat.c index ab800c4887..e3020b65c8 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2960,9 +2960,7 @@ static int do_commit(BDRVVVFATState* s) return ret; } =20 - if (s->qcow->bs->drv && s->qcow->bs->drv->bdrv_make_empty) { - s->qcow->bs->drv->bdrv_make_empty(s->qcow->bs); - } + bdrv_make_empty(s->qcow, NULL); =20 memset(s->used_clusters, 0, sector2cluster(s, s->sector_count)); =20 --=20 2.25.4 From nobody Sun May 19 00:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588080562; cv=none; d=zohomail.com; s=zohoarc; b=Comg8qrjbj4r7b5t2FSNlYTGpyZcmQRWnPmcDRTpz4od4bTXJP9xKTb4RGjrabV3LYCaqzbl6Em2ReBlqNg1kSGSh5BvN68OwBd23td8TX9UOvBBiWUP9pF4VQIDlLAYHTcPoViOmdh7AWDh0AENvnUbUqwoB9B9RMGJcwOodk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588080562; 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=SsHLhS49WH24+Z/XU/jsCtHVgNxsldj+VAx19rqxs08=; b=RoLCqRNI3cubInZOzwahQnzxYX8+9+RXRUytx7GVEMXASRyTjTP58kLwGNG9CwOFJvOSvi/Ykdpj0NkK2bl3aETPuTaPrJ4w/CeX1l4c6StKv3WuGBvWbDu0hniwIxzQovVnIFkCiQ4EeGghalk+Cb3FQy7SJDyjmamCD0w97Uc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1588080562578547.5276329225171; Tue, 28 Apr 2020 06:29:22 -0700 (PDT) Received: from localhost ([::1]:57714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQIb-0008I3-8C for importer@patchew.org; Tue, 28 Apr 2020 09:29:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35180) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQG2-0003BY-KA for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTQG0-0001o1-W1 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:42 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:39298 helo=us-smtp-delivery-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 1jTQG0-0001nc-Gj for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:40 -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-92-IbfqFWYWPL2-TG5DHqLKog-1; Tue, 28 Apr 2020 09:26:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55DDD107ACF8; Tue, 28 Apr 2020 13:26:37 +0000 (UTC) Received: from localhost (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ECCDB60CD3; Tue, 28 Apr 2020 13:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588080399; 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=SsHLhS49WH24+Z/XU/jsCtHVgNxsldj+VAx19rqxs08=; b=flW1/jtyMtm4H1zdExx/w0/H9Hc/CZm6dzAwmrp5YRxQEk7J31qKEuRc8qluY+wNpizGPY j8WCpOdkgV1ifhl0WOiLZ1At5R/d26gfRtkUsS39QM9tefbKgqpwtbusxzISWalC+iIJ2b tsnh7HiL7d4G2nDMcsj2PSVhLuqJb+0= X-MC-Unique: IbfqFWYWPL2-TG5DHqLKog-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 3/4] block: Add blk_make_empty() Date: Tue, 28 Apr 2020 15:26:28 +0200 Message-Id: <20200428132629.796753-4-mreitz@redhat.com> In-Reply-To: <20200428132629.796753-1-mreitz@redhat.com> References: <20200428132629.796753-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/28 02:06:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Two callers of BlockDriver.bdrv_make_empty() remain that should not call this method directly. Both do not have access to a BdrvChild, but they can use a BlockBackend, so we add this function that lets them use it. Signed-off-by: Max Reitz --- include/sysemu/block-backend.h | 2 ++ block/block-backend.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index d37c1244dd..14338b76dc 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -266,4 +266,6 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in= , int64_t off_in, =20 const BdrvChild *blk_root(BlockBackend *blk); =20 +int blk_make_empty(BlockBackend *blk, Error **errp); + #endif diff --git a/block/block-backend.c b/block/block-backend.c index 3592066b42..5d36efd32f 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2402,3 +2402,8 @@ const BdrvChild *blk_root(BlockBackend *blk) { return blk->root; } + +int blk_make_empty(BlockBackend *blk, Error **errp) +{ + return bdrv_make_empty(blk->root, errp); +} --=20 2.25.4 From nobody Sun May 19 00:17:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588080471; cv=none; d=zohomail.com; s=zohoarc; b=eCvLGi86trSptVRWIcRAmMHKHqLMjHjaHGAE2tIVyPTHdkDAn2GZr6ysF8LPKFTmjg44OdZMmX47NRz8rRlEGJR10AGVA2XD+WtbbkVLgQS0AtgY0uDAEv1+7IeOceYHZE+4//rETMzUnhD/qft9m+63PfmY0XIx/dUCzgBqzso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588080471; 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=GEyOAEDZWInkg5GvbTHqHJ7asx8yW0xK/qDXZe7F7Wo=; b=BD+Y9YcvVxubqJa65Ge/1pz+HOdBdSW+Hrdv2icVcVfQbcpwcc7iB1aetP8lsSsTRxsNauytws2YNpkHL4JheTRc7P8e7jMiVCj13vGAjVQpm1mVsyDjtofr1ya6+Lz61pZV6R2q2h+sAQi7MEKB4GDv+AskLkHfJdKgI9yF+AE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1588080470995801.9563492659814; Tue, 28 Apr 2020 06:27:50 -0700 (PDT) Received: from localhost ([::1]:57572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQH6-0005EL-Hr for importer@patchew.org; Tue, 28 Apr 2020 09:27:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35192) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTQG4-0003ES-I9 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTQG3-0001oo-95 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:44 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28003 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 1jTQG2-0001oS-S0 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 09:26:42 -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-70-j8MmwSQtMeeGUzYxEhH6NQ-1; Tue, 28 Apr 2020 09:26:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 820EABFC0; Tue, 28 Apr 2020 13:26:39 +0000 (UTC) Received: from localhost (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2159160C81; Tue, 28 Apr 2020 13:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588080402; 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=GEyOAEDZWInkg5GvbTHqHJ7asx8yW0xK/qDXZe7F7Wo=; b=SV1qyGvU/9Pud0HjExukas+U2lPeAMS5c6dNgg0Dq8P63O1d73Tu8E+72IDr3AwFSorKVa 4scSjbxVnwZRzTCaifHuAPQbiXyJPNa8CQsT6YtTk87ndyUGtlA5h+DFPCzOxWsoNnTAO/ aOPmWWByml853RLC6EH8CABM0v2g5+M= X-MC-Unique: j8MmwSQtMeeGUzYxEhH6NQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 4/4] block: Use blk_make_empty() after commits Date: Tue, 28 Apr 2020 15:26:29 +0200 Message-Id: <20200428132629.796753-5-mreitz@redhat.com> In-Reply-To: <20200428132629.796753-1-mreitz@redhat.com> References: <20200428132629.796753-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/28 02:16:38 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- block/commit.c | 8 +++++++- qemu-img.c | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/block/commit.c b/block/commit.c index 8e672799af..24720ba67d 100644 --- a/block/commit.c +++ b/block/commit.c @@ -493,10 +493,16 @@ int bdrv_commit(BlockDriverState *bs) } =20 if (drv->bdrv_make_empty) { - ret =3D drv->bdrv_make_empty(bs); + ret =3D blk_set_perm(src, BLK_PERM_WRITE, BLK_PERM_ALL, NULL); if (ret < 0) { goto ro_cleanup; } + + ret =3D blk_make_empty(src, NULL); + if (ret < 0) { + goto ro_cleanup; + } + blk_flush(src); } =20 diff --git a/qemu-img.c b/qemu-img.c index 821cbf610e..a5e8659867 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1065,11 +1065,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; } } --=20 2.25.4