From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcseM-0006QP-Uq for qemu-devel@nongnu.org; Thu, 16 May 2013 03:30:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcseK-0004MM-11 for qemu-devel@nongnu.org; Thu, 16 May 2013 03:30:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45837) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcseJ-0004M8-6j for qemu-devel@nongnu.org; Thu, 16 May 2013 03:30:51 -0400 Date: Thu, 16 May 2013 09:30:46 +0200 From: Stefan Hajnoczi Message-ID: <20130516073046.GB1597@stefanha-thinkpad.redhat.com> References: <1368628476-19622-1-git-send-email-stefanha@redhat.com> <1368628476-19622-3-git-send-email-stefanha@redhat.com> <5194522A.3010101@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5194522A.3010101@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v3 2/8] block: add basic backup support to block driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, imain@redhat.com, Paolo Bonzini , dietmar@proxmox.com On Thu, May 16, 2013 at 11:27:38AM +0800, Wenchao Xia wrote: > > +/* See if in-flight requests overlap and wait for them to complete */ > > +static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job, > > + int64_t start, > > + int64_t end) > > +{ > > + CowRequest *req; > > + bool retry; > > + > > + do { > > + retry = false; > > + QLIST_FOREACH(req, &job->inflight_reqs, list) { > > + if (end > req->start && start < req->end) { > > + qemu_co_queue_wait(&req->wait_queue); > > + retry = true; > > + break; > > + } > > + } > > + } while (retry); > > +} > > + > > In my understanding, there will be possible two program routines entering > here at same time since it holds read lock instead of write lock, and > they may also modify job->inflight_reqs, is it possible a race > condition here? I am not sure whether back-ground job will becomes a > thread. No, all operations on a BlockDriverState execute in the same event loop thread. Only coroutine synchronization is necessary, which is provided in these patches.