From nobody Fri May 17 06:43:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554031188023150.85530488054314; Sun, 31 Mar 2019 04:19:48 -0700 (PDT) Received: from localhost ([127.0.0.1]:57118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAYV6-0000Zd-W0 for importer@patchew.org; Sun, 31 Mar 2019 07:19:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAYU1-0000Ch-Gf for qemu-devel@nongnu.org; Sun, 31 Mar 2019 07:18:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hAYTu-0006Zs-Id for qemu-devel@nongnu.org; Sun, 31 Mar 2019 07:18:34 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56357) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hAYTk-0006Ph-TD; Sun, 31 Mar 2019 07:18:22 -0400 Received: from 87-100-202-60.bb.dnainternet.fi ([87.100.202.60] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1hAYTV-0003LM-Jl; Sun, 31 Mar 2019 13:18:05 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1hAYTG-0003pb-Ny; Sun, 31 Mar 2019 14:17:50 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=L/yOcZmSWDJlyD6wuV0CPSqcB7v3v0AaNoo9uljA7Jc=; b=hH936fAe7fMDUDr4lpPBFfHtuXQmhHe4zqz8ZbeVPAK9LjNif4uRS8insAkvmRuuwAJ9yY1aRKo3ruAv5o/6SdLA1A7/blWKlziHyyad1DD56/6DR6hR13HidBlXZxuW+JBlG3kLbZgMvALJ0+fLNbJZf8JdVFcijs9reQPebYseKf0nk+TL2pdaXIz0xCVGbCldf0rMwXRHfA9vTKmWA4+tffH87SJT1dAs5lh+EoToc97fCkyyANUzC1OA+vWtp4LFvl7pvaiEJ91/8zXU9AdchnyPPwEii0uj6JbdB9jRn224HfdpHkC6w3Q43+4qORt2jPyLp9linsNGRCYVcw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Sun, 31 Mar 2019 14:17:47 +0300 Message-Id: <20190331111747.14685-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH for-4.1] block: Use bdrv_unref_child() for all children in bdrv_close() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_unref_child() does the following things: - Updates the child->bs->inherits_from pointer. - Calls bdrv_detach_child() to remove the BdrvChild from bs->children. - Calls bdrv_unref() to unref the child BlockDriverState. When bdrv_unref_child() was introduced in commit 33a604075c it was not used in bdrv_close() because the drivers that had additional children (like quorum or blkverify) had already called bdrv_unref() on their children during their own close functions. This was changed later (in 0bd6e91a7e for quorum, in 3e586be0b2 for blkverify) so there's no reason not to use bdrv_unref_child() in bdrv_close() anymore. After this there's also no need to remove bs->backing and bs->file separately from the rest of the children, so bdrv_close() can be simplified. Signed-off-by: Alberto Garcia --- block.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 0a93ee9ac8..3b7c12d68e 100644 --- a/block.c +++ b/block.c @@ -3842,22 +3842,12 @@ static void bdrv_close(BlockDriverState *bs) bs->drv =3D NULL; } =20 - bdrv_set_backing_hd(bs, NULL, &error_abort); - - if (bs->file !=3D NULL) { - bdrv_unref_child(bs, bs->file); - bs->file =3D NULL; - } - QLIST_FOREACH_SAFE(child, &bs->children, next, next) { - /* TODO Remove bdrv_unref() from drivers' close function and use - * bdrv_unref_child() here */ - if (child->bs->inherits_from =3D=3D bs) { - child->bs->inherits_from =3D NULL; - } - bdrv_detach_child(child); + bdrv_unref_child(bs, child); } =20 + bs->backing =3D NULL; + bs->file =3D NULL; g_free(bs->opaque); bs->opaque =3D NULL; atomic_set(&bs->copy_on_read, 0); --=20 2.11.0