mirror of
https://github.com/qemu/qemu.git
synced 2024-11-23 10:53:37 +08:00
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>
This commit is contained in:
parent
da4afaff07
commit
b2ab5f545f
2
block.c
2
block.c
@ -680,7 +680,7 @@ int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ block_crypto_co_create_generic(BlockDriverState *bs, int64_t size,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
qcrypto_block_free(crypto);
|
qcrypto_block_free(crypto);
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,7 +661,7 @@ block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp)
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
fail:
|
fail:
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +730,7 @@ fail:
|
|||||||
bdrv_co_delete_file_noerr(bs);
|
bdrv_co_delete_file_noerr(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
qapi_free_QCryptoBlockCreateOptions(create_opts);
|
qapi_free_QCryptoBlockCreateOptions(create_opts);
|
||||||
qobject_unref(cryptoopts);
|
qobject_unref(cryptoopts);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -613,8 +613,8 @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@ -691,7 +691,7 @@ parallels_co_create_opts(BlockDriver *drv, const char *filename,
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
qobject_unref(qdict);
|
qobject_unref(qdict);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
qapi_free_BlockdevCreateOptions(create_options);
|
qapi_free_BlockdevCreateOptions(create_options);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -915,8 +915,8 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
|
|||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
exit:
|
exit:
|
||||||
blk_unref(qcow_blk);
|
blk_co_unref(qcow_blk);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
qcrypto_block_free(crypto);
|
qcrypto_block_free(crypto);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1015,7 +1015,7 @@ qcow_co_create_opts(BlockDriver *drv, const char *filename,
|
|||||||
fail:
|
fail:
|
||||||
g_free(backing_fmt);
|
g_free(backing_fmt);
|
||||||
qobject_unref(qdict);
|
qobject_unref(qdict);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
qapi_free_BlockdevCreateOptions(create_options);
|
qapi_free_BlockdevCreateOptions(create_options);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -3705,7 +3705,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
blk = NULL;
|
blk = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3785,7 +3785,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
blk = NULL;
|
blk = NULL;
|
||||||
|
|
||||||
/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning.
|
/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning.
|
||||||
@ -3810,9 +3810,9 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
bdrv_unref(data_bs);
|
bdrv_co_unref(data_bs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3943,8 +3943,8 @@ finish:
|
|||||||
}
|
}
|
||||||
|
|
||||||
qobject_unref(qdict);
|
qobject_unref(qdict);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
bdrv_unref(data_bs);
|
bdrv_co_unref(data_bs);
|
||||||
qapi_free_BlockdevCreateOptions(create_options);
|
qapi_free_BlockdevCreateOptions(create_options);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -748,8 +748,8 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts,
|
|||||||
ret = 0; /* success */
|
ret = 0; /* success */
|
||||||
out:
|
out:
|
||||||
g_free(l1_table);
|
g_free(l1_table);
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,7 +819,7 @@ bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename,
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
qobject_unref(qdict);
|
qobject_unref(qdict);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
qapi_free_BlockdevCreateOptions(create_options);
|
qapi_free_BlockdevCreateOptions(create_options);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -886,8 +886,8 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
exit:
|
exit:
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
bdrv_unref(bs_file);
|
bdrv_co_unref(bs_file);
|
||||||
g_free(bmap);
|
g_free(bmap);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -975,7 +975,7 @@ vdi_co_create_opts(BlockDriver *drv, const char *filename,
|
|||||||
done:
|
done:
|
||||||
qobject_unref(qdict);
|
qobject_unref(qdict);
|
||||||
qapi_free_BlockdevCreateOptions(create_options);
|
qapi_free_BlockdevCreateOptions(create_options);
|
||||||
bdrv_unref(bs_file);
|
bdrv_co_unref(bs_file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2053,8 +2053,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
delete_and_exit:
|
delete_and_exit:
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
g_free(creator);
|
g_free(creator);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -2144,7 +2144,7 @@ vhdx_co_create_opts(BlockDriver *drv, const char *filename,
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
qobject_unref(qdict);
|
qobject_unref(qdict);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
qapi_free_BlockdevCreateOptions(create_options);
|
qapi_free_BlockdevCreateOptions(create_options);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
18
block/vmdk.c
18
block/vmdk.c
@ -2306,7 +2306,7 @@ exit:
|
|||||||
if (pbb) {
|
if (pbb) {
|
||||||
*pbb = blk;
|
*pbb = blk;
|
||||||
} else {
|
} else {
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
blk = NULL;
|
blk = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2516,12 +2516,12 @@ vmdk_co_do_create(int64_t size,
|
|||||||
if (strcmp(blk_bs(backing)->drv->format_name, "vmdk")) {
|
if (strcmp(blk_bs(backing)->drv->format_name, "vmdk")) {
|
||||||
error_setg(errp, "Invalid backing file format: %s. Must be vmdk",
|
error_setg(errp, "Invalid backing file format: %s. Must be vmdk",
|
||||||
blk_bs(backing)->drv->format_name);
|
blk_bs(backing)->drv->format_name);
|
||||||
blk_unref(backing);
|
blk_co_unref(backing);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
ret = vmdk_read_cid(blk_bs(backing), 0, &parent_cid);
|
ret = vmdk_read_cid(blk_bs(backing), 0, &parent_cid);
|
||||||
blk_unref(backing);
|
blk_co_unref(backing);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error_setg(errp, "Failed to read parent CID");
|
error_setg(errp, "Failed to read parent CID");
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -2542,14 +2542,14 @@ vmdk_co_do_create(int64_t size,
|
|||||||
blk_bs(extent_blk)->filename);
|
blk_bs(extent_blk)->filename);
|
||||||
created_size += cur_size;
|
created_size += cur_size;
|
||||||
extent_idx++;
|
extent_idx++;
|
||||||
blk_unref(extent_blk);
|
blk_co_unref(extent_blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether we got excess extents */
|
/* Check whether we got excess extents */
|
||||||
extent_blk = extent_fn(-1, extent_idx, flat, split, compress, zeroed_grain,
|
extent_blk = extent_fn(-1, extent_idx, flat, split, compress, zeroed_grain,
|
||||||
opaque, NULL);
|
opaque, NULL);
|
||||||
if (extent_blk) {
|
if (extent_blk) {
|
||||||
blk_unref(extent_blk);
|
blk_co_unref(extent_blk);
|
||||||
error_setg(errp, "List of extents contains unused extents");
|
error_setg(errp, "List of extents contains unused extents");
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -2590,7 +2590,7 @@ vmdk_co_do_create(int64_t size,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
exit:
|
exit:
|
||||||
if (blk) {
|
if (blk) {
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
}
|
}
|
||||||
g_free(desc);
|
g_free(desc);
|
||||||
g_free(parent_desc_line);
|
g_free(parent_desc_line);
|
||||||
@ -2641,7 +2641,7 @@ vmdk_co_create_opts_cb(int64_t size, int idx, bool flat, bool split,
|
|||||||
errp)) {
|
errp)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
exit:
|
exit:
|
||||||
g_free(ext_filename);
|
g_free(ext_filename);
|
||||||
return blk;
|
return blk;
|
||||||
@ -2797,12 +2797,12 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(int64_t size, int idx,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
blk_set_allow_write_beyond_eof(blk, true);
|
blk_set_allow_write_beyond_eof(blk, true);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
|
|
||||||
if (size != -1) {
|
if (size != -1) {
|
||||||
ret = vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp);
|
ret = vmdk_init_extent(blk, size, flat, compress, zeroed_grain, errp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
blk = NULL;
|
blk = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1082,8 +1082,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts,
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
blk_unref(blk);
|
blk_co_unref(blk);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1162,7 +1162,7 @@ vpc_co_create_opts(BlockDriver *drv, const char *filename,
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
qobject_unref(qdict);
|
qobject_unref(qdict);
|
||||||
bdrv_unref(bs);
|
bdrv_co_unref(bs);
|
||||||
qapi_free_BlockdevCreateOptions(create_options);
|
qapi_free_BlockdevCreateOptions(create_options);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
|||||||
bool quiet, Error **errp);
|
bool quiet, Error **errp);
|
||||||
|
|
||||||
void bdrv_ref(BlockDriverState *bs);
|
void bdrv_ref(BlockDriverState *bs);
|
||||||
void bdrv_unref(BlockDriverState *bs);
|
void no_coroutine_fn bdrv_unref(BlockDriverState *bs);
|
||||||
|
void coroutine_fn no_co_wrapper bdrv_co_unref(BlockDriverState *bs);
|
||||||
void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);
|
void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);
|
||||||
BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
|
BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
|
||||||
BlockDriverState *child_bs,
|
BlockDriverState *child_bs,
|
||||||
|
@ -42,7 +42,10 @@ blk_co_new_open(const char *filename, const char *reference, QDict *options,
|
|||||||
|
|
||||||
int blk_get_refcnt(BlockBackend *blk);
|
int blk_get_refcnt(BlockBackend *blk);
|
||||||
void blk_ref(BlockBackend *blk);
|
void blk_ref(BlockBackend *blk);
|
||||||
void blk_unref(BlockBackend *blk);
|
|
||||||
|
void no_coroutine_fn blk_unref(BlockBackend *blk);
|
||||||
|
void coroutine_fn no_co_wrapper blk_co_unref(BlockBackend *blk);
|
||||||
|
|
||||||
void blk_remove_all_bs(void);
|
void blk_remove_all_bs(void);
|
||||||
BlockBackend *blk_by_name(const char *name);
|
BlockBackend *blk_by_name(const char *name);
|
||||||
BlockBackend *blk_next(BlockBackend *blk);
|
BlockBackend *blk_next(BlockBackend *blk);
|
||||||
|
Loading…
Reference in New Issue
Block a user