From nobody Sun Nov 9 21:12:56 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 1551896064842108.56030766912443; Wed, 6 Mar 2019 10:14:24 -0800 (PST) Received: from localhost ([127.0.0.1]:37173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1b3c-0005Tx-IF for importer@patchew.org; Wed, 06 Mar 2019 13:14:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1b1e-0004D8-Aw for qemu-devel@nongnu.org; Wed, 06 Mar 2019 13:12:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1b1a-0005sz-Vi for qemu-devel@nongnu.org; Wed, 06 Mar 2019 13:12:17 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:59322) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1b1W-0005g7-Dc; Wed, 06 Mar 2019 13:12:12 -0500 Received: from 87-92-21-153.bb.dnainternet.fi ([87.92.21.153] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1h1b10-0004qx-Ih; Wed, 06 Mar 2019 19:11:38 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1h1b0m-0005OS-6Z; Wed, 06 Mar 2019 20:11:24 +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=ZUjL0LOQuBnv5ZRQhyp3CnUl2kwQ8rudiTyz93taLEI=; b=K03/GUOch7/g3x1tXZgY6KNRd5FEZzQTUsvuUrNnCG4Oy2itUNezLi2J4aAtYOozBiBLjyG86r49VALwW24am08ARgTStMTNW+SEIH33CdqgraEgk0UgRDKurggorTk3ypumGMczJY56tK5SuTXAHdv0yEGm9f72uGh5C0YIj2o/Tbho+kpS0Id3Jdj04H54aF/5v1tn52oKGU46qk3VRhkXraNDLO+UwMlsivAaDB/6xQgT2c5hGoxlKPHOFmDqRGcaj2Fr+ajpjKE88tAUxIhMCYLNkj0iRYGtWpNQnH0z8ZGwfEBP//RiTpx5Gmpg/zwl0k/DqzwSWLYwZcGIEw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 20:11:05 +0200 Message-Id: <9f901b066150df5e4f6afc2d07713bf2efdc8b99.1551895814.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 05/13] block: Add 'keep_old_opts' parameter to bdrv_reopen_queue() 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" The bdrv_reopen_queue() function is used to create a queue with the BDSs that are going to be reopened and their new options. Once the queue is ready bdrv_reopen_multiple() is called to perform the operation. The original options from each one of the BDSs are kept, with the new options passed to bdrv_reopen_queue() applied on top of them. For "x-blockdev-reopen" we want a function that behaves much like "blockdev-add". We want to ignore the previous set of options so that only the ones actually specified by the user are applied, with the rest having their default values. One of the things that we need is a way to tell bdrv_reopen_queue() whether we want to keep the old set of options or not, and that's what this patch does. All current callers are setting this new parameter to true and x-blockdev-reopen will set it to false. Signed-off-by: Alberto Garcia --- block.c | 34 +++++++++++++++++++--------------- block/replication.c | 4 ++-- include/block/block.h | 3 ++- qemu-io-cmds.c | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index 6e9c72f0cd..e9ca49fb8e 100644 --- a/block.c +++ b/block.c @@ -3011,7 +3011,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, QDict *options, const BdrvChildRole *role, QDict *parent_options, - int parent_flags) + int parent_flags, + bool keep_old_opts) { assert(bs !=3D NULL); =20 @@ -3051,13 +3052,13 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, */ =20 /* Old explicitly set values (don't overwrite by inherited value) */ - if (bs_entry) { - old_options =3D qdict_clone_shallow(bs_entry->state.explicit_optio= ns); - } else { - old_options =3D qdict_clone_shallow(bs->explicit_options); + if (bs_entry || keep_old_opts) { + old_options =3D qdict_clone_shallow(bs_entry ? + bs_entry->state.explicit_options= : + bs->explicit_options); + bdrv_join_options(bs, options, old_options); + qobject_unref(old_options); } - bdrv_join_options(bs, options, old_options); - qobject_unref(old_options); =20 explicit_options =3D qdict_clone_shallow(options); =20 @@ -3069,10 +3070,12 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, flags =3D bdrv_get_flags(bs); } =20 - /* Old values are used for options that aren't set yet */ - old_options =3D qdict_clone_shallow(bs->options); - bdrv_join_options(bs, options, old_options); - qobject_unref(old_options); + if (keep_old_opts) { + /* Old values are used for options that aren't set yet */ + old_options =3D qdict_clone_shallow(bs->options); + bdrv_join_options(bs, options, old_options); + qobject_unref(old_options); + } =20 /* We have the final set of options so let's update the flags */ options_copy =3D qdict_clone_shallow(options); @@ -3122,7 +3125,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, g_free(child_key_dot); =20 bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, - child->role, options, flags); + child->role, options, flags, keep_old_opts= ); } =20 return bs_queue; @@ -3130,9 +3133,10 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, =20 BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, - QDict *options) + QDict *options, bool keep_old_opts) { - return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0); + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0, + keep_old_opts); } =20 /* @@ -3204,7 +3208,7 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, b= ool read_only, qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only); =20 bdrv_subtree_drained_begin(bs); - queue =3D bdrv_reopen_queue(NULL, bs, opts); + queue =3D bdrv_reopen_queue(NULL, bs, opts, true); ret =3D bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, errp); bdrv_subtree_drained_end(bs); =20 diff --git a/block/replication.c b/block/replication.c index 4c80b54daf..a2f3590310 100644 --- a/block/replication.c +++ b/block/replication.c @@ -374,14 +374,14 @@ static void reopen_backing_file(BlockDriverState *bs,= bool writable, QDict *opts =3D qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->hidden_disk->b= s, - opts); + opts, true); } =20 if (s->orig_secondary_read_only) { QDict *opts =3D qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->secondary_disk= ->bs, - opts); + opts, true); } =20 if (reopen_queue) { diff --git a/include/block/block.h b/include/block/block.h index e4a25674b1..d36a3a3977 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -299,7 +299,8 @@ BlockDriverState *bdrv_open(const char *filename, const= char *reference, BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_= name, int flags, Error **errp); BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, - BlockDriverState *bs, QDict *options); + BlockDriverState *bs, QDict *options, + bool keep_old_opts); int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Erro= r **errp); int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index b9f189f09b..ff9a5cd80f 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2080,7 +2080,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) } =20 bdrv_subtree_drained_begin(bs); - brq =3D bdrv_reopen_queue(NULL, bs, opts); + brq =3D bdrv_reopen_queue(NULL, bs, opts, true); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); bdrv_subtree_drained_end(bs); =20 --=20 2.11.0