[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 44/50] blockjob: protect iostatus field in BlockJob struct
From: |
Kevin Wolf |
Subject: |
[PULL 44/50] blockjob: protect iostatus field in BlockJob struct |
Date: |
Fri, 7 Oct 2022 12:47:46 +0200 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
iostatus is the only field (together with .job) that needs
protection using the job mutex.
It is set in the main loop (GLOBAL_STATE functions) but read
in I/O code (block_job_error_action).
In order to protect it, change block_job_iostatus_set_err
to block_job_iostatus_set_err_locked(), always called under
job lock.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20220926093214.506243-17-eesposit@redhat.com>
[kwolf: Fixed up type of iostatus]
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/mirror.c | 6 +++++-
blockjob.c | 5 +++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index c6bf7f40ce..80c0109d39 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -894,6 +894,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
BlockDriverState *bs = s->mirror_top_bs->backing->bs;
BlockDriverState *target_bs = blk_bs(s->target);
bool need_drain = true;
+ BlockDeviceIoStatus iostatus;
int64_t length;
int64_t target_length;
BlockDriverInfo bdi;
@@ -1016,8 +1017,11 @@ static int coroutine_fn mirror_run(Job *job, Error
**errp)
* We do so every BLKOCK_JOB_SLICE_TIME nanoseconds, or when there is
* an error, or when the source is clean, whichever comes first. */
delta = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_ns;
+ WITH_JOB_LOCK_GUARD() {
+ iostatus = s->common.iostatus;
+ }
if (delta < BLOCK_JOB_SLICE_TIME &&
- s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
+ iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 ||
(cnt == 0 && s->in_flight > 0)) {
trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight);
diff --git a/blockjob.c b/blockjob.c
index d8fb5311c7..d04f804001 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -363,7 +363,8 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
return block_job_query_locked(job, errp);
}
-static void block_job_iostatus_set_err(BlockJob *job, int error)
+/* Called with job lock held */
+static void block_job_iostatus_set_err_locked(BlockJob *job, int error)
{
if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
job->iostatus = error == ENOSPC ? BLOCK_DEVICE_IO_STATUS_NOSPACE :
@@ -577,8 +578,8 @@ BlockErrorAction block_job_error_action(BlockJob *job,
BlockdevOnError on_err,
*/
job->job.user_paused = true;
}
+ block_job_iostatus_set_err_locked(job, error);
}
- block_job_iostatus_set_err(job, error);
}
return action;
}
--
2.37.3
- [PULL 17/50] curl: add missing coroutine_fn annotations, (continued)
- [PULL 17/50] curl: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 11/50] nbd: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 15/50] qcow2: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 37/50] jobs: use job locks also in the unit tests, Kevin Wolf, 2022/10/07
- [PULL 33/50] job.c: add job_lock/unlock while keeping job.h intact, Kevin Wolf, 2022/10/07
- [PULL 48/50] blockjob: remove unused functions, Kevin Wolf, 2022/10/07
- [PULL 27/50] test-coroutine: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 13/50] nvme: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 22/50] job: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 19/50] quorum: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 44/50] blockjob: protect iostatus field in BlockJob struct,
Kevin Wolf <=
- [PULL 12/50] nfs: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 26/50] migration: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 05/50] qcow2: remove incorrect coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 09/50] file-posix: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 14/50] parallels: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 39/50] jobs: group together API calls under the same job lock, Kevin Wolf, 2022/10/07
- [PULL 42/50] blockjob.h: categorize fields in struct BlockJob, Kevin Wolf, 2022/10/07
- [PULL 10/50] iscsi: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 18/50] qed: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 16/50] copy-before-write: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07