aboutsummaryrefslogtreecommitdiff
path: root/job-qmp.c
diff options
context:
space:
mode:
authorEmanuele Giuseppe Esposito <eesposit@redhat.com>2022-09-26 05:32:11 -0400
committerKevin Wolf <kwolf@redhat.com>2022-10-07 12:11:41 +0200
commit6f592e5aca1a27fe1c1f661cfe68b35b90850acf (patch)
tree74f0dbf7c423bb4361cf0bb5c008a8b50de7fe6e /job-qmp.c
parent2fc3bdc3843d2d8bde54c2be4d4f4cc8a9ffcf50 (diff)
job.c: enable job lock/unlock and remove Aiocontext locks
Change the job_{lock/unlock} and macros to use job_mutex. Now that they are not nop anymore, remove the aiocontext to avoid deadlocks. Therefore: - when possible, remove completely the aiocontext lock/unlock pair - if it is used by some other function too, reduce the locking section as much as possible, leaving the job API outside. - change AIO_WAIT_WHILE in AIO_WAIT_WHILE_UNLOCKED, since we are not using the aiocontext lock anymore The only functions that still need the aiocontext lock are: - the JobDriver callbacks, already documented in job.h - job_cancel_sync() in replication.c is called with aio_context_lock taken, but now job is using AIO_WAIT_WHILE_UNLOCKED so we need to release the lock. Reduce the locking section to only cover the callback invocation and document the functions that take the AioContext lock, to avoid taking it twice. Also remove real_job_{lock/unlock}, as they are replaced by the public functions. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Message-Id: <20220926093214.506243-19-eesposit@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'job-qmp.c')
-rw-r--r--job-qmp.c46
1 files changed, 8 insertions, 38 deletions
diff --git a/job-qmp.c b/job-qmp.c
index 393d3a5b81..d498fc89c0 100644
--- a/job-qmp.c
+++ b/job-qmp.c
@@ -30,36 +30,27 @@
#include "trace/trace-root.h"
/*
- * Get a job using its ID and acquire its AioContext.
- * Called with job_mutex held.
+ * Get a job using its ID. Called with job_mutex held.
*/
-static Job *find_job_locked(const char *id,
- AioContext **aio_context,
- Error **errp)
+static Job *find_job_locked(const char *id, Error **errp)
{
Job *job;
- *aio_context = NULL;
-
job = job_get_locked(id);
if (!job) {
error_setg(errp, "Job not found");
return NULL;
}
- *aio_context = job->aio_context;
- aio_context_acquire(*aio_context);
-
return job;
}
void qmp_job_cancel(const char *id, Error **errp)
{
- AioContext *aio_context;
Job *job;
JOB_LOCK_GUARD();
- job = find_job_locked(id, &aio_context, errp);
+ job = find_job_locked(id, errp);
if (!job) {
return;
@@ -67,16 +58,14 @@ void qmp_job_cancel(const char *id, Error **errp)
trace_qmp_job_cancel(job);
job_user_cancel_locked(job, true, errp);
- aio_context_release(aio_context);
}
void qmp_job_pause(const char *id, Error **errp)
{
- AioContext *aio_context;
Job *job;
JOB_LOCK_GUARD();
- job = find_job_locked(id, &aio_context, errp);
+ job = find_job_locked(id, errp);
if (!job) {
return;
@@ -84,16 +73,14 @@ void qmp_job_pause(const char *id, Error **errp)
trace_qmp_job_pause(job);
job_user_pause_locked(job, errp);
- aio_context_release(aio_context);
}
void qmp_job_resume(const char *id, Error **errp)
{
- AioContext *aio_context;
Job *job;
JOB_LOCK_GUARD();
- job = find_job_locked(id, &aio_context, errp);
+ job = find_job_locked(id, errp);
if (!job) {
return;
@@ -101,16 +88,14 @@ void qmp_job_resume(const char *id, Error **errp)
trace_qmp_job_resume(job);
job_user_resume_locked(job, errp);
- aio_context_release(aio_context);
}
void qmp_job_complete(const char *id, Error **errp)
{
- AioContext *aio_context;
Job *job;
JOB_LOCK_GUARD();
- job = find_job_locked(id, &aio_context, errp);
+ job = find_job_locked(id, errp);
if (!job) {
return;
@@ -118,16 +103,14 @@ void qmp_job_complete(const char *id, Error **errp)
trace_qmp_job_complete(job);
job_complete_locked(job, errp);
- aio_context_release(aio_context);
}
void qmp_job_finalize(const char *id, Error **errp)
{
- AioContext *aio_context;
Job *job;
JOB_LOCK_GUARD();
- job = find_job_locked(id, &aio_context, errp);
+ job = find_job_locked(id, errp);
if (!job) {
return;
@@ -137,23 +120,15 @@ void qmp_job_finalize(const char *id, Error **errp)
job_ref_locked(job);
job_finalize_locked(job, errp);
- /*
- * Job's context might have changed via job_finalize (and job_txn_apply
- * automatically acquires the new one), so make sure we release the correct
- * one.
- */
- aio_context = job->aio_context;
job_unref_locked(job);
- aio_context_release(aio_context);
}
void qmp_job_dismiss(const char *id, Error **errp)
{
- AioContext *aio_context;
Job *job;
JOB_LOCK_GUARD();
- job = find_job_locked(id, &aio_context, errp);
+ job = find_job_locked(id, errp);
if (!job) {
return;
@@ -161,7 +136,6 @@ void qmp_job_dismiss(const char *id, Error **errp)
trace_qmp_job_dismiss(job);
job_dismiss_locked(&job, errp);
- aio_context_release(aio_context);
}
/* Called with job_mutex held. */
@@ -199,15 +173,11 @@ JobInfoList *qmp_query_jobs(Error **errp)
for (job = job_next_locked(NULL); job; job = job_next_locked(job)) {
JobInfo *value;
- AioContext *aio_context;
if (job_is_internal(job)) {
continue;
}
- aio_context = job->aio_context;
- aio_context_acquire(aio_context);
value = job_query_single_locked(job, errp);
- aio_context_release(aio_context);
if (!value) {
qapi_free_JobInfoList(head);
return NULL;