From nobody Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781245369553.6813356636727; Wed, 17 Oct 2018 06:00:45 -0700 (PDT) Received: from localhost ([::1]:36521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClRM-0006ZC-7w for importer@patchew.org; Wed, 17 Oct 2018 09:00:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005I8-6o for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006YC-3m for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34308) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yO-D9; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lO-H9; Wed, 17 Oct 2018 14:57:57 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005kX-8a; Wed, 17 Oct 2018 15:57:38 +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=aeJQCs3etXRwJZUw+0rnMgKW2ZWKM7PVVWfmn2JsHBw=; b=J0qYzxprf/JKTPH2/dR8gtIczaAkv0eEwT8ULrxzs/ojnN8fWbAYsvo6dk7gmud/P8JH+HzjZrmFTg+BxlrfJM6zZOT19S3praeZxT3bY2K4R90Tpf7DU21+iudc/ivzu9JX4n1FSYpoY+ZfSis8fHWap3uFylybpOZ25rfOYh7kjul+cMFZc8z5tOV6Of4ffh7H5tMT/YD5j/u07Vff5kaB1YpB4gSttOxTCE1TRXkPKH7sfp1MqFk1Cnj1xS1h7btTaaRX8pYlYDzlmOtAGpCx/Yav63vnHefMGhMIaiUl8kT2B6TsLaZmKo/4Dd2X6tzhW/F9lu3nSlc+KOh82A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:17 +0300 Message-Id: <5b203ceb35b456503115cb2a4ab2941b2fdc2a6a.1539780785.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 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 7710b399a3..47d5fe2f91 100644 --- a/block.c +++ b/block.c @@ -2942,12 +2942,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781539158366.2754207993644; Wed, 17 Oct 2018 06:05:39 -0700 (PDT) Received: from localhost ([::1]:36547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClW5-0001ld-SO for importer@patchew.org; Wed, 17 Oct 2018 09:05:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IH-82 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006Y5-3N for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34300) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yK-D4; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lR-HF; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005kZ-9a; Wed, 17 Oct 2018 15:57:38 +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=ZfKmnRL4qmMlJFAgogQoZRlqqp4EeosUWGIz5RQHmG4=; b=clSnHaL7vqHeOtLBmIAV4tZHTtLUW8mmrgkAAYbVAuk1Z9mRmiMiXzn9zG9L13oSR85duAzxnyZdMOT7BGS7mb1XGXoAqW55/Y0GvDKMRyadzZwciRTXlOpjszlk7moZ/D9HfRxShv3ViVJTPxfGXf6fNeYyW05fV8InmrRAsFIh0AdGzvUq2AVwitYKXEZoHm7MRVPu6cyTf3RMJcYD1303LT+dJOxQiiDzogcNI5CB7Zb2rQH71BlM2ZurYoOc8YgfcmQknOQtAeUxaply28jw51UCeOYBO8ZBSqmDCYUCPZQyhhQ+gXJIA6UXQtQv/bL+RckfcZUfpYTIpkcd+w==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:18 +0300 Message-Id: <38f4b775e2acf6e97b152fceed6993756c7c94a9.1539780785.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 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 47d5fe2f91..40c3a3d30b 100644 --- a/block.c +++ b/block.c @@ -3098,6 +3098,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 b189cf422e..97317fdfb6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -301,6 +301,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781586997183.2361372987226; Wed, 17 Oct 2018 06:06:26 -0700 (PDT) Received: from localhost ([::1]:36557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClWr-0002Te-PI for importer@patchew.org; Wed, 17 Oct 2018 09:06:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IB-7C for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006Wx-0j for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34301) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yM-D5; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lP-Hv; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005kc-AS; Wed, 17 Oct 2018 15:57:38 +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=2QernxnL4wjCz1+GxCiCb1pPuiXdmwTkEy4RrkGI2Kc=; b=Y2DNixeARRZhCdEOSc5jDsvv3QN6WwOkQxuS8Fz+0C8oO6p+dkhuQ+Z8tpH4RVTU9uDvCxqYQJvu2cVr7uQus4AceFgC0h0St9uJTFy9XklwB/nbW0RtjWxBO+rwt7dAasM4y6nAsGB7P2A4vWIovhXDxKJc2/h1ZwnAnlqdLSFvWUn8UcKW9uE7yDpITQFUWL1bc7+uxYciao4J8MSIGN5ISAFt1gSicRIW1dOASSHXoU7CyfRuPu/WgeTPGQA9jb8cR6O6lqIhWbl59tpy1+W9wS4UiK0RgHTCVSDfI+/XxkibzmHPWdFYdNLSO8+Qw/QyM5MG0zuepslv86tiDA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:19 +0300 Message-Id: <0d146a1d1c037c74e9d137d5147ff8ccf679e4a1.1539780785.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 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 40c3a3d30b..39d40f4556 100644 --- a/block.c +++ b/block.c @@ -1058,11 +1058,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; } @@ -1074,8 +1074,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781656718525.2186910149916; Wed, 17 Oct 2018 06:07:36 -0700 (PDT) Received: from localhost ([::1]:36563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClXz-0003Lb-GD for importer@patchew.org; Wed, 17 Oct 2018 09:07:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IE-7M for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006XG-1j for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34311) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yQ-Cv; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lU-It; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005ke-BS; Wed, 17 Oct 2018 15:57:38 +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=19Ov5fheguogZYtvmgEGscVh0qZYm9xCtL7NsuwV1so=; b=BObxPeq0lFRKyFZJ3OZZ9shXh8MVj+ZaXtqGpNy1FYL4sLTR/SQjiysq0J3wS7nJ+f1paEqHMnGpBf+Qh6WoFnYDZfgx9Ryh5eg6wxTVWeBya/U/FbCzTjybkN+iKOkBuYFfNzObzpK6LX/aFJ03CSRGxPSI/Kld+YgL61UkC9hRd9Hx+KyGa8ymH2KYUxrEgAoHKsMP6yEFwYIHVuFxPZ/SmBwtVgtxvkTGEwADtXM3Js59r7pSsm92UI9R75mF24lW2tg/eLJT30gcH4ORdiFarNgCH0FlTeRLRtq1ltNIpb2LHyotakX7NyrLMVG5q13YriAEdrNTCIYi569/Dw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:20 +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 v2 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 a2da5740b0..a53c2d04b0 100644 --- a/block/commit.c +++ b/block/commit.c @@ -38,7 +38,7 @@ typedef struct CommitBlockJob { BlockBackend *base; BlockDriverState *base_bs; BlockdevOnError on_error; - int base_flags; + bool base_read_only; char *backing_file_str; } CommitBlockJob; =20 @@ -124,8 +124,8 @@ static void commit_clean(Job *job) /* 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(s->base_bs)) { - bdrv_reopen(s->base_bs, s->base_flags, NULL); + if (s->base_read_only) { + bdrv_reopen_set_read_only(s->base_bs, true, NULL); } =20 g_free(s->backing_file_str); @@ -264,7 +264,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; @@ -283,11 +282,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781461720428.05635207515616; Wed, 17 Oct 2018 06:04:21 -0700 (PDT) Received: from localhost ([::1]:36543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClUj-0000gw-Bw for importer@patchew.org; Wed, 17 Oct 2018 09:04:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005ID-7Y for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006Y0-3a for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34313) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yP-Cx; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lQ-Ik; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005kg-CE; Wed, 17 Oct 2018 15:57:38 +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=/JMVMiejGi+2TIO4Ik/F/hGXLUN0ZLZRqbPBKQZjAAE=; b=DJMgQixn0LuAKyC3XWSXiZWAvsYrY/cA77P7XosmgR132CpSM1n6DJbS/iBilnICD5mbUi8xRbRvwyQeaxwDqG1BKlLGoeM9mhDbqxSdOOH8Y6Zzn9Yh+PYiJ8ZXQZjky4V4UyoNjBaN3rLs3DOuzWAg9pZh7MJQ4uyJPsDS5U01S32pPZHvhJSqVZN6UnwQBD2DWwlpg6jYN+OrnHBZeGD8TDafa5TZGLqUIH0O/4DkTq5STgAOHxmGooOwk7+8GqEImOzKOXo9IN8Hesew5YkOhb4nUgJSPGFZx8Q5sKygiMkf/GR75I72JJDEggSYUcspmfXe2QRuq7ugc+h2nw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:21 +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 v2 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 a53c2d04b0..53148e610b 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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781646840111.9846331356697; Wed, 17 Oct 2018 06:07:26 -0700 (PDT) Received: from localhost ([::1]:36560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClXp-0003DL-Hx for importer@patchew.org; Wed, 17 Oct 2018 09:07:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IC-7W for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006Yq-8W for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34296) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yI-Cp; Wed, 17 Oct 2018 08:58:35 -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 1gClOe-0000lS-HR; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005ki-D5; Wed, 17 Oct 2018 15:57:38 +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=FNioFclFDkK09WIoGQHGUlBh68V6ADD5h4TqK/JMjPM=; b=dZnLrT/q3SJ2j/SvmRo7m3bWZxWdo+z3rw6tZJpPz+Ut4UL5LpUs6SWqHGowDngUxeOou+7HT4tZZ+S3STlwBiDTBSF3NzyWdaZ+rdvtuKgLZLAywvJ2X7tv3sLsvN2jKHiE009C0SOsOHvzPJiv/eYL3aJvkI/FDrmDWWeVCfBTNnvkIUOCFdMfbqyiAQ90XT3h2vr3GLG9cLhL+AKLyKL2rKJW7LH6nq39GvtHMRmtTQWYIYrdPs+oLQwHTLaWB/19+jfpEbCDAaf77pAVx/WW/8IFfTDV9bKGUt/KBsH1vlcnocgGZU6qUTWW9qvHYa+BTrwCcidBkvpfj1wl1w==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:22 +0300 Message-Id: <06146e6783e39fe6a3a5a4e18d379abf01216fb0.1539780785.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 06/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 81a7ec8ece..262d280ccd 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, @@ -89,10 +89,10 @@ static void stream_clean(Job *job) BlockDriverState *bs =3D blk_bs(bjob->blk); =20 /* 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); @@ -226,12 +226,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; } } @@ -261,7 +261,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); @@ -269,7 +269,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781263136665.4773402672784; Wed, 17 Oct 2018 06:01:03 -0700 (PDT) Received: from localhost ([::1]:36524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClRZ-0006jk-Fk for importer@patchew.org; Wed, 17 Oct 2018 09:00:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IG-7h for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006Xp-5A for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34314) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yT-D9; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lT-GA; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005ko-Dx; Wed, 17 Oct 2018 15:57:38 +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=Ivx2YkR0hmEcXyGq/m2nT5rENX6jDLMgKzukRWaKA3k=; b=rVTQVPV5RsCPLxiBWBLMvx8GAkNxx/dz+XCCqh/h1X581pEHXR3KncLotdDHA7Q1Iigxlr6HhKNkQOw9zc5XIYb8k8so+xBPK1mChmSCouI782sTHrji1vIp3BDJwFDtro8BDV95S+Kpz8ehLS71B9HLkUAsgpY3fuLeRtpfUBQ6VGz3bAwVNE8ChTZ1MIxMwGW6tK45gP2lflksOs1xUriU20o9Mj0z0a0bal+iT6e0PJHnZZ60MSwJbCVzIK+hdUSUW3CSgp+am9mXGDuGKJKNLwml0f4DCgQOMXAmWSM+LvDef4zOwbKESKssLjozt5VcYLjdm4QF0cwB6Nhklg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:23 +0300 Message-Id: <9c4137858b9a012cbcb87441465ecba2e97ab13c.1539780785.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 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 a8755bd908..f64569795c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4064,7 +4064,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); @@ -4106,13 +4105,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; } } @@ -4128,7 +4124,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781335105720.7898534664569; Wed, 17 Oct 2018 06:02:15 -0700 (PDT) Received: from localhost ([::1]:36535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClSn-0007jD-Oz for importer@patchew.org; Wed, 17 Oct 2018 09:02:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005I9-6x for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006XA-3u for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34299) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yH-Cm; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lV-Ix; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005ks-Eo; Wed, 17 Oct 2018 15:57:38 +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=i7iscOvcYdMMyr+HmIfslyQYd/2MFtqOuSXY6wZAUA8=; b=VfiHzkDZpCvXabmAIe+IoXHbKINctqZFmIk7EciHaBLMVKwQBfPovhomRtHiqx2aLjLrZvlm7VLwXNDbcSGDrn8Xlh6xKAsLAx+ESnmn7YROl81/xJneuSMX/BjPretPQ1HCFMzrx2usB7+JZpyK8WXSB7YodQ2kAjwKw873hNiNMF7QK1/78PpOeyhRYE4BY1n7iYKTwM7n/UMH0eR4DcU1CBf+RuHr5L+2u4pOLhxUHoW5cVSNvnwiKvSQM5OYEWpKbXRYHel8QXtPFllFe1/6Ksc5wQXlQbgbYZLn7LpdX0cUw7+9cGpdWEgkxKrh6uszv7b4GzZ6gJnz4C0M+A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:24 +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 v2 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() call 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 f64569795c..7a57572e1a 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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781767391692.4182585047391; Wed, 17 Oct 2018 06:09:27 -0700 (PDT) Received: from localhost ([::1]:36574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClZl-00052t-S3 for importer@patchew.org; Wed, 17 Oct 2018 09:09:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IJ-8O for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPH-0006Xf-4Z for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34310) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004yS-D7; Wed, 17 Oct 2018 08:58:34 -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 1gClOe-0000lW-Ez; Wed, 17 Oct 2018 14:57:56 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005kw-Fg; Wed, 17 Oct 2018 15:57:38 +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=pdhIZ/yfkTNq/nmVJEisNfcDBHeyBDS+XZfduNhz2Yk=; b=YhHf7lXLc0SfBz2tL5C/nhWZNU10SgtYFHi8LCSbsNLaa+HDDR5UnCCWlF0i0JeuMgbBvhh4HjmsmwBC8pJeBkqZAVRWS5TlylqusGWblIpQLwN/j0UVlhG39k1aLDQ5Ujv2pQUQ3v1NEAf53QOKaAPDb6C1A9Y1l0fmxMIy27dRUDyfxcdBN1M3a2vCAErG4oeb3LJS46dl2syGNfhEi5LdWVVWR2S384npB/lgZPl/7V423r/ijDq52GNvRWWEb0FLNwuiZdIxvmugBy8u8EqEEsZSGjFn8gsphgj/OmFpPbOa4MBf4MtfkS9swdDa6ZfPSw78G/LYougzlxv0+Q==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:25 +0300 Message-Id: <8cfa521a9b969060c007d94c60355d42a0623666.1539780785.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 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 , 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 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 56d9ef7474..41b6cbaad6 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -672,9 +672,10 @@ static int mirror_exit_common(Job *job) =20 if (s->should_complete && !abort) { BlockDriverState *to_replace =3D s->to_replace ?: src; + bool ro =3D bdrv_is_read_only(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); + 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 @@ -1692,13 +1693,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, @@ -1717,6 +1720,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153978173398822.70414843062497; Wed, 17 Oct 2018 06:08:53 -0700 (PDT) Received: from localhost ([::1]:36567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClZE-0004YE-LL for importer@patchew.org; Wed, 17 Oct 2018 09:08:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPc-0005bG-WD for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPW-0007Vv-Va for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:56 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34318) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPV-00050E-AP; Wed, 17 Oct 2018 08:58:50 -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 1gClOg-0000lX-7M; Wed, 17 Oct 2018 14:57:58 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005kz-GT; Wed, 17 Oct 2018 15:57:38 +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=YNs4z2c+ZaOaqkLIjI62K8Uxg2MJjU4C/Ugh0rciv68=; b=Pok2NuoHCzz2zypHAVIWQ1p/RVxuYA30ig5WCR4aQC98c3hCIksF4MKsK9f+1LXk8aOAvwgTd8JJMMOeTbZqhzORanUZhvgMzMj1LwNG2po1EdnyFos9JNmhufbFPgpKj7KUAeRALa08g1+GQ4Icn7KMmaWYiEdE/G6qbX3eO5oeNw84JMeCX5ewGEodISNeNDeOkE5hnCOXKfN5BH5fpY8atNqnrDaeS3CtifHSJ+j+c3x7/iSoiexd2sXUIcuSSC4IQpCTvftVlWiJkiSdJiwt7/0sA+7P0n+tAvzm7pzzh+6LZwj/IP7en7VXKT/ruVpg8bJX7jzlwANT5gjGNQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:26 +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 v2 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 39d40f4556..406c2d1da7 100644 --- a/block.c +++ b/block.c @@ -3077,27 +3077,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 97317fdfb6..3649136689 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -300,7 +300,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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781818012793.8985449422408; Wed, 17 Oct 2018 06:10:18 -0700 (PDT) Received: from localhost ([::1]:36590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClaZ-0005uh-7x for importer@patchew.org; Wed, 17 Oct 2018 09:10:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPL-0005IF-7j for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPG-0006Vg-Qo for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34317) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPG-0004zL-Co; Wed, 17 Oct 2018 08:58:34 -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 1gClOf-0000lY-TL; Wed, 17 Oct 2018 14:57:58 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005l2-HV; Wed, 17 Oct 2018 15:57:38 +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=TyOmc1EJNdTIYj6mt1Zu90Nv1TLZ7Igu33rACBsT2BQ=; b=KeNZonNGJOsiECwwWsBrg4rd67Hyy7g1WmbFjctOsh2sodHRBi083ZW/6NkftIPrwQ9p0Q0M73EfQjNB5bmIzYoFhuRfEB0yr4RKDfMThdbCw/gx9wz/+VhJe088NJTouCx2xrNyxd8SgbJQBhUxt6M7x3xVmgZjZKBDtD1ZeoNh2TbB/M5f3QIfV+X0bbnnGKRVEpkAA+6aElITn/1zeSrFIQEbWq+ocmKFHLU2i/8wd/8djkwTKH40d5TbB/cgW/rLN6gKGT/9FM6t7WAJhCv3jtyxGfEsPxfyorbR/QE758slQJh+Rftfm78pbgXpJo6F9DE6kdRObwiy8HXFqA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:27 +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 v2 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..b49a816cc8 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("Cannot 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("Cannot 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..3cbe72c42b 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 corresponding 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..aa8cf19f9e 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 corresponding options is fo= rbidden =3D=3D=3D + +Cannot set both -r/-w and 'read-only' +Cannot set both -r/-w and 'read-only' +Cannot set both -c and the cache options +Cannot set both -c and the cache options +Cannot set both -c and the cache options *** done --=20 2.11.0 From nobody Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539782042597428.41121212175335; Wed, 17 Oct 2018 06:14:02 -0700 (PDT) Received: from localhost ([::1]:36618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCleD-0001W7-Eb for importer@patchew.org; Wed, 17 Oct 2018 09:14:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPe-0005cO-6A for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPc-0007ol-Va for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:57 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34334) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPb-00053Q-Ae; Wed, 17 Oct 2018 08:58:56 -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 1gClOg-0000lZ-Ac; Wed, 17 Oct 2018 14:57:58 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005l5-IL; Wed, 17 Oct 2018 15:57:38 +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=gbG3mENkNRy9ti7QBrR1W/Ec9DhS/kVAntxwCF7qvwg=; b=ndHaXvEoJzUCVdw0k/1Q0haVLrYlB+GibD8Ieh5Yeq8TUmDdQSEgmvGJFEnwuecZHbkS9wYRnLBI/kjaozpWBhtmkYNYT9fojIOuxh/T2qkHdgRChZhs0eTF/qCZLAy+zT8qsb6DfoMhYFCibyOC1PS5SRGp+w0MIFy7Q6H+EZeWpzKGchuvj3z036iv1OoghgECcAUTePT9Jr2yjX+dSGDB6D4LVojWZpqfUEX4AWy6iCJr41JbiP1wj4wX3SKpYpZq0YUxsnDzbVHAqtua7PiZSMSSPsnzIMdLdWzgl2v8neBjYAgXIUzCBn111C6RSvzndQeKYw8Z5ACjQp3CUA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:28 +0300 Message-Id: <0e1d74777717cac492cd68bc88cf4ec29936e403.1539780785.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 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 | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/block/replication.c b/block/replication.c index 6349d6958e..481a225924 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 @@ -371,44 +372,40 @@ static void secondary_do_checkpoint(BDRVReplicationSt= ate *s, Error **errp) } } =20 +/* This function is supposed to be called twice: + * first with writable =3D true, then with writable =3D false. + * The first call puts s->hidden_disk and s->secondary_disk in + * r/w mode, and the second puts them back in their original state. + */ static void reopen_backing_file(BlockDriverState *bs, bool writable, Error **errp) { 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_is_read_only(s->hidden_disk->bs); + s->orig_secondary_read_only =3D bdrv_is_read_only(s->secondary_dis= k->bs); } =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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781907436536.3254624173951; Wed, 17 Oct 2018 06:11:47 -0700 (PDT) Received: from localhost ([::1]:36604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClbw-0007FX-IO for importer@patchew.org; Wed, 17 Oct 2018 09:11:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPe-0005cS-8w for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPd-0007pN-14 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34321) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPb-00050s-Ad; Wed, 17 Oct 2018 08:58:56 -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 1gClOg-0000lb-H3; Wed, 17 Oct 2018 14:57:58 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005l8-JP; Wed, 17 Oct 2018 15:57:38 +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=0yz5zdrneIOwK9YOwLBgt+vEvN33B/ZA/Y7IuWBh/9s=; b=R1IaiwzOUzZyt1MFIgt8yKyBEnKfL849jHJiJDA+fCmf4zWw8jRwH54enfVSpVPyeNy9xmZ4+JgJhTRSDSuP42HNr21MyAREtVg+c4FfmkKoZtKDba5//F8n34hg0TAm0uD5ZHPDfpBKJYNfUGY3bjh5kvWKBEQ+P0WlXfVJWPt4SlGbfDoevEp1BianaIpmCxZzTQnoBLL4b9WnlY+Lki7ly5JTjSc3WojSC4Vc2qe6P0GWzX5Ng3rhR/ay5udOwoFTi91l6vpJ//jyW3vrns4ieTHeb9M0PaoZ13+CQnYGN+CBB0Tj3ky/KdML2f3gPTcf1MnB0POnQo+qPeGFPg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:29 +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 v2 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, 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 406c2d1da7..194200908d 100644 --- a/block.c +++ b/block.c @@ -3012,8 +3012,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); } @@ -3087,7 +3088,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 481a225924..fdbfe47fa4 100644 --- a/block/replication.c +++ b/block/replication.c @@ -393,19 +393,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 3649136689..38d5c1adf4 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -297,8 +297,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 b49a816cc8..e272e5c80b 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 Thu Nov 6 06:12:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539781975136286.3180504680489; Wed, 17 Oct 2018 06:12:55 -0700 (PDT) Received: from localhost ([::1]:36613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCld2-0008PY-Ro for importer@patchew.org; Wed, 17 Oct 2018 09:12:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPe-0005cb-GJ for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPd-0007pW-1e for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPb-00050u-Af; Wed, 17 Oct 2018 08:58:56 -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 1gClOg-0000lc-GN; Wed, 17 Oct 2018 14:57:58 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005lB-KJ; Wed, 17 Oct 2018 15:57:38 +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=wcp2s16wL8S9kjrJRlkXgo7DAE9dsk3DUsM6QAuiNvo=; b=gIByc1a3Wp4o0Bxc1W5fcpYXz6UDgMXZ+0x/vLRTzvOJf/qJdMqJn1KCoUG6hdCXn4emWJpLghD0HLYrSg55ZXz0XyyaRpSNKe/t4up8H5uFqJ+KpUAN3LgxDdUvVS92CTJG6LO6dMZ9ApXRKhbIsC+2KQ+wAKx5dws1BrqUpVDIwK0Lc6n3aZHadyjQy/gxZ9qV5Vyan7CcJOGoPRD4xN0lMF4Zsq0sdjsbm7mwOUhvmAvzy6X1EQHrN92MCpCu1bLtrLRh7i0YHpl2ZIDu70bRkmKW5ua0QFO4dWBdDmsS03yi0OB8peRQ1bMc85MrLubgk3obGTzqoz1lDZ151A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:30 +0300 Message-Id: <8bbea9f80f6bc15005f18a4065e86eda1b17dd5d.1539780785.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 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 | 62 ++++++++++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/block.c b/block.c index 194200908d..810b4083fe 100644 --- a/block.c +++ b/block.c @@ -2876,7 +2876,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) @@ -2885,7 +2884,10 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, =20 BlockReopenQueueEntry *bs_entry; BdrvChild *child; - QDict *old_options, *explicit_options; + QDict *old_options, *explicit_options, *options_copy; + int flags; + QemuOpts *opts; + Error *local_err =3D NULL; =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 @@ -2911,22 +2913,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); @@ -2940,23 +2931,10 @@ 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); - 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. - * 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); + } else { + flags =3D bdrv_get_flags(bs); } =20 /* Old values are used for options that aren't set yet */ @@ -2964,6 +2942,20 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, 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); + opts =3D qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort); + 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); + /* bdrv_open_inherit() sets and clears some additional flags internall= y */ flags &=3D ~BDRV_O_PROTOCOL; if (flags & BDRV_O_RDWR) { @@ -3003,7 +2995,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 @@ -3014,9 +3006,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