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.