mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
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>
This commit is contained in:
parent
279ac06e55
commit
880eeec613
6 changed files with 63 additions and 34 deletions
14
blockdev.c
14
blockdev.c
|
@ -150,12 +150,15 @@ void blockdev_mark_auto_del(BlockBackend *blk)
|
|||
return;
|
||||
}
|
||||
|
||||
for (job = block_job_next(NULL); job; job = block_job_next(job)) {
|
||||
JOB_LOCK_GUARD();
|
||||
|
||||
for (job = block_job_next_locked(NULL); job;
|
||||
job = block_job_next_locked(job)) {
|
||||
if (block_job_has_bdrv(job, blk_bs(blk))) {
|
||||
AioContext *aio_context = job->job.aio_context;
|
||||
aio_context_acquire(aio_context);
|
||||
|
||||
job_cancel(&job->job, false);
|
||||
job_cancel_locked(&job->job, false);
|
||||
|
||||
aio_context_release(aio_context);
|
||||
}
|
||||
|
@ -3756,7 +3759,10 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
|
|||
BlockJobInfoList *head = NULL, **tail = &head;
|
||||
BlockJob *job;
|
||||
|
||||
for (job = block_job_next(NULL); job; job = block_job_next(job)) {
|
||||
JOB_LOCK_GUARD();
|
||||
|
||||
for (job = block_job_next_locked(NULL); job;
|
||||
job = block_job_next_locked(job)) {
|
||||
BlockJobInfo *value;
|
||||
AioContext *aio_context;
|
||||
|
||||
|
@ -3765,7 +3771,7 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
|
|||
}
|
||||
aio_context = block_job_get_aio_context(job);
|
||||
aio_context_acquire(aio_context);
|
||||
value = block_job_query(job, errp);
|
||||
value = block_job_query_locked(job, errp);
|
||||
aio_context_release(aio_context);
|
||||
if (!value) {
|
||||
qapi_free_BlockJobInfoList(head);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue