blockjob: add block_job_start_shim

The purpose of this shim is to allow us to pause pre-started jobs.
The purpose of *that* is to allow us to buffer a pause request that
will be able to take effect before the job ever does any work, allowing
us to create jobs during a quiescent state (under which they will be
automatically paused), then resuming the jobs after the critical section
in any order, either:

(1) -block_job_start
    -block_job_resume (via e.g. drained_end)

(2) -block_job_resume (via e.g. drained_end)
    -block_job_start

The problem that requires a startup wrapper is the idea that a job must
start in the busy=true state only its first time-- all subsequent entries
require busy to be false, and the toggling of this state is otherwise
handled during existing pause and yield points.

The wrapper simply allows us to mandate that a job can "start," set busy
to true, then immediately pause only if necessary. We could avoid
requiring a wrapper, but all jobs would need to do it, so it's been
factored out here.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Message-id: 20170316212351.13797-2-jsnow@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
This commit is contained in:
John Snow 2017-03-16 17:23:49 -04:00 committed by Jeff Cody
parent d79df2a2ce
commit e3796a245a
1 changed files with 19 additions and 7 deletions

View File

@ -250,16 +250,28 @@ static bool block_job_started(BlockJob *job)
return job->co; return job->co;
} }
/**
* All jobs must allow a pause point before entering their job proper. This
* ensures that jobs can be paused prior to being started, then resumed later.
*/
static void coroutine_fn block_job_co_entry(void *opaque)
{
BlockJob *job = opaque;
assert(job && job->driver && job->driver->start);
block_job_pause_point(job);
job->driver->start(job);
}
void block_job_start(BlockJob *job) void block_job_start(BlockJob *job)
{ {
assert(job && !block_job_started(job) && job->paused && assert(job && !block_job_started(job) && job->paused &&
!job->busy && job->driver->start); job->driver && job->driver->start);
job->co = qemu_coroutine_create(job->driver->start, job); job->co = qemu_coroutine_create(block_job_co_entry, job);
if (--job->pause_count == 0) { job->pause_count--;
job->paused = false; job->busy = true;
job->busy = true; job->paused = false;
qemu_coroutine_enter(job->co); qemu_coroutine_enter(job->co);
}
} }
void block_job_ref(BlockJob *job) void block_job_ref(BlockJob *job)