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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535985458889427.6276985133637; Mon, 3 Sep 2018 07:37:38 -0700 (PDT) Received: from localhost ([::1]:45390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwpyy-0005Yc-22 for importer@patchew.org; Mon, 03 Sep 2018 10:37:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwpwh-0004G0-RZ 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-0000Yc-Jr for qemu-devel@nongnu.org; Mon, 03 Sep 2018 10:35:15 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:38249) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fwpwc-0000ON-0M; 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 1fwpvz-0007ga-OM; Mon, 03 Sep 2018 16:34:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fwpvk-0002z1-65; 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=9e3t7PHRkgopkn7YdjRNbgC6V0aRnMZDdJkCr6bYUiY=; b=li1qqwKv0j/0TaRAg8iU2uTPEpQ3BqBd4V3NlDT8xfP+j7V2L59BDMfae6TT+fnKdHDS+72xYPAv0E/IYj/K1gcAt2taZDXy0ypcc3fHzAIvLUBejcTkc8NhThCfbruJBhYEFsbYQKK+sqJTB25D5+Z0HYOJL5fKZtHXDjkrKbpouECKTbK5KVxQ/OWAjSnCktFx382joFuXFmCO88QJ1AnrfBkPcyElsWenizeyBm0aZT6FAu+/yUW1Q9ofgidghl+I6YEhq49wHYPQlW95Q0vfL4FkeNbdIISAuu+vEXvgtjrChPfbX/3ORKfPIjrcEdHhW1APsdPqZQYZPT2pMw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 3 Sep 2018 17:34:04 +0300 Message-Id: <293e7df1bffd17584b6e36d11efb097ea48cd214.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 06/10] block: Forbid trying to change unsupported options during reopen 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" The bdrv_reopen_prepare() function checks all options passed to each BlockDriverState (in the reopen_state->options QDict) and makes all necessary preparations to apply the option changes requested by the user. Options are removed from the QDict as they are processed, so at the end of bdrv_reopen_prepare() only the options that can't be changed are left. Then a loop goes over all remaining options and verifies that the old and new values are identical, returning an error if they're not. The problem is that at the moment there are options that are removed from the QDict although they can't be changed. The consequence of this is any modification to any of those options is silently ignored: (qemu) qemu-io virtio0 "reopen -o discard=3Don" This happens when all options from bdrv_runtime_opts are removed from the QDict but then only a few of them are processed. Since it's especially important that "node-name" and "driver" are not changed, the code puts them back into the QDict so they are checked at the end of the function. Instead of putting only those two options back into the QDict, this patch puts all unprocessed options using qemu_opts_to_qdict(). update_flags_from_options() also needs to be modified to prevent BDRV_OPT_CACHE_NO_FLUSH, BDRV_OPT_CACHE_DIRECT and BDRV_OPT_READ_ONLY from going back to the QDict. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 5223d16f1b..1c0f72454a 100644 --- a/block.c +++ b/block.c @@ -1094,19 +1094,19 @@ static void update_flags_from_options(int *flags, Q= emuOpts *opts) *flags &=3D ~BDRV_O_CACHE_MASK; =20 assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH)); - if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { + if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { *flags |=3D BDRV_O_NO_FLUSH; } =20 assert(qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT)); - if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_DIRECT, false)) { + if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_DIRECT, false)) { *flags |=3D BDRV_O_NOCACHE; } =20 *flags &=3D ~BDRV_O_RDWR; =20 assert(qemu_opt_find(opts, BDRV_OPT_READ_ONLY)); - if (!qemu_opt_get_bool(opts, BDRV_OPT_READ_ONLY, false)) { + if (!qemu_opt_get_bool_del(opts, BDRV_OPT_READ_ONLY, false)) { *flags |=3D BDRV_O_RDWR; } =20 @@ -3155,7 +3155,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state= , BlockReopenQueue *queue, BlockDriver *drv; QemuOpts *opts; QDict *orig_reopen_opts; - const char *value; bool read_only; =20 assert(reopen_state !=3D NULL); @@ -3178,17 +3177,10 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_sta= te, BlockReopenQueue *queue, =20 update_flags_from_options(&reopen_state->flags, opts); =20 - /* node-name and driver must be unchanged. Put them back into the QDic= t, so - * that they are checked at the end of this function. */ - value =3D qemu_opt_get(opts, "node-name"); - if (value) { - qdict_put_str(reopen_state->options, "node-name", value); - } - - value =3D qemu_opt_get(opts, "driver"); - if (value) { - qdict_put_str(reopen_state->options, "driver", value); - } + /* All other options (including node-name and driver) must be unchange= d. + * Put them back into the QDict, so that they are checked at the end + * of this function. */ + qemu_opts_to_qdict(opts, reopen_state->options); =20 /* If we are to stay read-only, do not allow permission change * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RD= WR is --=20 2.11.0