mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
blockjob: reimplement block_job_sleep_ns to allow cancellation
This reverts the effects of commit 4afeffc857
("blockjob: do not allow
coroutine double entry or entry-after-completion", 2017-11-21)
This fixed the symptom of a bug rather than the root cause. Canceling the
wait on a sleeping blockjob coroutine is generally fine, we just need to
make it work correctly across AioContexts. To do so, use a QEMUTimer
that calls block_job_enter. Use a mutex to ensure that block_job_enter
synchronizes correctly with block_job_sleep_ns.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-By: Jeff Cody <jcody@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
356f59b875
commit
fc24908e7d
3 changed files with 61 additions and 14 deletions
|
@ -77,7 +77,7 @@ typedef struct BlockJob {
|
|||
/**
|
||||
* Set to false by the job while the coroutine has yielded and may be
|
||||
* re-entered by block_job_enter(). There may still be I/O or event loop
|
||||
* activity pending.
|
||||
* activity pending. Accessed under block_job_mutex (in blockjob.c).
|
||||
*/
|
||||
bool busy;
|
||||
|
||||
|
@ -135,6 +135,12 @@ typedef struct BlockJob {
|
|||
*/
|
||||
int ret;
|
||||
|
||||
/**
|
||||
* Timer that is used by @block_job_sleep_ns. Accessed under
|
||||
* block_job_mutex (in blockjob.c).
|
||||
*/
|
||||
QEMUTimer sleep_timer;
|
||||
|
||||
/** Non-NULL if this job is part of a transaction */
|
||||
BlockJobTxn *txn;
|
||||
QLIST_ENTRY(BlockJob) txn_list;
|
||||
|
|
|
@ -142,8 +142,8 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
|||
* @ns: How many nanoseconds to stop for.
|
||||
*
|
||||
* Put the job to sleep (assuming that it wasn't canceled) for @ns
|
||||
* %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will not interrupt
|
||||
* the wait, so the cancel will not process until the coroutine wakes up.
|
||||
* %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will immediately
|
||||
* interrupt the wait.
|
||||
*/
|
||||
void block_job_sleep_ns(BlockJob *job, int64_t ns);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue