mirror of https://github.com/xqemu/xqemu.git
block: don't keep AioContext acquired after internal_snapshot_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-6-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
edd5adeecd
commit
a36e458cdd
47
blockdev.c
47
blockdev.c
|
@ -1454,7 +1454,6 @@ struct BlkActionState {
|
||||||
typedef struct InternalSnapshotState {
|
typedef struct InternalSnapshotState {
|
||||||
BlkActionState common;
|
BlkActionState common;
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
AioContext *aio_context;
|
|
||||||
QEMUSnapshotInfo sn;
|
QEMUSnapshotInfo sn;
|
||||||
bool created;
|
bool created;
|
||||||
} InternalSnapshotState;
|
} InternalSnapshotState;
|
||||||
|
@ -1485,6 +1484,7 @@ static void internal_snapshot_prepare(BlkActionState *common,
|
||||||
qemu_timeval tv;
|
qemu_timeval tv;
|
||||||
BlockdevSnapshotInternal *internal;
|
BlockdevSnapshotInternal *internal;
|
||||||
InternalSnapshotState *state;
|
InternalSnapshotState *state;
|
||||||
|
AioContext *aio_context;
|
||||||
int ret1;
|
int ret1;
|
||||||
|
|
||||||
g_assert(common->action->type ==
|
g_assert(common->action->type ==
|
||||||
|
@ -1506,32 +1506,33 @@ static void internal_snapshot_prepare(BlkActionState *common,
|
||||||
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);
|
|
||||||
|
|
||||||
state->bs = bs;
|
state->bs = bs;
|
||||||
|
|
||||||
|
/* Paired with .clean() */
|
||||||
bdrv_drained_begin(bs);
|
bdrv_drained_begin(bs);
|
||||||
|
|
||||||
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT, errp)) {
|
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT, errp)) {
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bdrv_is_read_only(bs)) {
|
if (bdrv_is_read_only(bs)) {
|
||||||
error_setg(errp, "Device '%s' is read only", device);
|
error_setg(errp, "Device '%s' is read only", device);
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bdrv_can_snapshot(bs)) {
|
if (!bdrv_can_snapshot(bs)) {
|
||||||
error_setg(errp, "Block format '%s' used by device '%s' "
|
error_setg(errp, "Block format '%s' used by device '%s' "
|
||||||
"does not support internal snapshots",
|
"does not support internal snapshots",
|
||||||
bs->drv->format_name, device);
|
bs->drv->format_name, device);
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strlen(name)) {
|
if (!strlen(name)) {
|
||||||
error_setg(errp, "Name is empty");
|
error_setg(errp, "Name is empty");
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check whether a snapshot with name exist */
|
/* check whether a snapshot with name exist */
|
||||||
|
@ -1539,12 +1540,12 @@ static void internal_snapshot_prepare(BlkActionState *common,
|
||||||
&local_err);
|
&local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
goto out;
|
||||||
} else if (ret) {
|
} else if (ret) {
|
||||||
error_setg(errp,
|
error_setg(errp,
|
||||||
"Snapshot with name '%s' already exists on device '%s'",
|
"Snapshot with name '%s' already exists on device '%s'",
|
||||||
name, device);
|
name, device);
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 3. take the snapshot */
|
/* 3. take the snapshot */
|
||||||
|
@ -1560,11 +1561,14 @@ static void internal_snapshot_prepare(BlkActionState *common,
|
||||||
error_setg_errno(errp, -ret1,
|
error_setg_errno(errp, -ret1,
|
||||||
"Failed to create snapshot '%s' on device '%s'",
|
"Failed to create snapshot '%s' on device '%s'",
|
||||||
name, device);
|
name, device);
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 4. succeed, mark a snapshot is created */
|
/* 4. succeed, mark a snapshot is created */
|
||||||
state->created = true;
|
state->created = true;
|
||||||
|
|
||||||
|
out:
|
||||||
|
aio_context_release(aio_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void internal_snapshot_abort(BlkActionState *common)
|
static void internal_snapshot_abort(BlkActionState *common)
|
||||||
|
@ -1573,12 +1577,16 @@ static void internal_snapshot_abort(BlkActionState *common)
|
||||||
DO_UPCAST(InternalSnapshotState, common, common);
|
DO_UPCAST(InternalSnapshotState, common, common);
|
||||||
BlockDriverState *bs = state->bs;
|
BlockDriverState *bs = state->bs;
|
||||||
QEMUSnapshotInfo *sn = &state->sn;
|
QEMUSnapshotInfo *sn = &state->sn;
|
||||||
|
AioContext *aio_context;
|
||||||
Error *local_error = NULL;
|
Error *local_error = NULL;
|
||||||
|
|
||||||
if (!state->created) {
|
if (!state->created) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aio_context = bdrv_get_aio_context(state->bs);
|
||||||
|
aio_context_acquire(aio_context);
|
||||||
|
|
||||||
if (bdrv_snapshot_delete(bs, sn->id_str, sn->name, &local_error) < 0) {
|
if (bdrv_snapshot_delete(bs, sn->id_str, sn->name, &local_error) < 0) {
|
||||||
error_reportf_err(local_error,
|
error_reportf_err(local_error,
|
||||||
"Failed to delete snapshot with id '%s' and "
|
"Failed to delete snapshot with id '%s' and "
|
||||||
|
@ -1586,19 +1594,26 @@ static void internal_snapshot_abort(BlkActionState *common)
|
||||||
sn->id_str, sn->name,
|
sn->id_str, sn->name,
|
||||||
bdrv_get_device_name(bs));
|
bdrv_get_device_name(bs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aio_context_release(aio_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void internal_snapshot_clean(BlkActionState *common)
|
static void internal_snapshot_clean(BlkActionState *common)
|
||||||
{
|
{
|
||||||
InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState,
|
InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState,
|
||||||
common, common);
|
common, common);
|
||||||
|
AioContext *aio_context;
|
||||||
|
|
||||||
if (state->aio_context) {
|
if (!state->bs) {
|
||||||
if (state->bs) {
|
return;
|
||||||
bdrv_drained_end(state->bs);
|
|
||||||
}
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* external snapshot private data */
|
/* external snapshot private data */
|
||||||
|
|
Loading…
Reference in New Issue