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