Blame SOURCES/kvm-job-Add-JobDriver.job_type.patch

357786
From afe531712d6465c1a850a8538c1756dbad10135a Mon Sep 17 00:00:00 2001
357786
From: Kevin Wolf <kwolf@redhat.com>
357786
Date: Tue, 26 Jun 2018 09:48:01 +0200
357786
Subject: [PATCH 32/89] job: Add JobDriver.job_type
357786
357786
RH-Author: Kevin Wolf <kwolf@redhat.com>
357786
Message-id: <20180626094856.6924-19-kwolf@redhat.com>
357786
Patchwork-id: 81063
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 18/73] job: Add JobDriver.job_type
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 the job_type field from BlockJobDriver to JobDriver.
357786
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
Reviewed-by: Max Reitz <mreitz@redhat.com>
357786
Reviewed-by: John Snow <jsnow@redhat.com>
357786
(cherry picked from commit 252291eaeafcd234a602d71cdf9415dbfc7bc867)
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/commit.c               |  2 +-
357786
 block/mirror.c               |  4 ++--
357786
 block/stream.c               |  2 +-
357786
 blockjob.c                   | 16 +++++++---------
357786
 include/block/blockjob_int.h |  3 ---
357786
 include/qemu/job.h           | 11 +++++++++++
357786
 job.c                        | 10 ++++++++++
357786
 8 files changed, 33 insertions(+), 17 deletions(-)
