26ba25
From 83f845c133441c92d87a0040f4b52c3e2654b995 Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Tue, 26 Jun 2018 09:48:26 +0200
26ba25
Subject: [PATCH 118/268] job: Add job_dismiss()
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20180626094856.6924-44-kwolf@redhat.com>
26ba25
Patchwork-id: 81125
26ba25
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 43/73] job: Add job_dismiss()
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
This moves block_job_dismiss() to the Job layer.
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Reviewed-by: Max Reitz <mreitz@redhat.com>
26ba25
(cherry picked from commit 5f9a6a08e8f65e01746d2485fc65a3a78e74865f)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 blockdev.c               | 10 ++++++----
26ba25
 blockjob.c               | 13 -------------
26ba25
 include/block/blockjob.h |  9 ---------
26ba25
 include/qemu/job.h       |  7 ++++++-
26ba25
 job.c                    | 15 ++++++++++++++-
26ba25
 tests/test-blockjob.c    |  4 ++--
26ba25
 6 files changed, 28 insertions(+), 30 deletions(-)
26ba25
26ba25
diff --git a/blockdev.c b/blockdev.c
26ba25
index c768e68..721dc9a 100644
26ba25
--- a/blockdev.c
26ba25
+++ b/blockdev.c
26ba25
@@ -3916,14 +3916,16 @@ void qmp_block_job_finalize(const char *id, Error **errp)
26ba25
 void qmp_block_job_dismiss(const char *id, Error **errp)
26ba25
 {
26ba25
     AioContext *aio_context;
26ba25
-    BlockJob *job = find_block_job(id, &aio_context, errp);
26ba25
+    BlockJob *bjob = find_block_job(id, &aio_context, errp);
26ba25
+    Job *job;
26ba25
 
26ba25
-    if (!job) {
26ba25
+    if (!bjob) {
26ba25
         return;
26ba25
     }
26ba25
 
26ba25
-    trace_qmp_block_job_dismiss(job);
26ba25
-    block_job_dismiss(&job, errp);
26ba25
+    trace_qmp_block_job_dismiss(bjob);
26ba25
+    job = &bjob->job;
26ba25
+    job_dismiss(&job, errp);
26ba25
     aio_context_release(aio_context);
26ba25
 }
26ba25
 
26ba25
diff --git a/blockjob.c b/blockjob.c
26ba25
index f146fe0..3ca009b 100644
26ba25
--- a/blockjob.c
26ba25
+++ b/blockjob.c
26ba25
@@ -242,19 +242,6 @@ int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n)
26ba25
     return ratelimit_calculate_delay(&job->limit, n);
26ba25
 }
26ba25
 
26ba25
-void block_job_dismiss(BlockJob **jobptr, Error **errp)
26ba25
-{
26ba25
-    BlockJob *job = *jobptr;
26ba25
-    /* similarly to _complete, this is QMP-interface only. */
26ba25
-    assert(job->job.id);
26ba25
-    if (job_apply_verb(&job->job, JOB_VERB_DISMISS, errp)) {
26ba25
-        return;
26ba25
-    }
26ba25
-
26ba25
-    job_do_dismiss(&job->job);
26ba25
-    *jobptr = NULL;
26ba25
-}
26ba25
-
26ba25
 void block_job_progress_update(BlockJob *job, uint64_t done)
26ba25
 {
26ba25
     job->offset += done;
26ba25
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
26ba25
index e9ed7b8..5a81afc 100644
26ba25
--- a/include/block/blockjob.h
26ba25
+++ b/include/block/blockjob.h
26ba25
@@ -141,15 +141,6 @@ void block_job_remove_all_bdrv(BlockJob *job);
26ba25
 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
26ba25
 
26ba25
 /**
26ba25
- * block_job_dismiss:
26ba25
- * @job: The job to be dismissed.
26ba25
- * @errp: Error object.
26ba25
- *
26ba25
- * Remove a concluded job from the query list.
26ba25
- */
26ba25
-void block_job_dismiss(BlockJob **job, Error **errp);
26ba25
-
26ba25
-/**
26ba25
  * block_job_progress_update:
26ba25
  * @job: The job that has made progress
26ba25
  * @done: How much progress the job made
26ba25
diff --git a/include/qemu/job.h b/include/qemu/job.h
26ba25
index 94900ec..1e8050c 100644
26ba25
--- a/include/qemu/job.h
26ba25
+++ b/include/qemu/job.h
26ba25
@@ -487,6 +487,12 @@ int job_complete_sync(Job *job, Error **errp);
26ba25
  */
26ba25
 void job_finalize(Job *job, Error **errp);
26ba25
 
26ba25
+/**
26ba25
+ * Remove the concluded @job from the query list and resets the passed pointer
26ba25
+ * to %NULL. Returns an error if the job is not actually concluded.
26ba25
+ */
26ba25
+void job_dismiss(Job **job, Error **errp);
26ba25
+
26ba25
 typedef void JobDeferToMainLoopFn(Job *job, void *opaque);
26ba25
 
26ba25
 /**
26ba25
@@ -515,6 +521,5 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
26ba25
 
26ba25
 /* TODO To be removed from the public interface */
26ba25
 void job_state_transition(Job *job, JobStatus s1);
26ba25
-void job_do_dismiss(Job *job);
26ba25
 
26ba25
 #endif
26ba25
diff --git a/job.c b/job.c
26ba25
index eede680..7cd3602 100644
26ba25
--- a/job.c
26ba25
+++ b/job.c
26ba25
@@ -568,7 +568,7 @@ void job_user_resume(Job *job, Error **errp)
26ba25
     job_resume(job);
26ba25
 }
26ba25
 
26ba25
-void job_do_dismiss(Job *job)
26ba25
+static void job_do_dismiss(Job *job)
26ba25
 {
26ba25
     assert(job);
26ba25
     job->busy = false;
26ba25
@@ -581,6 +581,19 @@ void job_do_dismiss(Job *job)
26ba25
     job_unref(job);
26ba25
 }
26ba25
 
26ba25
+void job_dismiss(Job **jobptr, Error **errp)
26ba25
+{
26ba25
+    Job *job = *jobptr;
26ba25
+    /* similarly to _complete, this is QMP-interface only. */
26ba25
+    assert(job->id);
26ba25
+    if (job_apply_verb(job, JOB_VERB_DISMISS, errp)) {
26ba25
+        return;
26ba25
+    }
26ba25
+
26ba25
+    job_do_dismiss(job);
26ba25
+    *jobptr = NULL;
26ba25
+}
26ba25
+
26ba25
 void job_early_fail(Job *job)
26ba25
 {
26ba25
     assert(job->status == JOB_STATUS_CREATED);
26ba25
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
26ba25
index 46a7873..7131cab 100644
26ba25
--- a/tests/test-blockjob.c
26ba25
+++ b/tests/test-blockjob.c
26ba25
@@ -233,8 +233,8 @@ static void cancel_common(CancelJob *s)
26ba25
 
26ba25
     job_cancel_sync(&job->job);
26ba25
     if (sts != JOB_STATUS_CREATED && sts != JOB_STATUS_CONCLUDED) {
26ba25
-        BlockJob *dummy = job;
26ba25
-        block_job_dismiss(&dummy, &error_abort);
26ba25
+        Job *dummy = &job->job;
26ba25
+        job_dismiss(&dummy, &error_abort);
26ba25
     }
26ba25
     assert(job->job.status == JOB_STATUS_NULL);
26ba25
     job_unref(&job->job);
26ba25
-- 
26ba25
1.8.3.1
26ba25