Skip to content

Commit

Permalink
qcow2: Unlock the graph in qcow2_do_open() where necessary
Browse files Browse the repository at this point in the history
qcow2_do_open() calls a few no_co_wrappers that wrap functions taking
the graph lock internally as a writer. Therefore, it can't hold the
reader lock across these calls, it causes deadlocks. Drop the lock
temporarily around the calls.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230510203601.418015-4-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
kevmw committed May 19, 2023
1 parent a184563 commit e3e31dc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions block/qcow2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,20 +1619,24 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,

if (open_data_file) {
/* Open external data file */
bdrv_graph_co_rdunlock();
s->data_file = bdrv_co_open_child(NULL, options, "data-file", bs,
&child_of_bds, BDRV_CHILD_DATA,
true, errp);
bdrv_graph_co_rdlock();
if (*errp) {
ret = -EINVAL;
goto fail;
}

if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) {
if (!s->data_file && s->image_data_file) {
bdrv_graph_co_rdunlock();
s->data_file = bdrv_co_open_child(s->image_data_file, options,
"data-file", bs,
&child_of_bds,
BDRV_CHILD_DATA, false, errp);
bdrv_graph_co_rdlock();
if (!s->data_file) {
ret = -EINVAL;
goto fail;
Expand Down Expand Up @@ -1857,7 +1861,9 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
fail:
g_free(s->image_data_file);
if (open_data_file && has_data_file(bs)) {
bdrv_graph_co_rdunlock();
bdrv_unref_child(bs, s->data_file);
bdrv_graph_co_rdlock();
s->data_file = NULL;
}
g_free(s->unknown_header_fields);
Expand Down

0 comments on commit e3e31dc

Please sign in to comment.