Skip to content
Snippets Groups Projects
Commit 4feeec7e authored by Hanna Reitz's avatar Hanna Reitz Committed by Vladimir Sementsov-Ogievskiy
Browse files

mirror: Check job_is_cancelled() earlier

We must check whether the job is force-cancelled early in our main loop,
most importantly before any `continue` statement.  For example, we used
to have `continue`s before our current checking location that are
triggered by `mirror_flush()` failing.  So, if `mirror_flush()` kept
failing, force-cancelling the job would not terminate it.

Jobs can be cancelled while they yield, and once they are
(force-cancelled), they should not generate new I/O requests.
Therefore, we should put the check after the last yield before
mirror_iteration() is invoked.

Buglink: https://gitlab.com/qemu-project/qemu/-/issues/462


Signed-off-by: default avatarHanna Reitz <hreitz@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20211006151940.214590-11-hreitz@redhat.com>
Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
parent 20ad4d20
No related merge requests found
...@@ -1007,6 +1007,11 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) ...@@ -1007,6 +1007,11 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
job_pause_point(&s->common.job); job_pause_point(&s->common.job);
if (job_is_cancelled(&s->common.job)) {
ret = 0;
goto immediate_exit;
}
cnt = bdrv_get_dirty_count(s->dirty_bitmap); cnt = bdrv_get_dirty_count(s->dirty_bitmap);
/* cnt is the number of dirty bytes remaining and s->bytes_in_flight is /* cnt is the number of dirty bytes remaining and s->bytes_in_flight is
* the number of bytes currently being processed; together those are * the number of bytes currently being processed; together those are
...@@ -1085,8 +1090,6 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) ...@@ -1085,8 +1090,6 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
break; break;
} }
ret = 0;
if (job_is_ready(&s->common.job) && !should_complete) { if (job_is_ready(&s->common.job) && !should_complete) {
delay_ns = (s->in_flight == 0 && delay_ns = (s->in_flight == 0 &&
cnt == 0 ? BLOCK_JOB_SLICE_TIME : 0); cnt == 0 ? BLOCK_JOB_SLICE_TIME : 0);
...@@ -1094,9 +1097,6 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) ...@@ -1094,9 +1097,6 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job), trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job),
delay_ns); delay_ns);
job_sleep_ns(&s->common.job, delay_ns); job_sleep_ns(&s->common.job, delay_ns);
if (job_is_cancelled(&s->common.job)) {
break;
}
s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment