Blame SOURCES/kvm-blockjob-Add-block_job_driver.patch

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