ae23c9
From b0753bf51b9b5dcd6645e3321aef01286a3584a9 Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Tue, 26 Jun 2018 09:47:56 +0200
ae23c9
Subject: [PATCH 088/268] blockjob: Add block_job_driver()
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20180626094856.6924-14-kwolf@redhat.com>
ae23c9
Patchwork-id: 81064
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 13/73] blockjob: Add block_job_driver()
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
The backup block job directly accesses the driver field in BlockJob. Add
ae23c9
a wrapper for getting it.
ae23c9
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Reviewed-by: Max Reitz <mreitz@redhat.com>
ae23c9
Reviewed-by: John Snow <jsnow@redhat.com>
ae23c9
(cherry picked from commit bd21935b50d100d8da8c05cd3c2009f0f3432cb4)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 block/backup.c           | 8 +++++---
ae23c9
 blockjob.c               | 5 +++++
ae23c9
 include/block/blockjob.h | 7 +++++++
ae23c9
 3 files changed, 17 insertions(+), 3 deletions(-)
ae23c9
ae23c9
diff --git a/block/backup.c b/block/backup.c
ae23c9
index cfdb6ec..e14d995 100644
ae23c9
--- a/block/backup.c
ae23c9
+++ b/block/backup.c
ae23c9
@@ -47,6 +47,8 @@ typedef struct BackupBlockJob {
ae23c9
     HBitmap *copy_bitmap;
ae23c9
 } BackupBlockJob;
ae23c9
 
ae23c9
+static const BlockJobDriver backup_job_driver;
ae23c9
+
ae23c9
 /* See if in-flight requests overlap and wait for them to complete */
ae23c9
 static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job,
ae23c9
                                                        int64_t start,
ae23c9
@@ -241,7 +243,7 @@ void backup_do_checkpoint(BlockJob *job, Error **errp)
ae23c9
     BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
ae23c9
     int64_t len;
ae23c9
 
ae23c9
-    assert(job->driver->job_type == BLOCK_JOB_TYPE_BACKUP);
ae23c9
+    assert(block_job_driver(job) == &backup_job_driver);
ae23c9
 
ae23c9
     if (backup_job->sync_mode != MIRROR_SYNC_MODE_NONE) {
ae23c9
         error_setg(errp, "The backup job only supports block checkpoint in"
ae23c9
@@ -259,7 +261,7 @@ void backup_wait_for_overlapping_requests(BlockJob *job, int64_t offset,
ae23c9
     BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
ae23c9
     int64_t start, end;
ae23c9
 
ae23c9
-    assert(job->driver->job_type == BLOCK_JOB_TYPE_BACKUP);
ae23c9
+    assert(block_job_driver(job) == &backup_job_driver);
ae23c9
 
ae23c9
     start = QEMU_ALIGN_DOWN(offset, backup_job->cluster_size);
ae23c9
     end = QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size);
ae23c9
@@ -272,7 +274,7 @@ void backup_cow_request_begin(CowRequest *req, BlockJob *job,
ae23c9
     BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
ae23c9
     int64_t start, end;
ae23c9
 
ae23c9
-    assert(job->driver->job_type == BLOCK_JOB_TYPE_BACKUP);
ae23c9
+    assert(block_job_driver(job) == &backup_job_driver);
ae23c9
 
ae23c9
     start = QEMU_ALIGN_DOWN(offset, backup_job->cluster_size);
ae23c9
     end = QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size);
ae23c9
diff --git a/blockjob.c b/blockjob.c
ae23c9
index e30f5ec..112672a 100644
ae23c9
--- a/blockjob.c
ae23c9
+++ b/blockjob.c
ae23c9
@@ -373,6 +373,11 @@ static bool block_job_started(BlockJob *job)
ae23c9
     return job->co;
ae23c9
 }
ae23c9
 
ae23c9
+const BlockJobDriver *block_job_driver(BlockJob *job)
ae23c9
+{
ae23c9
+    return job->driver;
ae23c9
+}
ae23c9
+
ae23c9
 /**
ae23c9
  * All jobs must allow a pause point before entering their job proper. This
ae23c9
  * ensures that jobs can be paused prior to being started, then resumed later.
ae23c9
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
ae23c9
index 82f52f4..0f56f72 100644
ae23c9
--- a/include/block/blockjob.h
ae23c9
+++ b/include/block/blockjob.h
ae23c9
@@ -452,4 +452,11 @@ void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job);
ae23c9
  */
ae23c9
 bool block_job_is_internal(BlockJob *job);
ae23c9
 
ae23c9
+/**
ae23c9
+ * block_job_driver:
ae23c9
+ *
ae23c9
+ * Returns the driver associated with a block job.
ae23c9
+ */
ae23c9
+const BlockJobDriver *block_job_driver(BlockJob *job);
ae23c9
+
ae23c9
 #endif
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9