Skip to content

Commit

Permalink
blockjob: Add block_job_yield()
Browse files Browse the repository at this point in the history
This will unset busy flag and put coroutine to sleep, can be used to
wait for QMP complete/cancel.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit dc71ce4)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
Fam Zheng authored and mdroth committed Aug 7, 2014
1 parent 520b341 commit 8e09e20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions blockjob.c
Expand Up @@ -206,6 +206,20 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)
job->busy = true;
}

void block_job_yield(BlockJob *job)
{
assert(job->busy);

/* Check cancellation *before* setting busy = false, too! */
if (block_job_is_cancelled(job)) {
return;
}

job->busy = false;
qemu_coroutine_yield();
job->busy = true;
}

BlockJobInfo *block_job_query(BlockJob *job)
{
BlockJobInfo *info = g_new0(BlockJobInfo, 1);
Expand Down
8 changes: 8 additions & 0 deletions include/block/blockjob.h
Expand Up @@ -143,6 +143,14 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
*/
void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);

/**
* block_job_yield:
* @job: The job that calls the function.
*
* Yield the block job coroutine.
*/
void block_job_yield(BlockJob *job);

/**
* block_job_completed:
* @job: The job being completed.
Expand Down

0 comments on commit 8e09e20

Please sign in to comment.