diff options
author | Emanuele Giuseppe Esposito <eesposit@redhat.com> | 2022-09-26 05:32:04 -0400 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2022-10-07 12:11:41 +0200 |
commit | 880eeec61329abc0aead900f0037fce91571b1ec (patch) | |
tree | 684676e354ff54754203f40579d6b7eb969805c7 /job-qmp.c | |
parent | 279ac06e55698b6152e7a6431f77b4db9d059002 (diff) |
jobs: group together API calls under the same job lock
Now that the API offers also _locked() functions, take advantage
of it and give also the caller control to take the lock and call
_locked functions.
This makes sense especially when we have for loops, because it
makes no sense to have:
for(job = job_next(); ...)
where each job_next() takes the lock internally.
Instead we want
JOB_LOCK_GUARD();
for(job = job_next_locked(); ...)
In addition, protect also direct field accesses, by either creating a
new critical section or widening the existing ones.
Note: at this stage, job_{lock/unlock} and job lock guard macros
are *nop*.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20220926093214.506243-12-eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'job-qmp.c')
-rw-r--r-- | job-qmp.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -164,7 +164,8 @@ void qmp_job_dismiss(const char *id, Error **errp) aio_context_release(aio_context); } -static JobInfo *job_query_single(Job *job, Error **errp) +/* Called with job_mutex held. */ +static JobInfo *job_query_single_locked(Job *job, Error **errp) { JobInfo *info; uint64_t progress_current; @@ -194,7 +195,9 @@ JobInfoList *qmp_query_jobs(Error **errp) JobInfoList *head = NULL, **tail = &head; Job *job; - for (job = job_next(NULL); job; job = job_next(job)) { + JOB_LOCK_GUARD(); + + for (job = job_next_locked(NULL); job; job = job_next_locked(job)) { JobInfo *value; AioContext *aio_context; @@ -203,7 +206,7 @@ JobInfoList *qmp_query_jobs(Error **errp) } aio_context = job->aio_context; aio_context_acquire(aio_context); - value = job_query_single(job, errp); + value = job_query_single_locked(job, errp); aio_context_release(aio_context); if (!value) { qapi_free_JobInfoList(head); |