From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636632684983944.6819967682787; Thu, 11 Nov 2021 04:11:24 -0800 (PST) Received: from localhost ([::1]:46136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml8vL-0003HN-7m for importer@patchew.org; Thu, 11 Nov 2021 07:11:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sp-0008QW-8m for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41153) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sm-00032X-TV for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:46 -0500 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-593-7K8bEA2LMOG7CptutArtBQ-1; Thu, 11 Nov 2021 07:08:38 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C8D3425C8; Thu, 11 Nov 2021 12:08:37 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 011785D6B1; Thu, 11 Nov 2021 12:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632521; 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=2Qf2yowMAttbNAAjdTZUK5uUohwtUk695K3OtJ96ke0=; b=TzAKUN1oV3lmtZsdqY4ImQ80u+hXHBL5icm3iPs8sVJqcj5Orl7tsgRbBfDfxcr6OPlEDc HLRPj+K/gdjzL7KQGsqCaG7pKuvpSYWzTq5mX9x0hR6rTLfxi6LrMb/NtQsc85fzOECxaA 76jBzHFb3ox6zBQLVDKMmZlTHssZmg8= X-MC-Unique: 7K8bEA2LMOG7CptutArtBQ-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 01/10] stream: Traverse graph after modification Date: Thu, 11 Nov 2021 13:08:20 +0100 Message-Id: <20211111120829.81329-2-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@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=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636632687097100001 Content-Type: text/plain; charset="utf-8" bdrv_cor_filter_drop() modifies the block graph. That means that other parties can also modify the block graph before it returns. Therefore, we cannot assume that the result of a graph traversal we did before remains valid afterwards. We should thus fetch `base` and `unfiltered_base` afterwards instead of before. Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/stream.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/block/stream.c b/block/stream.c index 97bee482dc..e45113aed6 100644 --- a/block/stream.c +++ b/block/stream.c @@ -54,8 +54,8 @@ static int stream_prepare(Job *job) { StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockDriverState *unfiltered_bs =3D bdrv_skip_filters(s->target_bs); - BlockDriverState *base =3D bdrv_filter_or_cow_bs(s->above_base); - BlockDriverState *unfiltered_base =3D bdrv_skip_filters(base); + BlockDriverState *base; + BlockDriverState *unfiltered_base; Error *local_err =3D NULL; int ret =3D 0; =20 @@ -63,6 +63,9 @@ static int stream_prepare(Job *job) bdrv_cor_filter_drop(s->cor_filter_bs); s->cor_filter_bs =3D NULL; =20 + base =3D bdrv_filter_or_cow_bs(s->above_base); + unfiltered_base =3D bdrv_skip_filters(base); + if (bdrv_cow_child(unfiltered_bs)) { const char *base_id =3D NULL, *base_fmt =3D NULL; if (unfiltered_base) { --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636632801076547.2024156414757; Thu, 11 Nov 2021 04:13:21 -0800 (PST) Received: from localhost ([::1]:53472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml8xE-00089M-3a for importer@patchew.org; Thu, 11 Nov 2021 07:13:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sr-0008SV-U6 for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25098) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sq-00035g-41 for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:49 -0500 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-178-dHYKbJ0dMiOp1RTUJ41Lrg-1; Thu, 11 Nov 2021 07:08:44 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CBA21017965; Thu, 11 Nov 2021 12:08:43 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16402197FC; Thu, 11 Nov 2021 12:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632527; 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=o+PAHv2V7jz95XP5m5W8oPbjYDrXB+UXUyRgmX9RjKU=; b=hhtjRVZ9wBW2W+83zyw7P9zMi3irLAbmtdTNfWUWb47Kp1F7zhSsLe+Oc/3OC35ycsa0cu +Pv6o33XiTZlYSBVT46ZuTakiDUKyLmAfVI/lRrhPvP3lGjRkzvhhhWBSs/dRTwy8Pohlj FaHe9rqBvdRGhTrtFYluRHz96Izn2hg= X-MC-Unique: dHYKbJ0dMiOp1RTUJ41Lrg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 02/10] block: Manipulate children list in .attach/.detach Date: Thu, 11 Nov 2021 13:08:21 +0100 Message-Id: <20211111120829.81329-3-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636632802228100001 Content-Type: text/plain; charset="utf-8" The children list is specific to BDS parents. We should not modify it in the general children modification code, but let BDS parents deal with it in their .attach() and .detach() methods. This also has the advantage that a BdrvChild is removed from the children list before its .bs pointer can become NULL. BDS parents generally assume that their children's .bs pointer is never NULL, so this is actually a bug fix. Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 580cb77a70..ca024ffced 100644 --- a/block.c +++ b/block.c @@ -1387,6 +1387,8 @@ static void bdrv_child_cb_attach(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; =20 + QLIST_INSERT_HEAD(&bs->children, child, next); + if (child->role & BDRV_CHILD_COW) { bdrv_backing_attach(child); } @@ -1403,6 +1405,8 @@ static void bdrv_child_cb_detach(BdrvChild *child) } =20 bdrv_unapply_subtree_drain(child, bs); + + QLIST_REMOVE(child, next); } =20 static int bdrv_child_cb_update_filename(BdrvChild *c, BlockDriverState *b= ase, @@ -2747,7 +2751,7 @@ static void bdrv_child_free(void *opaque) static void bdrv_remove_empty_child(BdrvChild *child) { assert(!child->bs); - QLIST_SAFE_REMOVE(child, next); + assert(!child->next.le_prev); /* not in children list */ bdrv_child_free(child); } =20 @@ -2913,12 +2917,6 @@ static int bdrv_attach_child_noperm(BlockDriverState= *parent_bs, return ret; } =20 - QLIST_INSERT_HEAD(&parent_bs->children, *child, next); - /* - * child is removed in bdrv_attach_child_common_abort(), so don't care= to - * abort this change separately. - */ - return 0; } =20 @@ -4851,7 +4849,6 @@ static void bdrv_remove_filter_or_cow_child_abort(voi= d *opaque) BdrvRemoveFilterOrCowChild *s =3D opaque; BlockDriverState *parent_bs =3D s->child->opaque; =20 - QLIST_INSERT_HEAD(&parent_bs->children, s->child, next); if (s->is_backing) { parent_bs->backing =3D s->child; } else { @@ -4906,7 +4903,6 @@ static void bdrv_remove_file_or_backing_child(BlockDr= iverState *bs, }; tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); =20 - QLIST_SAFE_REMOVE(child, next); if (s->is_backing) { bs->backing =3D NULL; } else { --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636632700419376.0166996333189; Thu, 11 Nov 2021 04:11:40 -0800 (PST) Received: from localhost ([::1]:46736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml8vb-0003fN-DC for importer@patchew.org; Thu, 11 Nov 2021 07:11:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8ss-0008SY-H6 for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56277) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sq-00035k-5T for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:50 -0500 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-179-Mqr0phCXMPKoVDUQkuMU9Q-1; Thu, 11 Nov 2021 07:08:46 -0500 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 4F4D881C85D; Thu, 11 Nov 2021 12:08:45 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C90AE5C1B4; Thu, 11 Nov 2021 12:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632527; 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=blNeOdAFk9BJKZgYWPxvzOhKYm6MQnYcVgnLZmDa/dg=; b=RLdxqFj8Ny2aqZrVog92Ekr0pCTuvZ0VAjhOIi3ObjuXWHyRP9d0gxcV3qrWh5jn0kDHui vLRsg4LZh5/8ngAnJ4BHzsQVrNYELXjX8TMXqKpuX8rg2jaBiadIFqVBCMb32LNXWkTyD5 e1P4R9pDy2JDt1qB7JS/cgTsTzjULfY= X-MC-Unique: Mqr0phCXMPKoVDUQkuMU9Q-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 03/10] block: Unite remove_empty_child and child_free Date: Thu, 11 Nov 2021 13:08:22 +0100 Message-Id: <20211111120829.81329-4-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@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=hreitz@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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636632701632100001 Content-Type: text/plain; charset="utf-8" Now that bdrv_remove_empty_child() no longer removes the child from the parent's children list but only checks that it is not in such a list, it is only a wrapper around bdrv_child_free() that checks that the child is empty and unused. That should apply to all children that we free, so put those checks into bdrv_child_free() and drop bdrv_remove_empty_child(). Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index ca024ffced..19bff4f95c 100644 --- a/block.c +++ b/block.c @@ -2740,19 +2740,19 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, } } =20 -static void bdrv_child_free(void *opaque) -{ - BdrvChild *c =3D opaque; - - g_free(c->name); - g_free(c); -} - -static void bdrv_remove_empty_child(BdrvChild *child) +/** + * Free the given @child. + * + * The child must be empty (i.e. `child->bs =3D=3D NULL`) and it must be + * unused (i.e. not in a children list). + */ +static void bdrv_child_free(BdrvChild *child) { assert(!child->bs); assert(!child->next.le_prev); /* not in children list */ - bdrv_child_free(child); + + g_free(child->name); + g_free(child); } =20 typedef struct BdrvAttachChildCommonState { @@ -2786,7 +2786,7 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) } =20 bdrv_unref(bs); - bdrv_remove_empty_child(child); + bdrv_child_free(child); *s->child =3D NULL; } =20 @@ -2859,7 +2859,7 @@ static int bdrv_attach_child_common(BlockDriverState = *child_bs, =20 if (ret < 0) { error_propagate(errp, local_err); - bdrv_remove_empty_child(new_child); + bdrv_child_free(new_child); return ret; } } @@ -2925,7 +2925,7 @@ static void bdrv_detach_child(BdrvChild *child) BlockDriverState *old_bs =3D child->bs; =20 bdrv_replace_child_noperm(child, NULL); - bdrv_remove_empty_child(child); + bdrv_child_free(child); =20 if (old_bs) { /* --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636632840118773.7388784684854; Thu, 11 Nov 2021 04:14:00 -0800 (PST) Received: from localhost ([::1]:54628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml8xr-0000W6-1x for importer@patchew.org; Thu, 11 Nov 2021 07:13:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8su-0008VL-Ie for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sr-000366-TM for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:51 -0500 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-560-FmF-P-FRP4mAPw8P2cR_BA-1; Thu, 11 Nov 2021 07:08:48 -0500 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 3FA2A87D541; Thu, 11 Nov 2021 12:08:47 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA7B95C1A3; Thu, 11 Nov 2021 12:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632529; 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=62CeFwou3FsoOAyfFpCis1e0vM8bDZyqp8CVWH3+0+A=; b=bwfROfkCKqEbqzEfZTxSlhTTVoQ01yyLmjIML13lkI+/PHini5b+ksUUD37Q9EI3GRgir3 a7XvaODvlGratiwK9B7hbgY30h7e7pHrG5Igyo0PiOeAu3dxNEDg8lzkDstnsY9p0mvu/n cY8fYTVzY6eZgO6DCLupyDcP7YMCiNI= X-MC-Unique: FmF-P-FRP4mAPw8P2cR_BA-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 04/10] block: Drop detached child from ignore list Date: Thu, 11 Nov 2021 13:08:23 +0100 Message-Id: <20211111120829.81329-5-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@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=hreitz@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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636632847130100001 Content-Type: text/plain; charset="utf-8" bdrv_attach_child_common_abort() restores the parent's AioContext. To do so, the child (which was supposed to be attached, but is now detached again by this abort handler) is added to the ignore list for the AioContext changing functions. However, since we modify a BDS's children list in the BdrvChildClass's .attach and .detach handlers, the child is already effectively detached from the parent by this point. We do not need to put it into the ignore list. Use this opportunity to clean up the empty line structure: Keep setting the ignore list, invoking the AioContext function, and freeing the ignore list in blocks separated by empty lines. Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 19bff4f95c..c7d5aa5254 100644 --- a/block.c +++ b/block.c @@ -2774,14 +2774,16 @@ static void bdrv_attach_child_common_abort(void *op= aque) } =20 if (bdrv_child_get_parent_aio_context(child) !=3D s->old_parent_ctx) { - GSList *ignore =3D g_slist_prepend(NULL, child); + GSList *ignore; =20 + /* No need to ignore `child`, because it has been detached already= */ + ignore =3D NULL; child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore, &error_abort); g_slist_free(ignore); - ignore =3D g_slist_prepend(NULL, child); - child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore); =20 + ignore =3D NULL; + child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore); g_slist_free(ignore); } =20 --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636632853735481.47723767162006; Thu, 11 Nov 2021 04:14:13 -0800 (PST) Received: from localhost ([::1]:55442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml8y4-00014X-Oh for importer@patchew.org; Thu, 11 Nov 2021 07:14:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8t1-000082-8H for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sz-00036v-6J for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:58 -0500 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-462-a3knXNu1OlmSnw3J3timvA-1; Thu, 11 Nov 2021 07:08:50 -0500 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 731F4101796A; Thu, 11 Nov 2021 12:08:49 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE6EA5C1A3; Thu, 11 Nov 2021 12:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632534; 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=uyzUp2gROLRX2Mtjs6Y0dXbVxkZC5iqmMyE5EANOx5Y=; b=MjwPi/KAqg6pUBDTQX16TWIQUXFkzEcZ4812YArJbnjloOPL511Mm/L0YnO462BJpHd8k9 PZNc+bNxRI0jbC6fOx9+c4JunDyLP5TT8ZIXL4fwhfSCtqStN535yDQS4uImfA/YItTA2I 8kCPbJZR63K/j/qXK71PtrzMsAKxwTw= X-MC-Unique: a3knXNu1OlmSnw3J3timvA-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 05/10] block: Pass BdrvChild ** to replace_child_noperm Date: Thu, 11 Nov 2021 13:08:24 +0100 Message-Id: <20211111120829.81329-6-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@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=hreitz@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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636632855650100003 Content-Type: text/plain; charset="utf-8" bdrv_replace_child_noperm() modifies BdrvChild.bs, and can potentially set it to NULL. That is dangerous, because BDS parents generally assume that their children's .bs pointer is never NULL. We therefore want to let bdrv_replace_child_noperm() set the corresponding BdrvChild pointer to NULL, too. This patch lays the foundation for it by passing a BdrvChild ** pointer to bdrv_replace_child_noperm() so that it can later use it to NULL the BdrvChild pointer immediately after setting BdrvChild.bs to NULL. (We will still need to undertake some intermediate steps, though.) Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index c7d5aa5254..d668156eca 100644 --- a/block.c +++ b/block.c @@ -87,7 +87,7 @@ static BlockDriverState *bdrv_open_inherit(const char *fi= lename, static bool bdrv_recurse_has_child(BlockDriverState *bs, BlockDriverState *child); =20 -static void bdrv_replace_child_noperm(BdrvChild *child, +static void bdrv_replace_child_noperm(BdrvChild **child, BlockDriverState *new_bs); static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, BdrvChild *child, @@ -2270,7 +2270,7 @@ static void bdrv_replace_child_abort(void *opaque) BlockDriverState *new_bs =3D s->child->bs; =20 /* old_bs reference is transparently moved from @s to @s->child */ - bdrv_replace_child_noperm(s->child, s->old_bs); + bdrv_replace_child_noperm(&s->child, s->old_bs); bdrv_unref(new_bs); } =20 @@ -2300,7 +2300,7 @@ static void bdrv_replace_child_tran(BdrvChild *child,= BlockDriverState *new_bs, if (new_bs) { bdrv_ref(new_bs); } - bdrv_replace_child_noperm(child, new_bs); + bdrv_replace_child_noperm(&child, new_bs); /* old_bs reference is transparently moved from @child to @s */ } =20 @@ -2672,9 +2672,10 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission = qapi_perm) return permissions[qapi_perm]; } =20 -static void bdrv_replace_child_noperm(BdrvChild *child, +static void bdrv_replace_child_noperm(BdrvChild **childp, BlockDriverState *new_bs) { + BdrvChild *child =3D *childp; BlockDriverState *old_bs =3D child->bs; int new_bs_quiesce_counter; int drain_saldo; @@ -2767,7 +2768,7 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) BdrvChild *child =3D *s->child; BlockDriverState *bs =3D child->bs; =20 - bdrv_replace_child_noperm(child, NULL); + bdrv_replace_child_noperm(s->child, NULL); =20 if (bdrv_get_aio_context(bs) !=3D s->old_child_ctx) { bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); @@ -2867,7 +2868,7 @@ static int bdrv_attach_child_common(BlockDriverState = *child_bs, } =20 bdrv_ref(child_bs); - bdrv_replace_child_noperm(new_child, child_bs); + bdrv_replace_child_noperm(&new_child, child_bs); =20 *child =3D new_child; =20 @@ -2922,12 +2923,12 @@ static int bdrv_attach_child_noperm(BlockDriverStat= e *parent_bs, return 0; } =20 -static void bdrv_detach_child(BdrvChild *child) +static void bdrv_detach_child(BdrvChild **childp) { - BlockDriverState *old_bs =3D child->bs; + BlockDriverState *old_bs =3D (*childp)->bs; =20 - bdrv_replace_child_noperm(child, NULL); - bdrv_child_free(child); + bdrv_replace_child_noperm(childp, NULL); + bdrv_child_free(*childp); =20 if (old_bs) { /* @@ -3033,7 +3034,7 @@ void bdrv_root_unref_child(BdrvChild *child) BlockDriverState *child_bs; =20 child_bs =3D child->bs; - bdrv_detach_child(child); + bdrv_detach_child(&child); bdrv_unref(child_bs); } =20 --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636632950924113.5057506711122; Thu, 11 Nov 2021 04:15:50 -0800 (PST) Received: from localhost ([::1]:60456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml8zd-0004Wj-Oi for importer@patchew.org; Thu, 11 Nov 2021 07:15:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8t2-00009z-20 for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25607) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8sz-000377-6o for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:08:59 -0500 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-414-pYCJay2aN16MgjzAI2MGJg-1; Thu, 11 Nov 2021 07:08:52 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8888981C85D; Thu, 11 Nov 2021 12:08:51 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DC7B67842; Thu, 11 Nov 2021 12:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632535; 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=H0DBrXhYuq69qzyEzXx2sq+C3X1Trt3RY1zSE6P2mN8=; b=P8wNxsNUqAvr/r+uqEjlhENgl6NyPzvEpmW1jNAdBQwTWfpuviFwIXQ3DXlkw2DCzoxxGC kKiFUeotA/aqIsoUHSKc9x4EXZuPCMSY6y+weELV9GKk9UFHRTPtMAEmDNSqc5ZFixc3bC 5dVcSMfV27ZrJaCaC+9IDlaZZBL4GFo= X-MC-Unique: pYCJay2aN16MgjzAI2MGJg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 06/10] block: Restructure remove_file_or_backing_child() Date: Thu, 11 Nov 2021 13:08:25 +0100 Message-Id: <20211111120829.81329-7-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636632952611100001 Content-Type: text/plain; charset="utf-8" As of a future patch, bdrv_replace_child_tran() will take a BdrvChild ** pointer. Prepare for that by getting such a pointer and using it where applicable, and (dereferenced) as a parameter for bdrv_replace_child_tran(). Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index d668156eca..8da057f800 100644 --- a/block.c +++ b/block.c @@ -4887,30 +4887,33 @@ static void bdrv_remove_file_or_backing_child(Block= DriverState *bs, BdrvChild *child, Transaction *tran) { + BdrvChild **childp; BdrvRemoveFilterOrCowChild *s; =20 - assert(child =3D=3D bs->backing || child =3D=3D bs->file); - if (!child) { return; } =20 + if (child =3D=3D bs->backing) { + childp =3D &bs->backing; + } else if (child =3D=3D bs->file) { + childp =3D &bs->file; + } else { + g_assert_not_reached(); + } + if (child->bs) { - bdrv_replace_child_tran(child, NULL, tran); + bdrv_replace_child_tran(*childp, NULL, tran); } =20 s =3D g_new(BdrvRemoveFilterOrCowChild, 1); *s =3D (BdrvRemoveFilterOrCowChild) { .child =3D child, - .is_backing =3D (child =3D=3D bs->backing), + .is_backing =3D (childp =3D=3D &bs->backing), }; tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); =20 - if (s->is_backing) { - bs->backing =3D NULL; - } else { - bs->file =3D NULL; - } + *childp =3D NULL; } =20 /* --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636633099644474.5335608549806; Thu, 11 Nov 2021 04:18:19 -0800 (PST) Received: from localhost ([::1]:38368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml922-0000Ot-Lz for importer@patchew.org; Thu, 11 Nov 2021 07:18:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8t6-0000Dc-7L for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8t0-00037W-SL for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:03 -0500 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-307-bjGn7a0sM8u7nyOXd7DQSw-1; Thu, 11 Nov 2021 07:08:55 -0500 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 1CEC0425C8; Thu, 11 Nov 2021 12:08:54 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C2CA5C1B4; Thu, 11 Nov 2021 12:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632538; 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=LTwU1wxiju8LS239rJNt8QDqlXENRjV3DDrajp7ulPo=; b=HvzK52rNfhbsdVTI/mPq8Frvlx/DqheY3DnjWmakgRfmxai9skp4oRqBnZZoCOwat39E9A 1AklycqIkPbT9fYenp/EavgQuDPY9lEOatGcCQ5juYHiVCoHHaEfNqUq3s9NxujahS3crH FQuQR34a5E8xBr2woyhVi67IK5ENccM= X-MC-Unique: bjGn7a0sM8u7nyOXd7DQSw-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 07/10] transactions: Invoke clean() after everything else Date: Thu, 11 Nov 2021 13:08:26 +0100 Message-Id: <20211111120829.81329-8-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@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=hreitz@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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636633100700100001 Content-Type: text/plain; charset="utf-8" Invoke the transaction drivers' .clean() methods only after all .commit() or .abort() handlers are done. This makes it easier to have nested transactions where the top-level transactions pass objects to lower transactions that the latter can still use throughout their commit/abort phases, while the top-level transaction keeps a reference that is released in its .clean() method. (Before this commit, that is also possible, but the top-level transaction would need to take care to invoke tran_add() before the lower-level transaction does. This commit makes the ordering irrelevant, which is just a bit nicer.) Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/qemu/transactions.h | 3 +++ util/transactions.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/qemu/transactions.h b/include/qemu/transactions.h index 92c5965235..2f2060acd9 100644 --- a/include/qemu/transactions.h +++ b/include/qemu/transactions.h @@ -31,6 +31,9 @@ * tran_create(), call your "prepare" functions on it, and finally call * tran_abort() or tran_commit() to finalize the transaction by correspond= ing * finalization actions in reverse order. + * + * The clean() functions registered by the drivers in a transaction are ca= lled + * last, after all abort() or commit() functions have been called. */ =20 #ifndef QEMU_TRANSACTIONS_H diff --git a/util/transactions.c b/util/transactions.c index d0bc9a3e73..2dbdedce95 100644 --- a/util/transactions.c +++ b/util/transactions.c @@ -61,11 +61,13 @@ void tran_abort(Transaction *tran) { TransactionAction *act, *next; =20 - QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { + QSLIST_FOREACH(act, &tran->actions, entry) { if (act->drv->abort) { act->drv->abort(act->opaque); } + } =20 + QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { if (act->drv->clean) { act->drv->clean(act->opaque); } @@ -80,11 +82,13 @@ void tran_commit(Transaction *tran) { TransactionAction *act, *next; =20 - QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { + QSLIST_FOREACH(act, &tran->actions, entry) { if (act->drv->commit) { act->drv->commit(act->opaque); } + } =20 + QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { if (act->drv->clean) { act->drv->clean(act->opaque); } --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636632979375206.61792760534274; Thu, 11 Nov 2021 04:16:19 -0800 (PST) Received: from localhost ([::1]:33294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml906-0005FM-4m for importer@patchew.org; Thu, 11 Nov 2021 07:16:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8t7-0000Gz-81 for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8t5-00038d-5T for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:04 -0500 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-566-qpmZzM7KPRWqkorCF80C7A-1; Thu, 11 Nov 2021 07:09:00 -0500 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 8404C1017965; Thu, 11 Nov 2021 12:08:59 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD69A60854; Thu, 11 Nov 2021 12:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632541; 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=3zuskU1Ue0kfE0EDREK5yYTdp2Ndwxa+1qk5r8gf1yc=; b=OgDAI48ahyeHwm21Nmcbc51gYrLy02ydG9dx/JSCLF9mTPFglQe453PTxIKgjOFs0rsME7 IqfymBiOodbt5OmRHHhhFjxkJIEyuji79eA/6Xfzx3ATyHdId1TG+ecuUI7+clkB+8OtvG 4UVS48StIOqNjW2wLmCGe6t2HZKRt6c= X-MC-Unique: qpmZzM7KPRWqkorCF80C7A-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 08/10] block: Let replace_child_tran keep indirect pointer Date: Thu, 11 Nov 2021 13:08:27 +0100 Message-Id: <20211111120829.81329-9-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636632979953100001 Content-Type: text/plain; charset="utf-8" As of a future commit, bdrv_replace_child_noperm() will clear the indirect BdrvChild pointer passed to it if the new child BDS is NULL. bdrv_replace_child_tran() will want to let it do that, but revert this change in its abort handler. For that, we need to have it receive a BdrvChild ** pointer, too, and keep it stored in the BdrvReplaceChildState object that we attach to the transaction. Note that we do not need to store it in the BdrvReplaceChildState when new_bs is not NULL, because then there is nothing to revert. This is important so that bdrv_replace_node_noperm() can pass a pointer to a loop-local variable to bdrv_replace_child_tran() without worrying that this pointer will outlive one loop iteration. (Of course, for that to work, bdrv_replace_node_noperm() and in turn bdrv_replace_node() and its relatives may not be called with a NULL @to node. Luckily, they already are not, but now we should assert this.) bdrv_remove_file_or_backing_child() on the other hand needs to ensure that the indirect pointer it passes will stay valid for the duration of the transaction. Ensure this by keeping a strong reference to the BDS whose &bs->backing or &bs->file it passes to bdrv_replace_child_tran(), and giving up that reference only in the transaction .clean() handler. Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 8da057f800..a40027161c 100644 --- a/block.c +++ b/block.c @@ -2254,6 +2254,7 @@ static int bdrv_drv_set_perm(BlockDriverState *bs, ui= nt64_t perm, =20 typedef struct BdrvReplaceChildState { BdrvChild *child; + BdrvChild **childp; BlockDriverState *old_bs; } BdrvReplaceChildState; =20 @@ -2269,7 +2270,29 @@ static void bdrv_replace_child_abort(void *opaque) BdrvReplaceChildState *s =3D opaque; BlockDriverState *new_bs =3D s->child->bs; =20 - /* old_bs reference is transparently moved from @s to @s->child */ + /* + * old_bs reference is transparently moved from @s to s->child. + * + * Pass &s->child here instead of s->childp, because: + * (1) s->old_bs must be non-NULL, so bdrv_replace_child_noperm() will= not + * modify the BdrvChild * pointer we indirectly pass to it, i.e. it + * will not modify s->child. From that perspective, it does not m= atter + * whether we pass s->childp or &s->child. + * (TODO: Right now, bdrv_replace_child_noperm() never modifies th= at + * pointer anyway (though it will in the future), so at this point= it + * absolutely does not matter whether we pass s->childp or &s->chi= ld.) + * (2) If new_bs is not NULL, s->childp will be NULL. We then cannot = use + * it here. + * (3) If new_bs is NULL, *s->childp will have been NULLed by + * bdrv_replace_child_tran()'s bdrv_replace_child_noperm() call, a= nd we + * must not pass a NULL *s->childp here. + * (TODO: In its current state, bdrv_replace_child_noperm() will n= ot + * have NULLed *s->childp, so this does not apply yet. It will in= the + * future.) + * + * So whether new_bs was NULL or not, we cannot pass s->childp here; a= nd in + * any case, there is no reason to pass it anyway. + */ bdrv_replace_child_noperm(&s->child, s->old_bs); bdrv_unref(new_bs); } @@ -2286,22 +2309,32 @@ static TransactionActionDrv bdrv_replace_child_drv = =3D { * Note: real unref of old_bs is done only on commit. * * The function doesn't update permissions, caller is responsible for this. + * + * Note that if new_bs =3D=3D NULL, @childp is stored in a state object at= tached + * to @tran, so that the old child can be reinstated in the abort handler. + * Therefore, if @new_bs can be NULL, @childp must stay valid until the + * transaction is committed or aborted. + * + * (TODO: The reinstating does not happen yet, but it will once + * bdrv_replace_child_noperm() NULLs *childp when new_bs is NULL.) */ -static void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *ne= w_bs, +static void bdrv_replace_child_tran(BdrvChild **childp, + BlockDriverState *new_bs, Transaction *tran) { BdrvReplaceChildState *s =3D g_new(BdrvReplaceChildState, 1); *s =3D (BdrvReplaceChildState) { - .child =3D child, - .old_bs =3D child->bs, + .child =3D *childp, + .childp =3D new_bs =3D=3D NULL ? childp : NULL, + .old_bs =3D (*childp)->bs, }; tran_add(tran, &bdrv_replace_child_drv, s); =20 if (new_bs) { bdrv_ref(new_bs); } - bdrv_replace_child_noperm(&child, new_bs); - /* old_bs reference is transparently moved from @child to @s */ + bdrv_replace_child_noperm(childp, new_bs); + /* old_bs reference is transparently moved from *childp to @s */ } =20 /* @@ -4844,6 +4877,7 @@ static bool should_update_child(BdrvChild *c, BlockDr= iverState *to) =20 typedef struct BdrvRemoveFilterOrCowChild { BdrvChild *child; + BlockDriverState *bs; bool is_backing; } BdrvRemoveFilterOrCowChild; =20 @@ -4873,10 +4907,19 @@ static void bdrv_remove_filter_or_cow_child_commit(= void *opaque) bdrv_child_free(s->child); } =20 +static void bdrv_remove_filter_or_cow_child_clean(void *opaque) +{ + BdrvRemoveFilterOrCowChild *s =3D opaque; + + /* Drop the bs reference after the transaction is done */ + bdrv_unref(s->bs); + g_free(s); +} + static TransactionActionDrv bdrv_remove_filter_or_cow_child_drv =3D { .abort =3D bdrv_remove_filter_or_cow_child_abort, .commit =3D bdrv_remove_filter_or_cow_child_commit, - .clean =3D g_free, + .clean =3D bdrv_remove_filter_or_cow_child_clean, }; =20 /* @@ -4894,6 +4937,11 @@ static void bdrv_remove_file_or_backing_child(BlockD= riverState *bs, return; } =20 + /* + * Keep a reference to @bs so @childp will stay valid throughout the + * transaction (required by bdrv_replace_child_tran()) + */ + bdrv_ref(bs); if (child =3D=3D bs->backing) { childp =3D &bs->backing; } else if (child =3D=3D bs->file) { @@ -4903,12 +4951,13 @@ static void bdrv_remove_file_or_backing_child(Block= DriverState *bs, } =20 if (child->bs) { - bdrv_replace_child_tran(*childp, NULL, tran); + bdrv_replace_child_tran(childp, NULL, tran); } =20 s =3D g_new(BdrvRemoveFilterOrCowChild, 1); *s =3D (BdrvRemoveFilterOrCowChild) { .child =3D child, + .bs =3D bs, .is_backing =3D (childp =3D=3D &bs->backing), }; tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); @@ -4934,6 +4983,8 @@ static int bdrv_replace_node_noperm(BlockDriverState = *from, { BdrvChild *c, *next; =20 + assert(to !=3D NULL); + QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { assert(c->bs =3D=3D from); if (!should_update_child(c, to)) { @@ -4949,7 +5000,12 @@ static int bdrv_replace_node_noperm(BlockDriverState= *from, c->name, from->node_name); return -EPERM; } - bdrv_replace_child_tran(c, to, tran); + + /* + * Passing a pointer to the local variable @c is fine here, because + * @to is not NULL, and so &c will not be attached to the transact= ion. + */ + bdrv_replace_child_tran(&c, to, tran); } =20 return 0; @@ -4964,6 +5020,8 @@ static int bdrv_replace_node_noperm(BlockDriverState = *from, * * With @detach_subchain=3Dtrue @to must be in a backing chain of @from. I= n this * case backing link of the cow-parent of @to is removed. + * + * @to must not be NULL. */ static int bdrv_replace_node_common(BlockDriverState *from, BlockDriverState *to, @@ -4976,6 +5034,8 @@ static int bdrv_replace_node_common(BlockDriverState = *from, BlockDriverState *to_cow_parent =3D NULL; int ret; =20 + assert(to !=3D NULL); + if (detach_subchain) { assert(bdrv_chain_contains(from, to)); assert(from !=3D to); @@ -5031,6 +5091,9 @@ out: return ret; } =20 +/** + * Replace node @from by @to (where neither may be NULL). + */ int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, Error **errp) { @@ -5098,7 +5161,7 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriv= erState *new_bs, bdrv_drained_begin(old_bs); bdrv_drained_begin(new_bs); =20 - bdrv_replace_child_tran(child, new_bs, tran); + bdrv_replace_child_tran(&child, new_bs, tran); =20 found =3D g_hash_table_new(NULL, NULL); refresh_list =3D bdrv_topological_dfs(refresh_list, found, old_bs); --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16366333031941020.7481737727536; Thu, 11 Nov 2021 04:21:43 -0800 (PST) Received: from localhost ([::1]:45476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml95J-0005Jy-V5 for importer@patchew.org; Thu, 11 Nov 2021 07:21:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8tH-0000TE-0f for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8tD-00039v-6N for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:14 -0500 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-174-5ppcTJKlNb-uqQP-Vs249Q-1; Thu, 11 Nov 2021 07:09:05 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD88C1006AA1; Thu, 11 Nov 2021 12:09:04 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 590351048127; Thu, 11 Nov 2021 12:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632549; 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=foivRn0VHMxBDwXJV39FICcad0Dz9e5GvpRGWcZNLi4=; b=OU+BIRK9D26Py7DxnVAgnUL24Ys4yoKKNRALhM/khLijX6QwrwW6FFOeqJ6ftDXMZiptoW c2MAxROzzu6W33Hp43wmN4Y9a77SQPgsrFt4c34JqB0aijjAebyO/aIzvUBm512hB5IyE7 5gZNgYCNfBIgbtqruPYL2Q/J/S7I5W4= X-MC-Unique: 5ppcTJKlNb-uqQP-Vs249Q-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 09/10] block: Let replace_child_noperm free children Date: Thu, 11 Nov 2021 13:08:28 +0100 Message-Id: <20211111120829.81329-10-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636633304019100001 Content-Type: text/plain; charset="utf-8" In most of the block layer, especially when traversing down from other BlockDriverStates, we assume that BdrvChild.bs can never be NULL. When it becomes NULL, it is expected that the corresponding BdrvChild pointer also becomes NULL and the BdrvChild object is freed. Therefore, once bdrv_replace_child_noperm() sets the BdrvChild.bs pointer to NULL, it should also immediately set the corresponding BdrvChild pointer (like bs->file or bs->backing) to NULL. In that context, it also makes sense for this function to free the child. Sometimes we cannot do so, though, because it is called in a transactional context where the caller might still want to reinstate the child in the abort branch (and free it only on commit), so this behavior has to remain optional. In bdrv_replace_child_tran()'s abort handler, we now rely on the fact that the BdrvChild passed to bdrv_replace_child_tran() must have had a non-NULL .bs pointer initially. Make a note of that and assert it. Signed-off-by: Hanna Reitz --- block.c | 102 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/block.c b/block.c index a40027161c..0ac5b163d2 100644 --- a/block.c +++ b/block.c @@ -87,8 +87,10 @@ static BlockDriverState *bdrv_open_inherit(const char *f= ilename, static bool bdrv_recurse_has_child(BlockDriverState *bs, BlockDriverState *child); =20 +static void bdrv_child_free(BdrvChild *child); static void bdrv_replace_child_noperm(BdrvChild **child, - BlockDriverState *new_bs); + BlockDriverState *new_bs, + bool free_empty_child); static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, BdrvChild *child, Transaction *tran); @@ -2256,12 +2258,16 @@ typedef struct BdrvReplaceChildState { BdrvChild *child; BdrvChild **childp; BlockDriverState *old_bs; + bool free_empty_child; } BdrvReplaceChildState; =20 static void bdrv_replace_child_commit(void *opaque) { BdrvReplaceChildState *s =3D opaque; =20 + if (s->free_empty_child && !s->child->bs) { + bdrv_child_free(s->child); + } bdrv_unref(s->old_bs); } =20 @@ -2278,22 +2284,26 @@ static void bdrv_replace_child_abort(void *opaque) * modify the BdrvChild * pointer we indirectly pass to it, i.e. it * will not modify s->child. From that perspective, it does not m= atter * whether we pass s->childp or &s->child. - * (TODO: Right now, bdrv_replace_child_noperm() never modifies th= at - * pointer anyway (though it will in the future), so at this point= it - * absolutely does not matter whether we pass s->childp or &s->chi= ld.) * (2) If new_bs is not NULL, s->childp will be NULL. We then cannot = use * it here. * (3) If new_bs is NULL, *s->childp will have been NULLed by * bdrv_replace_child_tran()'s bdrv_replace_child_noperm() call, a= nd we * must not pass a NULL *s->childp here. - * (TODO: In its current state, bdrv_replace_child_noperm() will n= ot - * have NULLed *s->childp, so this does not apply yet. It will in= the - * future.) * * So whether new_bs was NULL or not, we cannot pass s->childp here; a= nd in * any case, there is no reason to pass it anyway. */ - bdrv_replace_child_noperm(&s->child, s->old_bs); + bdrv_replace_child_noperm(&s->child, s->old_bs, true); + /* + * The child was pre-existing, so s->old_bs must be non-NULL, and + * s->child thus must not have been freed + */ + assert(s->child !=3D NULL); + if (!new_bs) { + /* As described above, *s->childp was cleared, so restore it */ + assert(s->childp !=3D NULL); + *s->childp =3D s->child; + } bdrv_unref(new_bs); } =20 @@ -2310,30 +2320,44 @@ static TransactionActionDrv bdrv_replace_child_drv = =3D { * * The function doesn't update permissions, caller is responsible for this. * + * (*childp)->bs must not be NULL. + * * Note that if new_bs =3D=3D NULL, @childp is stored in a state object at= tached * to @tran, so that the old child can be reinstated in the abort handler. * Therefore, if @new_bs can be NULL, @childp must stay valid until the * transaction is committed or aborted. * - * (TODO: The reinstating does not happen yet, but it will once - * bdrv_replace_child_noperm() NULLs *childp when new_bs is NULL.) + * If @free_empty_child is true and @new_bs is NULL, the BdrvChild is + * freed (on commit). @free_empty_child should only be false if the + * caller will free the BDrvChild themselves (which may be important + * if this is in turn called in another transactional context). */ static void bdrv_replace_child_tran(BdrvChild **childp, BlockDriverState *new_bs, - Transaction *tran) + Transaction *tran, + bool free_empty_child) { BdrvReplaceChildState *s =3D g_new(BdrvReplaceChildState, 1); *s =3D (BdrvReplaceChildState) { .child =3D *childp, .childp =3D new_bs =3D=3D NULL ? childp : NULL, .old_bs =3D (*childp)->bs, + .free_empty_child =3D free_empty_child, }; tran_add(tran, &bdrv_replace_child_drv, s); =20 + /* The abort handler relies on this */ + assert(s->old_bs !=3D NULL); + if (new_bs) { bdrv_ref(new_bs); } - bdrv_replace_child_noperm(childp, new_bs); + /* + * Pass free_empty_child=3Dfalse, we will free the child (if + * necessary) in bdrv_replace_child_commit() (if our + * @free_empty_child parameter was true). + */ + bdrv_replace_child_noperm(childp, new_bs, false); /* old_bs reference is transparently moved from *childp to @s */ } =20 @@ -2705,8 +2729,22 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission = qapi_perm) return permissions[qapi_perm]; } =20 +/** + * Replace (*childp)->bs by @new_bs. + * + * If @new_bs is NULL, *childp will be set to NULL, too: BDS parents + * generally cannot handle a BdrvChild with .bs =3D=3D NULL, so clearing + * BdrvChild.bs should generally immediately be followed by the + * BdrvChild pointer being cleared as well. + * + * If @free_empty_child is true and @new_bs is NULL, the BdrvChild is + * freed. @free_empty_child should only be false if the caller will + * free the BdrvChild themselves (this may be important in a + * transactional context, where it may only be freed on commit). + */ static void bdrv_replace_child_noperm(BdrvChild **childp, - BlockDriverState *new_bs) + BlockDriverState *new_bs, + bool free_empty_child) { BdrvChild *child =3D *childp; BlockDriverState *old_bs =3D child->bs; @@ -2743,6 +2781,9 @@ static void bdrv_replace_child_noperm(BdrvChild **chi= ldp, } =20 child->bs =3D new_bs; + if (!new_bs) { + *childp =3D NULL; + } =20 if (new_bs) { QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); @@ -2772,6 +2813,10 @@ static void bdrv_replace_child_noperm(BdrvChild **ch= ildp, bdrv_parent_drained_end_single(child); drain_saldo++; } + + if (free_empty_child && !child->bs) { + bdrv_child_free(child); + } } =20 /** @@ -2801,7 +2846,14 @@ static void bdrv_attach_child_common_abort(void *opa= que) BdrvChild *child =3D *s->child; BlockDriverState *bs =3D child->bs; =20 - bdrv_replace_child_noperm(s->child, NULL); + /* + * Pass free_empty_child=3Dfalse, because we still need the child + * for the AioContext operations on the parent below; those + * BdrvChildClass methods all work on a BdrvChild object, so we + * need to keep it as an empty shell (after this function, it will + * not be attached to any parent, and it will not have a .bs). + */ + bdrv_replace_child_noperm(s->child, NULL, false); =20 if (bdrv_get_aio_context(bs) !=3D s->old_child_ctx) { bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); @@ -2823,7 +2875,6 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) =20 bdrv_unref(bs); bdrv_child_free(child); - *s->child =3D NULL; } =20 static TransactionActionDrv bdrv_attach_child_common_drv =3D { @@ -2901,7 +2952,9 @@ static int bdrv_attach_child_common(BlockDriverState = *child_bs, } =20 bdrv_ref(child_bs); - bdrv_replace_child_noperm(&new_child, child_bs); + bdrv_replace_child_noperm(&new_child, child_bs, true); + /* child_bs was non-NULL, so new_child must not have been freed */ + assert(new_child !=3D NULL); =20 *child =3D new_child; =20 @@ -2960,8 +3013,7 @@ static void bdrv_detach_child(BdrvChild **childp) { BlockDriverState *old_bs =3D (*childp)->bs; =20 - bdrv_replace_child_noperm(childp, NULL); - bdrv_child_free(*childp); + bdrv_replace_child_noperm(childp, NULL, true); =20 if (old_bs) { /* @@ -4951,7 +5003,11 @@ static void bdrv_remove_file_or_backing_child(BlockD= riverState *bs, } =20 if (child->bs) { - bdrv_replace_child_tran(childp, NULL, tran); + /* + * Pass free_empty_child=3Dfalse, we will free the child in + * bdrv_remove_filter_or_cow_child_commit() + */ + bdrv_replace_child_tran(childp, NULL, tran, false); } =20 s =3D g_new(BdrvRemoveFilterOrCowChild, 1); @@ -4961,8 +5017,6 @@ static void bdrv_remove_file_or_backing_child(BlockDr= iverState *bs, .is_backing =3D (childp =3D=3D &bs->backing), }; tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); - - *childp =3D NULL; } =20 /* @@ -5005,7 +5059,7 @@ static int bdrv_replace_node_noperm(BlockDriverState = *from, * Passing a pointer to the local variable @c is fine here, because * @to is not NULL, and so &c will not be attached to the transact= ion. */ - bdrv_replace_child_tran(&c, to, tran); + bdrv_replace_child_tran(&c, to, tran, true); } =20 return 0; @@ -5161,7 +5215,9 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriv= erState *new_bs, bdrv_drained_begin(old_bs); bdrv_drained_begin(new_bs); =20 - bdrv_replace_child_tran(&child, new_bs, tran); + bdrv_replace_child_tran(&child, new_bs, tran, true); + /* @new_bs must have been non-NULL, so @child must not have been freed= */ + assert(child !=3D NULL); =20 found =3D g_hash_table_new(NULL, NULL); refresh_list =3D bdrv_topological_dfs(refresh_list, found, old_bs); --=20 2.33.1 From nobody Sun May 19 17:42:33 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636633017391564.4239715659247; Thu, 11 Nov 2021 04:16:57 -0800 (PST) Received: from localhost ([::1]:34990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml90i-0006R7-Ce for importer@patchew.org; Thu, 11 Nov 2021 07:16:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8tG-0000T2-K1 for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml8tE-0003A4-NZ for qemu-devel@nongnu.org; Thu, 11 Nov 2021 07:09:14 -0500 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-332-ksdD1x2XN8O9tQiebYt8IA-1; Thu, 11 Nov 2021 07:09:09 -0500 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 2247E1017968; Thu, 11 Nov 2021 12:09:07 +0000 (UTC) Received: from localhost (unknown [10.39.193.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB5AC19C59; Thu, 11 Nov 2021 12:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636632552; 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=shVN2QICfYZ2g0c6Fg0kFCLqBxPQx2O4ZEwnCnj642E=; b=HCcQ6xgQ8dn3o9t7ruEKwWnKeaxvDK2tMmDVyq87lQk2jY22V6TeSnKb2RsUejjr3v6yf3 93HBBbdUmn+obiOpS3BmCbqoa5TOwggC39rfBmDRfaTVqMmBhlTGpa44jeJp70ujzJ3zas aLx/IM0NYowHfv8BRN1xLz4LcQmEEB4= X-MC-Unique: ksdD1x2XN8O9tQiebYt8IA-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 10/10] iotests/030: Unthrottle parallel jobs in reverse Date: Thu, 11 Nov 2021 13:08:29 +0100 Message-Id: <20211111120829.81329-11-hreitz@redhat.com> In-Reply-To: <20211111120829.81329-1-hreitz@redhat.com> References: <20211111120829.81329-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, 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_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-devel@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-ZM-MESSAGEID: 1636633019486100001 Content-Type: text/plain; charset="utf-8" See the comment for why this is necessary. Signed-off-by: Hanna Reitz --- tests/qemu-iotests/030 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 index 5fb65b4bef..567bf1da67 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -251,7 +251,16 @@ class TestParallelOps(iotests.QMPTestCase): speed=3D1024) self.assert_qmp(result, 'return', {}) =20 - for job in pending_jobs: + # Do this in reverse: After unthrottling them, some jobs may finish + # before we have unthrottled all of them. This will drain their + # subgraph, and this will make jobs above them advance (despite th= ose + # jobs on top being throttled). In the worst case, all jobs below= the + # top one are finished before we can unthrottle it, and this makes= it + # advance so far that it completes before we can unthrottle it - w= hich + # results in an error. + # Starting from the top (i.e. in reverse) does not have this probl= em: + # When a job finishes, the ones below it are not advanced. + for job in reversed(pending_jobs): result =3D self.vm.qmp('block-job-set-speed', device=3Djob, sp= eed=3D0) self.assert_qmp(result, 'return', {}) =20 --=20 2.33.1