@@ -165,7 +165,6 @@ static void job_txn_del_job(Job *job)
static int job_txn_apply(Job *job, int fn(Job *))
{
- AioContext *inner_ctx;
Job *other_job, *next;
JobTxn *txn = job->txn;
int rc = 0;
@@ -180,10 +179,7 @@ static int job_txn_apply(Job *job, int fn(Job *))
aio_context_release(job->aio_context);
QLIST_FOREACH_SAFE(other_job, &txn->jobs, txn_list, next) {
- inner_ctx = other_job->aio_context;
- aio_context_acquire(inner_ctx);
rc = fn(other_job);
- aio_context_release(inner_ctx);
if (rc) {
break;
}
@@ -796,11 +792,15 @@ static void job_clean(Job *job)
static int job_finalize_single(Job *job)
{
+ AioContext *ctx = job->aio_context;
+
assert(job_is_completed_locked(job));
/* Ensure abort is called for late-transactional failures */
job_update_rc(job);
+ aio_context_acquire(ctx);
+
if (!job->ret) {
job_commit(job);
} else {
@@ -808,6 +808,8 @@ static int job_finalize_single(Job *job)
}
job_clean(job);
+ aio_context_release(ctx);
+
if (job->cb) {
job->cb(job->opaque, job->ret);
}
@@ -928,11 +930,16 @@ static void job_completed_txn_abort(Job *job)
static int job_prepare(Job *job)
{
+ AioContext *ctx = job->aio_context;
assert(qemu_in_main_thread());
+
if (job->ret == 0 && job->driver->prepare) {
+ aio_context_acquire(ctx);
job->ret = job->driver->prepare(job);
+ aio_context_release(ctx);
job_update_rc(job);
}
+
return job->ret;
}
Instead of having the lock in job_tnx_apply, move it inside in the callback. This will be helpful for next commits, when we introduce job_lock/unlock pairs. job_transition_to_pending() and job_needs_finalize() do not need to be protected by the aiocontext lock. No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> --- job.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)