From nobody Sat Feb 7 15:12:32 2026 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 1537368935441574.1367768631512; Wed, 19 Sep 2018 07:55:35 -0700 (PDT) Received: from localhost ([::1]:45791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dt7-0005Hg-Lt for importer@patchew.org; Wed, 19 Sep 2018 10:55:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E1-RE for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000JL-NP for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56753) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Et-3V; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003d9-DC; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004TS-Ls; Wed, 19 Sep 2018 17:48:05 +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=16OsZGvx/b+FrR4eLFIl9tSuOH3D6sIsJ5/aD+Y4QgQ=; b=HFsKyayo4Q28uVRviHWQweE/3vpUpSxMgL9KXY2SF1JsC2FuhK/8vUtF8257v17mS8XgovUSRTx5AH8RkghAawRX+6m/1ekIs5SpD4egUX40L5slLsJ7ltvYtry2TO/dmhEPahObFJU2OyS/0xjWyeY9znn2XS+lhknqk9AUxxIrTlloW4vvF22Pa7xld7SB1PimlnCNb0LsoEMTxH1yr+nr0kMHC1jp78yj+y24EMsyZ9i2LcGDwWsQ5aQlVa4YR0SJqwpchEj3I7pmYaQOeGSFO/Byr8Ujs0VKEKSDe4fJCTvjBlnTf+e3FdG14JN7ikbQAskypu55MUeFxZC2RA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:39 +0300 Message-Id: <16ec059666d4e2177ad59b9a85978979a0d45917.1537367701.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 01/14] block: Don't call update_flags_from_options() if the options are wrong 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" If qemu_opts_absorb_qdict() fails and we carry on and call update_flags_from_options() then that can result on a failed assertion: $ qemu-io -c 'reopen -o read-only=3Dfoo' hd.qcow2 block.c:1101: update_flags_from_options: Assertion `qemu_opt_find(opts, = BDRV_OPT_CACHE_DIRECT)' failed. Aborted This only happens in bdrv_reopen_queue_child(). Although this function doesn't return errors, we can simply keep the wrong options in the reopen queue and later bdrv_reopen_prepare() will fail. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 11 +++++++++-- tests/qemu-iotests/133 | 6 ++++++ tests/qemu-iotests/133.out | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 57cc4161a2..d79b6cdc73 100644 --- a/block.c +++ b/block.c @@ -2950,12 +2950,19 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, if (parent_options) { QemuOpts *opts; QDict *options_copy; + Error *local_err =3D NULL; assert(!flags); role->inherit_options(&flags, options, parent_flags, parent_option= s); options_copy =3D qdict_clone_shallow(options); opts =3D qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abor= t); - qemu_opts_absorb_qdict(opts, options_copy, NULL); - update_flags_from_options(&flags, opts); + qemu_opts_absorb_qdict(opts, options_copy, &local_err); + /* Don't call update_flags_from_options() if the options are wrong. + * bdrv_reopen_prepare() will later return an error. */ + if (!local_err) { + update_flags_from_options(&flags, opts); + } else { + error_free(local_err); + } qemu_opts_del(opts); qobject_unref(options_copy); } diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index af6b3e1dd4..b9f17c996f 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -92,6 +92,12 @@ echo IMGOPTSSYNTAX=3Dfalse $QEMU_IO -f null-co -c 'reopen' -c 'info' \ "json:{'driver': 'null-co', 'size': 65536}" =20 +echo +echo "=3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D" +echo + +$QEMU_IO -c 'reopen -o read-only=3Dfoo' $TEST_IMG + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/133.out b/tests/qemu-iotests/133.out index f4a85aeb63..570f623b6b 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -24,4 +24,8 @@ Cannot change the option 'driver' =20 format name: null-co format name: null-co + +=3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D + +Parameter 'read-only' expects 'on' or 'off' *** done --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537368705848168.0948424377474; Wed, 19 Sep 2018 07:51:45 -0700 (PDT) Received: from localhost ([::1]:45770 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dpQ-000269-G7 for importer@patchew.org; Wed, 19 Sep 2018 10:51:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E7-S3 for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000J1-Lv for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56739) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Ek-31; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dB-Ba; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004TU-Mx; Wed, 19 Sep 2018 17:48:05 +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=dm8KSIam4utV+JuF544IWMHNII5Ui7XEObJ3w1xVp4M=; b=FbBfYXn+aNYympFxXHdcb9zsuQtybQU3/exg8kkw8y4fB6tR/2YvrANyV1CkkKnUygAOhkeGaeNlKmHkRyjSgwu2gHW06TDbkgW7l9yGF9GBRularFJhVbcGnm2AT1t0EQhQFHprXXGBT95J/vJyv7/W7dJr5BPYKNflbkPk3zkYhD6X5L+yu4421SaHfry1T2Eno7rbXcOOfHsGBxrrYHSgnNXbF1BaqrFN64jU+OOeisz4i2lUU2P4v37OVsPsgPzuX2vnh0raOFHGV9iMMM2OdGK+GFxFKS/rJ16g9RwwoUX01KkxEIQG0wjFlcYy/wO/UqeOCDFSUgMekMVY9w==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:40 +0300 Message-Id: <23f88429b3135b18abdc8643fb5cc35a6dd5d912.1537367701.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 02/14] block: Add bdrv_reopen_set_read_only() 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" Most callers of bdrv_reopen() only use it to switch a BlockDriverState between read-only and read-write, so this patch adds a new function that does just that. We also want to get rid of the flags parameter in the bdrv_reopen() API, so this function sets the "read-only" option and passes the original flags (which will then be updated in bdrv_reopen_prepare()). Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 17 +++++++++++++++++ include/block/block.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/block.c b/block.c index d79b6cdc73..e023945c8e 100644 --- a/block.c +++ b/block.c @@ -3106,6 +3106,23 @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flags= , Error **errp) return ret; } =20 +int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, + Error **errp) +{ + int ret; + BlockReopenQueue *queue; + QDict *opts =3D qdict_new(); + + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only); + + bdrv_subtree_drained_begin(bs); + queue =3D bdrv_reopen_queue(NULL, bs, opts, bdrv_get_flags(bs)); + ret =3D bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, errp); + bdrv_subtree_drained_end(bs); + + return ret; +} + static BlockReopenQueueEntry *find_parent_in_reopen_queue(BlockReopenQueue= *q, BdrvChild *c) { diff --git a/include/block/block.h b/include/block/block.h index a49a027c54..47ee32512f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -302,6 +302,8 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *b= s_queue, QDict *options, int flags); int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Erro= r **errp); int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp); +int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, + Error **errp); int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp); void bdrv_reopen_commit(BDRVReopenState *reopen_state); --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537368815488357.8075531484146; Wed, 19 Sep 2018 07:53:35 -0700 (PDT) Received: from localhost ([::1]:45779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2drC-0003gp-C0 for importer@patchew.org; Wed, 19 Sep 2018 10:53:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E0-RE for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000If-IJ for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56738) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000El-2A; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dA-D1; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004TW-Nx; Wed, 19 Sep 2018 17:48:05 +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=jKDfe942sZOKm7iwnj3QBQsnspZI1upBNzjT01xPG18=; b=Pm7t/M+8znXYetsndlF0qJmqtkgPxVfGEY9xxmogmy8ZUTpb4FSwkGtqI/OunDFmPzG18IHbT8Pkyzd0AWZ0HhixsIs3aQ4U/6t5mUw+Yj6RPsTtGF1wgn4/Cd9CpBGVXlI+4eE12YIoETJUjC1kCCK6GI3gcEoOw0EjCW2ZkiQKEZz6O+lpU4wpFBFx2hElBkk4vSbF8Wc2zbZIwaMH3v1RVg7zqaOCyxPkXZ3bd0viSipLbQbrdgDkG54PvjXvBcYhiNu8a1iu5A6hx2rADJAf6fwBSEYSlvcVnkyVNuQRtUMn6GwTxtLl5YFUUDeEKwfb1p9bTfI1n7HiygOOLA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:41 +0300 Message-Id: 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 03/14] block: Use bdrv_reopen_set_read_only() in bdrv_backing_update_filename() 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" This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index e023945c8e..ac945b4bc8 100644 --- a/block.c +++ b/block.c @@ -1070,11 +1070,11 @@ static int bdrv_backing_update_filename(BdrvChild *= c, BlockDriverState *base, const char *filename, Error **errp) { BlockDriverState *parent =3D c->opaque; - int orig_flags =3D bdrv_get_flags(parent); + bool read_only =3D bdrv_is_read_only(parent); int ret; =20 - if (!(orig_flags & BDRV_O_RDWR)) { - ret =3D bdrv_reopen(parent, orig_flags | BDRV_O_RDWR, errp); + if (read_only) { + ret =3D bdrv_reopen_set_read_only(parent, false, errp); if (ret < 0) { return ret; } @@ -1086,8 +1086,8 @@ static int bdrv_backing_update_filename(BdrvChild *c,= BlockDriverState *base, error_setg_errno(errp, -ret, "Could not update backing file link"); } =20 - if (!(orig_flags & BDRV_O_RDWR)) { - bdrv_reopen(parent, orig_flags, NULL); + if (read_only) { + bdrv_reopen_set_read_only(parent, true, NULL); } =20 return ret; --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537369282948555.2378665786614; Wed, 19 Sep 2018 08:01:22 -0700 (PDT) Received: from localhost ([::1]:45835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dyj-00020o-Lp for importer@patchew.org; Wed, 19 Sep 2018 11:01:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E4-Ri for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000KX-Oj for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56746) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Es-1C; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dD-D5; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004TY-Oz; Wed, 19 Sep 2018 17:48:05 +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=oTW0a4VK4KYTIgCGov2gcHFi+6QGYjpcG+OjvV07jsE=; b=QQjTwYwy7qEI/d5yMBqfUGcsUKKxDI0KQXKmoCWJvP1kV7lug7NngiswpqwscKumpSG15Hw/EppjKxaaLKimNojo6eT3gQ2nofKxTUYhTr1I4kmfU2RVJ2Tn0WEH83refVIDdKorUD6lPVi7uwrHgrwSZvja0sH9L4Ybw9FQAgxrIIDTHhxZuaRAgU2V+okE8M+QJRO5Rx/ktBnp0FfClqhO7J/cLiTS02k+/M91LVj52jJ5nz1CU/+wS63JaNto9SpXnBAzeOODJQ3G0U7o5ODKmg75HfbGts8qlV5SVo9CsftEqaKXVCuFzP4ZzrBzZ5fMtnmoG0Yrxakq4bNdVw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:42 +0300 Message-Id: <57d02fc28b31eebda8ee6d751587c5f25ebf5af0.1537367701.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 04/14] block: Use bdrv_reopen_set_read_only() in commit_start/complete() 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" This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/commit.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/block/commit.c b/block/commit.c index eb414579bd..fcadcab33a 100644 --- a/block/commit.c +++ b/block/commit.c @@ -37,7 +37,7 @@ typedef struct CommitBlockJob { BlockBackend *top; BlockBackend *base; BlockdevOnError on_error; - int base_flags; + bool base_read_only; char *backing_file_str; } CommitBlockJob; =20 @@ -105,8 +105,8 @@ static void commit_complete(Job *job, void *opaque) /* restore base open flags here if appropriate (e.g., change the base = back * to r/o). These reopens do not need to be atomic, since we won't abo= rt * even on failure here */ - if (s->base_flags !=3D bdrv_get_flags(base)) { - bdrv_reopen(base, s->base_flags, NULL); + if (s->base_read_only) { + bdrv_reopen_set_read_only(base, true, NULL); } g_free(s->backing_file_str); blk_unref(s->top); @@ -265,7 +265,6 @@ void commit_start(const char *job_id, BlockDriverState = *bs, const char *filter_node_name, Error **errp) { CommitBlockJob *s; - int orig_base_flags; BlockDriverState *iter; BlockDriverState *commit_top_bs =3D NULL; Error *local_err =3D NULL; @@ -284,11 +283,9 @@ void commit_start(const char *job_id, BlockDriverState= *bs, } =20 /* convert base to r/w, if necessary */ - orig_base_flags =3D bdrv_get_flags(base); - if (!(orig_base_flags & BDRV_O_RDWR)) { - bdrv_reopen(base, orig_base_flags | BDRV_O_RDWR, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); + s->base_read_only =3D bdrv_is_read_only(base); + if (s->base_read_only) { + if (bdrv_reopen_set_read_only(base, false, errp) !=3D 0) { goto fail; } } @@ -363,7 +360,6 @@ void commit_start(const char *job_id, BlockDriverState = *bs, goto fail; } =20 - s->base_flags =3D orig_base_flags; s->backing_file_str =3D g_strdup(backing_file_str); s->on_error =3D on_error; =20 --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537368757120936.749894845165; Wed, 19 Sep 2018 07:52:37 -0700 (PDT) Received: from localhost ([::1]:45775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dqG-0002kz-25 for importer@patchew.org; Wed, 19 Sep 2018 10:52:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008EA-Sj for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000JI-Ok for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56742) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Ep-1H; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dE-7W; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Te-Pu; Wed, 19 Sep 2018 17:48:05 +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=rcamYkZn8Ss1jXNi8jESWTt2zpIEmr/ob4nSQWacnBU=; b=P5mafRvravq6FfgeW92lcHFaD6cn1LMj5s11tCxc9WQfcULLy2yHObARuS6d0NLvkm625e8Y/d52ZPtRLPsH0NUAX9H8MKcGs4nzmlsZ5j/APgWwFyO9Wf4cKvVM7htnIVa3MPQTcxLSijl1v5E6BjWQfc1iqRyPN7IxPz7aYCQHYxaH6NyoRBRNKc+hDEetVB26cEYwter4P42PwczI4afjib3hhM06KecGt9d2y4ro0UfVIgJlBh5sB4xZt4UVmSpAcl0pn/DkBwkmcmJ95lv8vrxfzJKb9aECwxAvWmiTO7mRulVHZVozDWRyKZD5BlEbo9tM7bZRFCn1QmSqHg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:43 +0300 Message-Id: <27ece91df0fbe7528e01425e94992e46b71ff042.1537367701.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 05/14] block: Use bdrv_reopen_set_read_only() in bdrv_commit() 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" This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/commit.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/commit.c b/block/commit.c index fcadcab33a..2ed13825b3 100644 --- a/block/commit.c +++ b/block/commit.c @@ -391,7 +391,7 @@ int bdrv_commit(BlockDriverState *bs) BlockDriverState *commit_top_bs =3D NULL; BlockDriver *drv =3D bs->drv; int64_t offset, length, backing_length; - int ro, open_flags; + int ro; int64_t n; int ret =3D 0; uint8_t *buf =3D NULL; @@ -410,10 +410,9 @@ int bdrv_commit(BlockDriverState *bs) } =20 ro =3D bs->backing->bs->read_only; - open_flags =3D bs->backing->bs->open_flags; =20 if (ro) { - if (bdrv_reopen(bs->backing->bs, open_flags | BDRV_O_RDWR, NULL)) { + if (bdrv_reopen_set_read_only(bs->backing->bs, false, NULL)) { return -EACCES; } } @@ -523,7 +522,7 @@ ro_cleanup: =20 if (ro) { /* ignoring error return here */ - bdrv_reopen(bs->backing->bs, open_flags & ~BDRV_O_RDWR, NULL); + bdrv_reopen_set_read_only(bs->backing->bs, true, NULL); } =20 return ret; --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537369170379334.7106457516127; Wed, 19 Sep 2018 07:59:30 -0700 (PDT) Received: from localhost ([::1]:45820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dwm-0000kT-CQ for importer@patchew.org; Wed, 19 Sep 2018 10:59:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E9-SD for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000JA-Mp for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56755) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Ev-1H; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dF-Dq; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Th-R0; Wed, 19 Sep 2018 17:48:05 +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=rqIasglyqjzqRhxz0tO0/TMSVX1sHe6/uVMWDeb4U44=; b=AFiuW0GHgtuNiWKEIY+WWOEEPv4rzlw6V3pbLh+0vJ7AAgxvDGyILqyNNF0DW1iBVEM/lp4TxUFhrLAM/KR2uG1sdHkxkFm0mkhtTk/9EekYoflg5CnbxDaFtXgiRbiBPZ9r8wqAoHYR/crwffs83I1gdGdAGyL9V/wBW0WRCag7As2oKQIHwHGbjU2LpKMEcco7TCEDnTr9lmerztnMinPbaw5DGdUPFPV2qnrGhIysGej+IZXGZn/WDJCOGiIQNMOdeCB5Z8vhShMBhnnjkTrnk2Il0EPOFFS1RZbPWhX/2IcyPKfKkr+/KB4LM/wSiarTVrKYMBjqXRgHP3Otvg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:44 +0300 Message-Id: <5f1c063ccfaf20fde5d1334652648f054b0f9d8a.1537367701.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 06/14] block: Use bdrv_reopen_set_read_only() in stream_start/complete() 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" This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/stream.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/stream.c b/block/stream.c index 9264b68a1e..07201f3df5 100644 --- a/block/stream.c +++ b/block/stream.c @@ -34,7 +34,7 @@ typedef struct StreamBlockJob { BlockDriverState *base; BlockdevOnError on_error; char *backing_file_str; - int bs_flags; + bool bs_read_only; } StreamBlockJob; =20 static int coroutine_fn stream_populate(BlockBackend *blk, @@ -86,10 +86,10 @@ static void stream_complete(Job *job, void *opaque) =20 out: /* Reopen the image back in read-only mode if necessary */ - if (s->bs_flags !=3D bdrv_get_flags(bs)) { + if (s->bs_read_only) { /* Give up write permissions before making it read-only */ blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort); - bdrv_reopen(bs, s->bs_flags, NULL); + bdrv_reopen_set_read_only(bs, true, NULL); } =20 g_free(s->backing_file_str); @@ -225,12 +225,12 @@ void stream_start(const char *job_id, BlockDriverStat= e *bs, { StreamBlockJob *s; BlockDriverState *iter; - int orig_bs_flags; + int bs_read_only; =20 /* Make sure that the image is opened in read-write mode */ - orig_bs_flags =3D bdrv_get_flags(bs); - if (!(orig_bs_flags & BDRV_O_RDWR)) { - if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) !=3D 0) { + bs_read_only =3D bdrv_is_read_only(bs); + if (bs_read_only) { + if (bdrv_reopen_set_read_only(bs, false, errp) !=3D 0) { return; } } @@ -260,7 +260,7 @@ void stream_start(const char *job_id, BlockDriverState = *bs, =20 s->base =3D base; s->backing_file_str =3D g_strdup(backing_file_str); - s->bs_flags =3D orig_bs_flags; + s->bs_read_only =3D bs_read_only; =20 s->on_error =3D on_error; trace_stream_start(bs, base, s); @@ -268,7 +268,7 @@ void stream_start(const char *job_id, BlockDriverState = *bs, return; =20 fail: - if (orig_bs_flags !=3D bdrv_get_flags(bs)) { - bdrv_reopen(bs, orig_bs_flags, NULL); + if (bs_read_only) { + bdrv_reopen_set_read_only(bs, true, NULL); } } --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537368638344938.00490107503; Wed, 19 Sep 2018 07:50:38 -0700 (PDT) Received: from localhost ([::1]:45759 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2doL-00014v-49 for importer@patchew.org; Wed, 19 Sep 2018 10:50:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008Dz-RG for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000Kd-QI for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56744) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Em-1E; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dG-Bu; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Tk-Rs; Wed, 19 Sep 2018 17:48:05 +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=8uF5LtYgKZTE6uKrmyjuYIGyCCuDw3jPavzeyZimOI0=; b=HSWoETAXOQTX7R/9sa3/FMQ0dJw7F5TJpXL73YHxOHdd1LZBey/CvMUZv5BDJF0M7PHiO5KpaBomjUX+6ld3xA9IA1dofGiGH8kRCEKIa0phVedJwmkevraqytr8syZwwL4XJ00ChYTi1JbBIOSM0/DjW3GuIBGfK7LH7KoFm+ATJVi32OGIHv+xEouEjTUQXXVuvNpSccTDhaYzAluKpGrgoGi58GLD13oI/JjY6RAdHkkUGEAWVecSNeRLMJN5BoCDaS1xwM2F0JkoLjTPPeqi7gfXbAxqrGCUwTnagCUI6oQhIGxyf3IbyLxcsULxO75w3eODsMSTlL+Mqx1idA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:45 +0300 Message-Id: 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 07/14] block: Use bdrv_reopen_set_read_only() in qmp_change_backing_file() 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" This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- blockdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index 72f5347df5..58e057b0d9 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3996,7 +3996,6 @@ void qmp_change_backing_file(const char *device, BlockDriverState *image_bs =3D NULL; Error *local_err =3D NULL; bool ro; - int open_flags; int ret; =20 bs =3D qmp_get_root_bs(device, errp); @@ -4038,13 +4037,10 @@ void qmp_change_backing_file(const char *device, } =20 /* if not r/w, reopen to make r/w */ - open_flags =3D image_bs->open_flags; ro =3D bdrv_is_read_only(image_bs); =20 if (ro) { - bdrv_reopen(image_bs, open_flags | BDRV_O_RDWR, &local_err); - if (local_err) { - error_propagate(errp, local_err); + if (bdrv_reopen_set_read_only(image_bs, false, errp) !=3D 0) { goto out; } } @@ -4060,7 +4056,7 @@ void qmp_change_backing_file(const char *device, } =20 if (ro) { - bdrv_reopen(image_bs, open_flags, &local_err); + bdrv_reopen_set_read_only(image_bs, true, &local_err); error_propagate(errp, local_err); } =20 --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537368639397575.878157058588; Wed, 19 Sep 2018 07:50:39 -0700 (PDT) Received: from localhost ([::1]:45763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2doM-00015u-7L for importer@patchew.org; Wed, 19 Sep 2018 10:50:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E2-RI for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000Im-Kd for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Eq-2X; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dH-DK; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Tn-Sj; Wed, 19 Sep 2018 17:48:05 +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=ShFJku5U+sCMMWdihuZTwaLKOZtU9d2x2+PwRNid/Kk=; b=e8npZQi/RkfbBl96gKU2Lz9xi05+TqJ06MAi7PRvaQoXCz+G2ZoZRw04UPNqjJkWayeGy5PVwNmha8U13+lgT4Yx6WhOIExU+O1HmPPhf6X1yLKsMPHs3aGCztIZtH82uVK67PVEHEJHJUvk4NJv5NhBvFqK3a4PLtScMQfhRCv2nSB1HCCfgREElRTSYsXZ192EzMLGWrm6DbUuu5YOV5e4aLs//1kubWePQh9MFhJXN4Abj2WnGOvNqslCaz3ujhGwaFv3H1pQK5TFQQbhbPFHah0QtibEyikjuOEkG619ouEI01Cd0NQvmaTjySpcWLzPFoC+t0QJ9m1wcNj30g==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:46 +0300 Message-Id: <8f8a151dae565027208268ed8d120e4612ef5f9f.1537367701.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 08/14] block: Use bdrv_reopen_set_read_only() in external_snapshot_commit() 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" This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- blockdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 58e057b0d9..2f2359593e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1701,8 +1701,7 @@ static void external_snapshot_commit(BlkActionState *= common) * bdrv_reopen_multiple() across all the entries at once, because we * don't want to abort all of them if one of them fails the reopen */ if (!atomic_read(&state->old_bs->copy_on_read)) { - bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDW= R, - NULL); + bdrv_reopen_set_read_only(state->old_bs, true, NULL); } =20 aio_context_release(aio_context); --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537369056512871.0987933450743; Wed, 19 Sep 2018 07:57:36 -0700 (PDT) Received: from localhost ([::1]:45813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dv5-0007Q4-DL for importer@patchew.org; Wed, 19 Sep 2018 10:57:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E3-Rh for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmC-0000IZ-Gp for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmC-0000Er-1B; Wed, 19 Sep 2018 10:48:24 -0400 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 1g2dm9-0003dI-AV; Wed, 19 Sep 2018 16:48:21 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Tq-Ta; Wed, 19 Sep 2018 17:48:05 +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=KM7EYbUImEn5M/6OMHFSoKjO+MNh6h6pj0V1AUw1Wg8=; b=rHEvIohck11vwILlwBfADxBgxf5JEIsVnQB8XdN3S/vq7u2wtagH/E6x5ayvELPu+7NumcEHswCh+SugqS5jRHzGNMq7yh+sBAs70dvG+63dcdDkoNHvAwoKwUuUhItZLz84goRXnrjAD7kSDwhuhgXJE8FeoT60PYENnmV1+Ws7vgH4tnJtWD4RWfHblqsW6P8l+oPBYrzpkAASjTm9A6QDC6UqYt38hKn3VJgijdHR/hMNOvGgRy0Ori7YOb5HwU/2OIiDaBpO6z+kX06jsHqFEIM03ZC7KE5uv07mMa4TnBbK7JRsZ1Pve1HP3PNVRirc6QcIJHM+fX+byNnfmQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:47 +0300 Message-Id: <32c99e47940fcee5e83c780147e34a8f3840f7e4.1537367701.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 09/14] block: Use bdrv_reopen_set_read_only() in the mirror driver 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 , Jeff Cody , 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 'block-commit' QMP command is implemented internally using two different drivers. If the source image is the active layer then the mirror driver is used (commit_active_start()), otherwise the commit driver is used (commit_start()). In both cases the destination image must be put temporarily in read-write mode. This is done correctly in the latter case, but what commit_active_start() does is copy all flags instead. This patch replaces the bdrv_reopen() calls in that function with bdrv_reopen_set_read_only() so that only the read-only status is changed. A similar change is made in mirror_exit(), which is also used by the 'drive-mirror' and 'blockdev-mirror' commands. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/mirror.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 6cc10df5c9..37f8d3ac56 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -663,13 +663,15 @@ static void mirror_exit(Job *job, void *opaque) } =20 if (s->should_complete && data->ret =3D=3D 0) { + bool ro; BlockDriverState *to_replace =3D src; if (s->to_replace) { to_replace =3D s->to_replace; } =20 - if (bdrv_get_flags(target_bs) !=3D bdrv_get_flags(to_replace)) { - bdrv_reopen(target_bs, bdrv_get_flags(to_replace), NULL); + ro =3D bdrv_is_read_only(to_replace); + if (ro !=3D bdrv_is_read_only(target_bs)) { + bdrv_reopen_set_read_only(target_bs, ro, NULL); } =20 /* The mirror job has no requests in flight any more, but we need = to @@ -1674,13 +1676,15 @@ void commit_active_start(const char *job_id, BlockD= riverState *bs, BlockCompletionFunc *cb, void *opaque, bool auto_complete, Error **errp) { - int orig_base_flags; + bool base_read_only; Error *local_err =3D NULL; =20 - orig_base_flags =3D bdrv_get_flags(base); + base_read_only =3D bdrv_is_read_only(base); =20 - if (bdrv_reopen(base, bs->open_flags, errp)) { - return; + if (base_read_only) { + if (bdrv_reopen_set_read_only(base, false, errp) < 0) { + return; + } } =20 mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0, @@ -1699,6 +1703,8 @@ void commit_active_start(const char *job_id, BlockDri= verState *bs, error_restore_flags: /* ignore error and errp for bdrv_reopen, because we want to propagate * the original error */ - bdrv_reopen(base, orig_base_flags, NULL); + if (base_read_only) { + bdrv_reopen_set_read_only(base, true, NULL); + } return; } --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537368997780976.5100057788866; Wed, 19 Sep 2018 07:56:37 -0700 (PDT) Received: from localhost ([::1]:45804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2du8-0006ju-OH for importer@patchew.org; Wed, 19 Sep 2018 10:56:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dme-00007D-Rc for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmZ-0000j1-DY for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:52 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56793) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmZ-0000NX-0L; Wed, 19 Sep 2018 10:48:47 -0400 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 1g2dmD-0003dJ-RP; Wed, 19 Sep 2018 16:48:25 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Tt-UO; Wed, 19 Sep 2018 17:48:05 +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=dEbPtjpLKRUw4I+DR17Xe3W+7Jp1d2HZv+YyoKB5Daw=; b=puQyjyhJEfPC2t/kq1cJJumqA4bfgGiqyLH04uaveAn/riTX+Ekdf9oLu4/5wjw60QJqRzU9mHhUimjaTLdjRJbRCsR4lUIcaX+dcPPHZPIYmj68YwWIc4Ku6XSMbn5KPaWkt1LD//vE7YJNDzf4PrOdP59JpIX2NRnaY8rblNuGrHb9ldYvGNJB40q0ymao+ZKGi3EppU1Qb4xaTuGiJ7a+0qOrb7DnA5e8uW+CHVjGaIYpGBzfL1KujSWo73ZQYRqkHVTCUrk6T6fuaTAAuQAhu4utGTP18gwTas54yjj1XEgsEF5U4HroeUodD1liZPDC0OQhacyPl2lcflHWzg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:48 +0300 Message-Id: <570b9109b10c519aceb6c333a6e0d0a59795defb.1537367701.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/14] block: Drop bdrv_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" No one is using this function anymore, so we can safely remove it Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 21 --------------------- include/block/block.h | 1 - 2 files changed, 22 deletions(-) diff --git a/block.c b/block.c index ac945b4bc8..3751167434 100644 --- a/block.c +++ b/block.c @@ -3085,27 +3085,6 @@ cleanup: return ret; } =20 - -/* Reopen a single BlockDriverState with the specified flags. */ -int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp) -{ - int ret =3D -1; - Error *local_err =3D NULL; - BlockReopenQueue *queue; - - bdrv_subtree_drained_begin(bs); - - queue =3D bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags); - ret =3D bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, &local_e= rr); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); - } - - bdrv_subtree_drained_end(bs); - - return ret; -} - int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) { diff --git a/include/block/block.h b/include/block/block.h index 47ee32512f..1650b1ac14 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -301,7 +301,6 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *b= s_queue, BlockDriverState *bs, QDict *options, int flags); int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Erro= r **errp); -int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp); int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); int bdrv_reopen_prepare(BDRVReopenState *reopen_state, --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537368816485589.7987275352357; Wed, 19 Sep 2018 07:53:36 -0700 (PDT) Received: from localhost ([::1]:45778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2drD-0003f8-C4 for importer@patchew.org; Wed, 19 Sep 2018 10:53:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dmG-0008E8-SB for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmF-0000Oi-7Y for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:28 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56791) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmE-0000MY-RF; Wed, 19 Sep 2018 10:48:27 -0400 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 1g2dmD-0003dK-OB; Wed, 19 Sep 2018 16:48:25 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Tw-VD; Wed, 19 Sep 2018 17:48:05 +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=jKyLDFCIyuMqTCHJHkLgJQTQh60/QMVJLm3BwrDIlfE=; b=PPsypCc8r1Ehr4y7RoB6XoSPqj+jm2QT+Gmvd6st2YsDNjEaRaKA3FXjnImPsyY4kek6fvTTVeB2D6Jmo3afI4/JeMrx8M4tkenq7n3LZfRASAP5RYu7hYLRnkSDvNR3pfAbILMKm+c5kgYyQhAHt27BueerVUm0jKO1PWCdIkC9ks+/8ebiovlQbAgG86kHrsdnihMSvPUZu8ZGKwWA/G4XnUuGRGYud7zs1gyeo6TQKp++r0kcE7V9T6dE0pY6wnb4NMaxqxbmvOJeT8YU4jLE9cLykpTMMAEuhO2jAl5TimwL8See0pQ1VMkADASy1FcBmFaxUE6R2QrYFFcbew==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:49 +0300 Message-Id: <298f85a0b53dc90b1d6bea272c26983ab684619e.1537367701.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 11/14] qemu-io: Put flag changes in the options QDict in reopen_f() 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" When reopen_f() puts a block device in the reopen queue, some of the new options are passed using a QDict, but others ("read-only" and the cache options) are passed as flags. This patch puts those flags in the QDict. This way the flags parameter becomes redundant and we'll be able to get rid of it in a subsequent patch. Signed-off-by: Alberto Garcia --- qemu-io-cmds.c | 27 ++++++++++++++++++++++++++- tests/qemu-iotests/133 | 9 +++++++++ tests/qemu-iotests/133.out | 8 ++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index db0b3ee5ef..4ad5269abc 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -10,6 +10,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "qemu-io.h" #include "sysemu/block-backend.h" #include "block/block.h" @@ -1978,6 +1979,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) int flags =3D bs->open_flags; bool writethrough =3D !blk_enable_write_cache(blk); bool has_rw_option =3D false; + bool has_cache_option =3D false; =20 BlockReopenQueue *brq; Error *local_err =3D NULL; @@ -1989,6 +1991,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) error_report("Invalid cache option: %s", optarg); return -EINVAL; } + has_cache_option =3D true; break; case 'o': if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) { @@ -2046,9 +2049,31 @@ static int reopen_f(BlockBackend *blk, int argc, cha= r **argv) } =20 qopts =3D qemu_opts_find(&reopen_opts, NULL); - opts =3D qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; + opts =3D qopts ? qemu_opts_to_qdict(qopts, NULL) : qdict_new(); qemu_opts_reset(&reopen_opts); =20 + if (qdict_haskey(opts, BDRV_OPT_READ_ONLY)) { + if (has_rw_option) { + error_report("Can't set both -r/-w and '" BDRV_OPT_READ_ONLY "= '"); + qobject_unref(opts); + return -EINVAL; + } + } else { + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR)); + } + + if (qdict_haskey(opts, BDRV_OPT_CACHE_DIRECT) || + qdict_haskey(opts, BDRV_OPT_CACHE_NO_FLUSH)) { + if (has_cache_option) { + error_report("Can't set both -c and the cache options"); + qobject_unref(opts); + return -EINVAL; + } + } else { + qdict_put_bool(opts, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCACHE= ); + qdict_put_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, flags & BDRV_O_NO_FL= USH); + } + bdrv_subtree_drained_begin(bs); brq =3D bdrv_reopen_queue(NULL, bs, opts, flags); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index b9f17c996f..a58130c5b4 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -98,6 +98,15 @@ echo =20 $QEMU_IO -c 'reopen -o read-only=3Dfoo' $TEST_IMG =20 +echo +echo "=3D=3D=3D Check that mixing -c/-r/-w and their equivalent options is= forbidden =3D=3D=3D" +echo + +$QEMU_IO -c 'reopen -r -o read-only=3Don' $TEST_IMG +$QEMU_IO -c 'reopen -w -o read-only=3Don' $TEST_IMG +$QEMU_IO -c 'reopen -c none -o cache.direct=3Don' $TEST_IMG +$QEMU_IO -c 'reopen -c writeback -o cache.direct=3Don' $TEST_IMG +$QEMU_IO -c 'reopen -c directsync -o cache.no-flush=3Don' $TEST_IMG # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/133.out b/tests/qemu-iotests/133.out index 570f623b6b..4d84401688 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -28,4 +28,12 @@ format name: null-co =3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D =20 Parameter 'read-only' expects 'on' or 'off' + +=3D=3D=3D Check that mixing -c/-r/-w and their equivalent options is forbi= dden =3D=3D=3D + +Can't set both -r/-w and 'read-only' +Can't set both -r/-w and 'read-only' +Can't set both -c and the cache options +Can't set both -c and the cache options +Can't set both -c and the cache options *** done --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537369107740170.294222593604; Wed, 19 Sep 2018 07:58:27 -0700 (PDT) Received: from localhost ([::1]:45814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dvu-00007q-Kc for importer@patchew.org; Wed, 19 Sep 2018 10:58:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dme-00007F-Rf for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmZ-0000jK-Ju for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:52 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmZ-0000OM-84; Wed, 19 Sep 2018 10:48:47 -0400 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 1g2dmD-0003dL-Qh; Wed, 19 Sep 2018 16:48:25 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlt-0004Tz-W6; Wed, 19 Sep 2018 17:48:05 +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=dSdjPsfEQWnBP7fTyDrvzdgTQNp+MnRFPfPSD0j9BrA=; b=HffVYvtXGVZ3MMtJnu2KCu4lLEzq1rfcw6Xj05akdWWf66IKdULSSYv2SpMXOV+IR3QcUvZtigU2WYUB1dTR34ZUt0I7wD1IWWqgLpoZrbiuZmg02cD08e5T2k9ljL49szarFAsAKcfPwD2aX/z5CvYKZtiWuhC0JDAs6quqgma/IuXaN5KN5n5umewOf1aWJntzxCt9H2e3hYQD9n6e07n/jJW3teWqCKQl5x887MVfZkBkseRS+iYRulxJKpN7Q3H362zJihDBS5F9KiXRoJw0oJGyrpP0oRdbslKaRIrHQbkfxyV9/CGdV0NbZLW35EwbZPxZ0AI88/cP/LVyYQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:50 +0300 Message-Id: <95addb261af316f49517069e1cce4d9c601d274b.1537367701.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 12/14] block: Clean up reopen_backing_file() in block/replication.c 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, Wen Congyang , Xie Changlong , 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" This function is used to put the hidden and secondary disks in read-write mode before launching the backup job, and back in read-only mode afterwards. This patch does the following changes: - Use an options QDict with the "read-only" option instead of passing the changes as flags only. - Simplify the code (it was unnecessarily complicated and verbose). - Fix a bug due to which the secondary disk was not being put back in read-only mode when writable=3Dfalse (because in this case orig_secondary_flags always had the BDRV_O_RDWR flag set). - Stop clearing the BDRV_O_INACTIVE flag. The flags parameter to bdrv_reopen_queue() becomes redundant and we'll be able to get rid of it in a subsequent patch. Signed-off-by: Alberto Garcia --- block/replication.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/block/replication.c b/block/replication.c index 6349d6958e..1ad0ef2ef8 100644 --- a/block/replication.c +++ b/block/replication.c @@ -20,6 +20,7 @@ #include "block/block_backup.h" #include "sysemu/block-backend.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "replication.h" =20 typedef enum { @@ -39,8 +40,8 @@ typedef struct BDRVReplicationState { char *top_id; ReplicationState *rs; Error *blocker; - int orig_hidden_flags; - int orig_secondary_flags; + bool orig_hidden_read_only; + bool orig_secondary_read_only; int error; } BDRVReplicationState; =20 @@ -376,39 +377,32 @@ static void reopen_backing_file(BlockDriverState *bs,= bool writable, { BDRVReplicationState *s =3D bs->opaque; BlockReopenQueue *reopen_queue =3D NULL; - int orig_hidden_flags, orig_secondary_flags; - int new_hidden_flags, new_secondary_flags; Error *local_err =3D NULL; =20 if (writable) { - orig_hidden_flags =3D s->orig_hidden_flags =3D - bdrv_get_flags(s->hidden_disk->bs); - new_hidden_flags =3D (orig_hidden_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - orig_secondary_flags =3D s->orig_secondary_flags =3D - bdrv_get_flags(s->secondary_disk->bs); - new_secondary_flags =3D (orig_secondary_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - } else { - orig_hidden_flags =3D (s->orig_hidden_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - new_hidden_flags =3D s->orig_hidden_flags; - orig_secondary_flags =3D (s->orig_secondary_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - new_secondary_flags =3D s->orig_secondary_flags; + s->orig_hidden_read_only =3D + !(bdrv_get_flags(s->hidden_disk->bs) & BDRV_O_RDWR); + s->orig_secondary_read_only =3D + !(bdrv_get_flags(s->secondary_disk->bs) & BDRV_O_RDWR); } =20 bdrv_subtree_drained_begin(s->hidden_disk->bs); bdrv_subtree_drained_begin(s->secondary_disk->bs); =20 - if (orig_hidden_flags !=3D new_hidden_flags) { - reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->hidden_disk->b= s, NULL, - new_hidden_flags); + if (s->orig_hidden_read_only) { + int flags =3D bdrv_get_flags(s->hidden_disk->bs); + 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, flags); } =20 - if (!(orig_secondary_flags & BDRV_O_RDWR)) { + if (s->orig_secondary_read_only) { + int flags =3D bdrv_get_flags(s->secondary_disk->bs); + 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, - NULL, new_secondary_flags); + opts, flags); } =20 if (reopen_queue) { --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537369222456822.4903654017361; Wed, 19 Sep 2018 08:00:22 -0700 (PDT) Received: from localhost ([::1]:45822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dxb-0001Jj-JH for importer@patchew.org; Wed, 19 Sep 2018 11:00:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dme-00007C-Qi for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmZ-0000jE-Io for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:52 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56796) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmZ-0000ON-7R; Wed, 19 Sep 2018 10:48:47 -0400 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 1g2dmD-0003dM-O6; Wed, 19 Sep 2018 16:48:25 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlu-0004U2-0i; Wed, 19 Sep 2018 17:48:06 +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=wrn6NGYWgmv0hQLHuX6mDUkB/xgO/K3SfZJI5mscDI8=; b=pgBCzYuOahNmhL9cAZ7iq39/dcmX5FQYMAUNGAKiAESSeCWw009vVNdBne1KP3sK2OgNWXOk+bk4qRxbuTCiQ34bzRvjus6GQ8JXeSN3hPMRfFA1n/o7RS8vFTaNfT9QpmMOkOjiUJax8kC1b3+J65ofTJeq2qAR3PPrK1G6drAE3Z77OyHR/BphkcfUWMDcd+R0WazDCr+awWmbIf/lkfvFrxZVnfUOblx3bIBsqG1pmhqGOrPwOD2k38joFw7VrsV6K9AQKzzf7ApnWD8BqTVIVIUUCtoqxhNpMguzrTFBBfZ9Qr/MZkaEHWUh1lQsdeT7f/xOlGtugi6AmosMUQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:51 +0300 Message-Id: <8e3622ca8e46a8f450dd94f6f2a485bfbe4a72ab.1537367701.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 13/14] block: Remove flags parameter from 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, Wen Congyang , Xie Changlong , 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" Now that all callers are passing all flag changes as QDict options, the flags parameter is no longer necessary, so we can get rid of it. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 5 +++-- block/replication.c | 6 ++---- include/block/block.h | 3 +-- qemu-io-cmds.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 3751167434..fd27b204d9 100644 --- a/block.c +++ b/block.c @@ -3020,8 +3020,9 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, =20 BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, - QDict *options, int flags) + QDict *options) { + int flags =3D bdrv_get_flags(bs); return bdrv_reopen_queue_child(bs_queue, bs, options, flags, NULL, NULL, 0); } @@ -3095,7 +3096,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, bdrv_get_flags(bs)); + queue =3D bdrv_reopen_queue(NULL, bs, opts); 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 1ad0ef2ef8..08c44fec5c 100644 --- a/block/replication.c +++ b/block/replication.c @@ -390,19 +390,17 @@ static void reopen_backing_file(BlockDriverState *bs,= bool writable, bdrv_subtree_drained_begin(s->secondary_disk->bs); =20 if (s->orig_hidden_read_only) { - int flags =3D bdrv_get_flags(s->hidden_disk->bs); 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, flags); + opts); } =20 if (s->orig_secondary_read_only) { - int flags =3D bdrv_get_flags(s->secondary_disk->bs); 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, flags); + opts); } =20 if (reopen_queue) { diff --git a/include/block/block.h b/include/block/block.h index 1650b1ac14..8da74548e6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -298,8 +298,7 @@ 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, int flags); + BlockDriverState *bs, QDict *options); 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 4ad5269abc..4d2f28617a 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2075,7 +2075,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, flags); + brq =3D bdrv_reopen_queue(NULL, bs, opts); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); bdrv_subtree_drained_end(bs); =20 --=20 2.11.0 From nobody Sat Feb 7 15:12:32 2026 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 1537369471351532.8424235575992; Wed, 19 Sep 2018 08:04:31 -0700 (PDT) Received: from localhost ([::1]:45852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2e1m-0004i0-68 for importer@patchew.org; Wed, 19 Sep 2018 11:04:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2dme-00007E-Rd for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2dmZ-0000is-AD for qemu-devel@nongnu.org; Wed, 19 Sep 2018 10:48:52 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g2dmY-0000NY-W7; Wed, 19 Sep 2018 10:48:47 -0400 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 1g2dmD-0003dN-Ra; Wed, 19 Sep 2018 16:48:26 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1g2dlu-0004U5-1X; Wed, 19 Sep 2018 17:48:06 +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=dMgvXxKGf7wctKRVgi/FoD45UhJsUKKNse/gYE6wjVs=; b=FD3CiPwpn/y3mm+O6RCInSDTj9fCbTq2+Yqp+XNUX3LlSXSNteBmZvUPD5Ks/ftfBmrG9JY3A1QoJ05pbl+OWUNtfMA8CIXxSngALaE8AxNKMiS9zT24u1IwrARbf+PNg4DdX8fuh2K0VyRHjnBnYjx73cQRfLEghgvEqkhGJPTzlfddoqnlkoMTYlW3NlJfVYpTWUsj9ICBPNzkYKPP0RT4UwoLZpWaIhuELuXu54q6fh5Z7/Z20eHbkon8Xv4rbRNJ9iBEs5IkKmehabnw12KOv7tB/3tubgipNmP/pD2X79a2qzCygbxlqUVFy9TA1yyU1/d2QoI0AjXUVG+o+Q==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 17:47:52 +0300 Message-Id: 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 14/14] block: Stop passing flags to bdrv_reopen_queue_child() 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" Now that all callers are passing the new options using the QDict we no longer need the 'flags' parameter. This patch makes the following changes: 1) The update_options_from_flags() call is no longer necessary so it can be removed. 2) The update_flags_from_options() call is now used in all cases, and is moved down a few lines so it happens after the options QDict contains the final set of values. 3) The flags parameter is removed. Now the flags are initialized using the current value (for the top-level node) or the parent flags (after inherit_options()). In both cases the initial values are updated to reflect the new options in the QDict. This happens in bdrv_reopen_queue_child() (as explained above) and in bdrv_reopen_prepare(). Signed-off-by: Alberto Garcia --- block.c | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index fd27b204d9..26c6a4e58a 100644 --- a/block.c +++ b/block.c @@ -2884,7 +2884,6 @@ BlockDriverState *bdrv_open(const char *filename, con= st char *reference, static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queu= e, BlockDriverState *bs, QDict *options, - int flags, const BdrvChildRole *role, QDict *parent_options, int parent_flags) @@ -2894,6 +2893,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, BlockReopenQueueEntry *bs_entry; BdrvChild *child; QDict *old_options, *explicit_options; + int flags; =20 /* Make sure that the caller remembered to use a drained section. This= is * important to avoid graph changes between the recursive queuing here= and @@ -2919,22 +2919,11 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, /* * Precedence of options: * 1. Explicitly passed in options (highest) - * 2. Set in flags (only for top level) - * 3. Retained from explicitly set options of bs - * 4. Inherited from parent node - * 5. Retained from effective options of bs + * 2. Retained from explicitly set options of bs + * 3. Inherited from parent node + * 4. Retained from effective options of bs */ =20 - if (!parent_options) { - /* - * Any setting represented by flags is always updated. If the - * corresponding QDict option is set, it takes precedence. Otherwi= se - * the flag is translated into a QDict option. The old setting of = bs is - * not considered. - */ - update_options_from_flags(options, flags); - } - /* 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); @@ -2948,12 +2937,22 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, =20 /* Inherit from parent node */ if (parent_options) { - QemuOpts *opts; - QDict *options_copy; - Error *local_err =3D NULL; - assert(!flags); + flags =3D 0; role->inherit_options(&flags, options, parent_flags, parent_option= s); - options_copy =3D qdict_clone_shallow(options); + } else { + flags =3D bdrv_get_flags(bs); + } + + /* 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); + + /* We have the final set of options so let's update the flags */ + { + Error *local_err =3D NULL; + QemuOpts *opts; + QDict *options_copy =3D qdict_clone_shallow(options); opts =3D qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abor= t); qemu_opts_absorb_qdict(opts, options_copy, &local_err); /* Don't call update_flags_from_options() if the options are wrong. @@ -2967,11 +2966,6 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, qobject_unref(options_copy); } =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); - /* bdrv_open_inherit() sets and clears some additional flags internall= y */ flags &=3D ~BDRV_O_PROTOCOL; if (flags & BDRV_O_RDWR) { @@ -3011,7 +3005,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, qdict_extract_subqdict(options, &new_child_options, child_key_dot); g_free(child_key_dot); =20 - bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, 0, + bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, child->role, options, flags); } =20 @@ -3022,9 +3016,7 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue = *bs_queue, BlockDriverState *bs, QDict *options) { - int flags =3D bdrv_get_flags(bs); - return bdrv_reopen_queue_child(bs_queue, bs, options, flags, - NULL, NULL, 0); + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0); } =20 /* --=20 2.11.0