Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
block: bdrv/blk_co_unref() for calls in coroutine context
These functions must not be called in coroutine context, because they
need write access to the graph.

Cc: qemu-stable@nongnu.org
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20230504115750.54437-4-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit b2ab5f5)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(mjt: remove [no_]coroutine_fn markers which don't exist in 7.2)
  • Loading branch information
Kevin Wolf authored and Michael Tokarev committed May 11, 2023
1 parent da9db11 commit a1a63c4
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion block.c
Expand Up @@ -721,7 +721,7 @@ int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv,

ret = 0;
out:
blk_unref(blk);
blk_co_unref(blk);
return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions block/crypto.c
Expand Up @@ -356,7 +356,7 @@ static int block_crypto_co_create_generic(BlockDriverState *bs,
ret = 0;
cleanup:
qcrypto_block_free(crypto);
blk_unref(blk);
blk_co_unref(blk);
return ret;
}

Expand Down Expand Up @@ -661,7 +661,7 @@ block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp)

ret = 0;
fail:
bdrv_unref(bs);
bdrv_co_unref(bs);
return ret;
}

Expand Down Expand Up @@ -731,7 +731,7 @@ static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv,
bdrv_co_delete_file_noerr(bs);
}

bdrv_unref(bs);
bdrv_co_unref(bs);
qapi_free_QCryptoBlockCreateOptions(create_opts);
qobject_unref(cryptoopts);
return ret;
Expand Down
6 changes: 3 additions & 3 deletions block/parallels.c
Expand Up @@ -611,8 +611,8 @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts,

ret = 0;
out:
blk_unref(blk);
bdrv_unref(bs);
blk_co_unref(blk);
bdrv_co_unref(bs);
return ret;

exit:
Expand Down Expand Up @@ -690,7 +690,7 @@ static int coroutine_fn parallels_co_create_opts(BlockDriver *drv,

done:
qobject_unref(qdict);
bdrv_unref(bs);
bdrv_co_unref(bs);
qapi_free_BlockdevCreateOptions(create_options);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions block/qcow.c
Expand Up @@ -917,8 +917,8 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
g_free(tmp);
ret = 0;
exit:
blk_unref(qcow_blk);
bdrv_unref(bs);
blk_co_unref(qcow_blk);
bdrv_co_unref(bs);
qcrypto_block_free(crypto);
return ret;
}
Expand Down Expand Up @@ -1017,7 +1017,7 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
fail:
g_free(backing_fmt);
qobject_unref(qdict);
bdrv_unref(bs);
bdrv_co_unref(bs);
qapi_free_BlockdevCreateOptions(create_options);
return ret;
}
Expand Down
14 changes: 7 additions & 7 deletions block/qcow2.c
Expand Up @@ -3697,7 +3697,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
goto out;
}

blk_unref(blk);
blk_co_unref(blk);
blk = NULL;

/*
Expand Down Expand Up @@ -3777,7 +3777,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
}

blk_unref(blk);
blk_co_unref(blk);
blk = NULL;

/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning.
Expand All @@ -3802,9 +3802,9 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)

ret = 0;
out:
blk_unref(blk);
bdrv_unref(bs);
bdrv_unref(data_bs);
blk_co_unref(blk);
bdrv_co_unref(bs);
bdrv_co_unref(data_bs);
return ret;
}

Expand Down Expand Up @@ -3936,8 +3936,8 @@ static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
}

qobject_unref(qdict);
bdrv_unref(bs);
bdrv_unref(data_bs);
bdrv_co_unref(bs);
bdrv_co_unref(data_bs);
qapi_free_BlockdevCreateOptions(create_options);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions block/qed.c
Expand Up @@ -731,8 +731,8 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts,
ret = 0; /* success */
out:
g_free(l1_table);
blk_unref(blk);
bdrv_unref(bs);
blk_co_unref(blk);
bdrv_co_unref(bs);
return ret;
}

Expand Down Expand Up @@ -803,7 +803,7 @@ static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv,

fail:
qobject_unref(qdict);
bdrv_unref(bs);
bdrv_co_unref(bs);
qapi_free_BlockdevCreateOptions(create_options);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions block/vdi.c
Expand Up @@ -885,8 +885,8 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,

