From nobody Tue Apr 15 03:12:58 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=1619782997; cv=none; d=zohomail.com; s=zohoarc; b=RaaGnZ++LIujBsZ4aHqIM6rNK+N8ysMLRi3Kg7d4aiRwRtnRJTnaYWGrjju3ij0PUcc7Z6BcPaJvpyhb8MnrO5el/BmzeHOpw6NsV0XEh6ttWIbzyUGxigbRhGfSH51qSk14Ndz5fEfm7uZ4tPxZO/u1z99g2ITIxY27iblsaT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619782997; 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=3g62pv01KCAWRhayeeMaWdBbIbPsWhoqn3TUsyQRQnU=; b=X70odVfS8T90Wj5t3vOty+XD8aHCERRAQQyhzcl7d9ly9fCURb0F9rxFxJtpb5lwClhSUYoFhiW6c1E5a9lDlzJZHhFW7Rek5tUqBbJ6fhkJA36JLGquJFc2HSyeGebIVQk51wGUMZKfc82sFYXuEpbi8RzQWs18+KaYq6fJ8K8= 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 1619782997647136.25904589506604; Fri, 30 Apr 2021 04:43:17 -0700 (PDT) Received: from localhost ([::1]:58942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcRYC-0006I4-F2 for importer@patchew.org; Fri, 30 Apr 2021 07:43:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcQm2-0005MO-G7 for qemu-devel@nongnu.org; Fri, 30 Apr 2021 06:53:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcQlw-0002zz-OG for qemu-devel@nongnu.org; Fri, 30 Apr 2021 06:53:30 -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-85-F0BuJKgyNHKio0fT8JYnyw-1; Fri, 30 Apr 2021 06:53: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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90A80890AEE; Fri, 30 Apr 2021 10:53:14 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-197.ams2.redhat.com [10.36.114.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F9995F707; Fri, 30 Apr 2021 10:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619780004; 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=3g62pv01KCAWRhayeeMaWdBbIbPsWhoqn3TUsyQRQnU=; b=U2BUcgKdsnv6oFj03/AHJloBmEpT9/ypOjxBhIpGJ5aH01WAe3GQo+cQyEZrPNiL+Gl00P wTFOL8TRDH1BbleX49aoRXJqcnVrRcm8/K0zLL3WEyT3FeST7MV1kCvCZGu9eLEeMg69DA 8AIb4EPg0zfY/5pY08TzRv7sFujRx+U= X-MC-Unique: F0BuJKgyNHKio0fT8JYnyw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 28/39] block: add bdrv_set_backing_noperm() transaction action Date: Fri, 30 Apr 2021 12:51:36 +0200 Message-Id: <20210430105147.125840-29-kwolf@redhat.com> In-Reply-To: <20210430105147.125840-1-kwolf@redhat.com> References: <20210430105147.125840-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no 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: Vladimir Sementsov-Ogievskiy Split out no-perm part of bdrv_set_backing_hd() as a separate transaction action. Note the in case of existing BdrvChild we reuse it, not recreate, just to do less actions. We don't need to create extra reference to backing_hd as we don't lose it in bdrv_attach_child(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Message-Id: <20210428151804.439460-29-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- block.c | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index 9922943793..bdfe59d94d 100644 --- a/block.c +++ b/block.c @@ -92,6 +92,8 @@ static int bdrv_attach_child_noperm(BlockDriverState *par= ent_bs, BdrvChild **child, Transaction *tran, Error **errp); +static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, + Transaction *tran); =20 static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQ= ueue *queue, Error **errp); @@ -3322,8 +3324,9 @@ static BdrvChildRole bdrv_backing_role(BlockDriverSta= te *bs) * Sets the bs->backing link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref(). */ -int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, - Error **errp) +static int bdrv_set_backing_noperm(BlockDriverState *bs, + BlockDriverState *backing_hd, + Transaction *tran, Error **errp) { int ret =3D 0; bool update_inherits_from =3D bdrv_chain_contains(bs, backing_hd) && @@ -3333,36 +3336,53 @@ int bdrv_set_backing_hd(BlockDriverState *bs, Block= DriverState *backing_hd, return -EPERM; } =20 - if (backing_hd) { - bdrv_ref(backing_hd); - } - if (bs->backing) { /* Cannot be frozen, we checked that above */ - bdrv_unref_child(bs, bs->backing); - bs->backing =3D NULL; + bdrv_unset_inherits_from(bs, bs->backing, tran); + bdrv_remove_filter_or_cow_child(bs, tran); } =20 if (!backing_hd) { goto out; } =20 - bs->backing =3D bdrv_attach_child(bs, backing_hd, "backing", &child_of= _bds, - bdrv_backing_role(bs), errp); - if (!bs->backing) { - ret =3D -EPERM; - goto out; + ret =3D bdrv_attach_child_noperm(bs, backing_hd, "backing", + &child_of_bds, bdrv_backing_role(bs), + &bs->backing, tran, errp); + if (ret < 0) { + return ret; } =20 - /* If backing_hd was already part of bs's backing chain, and + + /* + * If backing_hd was already part of bs's backing chain, and * inherits_from pointed recursively to bs then let's update it to - * point directly to bs (else it will become NULL). */ + * point directly to bs (else it will become NULL). + */ if (update_inherits_from) { - backing_hd->inherits_from =3D bs; + bdrv_set_inherits_from(backing_hd, bs, tran); } =20 out: - bdrv_refresh_limits(bs, NULL, NULL); + bdrv_refresh_limits(bs, tran, NULL); + + return 0; +} + +int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, + Error **errp) +{ + int ret; + Transaction *tran =3D tran_new(); + + ret =3D bdrv_set_backing_noperm(bs, backing_hd, tran, errp); + if (ret < 0) { + goto out; + } + + ret =3D bdrv_refresh_perms(bs, errp); +out: + tran_finalize(tran, ret); =20 return ret; } --=20 2.30.2