From nobody Thu Nov 6 08:26:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539782042597428.41121212175335; Wed, 17 Oct 2018 06:14:02 -0700 (PDT) Received: from localhost ([::1]:36618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCleD-0001W7-Eb for importer@patchew.org; Wed, 17 Oct 2018 09:14:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gClPe-0005cO-6A for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gClPc-0007ol-Va for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:58:57 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34334) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gClPb-00053Q-Ae; Wed, 17 Oct 2018 08:58:56 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gClOg-0000lZ-Ac; Wed, 17 Oct 2018 14:57:58 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gClOM-0005l5-IL; Wed, 17 Oct 2018 15:57:38 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=gbG3mENkNRy9ti7QBrR1W/Ec9DhS/kVAntxwCF7qvwg=; b=ndHaXvEoJzUCVdw0k/1Q0haVLrYlB+GibD8Ieh5Yeq8TUmDdQSEgmvGJFEnwuecZHbkS9wYRnLBI/kjaozpWBhtmkYNYT9fojIOuxh/T2qkHdgRChZhs0eTF/qCZLAy+zT8qsb6DfoMhYFCibyOC1PS5SRGp+w0MIFy7Q6H+EZeWpzKGchuvj3z036iv1OoghgECcAUTePT9Jr2yjX+dSGDB6D4LVojWZpqfUEX4AWy6iCJr41JbiP1wj4wX3SKpYpZq0YUxsnDzbVHAqtua7PiZSMSSPsnzIMdLdWzgl2v8neBjYAgXIUzCBn111C6RSvzndQeKYw8Z5ACjQp3CUA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 15:57:28 +0300 Message-Id: <0e1d74777717cac492cd68bc88cf4ec29936e403.1539780785.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 12/14] block: Clean up reopen_backing_file() in block/replication.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Wen Congyang , Xie Changlong , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This function is used to put the hidden and secondary disks in read-write mode before launching the backup job, and back in read-only mode afterwards. This patch does the following changes: - Use an options QDict with the "read-only" option instead of passing the changes as flags only. - Simplify the code (it was unnecessarily complicated and verbose). - Fix a bug due to which the secondary disk was not being put back in read-only mode when writable=3Dfalse (because in this case orig_secondary_flags always had the BDRV_O_RDWR flag set). - Stop clearing the BDRV_O_INACTIVE flag. The flags parameter to bdrv_reopen_queue() becomes redundant and we'll be able to get rid of it in a subsequent patch. Signed-off-by: Alberto Garcia --- block/replication.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/block/replication.c b/block/replication.c index 6349d6958e..481a225924 100644 --- a/block/replication.c +++ b/block/replication.c @@ -20,6 +20,7 @@ #include "block/block_backup.h" #include "sysemu/block-backend.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "replication.h" =20 typedef enum { @@ -39,8 +40,8 @@ typedef struct BDRVReplicationState { char *top_id; ReplicationState *rs; Error *blocker; - int orig_hidden_flags; - int orig_secondary_flags; + bool orig_hidden_read_only; + bool orig_secondary_read_only; int error; } BDRVReplicationState; =20 @@ -371,44 +372,40 @@ static void secondary_do_checkpoint(BDRVReplicationSt= ate *s, Error **errp) } } =20 +/* This function is supposed to be called twice: + * first with writable =3D true, then with writable =3D false. + * The first call puts s->hidden_disk and s->secondary_disk in + * r/w mode, and the second puts them back in their original state. + */ static void reopen_backing_file(BlockDriverState *bs, bool writable, Error **errp) { BDRVReplicationState *s =3D bs->opaque; BlockReopenQueue *reopen_queue =3D NULL; - int orig_hidden_flags, orig_secondary_flags; - int new_hidden_flags, new_secondary_flags; Error *local_err =3D NULL; =20 if (writable) { - orig_hidden_flags =3D s->orig_hidden_flags =3D - bdrv_get_flags(s->hidden_disk->bs); - new_hidden_flags =3D (orig_hidden_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - orig_secondary_flags =3D s->orig_secondary_flags =3D - bdrv_get_flags(s->secondary_disk->bs); - new_secondary_flags =3D (orig_secondary_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - } else { - orig_hidden_flags =3D (s->orig_hidden_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - new_hidden_flags =3D s->orig_hidden_flags; - orig_secondary_flags =3D (s->orig_secondary_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - new_secondary_flags =3D s->orig_secondary_flags; + s->orig_hidden_read_only =3D bdrv_is_read_only(s->hidden_disk->bs); + s->orig_secondary_read_only =3D bdrv_is_read_only(s->secondary_dis= k->bs); } =20 bdrv_subtree_drained_begin(s->hidden_disk->bs); bdrv_subtree_drained_begin(s->secondary_disk->bs); =20 - if (orig_hidden_flags !=3D new_hidden_flags) { - reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->hidden_disk->b= s, NULL, - new_hidden_flags); + if (s->orig_hidden_read_only) { + int flags =3D bdrv_get_flags(s->hidden_disk->bs); + QDict *opts =3D qdict_new(); + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); + reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->hidden_disk->b= s, + opts, flags); } =20 - if (!(orig_secondary_flags & BDRV_O_RDWR)) { + if (s->orig_secondary_read_only) { + int flags =3D bdrv_get_flags(s->secondary_disk->bs); + QDict *opts =3D qdict_new(); + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->secondary_disk= ->bs, - NULL, new_secondary_flags); + opts, flags); } =20 if (reopen_queue) { --=20 2.11.0