From nobody Wed Nov 5 10:33:18 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 1499359494983143.69459819430142; Thu, 6 Jul 2017 09:44:54 -0700 (PDT) Received: from localhost ([::1]:52409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9td-0001pH-QD for importer@patchew.org; Thu, 06 Jul 2017 12:44:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nj-0004s9-1n for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9nh-00063i-Tr for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nf-00061V-DD; Thu, 06 Jul 2017 12:38:43 -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 5593D7D0C2; Thu, 6 Jul 2017 16:38:42 +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 34B2B53CD1; Thu, 6 Jul 2017 16:38:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5593D7D0C2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5593D7D0C2 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:22 +0200 Message-Id: <20170706163828.24082-6-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.26]); Thu, 06 Jul 2017 16:38:42 +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 05/11] block-backup: add reqs_lock 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" Protect the list of inflight reqs and the CoQueues for dependent requests. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/backup.c | 20 +++++++++++++++----- block/replication.c | 2 +- include/block/block_backup.h | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/block/backup.c b/block/backup.c index 9214ffcc58..0ed7726fe6 100644 --- a/block/backup.c +++ b/block/backup.c @@ -45,6 +45,7 @@ typedef struct BackupBlockJob { bool compress; NotifierWithReturn before_write; QLIST_HEAD(, CowRequest) inflight_reqs; + CoMutex reqs_lock; } BackupBlockJob; =20 /* Size of a cluster in sectors, instead of bytes. */ @@ -61,16 +62,18 @@ static void coroutine_fn wait_for_overlapping_requests(= BackupBlockJob *job, CowRequest *req; bool retry; =20 + qemu_co_mutex_lock(&job->reqs_lock); do { retry =3D false; QLIST_FOREACH(req, &job->inflight_reqs, list) { if (end > req->start && start < req->end) { - qemu_co_queue_wait(&req->wait_queue, NULL); + qemu_co_queue_wait(&req->wait_queue, &job->reqs_lock); retry =3D true; break; } } } while (retry); + qemu_co_mutex_unlock(&job->reqs_lock); } =20 /* Keep track of an in-flight request */ @@ -80,14 +83,18 @@ static void cow_request_begin(CowRequest *req, BackupBl= ockJob *job, req->start =3D start; req->end =3D end; qemu_co_queue_init(&req->wait_queue); + qemu_co_mutex_lock(&job->reqs_lock); QLIST_INSERT_HEAD(&job->inflight_reqs, req, list); + qemu_co_mutex_unlock(&job->reqs_lock); } =20 /* Forget about a completed request */ -static void cow_request_end(CowRequest *req) +static void cow_request_end(CowRequest *req, BackupBlockJob *job) { + qemu_co_mutex_lock(&job->reqs_lock); QLIST_REMOVE(req, list); qemu_co_queue_restart_all(&req->wait_queue); + qemu_co_mutex_unlock(&job->reqs_lock); } =20 static int coroutine_fn backup_do_cow(BackupBlockJob *job, @@ -175,7 +182,7 @@ out: qemu_vfree(bounce_buffer); } =20 - cow_request_end(&cow_request); + cow_request_end(&cow_request, job); =20 trace_backup_do_cow_return(job, sector_num, nb_sectors, ret); =20 @@ -311,9 +318,11 @@ void backup_cow_request_begin(CowRequest *req, BlockJo= b *job, cow_request_begin(req, backup_job, start, end); } =20 -void backup_cow_request_end(CowRequest *req) +void backup_cow_request_end(CowRequest *req, BlockJob *job) { - cow_request_end(req); + BackupBlockJob *backup_job =3D container_of(job, BackupBlockJob, commo= n); + + cow_request_end(req, backup_job); } =20 static void backup_drain(BlockJob *job) @@ -653,6 +662,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, goto error; } =20 + qemu_co_mutex_init(&job->reqs_lock); job->on_source_error =3D on_source_error; job->on_target_error =3D on_target_error; job->sync_mode =3D sync_mode; diff --git a/block/replication.c b/block/replication.c index 3885f04c31..5d6e2ec916 100644 --- a/block/replication.c +++ b/block/replication.c @@ -240,7 +240,7 @@ static coroutine_fn int replication_co_readv(BlockDrive= rState *bs, remaining_sectors); ret =3D bdrv_co_readv(bs->file, sector_num, remaining_sectors, qiov); - backup_cow_request_end(&req); + backup_cow_request_end(&req, child->bs->job); goto out; } =20 diff --git a/include/block/block_backup.h b/include/block/block_backup.h index 8a759477a3..2fe0cdd808 100644 --- a/include/block/block_backup.h +++ b/include/block/block_backup.h @@ -32,7 +32,7 @@ void backup_wait_for_overlapping_requests(BlockJob *job, = int64_t sector_num, void backup_cow_request_begin(CowRequest *req, BlockJob *job, int64_t sector_num, int nb_sectors); -void backup_cow_request_end(CowRequest *req); +void backup_cow_request_end(CowRequest *req, BlockJob *job); =20 void backup_do_checkpoint(BlockJob *job, Error **errp); =20 --=20 2.13.0