From nobody Wed Nov 5 10:30:41 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; 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 1499359615724697.1888112118387; Thu, 6 Jul 2017 09:46:55 -0700 (PDT) Received: from localhost ([::1]:52420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9vZ-0003K3-6E for importer@patchew.org; Thu, 06 Jul 2017 12:46:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nr-00050f-DO for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9np-00067y-W4 for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nl-00065j-Fd; Thu, 06 Jul 2017 12:38:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 666F94DD49; Thu, 6 Jul 2017 16:38:48 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F21660A9D; Thu, 6 Jul 2017 16:38:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 666F94DD49 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 666F94DD49 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:26 +0200 Message-Id: <20170706163828.24082-10-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 06 Jul 2017 16:38:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/11] block/replication: do not acquire AioContext 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: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Replication functions are mostly called when the BDS is quiescent and does not have any pending I/O. They do not need to synchronize on anything since BDS and BB are now thread-safe. Signed-off-by: Paolo Bonzini --- block/replication.c | 51 ++++++++++++-------------------------------------= -- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/block/replication.c b/block/replication.c index 5d6e2ec916..7a3b94b90f 100644 --- a/block/replication.c +++ b/block/replication.c @@ -41,6 +41,8 @@ typedef struct BDRVReplicationState { Error *blocker; int orig_hidden_flags; int orig_secondary_flags; + + /* This field is accessed asynchronously. */ int error; } BDRVReplicationState; =20 @@ -201,7 +203,7 @@ static int replication_return_value(BDRVReplicationStat= e *s, int ret) } =20 if (ret < 0) { - s->error =3D ret; + atomic_set(&s->error, ret); ret =3D 0; } =20 @@ -311,6 +313,7 @@ static bool replication_recurse_is_first_non_filter(Blo= ckDriverState *bs, return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); } =20 +/* Called with no I/O pending. */ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) { Error *local_err =3D NULL; @@ -405,7 +408,7 @@ static void backup_job_completed(void *opaque, int ret) =20 if (s->stage !=3D BLOCK_REPLICATION_FAILOVER) { /* The backup job is cancelled unexpectedly */ - s->error =3D -EIO; + atomic_set(&s->error, -EIO); } =20 backup_job_cleanup(bs); @@ -430,6 +433,7 @@ static bool check_top_bs(BlockDriverState *top_bs, Bloc= kDriverState *bs) return false; } =20 +/* Called with no I/O pending. */ static void replication_start(ReplicationState *rs, ReplicationMode mode, Error **errp) { @@ -437,24 +441,19 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, BDRVReplicationState *s; BlockDriverState *top_bs; int64_t active_length, hidden_length, disk_length; - AioContext *aio_context; Error *local_err =3D NULL; BlockJob *job; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->stage !=3D BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is running or done"); - aio_context_release(aio_context); return; } =20 if (s->mode !=3D mode) { error_setg(errp, "The parameter mode's value is invalid, needs %d," " but got %d", s->mode, mode); - aio_context_release(aio_context); return; } =20 @@ -466,21 +465,18 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, if (!s->active_disk || !s->active_disk->bs || !s->active_disk->bs->backing) { error_setg(errp, "Active disk doesn't have backing file"); - aio_context_release(aio_context); return; } =20 s->hidden_disk =3D s->active_disk->bs->backing; if (!s->hidden_disk->bs || !s->hidden_disk->bs->backing) { error_setg(errp, "Hidden disk doesn't have backing file"); - aio_context_release(aio_context); return; } =20 s->secondary_disk =3D s->hidden_disk->bs->backing; if (!s->secondary_disk->bs || !bdrv_has_blk(s->secondary_disk->bs)= ) { error_setg(errp, "The secondary disk doesn't have block backen= d"); - aio_context_release(aio_context); return; } =20 @@ -492,7 +488,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, active_length !=3D hidden_length || hidden_length !=3D disk_le= ngth) { error_setg(errp, "Active disk, hidden disk, secondary disk's l= ength" " are not the same"); - aio_context_release(aio_context); return; } =20 @@ -500,7 +495,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, !s->hidden_disk->bs->drv->bdrv_make_empty) { error_setg(errp, "Active disk or hidden disk doesn't support make_em= pty"); - aio_context_release(aio_context); return; } =20 @@ -508,7 +502,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, reopen_backing_file(bs, true, &local_err); if (local_err) { error_propagate(errp, local_err); - aio_context_release(aio_context); return; } =20 @@ -521,7 +514,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, !check_top_bs(top_bs, bs)) { error_setg(errp, "No top_bs or it is invalid"); reopen_backing_file(bs, false, NULL); - aio_context_release(aio_context); return; } bdrv_op_block_all(top_bs, s->blocker); @@ -535,13 +527,11 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, if (local_err) { error_propagate(errp, local_err); backup_job_cleanup(bs); - aio_context_release(aio_context); return; } block_job_start(job); break; default: - aio_context_release(aio_context); abort(); } =20 @@ -551,48 +541,38 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, secondary_do_checkpoint(s, errp); } =20 - s->error =3D 0; - aio_context_release(aio_context); + atomic_set(&s->error, 0); } =20 +/* Called with no I/O pending. */ static void replication_do_checkpoint(ReplicationState *rs, Error **errp) { BlockDriverState *bs =3D rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->mode =3D=3D REPLICATION_MODE_SECONDARY) { secondary_do_checkpoint(s, errp); } - aio_context_release(aio_context); } =20 static void replication_get_error(ReplicationState *rs, Error **errp) { BlockDriverState *bs =3D rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->stage !=3D BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); - aio_context_release(aio_context); return; } =20 - if (s->error) { + if (atomic_read(&s->error)) { error_setg(errp, "I/O error occurred"); - aio_context_release(aio_context); return; } - aio_context_release(aio_context); } =20 static void replication_done(void *opaque, int ret) @@ -608,10 +588,10 @@ static void replication_done(void *opaque, int ret) s->active_disk =3D NULL; s->secondary_disk =3D NULL; s->hidden_disk =3D NULL; - s->error =3D 0; + atomic_set(&s->error, 0); } else { s->stage =3D BLOCK_REPLICATION_FAILOVER_FAILED; - s->error =3D -EIO; + atomic_set(&s->error, -EIO); } } =20 @@ -619,22 +599,18 @@ static void replication_stop(ReplicationState *rs, bo= ol failover, Error **errp) { BlockDriverState *bs =3D rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->stage !=3D BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); - aio_context_release(aio_context); return; } =20 switch (s->mode) { case REPLICATION_MODE_PRIMARY: s->stage =3D BLOCK_REPLICATION_DONE; - s->error =3D 0; + atomic_set(&s->error, 0); break; case REPLICATION_MODE_SECONDARY: /* @@ -649,7 +625,6 @@ static void replication_stop(ReplicationState *rs, bool= failover, Error **errp) if (!failover) { secondary_do_checkpoint(s, errp); s->stage =3D BLOCK_REPLICATION_DONE; - aio_context_release(aio_context); return; } =20 @@ -659,10 +634,8 @@ static void replication_stop(ReplicationState *rs, boo= l failover, Error **errp) NULL, replication_done, bs, true, errp); break; default: - aio_context_release(aio_context); abort(); } - aio_context_release(aio_context); } =20 BlockDriver bdrv_replication =3D { --=20 2.13.0