Replication/Blockjobs: Create replication jobs as internal

Bubble up the internal interface to commit and backup jobs, then switch
replication tasks over to using this methodology.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Message-id: 1477584421-1399-4-git-send-email-jsnow@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
master
John Snow 2016-10-27 12:06:57 -04:00 committed by Jeff Cody
parent f81e0b4532
commit 47970dfb0a
6 changed files with 36 additions and 27 deletions

View File

@ -543,6 +543,7 @@ void backup_start(const char *job_id, BlockDriverState *bs,
bool compress, bool compress,
BlockdevOnError on_source_error, BlockdevOnError on_source_error,
BlockdevOnError on_target_error, BlockdevOnError on_target_error,
int creation_flags,
BlockCompletionFunc *cb, void *opaque, BlockCompletionFunc *cb, void *opaque,
BlockJobTxn *txn, Error **errp) BlockJobTxn *txn, Error **errp)
{ {
@ -612,7 +613,7 @@ void backup_start(const char *job_id, BlockDriverState *bs,
} }
job = block_job_create(job_id, &backup_job_driver, bs, speed, job = block_job_create(job_id, &backup_job_driver, bs, speed,
BLOCK_JOB_DEFAULT, cb, opaque, errp); creation_flags, cb, opaque, errp);
if (!job) { if (!job) {
goto error; goto error;
} }

View File

@ -937,9 +937,9 @@ static const BlockJobDriver commit_active_job_driver = {
}; };
static void mirror_start_job(const char *job_id, BlockDriverState *bs, static void mirror_start_job(const char *job_id, BlockDriverState *bs,
BlockDriverState *target, const char *replaces, int creation_flags, BlockDriverState *target,
int64_t speed, uint32_t granularity, const char *replaces, int64_t speed,
int64_t buf_size, uint32_t granularity, int64_t buf_size,
BlockMirrorBackingMode backing_mode, BlockMirrorBackingMode backing_mode,
BlockdevOnError on_source_error, BlockdevOnError on_source_error,
BlockdevOnError on_target_error, BlockdevOnError on_target_error,
@ -967,8 +967,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
buf_size = DEFAULT_MIRROR_BUF_SIZE; buf_size = DEFAULT_MIRROR_BUF_SIZE;
} }
s = block_job_create(job_id, driver, bs, speed, s = block_job_create(job_id, driver, bs, speed, creation_flags,
BLOCK_JOB_DEFAULT, cb, opaque, errp); cb, opaque, errp);
if (!s) { if (!s) {
return; return;
} }
@ -1031,17 +1031,16 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
} }
is_none_mode = mode == MIRROR_SYNC_MODE_NONE; is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
base = mode == MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL; base = mode == MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL;
mirror_start_job(job_id, bs, target, replaces, mirror_start_job(job_id, bs, BLOCK_JOB_DEFAULT, target, replaces,
speed, granularity, buf_size, backing_mode, speed, granularity, buf_size, backing_mode,
on_source_error, on_target_error, unmap, cb, opaque, errp, on_source_error, on_target_error, unmap, cb, opaque, errp,
&mirror_job_driver, is_none_mode, base, false); &mirror_job_driver, is_none_mode, base, false);
} }
void commit_active_start(const char *job_id, BlockDriverState *bs, void commit_active_start(const char *job_id, BlockDriverState *bs,
BlockDriverState *base, int64_t speed, BlockDriverState *base, int creation_flags,
BlockdevOnError on_error, int64_t speed, BlockdevOnError on_error,
BlockCompletionFunc *cb, BlockCompletionFunc *cb, void *opaque, Error **errp,
void *opaque, Error **errp,
bool auto_complete) bool auto_complete)
{ {
int64_t length, base_length; int64_t length, base_length;
@ -1080,7 +1079,7 @@ void commit_active_start(const char *job_id, BlockDriverState *bs,
} }
} }
mirror_start_job(job_id, bs, base, NULL, speed, 0, 0, mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0,
MIRROR_LEAVE_BACKING_CHAIN, MIRROR_LEAVE_BACKING_CHAIN,
on_error, on_error, true, cb, opaque, &local_err, on_error, on_error, true, cb, opaque, &local_err,
&commit_active_job_driver, false, base, auto_complete); &commit_active_job_driver, false, base, auto_complete);

View File

@ -508,10 +508,11 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,
bdrv_op_block_all(top_bs, s->blocker); bdrv_op_block_all(top_bs, s->blocker);
bdrv_op_unblock(top_bs, BLOCK_OP_TYPE_DATAPLANE, s->blocker); bdrv_op_unblock(top_bs, BLOCK_OP_TYPE_DATAPLANE, s->blocker);
backup_start("replication-backup", s->secondary_disk->bs, backup_start(NULL, s->secondary_disk->bs, s->hidden_disk->bs, 0,
s->hidden_disk->bs, 0, MIRROR_SYNC_MODE_NONE, NULL, false, MIRROR_SYNC_MODE_NONE, NULL, false,
BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
backup_job_completed, bs, NULL, &local_err); BLOCK_JOB_INTERNAL, backup_job_completed, bs,
NULL, &local_err);
if (local_err) { if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
backup_job_cleanup(bs); backup_job_cleanup(bs);
@ -633,10 +634,9 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)
} }
s->replication_state = BLOCK_REPLICATION_FAILOVER; s->replication_state = BLOCK_REPLICATION_FAILOVER;
commit_active_start("replication-commit", s->active_disk->bs, commit_active_start(NULL, s->active_disk->bs, s->secondary_disk->bs,
s->secondary_disk->bs, 0, BLOCKDEV_ON_ERROR_REPORT, BLOCK_JOB_INTERNAL, 0, BLOCKDEV_ON_ERROR_REPORT,
replication_done, replication_done, bs, errp, true);
bs, errp, true);
break; break;
default: default:
aio_context_release(aio_context); aio_context_release(aio_context);

