From nobody Sun May 5 18:11:12 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 1539952495212705.5103324194113; Fri, 19 Oct 2018 05:34:55 -0700 (PDT) Received: from localhost ([::1]:50002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTzM-0003tG-13 for importer@patchew.org; Fri, 19 Oct 2018 08:34:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rI-Ra for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-000062-7S for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51808) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074l-2i; Fri, 19 Oct 2018 08:26:12 -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 1gDTq3-00081V-M3; Fri, 19 Oct 2018 14:25:11 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002L7-Iz; Fri, 19 Oct 2018 15:24:51 +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=KBXYE9JW9aEGhZqel72OCbeuUWTlfH6Wod2j7xWMTDQ=; b=qxwsJhQfBeoj5W6xnhgpNrIVKjL9zND3guveoo5QwbP7Db5kapYDUzWZLkF9iaFPlskME6DvkBaTUI2VyUMb/cunOlzkwh1ajBygpXgP5L7Blw3mEZIfBd5DYRAIumK/EqvadFym4OdBQsM2bgBN+w4V02TJpRzDyWNqhWknkG69T6HKLhcr9FKFReZ8Pqik63pQ92CuSPzyBIvHRT6jhxOC7kZJGg4a/F1eNrcNUDtaybKabaZ0VmWkZzRXAddqoB9bpYf8iDl0zqXBn3SF/TUcsGR+LRjuaCV29FM4BuT/JuadD7ZUPyNrhLrZ94UjsBqDkAmyk14szq1jN3px6Q==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:32 +0300 Message-Id: <53e27da7d9cdc008c5601dd62b7f22d0086b40bb.1539950487.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 v3 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) 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 7710b399a3..d09019d9c9 100644 --- a/block.c +++ b/block.c @@ -3091,6 +3091,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 Sun May 5 18:11:12 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 1539952295817732.7222231375973; Fri, 19 Oct 2018 05:31:35 -0700 (PDT) Received: from localhost ([::1]:49990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTwE-0000xA-MZ for importer@patchew.org; Fri, 19 Oct 2018 08:31:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004r4-Nj for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00006l-4F for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51783) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074T-2E; Fri, 19 Oct 2018 08:26:12 -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 1gDTq2-00081C-Cd; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002L9-Jz; Fri, 19 Oct 2018 15:24:51 +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=rzrHxJMsUbDwZTgzpLBGhcnQsXTSGZXLXdSuD5SZhSM=; b=Q4xT5+IZaxrST4tECxNcehR1Xm+UOgtTQz9pd5nKxcW+QzG+uSKxNbxdgpIyBtmEI8WNsRbzamLmT3Auc18/+/+fX0Z9/sj9ZRXiH9hdfye5iy0PXzO731EEN8SbWFetdVMxI2vd9C9js4gN0QPvHSYSOdLGMoBVv5nswGbUb7/llUCg2UEcj9H6mYgG8GZDAQmoUsnzfCobmZuZIAuW+ClP9RWaBG3dRpKO7+BPdYlicwbrio7IHGoXhFeGpyZqSvH61btss3OL1MVIRky8pXfBy4n8W1mmcDhHrj+wD7rMNANklYEvr2cRFLwjH1h8Rr0BxQj/C6FJihLsREDVDA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:33 +0300 Message-Id: <2ce98dc17810cdd4c0cbd4cb061cf592ec543a54.1539950487.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 v3 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) 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 d09019d9c9..744509f683 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 Sun May 5 18:11:12 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 1539952499852799.6368040466638; Fri, 19 Oct 2018 05:34:59 -0700 (PDT) Received: from localhost ([::1]:50004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTzW-0003zK-Pe for importer@patchew.org; Fri, 19 Oct 2018 08:34:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rA-Qh for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00006U-Ah for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51790) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074X-2G; Fri, 19 Oct 2018 08:26:12 -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 1gDTq2-00081D-DN; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LB-L3; Fri, 19 Oct 2018 15:24:51 +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=NYNbriiSe7akPc8H06MhwBIDwIKHN4X+MrJfafmnsTE/Zov2jYd7qjwauGvxSY37ucEFoSDXjSAYj7i4ujqZ2s7XEtapnaRd2ujuwb+UPBvKJVMx9A+PSKe2GB1GmkoO6Ol4Amh7mWCyI6Uq6v4syXvnH9+8XooGl2wtEBQbb7CJMgWThZoaiGdPJzuB6FZKGKsjOo0tcqxVAXx/P7AoGHkzE9leIy1fzPKzIiG+zHl7Jp1KcAoXYWiU1oPY4xYpyCBNj/B+1+VVWLg8hgdylEwCvxYeCxrD8pRJdklPo7fD6kOotlJuP8d/B1p9kykCQbYVDGdAewuvyJE7odZPRQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:34 +0300 Message-Id: <7dacb1e9d0374de246dd4ae5c242c88c675cbb19.1539950487.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 v3 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) 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 Sun May 5 18:11:12 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 1539952348212940.2562587773243; Fri, 19 Oct 2018 05:32:28 -0700 (PDT) Received: from localhost ([::1]:49993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTx4-0001YO-UZ for importer@patchew.org; Fri, 19 Oct 2018 08:32:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rH-Rx for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00006D-9T for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51879) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00077u-26; Fri, 19 Oct 2018 08:26:12 -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 1gDTq8-00081X-H4; Fri, 19 Oct 2018 14:25:16 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LD-M6; Fri, 19 Oct 2018 15:24:51 +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=shbMMrEj4XfV9J9/59SlpWGNJNsD8tXUah9O6E/N8JZ9SRx2K+pYm0duJcBEk0KVeTMjmu+Noz0s2QfSBUgX7kSsDFQ2+RPgsz2ql5QxcFLPgqKkqxhXHleEA8OFfiOJLhk3wufSNAxFo0zNBkOia95XwU5gWvVp0yulLRYLS9IbUe6TV4UTPMljROpE/IkxBLb4a5qc9UXeEnduiuk/6L5FfZdQwkXzskbcC7wJgyeFVFIUYSyc+Oq2Zt0p1pOfQ4X2JTjdZ7whLxIKWe0gwbvZTMuwOiC05cN3e39CC6RfNz1rfi2kCtm6zcg70qJZXvUcEDw8Kb6XGr3WvyjaSw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:35 +0300 Message-Id: <4a1378135c5bfd2863ecf3e5dd4ad3189c230e77.1539950487.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 v3 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) 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 Sun May 5 18:11:12 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 1539952744602582.1808482299134; Fri, 19 Oct 2018 05:39:04 -0700 (PDT) Received: from localhost ([::1]:50030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDU3K-0007HR-0v for importer@patchew.org; Fri, 19 Oct 2018 08:38:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrU-0004ul-2w for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrQ-0000Sd-0y for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51788) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTrL-00074W-49; Fri, 19 Oct 2018 08:26: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 1gDTq2-00081A-AR; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LF-NC; Fri, 19 Oct 2018 15:24:51 +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=nNejUX0+5Xz8XZi+m3MlXX42JxfywjY78ZCEqz++ZSerteQfnjLaf8clbjwoU8oVymBlIXzkye+KJqPocm8WAmnvzSgNdfL5oFhjSe6xzxll1KGoyPCd/lsyNoczlwvTzSAZ/HRoARqKiE50zxDF7JrSzsLC1D+a26WQHP1+hcCyL4UEiFwKNqaYmqKMyC9Q7PJ5O/SN8B2GQbIpmXGZ049ARVTuMMXZaArTKDP29FdSSAY3CMJhWwYS952Q3hOo9Q72I/Trvjb+VvjtNJHrWfO1OZlU8eM5DsxoOu54SJETdz9T8OyiU1j4gkGY6KpXt2v3gZWGlDeDzKyderqR/g==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:36 +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 v3 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) 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 Sun May 5 18:11:12 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 1539952626180317.2458417536718; Fri, 19 Oct 2018 05:37:06 -0700 (PDT) Received: from localhost ([::1]:50019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDU1U-0005WN-Tg for importer@patchew.org; Fri, 19 Oct 2018 08:37:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrU-0004uk-2Q for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrQ-0000SK-1y for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51794) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTrH-00074Y-1v; Fri, 19 Oct 2018 08:26:32 -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 1gDTq2-00081B-E0; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LH-O7; Fri, 19 Oct 2018 15:24:51 +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=hcMTvCsoa/jUXZKMT/hGGXd99XjYkZ4cxD1uKLakFkqmGU88aF3FXdqsLRO1Qc8GxcoiYmANKurzsICyw+Z7tXnrFd+aSmkw3ThICMJ6FULH+sWFJdgNRLHqWQJ8s5QKeUIAkRE9Ni/w/IiNYcd6csDm3BDNN9kjv/MqiDHbukosvUCsBcin2IuI+aOOTOZpZ4XyqUwfaYUoPrQ2HHbCBsCdUe7z0CyT9YWqL4BhNoqTxv6St0HjBHcLbSi+a65+bvONlr5GXPnkzYDzMvRQP0IN8gXXtcTcw3/IqSmuBUrJHL/Cb26DVdjJCzIvVEZdd0tDGeDiXhpTHgmWWwvhqA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:37 +0300 Message-Id: <8cc178a07169242ad995973fddbebb7efde557b9.1539950487.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 v3 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) 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 Sun May 5 18:11:12 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 1539952550522190.4772097631453; Fri, 19 Oct 2018 05:35:50 -0700 (PDT) Received: from localhost ([::1]:50014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDU0L-0004cp-Ch for importer@patchew.org; Fri, 19 Oct 2018 08:35:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rK-T4 for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00006V-4N for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074Z-2t; Fri, 19 Oct 2018 08:26:12 -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 1gDTq2-00081E-Fj; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LJ-Oy; Fri, 19 Oct 2018 15:24:51 +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=l+k0BljGMK4zmMNFWDmS8kjjC6/OsJR1Euy2pN8dKFgiJ6eZKCx5+uVNzA90bItsoGrRwBWkhMbL5BppIC0+ZtWXozY+loYJ1AsRrZPpqetoH7/SPSydn6EW8LbDVE8dAjz1dDf8npfc/aVyKy4LQ9fj0myK6MHKFdZfy1KtXkyxL9x88O92dOBmzNwmK3MsMyBTUJmYXPuycuWhgNiYW1/M2PmeoXcOIOEPEcyVyC6tLdRDasBEULrNZCy8ZcMm/+qvonsf+NIksur02/bQKPzWHxlyq3Jni9fqpoAY+bxTa06MlrcLcTvDyvOtpD/XLpIx+SKsLienPC1HYFjPVQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:38 +0300 Message-Id: <06050581abb10c9cd3006a59b58a1ed15150e502.1539950487.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 v3 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) 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 Sun May 5 18:11:12 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 1539952120637325.3573580047349; Fri, 19 Oct 2018 05:28:40 -0700 (PDT) Received: from localhost ([::1]:49963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTtP-0006xp-Dh for importer@patchew.org; Fri, 19 Oct 2018 08:28:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rO-Tl for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00006u-4L for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51786) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074V-2B; Fri, 19 Oct 2018 08:26:12 -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 1gDTq2-00081F-D4; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LM-Pq; Fri, 19 Oct 2018 15:24:51 +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=HbH9Jd2yiYtSrrA+vWkYtK+e6TAy+JP1FXo2pnHS8VmxPjCveVLqt0y+lfOewd0eE8CVF3C5g9hLCtcWyQ9vd3+bcrmlHCDsLxGWGsYSz/vNemK5aetFVjvXp1H7oF/LZ8MF4q7+IB76ri9acV/QllMpYThhnUJk0RdmHfPN+cvVrq2QeDzEuWW5JIr40O6LXrONrwI+MSpBOV2K3TgPzKJttRTCVMfiwZaYyu3z9Vk1meN0mGjZT38s57xeFViZe8Uuw7kkdNWwlxDFX+37aV5y2R1sDAUUQepOXtAGG2rhYhV9UEzc9ZH6Se/2FqxkgHRDtJHiIZUwwDsaWo0sGQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:39 +0300 Message-Id: <27cefc6ff02cde03d205f0e0c883be0dd184f1a1.1539950487.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 v3 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) 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 Sun May 5 18:11:12 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 1539953177721737.3542400217424; Fri, 19 Oct 2018 05:46:17 -0700 (PDT) Received: from localhost ([::1]:50133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDUAS-0006J8-IT for importer@patchew.org; Fri, 19 Oct 2018 08:46:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrW-0004uo-1F for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrQ-0000TG-2E for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:41 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51797) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTrK-00074a-Br; Fri, 19 Oct 2018 08:26: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 1gDTq2-00081G-Fh; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LT-Qi; Fri, 19 Oct 2018 15:24:51 +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=3pjLhRyq98+jbNo43UsuuarviVK/NTtJ6zgwJCAUdWQ=; b=FIqOYffzXO/w04YGCOpwE2aZEB2C7Te4DSZF9aIiL6Hyuxvr7u/CxCPikGolhwhnR9UwVK5nD9OP/wEh+Me5GasGTmniOqdoaxigcOOog42egRi2DkVCSI5URnbTWV/Jf1y9AvZcAdQAcBGsFhHKX98OIN13t1LJUWIrmX6SGyyIn1dlQ1kJdffeywyDltkm7ZQ9fA1VLTuyuZXDfOFR7R4Xq9/Fe/bRzeYhL0UzybVRskbXaD/zK4xEiOkU2R3pDiz5/nr5K8nWElDjvJx8FngwO0isfi2kEsA3fJ/syVosQznMpCoyd/Gmn5BKZmkVPNlPVBq9qzyt5dT3c7ckhA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:40 +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 v3 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) 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 744509f683..edb880a66b 100644 --- a/block.c +++ b/block.c @@ -3070,27 +3070,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 Sun May 5 18:11:12 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 1539952431648443.26996543237794; Fri, 19 Oct 2018 05:33:51 -0700 (PDT) Received: from localhost ([::1]:49998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTyH-0002xI-BE for importer@patchew.org; Fri, 19 Oct 2018 08:33:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rN-Tg for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00006Z-8L for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51782) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074S-2O; Fri, 19 Oct 2018 08:26:12 -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 1gDTq2-00081H-F2; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LW-Ri; Fri, 19 Oct 2018 15:24:51 +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=CYblKd5sPQta9ntoclRvPW3DFLt4kcofCskaBXPE2aw=; b=hFwejHi4jkRFwzltlY5ombRbmGqPzql4lZuA5PsegaV3obyp+C0ESdrBeTMPQJbCx1byA1XYL/Y3PkZeshlGKk7dG6iOMn+BlTCVjeC762b2fAlwhCbrnWwek8WzHwC2lO1LjYolDzaz5ciQRay6L8CjlVDZea+l22bey57VCZmH2YpWTZ6T5ECvsNvSUtQ2ADeO8P+y66r1+BCUJNZbJsbeXaBhAxRc0ZOQ6L1C3Ao821rY9rIJ74n5pDBzkVcjttzC1NjgarCoYnlU3t+1XyQnhQW+oM0zdcassXRBuqyfuzbT1kmk/j78olKHNSk5UzewU8I+TXijC+98ab3wyw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:41 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 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) 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 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 Sun May 5 18:11:12 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 1539952295410380.66708996711327; Fri, 19 Oct 2018 05:31:35 -0700 (PDT) Received: from localhost ([::1]:49989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTw9-0000sr-RT for importer@patchew.org; Fri, 19 Oct 2018 08:31:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rM-SR for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-000069-7c for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51802) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074d-20; Fri, 19 Oct 2018 08:26:12 -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 1gDTq2-00081I-Ee; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002LZ-Sb; Fri, 19 Oct 2018 15:24:51 +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=oD6t8+MVg7kJqnAxYkGtzy94+iboiFVq8MIShK4xw+WLJ0C/B0AjTu90KJVHcNLA3lexT/tF22PkzJESUuwDK4MWysBL/u6C9EY/Shh/POVoLH38yy438TSX1tL7aW2e+L23Rmtj8JfLHaG8l3urkpsRHGn3OrT4uTxScS/qwa4ssV+OGl5uFVrPLLA8DdeUgyM/9r++TEEFf1llH2Ctfm5FwNIybJmY5Q0OFlsiZcdFs0a++KTLp9qnh0XyI4JOgCl0ZrwIu3dCNc5wsCGVBdtY2yuBF9fcETTrjkHZPJ2i8S7vyBLAn5jVSaRa/RJJ6khiLKoD01yhil4cLcN5lw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:42 +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 v3 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, 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 Sun May 5 18:11:12 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 153995222393565.84582247779997; Fri, 19 Oct 2018 05:30:23 -0700 (PDT) Received: from localhost ([::1]:49980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTv4-0008RA-TA for importer@patchew.org; Fri, 19 Oct 2018 08:30:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rE-RE for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrA-00004z-CG for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51787) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074U-1y; Fri, 19 Oct 2018 08:26:12 -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 1gDTq2-00081J-En; Fri, 19 Oct 2018 14:25:10 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002Lc-TU; Fri, 19 Oct 2018 15:24:51 +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=kxNgy6NheQCg9888T8buM8L3uRBAkmNh/MCaev/4HUE=; b=QOGvzmYconkdAQYZc7yIoZ7k0kbS+bNG/9MnVa7mk/wHxaFA8YY07UuKrUwsjfpRuftOD31AG8Fx5Byga2Y/Gob5JjB5vTIQkJYKQDOc7E19pkICBnC4oOMLtaHSZScjYbj6qpx4EjBXptEVLznUpNh1FqJhBpuLUbSqy/YA+K3QmcRh7sPEDnn7uaDcNarFwatLDxPUYEBlH4sXWMHcqOgtqBCybIvOVmRUP/7XPGnAAhAfIMcJ7Gl3QwB09KpPnTlfOagoWH7u+2Gf4IG6R6RFlIyTVjjeDqFs0dA62g5S22ZN8qCcIPAbqCYEt9emhySq5EuZDGFZFYSUBng3GQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:43 +0300 Message-Id: <957510b568a46b46dba275643cda8321f6d6e8fe.1539950487.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 v3 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) 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 edb880a66b..c142773358 100644 --- a/block.c +++ b/block.c @@ -3005,8 +3005,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); } @@ -3080,7 +3081,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 Sun May 5 18:11:12 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 1539952850477216.10045527903276; Fri, 19 Oct 2018 05:40:50 -0700 (PDT) Received: from localhost ([::1]:50085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDU5B-0000lo-58 for importer@patchew.org; Fri, 19 Oct 2018 08:40:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrU-0004uj-2P for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrQ-0000S6-0m for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:39 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51814) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTrL-00074o-4H; Fri, 19 Oct 2018 08:26: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 1gDTq3-00081K-Nb; Fri, 19 Oct 2018 14:25:11 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002Lf-UH; Fri, 19 Oct 2018 15:24:51 +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=zghxbj6/kmSF0fXN9gM2ynrXMIVdtju+9gPGzDXOdsQ=; b=gNf+K3QHG1GmlWgHIxfqKIRtZEqh8rFgHA8g8OajUsSpb0ey3NwMY1PcBn7onWd6zE/QnhimNxom85Y1INXaJ0IIMWYjNH234d/894q5WDABNTx+rLR9p7dG5u4IiAm0I2uXXyYetRVCyR2rfTPfUyzYSDdN11IXLE6KJ/isqoJMG8kQGYpaMzoq3pfz2KOZwjz7nhe4B7X0QD0KW4KyKr42fea6f0QzBj7kMN+uBsLjC6kusuSyO91vYAIdjtAdp83Rtu70XsVpZmTdGpb6kMFHzZxXdGYuzFOCzqhwvM+qE1SAd63mBnZVzS2ah200KDCzp/sm0acGvx5iUpbNFw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:44 +0300 Message-Id: <1995f7b663b999bbe05b41ca901fed8aa432807a.1539950487.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 v3 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) 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 | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index c142773358..039f03703b 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,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 @@ -2911,22 +2912,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,16 +2930,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 */ @@ -2957,6 +2941,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) { @@ -2996,7 +2988,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 @@ -3007,9 +2999,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 Sun May 5 18:11:12 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 1539952692256514.1150124589341; Fri, 19 Oct 2018 05:38:12 -0700 (PDT) Received: from localhost ([::1]:50024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDU2a-0006Rh-UZ for importer@patchew.org; Fri, 19 Oct 2018 08:38:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004rB-QS for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00006q-68 for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51806) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074k-2I; Fri, 19 Oct 2018 08:26:12 -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 1gDTq3-00081L-Lp; Fri, 19 Oct 2018 14:25:11 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002Li-VC; Fri, 19 Oct 2018 15:24:51 +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=sLq3DxmHQZV+RBHNpxdyAZf5SSM2WtgA0+tmvHJWpKI=; b=bb51bC1DXNLOFkMY+ANxWLXvnrz/3kDccmoiq5dbAbkoiD4lM278YauHlAmr/4DX4tWCNjCWh7K8c19nr9GiSFWRPXaAo49o3p0wVpRQEWrvJr8cJ/fu7kVl2FDeSiX5//3cmC2tAgoHG2UAK6KwEwNz7LgEbE3kOHjil5MTJH1jFI3nyhKR8r0mRp5z+eu5e48XkUx8RkEskYgu2EUDOfPjJe6WIekEd6u2WOb1BmZu6AUuCbddzk3Pbsyu924Un7hglreKqy11e7pe2wAoIM47wgPMg3ike6Ibbk5Iedk7sde4Qun+H6Ug2t2IPM++blRjH2ffmaI3T4OWfdCBaQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:45 +0300 Message-Id: <831a1397ea8cf39f5ac1776e5fce03ee4a1a1bc8.1539950487.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 v3 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) 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 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 --- block.c | 3 --- tests/qemu-iotests/133 | 8 ++++++++ tests/qemu-iotests/133.out | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 039f03703b..0a0de2dc78 100644 --- a/block.c +++ b/block.c @@ -1118,19 +1118,16 @@ 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; } 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 Sun May 5 18:11:12 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 1539952166564314.10328717028995; Fri, 19 Oct 2018 05:29:26 -0700 (PDT) Received: from localhost ([::1]:49975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTu9-0007bR-Cf for importer@patchew.org; Fri, 19 Oct 2018 08:29:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDTrP-0004ra-W0 for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDTrB-00005p-4O for qemu-devel@nongnu.org; Fri, 19 Oct 2018 08:26:26 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:51809) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDTr2-00074m-2q; Fri, 19 Oct 2018 08:26:12 -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 1gDTq3-00081M-NO; Fri, 19 Oct 2018 14:25:11 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gDTpj-0002Ll-W3; Fri, 19 Oct 2018 15:24:51 +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=k39cint+yiHeqF9nCC+izn0gOH3D+/TYCMJQCWY8EkU=; b=iV1R4GlbnNauecsd9TW+yKLg+AOiVgnGHR0S/W9nVaTGrcei1lZsZb6GsN2zw3cW3BgTtg+DQjfBuluNuNEAg++7j1GGM8m/NFKxssr8c0qsXrDv0Aq0jneS3cuXumaiA4WJ6JyAI88qyLhzSr85H63rMFHa9wuxsA76I+GGcv6FTwz1Q3TCk5AMjQJPe8QixPNo69vvpAsIbiuzRUT6CJ5AzY0cs1saUaZ8UIOoXLhQmvgjBbC+fsIytQsNecj7wTvqkQPvSIMa2BiNthxfRnEomWK+kH0f2jWRosPiyMLPoqsdbn/32F+mNHDexCRzBMgT5SKbv9wq8rF7nedyTw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 15:24:46 +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 v3 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) 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" 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 --- block.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block.c b/block.c index 0a0de2dc78..1d1cf3fb5f 100644 --- a/block.c +++ b/block.c @@ -3143,6 +3143,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; @@ -3168,7 +3169,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, "discard"); if (discard !=3D NULL) { --=20 2.11.0