ret = 0;
exit:
blk_unref(blk);
bdrv_unref(bs_file);
blk_co_unref(blk);
bdrv_co_unref(bs_file);
g_free(bmap);
return ret;
}
Expand Down Expand Up @@ -975,7 +975,7 @@ static int coroutine_fn vdi_co_create_opts(BlockDriver *drv,
done:
qobject_unref(qdict);
qapi_free_BlockdevCreateOptions(create_options);
bdrv_unref(bs_file);
bdrv_co_unref(bs_file);
return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions block/vhdx.c
Expand Up @@ -2051,8 +2051,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,

ret = 0;
delete_and_exit:
blk_unref(blk);
bdrv_unref(bs);
blk_co_unref(blk);
bdrv_co_unref(bs);
g_free(creator);
return ret;
}
Expand Down Expand Up @@ -2143,7 +2143,7 @@ static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv,

fail:
qobject_unref(qdict);
bdrv_unref(bs);
bdrv_co_unref(bs);
qapi_free_BlockdevCreateOptions(create_options);
return ret;
}
Expand Down
18 changes: 9 additions & 9 deletions block/vmdk.c
Expand Up @@ -2314,7 +2314,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
if (pbb) {
*pbb = blk;
} else {
blk_unref(blk);
blk_co_unref(blk);
blk = NULL;
}
}
Expand Down Expand Up @@ -2527,12 +2527,12 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
if (strcmp(blk_bs(backing)->drv->format_name, "vmdk")) {
error_setg(errp, "Invalid backing file format: %s. Must be vmdk",
blk_bs(backing)->drv->format_name);
blk_unref(backing);
blk_co_unref(backing);
ret = -EINVAL;
goto exit;
}
ret = vmdk_read_cid(blk_bs(backing), 0, &parent_cid);
blk_unref(backing);
blk_co_unref(backing);
if (ret) {
error_setg(errp, "Failed to read parent CID");
goto exit;
Expand All @@ -2553,14 +2553,14 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
blk_bs(extent_blk)->filename);
created_size += cur_size;
extent_idx++;
blk_unref(extent_blk);
blk_co_unref(extent_blk);
}

/* Check whether we got excess extents */
extent_blk = extent_fn(-1, extent_idx, flat, split, compress, zeroed_grain,
opaque, NULL);
if (extent_blk) {
blk_unref(extent_blk);
blk_co_unref(extent_blk);
error_setg(errp, "List of extents contains unused extents");
ret = -EINVAL;
goto exit;
Expand Down Expand Up @@ -2601,7 +2601,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
ret = 0;
exit:
if (blk) {
blk_unref(blk);
blk_co_unref(blk);
}
g_free(desc);
g_free(parent_desc_line);
Expand Down Expand Up @@ -2652,7 +2652,7 @@ static BlockBackend *vmdk_co_create_opts_cb(int64_t size, int idx,
errp)) {
goto exit;
}
bdrv_unref(bs);
bdrv_co_unref(bs);
exit:
g_free(ext_filename);
return blk;
Expand Down Expand Up @@ -2806,12 +2806,12 @@ static BlockBackend *vmdk_co_create_cb(int64_t size, int idx,
return NULL;
}
blk_set_allow_write_beyond_eof(blk, true);
bdrv_unref(bs);
bdrv_co_unref(bs);

if (size != -1) {
ret = vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp);
if (ret) {
blk_unref(blk);
blk_co_unref(blk);
blk = NULL;
}
}
Expand Down
6 changes: 3 additions & 3 deletions block/vpc.c
Expand Up @@ -1081,8 +1081,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts,
}

out:
blk_unref(blk);
bdrv_unref(bs);
blk_co_unref(blk);
bdrv_co_unref(bs);
return ret;
}

Expand Down Expand Up @@ -1162,7 +1162,7 @@ static int coroutine_fn vpc_co_create_opts(BlockDriver *drv,

fail:
qobject_unref(qdict);
bdrv_unref(bs);
bdrv_co_unref(bs);
qapi_free_BlockdevCreateOptions(create_options);
return ret;
}
Expand Down
1 change: 1 addition & 0 deletions include/block/block-global-state.h
Expand Up @@ -188,6 +188,7 @@ void bdrv_img_create(const char *filename, const char *fmt,

void bdrv_ref(BlockDriverState *bs);
void bdrv_unref(BlockDriverState *bs);
void bdrv_co_unref(BlockDriverState *bs);
void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);
BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
BlockDriverState *child_bs,
Expand Down
3 changes: 3 additions & 0 deletions include/sysemu/block-backend-global-state.h
Expand Up @@ -29,7 +29,10 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
QDict *options, int flags, Error **errp);
int blk_get_refcnt(BlockBackend *blk);
void blk_ref(BlockBackend *blk);

void blk_unref(BlockBackend *blk);
void blk_co_unref(BlockBackend *blk);

void blk_remove_all_bs(void);
BlockBackend *blk_by_name(const char *name);
BlockBackend *blk_next(BlockBackend *blk);
Expand Down

0 comments on commit a1a63c4

Please sign in to comment.