Skip to content

Commit 4feeec7

Browse files
XanClicVladimir Sementsov-Ogievskiy
authored andcommitted
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: Hanna Reitz <[email protected]> Reviewed-by: Eric Blake <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Message-Id: <[email protected]> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
1 parent 20ad4d2 commit 4feeec7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

block/mirror.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,11 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
10071007

10081008
job_pause_point(&s->common.job);
10091009

1010+
if (job_is_cancelled(&s->common.job)) {
1011+
ret = 0;
1012+
goto immediate_exit;
1013+
}
1014+
10101015
cnt = bdrv_get_dirty_count(s->dirty_bitmap);
10111016
/* cnt is the number of dirty bytes remaining and s->bytes_in_flight is
10121017
* the number of bytes currently being processed; together those are
@@ -1085,18 +1090,13 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
10851090
break;
10861091
}
10871092

1088-
ret = 0;
1089-
10901093
if (job_is_ready(&s->common.job) && !should_complete) {
10911094
delay_ns = (s->in_flight == 0 &&
10921095
cnt == 0 ? BLOCK_JOB_SLICE_TIME : 0);
10931096
}
10941097
trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job),
10951098
delay_ns);
10961099
job_sleep_ns(&s->common.job, delay_ns);
1097-
if (job_is_cancelled(&s->common.job)) {
1098-
break;
1099-
}
11001100
s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
11011101
}
11021102

0 commit comments

Comments
 (0)