From nobody Sat Apr 12 07:45:30 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=1636988187; cv=none; d=zohomail.com; s=zohoarc; b=MsHfkWonTr0TYTqDLqcJKejQsftdYNUspO8kg+sztD+ZIM4OEBoYOOaLlq4RhLuCl979Cp+wJ50F2ozrB7EIrVTGyjiH1yHMeBgotg4LrUkSpY73heFyir1lGxH87kT+RdO7TmyiZVHAP+2hFFeavJcUA35FwgaEAb9Y0LtJg28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988187; 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=xpxC+2IJsYUvPEa/2qZDF6B1VbMTSoDQpd6XxDZfkxI=; b=gEkT+Qil1RbbHYDYMpgzTDVSuP1BqT/MbT+qLjbgtxyZ1BbwhjG7ipq21VnWcOw45XNnNtlXHIDGTx2Mbt630nv3sZ++y+lJ3jEY+TIBliWQqjI5EyiJldVk9HUKFrWbFLvJ+yKAWmCskcyK+pjn9PndIbSJhli7rkl1NrIyfuM= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988187295485.0192489623847; Mon, 15 Nov 2021 06:56:27 -0800 (PST) Received: from localhost ([::1]:50976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdPG-0006CN-6R for importer@patchew.org; Mon, 15 Nov 2021 09:56:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNG-0003A5-Vv for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27822) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNF-0007lK-68 for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:22 -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-211-tfd95u-yPOGRgUJyH33wng-1; Mon, 15 Nov 2021 09:54:17 -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 ED7721015DC9; Mon, 15 Nov 2021 14:54:15 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA25C19D9F; Mon, 15 Nov 2021 14:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988060; 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=xpxC+2IJsYUvPEa/2qZDF6B1VbMTSoDQpd6XxDZfkxI=; b=UBXO0K/+jwVUPfqef823BVKvCo+oNic+PIrlqkcYKy/bDtRT08oFV48FWAmEN5ETg7CN+a /8BXyNek/yVyMeBiqh9fKdTgr3jl4id4dlBYMj2NC2hVBIhcsw4SBMsVTRW+9Q7PpgC89f ZDIyJOfpHilvD01fZAlnYkvunPOyubg= X-MC-Unique: tfd95u-yPOGRgUJyH33wng-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 01/13] stream: Traverse graph after modification Date: Mon, 15 Nov 2021 15:53:57 +0100 Message-Id: <20211115145409.176785-2-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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=170.10.129.124; envelope-from=kwolf@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: 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) X-ZM-MESSAGEID: 1636988188539100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-2-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988190; cv=none; d=zohomail.com; s=zohoarc; b=cJmBZeGX6NJqwRilz/TL1dlmsVIw1uMDQO950y1PWOCdllu/HY8O0zyi8DPU+ObybMyAaT8D5e9S0+3/2a+EjdtYOblnf9deIsLsQGqdbDMo6Y2Q61g3yghQ0lztV1kpYX6n4rTY00eJXbnBLa4l6Bq4p+UxuPvySGKjgAbJaJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988190; 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=UJIOMpkoMCyUOvXH6b7KDq036JHK6Rb+aczp6JsS9iA=; b=Hm6IKeDZL9z1+ioU/abj15wcpYGcgYXIeDziNI4xAd6h9Yegy5PV57kX1ZZ2KWcgoKqPL3pI9VxSirCXnYIRwJ3scTor4aS8FMufPFAmwIAOXQKF/r8MSjeQjBmI8AxiluSi3gH8SiRZewToy8VUAhIeo0a2VDU5hNubDZ8JAHM= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988190939758.06967104611; Mon, 15 Nov 2021 06:56:30 -0800 (PST) Received: from localhost ([::1]:51240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdPJ-0006Mt-VO for importer@patchew.org; Mon, 15 Nov 2021 09:56:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNK-0003KC-45 for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20200) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNG-0007mD-TE for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:25 -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-344-xTajZJKEOFSAFkSLrORVCg-1; Mon, 15 Nov 2021 09:54:18 -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 4068D19057A0; Mon, 15 Nov 2021 14:54:17 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43B9019D9F; Mon, 15 Nov 2021 14:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988062; 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=UJIOMpkoMCyUOvXH6b7KDq036JHK6Rb+aczp6JsS9iA=; b=dX/1EkIKj4P0pa1IiG61QqgJTu3oZpRg3lYpUb3I4rykofTBek9FJagUXbtEdumfPB3JtP 6WE0E3EwGe5msCRm9E8YLjYmEnzKj0o+neuaJxrxmZet4sGSIa4JKM3df2RgLui5MWaFUG 6EYwBfKpJetsR/KB7EwS+smHor/cWS0= X-MC-Unique: xTajZJKEOFSAFkSLrORVCg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 02/13] block: Manipulate children list in .attach/.detach Date: Mon, 15 Nov 2021 15:53:58 +0100 Message-Id: <20211115145409.176785-3-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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=170.10.133.124; envelope-from=kwolf@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: 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) X-ZM-MESSAGEID: 1636988192013100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-3-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988356; cv=none; d=zohomail.com; s=zohoarc; b=TNXiFiTkP5mrzgyBLD6KRA1eygQyLKAsn7TxGN+dmvI5+jZhvYSyHOiTjGx2W9Bvp5W8JgXBN7xrhm+YFTGLODEC0uA1lo/i+EcCKvJ1irPU2y+3tIneKA1yjN38wceeENUzXWk9O39Tq9diieNOXQjLXm6gF4RNQn+xPoe8i5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988356; 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=bz96UtPE3myvzdapdLmAF+2XWx2TRaJMMfM4QfF/ssE=; b=brv4utAZN1yXPayiRVLDvKTEZizXm4mwNVyUZxHWcFixZ7lCe8lpH0Hv/x3/XidmXK5juwnbuf5vK9Ov8T9DZErd+E38aRESwpqI+lO9wCOplna1wtNl/sAnKDLhXUKp1CNOg/cxU+QLrEBkca5yEM/TX5k9uJyViHFzZeM04Ek= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988356075414.18152153703863; Mon, 15 Nov 2021 06:59:16 -0800 (PST) Received: from localhost ([::1]:35486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdRz-0006CP-3e for importer@patchew.org; Mon, 15 Nov 2021 09:59:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNK-0003Lz-Ix for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59843) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNH-0007mX-I3 for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:26 -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-485-6QpJeImnMTW93J6Ny2l2rQ-1; Mon, 15 Nov 2021 09:54:19 -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 871F81015DC9; Mon, 15 Nov 2021 14:54:18 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A49E19D9F; Mon, 15 Nov 2021 14:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988063; 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=bz96UtPE3myvzdapdLmAF+2XWx2TRaJMMfM4QfF/ssE=; b=B9z08kxWh9I5C92bl/sQ8ws/Aeh1dBoaBxC4/s65DV1HAtQXjAOcXYQgH8OLAcOmF1W0Z+ 9RELy+fLQg65Z4reC5qyaO5EE+nPNUcS1k90PyRq5LyesjSdm6hcdJ4ZSW122tHwQI1QuK x/H7ZEhIRs3ONWUu7qwcBM5Tgiffqj0= X-MC-Unique: 6QpJeImnMTW93J6Ny2l2rQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 03/13] block: Unite remove_empty_child and child_free Date: Mon, 15 Nov 2021 15:53:59 +0100 Message-Id: <20211115145409.176785-4-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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: -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: 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) X-ZM-MESSAGEID: 1636988356993100005 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-4-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988306; cv=none; d=zohomail.com; s=zohoarc; b=VafG4VpKrGLSGkQjdyfyqVEzCAPdaWrOT3CXp7uMO7vmzfc7YbxvxtMSFaNo43ymrmz9T84XCVy8HOmKK093YxONmIxZ7huLyZlmO+LM959PaCEAl8/ni0aiN6CSpBL4Pk8lpAfVEyVOOyRlGCnlcxCtJHvL2AOYyUj8kXesQS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988306; 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=Q9i98B6FfifASQ8YRx9sl+umM4N4n2zAtTX381Z51PI=; b=GVAYbTj82V/ThYgk9eEUCaYSKgsRfPr0/wVR7MuN3RCZMlScy4bb4AIpcMw5by08Nj4DLsTOKpKulwlJlqo0Zy18FHE987SIwCTIaW4SQj0HnpRR0Ijl2BG8VQ4aOPV/YKVZ1nymDH5Syt1ttIFErvg0hgew2e1k9js7KxNYnbE= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988306327645.0457882058723; Mon, 15 Nov 2021 06:58:26 -0800 (PST) Received: from localhost ([::1]:59168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdRB-0003CJ-9b for importer@patchew.org; Mon, 15 Nov 2021 09:58:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNJ-0003Hq-HB for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNG-0007m7-OS for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:25 -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-433-MJpWrEZgP6KDfnA3puobuw-1; Mon, 15 Nov 2021 09:54:21 -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 CF28F1015DA4; Mon, 15 Nov 2021 14:54:19 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id D215E19723; Mon, 15 Nov 2021 14:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988062; 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=Q9i98B6FfifASQ8YRx9sl+umM4N4n2zAtTX381Z51PI=; b=MoM+m3ThC9q4EUaDkK5NQt1PIqkM0vgeB14+TEo51OYo6zZjQuUT1Ef73JbyVvhfVcMDdB M5NHtb2F3OnrzjkDA+cchhgEw+uqnP9O2WcVMEAwESyWYR2RIOqOSX8LEacypiWo97jBER i1NuLFuJyxrSRbeNhefGdhZwZ2qHfjI= X-MC-Unique: MJpWrEZgP6KDfnA3puobuw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 04/13] block: Drop detached child from ignore list Date: Mon, 15 Nov 2021 15:54:00 +0100 Message-Id: <20211115145409.176785-5-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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: -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: 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) X-ZM-MESSAGEID: 1636988307199100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-5-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988576; cv=none; d=zohomail.com; s=zohoarc; b=hbFLwjCeitLIBNvKyj5RLofJ6fq8aHEdL/PksYWy15oAcnI/psnVQOxpedrmaXJ7sa4Io4WCdwpAouCCksQdXE2UbWsr3LU+0AboHele1d+mXMy0X/NPbergq6fQanj1hO3buVnmkKmn+VqALG19/Cp2Ie+dMkHJMpHAc5zaLu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988576; 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=ggQ3eMguWrjL2NKp2PRn1t6/2Vnu2ONL17/sv+qyTm4=; b=hK5VPkS3QrqNeMSHAOR/NfCPSP7XkMbDJloL22/dbuWUJqyusQnTqcGO0H0hxm09bEZhQUNZDG2stqcHbBVrPxJcx3Rz5qZ4W5usq+Y6blt5eY/zXOFEF1biBRZBQRpI7j1GxudSN9+2I5qLcb4iDG9BQtXDIHNruOyKwwGZ5eg= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988576303115.97173908506193; Mon, 15 Nov 2021 07:02:56 -0800 (PST) Received: from localhost ([::1]:43384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdVX-0003Az-7P for importer@patchew.org; Mon, 15 Nov 2021 10:02:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNK-0003Mv-TZ for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNI-0007mw-U3 for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:26 -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-1-rid9MesDO_qDn8_dID69zg-1; Mon, 15 Nov 2021 09:54:22 -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 23CC919057A2; Mon, 15 Nov 2021 14:54:21 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2591719D9F; Mon, 15 Nov 2021 14:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988064; 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=ggQ3eMguWrjL2NKp2PRn1t6/2Vnu2ONL17/sv+qyTm4=; b=cefkma2e3mgRIppzsZxI4fKWDmcLHb1iH83mfKNDJNi+TM3w2u1bpPcL5ROkeYMUpHvfaE PrHr/pVmgYcj1Pe2fA3mwHUMEPt7SC/LajQ84/F3KRJKyS4r8NZsjPemRwJxP7/HVcakKX 8P3LegCPBo0gSc5I6RRn6eecgYidegE= X-MC-Unique: rid9MesDO_qDn8_dID69zg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 05/13] block: Pass BdrvChild ** to replace_child_noperm Date: Mon, 15 Nov 2021 15:54:01 +0100 Message-Id: <20211115145409.176785-6-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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=170.10.129.124; envelope-from=kwolf@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: 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) X-ZM-MESSAGEID: 1636988699796100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-6-hreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988733; cv=none; d=zohomail.com; s=zohoarc; b=k0zlBPTCPkvNUJz694B9IB69DP9rR9VmDsfL23qDfG9QmTIN9ZnW+sxptTen45En8tNA1YJt4hoeSp2kVEhPy15OqRsusjv+ISd+tDIDj9K+SKoFZjhiktAKom1si85MItgJtOiOl1vQg+SywIXqWqB7u0scrTq34Ux2DoWzoKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988733; 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=pxiQ+5VQoVocv97B4ROLz32XbzrxQBW1M52T/UdBuBI=; b=Yb3oAB3GHzO0KQkPU2ghNpkamxitgJU9oEZjxCV9Z2Y5jei2jozx0AX7XRjbQ8dhZWEmH/N21jSAQvCzqrb+fRwMOHsON89YYEv+Anmdp6IHBa6NIKEfY3/hN7xePeQAaOosrFefLrXLRwmq9/wU/oXqRPrW39CUN6zgixabk5g= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988733483758.5150097967531; Mon, 15 Nov 2021 07:05:33 -0800 (PST) Received: from localhost ([::1]:51726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdY4-0000HZ-DV for importer@patchew.org; Mon, 15 Nov 2021 10:05:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNQ-0003k5-MS for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58627) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNP-0007p1-4p for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:32 -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-322-Ujgwm5cBOXyOvMpKTSeaQQ-1; Mon, 15 Nov 2021 09:54:23 -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 956C015728; Mon, 15 Nov 2021 14:54:22 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A85E19723; Mon, 15 Nov 2021 14:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988070; 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=pxiQ+5VQoVocv97B4ROLz32XbzrxQBW1M52T/UdBuBI=; b=IJagvL+LLrDdKM4iRed8AiwNPmLox1KyPgBZd0aX0Wp3lOOAuhR2nb+ig0V5p662K2f/xF iHLuDfG/X/xMzPUE34xqccJHXfpAgpb84o07eqhXfv6Zw/W/it+78dUh5Q/TL3d/vOSC6y j0qzS4QXGOoz/I1oXJO+WTtIA5Yia+Q= X-MC-Unique: Ujgwm5cBOXyOvMpKTSeaQQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 06/13] block: Restructure remove_file_or_backing_child() Date: Mon, 15 Nov 2021 15:54:02 +0100 Message-Id: <20211115145409.176785-7-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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=170.10.133.124; envelope-from=kwolf@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: 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) X-ZM-MESSAGEID: 1636988855534100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-7-hreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636989272; cv=none; d=zohomail.com; s=zohoarc; b=TshIoRAPnIviRX4PBNh/mI366cm3ST1xagdr0pGmEinqj3b/cGfiE84f+n4l4JZN2kIO+8O1sBvj8sqDTuN+JFBviXIXiVuPy3lq0zblRhLLxO2r4gX2YfU8JitQoanpaTr3uh5nd0kP460npfYZwoe+9WYocofSMhGQFd5Z6i8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636989272; 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=27m0MYEJxiAG2aHi4wg8yJ/9eridihpe+rS+HS/7iNo=; b=lTXS8/JB5gJc6by/MKKIvLyNYolUSFx+3p6C4qXiOf82saxNS3y/Hh7xvVgRmPj4iWmqy1yS7wMYgY9gLfhilv+DgCqduwqm9fTOcb0FeRTaBtL17yNJO+5aPZYUAqn1QMoaMkMV0yY1d1trVtnVzRiRB0rmNluzaLRBTbnySoo= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636989272883307.53851472912754; Mon, 15 Nov 2021 07:14:32 -0800 (PST) Received: from localhost ([::1]:50318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdgl-0001ep-T5 for importer@patchew.org; Mon, 15 Nov 2021 10:14:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNh-0004Ah-I3 for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:51071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNf-0007tI-9A for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:48 -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-17-UsXdb6DCNgiRVHH3kRfK3A-1; Mon, 15 Nov 2021 09:54:25 -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 DEC931006AAD; Mon, 15 Nov 2021 14:54:23 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB046196F9; Mon, 15 Nov 2021 14:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988086; 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=27m0MYEJxiAG2aHi4wg8yJ/9eridihpe+rS+HS/7iNo=; b=iMk/oLA5fL10OFhxHrV2qriuZ9H70cVxrzeDLjEC9b8w2inWtaBWpC7dU/cDK5J4HLeOLK WKq3/kNiQWDfBwg7titamKsHKG/3IuYba/EDM85Yw2I5ofhPjAU4Rk1UYWRtxmvisbXA0b UE09O75wOyOxwvBo4BUSZ+5Nff/h/lg= X-MC-Unique: UsXdb6DCNgiRVHH3kRfK3A-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 07/13] transactions: Invoke clean() after everything else Date: Mon, 15 Nov 2021 15:54:03 +0100 Message-Id: <20211115145409.176785-8-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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=170.10.129.124; envelope-from=kwolf@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: 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) X-ZM-MESSAGEID: 1636989372999100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-8-hreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988325; cv=none; d=zohomail.com; s=zohoarc; b=cUpChlVxjFu0DogN0PkK7C4xKQ3OKwIr4DRgtnJFdwEV76kPm+avOFrflOpWCb9xso93i46zPJNVso4vYs+rKKLXXnnqIyNsGqaD3Af8UfOOyAuZu9OyG3pllfJt0RtPmzLIgzxNOhWu+eVUdkfCNFweUPhkUWUSm4uzJUp3fLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988325; 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=HZbA7jCkJgVavSq/jrLn/d6y1EMRVC2aA/ZkAdFVjag=; b=O6sAs0WBDdHfHr6PoejcH2q1X3o/Ae+OkRzIQ4Ge/czZ9S9nHDrUw7t/w9i+EyaW46OnQnkh3F7REUxCSiPrsd1+IoILlaYnDkOjEzsp1+c6ejRx1sq+KsjDXn6wDmxLWhOblyxUtjckZSAkIQcKLZ/h+QMa/qc99rYx9twl6XU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988325467286.4133302521882; Mon, 15 Nov 2021 06:58:45 -0800 (PST) Received: from localhost ([::1]:60894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdRU-0004Jj-De for importer@patchew.org; Mon, 15 Nov 2021 09:58:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNQ-0003jl-FJ for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNO-0007oY-FE for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:32 -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-429-aPYI7xw4Oves6dNZgfkUcg-1; Mon, 15 Nov 2021 09:54:26 -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 4E71F15721; Mon, 15 Nov 2021 14:54:25 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33C4819D9F; Mon, 15 Nov 2021 14:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988069; 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=HZbA7jCkJgVavSq/jrLn/d6y1EMRVC2aA/ZkAdFVjag=; b=K4smNN/vIkg0VXTH+eARQX4C6R6XTWDy/4QEEWlh0z0RmDaOf+8M9zyh//V0tobRUoTDnE WYmnVrBhRTRlkkBuvLLiwA6d17DDCIivikT13XD9dYnAfUZJAixQzPXv7i2JIwFfD7QPeU IJDNdRaJ+ALIIUMuWWNSb4zj36I5rCM= X-MC-Unique: aPYI7xw4Oves6dNZgfkUcg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 08/13] block: Let replace_child_tran keep indirect pointer Date: Mon, 15 Nov 2021 15:54:04 +0100 Message-Id: <20211115145409.176785-9-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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: -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: 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) X-ZM-MESSAGEID: 1636988327463100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-9-hreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636989116; cv=none; d=zohomail.com; s=zohoarc; b=LmXeZreCS1Jxw3mt/r5cm+bbgqpeYeKbr0bVZHeDREwABvNhG8HM2Vr/EeRBphdtFljZtxYGBJaVrD0tNJTXonaBUaEPZsmQTKLKtYvOfdrJMErvthefAUhsexp4xwc935TzpM7z6qzMlR54hrGDvRfWZCLT9CDrOMhd5EMjSII= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636989116; 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=Oyo2+ZGhAxvz81ubrhTiLp5hAO6Lgf4yVXNoBd1VkbU=; b=b3BNT5o9nDveh8irbCpaEBpYNHAy5DO9vKJ6PzWlekDOaAc8PEFX936Cy2IUle4YcV4ojOGW5leZ07wkJzrHOCHHQpvHBGcFnhK+gYKCUQz+Kh9ppU0uad+Thmt7bCNrEEytQsmqiMBDd0Ean26YApZlF8YxUbuLBLeWM0FqgQU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636989115989418.7857023663397; Mon, 15 Nov 2021 07:11:55 -0800 (PST) Received: from localhost ([::1]:42506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdeE-0004oB-PK for importer@patchew.org; Mon, 15 Nov 2021 10:11:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNa-00042m-BL for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39807) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNX-0007rg-LH for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:42 -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-562-g1Wa8-sKNKGgxjvN4c1zqg-1; Mon, 15 Nov 2021 09:54:27 -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 78EC01015DBD; Mon, 15 Nov 2021 14:54:26 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7ADFB19723; Mon, 15 Nov 2021 14:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988078; 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=Oyo2+ZGhAxvz81ubrhTiLp5hAO6Lgf4yVXNoBd1VkbU=; b=Sx/pNtU3WczMIj0JSwNmRe+cqYXFEcXoU5vgCIb8BATsmpekQ2q8reFdFNuG//MYy8i1bH QikmxNkglP+49ffcOwbkBZuSFbSUd2DT3vkPkymMFfcBbvJdDKWgF7/o+i3q9khMYgMdPf asEaGZJWHWsjk1cagfl5ZU6LeoZWQHs= X-MC-Unique: g1Wa8-sKNKGgxjvN4c1zqg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 09/13] block: Let replace_child_noperm free children Date: Mon, 15 Nov 2021 15:54:05 +0100 Message-Id: <20211115145409.176785-10-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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=170.10.133.124; envelope-from=kwolf@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: 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) X-ZM-MESSAGEID: 1636989234764100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz 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 Message-Id: <20211111120829.81329-10-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988268; cv=none; d=zohomail.com; s=zohoarc; b=IUEHQ63eKkoocrnzcrrSElKl6jLHjINJ2PzujzCKXEmQ2+C3yMxflchm8YoNGNOCA5FUk04s1Mrt3kruph2qi5vlzaO8hqIgwT8h2tfxajpl8AlAABbvGMyRpD4R+ERiwaS+fS/Lv8Rv9IeOSW2CjsSw2M8PoYvXYzpXTPHDDI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988268; 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=SbGQlYpKcUULcio3TMTlpgBuklIlNQR8vcoKb7irG38=; b=X7RcDiKYyqgo4pkgnro8zDKUMlLzM3iOmSzeW9gnogOMhqzOCbYb+QGVp/jSq2MTAAfCtviL+hc0EB4iCM9NhcYMmb5ipDeq2YYbMEX00v4ZUx0259++eJjRr4+a5avLovyCvsA2u73AiEApZxaWnQOhurOZtRWZkdDh8p4+IRE= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988268815729.4302265578416; Mon, 15 Nov 2021 06:57:48 -0800 (PST) Received: from localhost ([::1]:55496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdQZ-0000ly-Ok for importer@patchew.org; Mon, 15 Nov 2021 09:57:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNY-0003y4-0p for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59357) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNS-0007qf-Lv for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:38 -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-284-2GJ9WrINPDyK9Qd-kbdF4Q-1; Mon, 15 Nov 2021 09:54:28 -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 C3B581006AA1; Mon, 15 Nov 2021 14:54:27 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id C220B19D9F; Mon, 15 Nov 2021 14:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988074; 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=SbGQlYpKcUULcio3TMTlpgBuklIlNQR8vcoKb7irG38=; b=ZGzgfEeiNCDdjgCmoHmy4v0w0dZtklpUJopgVMS7j/xqzhljF/+fpWtAsQ72pOw9L2wHTM vkw0sp0Vd4LOW1uYKTN9GcW9ta92xVf3gXvMdhSyAazk5OaB/HCYgwMdoa+V8IaK1P1+VR /F6rarNZCFcD49LWPRGlQr0g+BHJk7E= X-MC-Unique: 2GJ9WrINPDyK9Qd-kbdF4Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 10/13] iotests/030: Unthrottle parallel jobs in reverse Date: Mon, 15 Nov 2021 15:54:06 +0100 Message-Id: <20211115145409.176785-11-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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=170.10.133.124; envelope-from=kwolf@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: 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) X-ZM-MESSAGEID: 1636988270552100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz See the comment for why this is necessary. Signed-off-by: Hanna Reitz Message-Id: <20211111120829.81329-11-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- 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.31.1 From nobody Sat Apr 12 07:45:30 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=1636988467; cv=none; d=zohomail.com; s=zohoarc; b=VevRj8GkTjpV2Bc7hSkJM+fl5rgGCaTmwKKoXv/fp7OEmVxhzcIX8SDhpRONOSPrmvWE7XmpEKmYLgRYXXyhsJ2vcwGlnEg8la1HZxtLWUrIZwMV4QhVZl/NJup6AyNKVHN58J1NGhXDX3vU+xxL3TOs6lU4CoILfdgKXLTXnKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988467; 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=ax/J0cngJOyzUwkAz5FRH5HkX3+2Mw2inG8TjgLcLX4=; b=Sg6W3ZZYHSiWE7MnTZm+cS1edvA+JLV5SqLEQrzF7mNviOxHvIyyatyN7KzovVqayh6jH1U5vDotF5G6Dcp96vpofIG+vPksMyNm+WhHh+pphGoLHEtaKW3H4mjym6DnJJZUU3H+t4mYRpG41X7f6BLKVJpIr9Smr4OuOnnTgpQ= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988467711593.782492471741; Mon, 15 Nov 2021 07:01:07 -0800 (PST) Received: from localhost ([::1]:40212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdTm-00013E-PJ for importer@patchew.org; Mon, 15 Nov 2021 10:01:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNU-0003rR-M8 for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNS-0007qL-1A for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:35 -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-531-CSE1DePwNGusYLiCbDPX2w-1; Mon, 15 Nov 2021 09:54:30 -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 1478315726; Mon, 15 Nov 2021 14:54:29 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1961C19729; Mon, 15 Nov 2021 14:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988073; 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=ax/J0cngJOyzUwkAz5FRH5HkX3+2Mw2inG8TjgLcLX4=; b=ZfFR/jTf6Az0N6JtUbgRv0ILsIVipt+eVZGCrriEQ9t6MmdUFHAPQiTQOAlUjf2/myPuK8 lTV2l1avJhP13dCDHj0Z2pzs4kfeUvSIA803uEcK1xeGqM5KsB5YXdXzW5o7t9Kv7ZxTXz l3qVrJ1yV/zXfASi4nfgxTfqLkJH3WQ= X-MC-Unique: CSE1DePwNGusYLiCbDPX2w-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 11/13] docs: Deprecate incorrectly typed device_add arguments Date: Mon, 15 Nov 2021 15:54:07 +0100 Message-Id: <20211115145409.176785-12-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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: -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: 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) X-ZM-MESSAGEID: 1636988526253100001 While introducing a non-QemuOpts code path for device creation for JSON -device, we noticed that QMP device_add doesn't check its input correctly (accepting arguments that should have been rejected), and that users may be relying on this behaviour (libvirt did until it was fixed recently). Let's use a deprecation period before we fix this bug in QEMU to avoid nasty surprises for users. Signed-off-by: Kevin Wolf Message-Id: <20211111143530.18985-1-kwolf@redhat.com> Reviewed-by: Markus Armbruster Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Kevin Wolf --- docs/about/deprecated.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 600031210d..c03fcf951f 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -250,6 +250,20 @@ options are removed in favor of using explicit ``block= dev-create`` and ``blockdev-add`` calls. See :doc:`/interop/live-block-operations` for details. =20 +Incorrectly typed ``device_add`` arguments (since 6.2) +'''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Due to shortcomings in the internal implementation of ``device_add``, QEMU +incorrectly accepts certain invalid arguments: Any object or list argument= s are +silently ignored. Other argument types are not checked, but an implicit +conversion happens, so that e.g. string values can be assigned to integer +device properties or vice versa. + +This is a bug in QEMU that will be fixed in the future so that previously +accepted incorrect commands will return an error. Users should make sure t= hat +all arguments passed to ``device_add`` are consistent with the documented +property types. + System accelerators ------------------- =20 --=20 2.31.1 From nobody Sat Apr 12 07:45:30 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=1636988471; cv=none; d=zohomail.com; s=zohoarc; b=JXZWm10+HvRXmI9kXyOOrcwEIgNlO3M/nCYqqNNSrqvpeZfx6Ca10zJk6fFzxABtorIUreRMf5yibzMLdBo3hNOHx+uPkdjsNNKngEUNuG8PxVbsp6CLZ9sUbKs/3D1wzpao1gNGx5KLQMDyLDv3RpVwzWRtrZIDdsvbp8qPb+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636988471; 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=H8GOQNMUrlGtE+pHg4xC8CeyWYhzAWk5yCERQiKGPaE=; b=AAndiL2hW5NAhqSHwdNjdy3tzoiL5oPqFKzN8EqF4Cq33oo36y4z4JROLrfteInlOonSt64MTXdrruKh0lWMMWqxQRLYXeANNG+0YsN8zucr5FfSD13dAU0n1UfRFxdCfA+7NQbJOtKSMaGAhAKYwheQ/uR/5iF8fhv2Mx9cS+U= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988471387425.5218045586407; Mon, 15 Nov 2021 07:01:11 -0800 (PST) Received: from localhost ([::1]:40338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdTq-00018I-9a for importer@patchew.org; Mon, 15 Nov 2021 10:01:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNY-0003zJ-8n for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNU-0007qr-CF for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:40 -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-583-3tI8f65kMpG6AenFzAMKTQ-1; Mon, 15 Nov 2021 09:54:31 -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 6DF36804141; Mon, 15 Nov 2021 14:54:30 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 724B319D9F; Mon, 15 Nov 2021 14:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988075; 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=H8GOQNMUrlGtE+pHg4xC8CeyWYhzAWk5yCERQiKGPaE=; b=EHqEBUuaMwjDHdQLhRzX6/I3+n++izbBte8tjvu7bCYaPpobDNauGTvZPNdDNdP+ZJV3LD RsGihTOSogALjAgfL5r076jlmYlrdOo8/DILBd58vbZA4EIkNHOQ3D92oxoDNvT1Yvr5FF H7GgHW13pxt0zMCOnXTn3/3Zkk7M4DI= X-MC-Unique: 3tI8f65kMpG6AenFzAMKTQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 12/13] file-posix: Fix alignment after reopen changing O_DIRECT Date: Mon, 15 Nov 2021 15:54:08 +0100 Message-Id: <20211115145409.176785-13-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=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: -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: 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) X-ZM-MESSAGEID: 1636988534727100001 Content-Type: text/plain; charset="utf-8" At the end of a reopen, we already call bdrv_refresh_limits(), which should update bs->request_alignment according to the new file descriptor. However, raw_probe_alignment() relies on s->needs_alignment and just uses 1 if it isn't set. We neglected to update this field, so starting with cache=3Dwriteback and then reopening with cache=3Dnone means that we get an incorrect bs->request_alignment =3D=3D 1 and unaligned requests fail instead of being automatically aligned. Fix this by recalculating s->needs_alignment in raw_refresh_limits() before calling raw_probe_alignment(). Signed-off-by: Kevin Wolf Message-Id: <20211104113109.56336-1-kwolf@redhat.com> Reviewed-by: Hanna Reitz Reviewed-by: Stefano Garzarella Signed-off-by: Kevin Wolf --- block/file-posix.c | 20 ++++++++++++++++---- tests/qemu-iotests/142 | 22 ++++++++++++++++++++++ tests/qemu-iotests/142.out | 15 +++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 7a27c83060..b283093e5b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -167,6 +167,7 @@ typedef struct BDRVRawState { int page_cache_inconsistent; /* errno from fdatasync failure */ bool has_fallocate; bool needs_alignment; + bool force_alignment; bool drop_cache; bool check_cache_dropped; struct { @@ -351,6 +352,17 @@ static bool dio_byte_aligned(int fd) return false; } =20 +static bool raw_needs_alignment(BlockDriverState *bs) +{ + BDRVRawState *s =3D bs->opaque; + + if ((bs->open_flags & BDRV_O_NOCACHE) !=3D 0 && !dio_byte_aligned(s->f= d)) { + return true; + } + + return s->force_alignment; +} + /* Check if read is allowed with given memory buffer and length. * * This function is used to check O_DIRECT memory buffer and request align= ment. @@ -728,9 +740,6 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, =20 s->has_discard =3D true; s->has_write_zeroes =3D true; - if ((bs->open_flags & BDRV_O_NOCACHE) !=3D 0 && !dio_byte_aligned(s->f= d)) { - s->needs_alignment =3D true; - } =20 if (fstat(s->fd, &st) < 0) { ret =3D -errno; @@ -784,9 +793,10 @@ static int raw_open_common(BlockDriverState *bs, QDict= *options, * so QEMU makes sure all IO operations on the device are aligned * to sector size, or else FreeBSD will reject them with EINVAL. */ - s->needs_alignment =3D true; + s->force_alignment =3D true; } #endif + s->needs_alignment =3D raw_needs_alignment(bs); =20 #ifdef CONFIG_XFS if (platform_test_xfs_fd(s->fd)) { @@ -1251,7 +1261,9 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) BDRVRawState *s =3D bs->opaque; struct stat st; =20 + s->needs_alignment =3D raw_needs_alignment(bs); raw_probe_alignment(bs, s->fd, errp); + bs->bl.min_mem_alignment =3D s->buf_align; bs->bl.opt_mem_alignment =3D MAX(s->buf_align, qemu_real_host_page_siz= e); =20 diff --git a/tests/qemu-iotests/142 b/tests/qemu-iotests/142 index 69fd10ef51..07003c597a 100755 --- a/tests/qemu-iotests/142 +++ b/tests/qemu-iotests/142 @@ -350,6 +350,28 @@ info block backing-file" =20 echo "$hmp_cmds" | run_qemu -drive "$files","$ids" | grep "Cache" =20 +echo +echo "--- Alignment after changing O_DIRECT ---" +echo + +# Directly test the protocol level: Can unaligned requests succeed even if +# O_DIRECT was only enabled through a reopen and vice versa? + +$QEMU_IO --cache=3Dwriteback -f file $TEST_IMG < (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636988934147623.3087526150297; Mon, 15 Nov 2021 07:08:54 -0800 (PST) Received: from localhost ([::1]:34096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmdbJ-0007YN-7c for importer@patchew.org; Mon, 15 Nov 2021 10:08:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNY-0003yt-6g for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21972) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmdNU-0007r5-MU for qemu-devel@nongnu.org; Mon, 15 Nov 2021 09:54:39 -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-454-NLkjvHzKMqqIU-xogIdbtg-1; Mon, 15 Nov 2021 09:54:32 -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 C600E1006AB6; Mon, 15 Nov 2021 14:54:31 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id B801C19D9F; Mon, 15 Nov 2021 14:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636988076; 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=AOdFReUIemS5m4H/yoW/pvPIxTA1UiLo9iU1PEMmxSM=; b=NZRljWWFBh++CQ9gGITobhQhxmmGfAhZqgaxLum7OEdri040QN05+Jrgnz34R/aWvMjtj1 JzJ79u+UwMhdOrbDNaj1hr4QIPSgDc1NcWhEn2GdmdZ8BQHo6lMezMH6xantJzibU0UJgv ItR1KBTuXpdDxvRC6AUSdRAtp2egZ7M= X-MC-Unique: NLkjvHzKMqqIU-xogIdbtg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 13/13] softmmu/qdev-monitor: fix use-after-free in qdev_set_id() Date: Mon, 15 Nov 2021 15:54:09 +0100 Message-Id: <20211115145409.176785-14-kwolf@redhat.com> In-Reply-To: <20211115145409.176785-1-kwolf@redhat.com> References: <20211115145409.176785-1-kwolf@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=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=kwolf@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: 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) X-ZM-MESSAGEID: 1636989055192100001 From: Stefan Hajnoczi Reported by Coverity (CID 1465222). Fixes: 4a1d937796de0fecd8b22d7dbebf87f38e8282fd ("softmmu/qdev-monitor: add= error handling in qdev_set_id") Cc: Damien Hedde Cc: Kevin Wolf Cc: Michael S. Tsirkin Signed-off-by: Stefan Hajnoczi Message-Id: <20211102163342.31162-1-stefanha@redhat.com> Reviewed-by: Kevin Wolf Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Damien Hedde Reviewed-by: Markus Armbruster Signed-off-by: Kevin Wolf --- softmmu/qdev-monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index b5aaae4b8c..01ec420e61 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -593,8 +593,8 @@ const char *qdev_set_id(DeviceState *dev, char *id, Err= or **errp) if (prop) { dev->id =3D id; } else { - g_free(id); error_setg(errp, "Duplicate device ID '%s'", id); + g_free(id); return NULL; } } else { --=20 2.31.1