[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 09/15] job.c: move inner aiocontext lock in callbacks
From: |
Emanuele Giuseppe Esposito |
Subject: |
[RFC PATCH 09/15] job.c: move inner aiocontext lock in callbacks |
Date: |
Fri, 29 Oct 2021 12:39:08 -0400 |
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 | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/job.c b/job.c
index 88d911f2d7..eb6d321960 100644
--- a/job.c
+++ b/job.c
@@ -153,7 +153,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;
@@ -168,10 +167,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;
}
@@ -836,7 +832,10 @@ static void job_clean(Job *job)
static int job_finalize_single(Job *job)
{
+ AioContext *ctx = job->aio_context;
+
assert(job_is_completed(job));
+ aio_context_acquire(ctx);
/* Ensure abort is called for late-transactional failures */
job_update_rc(job);
@@ -863,6 +862,7 @@ static int job_finalize_single(Job *job)
job_txn_del_job(job);
job_conclude(job);
+ aio_context_release(ctx);
return 0;
}
@@ -968,11 +968,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());
+
+ aio_context_acquire(ctx);
if (job->ret == 0 && job->driver->prepare) {
job->ret = job->driver->prepare(job);
job_update_rc(job);
}
+ aio_context_release(ctx);
+
return job->ret;
}
--
2.27.0
- [RFC PATCH 00/15] job: replace AioContext lock with job_mutex, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 01/15] jobs: add job-common.h, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 02/15] job.c: make job_lock/unlock public, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 03/15] job-common.h: categorize fields in struct Job, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 04/15] jobs: add job-monitor.h, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 05/15] job-monitor.h: define the job monitor API, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 06/15] jobs: add job-driver.h, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 09/15] job.c: move inner aiocontext lock in callbacks,
Emanuele Giuseppe Esposito <=
- [RFC PATCH 07/15] job-driver.h: add helper functions, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 14/15] jobs: add missing job locks to replace aiocontext lock, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 15/15] jobs: remove all unnecessary AioContext locks, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 10/15] aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 13/15] jobs: use job locks and helpers also in the unit tests, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 12/15] jobs: protect jobs with job_lock/unlock, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 08/15] job.c: minor adjustments in preparation to job-driver, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 11/15] jobs: remove aiocontext locks since the functions are under BQL, Emanuele Giuseppe Esposito, 2021/10/29