When block jobs need an AioContext, they just take it from their main
block node. Generic jobs don't have a main block node, so we need to
assign them an AioContext explicitly.
Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Reviewed-by: John Snow <[email protected]>
{
BlockJob *job = opaque;
+ job->job.aio_context = new_context;
if (job->driver->attached_aio_context) {
job->driver->attached_aio_context(job, new_context);
}
block_job_drain(job);
}
+ job->job.aio_context = NULL;
job_unref(&job->job);
}
return NULL;
}
- job = job_create(job_id, &driver->job_driver, errp);
+ job = job_create(job_id, &driver->job_driver, blk_get_aio_context(blk),
+ errp);
if (job == NULL) {
blk_unref(blk);
return NULL;
/** Current state; See @JobStatus for details. */
JobStatus status;
+ /** AioContext to run the job coroutine in */
+ AioContext *aio_context;
+
/**
* Set to true if the job should cancel itself. The flag must
* always be tested just before toggling the busy flag from false
*
* @job_id: The id of the newly-created job, or %NULL for internal jobs
* @driver: The class object for the newly-created job.
+ * @ctx: The AioContext to run the job coroutine in.
* @errp: Error object.
*/
-void *job_create(const char *job_id, const JobDriver *driver, Error **errp);
+void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx,
+ Error **errp);
/**
* Add a reference to Job refcnt, it will be decreased with job_unref, and then
return NULL;
}
-void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
+void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx,
+ Error **errp)
{
Job *job;
job->driver = driver;
job->id = g_strdup(job_id);
job->refcnt = 1;
+ job->aio_context = ctx;
job_state_transition(job, JOB_STATUS_CREATED);