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

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