From nobody Sun Feb 8 19:59:02 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 1542032022356756.4666020253769; Mon, 12 Nov 2018 06:13:42 -0800 (PST) Received: from localhost ([::1]:48845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMCyD-0006ap-3g for importer@patchew.org; Mon, 12 Nov 2018 09:13:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMCn0-00010g-36 for qemu-devel@nongnu.org; Mon, 12 Nov 2018 09:02:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMCmw-0001im-6q for qemu-devel@nongnu.org; Mon, 12 Nov 2018 09:02:05 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:57674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gMCmt-0001Fo-8L; Mon, 12 Nov 2018 09:02: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 1gMCmA-00074B-Rc; Mon, 12 Nov 2018 15:01:15 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gMClq-0007CR-6Z; Mon, 12 Nov 2018 16:00:54 +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=qbtuNeKBkHQ9CteZDBuGJdMw+FBWPGhiN7yAxVnvtG96/uuqk2f7oK8JohFljggvArTbGBjhBvGq3++l9rg15T07lOpaxFlr5ObzD32y71U4E4r7dY6YHdPsLv+n9Iuels5AvUQhy45XmxcyuMPR9Y74cDdtjhM7zfvbYLhT7rp/jZ9yMsCCMwZhIwEv6DtsveT8md0D9i/UWtRL3PJmPOsshJtTny9T7M/0wTvBl5k17S0o9dpCg1HwQkWsSo+mvsYf7YV+iQdFAHYOfVg6hJP8ssTMtFZ1n3IPiugjCX19sUNNUrhxoGcke2nQieir1QeP1uqeCW260S66QjFETQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 12 Nov 2018 16:00:33 +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 v5 01/16] 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