aboutsummaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
Diffstat (limited to 'job.c')
-rw-r--r--job.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/job.c b/job.c
index 1b8cba15ff..fd10b1d267 100644
--- a/job.c
+++ b/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;