From nobody Sat Apr 27 18:27:59 2024 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 154159601095240.765817754508475; Wed, 7 Nov 2018 05:06:50 -0800 (PST) Received: from localhost ([::1]:48082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNXl-0000i2-ON for importer@patchew.org; Wed, 07 Nov 2018 08:06:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSU-0003xe-4N for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSA-0002GC-W8 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:13 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56864) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNS6-0001My-P1; Wed, 07 Nov 2018 08:01:00 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRM-000644-60; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-00069n-47; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=BbAm30HsQ86eagc5hdyvsHgXpwDPW0Fu0J1iaqjrw14=; b=fpWBdeoBzMrHkML4n9mDIboVTFs/ML1s7nVTs0cm7oZtY6lKZUlxfh9uDHiXJYxO10laJ/kZ812iSLdeZ/1em1mwlbaym8m8m1Wf9QdjsUjqGkspz8OKgvTamuyty8iH6vLEdbkv6Ez4e8RR1JtMcd03dlk6CL6S5R6sr0xkzjNO4cXZghWusFbLNjJoCPOlyT14Cm5ZcPLItaFEpl5v1s2RKjF7ZJ6jZnUIPiZUPK6oopGs3JkYatna+6hrD1MjVR/utUlkPJxL5aURYx+lU7JM7sGyKcBZ0OIk1QnjUZIV14T7pfhpU9/ND16HdGm6tICsPqLpWGn+u6epRJzoHQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:36 +0200 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 v4 01/15] 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) 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 fd67e14dfa..4e82c71ba4 100644 --- a/block.c +++ b/block.c @@ -3127,6 +3127,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 7f5453b45b..382e6643fc 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -303,6 +303,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 Apr 27 18:27:59 2024 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 154159599934722.974789696884613; Wed, 7 Nov 2018 05:06:39 -0800 (PST) Received: from localhost ([::1]:48080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNXa-0000Wc-2p for importer@patchew.org; Wed, 07 Nov 2018 08:06:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSa-000425-Cg for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSC-0002Kp-W8 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:22 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSC-0001N2-HI; Wed, 07 Nov 2018 08:01:04 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRL-000646-Tj; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-00069p-56; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=lLJsW3jmrA8/rRqSP/2RJzJQqJtWJOQ/aaEypd+9XlA=; b=Z++7LbbGebiLlfD9n/3iwh4ODwiz+bbmlBk/cgkZv7Se4SJ7I4TEOwcIRJECSWhUrHN73SImT2aAqWXzKkcv6fqX2257y1qFdERAly9uOOpbL1qT+nOEC2cbd9OX32MiVHp2pyVsUeaqbZhkZV45kcIfOv2/KWuqZPN+93scHin8qcgJAXE7ZJzBYSrOw1l2GkGt1ona7PPPhv9kMJGDXe39dRUL/xqGMdfVjPO9qNmDC2HtYZWRykhEXUf6ZDjLJKXzqsB49jUFqLvSDYV9Q8cZ0eSSR8TE6QVtswlD9xAZw/Tb5MuDFKV5l0DE/l7MZIybxmYDLnToSQr5ccJ1dA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:37 +0200 Message-Id: <4874ec8fdd2859f1d1c9787a7b7ed2ba876a467d.1541595424.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 v4 02/15] 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) 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 4e82c71ba4..cfa53f7114 100644 --- a/block.c +++ b/block.c @@ -1079,11 +1079,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; } @@ -1095,8 +1095,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 Apr 27 18:27:59 2024 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 1541595832538609.6917248486398; Wed, 7 Nov 2018 05:03:52 -0800 (PST) Received: from localhost ([::1]:48063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNUq-0005jc-TZ for importer@patchew.org; Wed, 07 Nov 2018 08:03:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSW-0003xr-9j for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSB-0002Hc-C5 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:15 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56862) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSA-0001Mx-P1; Wed, 07 Nov 2018 08:01:03 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRM-000648-8H; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-00069r-62; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=19Ov5fheguogZYtvmgEGscVh0qZYm9xCtL7NsuwV1so=; b=lowtD93Xbw9My0Ygzph1XeMZ/ZLznbh8I4lKv8vPfDrsyUlWAFCnBF8yC2OW0Slp6j5IQHzeHnrkGCrqpYBpRyyJIiVod6g3hQv4pBGpRINne258l28ssqfDvu1t+I6jaDc6gybw2ySY88wnfgjooA52je7ZHPx6Y1I1rifWlsI8urwAIAY7ZVRkA3WXtWXk4hn3SIbwEgK0wpaNDl6Ij+ZRd+LBW+mPgC5KQOMwOHC8PWueom5JWC8CoZlch4eo2PZSRe+ML2PMjVCwIn/K5SgIoBleTmTgndNgWd4hl7mZlWcVXheRUv5i+5oT+foKTk4bIK6zsNhwkc1dFzRqcg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:38 +0200 Message-Id: <4fba673e8cdeffa724d6c2881c652bb7e34da67a.1541595424.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 v4 03/15] 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) 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 Sat Apr 27 18:27:59 2024 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 154159581828660.74694138982238; Wed, 7 Nov 2018 05:03:38 -0800 (PST) Received: from localhost ([::1]:48062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNUf-0005Ir-2z for importer@patchew.org; Wed, 07 Nov 2018 08:03:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSB-0003k2-5d for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNS2-00022S-Ua for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:02 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56865) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNRu-0001Mt-MO; Wed, 07 Nov 2018 08:00:48 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRM-000647-87; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-00069t-6z; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=/JMVMiejGi+2TIO4Ik/F/hGXLUN0ZLZRqbPBKQZjAAE=; b=PT0x/FKlePJfT2hkJpS5Ehewp18vEhGXuU+MUbpDmihxY5qKfmB7a0WZVAyi3H27/HmkWwMHXU198ciqZOtQYFUE7Qa+1O3d6WMFZao7/RHgebd0WmjPBoJjF6X8tvWX+rSBZuL9wT4gEVzQSSwFEDmIgR7iIEjnpNTw1lKsii+CJlibPzr+H7vtPTMJjUVZ5BukxCvoKe+pbHaNCU6g/VTgTzf7ryBH+Fq0QTf2YndcE139UgAoFHz5FL8sTX/o42r6puRP+vNlg95gAmxiBfBz70YMEt3dEXEdK//gbqjBf2ZwMBtcmp2ZUtc/nOxZRaCvxi8ExR0nUR1Y3fpHQQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:39 +0200 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 v4 04/15] 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) 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 Sat Apr 27 18:27:59 2024 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 1541596289347335.41611869949065; Wed, 7 Nov 2018 05:11:29 -0800 (PST) Received: from localhost ([::1]:48134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNcF-0006yX-TO for importer@patchew.org; Wed, 07 Nov 2018 08:11:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSa-000423-CU for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSD-0002Ou-Vr for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:22 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56878) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSD-0001Mw-Jq; Wed, 07 Nov 2018 08:01:05 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRL-000649-Sz; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-00069v-82; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=FNioFclFDkK09WIoGQHGUlBh68V6ADD5h4TqK/JMjPM=; b=jtz3l7ldpMUoA86iY8OG0Gk/n+PnCzsas2+tgPpubjVrK0MCHgz41jU7BleAU6eo+MasQyDrjASuZA6ti03PN60zy/71BzovyGduNHFHGwieKfj5/3taQHnSZ6PGCzZg48rcMOlrhTEeYxQOJbDoKqZyHkbB5rtAfVuTJE4rUGSoWmq3tY23r3M1HtB7+fB5W5nJIdVzzS3lMRzBBm+2MJ+LCSPqqk4xLSsNndB/Q4pGg6/DarsKgkNThs8mybpa+8FPYvkJM2StnxD3SldlcBV0Bim3P49WdzcE9V3eoeMT3vuFvb25MXG4WAHalJGnYqD7ZuBIQoioyoo6doiLkA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:40 +0200 Message-Id: <30cde364141d6421ab66f3666ef44c7cfd949ddf.1541595424.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 v4 05/15] 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) 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 Sat Apr 27 18:27:59 2024 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 1541596301364850.7030168978571; Wed, 7 Nov 2018 05:11:41 -0800 (PST) Received: from localhost ([::1]:48135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNcS-00078N-1y for importer@patchew.org; Wed, 07 Nov 2018 08:11:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSY-0003zi-Aj for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSB-0002IO-U2 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:17 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56868) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSB-0001Mu-I7; Wed, 07 Nov 2018 08:01:03 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRL-00064A-Qq; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-00069x-93; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=sXxvfZkTk930TafIassTrcmxl3mr/SZ18g1xT9rFYiQ=; b=mVxqodBkCec9ULrrrYt76/D1j7DnUqmpcNijCD74Viy7Mb98uamitsyLrYp3tgjiEEAsj5rACbd0f68Ekz4uGIFrfvD3UmF3pLDAHd31X2NYCFIBs+yhwIrbHMoG436ki43d3BswCVQyZm7ssKBNh1BNq3kBnPGnAhlc7cLAEfjt90IzdIL0E+eVUKeL3Pa6ihOlJYfULhJyzm9GRVzdjzgi203Z7LBABppwWQcdm4ZWXtpFv1SwPnzWTFhUNP3WRodItm/K4pMgn0xPcRFvbwuL5JpwU74aBjOY4uDHZq1GubjkJ9w1etgf6BFpQpXlDJwKQCKwUtUzvSP2+QDi3g==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:41 +0200 Message-Id: <534597ffc4007b2f5f3ccb1929dd52b36b036b24.1541595424.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 v4 06/15] 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) 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 e5b5eb46e2..20d1d84bab 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4100,7 +4100,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); @@ -4142,13 +4141,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; } } @@ -4164,7 +4160,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 Apr 27 18:27:59 2024 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 154159653012156.63518900589577; Wed, 7 Nov 2018 05:15:30 -0800 (PST) Received: from localhost ([::1]:48170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNg8-0004lS-Sd for importer@patchew.org; Wed, 07 Nov 2018 08:15:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSa-000422-CS for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSD-0002NI-Ni for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:22 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56872) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSD-0001N1-57; Wed, 07 Nov 2018 08:01:05 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRM-00064C-81; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006A5-A0; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=sQCxV5wyx+HLUIM978YCa6OcSm59PAfxWWc62jb/wwM=; b=Llc2nsBWNLa2hx2yVxuO1V6aPhThfbdpYpRJdwzjtQJ8INiNV6s71lh6FYzPHmRm1Jeo9JoKKPwFNzly3tshum1ozbDjtWCR39nf6uVo5SXCrhbEiTis6zT0LrRb/UjYxpUT/IG2lrync/4zCYnrp4IYR+w5svUyozv6qEy9gbcFp+9BrlXp4TdJ24OQt0fq8tQdl1gPM2qer5deCkfjhVwdMAr/Ck9Od067f6gfNd8+l98T+Y2AYoH9r9qi5jF6MVCGT6uBEIMxkdP9C4DwOX4H8K40zQxpTwcWF1jej+Lk+QtOEgplPdHRjdMi6RzfvRwrHc2pA+3T5L/8Uzjbuw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:42 +0200 Message-Id: <94e958853a46a70f904a9864151caccbb8612726.1541595424.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 v4 07/15] 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) 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 20d1d84bab..112bc62ae5 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1703,8 +1703,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 Apr 27 18:27:59 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541595780574516.7270966924008; Wed, 7 Nov 2018 05:03:00 -0800 (PST) Received: from localhost ([::1]:48061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNTx-0004cP-Dm for importer@patchew.org; Wed, 07 Nov 2018 08:02:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNRz-0003eu-An for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:00:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNRm-0001jp-7o for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:00:46 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56867) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNRY-0001Mz-29; Wed, 07 Nov 2018 08:00:29 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRL-00064B-S9; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006A8-Au; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=pdhIZ/yfkTNq/nmVJEisNfcDBHeyBDS+XZfduNhz2Yk=; b=AQTJq9l8u7Vmsc5ygNZq25HA+vCsOB7/ttyMXzZC0J+pV8JsWmMF6hKkHmwp1GeddANq+nsSFJ+M91cQffvU6cOc7LERu0AEfhEuaYnt8GcW6tkJWJupZUYqsQSgpa+uI5+DjrQxu+Vp7p0tpZ7dQB5ecXS2j6UzKCO3ra1e8Jo8OCV2I/qUl7SXiRM242Ia1hHpZ9xamFS1cF8R3zCqI8g33l8ZShdmTk59ScA6S4G999qePIZ4T5pBarwCwe1UAeGZ2Vx3rARhzJyTLrsAbJl04+yQbLq/RT+hKJjQm4UMJguELNJR6IPSBB7d7kXyHmxyyPUuBD4gcnHioHm5dQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:43 +0200 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 v4 08/15] 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) 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 Sat Apr 27 18:27:59 2024 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 1541595834047545.5601155311565; Wed, 7 Nov 2018 05:03:54 -0800 (PST) Received: from localhost ([::1]:48064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNUu-0005pZ-SP for importer@patchew.org; Wed, 07 Nov 2018 08:03:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSW-0003xq-9i for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSC-0002Ia-1C for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:15 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSB-0001Mv-LB; Wed, 07 Nov 2018 08:01:03 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRM-00064D-89; Wed, 07 Nov 2018 14:00:12 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006AB-Bh; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=lX5JPwcZT+jguJikOTkIZSHtHuswzEgXXxIEcBT0hRI=; b=iK/8OuZk21upwlnoQ8osAObMjMHEtRID5mUGicAOnWlxkhKwOYYD0aomYYe/8wyZe97dhsP0tzUrX8m13//DglGk3KQ1LOHY2/8eysqbFSf6+ugmt1k7DRcS4gB9soPxIKwjxenOHur3JDlCYXmU4KcNvJPBCJ9/l2o12m2dqssGHllyXvtk88ipjrcDyo/rJzdp2Odq6roIQJy8usHxbKtwdQjt9A7NDWl4v5WFbYkgM2XfIjfe5IhhEyH1UkwVVH+OMldC6jUJUNEcEB26K1ddNAW8g6BsDa4piHl4EhwpVbpHp5ziF/oafxarGTIa5XaKv1BYiGJW8Qif4CvchA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:44 +0200 Message-Id: <23fc7cf1ae15080a1a0379af219bdd90bcda5993.1541595424.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 v4 09/15] 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) 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 cfa53f7114..31de7b2299 100644 --- a/block.c +++ b/block.c @@ -3106,27 +3106,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 382e6643fc..de72c7a093 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -302,7 +302,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 Apr 27 18:27:59 2024 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 1541596160075505.3793373458652; Wed, 7 Nov 2018 05:09:20 -0800 (PST) Received: from localhost ([::1]:48103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNaA-00057M-N5 for importer@patchew.org; Wed, 07 Nov 2018 08:09:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSU-0003xi-4Z for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSB-0002I4-L6 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:13 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56920) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSB-0001Q9-8g; Wed, 07 Nov 2018 08:01:03 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRR-00064E-KF; Wed, 07 Nov 2018 14:00:17 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006AE-CW; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=pszytWaa59tnO/TME7ludW1YQOqi8egF/xgvck/IEZ0=; b=iBhCcUF+JpoPDSB+APqw+8beBfk8aqCVXkXKHgR9tbtjpLd1Y3xbAB40TdFEKOyeiu6n1IkwaxTvSb+CLHpczTpKgztmgCtClIvcyQreNcDnoDYXkJTls3Yeux3HOM/3Yqwf4awAD15o6Z+5/RdAV6lf5SbYuNXUlYk4S10iiMq2hd4PAcvCAx7guuxlin+/GPtibc/a3HuJhAihiHOkRSoiAnDkFL58nzIdoH6FLgXLmOaIgyPZzk4TeSc3bAWMbkhcZFTH8Ra4ZatC7VzdwUAP67Ex+EJu6qkx0akr+EiPdryLkhlXL2C3Uyllsc4cSP6CUuZmktKXqNHrcJKwow==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:45 +0200 Message-Id: <9f849af9a99edbe97e449843bb8c20f6aab8f6fe.1541595424.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 v4 10/15] 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) 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 Reviewed-by: Max Reitz --- 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 5363482213..c9ae09d574 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 af6b3e1dd4..14e6b3b972 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -92,6 +92,15 @@ 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 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 f4a85aeb63..48a9d087f0 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -24,4 +24,12 @@ Cannot change the option 'driver' =20 format name: null-co format name: null-co + +=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 Sat Apr 27 18:27:59 2024 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 1541596427443629.0410352261151; Wed, 7 Nov 2018 05:13:47 -0800 (PST) Received: from localhost ([::1]:48162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNeS-0002Xv-6k for importer@patchew.org; Wed, 07 Nov 2018 08:13:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSZ-00040c-6B for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSC-0002JJ-8r for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:22 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56928) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSB-0001QQ-QF; Wed, 07 Nov 2018 08:01:04 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRR-00064F-V1; Wed, 07 Nov 2018 14:00:18 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006AH-DY; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=gbG3mENkNRy9ti7QBrR1W/Ec9DhS/kVAntxwCF7qvwg=; b=Q+X/SDCq3BdlWunrig/fjD3IK/ILr3CJlBEhV5wORyfF1XZcgwBz0sKBxyvv08s3RfOgpRjwVIFg+OhmtGhVe+0koaBuwkf83rcX1hMkiik6mXawfrZeTx0qwqEy0KC8ErFBI7P4FvgnxzJ3+b+B68RqfZoa0Rl7VqUSOET54hJ2HwVbYxZ22ZTHxKyGvm9zAN4kAfpasptUNiqQJ+G9I2Uc0gv3fOzj9x6tErxLqFuHakAZSq7yvWfLEdxV+cXjvuO+A2BK/RqBLI2rgTVZO754IAG5A8kO16F4tX5Q5kEq8YPyHYkb85+firQGo6vcFtN6sXw4lAmJq9ysFKae9g==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:46 +0200 Message-Id: <37b20c1e4ca5ef29ec7fbba2fa62dbf7acc292a5.1541595424.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 v4 11/15] 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, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Max Reitz --- 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 Sat Apr 27 18:27:59 2024 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 1541596173011171.85408632065673; Wed, 7 Nov 2018 05:09:33 -0800 (PST) Received: from localhost ([::1]:48105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNaL-0005II-UP for importer@patchew.org; Wed, 07 Nov 2018 08:09:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSU-0003xh-4T for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSB-0002Hr-Gk for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:13 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSB-0001QD-0P; Wed, 07 Nov 2018 08:01:03 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRR-00064G-Lm; Wed, 07 Nov 2018 14:00:17 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006AK-EP; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=si80j0+y8BG+mybcl3i7EhEO4w6DcRaFnnpYykLWLDc=; b=lTp+R8jLL085sJhW2Zt+ND3Obym+g6pj1BdbAdN/+7o+JegFCtJkvQTEq7IQNlHFpsc6OD81tgmqiXAyNzCyp6Rx2i7KLBFaXmnQz4WRCcbgcUQnjaN10U7bOgd0Iyxn8xL4nFKDW0km4E9yLdi+lt3ViQflJ5siS+7uI80QwM8agqx9tovhY2weFUaxGzZbJAgqR5WccQzQ8tSL6drX0s5gVVpVV6hurcYrw6uvf+fWhNeXU9v7GeOphSDhlLkg4kXiteqBSIQ2KYxEGGjTctylf7MtdTUHEfsAZy0TqTeSsAZnSXQwgejciHgm8LK1IfjZb127Gie9t/0X12QmSw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:47 +0200 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 v4 12/15] 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) 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 31de7b2299..8b401e1cf4 100644 --- a/block.c +++ b/block.c @@ -3041,8 +3041,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); } @@ -3116,7 +3117,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 de72c7a093..f70a843b72 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -299,8 +299,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 c9ae09d574..2c39124036 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 Apr 27 18:27:59 2024 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 154159617143243.83140282461352; Wed, 7 Nov 2018 05:09:31 -0800 (PST) Received: from localhost ([::1]:48104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNaJ-0005HB-NY for importer@patchew.org; Wed, 07 Nov 2018 08:09:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSY-0003zd-A0 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSB-0002IU-V8 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:17 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56930) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSB-0001QT-JU; Wed, 07 Nov 2018 08:01:03 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRR-00064I-VP; Wed, 07 Nov 2018 14:00:18 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006AN-FJ; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ZYcIZ9Nk/+A6bgic5N5xNobT+lt3e34k9yQ/9YOOIKk=; b=Vn6aqp7F+OLJzm6CzPUyrBW3hUgAy09/mzcCI9dWVEyTaCxReyb6hodYypJWKcev5nxIw2y05e/Fn/zW+o/w5JOTemO3zyN5MQHkxLDNBpQ0hTTdIXYYp821JZqz6/C7olGcpbwzbhodjqMjvS0NgaY2kDrfnH4y6SflxR4vWcp45HPI/w9tipF6iteW27boFSkqSFk4/5SR+fGjinVpLW9mSKtBS8Ewj51B4J+1QFrJ+5R4eB38OhW3cXdIPqRDiJgXe5Q2FWgHV+1DVwGg7M0OG6dyQFzywvS/loelHgLhoQ1ZnF8kcH6fewo5vRW98Id51bf2XStD2QwNHH2zBA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:48 +0200 Message-Id: <770670edd5f78338a0a1c2fd040e41829a05b6e3.1541595424.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 v4 13/15] 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) 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 Reviewed-by: Max Reitz --- block.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index 8b401e1cf4..8bc808d6f3 100644 --- a/block.c +++ b/block.c @@ -2912,7 +2912,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) @@ -2921,7 +2920,9 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, =20 BlockReopenQueueEntry *bs_entry; BdrvChild *child; - QDict *old_options, *explicit_options; + QDict *old_options, *explicit_options, *options_copy; + int flags; + QemuOpts *opts; =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 @@ -2947,22 +2948,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); @@ -2976,16 +2966,10 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, =20 /* Inherit from parent node */ if (parent_options) { - QemuOpts *opts; - QDict *options_copy; - 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, NULL); - update_flags_from_options(&flags, opts); - 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 */ @@ -2993,6 +2977,14 @@ 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, NULL); + update_flags_from_options(&flags, opts); + 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) { @@ -3032,7 +3024,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 @@ -3043,9 +3035,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 From nobody Sat Apr 27 18:27:59 2024 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 1541596661553576.4083271235439; Wed, 7 Nov 2018 05:17:41 -0800 (PST) Received: from localhost ([::1]:48190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNiG-00066Q-An for importer@patchew.org; Wed, 07 Nov 2018 08:17:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSl-0004Cz-Ss for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSk-0002mS-IO for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:39 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSj-0001Qa-GJ; Wed, 07 Nov 2018 08:01:37 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRS-00064J-0j; Wed, 07 Nov 2018 14:00:18 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006AQ-G5; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=boKq2+vVXji4p9CkZFy7tO3z7+kMDKA7zwCmJUkWS6A=; b=X2DM5GQn8cKtvX2IDSgTI0UNcWeWskQ90yzHxjtobDEMislmUZnWte34UBtPigxCb0UA9Vm6xPiS7SYORu4juZEoox0rZeded6uqIhTVQBvlfKMB/QY4tCa3J7wvxruBq3erwmXzqU5JHPFEmua2uZKrRz8jYNc/6YKUVpcgnoKusEoeOtfSfx94BphdpqM88rLmz9U7kWJcZkN8AVaIWi1WDCJ4bW5OQwwAxBOvihhOqoH2HQfGivLPKSqwXEUZNN3XolPXoYJ6aGV2B8+Pam89SwnrYxoDu0YrdPiTizn3wBWBoezx3fuEfHtuuSAPcUX3tcuYjNKJmkuYl60TNg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:49 +0200 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 v4 14/15] block: Remove assertions from update_flags_from_options() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This function takes three options (cache.direct, cache.no-flush and read-only) from a QemuOpts object and updates the flags accordingly. If any of those options is not set (because it was missing from the original QDict or because it had an invalid value) then the function aborts with a failed assertion: $ qemu-io -c 'reopen -o read-only=3Dfoo' hd.qcow2 block.c:1126: update_flags_from_options: Assertion `qemu_opt_find(opts, = BDRV_OPT_CACHE_DIRECT)' failed. Aborted This assertion is unnecessary, and it forces any caller of bdrv_reopen() to pass all the aforementioned three options. This may have made sense in order to remove ambiguity when bdrv_reopen() was taking both flags and options, but that's not the case anymore. It's also unnecessary if we want to validate the option values, because bdrv_reopen_prepare() already takes care of that, as we can see if we remove the assertions: $ qemu-io -c 'reopen -o read-only=3Dfoo' hd.qcow2 Parameter 'read-only' expects 'on' or 'off' Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 4 ---- tests/qemu-iotests/133 | 8 ++++++++ tests/qemu-iotests/133.out | 6 ++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 8bc808d6f3..68f1e3b45e 100644 --- a/block.c +++ b/block.c @@ -1139,24 +1139,20 @@ static void update_flags_from_options(int *flags, Q= emuOpts *opts) { *flags &=3D ~BDRV_O_CACHE_MASK; =20 - assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { *flags |=3D BDRV_O_NO_FLUSH; } =20 - assert(qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_DIRECT, false)) { *flags |=3D BDRV_O_NOCACHE; } =20 *flags &=3D ~BDRV_O_RDWR; =20 - assert(qemu_opt_find(opts, BDRV_OPT_READ_ONLY)); if (!qemu_opt_get_bool_del(opts, BDRV_OPT_READ_ONLY, false)) { *flags |=3D BDRV_O_RDWR; } =20 - assert(qemu_opt_find(opts, BDRV_OPT_AUTO_READ_ONLY)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_AUTO_READ_ONLY, false)) { *flags |=3D BDRV_O_AUTO_RDONLY; } diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index 14e6b3b972..59d5e2ea25 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -101,6 +101,14 @@ $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 + +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 +$QEMU_IO -c 'reopen -o cache.no-flush=3Dbar' $TEST_IMG +$QEMU_IO -c 'reopen -o cache.direct=3Dbaz' $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 48a9d087f0..551096a9c4 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -32,4 +32,10 @@ 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 + +=3D=3D=3D Check that invalid options are handled correctly =3D=3D=3D + +Parameter 'read-only' expects 'on' or 'off' +Parameter 'cache.no-flush' expects 'on' or 'off' +Parameter 'cache.direct' expects 'on' or 'off' *** done --=20 2.11.0 From nobody Sat Apr 27 18:27:59 2024 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 1541596009249419.49479647518024; Wed, 7 Nov 2018 05:06:49 -0800 (PST) Received: from localhost ([::1]:48081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNXk-0000eo-1B for importer@patchew.org; Wed, 07 Nov 2018 08:06:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNSY-0003zh-AO for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNSD-0002Ln-GZ for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:01:17 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56925) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNSC-0001QF-S7; Wed, 07 Nov 2018 08:01:05 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gKNRR-00064H-NG; Wed, 07 Nov 2018 14:00:17 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gKNR6-0006AT-H6; Wed, 07 Nov 2018 14:59:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=BLea/m2abJOzIyafOiJmpl8Ry1teyFPmru7nkkdCYX0=; b=o1nEJ6vTa83MzAmY1hZIDBmRBfuHuWq7hbDQ/JIpjmu5TCbuKuA0HgbXOvXfm4O9CGhfXGpTNQKYNecudX5x/ADZ3jTNJK3tiOy8C5nU0jBkpotbvUrX6nd01vWmj41zmYF41hxE1RtxEm7RUQAfDCHRpRXwdK0+zNWdOXG6NLfLvUOaa6BX8Rvfh9E05xLg0Dg03kw/FC5XurJKMEJz6qxtiEv5r2bBXwMti9eRr8yR5SkFJHe24MGN6eKqkjcwqk6fXrjgRh5c405rV/OXci74X5BGWADuXEHVvNHOHwPXTU1djPXlhzYFe0FfKZXB5nYKXPZrmbGkoZ9wDRqrDg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 14:59:50 +0200 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 v4 15/15] block: Assert that flags are up-to-date in bdrv_reopen_prepare() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Towards the end of bdrv_reopen_queue_child(), before starting to process the children, the update_flags_from_options() function is called in order to have BDRVReopenState.flags in sync with the options from the QDict. This is necessary because during the reopen process flags must be updated for all nodes in the queue so bdrv_is_writable_after_reopen() and the permission checks work correctly. Because of that, calling update_flags_from_options() again in bdrv_reopen_prepare() doesn't really change the flags (they are already up-to-date). But we need to call it in order to remove those options from QemuOpts and that way indicate that they have been processed. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block.c b/block.c index 68f1e3b45e..03277b3d19 100644 --- a/block.c +++ b/block.c @@ -3178,6 +3178,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state= , BlockReopenQueue *queue, Error **errp) { int ret =3D -1; + int old_flags; Error *local_err =3D NULL; BlockDriver *drv; QemuOpts *opts; @@ -3203,7 +3204,12 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, goto error; } =20 + /* This was already called in bdrv_reopen_queue_child() so the flags + * are up-to-date. This time we simply want to remove the options from + * QemuOpts in order to indicate that they have been processed. */ + old_flags =3D reopen_state->flags; update_flags_from_options(&reopen_state->flags, opts); + assert(old_flags =3D=3D reopen_state->flags); =20 discard =3D qemu_opt_get_del(opts, BDRV_OPT_DISCARD); if (discard !=3D NULL) { --=20 2.11.0