From nobody Wed Nov 5 16:40:51 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 1535293321780188.76342687701037; Sun, 26 Aug 2018 07:22:01 -0700 (PDT) Received: from localhost ([::1]:49279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftvvQ-0000Zw-Is for importer@patchew.org; Sun, 26 Aug 2018 10:21:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftvl9-00082q-Hj for qemu-devel@nongnu.org; Sun, 26 Aug 2018 10:11:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftvl6-0006yk-9d for qemu-devel@nongnu.org; Sun, 26 Aug 2018 10:11:19 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:59593) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ftvl3-0006UB-VZ; Sun, 26 Aug 2018 10:11:16 -0400 Received: from 85-76-74-234-nat.elisa-mobile.fi ([85.76.74.234] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ftvkQ-0004AK-KD; Sun, 26 Aug 2018 16:10:34 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ftvkB-0004mK-5Z; Sun, 26 Aug 2018 17:10:19 +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=23Jz5rbWf4mqYY6z5uzgX2CqWDXVyzYPl7mwDaCtKO8=; b=ROj83KYph35exD2IV1iemE01fY6yizZvtojm0KYCXtOBEL/XnL1l5/oqn1m4rmJ/ygAo7V3PwP28tnWcNaVT7tLMtWPZ+bauZEppAyvyyzrsSEMUhJ9X/gHOR4r/0IrGHOndLkdTshhOImIaM/pb9o6Z/r6MtenbLIPtN7GdOGVRzUga+Hm/2GWI9mYgdFX8wIZHdKZvH7GJsUCL79TWLvFMSxccMG1QhXfPQpLXas+mDwIz+Vu01xSU8SKOx2DEc+p9L1lQ24BCw/c1VArKZlT8uXmXu4v3+0v+lcf5uQ1aLKi7N1nq7tbgl306esqfVhuqYPmh+Zi9Lln6OFEPiw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Sun, 26 Aug 2018 17:09:34 +0300 Message-Id: <054195c8f83f524ee1f4d117407ac507dd18b0d8.1535291602.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 3/9] 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 --- block.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 0dbb1fcc7b..2f2484965d 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,12 @@ 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 */ + 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