From nobody Sun Apr 13 17:13:35 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538414914002756.5343194293611; Mon, 1 Oct 2018 10:28:34 -0700 (PDT) Received: from localhost ([::1]:39862 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g71zk-0000hl-Js for importer@patchew.org; Mon, 01 Oct 2018 13:28:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g71r2-0002ND-Uh for qemu-devel@nongnu.org; Mon, 01 Oct 2018 13:19:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g71qz-00075L-3J for qemu-devel@nongnu.org; Mon, 01 Oct 2018 13:19:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39440) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g71qk-0006s9-BO; Mon, 01 Oct 2018 13:19:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D54BC81114; Mon, 1 Oct 2018 17:19:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-246.ams2.redhat.com [10.36.116.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF6B978915; Mon, 1 Oct 2018 17:19:09 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 1 Oct 2018 19:18:42 +0200 Message-Id: <20181001171901.11004-5-kwolf@redhat.com> In-Reply-To: <20181001171901.11004-1-kwolf@redhat.com> References: <20181001171901.11004-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 01 Oct 2018 17:19:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/23] block: Remove child references 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: 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alberto Garcia Block drivers allow opening their children using a reference to an existing BlockDriverState. These references remain stored in the 'options' and 'explicit_options' QDicts, but we don't need to keep them once everything is open. What is more important, these values can become wrong if the children change: $ qemu-img create -f qcow2 hd0.qcow2 10M $ qemu-img create -f qcow2 hd1.qcow2 10M $ qemu-img create -f qcow2 hd2.qcow2 10M $ $QEMU -drive if=3Dnone,file=3Dhd0.qcow2,node-name=3Dhd0 \ -drive if=3Dnone,file=3Dhd1.qcow2,node-name=3Dhd1,backing=3Dhd0= \ -drive file=3Dhd2.qcow2,node-name=3Dhd2,backing=3Dhd1 After this hd2 has hd1 as its backing file. Now let's remove it using block_stream: (qemu) block_stream hd2 0 hd0.qcow2 Now hd0 is the backing file of hd2, but hd2's options QDicts still contain backing=3Dhd1. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index c298ca6a19..db71ea5b9a 100644 --- a/block.c +++ b/block.c @@ -2763,12 +2763,15 @@ static BlockDriverState *bdrv_open_inherit(const ch= ar *filename, } } =20 - /* Remove all children options from bs->options and bs->explicit_optio= ns */ + /* Remove all children options and references + * from bs->options and bs->explicit_options */ 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); + qdict_del(bs->explicit_options, child->name); + qdict_del(bs->options, child->name); g_free(child_key_dot); } =20 @@ -3290,6 +3293,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) { BlockDriver *drv; BlockDriverState *bs; + BdrvChild *child; bool old_can_write, new_can_write; =20 assert(reopen_state !=3D NULL); @@ -3314,6 +3318,13 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_stat= e) bs->open_flags =3D reopen_state->flags; bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); =20 + /* Remove child references from bs->options and bs->explicit_options. + * Child options were already removed in bdrv_reopen_queue_child() */ + QLIST_FOREACH(child, &bs->children, next) { + qdict_del(bs->explicit_options, child->name); + qdict_del(bs->options, child->name); + } + bdrv_refresh_limits(bs, NULL); =20 bdrv_set_perm(reopen_state->bs, reopen_state->perm, --=20 2.13.6