View File

@ -3110,8 +3110,9 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
" but 'top' is the active layer"); " but 'top' is the active layer");
goto out; goto out;
} }
commit_active_start(has_job_id ? job_id : NULL, bs, base_bs, speed, commit_active_start(has_job_id ? job_id : NULL, bs, base_bs,
on_error, block_job_cb, bs, &local_err, false); BLOCK_JOB_DEFAULT, speed, on_error, block_job_cb,
bs, &local_err, false);
} else { } else {
BlockDriverState *overlay_bs = bdrv_find_overlay(bs, top_bs); BlockDriverState *overlay_bs = bdrv_find_overlay(bs, top_bs);
if (bdrv_op_is_blocked(overlay_bs, BLOCK_OP_TYPE_COMMIT_TARGET, errp)) { if (bdrv_op_is_blocked(overlay_bs, BLOCK_OP_TYPE_COMMIT_TARGET, errp)) {
@ -3239,7 +3240,8 @@ static void do_drive_backup(DriveBackup *backup, BlockJobTxn *txn, Error **errp)
backup_start(backup->job_id, bs, target_bs, backup->speed, backup->sync, backup_start(backup->job_id, bs, target_bs, backup->speed, backup->sync,
bmap, backup->compress, backup->on_source_error, bmap, backup->compress, backup->on_source_error,
backup->on_target_error, block_job_cb, bs, txn, &local_err); backup->on_target_error, BLOCK_JOB_DEFAULT,
block_job_cb, bs, txn, &local_err);
bdrv_unref(target_bs); bdrv_unref(target_bs);
if (local_err != NULL) { if (local_err != NULL) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
@ -3309,7 +3311,8 @@ void do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, Error **errp)
} }
backup_start(backup->job_id, bs, target_bs, backup->speed, backup->sync, backup_start(backup->job_id, bs, target_bs, backup->speed, backup->sync,
NULL, backup->compress, backup->on_source_error, NULL, backup->compress, backup->on_source_error,
backup->on_target_error, block_job_cb, bs, txn, &local_err); backup->on_target_error, BLOCK_JOB_DEFAULT,
block_job_cb, bs, txn, &local_err);
if (local_err != NULL) { if (local_err != NULL) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
} }

View File

@ -706,6 +706,8 @@ void commit_start(const char *job_id, BlockDriverState *bs,
* device name of @bs. * device name of @bs.
* @bs: Active block device to be committed. * @bs: Active block device to be committed.
* @base: Block device that will be written into, and become the new top. * @base: Block device that will be written into, and become the new top.
* @creation_flags: Flags that control the behavior of the Job lifetime.
* See @BlockJobCreateFlags
* @speed: The maximum speed, in bytes per second, or 0 for unlimited. * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
* @on_error: The action to take upon error. * @on_error: The action to take upon error.
* @cb: Completion function for the job. * @cb: Completion function for the job.
@ -715,8 +717,8 @@ void commit_start(const char *job_id, BlockDriverState *bs,
* *
*/ */
void commit_active_start(const char *job_id, BlockDriverState *bs, void commit_active_start(const char *job_id, BlockDriverState *bs,
BlockDriverState *base, int64_t speed, BlockDriverState *base, int creation_flags,
BlockdevOnError on_error, int64_t speed, BlockdevOnError on_error,
BlockCompletionFunc *cb, BlockCompletionFunc *cb,
void *opaque, Error **errp, bool auto_complete); void *opaque, Error **errp, bool auto_complete);
/* /*
@ -765,6 +767,8 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
* @sync_bitmap: The dirty bitmap if sync_mode is MIRROR_SYNC_MODE_INCREMENTAL. * @sync_bitmap: The dirty bitmap if sync_mode is MIRROR_SYNC_MODE_INCREMENTAL.
* @on_source_error: The action to take upon error reading from the source. * @on_source_error: The action to take upon error reading from the source.
* @on_target_error: The action to take upon error writing to the target. * @on_target_error: The action to take upon error writing to the target.
* @creation_flags: Flags that control the behavior of the Job lifetime.
* See @BlockJobCreateFlags
* @cb: Completion function for the job. * @cb: Completion function for the job.
* @opaque: Opaque pointer value passed to @cb. * @opaque: Opaque pointer value passed to @cb.
* @txn: Transaction that this job is part of (may be NULL). * @txn: Transaction that this job is part of (may be NULL).
@ -778,6 +782,7 @@ void backup_start(const char *job_id, BlockDriverState *bs,
bool compress, bool compress,
BlockdevOnError on_source_error, BlockdevOnError on_source_error,
BlockdevOnError on_target_error, BlockdevOnError on_target_error,
int creation_flags,
BlockCompletionFunc *cb, void *opaque, BlockCompletionFunc *cb, void *opaque,
BlockJobTxn *txn, Error **errp); BlockJobTxn *txn, Error **errp);

View File

@ -933,8 +933,9 @@ static int img_commit(int argc, char **argv)
aio_context = bdrv_get_aio_context(bs); aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context); aio_context_acquire(aio_context);
commit_active_start("commit", bs, base_bs, 0, BLOCKDEV_ON_ERROR_REPORT, commit_active_start("commit", bs, base_bs, BLOCK_JOB_DEFAULT, 0,
common_block_job_cb, &cbi, &local_err, false); BLOCKDEV_ON_ERROR_REPORT, common_block_job_cb, &cbi,
&local_err, false);
aio_context_release(aio_context); aio_context_release(aio_context);
if (local_err) { if (local_err) {
goto done; goto done;