|
|
26ba25 |
From b8d8e8478603258bc5505a9b606321a81b14d896 Mon Sep 17 00:00:00 2001
|
|
|
26ba25 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Date: Tue, 26 Jun 2018 09:48:11 +0200
|
|
|
26ba25 |
Subject: [PATCH 103/268] job: Move pause/resume functions to Job
|
|
|
26ba25 |
|
|
|
26ba25 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Message-id: <20180626094856.6924-29-kwolf@redhat.com>
|
|
|
26ba25 |
Patchwork-id: 81062
|
|
|
26ba25 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 28/73] job: Move pause/resume functions to Job
|
|
|
26ba25 |
Bugzilla: 1513543
|
|
|
26ba25 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
26ba25 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
26ba25 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
26ba25 |
|
|
|
26ba25 |
While we already moved the state related to job pausing to Job, the
|
|
|
26ba25 |
functions to do were still BlockJob only. This commit moves them over to
|
|
|
26ba25 |
Job.
|
|
|
26ba25 |
|
|
|
26ba25 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
26ba25 |
Reviewed-by: John Snow <jsnow@redhat.com>
|
|
|
26ba25 |
(cherry picked from commit b15de82867975e0b4acf644b5ee36d84904b6612)
|
|
|
26ba25 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
26ba25 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
26ba25 |
---
|
|
|
26ba25 |
block/backup.c | 1 +
|
|
|
26ba25 |
block/commit.c | 1 +
|
|
|
26ba25 |
block/mirror.c | 2 ++
|
|
|
26ba25 |
block/stream.c | 1 +
|
|
|
26ba25 |
blockdev.c | 6 ++--
|
|
|
26ba25 |
blockjob.c | 81 +++++++++-----------------------------------
|
|
|
26ba25 |
include/block/blockjob.h | 32 -----------------
|
|
|
26ba25 |
include/block/blockjob_int.h | 7 ++++
|
|
|
26ba25 |
include/qemu/job.h | 37 ++++++++++++++++++++
|
|
|
26ba25 |
job.c | 59 ++++++++++++++++++++++++++++++++
|
|
|
26ba25 |
tests/test-bdrv-drain.c | 1 +
|
|
|
26ba25 |
tests/test-blockjob-txn.c | 1 +
|
|
|
26ba25 |
tests/test-blockjob.c | 6 ++--
|
|
|
26ba25 |
13 files changed, 133 insertions(+), 102 deletions(-)
|
|
|
26ba25 |
|
|
|
26ba25 |
diff --git a/block/backup.c b/block/backup.c
|
|
|
26ba25 |
index f3a4f7c..4d011d5 100644
|
|
|
26ba25 |
--- a/block/backup.c
|
|
|
26ba25 |
+++ b/block/backup.c
|
|
|
26ba25 |
@@ -528,6 +528,7 @@ static const BlockJobDriver backup_job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(BackupBlockJob),
|
|
|
26ba25 |
.job_type = JOB_TYPE_BACKUP,
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
.start = backup_run,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
.commit = backup_commit,
|
|
|
26ba25 |
diff --git a/block/commit.c b/block/commit.c
|
|
|
26ba25 |
index 1c6cb6c..c4a98e5 100644
|
|
|
26ba25 |
--- a/block/commit.c
|
|
|
26ba25 |
+++ b/block/commit.c
|
|
|
26ba25 |
@@ -220,6 +220,7 @@ static const BlockJobDriver commit_job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(CommitBlockJob),
|
|
|
26ba25 |
.job_type = JOB_TYPE_COMMIT,
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
.start = commit_run,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
};
|
|
|
26ba25 |
diff --git a/block/mirror.c b/block/mirror.c
|
|
|
26ba25 |
index 5d8f75c..9a7226f 100644
|
|
|
26ba25 |
--- a/block/mirror.c
|
|
|
26ba25 |
+++ b/block/mirror.c
|
|
|
26ba25 |
@@ -991,6 +991,7 @@ static const BlockJobDriver mirror_job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(MirrorBlockJob),
|
|
|
26ba25 |
.job_type = JOB_TYPE_MIRROR,
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
.start = mirror_run,
|
|
|
26ba25 |
.pause = mirror_pause,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
@@ -1004,6 +1005,7 @@ static const BlockJobDriver commit_active_job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(MirrorBlockJob),
|
|
|
26ba25 |
.job_type = JOB_TYPE_COMMIT,
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
.start = mirror_run,
|
|
|
26ba25 |
.pause = mirror_pause,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
diff --git a/block/stream.c b/block/stream.c
|
|
|
26ba25 |
index 1faab02..e81b488 100644
|
|
|
26ba25 |
--- a/block/stream.c
|
|
|
26ba25 |
+++ b/block/stream.c
|
|
|
26ba25 |
@@ -214,6 +214,7 @@ static const BlockJobDriver stream_job_driver = {
|
|
|
26ba25 |
.job_type = JOB_TYPE_STREAM,
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
.start = stream_run,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
};
|
|
|
26ba25 |
|
|
|
26ba25 |
diff --git a/blockdev.c b/blockdev.c
|
|
|
26ba25 |
index 93a4cdf..522158c 100644
|
|
|
26ba25 |
--- a/blockdev.c
|
|
|
26ba25 |
+++ b/blockdev.c
|
|
|
26ba25 |
@@ -3845,7 +3845,7 @@ void qmp_block_job_cancel(const char *device,
|
|
|
26ba25 |
force = false;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
- if (block_job_user_paused(job) && !force) {
|
|
|
26ba25 |
+ if (job_user_paused(&job->job) && !force) {
|
|
|
26ba25 |
error_setg(errp, "The block job for device '%s' is currently paused",
|
|
|
26ba25 |
device);
|
|
|
26ba25 |
goto out;
|
|
|
26ba25 |
@@ -3867,7 +3867,7 @@ void qmp_block_job_pause(const char *device, Error **errp)
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
trace_qmp_block_job_pause(job);
|
|
|
26ba25 |
- block_job_user_pause(job, errp);
|
|
|
26ba25 |
+ job_user_pause(&job->job, errp);
|
|
|
26ba25 |
aio_context_release(aio_context);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
@@ -3881,7 +3881,7 @@ void qmp_block_job_resume(const char *device, Error **errp)
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
trace_qmp_block_job_resume(job);
|
|
|
26ba25 |
- block_job_user_resume(job, errp);
|
|
|
26ba25 |
+ job_user_resume(&job->job, errp);
|
|
|
26ba25 |
aio_context_release(aio_context);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
diff --git a/blockjob.c b/blockjob.c
|
|
|
26ba25 |
index 4dc360c..6334a54 100644
|
|
|
26ba25 |
--- a/blockjob.c
|
|
|
26ba25 |
+++ b/blockjob.c
|
|
|
26ba25 |
@@ -140,29 +140,6 @@ static void block_job_txn_del_job(BlockJob *job)
|
|
|
26ba25 |
}
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
-/* Assumes the job_mutex is held */
|
|
|
26ba25 |
-static bool job_timer_not_pending(Job *job)
|
|
|
26ba25 |
-{
|
|
|
26ba25 |
- return !timer_pending(&job->sleep_timer);
|
|
|
26ba25 |
-}
|
|
|
26ba25 |
-
|
|
|
26ba25 |
-static void block_job_pause(BlockJob *job)
|
|
|
26ba25 |
-{
|
|
|
26ba25 |
- job->job.pause_count++;
|
|
|
26ba25 |
-}
|
|
|
26ba25 |
-
|
|
|
26ba25 |
-static void block_job_resume(BlockJob *job)
|
|
|
26ba25 |
-{
|
|
|
26ba25 |
- assert(job->job.pause_count > 0);
|
|
|
26ba25 |
- job->job.pause_count--;
|
|
|
26ba25 |
- if (job->job.pause_count) {
|
|
|
26ba25 |
- return;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
-
|
|
|
26ba25 |
- /* kick only if no timer is pending */
|
|
|
26ba25 |
- job_enter_cond(&job->job, job_timer_not_pending);
|
|
|
26ba25 |
-}
|
|
|
26ba25 |
-
|
|
|
26ba25 |
static void block_job_attached_aio_context(AioContext *new_context,
|
|
|
26ba25 |
void *opaque);
|
|
|
26ba25 |
static void block_job_detach_aio_context(void *opaque);
|
|
|
26ba25 |
@@ -193,7 +170,7 @@ static void block_job_attached_aio_context(AioContext *new_context,
|
|
|
26ba25 |
job->driver->attached_aio_context(job, new_context);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
- block_job_resume(job);
|
|
|
26ba25 |
+ job_resume(&job->job);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
static void block_job_drain(BlockJob *job)
|
|
|
26ba25 |
@@ -214,7 +191,7 @@ static void block_job_detach_aio_context(void *opaque)
|
|
|
26ba25 |
/* In case the job terminates during aio_poll()... */
|
|
|
26ba25 |
job_ref(&job->job);
|
|
|
26ba25 |
|
|
|
26ba25 |
- block_job_pause(job);
|
|
|
26ba25 |
+ job_pause(&job->job);
|
|
|
26ba25 |
|
|
|
26ba25 |
while (!job->job.paused && !job->completed) {
|
|
|
26ba25 |
block_job_drain(job);
|
|
|
26ba25 |
@@ -233,13 +210,13 @@ static char *child_job_get_parent_desc(BdrvChild *c)
|
|
|
26ba25 |
static void child_job_drained_begin(BdrvChild *c)
|
|
|
26ba25 |
{
|
|
|
26ba25 |
BlockJob *job = c->opaque;
|
|
|
26ba25 |
- block_job_pause(job);
|
|
|
26ba25 |
+ job_pause(&job->job);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
static void child_job_drained_end(BdrvChild *c)
|
|
|
26ba25 |
{
|
|
|
26ba25 |
BlockJob *job = c->opaque;
|
|
|
26ba25 |
- block_job_resume(job);
|
|
|
26ba25 |
+ job_resume(&job->job);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
static const BdrvChildRole child_job = {
|
|
|
26ba25 |
@@ -396,9 +373,9 @@ static void block_job_cancel_async(BlockJob *job, bool force)
|
|
|
26ba25 |
if (job->iostatus != BLOCK_DEVICE_IO_STATUS_OK) {
|
|
|
26ba25 |
block_job_iostatus_reset(job);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
- if (job->user_paused) {
|
|
|
26ba25 |
+ if (job->job.user_paused) {
|
|
|
26ba25 |
/* Do not call block_job_enter here, the caller will handle it. */
|
|
|
26ba25 |
- job->user_paused = false;
|
|
|
26ba25 |
+ job->job.user_paused = false;
|
|
|
26ba25 |
job->job.pause_count--;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
job->job.cancelled = true;
|
|
|
26ba25 |
@@ -628,39 +605,6 @@ void block_job_dismiss(BlockJob **jobptr, Error **errp)
|
|
|
26ba25 |
*jobptr = NULL;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
-void block_job_user_pause(BlockJob *job, Error **errp)
|
|
|
26ba25 |
-{
|
|
|
26ba25 |
- if (job_apply_verb(&job->job, JOB_VERB_PAUSE, errp)) {
|
|
|
26ba25 |
- return;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
- if (job->user_paused) {
|
|
|
26ba25 |
- error_setg(errp, "Job is already paused");
|
|
|
26ba25 |
- return;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
- job->user_paused = true;
|
|
|
26ba25 |
- block_job_pause(job);
|
|
|
26ba25 |
-}
|
|
|
26ba25 |
-
|
|
|
26ba25 |
-bool block_job_user_paused(BlockJob *job)
|
|
|
26ba25 |
-{
|
|
|
26ba25 |
- return job->user_paused;
|
|
|
26ba25 |
-}
|
|
|
26ba25 |
-
|
|
|
26ba25 |
-void block_job_user_resume(BlockJob *job, Error **errp)
|
|
|
26ba25 |
-{
|
|
|
26ba25 |
- assert(job);
|
|
|
26ba25 |
- if (!job->user_paused || job->job.pause_count <= 0) {
|
|
|
26ba25 |
- error_setg(errp, "Can't resume a job that was not paused");
|
|
|
26ba25 |
- return;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
- if (job_apply_verb(&job->job, JOB_VERB_RESUME, errp)) {
|
|
|
26ba25 |
- return;
|
|
|
26ba25 |
- }
|
|
|
26ba25 |
- block_job_iostatus_reset(job);
|
|
|
26ba25 |
- job->user_paused = false;
|
|
|
26ba25 |
- block_job_resume(job);
|
|
|
26ba25 |
-}
|
|
|
26ba25 |
-
|
|
|
26ba25 |
void block_job_cancel(BlockJob *job, bool force)
|
|
|
26ba25 |
{
|
|
|
26ba25 |
if (job->job.status == JOB_STATUS_CONCLUDED) {
|
|
|
26ba25 |
@@ -851,6 +795,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
|
|
26ba25 |
|
|
|
26ba25 |
assert(is_block_job(&job->job));
|
|
|
26ba25 |
assert(job->job.driver->free == &block_job_free);
|
|
|
26ba25 |
+ assert(job->job.driver->user_resume == &block_job_user_resume);
|
|
|
26ba25 |
|
|
|
26ba25 |
job->driver = driver;
|
|
|
26ba25 |
job->blk = blk;
|
|
|
26ba25 |
@@ -941,10 +886,16 @@ void block_job_iostatus_reset(BlockJob *job)
|
|
|
26ba25 |
if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
|
|
26ba25 |
return;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
- assert(job->user_paused && job->job.pause_count > 0);
|
|
|
26ba25 |
+ assert(job->job.user_paused && job->job.pause_count > 0);
|
|
|
26ba25 |
job->iostatus = BLOCK_DEVICE_IO_STATUS_OK;
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
+void block_job_user_resume(Job *job)
|
|
|
26ba25 |
+{
|
|
|
26ba25 |
+ BlockJob *bjob = container_of(job, BlockJob, job);
|
|
|
26ba25 |
+ block_job_iostatus_reset(bjob);
|
|
|
26ba25 |
+}
|
|
|
26ba25 |
+
|
|
|
26ba25 |
void block_job_event_ready(BlockJob *job)
|
|
|
26ba25 |
{
|
|
|
26ba25 |
job_state_transition(&job->job, JOB_STATUS_READY);
|
|
|
26ba25 |
@@ -991,9 +942,9 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
|
|
|
26ba25 |
action, &error_abort);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
if (action == BLOCK_ERROR_ACTION_STOP) {
|
|
|
26ba25 |
- block_job_pause(job);
|
|
|
26ba25 |
+ job_pause(&job->job);
|
|
|
26ba25 |
/* make the pause user visible, which will be resumed from QMP. */
|
|
|
26ba25 |
- job->user_paused = true;
|
|
|
26ba25 |
+ job->job.user_paused = true;
|
|
|
26ba25 |
block_job_iostatus_set_err(job, error);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
return action;
|
|
|
26ba25 |
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
|
|
|
26ba25 |
index b60d919..556a8f6 100644
|
|
|
26ba25 |
--- a/include/block/blockjob.h
|
|
|
26ba25 |
+++ b/include/block/blockjob.h
|
|
|
26ba25 |
@@ -57,12 +57,6 @@ typedef struct BlockJob {
|
|
|
26ba25 |
bool force;
|
|
|
26ba25 |
|
|
|
26ba25 |
/**
|
|
|
26ba25 |
- * Set to true if the job is paused by user. Can be unpaused with the
|
|
|
26ba25 |
- * block-job-resume QMP command.
|
|
|
26ba25 |
- */
|
|
|
26ba25 |
- bool user_paused;
|
|
|
26ba25 |
-
|
|
|
26ba25 |
- /**
|
|
|
26ba25 |
* Set to true when the job is ready to be completed.
|
|
|
26ba25 |
*/
|
|
|
26ba25 |
bool ready;
|
|
|
26ba25 |
@@ -248,32 +242,6 @@ void block_job_progress_set_remaining(BlockJob *job, uint64_t remaining);
|
|
|
26ba25 |
BlockJobInfo *block_job_query(BlockJob *job, Error **errp);
|
|
|
26ba25 |
|
|
|
26ba25 |
/**
|
|
|
26ba25 |
- * block_job_user_pause:
|
|
|
26ba25 |
- * @job: The job to be paused.
|
|
|
26ba25 |
- *
|
|
|
26ba25 |
- * Asynchronously pause the specified job.
|
|
|
26ba25 |
- * Do not allow a resume until a matching call to block_job_user_resume.
|
|
|
26ba25 |
- */
|
|
|
26ba25 |
-void block_job_user_pause(BlockJob *job, Error **errp);
|
|
|
26ba25 |
-
|
|
|
26ba25 |
-/**
|
|
|
26ba25 |
- * block_job_paused:
|
|
|
26ba25 |
- * @job: The job to query.
|
|
|
26ba25 |
- *
|
|
|
26ba25 |
- * Returns true if the job is user-paused.
|
|
|
26ba25 |
- */
|
|
|
26ba25 |
-bool block_job_user_paused(BlockJob *job);
|
|
|
26ba25 |
-
|
|
|
26ba25 |
-/**
|
|
|
26ba25 |
- * block_job_user_resume:
|
|
|
26ba25 |
- * @job: The job to be resumed.
|
|
|
26ba25 |
- *
|
|
|
26ba25 |
- * Resume the specified job.
|
|
|
26ba25 |
- * Must be paired with a preceding block_job_user_pause.
|
|
|
26ba25 |
- */
|
|
|
26ba25 |
-void block_job_user_resume(BlockJob *job, Error **errp);
|
|
|
26ba25 |
-
|
|
|
26ba25 |
-/**
|
|
|
26ba25 |
* block_job_user_cancel:
|
|
|
26ba25 |
* @job: The job to be cancelled.
|
|
|
26ba25 |
* @force: Quit a job without waiting for data to be in sync.
|
|
|
26ba25 |
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
|
|
|
26ba25 |
index 8937f5b..7e705ae 100644
|
|
|
26ba25 |
--- a/include/block/blockjob_int.h
|
|
|
26ba25 |
+++ b/include/block/blockjob_int.h
|
|
|
26ba25 |
@@ -134,6 +134,13 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
|
|
26ba25 |
void block_job_free(Job *job);
|
|
|
26ba25 |
|
|
|
26ba25 |
/**
|
|
|
26ba25 |
+ * block_job_user_resume:
|
|
|
26ba25 |
+ * Callback to be used for JobDriver.user_resume in all block jobs. Resets the
|
|
|
26ba25 |
+ * iostatus when the user resumes @job.
|
|
|
26ba25 |
+ */
|
|
|
26ba25 |
+void block_job_user_resume(Job *job);
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+/**
|
|
|
26ba25 |
* block_job_yield:
|
|
|
26ba25 |
* @job: The job that calls the function.
|
|
|
26ba25 |
*
|
|
|
26ba25 |
diff --git a/include/qemu/job.h b/include/qemu/job.h
|
|
|
26ba25 |
index 509408f..bc63985 100644
|
|
|
26ba25 |
--- a/include/qemu/job.h
|
|
|
26ba25 |
+++ b/include/qemu/job.h
|
|
|
26ba25 |
@@ -83,6 +83,12 @@ typedef struct Job {
|
|
|
26ba25 |
bool paused;
|
|
|
26ba25 |
|
|
|
26ba25 |
/**
|
|
|
26ba25 |
+ * Set to true if the job is paused by user. Can be unpaused with the
|
|
|
26ba25 |
+ * block-job-resume QMP command.
|
|
|
26ba25 |
+ */
|
|
|
26ba25 |
+ bool user_paused;
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+ /**
|
|
|
26ba25 |
* Set to true if the job should cancel itself. The flag must
|
|
|
26ba25 |
* always be tested just before toggling the busy flag from false
|
|
|
26ba25 |
* to true. After a job has been cancelled, it should only yield
|
|
|
26ba25 |
@@ -124,6 +130,12 @@ struct JobDriver {
|
|
|
26ba25 |
*/
|
|
|
26ba25 |
void coroutine_fn (*resume)(Job *job);
|
|
|
26ba25 |
|
|
|
26ba25 |
+ /**
|
|
|
26ba25 |
+ * Called when the job is resumed by the user (i.e. user_paused becomes
|
|
|
26ba25 |
+ * false). .user_resume is called before .resume.
|
|
|
26ba25 |
+ */
|
|
|
26ba25 |
+ void (*user_resume)(Job *job);
|
|
|
26ba25 |
+
|
|
|
26ba25 |
/** Called when the job is freed */
|
|
|
26ba25 |
void (*free)(Job *job);
|
|
|
26ba25 |
};
|
|
|
26ba25 |
@@ -203,6 +215,31 @@ const char *job_type_str(const Job *job);
|
|
|
26ba25 |
bool job_is_cancelled(Job *job);
|
|
|
26ba25 |
|
|
|
26ba25 |
/**
|
|
|
26ba25 |
+ * Request @job to pause at the next pause point. Must be paired with
|
|
|
26ba25 |
+ * job_resume(). If the job is supposed to be resumed by user action, call
|
|
|
26ba25 |
+ * job_user_pause() instead.
|
|
|
26ba25 |
+ */
|
|
|
26ba25 |
+void job_pause(Job *job);
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+/** Resumes a @job paused with job_pause. */
|
|
|
26ba25 |
+void job_resume(Job *job);
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+/**
|
|
|
26ba25 |
+ * Asynchronously pause the specified @job.
|
|
|
26ba25 |
+ * Do not allow a resume until a matching call to job_user_resume.
|
|
|
26ba25 |
+ */
|
|
|
26ba25 |
+void job_user_pause(Job *job, Error **errp);
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+/** Returns true if the job is user-paused. */
|
|
|
26ba25 |
+bool job_user_paused(Job *job);
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+/**
|
|
|
26ba25 |
+ * Resume the specified @job.
|
|
|
26ba25 |
+ * Must be paired with a preceding job_user_pause.
|
|
|
26ba25 |
+ */
|
|
|
26ba25 |
+void job_user_resume(Job *job, Error **errp);
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+/**
|
|
|
26ba25 |
* Get the next element from the list of block jobs after @job, or the
|
|
|
26ba25 |
* first one if @job is %NULL.
|
|
|
26ba25 |
*
|
|
|
26ba25 |
diff --git a/job.c b/job.c
|
|
|
26ba25 |
index 1b8cba1..fd10b1d 100644
|
|
|
26ba25 |
--- a/job.c
|
|
|
26ba25 |
+++ b/job.c
|
|
|
26ba25 |
@@ -341,6 +341,65 @@ void job_start(Job *job)
|
|
|
26ba25 |
aio_co_enter(job->aio_context, job->co);
|
|
|
26ba25 |
}
|
|
|
26ba25 |
|
|
|
26ba25 |
+/* Assumes the block_job_mutex is held */
|
|
|
26ba25 |
+static bool job_timer_not_pending(Job *job)
|
|
|
26ba25 |
+{
|
|
|
26ba25 |
+ return !timer_pending(&job->sleep_timer);
|
|
|
26ba25 |
+}
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+void job_pause(Job *job)
|
|
|
26ba25 |
+{
|
|
|
26ba25 |
+ job->pause_count++;
|
|
|
26ba25 |
+}
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+void job_resume(Job *job)
|
|
|
26ba25 |
+{
|
|
|
26ba25 |
+ assert(job->pause_count > 0);
|
|
|
26ba25 |
+ job->pause_count--;
|
|
|
26ba25 |
+ if (job->pause_count) {
|
|
|
26ba25 |
+ return;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+ /* kick only if no timer is pending */
|
|
|
26ba25 |
+ job_enter_cond(job, job_timer_not_pending);
|
|
|
26ba25 |
+}
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+void job_user_pause(Job *job, Error **errp)
|
|
|
26ba25 |
+{
|
|
|
26ba25 |
+ if (job_apply_verb(job, JOB_VERB_PAUSE, errp)) {
|
|
|
26ba25 |
+ return;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+ if (job->user_paused) {
|
|
|
26ba25 |
+ error_setg(errp, "Job is already paused");
|
|
|
26ba25 |
+ return;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+ job->user_paused = true;
|
|
|
26ba25 |
+ job_pause(job);
|
|
|
26ba25 |
+}
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+bool job_user_paused(Job *job)
|
|
|
26ba25 |
+{
|
|
|
26ba25 |
+ return job->user_paused;
|
|
|
26ba25 |
+}
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+void job_user_resume(Job *job, Error **errp)
|
|
|
26ba25 |
+{
|
|
|
26ba25 |
+ assert(job);
|
|
|
26ba25 |
+ if (!job->user_paused || job->pause_count <= 0) {
|
|
|
26ba25 |
+ error_setg(errp, "Can't resume a job that was not paused");
|
|
|
26ba25 |
+ return;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+ if (job_apply_verb(job, JOB_VERB_RESUME, errp)) {
|
|
|
26ba25 |
+ return;
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+ if (job->driver->user_resume) {
|
|
|
26ba25 |
+ job->driver->user_resume(job);
|
|
|
26ba25 |
+ }
|
|
|
26ba25 |
+ job->user_paused = false;
|
|
|
26ba25 |
+ job_resume(job);
|
|
|
26ba25 |
+}
|
|
|
26ba25 |
+
|
|
|
26ba25 |
+
|
|
|
26ba25 |
typedef struct {
|
|
|
26ba25 |
Job *job;
|
|
|
26ba25 |
JobDeferToMainLoopFn *fn;
|
|
|
26ba25 |
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
|
|
|
26ba25 |
index 50232f5..c993512 100644
|
|
|
26ba25 |
--- a/tests/test-bdrv-drain.c
|
|
|
26ba25 |
+++ b/tests/test-bdrv-drain.c
|
|
|
26ba25 |
@@ -524,6 +524,7 @@ BlockJobDriver test_job_driver = {
|
|
|
26ba25 |
.job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(TestBlockJob),
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
.start = test_job_start,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
.complete = test_job_complete,
|
|
|
26ba25 |
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
|
|
|
26ba25 |
index 0e6162b..93d1ff0 100644
|
|
|
26ba25 |
--- a/tests/test-blockjob-txn.c
|
|
|
26ba25 |
+++ b/tests/test-blockjob-txn.c
|
|
|
26ba25 |
@@ -78,6 +78,7 @@ static const BlockJobDriver test_block_job_driver = {
|
|
|
26ba25 |
.job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(TestBlockJob),
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
.start = test_block_job_run,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
};
|
|
|
26ba25 |
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
|
|
|
26ba25 |
index b329bd5..ceb5960 100644
|
|
|
26ba25 |
--- a/tests/test-blockjob.c
|
|
|
26ba25 |
+++ b/tests/test-blockjob.c
|
|
|
26ba25 |
@@ -20,6 +20,7 @@ static const BlockJobDriver test_block_job_driver = {
|
|
|
26ba25 |
.job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(BlockJob),
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
};
|
|
|
26ba25 |
|
|
|
26ba25 |
@@ -199,6 +200,7 @@ static const BlockJobDriver test_cancel_driver = {
|
|
|
26ba25 |
.job_driver = {
|
|
|
26ba25 |
.instance_size = sizeof(CancelJob),
|
|
|
26ba25 |
.free = block_job_free,
|
|
|
26ba25 |
+ .user_resume = block_job_user_resume,
|
|
|
26ba25 |
.start = cancel_job_start,
|
|
|
26ba25 |
},
|
|
|
26ba25 |
.complete = cancel_job_complete,
|
|
|
26ba25 |
@@ -270,7 +272,7 @@ static void test_cancel_paused(void)
|
|
|
26ba25 |
job_start(&job->job);
|
|
|
26ba25 |
assert(job->job.status == JOB_STATUS_RUNNING);
|
|
|
26ba25 |
|
|
|
26ba25 |
- block_job_user_pause(job, &error_abort);
|
|
|
26ba25 |
+ job_user_pause(&job->job, &error_abort);
|
|
|
26ba25 |
block_job_enter(job);
|
|
|
26ba25 |
assert(job->job.status == JOB_STATUS_PAUSED);
|
|
|
26ba25 |
|
|
|
26ba25 |
@@ -308,7 +310,7 @@ static void test_cancel_standby(void)
|
|
|
26ba25 |
block_job_enter(job);
|
|
|
26ba25 |
assert(job->job.status == JOB_STATUS_READY);
|
|
|
26ba25 |
|
|
|
26ba25 |
- block_job_user_pause(job, &error_abort);
|
|
|
26ba25 |
+ job_user_pause(&job->job, &error_abort);
|
|
|
26ba25 |
block_job_enter(job);
|
|
|
26ba25 |
assert(job->job.status == JOB_STATUS_STANDBY);
|
|
|
26ba25 |
|
|
|
26ba25 |
--
|
|
|
26ba25 |
1.8.3.1
|
|
|
26ba25 |
|