From nobody Wed Nov 5 18:43:18 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 153598589933198.45588756546783; Mon, 3 Sep 2018 07:44:59 -0700 (PDT) Received: from localhost ([::1]:45445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwq66-00075V-EL for importer@patchew.org; Mon, 03 Sep 2018 10:44:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36709) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwpwh-0004G9-TZ for qemu-devel@nongnu.org; Mon, 03 Sep 2018 10:35:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwpwc-0000Yq-LT for qemu-devel@nongnu.org; Mon, 03 Sep 2018 10:35:15 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:38280) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fwpwc-0000PT-0O; Mon, 03 Sep 2018 10:35:10 -0400 Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fwpw0-0007hF-2M; Mon, 03 Sep 2018 16:34:32 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fwpvk-0002yu-29; Mon, 03 Sep 2018 17:34:16 +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=b4tl5sm/MeQL1Sa4ylfMfaQWKZX4fP88dvTHhUlGAII=; b=efmrs06jyNxv9PDXcd5c6DoFlTtlPQqD6CqGH/ALqR9aNN+xsvzDkGIyHriqhi2ri6pFn8uXE0pVBQM3SdkXMJA7IxiSNoQHfFKAVjpqbfeE56kSRRWGD9MgKopPz3pu+EHumGs9+2UG2i9qdw2CSCqTxflROAZXOidW0XVTlRIwy0SCrKfepuwytG7NuQorA5DXHx8kmtRbyqfTe5tvy724mptihtrQC6y3gz1DHvbjv+SzLDAtoK90NTSfcesolw0AqffV1TpqYpxxPRew1skC1J/kv+o933f+jLgisO4LTHh22nGEeJDnEDPE+dZx5BhzZp95YWgodHZsUFCgdg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 3 Sep 2018 17:34:01 +0300 Message-Id: <9d8847a58f91ffafb732e89f6196fe00b7d0ec3f.1535983918.git.berto@igalia.com> 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 v2 03/10] 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: 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" 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 --- block.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 0dbb1fcc7b..c764eb731c 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 @@ -3289,6 +3292,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); @@ -3313,6 +3317,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.11.0