From fa4478d5c8b74a5f0c8b93cc00590ec007be5016 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 8 May 2012 16:51:46 +0200 Subject: block: wait for job callback in block_job_cancel_sync The limitation on not having I/O after cancellation cannot really be kept. Even streaming has a very small race window where you could cancel a job and have it report completion. If this window is hit, bdrv_change_backing_file() will yield and possibly cause accesses to dangling pointers etc. So, let's just assume that we cannot know exactly what will happen after the coroutine has set busy to false. We can set a very lax condition: - if we cancel the job, the coroutine won't set it to false again (and hence will not call co_sleep_ns again). - block_job_cancel_sync will wait for the coroutine to exit, which pretty much ensures no race. Instead, we track the coroutine that executes the job and put very strict conditions on what to do while it is quiescent (busy = false). First of all, the coroutine must never set busy = false while the job has been cancelled. Second, the coroutine can be reentered arbitrarily while it is quiescent, so you cannot really do anything but co_sleep_ns at that time. This condition is obeyed by the block_job_sleep_ns function. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- block/stream.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'block/stream.c') diff --git a/block/stream.c b/block/stream.c index b279acda7b..930e3cf37b 100644 --- a/block/stream.c +++ b/block/stream.c @@ -270,7 +270,6 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base, void *opaque, Error **errp) { StreamBlockJob *s; - Coroutine *co; s = block_job_create(&stream_job_type, bs, speed, cb, opaque, errp); if (!s) { @@ -282,7 +281,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base, pstrcpy(s->backing_file_id, sizeof(s->backing_file_id), base_id); } - co = qemu_coroutine_create(stream_run); - trace_stream_start(bs, base, s, co, opaque); - qemu_coroutine_enter(co, s); + s->common.co = qemu_coroutine_create(stream_run); + trace_stream_start(bs, base, s, s->common.co, opaque); + qemu_coroutine_enter(s->common.co, s); } -- cgit v1.2.3