From nobody Tue Nov 4 15:16:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530272988259907.1594586174833; Fri, 29 Jun 2018 04:49:48 -0700 (PDT) Received: from localhost ([::1]:41403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYruN-0002eG-EO for importer@patchew.org; Fri, 29 Jun 2018 07:49:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYrjC-0001rn-39 for qemu-devel@nongnu.org; Fri, 29 Jun 2018 07:38:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYriz-0005HK-HF for qemu-devel@nongnu.org; Fri, 29 Jun 2018 07:38:14 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:41367) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYriz-0004S5-3M; Fri, 29 Jun 2018 07:38:01 -0400 Received: from 88-114-101-78.elisa-laajakaista.fi ([88.114.101.78] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fYriN-0006Oc-Qg; Fri, 29 Jun 2018 13:37:23 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fYriA-0008Kc-OV; Fri, 29 Jun 2018 14:37:10 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=0IyCVGbYMU2GySxOG0dMh7VqSurr7zCORbVPBKr/k4A=; b=GsVvzW6sAauVUOn132BTuzss/IAqF6HpTq6Qp0Ith7CB5UtH+a7aApmpChT0cNbDVLN03j6C1Hky3C4snmltYUFMFmpjG+ylKkgQMM3d17tWf9msoW+Uxi+OG9GE0AEpOCIbPql8bRHDvqOi0XDyjfQYqi4bPqsVrUxhDxonHPGT5y6waiR0j50pJ1QGEGaiMJbn30pQRwOSFIY5f/pKTBklPbFxXQ11ft4f2yITfo2JJiQg5zm+iSj1CoWEUYA0Hd+YAkE1lxx5uv87hgDfKzV6jPDOP5nOwENaZEY3zHwmqq6JkDbrzlP3DdDxB+Xjc3IFOaOOAr164Ku7zTjGqQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 29 Jun 2018 14:37:00 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: 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 2/5] block: Remove children options from bs->{options, explicit_options} 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) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When bdrv_open_inherit() opens a BlockDriverState the options QDict can contain options for some of its children, passed in the form of child-name.option=3Dvalue So while each child is opened with that subset of options, those same options remain stored in the parent BDS, leaving (at least) two copies of each one of them ("child-name.option=3Dvalue" in the parent and "option=3Dvalue" in the child). Having the children options stored in the parent is unnecessary and it can easily lead to an inconsistent state: $ qemu-img create -f qcow2 hd0.qcow2 10M $ qemu-img create -f qcow2 -b hd0.qcow2 hd1.qcow2 $ qemu-img create -f qcow2 -b hd1.qcow2 hd2.qcow2 $ $QEMU -drive file=3Dhd2.qcow2,node-name=3Dhd2,backing.node-name=3Dhd1 This opens a chain of images hd0 <- hd1 <- hd2. Now let's remove hd1 using block_stream: (qemu) block_stream hd2 0 hd0.qcow2 After this hd2 contains backing.node-name=3Dhd1, which is no longer correct because hd1 doesn't exist anymore. This patch removes all children options from the parent dictionaries at the end of bdrv_open_inherit() and bdrv_reopen_queue_child(). Signed-off-by: Alberto Garcia --- block.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block.c b/block.c index 1b8147c1b3..5aaed424b9 100644 --- a/block.c +++ b/block.c @@ -2594,6 +2594,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, BlockBackend *file =3D NULL; BlockDriverState *bs; BlockDriver *drv =3D NULL; + BdrvChild *child; const char *drvname; const char *backing; Error *local_err =3D NULL; @@ -2777,6 +2778,15 @@ static BlockDriverState *bdrv_open_inherit(const cha= r *filename, } } =20 + /* Remove all children options from bs->options and bs->explicit_optio= ns */ + QLIST_FOREACH(child, &bs->children, next) { + char *child_key_dot; + child_key_dot =3D g_strdup_printf("%s.", child->name); + qdict_extract_subqdict(bs->explicit_options, NULL, child_key_dot); + qdict_extract_subqdict(bs->options, NULL, child_key_dot); + g_free(child_key_dot); + } + bdrv_refresh_filename(bs); =20 /* Check if any unknown options were used */ @@ -2986,6 +2996,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, } =20 child_key_dot =3D g_strdup_printf("%s.", child->name); + qdict_extract_subqdict(explicit_options, NULL, child_key_dot); qdict_extract_subqdict(options, &new_child_options, child_key_dot); g_free(child_key_dot); =20 --=20 2.11.0