Skip to content

Commit

Permalink
block: Fix locking in external_snapshot_prepare()
Browse files Browse the repository at this point in the history
bdrv_img_create() polls internally (when calling bdrv_create(), which is
a co_wrapper), so it can't be called while holding the lock of any
AioContext except the current one without causing deadlocks. Drop the
lock around the call in external_snapshot_prepare().

Signed-off-by: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Emanuele Giuseppe Esposito <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
kevmw committed Dec 15, 2022
1 parent 617f3a9 commit e135505
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -6924,6 +6924,10 @@ bool bdrv_op_blocker_is_empty(BlockDriverState *bs)
return true;
}

/*
* Must not be called while holding the lock of an AioContext other than the
* current one.
*/
void bdrv_img_create(const char *filename, const char *fmt,
const char *base_filename, const char *base_fmt,
char *options, uint64_t img_size, int flags, bool quiet,
Expand Down
4 changes: 4 additions & 0 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,10 +1507,14 @@ static void external_snapshot_prepare(BlkActionState *common,
goto out;
}
bdrv_refresh_filename(state->old_bs);

aio_context_release(aio_context);
bdrv_img_create(new_image_file, format,
state->old_bs->filename,
state->old_bs->drv->format_name,
NULL, size, flags, false, &local_err);
aio_context_acquire(aio_context);

if (local_err) {
error_propagate(errp, local_err);
goto out;
Expand Down

0 comments on commit e135505

Please sign in to comment.