357786
357786
diff --git a/block/backup.c b/block/backup.c
357786
index c49ea92..baf8d43 100644
357786
--- a/block/backup.c
357786
+++ b/block/backup.c
357786
@@ -525,8 +525,8 @@ static void coroutine_fn backup_run(void *opaque)
357786
 static const BlockJobDriver backup_job_driver = {
357786
     .job_driver = {
357786
         .instance_size          = sizeof(BackupBlockJob),
357786
+        .job_type               = JOB_TYPE_BACKUP,
357786
     },
357786
-    .job_type               = JOB_TYPE_BACKUP,
357786
     .start                  = backup_run,
357786
     .commit                 = backup_commit,
357786
     .abort                  = backup_abort,
357786
diff --git a/block/commit.c b/block/commit.c
357786
index afa2b2b..32d29c8 100644
357786
--- a/block/commit.c
357786
+++ b/block/commit.c
357786
@@ -217,8 +217,8 @@ out:
357786
 static const BlockJobDriver commit_job_driver = {
357786
     .job_driver = {
357786
         .instance_size = sizeof(CommitBlockJob),
357786
+        .job_type      = JOB_TYPE_COMMIT,
357786
     },
357786
-    .job_type      = JOB_TYPE_COMMIT,
357786
     .start         = commit_run,
357786
 };
357786
 
357786
diff --git a/block/mirror.c b/block/mirror.c
357786
index ed72656..35fcc1f 100644
357786
--- a/block/mirror.c
357786
+++ b/block/mirror.c
357786
@@ -988,8 +988,8 @@ static void mirror_drain(BlockJob *job)
357786
 static const BlockJobDriver mirror_job_driver = {
357786
     .job_driver = {
357786
         .instance_size          = sizeof(MirrorBlockJob),
357786
+        .job_type               = JOB_TYPE_MIRROR,
357786
     },
357786
-    .job_type               = JOB_TYPE_MIRROR,
357786
     .start                  = mirror_run,
357786
     .complete               = mirror_complete,
357786
     .pause                  = mirror_pause,
357786
@@ -1000,8 +1000,8 @@ static const BlockJobDriver mirror_job_driver = {
357786
 static const BlockJobDriver commit_active_job_driver = {
357786
     .job_driver = {
357786
         .instance_size          = sizeof(MirrorBlockJob),
357786
+        .job_type               = JOB_TYPE_COMMIT,
357786
     },
357786
-    .job_type               = JOB_TYPE_COMMIT,
357786
     .start                  = mirror_run,
357786
     .complete               = mirror_complete,
357786
     .pause                  = mirror_pause,
357786
diff --git a/block/stream.c b/block/stream.c
357786
index 048bceb..cb723f1 100644
357786
--- a/block/stream.c
357786
+++ b/block/stream.c
357786
@@ -211,8 +211,8 @@ out:
357786
 static const BlockJobDriver stream_job_driver = {
357786
     .job_driver = {
357786
         .instance_size = sizeof(StreamBlockJob),
357786
+        .job_type      = JOB_TYPE_STREAM,
357786
     },
357786
-    .job_type      = JOB_TYPE_STREAM,
357786
     .start         = stream_run,
357786
 };
357786
 
357786
diff --git a/blockjob.c b/blockjob.c
357786
index 2a38447..ea71ec0 100644
357786
--- a/blockjob.c
357786
+++ b/blockjob.c
357786
@@ -309,9 +309,7 @@ static void block_job_detach_aio_context(void *opaque)
357786
 static char *child_job_get_parent_desc(BdrvChild *c)
357786
 {
357786
     BlockJob *job = c->opaque;
357786
-    return g_strdup_printf("%s job '%s'",
357786
-                           JobType_str(job->driver->job_type),
357786
-                           job->job.id);
357786
+    return g_strdup_printf("%s job '%s'", job_type_str(&job->job), job->job.id);
357786
 }
357786
 
357786
 static void child_job_drained_begin(BdrvChild *c)
357786
@@ -847,7 +845,7 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
357786
         return NULL;
357786
     }
357786
     info = g_new0(BlockJobInfo, 1);
357786
-    info->type      = g_strdup(JobType_str(job->driver->job_type));
357786
+    info->type      = g_strdup(job_type_str(&job->job));
357786
     info->device    = g_strdup(job->job.id);
357786
     info->len       = job->len;
357786
     info->busy      = atomic_read(&job->busy);
357786
@@ -878,7 +876,7 @@ static void block_job_event_cancelled(BlockJob *job)
357786
         return;
357786
     }
357786
 
357786
-    qapi_event_send_block_job_cancelled(job->driver->job_type,
357786
+    qapi_event_send_block_job_cancelled(job_type(&job->job),
357786
                                         job->job.id,
357786
                                         job->len,
357786
                                         job->offset,
357786
@@ -892,7 +890,7 @@ static void block_job_event_completed(BlockJob *job, const char *msg)
357786
         return;
357786
     }
357786
 
357786
-    qapi_event_send_block_job_completed(job->driver->job_type,
357786
+    qapi_event_send_block_job_completed(job_type(&job->job),
357786
                                         job->job.id,
357786
                                         job->len,
357786
                                         job->offset,
357786
@@ -906,7 +904,7 @@ static int block_job_event_pending(BlockJob *job)
357786
 {
357786
     block_job_state_transition(job, BLOCK_JOB_STATUS_PENDING);
357786
     if (!job->auto_finalize && !block_job_is_internal(job)) {
357786
-        qapi_event_send_block_job_pending(job->driver->job_type,
357786
+        qapi_event_send_block_job_pending(job_type(&job->job),
357786
                                           job->job.id,
357786
                                           &error_abort);
357786
     }
357786
@@ -980,7 +978,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
357786
                    block_job_sleep_timer_cb, job);
357786
 
357786
     error_setg(&job->blocker, "block device is in use by block job: %s",
357786
-               JobType_str(driver->job_type));
357786
+               job_type_str(&job->job));
357786
     block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort);
357786
     bs->job = job;
357786
 
357786
@@ -1184,7 +1182,7 @@ void block_job_event_ready(BlockJob *job)
357786
         return;
357786
     }
357786
 
357786
-    qapi_event_send_block_job_ready(job->driver->job_type,
357786
+    qapi_event_send_block_job_ready(job_type(&job->job),
357786
                                     job->job.id,
357786
                                     job->len,
357786
                                     job->offset,
357786
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
357786
index 8e7e0a2..1e62d6d 100644
357786
--- a/include/block/blockjob_int.h
357786
+++ b/include/block/blockjob_int.h
357786
@@ -38,9 +38,6 @@ struct BlockJobDriver {
357786
     /** Generic JobDriver callbacks and settings */
357786
     JobDriver job_driver;
357786
 
357786
-    /** String describing the operation, part of query-block-jobs QMP API */
357786
-    JobType job_type;
357786
-
357786
     /** Mandatory: Entrypoint for the Coroutine. */
357786
     CoroutineEntry *start;
357786
 
357786
diff --git a/include/qemu/job.h b/include/qemu/job.h
357786
index b4b49f1..279ce68 100644
357786
--- a/include/qemu/job.h
357786
+++ b/include/qemu/job.h
357786
@@ -26,6 +26,8 @@
357786
 #ifndef JOB_H
357786
 #define JOB_H
357786
 
357786
+#include "qapi/qapi-types-block-core.h"
357786
+
357786
 typedef struct JobDriver JobDriver;
357786
 
357786
 /**
357786
@@ -45,6 +47,9 @@ typedef struct Job {
357786
 struct JobDriver {
357786
     /** Derived Job struct size */
357786
     size_t instance_size;
357786
+
357786
+    /** Enum describing the operation */
357786
+    JobType job_type;
357786
 };
357786
 
357786
 
357786
@@ -57,4 +62,10 @@ struct JobDriver {
357786
  */
357786
 void *job_create(const char *job_id, const JobDriver *driver, Error **errp);
357786
 
357786
+/** Returns the JobType of a given Job. */
357786
+JobType job_type(const Job *job);
357786
+
357786
+/** Returns the enum string for the JobType of a given Job. */
357786
+const char *job_type_str(const Job *job);
357786
+
357786
 #endif
357786
diff --git a/job.c b/job.c
357786
index 87fd484..83724a4 100644
357786
--- a/job.c
357786
+++ b/job.c
357786
@@ -29,6 +29,16 @@
357786
 #include "qemu/job.h"
357786
 #include "qemu/id.h"
357786
 
357786
+JobType job_type(const Job *job)
357786
+{
357786
+    return job->driver->job_type;
357786
+}
357786
+
357786
+const char *job_type_str(const Job *job)
357786
+{
357786
+    return JobType_str(job_type(job));
357786
+}
357786
+
357786
 void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
357786
 {
357786
     Job *job;
357786
-- 
357786
1.8.3.1
357786