From nobody Sun Feb 8 19:12:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 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