[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 13/19] block/mirror.c: use of job helpers in drivers to avoid
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH v4 13/19] block/mirror.c: use of job helpers in drivers to avoid TOC/TOU |
Date: |
Fri, 28 Jan 2022 06:50:25 -0500 |
Once job lock is used and aiocontext is removed, mirror has
to perform job operations under the same critical section,
using the helpers prepared in previous commit.
Note: at this stage, job_{lock/unlock} and job lock guard macros
are *nop*.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block/mirror.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index bfc3ac1f77..0a3eb712e6 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -653,9 +653,13 @@ static int mirror_exit_common(Job *job)
BlockDriverState *target_bs;
BlockDriverState *mirror_top_bs;
Error *local_err = NULL;
- bool abort = job->ret < 0;
+ bool abort;
int ret = 0;
+ WITH_JOB_LOCK_GUARD() {
+ abort = job->ret < 0;
+ }
+
if (s->prepared) {
return 0;
}
@@ -1151,8 +1155,10 @@ static void mirror_complete(Job *job, Error **errp)
s->should_complete = true;
/* If the job is paused, it will be re-entered when it is resumed */
- if (!job->paused) {
- job_enter(job);
+ WITH_JOB_LOCK_GUARD() {
+ if (!job->paused) {
+ job_enter_cond_locked(job, NULL);
+ }
}
}
@@ -1172,8 +1178,11 @@ static bool mirror_drained_poll(BlockJob *job)
* from one of our own drain sections, to avoid a deadlock waiting for
* ourselves.
*/
- if (!s->common.job.paused && !job_is_cancelled(&job->job) && !s->in_drain)
{
- return true;
+ WITH_JOB_LOCK_GUARD() {
+ if (!s->common.job.paused && !job_is_cancelled_locked(&job->job)
+ && !s->in_drain) {
+ return true;
+ }
}
return !!s->in_flight;
--
2.31.1
- [PATCH v4 14/19] blockjob: block_job_get_aio_context is a GS function, (continued)
- [PATCH v4 14/19] blockjob: block_job_get_aio_context is a GS function, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 06/19] jobs: remove aiocontext locks since the functions are under BQL, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 09/19] jobs: use job locks also in the unit tests, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 16/19] job: detect change of aiocontext within job coroutine, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 12/19] job.h: define unlocked functions, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 17/19] jobs: protect job.aio_context with BQL and job_mutex, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 18/19] job.c: enable job lock/unlock and remove Aiocontext locks, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 19/19] block_job_query: remove atomic read, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 11/19] jobs: document all static functions and add _locked() suffix, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 08/19] jobs: add job lock in find_* functions, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 13/19] block/mirror.c: use of job helpers in drivers to avoid TOC/TOU,
Emanuele Giuseppe Esposito <=
- [PATCH v4 15/19] commit and mirror: create new nodes using bdrv_get_aio_context, and not the job aiocontext, Emanuele Giuseppe Esposito, 2022/01/28
- [PATCH v4 10/19] job.h: define locked functions, Emanuele Giuseppe Esposito, 2022/01/28