thebeanogamer / rpms / qemu-kvm

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