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