Signed-off-by: Wen Congyang <we...@cn.fujitsu.com> Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> Signed-off-by: Gonglei <arei.gong...@huawei.com> Reviewed-by: Jeff Cody <jc...@redhat.com> --- block/backup.c | 14 ++++++++++++++ blockjob.c | 11 +++++++++++ include/block/blockjob.h | 12 ++++++++++++ 3 files changed, 37 insertions(+)
diff --git a/block/backup.c b/block/backup.c index 3b39119..1ca102d 100644 --- a/block/backup.c +++ b/block/backup.c @@ -253,11 +253,25 @@ static void backup_abort(BlockJob *job) } } +static void backup_do_checkpoint(BlockJob *job, Error **errp) +{ + BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common); + + if (backup_job->sync_mode != MIRROR_SYNC_MODE_NONE) { + error_setg(errp, "The backup job only supports block checkpoint in" + " sync=none mode"); + return; + } + + hbitmap_reset_all(backup_job->bitmap); +} + static const BlockJobDriver backup_job_driver = { .instance_size = sizeof(BackupBlockJob), .job_type = BLOCK_JOB_TYPE_BACKUP, .set_speed = backup_set_speed, .iostatus_reset = backup_iostatus_reset, + .do_checkpoint = backup_do_checkpoint, .commit = backup_commit, .abort = backup_abort, }; diff --git a/blockjob.c b/blockjob.c index 80adb9d..0c8edfe 100644 --- a/blockjob.c +++ b/blockjob.c @@ -533,3 +533,14 @@ void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job) QLIST_INSERT_HEAD(&txn->jobs, job, txn_list); block_job_txn_ref(txn); } + +void block_job_do_checkpoint(BlockJob *job, Error **errp) +{ + if (!job->driver->do_checkpoint) { + error_setg(errp, "The job %s doesn't support block checkpoint", + BlockJobType_lookup[job->driver->job_type]); + return; + } + + job->driver->do_checkpoint(job, errp); +} diff --git a/include/block/blockjob.h b/include/block/blockjob.h index d84ccd8..abdba7c 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -70,6 +70,9 @@ typedef struct BlockJobDriver { * never both. */ void (*abort)(BlockJob *job); + + /** Optional callback for job types that support checkpoint. */ + void (*do_checkpoint)(BlockJob *job, Error **errp); } BlockJobDriver; /** @@ -443,4 +446,13 @@ void block_job_txn_unref(BlockJobTxn *txn); */ void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job); +/** + * block_job_do_checkpoint: + * @job: The job. + * @errp: Error object. + * + * Do block checkpoint on the specified job. + */ +void block_job_do_checkpoint(BlockJob *job, Error **errp); + #endif -- 2.5.0