From nobody Fri Nov 7 12:20:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15477394255714.1541984940221255; Thu, 17 Jan 2019 07:37:05 -0800 (PST) Received: from localhost ([127.0.0.1]:46719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gk9j6-0003UE-Du for importer@patchew.org; Thu, 17 Jan 2019 10:37:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gk9gp-0001tx-9L for qemu-devel@nongnu.org; Thu, 17 Jan 2019 10:34:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gk9gn-0007pE-K5 for qemu-devel@nongnu.org; Thu, 17 Jan 2019 10:34:43 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:59809) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gk9gn-0007Ig-9M; Thu, 17 Jan 2019 10:34:41 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gk9gY-0003bf-FF; Thu, 17 Jan 2019 16:34:26 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gk9gJ-0007RV-2W; Thu, 17 Jan 2019 17:34:11 +0200 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=N6jrAsxIHf3tcbEMYyvP64gHgcujs3gPNA9sPYvRdqQ=; b=QSBdqd80RMJGztymup6uyZg7G8qpJtG5CxbDdPOKvGpJLwNZ9EEtLJxJF6fNO/S3I/2HmKWocE7rHMJxrfy3eVjF/h5+kwxWjcuSbISqR7aAmOlRx/n2DLLpar120Pp2xTixXDa3j3qDkOqoCu6iHhW0PVfOZpv92q+Wbg+HP9RiVgmtJRV7aSEJqxd92g00rOq3u/IeUnOUqSn2Ab6KM3Vo8rabWb/k/FbdoTmddBdDQJEHzoKawkHXURcl7gnYMNQ5xHNWKIeTZUOo28RSPpN+Omr/1KCL9li9kTJ0EicjTUvgvT4gCTAnFKNJvg5jEBuFZrb/KukVqYpczT5+Lg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 17 Jan 2019 17:34:01 +0200 Message-Id: <5ab350fa5bd78747f4162b294e46ef125243b66c.1547739122.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 10/13] block: Add bdrv_reset_options_allowed() 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) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_reopen_prepare() receives a BDRVReopenState with (among other things) a new set of options to be applied to that BlockDriverState. If an option is missing then it means that we want to reset it to its default value rather than keep the previous one. This way the state of the block device after being reopened is comparable to that of a device added with "blockdev-add" using the same set of options. Not all options from all drivers can be changed this way, however. If the user attempts to reset an immutable option to its default value using this method then we must forbid it. This new function takes a QemuOptsList with the options of a block driver and checks if there's any that was previously set but is missing from the new set of options in the BDRVReopenState. If the option is present in both sets we don't need to check that they have the same value. The loop at the end of bdrv_reopen_prepare() already takes care of that. Signed-off-by: Alberto Garcia --- block.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/block.c b/block.c index 10847416b2..eea7aefa99 100644 --- a/block.c +++ b/block.c @@ -2909,6 +2909,43 @@ BlockDriverState *bdrv_open(const char *filename, co= nst char *reference, } =20 /* + * For every option in @list, check that if it is set in the current + * set of options (@state->bs->options) then it is also set in the new + * set (@state->options). Options listed in @mutable_opts are skipped. + * + * @mutable_opts is either NULL or a NULL-terminated array of option + * names. + * + * Return 0 on success, -EINVAL otherwise. + */ +static int bdrv_reset_options_allowed(BDRVReopenState *state, + QemuOptsList *list, + const char *const mutable_opts[], + Error **errp) +{ + QemuOptDesc *desc =3D list->desc; + while (desc->name) { + unsigned i; + for (i =3D 0; mutable_opts !=3D NULL && mutable_opts[i] !=3D NULL;= i++) { + if (!strcmp(desc->name, mutable_opts[i])) { + goto next; + } + } + + if (!qdict_haskey(state->options, desc->name) && + qdict_haskey(state->bs->options, desc->name)) { + error_setg(errp, "Option '%s' can't be reset to its default va= lue", + desc->name); + return -EINVAL; + } + next: + desc++; + } + + return 0; +} + +/* * Returns true if @child can be reached recursively from @bs */ static bool bdrv_recurse_has_child(BlockDriverState *bs, @@ -3392,6 +3429,19 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, } =20 if (drv->bdrv_reopen_prepare) { + /* + * If a driver-specific option is missing, it means that we + * should reset it to its default value. + * But not all options allow that, so we need to check it first. + */ + if (drv->runtime_opts) { + ret =3D bdrv_reset_options_allowed(reopen_state, drv->runtime_= opts, + drv->mutable_opts, errp); + if (ret) { + goto error; + } + } + ret =3D drv->bdrv_reopen_prepare(reopen_state, queue, &local_err); if (ret) { if (local_err !=3D NULL) { --=20 2.11.0