mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
job: Move pause/resume functions to Job
While we already moved the state related to job pausing to Job, the functions to do were still BlockJob only. This commit moves them over to Job. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com>
This commit is contained in:
parent
5d43e86e11
commit
b15de82867
13 changed files with 133 additions and 102 deletions
59
job.c
59
job.c
|
@ -341,6 +341,65 @@ void job_start(Job *job)
|
|||
aio_co_enter(job->aio_context, job->co);
|
||||
}
|
||||
|
||||
/* Assumes the block_job_mutex is held */
|
||||
static bool job_timer_not_pending(Job *job)
|
||||
{
|
||||
return !timer_pending(&job->sleep_timer);
|
||||
}
|
||||
|
||||
void job_pause(Job *job)
|
||||
{
|
||||
job->pause_count++;
|
||||
}
|
||||
|
||||
void job_resume(Job *job)
|
||||
{
|
||||
assert(job->pause_count > 0);
|
||||
job->pause_count--;
|
||||
if (job->pause_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* kick only if no timer is pending */
|
||||
job_enter_cond(job, job_timer_not_pending);
|
||||
}
|
||||
|
||||
void job_user_pause(Job *job, Error **errp)
|
||||
{
|
||||
if (job_apply_verb(job, JOB_VERB_PAUSE, errp)) {
|
||||
return;
|
||||
}
|
||||
if (job->user_paused) {
|
||||
error_setg(errp, "Job is already paused");
|
||||
return;
|
||||
}
|
||||
job->user_paused = true;
|
||||
job_pause(job);
|
||||
}
|
||||
|
||||
bool job_user_paused(Job *job)
|
||||
{
|
||||
return job->user_paused;
|
||||
}
|
||||
|
||||
void job_user_resume(Job *job, Error **errp)
|
||||
{
|
||||
assert(job);
|
||||
if (!job->user_paused || job->pause_count <= 0) {
|
||||
error_setg(errp, "Can't resume a job that was not paused");
|
||||
return;
|
||||
}
|
||||
if (job_apply_verb(job, JOB_VERB_RESUME, errp)) {
|
||||
return;
|
||||
}
|
||||
if (job->driver->user_resume) {
|
||||
job->driver->user_resume(job);
|
||||
}
|
||||
job->user_paused = false;
|
||||
job_resume(job);
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
Job *job;
|
||||
JobDeferToMainLoopFn *fn;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue