yeahuh / rpms / qemu-kvm

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