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