block: don't keep AioContext acquired after drive_backup_prepare()

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20171206144550.22295-4-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Stefan Hajnoczi 2017-12-06 14:45:44 +00:00
parent 2d24b60b77
commit 66d56054bc

View File

@ -1845,7 +1845,6 @@ static void external_snapshot_clean(BlkActionState *common)
typedef struct DriveBackupState { typedef struct DriveBackupState {
BlkActionState common; BlkActionState common;
BlockDriverState *bs; BlockDriverState *bs;
AioContext *aio_context;
BlockJob *job; BlockJob *job;
} DriveBackupState; } DriveBackupState;
@ -1857,6 +1856,7 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp)
DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
BlockDriverState *bs; BlockDriverState *bs;
DriveBackup *backup; DriveBackup *backup;
AioContext *aio_context;
Error *local_err = NULL; Error *local_err = NULL;
assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP);
@ -1867,24 +1867,36 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp)
return; return;
} }
/* AioContext is released in .clean() */ aio_context = bdrv_get_aio_context(bs);
state->aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context);
aio_context_acquire(state->aio_context);
/* Paired with .clean() */
bdrv_drained_begin(bs); bdrv_drained_begin(bs);
state->bs = bs; state->bs = bs;
state->job = do_drive_backup(backup, common->block_job_txn, &local_err); state->job = do_drive_backup(backup, common->block_job_txn, &local_err);
if (local_err) { if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
return; goto out;
} }
out:
aio_context_release(aio_context);
} }
static void drive_backup_commit(BlkActionState *common) static void drive_backup_commit(BlkActionState *common)
{ {
DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
AioContext *aio_context;
aio_context = bdrv_get_aio_context(state->bs);
aio_context_acquire(aio_context);
assert(state->job); assert(state->job);
block_job_start(state->job); block_job_start(state->job);
aio_context_release(aio_context);
} }
static void drive_backup_abort(BlkActionState *common) static void drive_backup_abort(BlkActionState *common)
@ -1892,18 +1904,32 @@ static void drive_backup_abort(BlkActionState *common)
DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
if (state->job) { if (state->job) {
AioContext *aio_context;
aio_context = bdrv_get_aio_context(state->bs);
aio_context_acquire(aio_context);
block_job_cancel_sync(state->job); block_job_cancel_sync(state->job);
aio_context_release(aio_context);
} }
} }
static void drive_backup_clean(BlkActionState *common) static void drive_backup_clean(BlkActionState *common)
{ {
DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
AioContext *aio_context;
if (state->aio_context) { if (!state->bs) {
bdrv_drained_end(state->bs); return;
aio_context_release(state->aio_context);
} }
aio_context = bdrv_get_aio_context(state->bs);
aio_context_acquire(aio_context);
bdrv_drained_end(state->bs);
aio_context_release(aio_context);
} }
typedef struct BlockdevBackupState { typedef struct BlockdevBackupState {