|
|
357786 |
From 053dd2951086a745e456f083d67e055f27029c3d Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Date: Tue, 26 Jun 2018 09:48:25 +0200
|
|
|
357786 |
Subject: [PATCH 56/89] job: Add job_yield()
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Message-id: <20180626094856.6924-43-kwolf@redhat.com>
|
|
|
357786 |
Patchwork-id: 81120
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 42/73] job: Add job_yield()
|
|
|
357786 |
Bugzilla: 1513543
|
|
|
357786 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
357786 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
This moves block_job_yield() to the Job layer.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit 198c49cc8d81e8eb0df3749d395599895c3a3a76)
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
block/backup.c | 2 +-
|
|
|
357786 |
block/mirror.c | 2 +-
|
|
|
357786 |
blockjob.c | 16 ----------------
|
|
|
357786 |
include/block/blockjob_int.h | 8 --------
|
|
|
357786 |
include/qemu/job.h | 9 +++++++--
|
|
|
357786 |
job.c | 20 ++++++++++++++++++--
|
|
|
357786 |
tests/test-blockjob-txn.c | 2 +-
|
|
|
357786 |
7 files changed, 28 insertions(+), 31 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/block/backup.c b/block/backup.c
|
|
|
357786 |
index b13f91d..6f4f3df 100644
|
|
|
357786 |
--- a/block/backup.c
|
|
|
357786 |
+++ b/block/backup.c
|
|
|
357786 |
@@ -444,7 +444,7 @@ static void coroutine_fn backup_run(void *opaque)
|
|
|
357786 |
while (!job_is_cancelled(&job->common.job)) {
|
|
|
357786 |
/* Yield until the job is cancelled. We just let our before_write
|
|
|
357786 |
* notify callback service CoW requests. */
|
|
|
357786 |
- block_job_yield(&job->common);
|
|
|
357786 |
+ job_yield(&job->common.job);
|
|
|
357786 |
}
|
|
|
357786 |
} else if (job->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
|
|
|
357786 |
ret = backup_run_incremental(job);
|
|
|
357786 |
diff --git a/block/mirror.c b/block/mirror.c
|
|
|
357786 |
index c63cf7c..687f955 100644
|
|
|
357786 |
--- a/block/mirror.c
|
|
|
357786 |
+++ b/block/mirror.c
|
|
|
357786 |
@@ -731,7 +731,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
|
|
357786 |
block_job_event_ready(&s->common);
|
|
|
357786 |
s->synced = true;
|
|
|
357786 |
while (!job_is_cancelled(&s->common.job) && !s->should_complete) {
|
|
|
357786 |
- block_job_yield(&s->common);
|
|
|
357786 |
+ job_yield(&s->common.job);
|
|
|
357786 |
}
|
|
|
357786 |
s->common.job.cancelled = false;
|
|
|
357786 |
goto immediate_exit;
|
|
|
357786 |
diff --git a/blockjob.c b/blockjob.c
|
|
|
357786 |
index 438baa1..f146fe0 100644
|
|
|
357786 |
--- a/blockjob.c
|
|
|
357786 |
+++ b/blockjob.c
|
|
|
357786 |
@@ -431,22 +431,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
|
|
357786 |
return job;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-void block_job_yield(BlockJob *job)
|
|
|
357786 |
-{
|
|
|
357786 |
- assert(job->job.busy);
|
|
|
357786 |
-
|
|
|
357786 |
- /* Check cancellation *before* setting busy = false, too! */
|
|
|
357786 |
- if (job_is_cancelled(&job->job)) {
|
|
|
357786 |
- return;
|
|
|
357786 |
- }
|
|
|
357786 |
-
|
|
|
357786 |
- if (!job_should_pause(&job->job)) {
|
|
|
357786 |
- job_do_yield(&job->job, -1);
|
|
|
357786 |
- }
|
|
|
357786 |
-
|
|
|
357786 |
- job_pause_point(&job->job);
|
|
|
357786 |
-}
|
|
|
357786 |
-
|
|
|
357786 |
void block_job_iostatus_reset(BlockJob *job)
|
|
|
357786 |
{
|
|
|
357786 |
if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
|
|
357786 |
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
|
|
|
357786 |
index 7df07b2..806ac64 100644
|
|
|
357786 |
--- a/include/block/blockjob_int.h
|
|
|
357786 |
+++ b/include/block/blockjob_int.h
|
|
|
357786 |
@@ -108,14 +108,6 @@ void block_job_user_resume(Job *job);
|
|
|
357786 |
void block_job_drain(Job *job);
|
|
|
357786 |
|
|
|
357786 |
/**
|
|
|
357786 |
- * block_job_yield:
|
|
|
357786 |
- * @job: The job that calls the function.
|
|
|
357786 |
- *
|
|
|
357786 |
- * Yield the block job coroutine.
|
|
|
357786 |
- */
|
|
|
357786 |
-void block_job_yield(BlockJob *job);
|
|
|
357786 |
-
|
|
|
357786 |
-/**
|
|
|
357786 |
* block_job_ratelimit_get_delay:
|
|
|
357786 |
*
|
|
|
357786 |
* Calculate and return delay for the next request in ns. See the documentation
|
|
|
357786 |
diff --git a/include/qemu/job.h b/include/qemu/job.h
|
|
|
357786 |
index bbe1b0c..94900ec 100644
|
|
|
357786 |
--- a/include/qemu/job.h
|
|
|
357786 |
+++ b/include/qemu/job.h
|
|
|
357786 |
@@ -339,6 +339,13 @@ void coroutine_fn job_pause_point(Job *job);
|
|
|
357786 |
|
|
|
357786 |
/**
|
|
|
357786 |
* @job: The job that calls the function.
|
|
|
357786 |
+ *
|
|
|
357786 |
+ * Yield the job coroutine.
|
|
|
357786 |
+ */
|
|
|
357786 |
+void job_yield(Job *job);
|
|
|
357786 |
+
|
|
|
357786 |
+/**
|
|
|
357786 |
+ * @job: The job that calls the function.
|
|
|
357786 |
* @ns: How many nanoseconds to stop for.
|
|
|
357786 |
*
|
|
|
357786 |
* Put the job to sleep (assuming that it wasn't canceled) for @ns
|
|
|
357786 |
@@ -508,8 +515,6 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
|
|
|
357786 |
|
|
|
357786 |
/* TODO To be removed from the public interface */
|
|
|
357786 |
void job_state_transition(Job *job, JobStatus s1);
|
|
|
357786 |
-void coroutine_fn job_do_yield(Job *job, uint64_t ns);
|
|
|
357786 |
-bool job_should_pause(Job *job);
|
|
|
357786 |
void job_do_dismiss(Job *job);
|
|
|
357786 |
|
|
|
357786 |
#endif
|
|
|
357786 |
diff --git a/job.c b/job.c
|
|
|
357786 |
index 2e453f6..eede680 100644
|
|
|
357786 |
--- a/job.c
|
|
|
357786 |
+++ b/job.c
|
|
|
357786 |
@@ -226,7 +226,7 @@ static bool job_started(Job *job)
|
|
|
357786 |
return job->co;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-bool job_should_pause(Job *job)
|
|
|
357786 |
+static bool job_should_pause(Job *job)
|
|
|
357786 |
{
|
|
|
357786 |
return job->pause_count > 0;
|
|
|
357786 |
}
|
|
|
357786 |
@@ -396,7 +396,7 @@ void job_enter(Job *job)
|
|
|
357786 |
*
|
|
|
357786 |
* If @ns is (uint64_t) -1, no timer is scheduled and job_enter() must be
|
|
|
357786 |
* called explicitly. */
|
|
|
357786 |
-void coroutine_fn job_do_yield(Job *job, uint64_t ns)
|
|
|
357786 |
+static void coroutine_fn job_do_yield(Job *job, uint64_t ns)
|
|
|
357786 |
{
|
|
|
357786 |
job_lock();
|
|
|
357786 |
if (ns != -1) {
|
|
|
357786 |
@@ -441,6 +441,22 @@ void coroutine_fn job_pause_point(Job *job)
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+void job_yield(Job *job)
|
|
|
357786 |
+{
|
|
|
357786 |
+ assert(job->busy);
|
|
|
357786 |
+
|
|
|
357786 |
+ /* Check cancellation *before* setting busy = false, too! */
|
|
|
357786 |
+ if (job_is_cancelled(job)) {
|
|
|
357786 |
+ return;
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
+ if (!job_should_pause(job)) {
|
|
|
357786 |
+ job_do_yield(job, -1);
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
+ job_pause_point(job);
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
void coroutine_fn job_sleep_ns(Job *job, int64_t ns)
|
|
|
357786 |
{
|
|
|
357786 |
assert(job->busy);
|
|
|
357786 |
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
|
|
|
357786 |
index 34ee179..fce8366 100644
|
|
|
357786 |
--- a/tests/test-blockjob-txn.c
|
|
|
357786 |
+++ b/tests/test-blockjob-txn.c
|
|
|
357786 |
@@ -47,7 +47,7 @@ static void coroutine_fn test_block_job_run(void *opaque)
|
|
|
357786 |
if (s->use_timer) {
|
|
|
357786 |
job_sleep_ns(&job->job, 0);
|
|
|
357786 |
} else {
|
|
|
357786 |
- block_job_yield(job);
|
|
|
357786 |
+ job_yield(&job->job);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (job_is_cancelled(&job->job)) {
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|