block: Mark bdrv_co_create() and callers GRAPH_RDLOCK
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_create() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20230203152202.49054-17-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
7b9e8b22bc
commit
4ec8df0183
1
block.c
1
block.c
@ -533,6 +533,7 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
|
||||
int ret;
|
||||
GLOBAL_STATE_CODE();
|
||||
ERRP_GUARD();
|
||||
assert_bdrv_graph_readable();
|
||||
|
||||
if (!drv->bdrv_co_create_opts) {
|
||||
error_setg(errp, "Driver '%s' does not support image creation",
|
||||
|
@ -43,6 +43,7 @@ static int coroutine_fn blockdev_create_run(Job *job, Error **errp)
|
||||
int ret;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
GRAPH_RDLOCK_GUARD();
|
||||
|
||||
job_progress_set_remaining(&s->common, 1);
|
||||
ret = s->drv->bdrv_co_create(s->opts, errp);
|
||||
@ -59,6 +60,12 @@ static const JobDriver blockdev_create_job_driver = {
|
||||
.run = blockdev_create_run,
|
||||
};
|
||||
|
||||
/* Checking whether the function is present doesn't require the graph lock */
|
||||
static inline bool TSA_NO_TSA has_bdrv_co_create(BlockDriver *drv)
|
||||
{
|
||||
return drv->bdrv_co_create;
|
||||
}
|
||||
|
||||
void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
|
||||
Error **errp)
|
||||
{
|
||||
@ -79,7 +86,7 @@ void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
|
||||
}
|
||||
|
||||
/* Error out if the driver doesn't support .bdrv_co_create */
|
||||
if (!drv->bdrv_co_create) {
|
||||
if (!has_bdrv_co_create(drv)) {
|
||||
error_setg(errp, "Driver does not support blockdev-create");
|
||||
return;
|
||||
}
|
||||
|
@ -664,10 +664,9 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
QCryptoBlockCreateOptions *create_opts = NULL;
|
||||
BlockDriverState *bs = NULL;
|
||||
|
@ -2607,10 +2607,9 @@ out:
|
||||
return result;
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
raw_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions options;
|
||||
int64_t total_size = 0;
|
||||
|
@ -613,10 +613,9 @@ static int raw_co_create(BlockdevCreateOptions *options, Error **errp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
raw_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions options;
|
||||
int64_t total_size = 0;
|
||||
|
@ -622,10 +622,9 @@ exit:
|
||||
goto out;
|
||||
}
|
||||
|
||||
static int coroutine_fn parallels_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
parallels_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions *create_options = NULL;
|
||||
BlockDriverState *bs = NULL;
|
||||
|
@ -921,9 +921,9 @@ exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
qcow_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions *create_options = NULL;
|
||||
BlockDriverState *bs = NULL;
|
||||
|
@ -3816,10 +3816,9 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts,
|
||||
Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions *create_options = NULL;
|
||||
QDict *qdict;
|
||||
|
@ -754,10 +754,9 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions *create_options = NULL;
|
||||
QDict *qdict;
|
||||
|
@ -430,10 +430,9 @@ static int raw_has_zero_init(BlockDriverState *bs)
|
||||
return bdrv_has_zero_init(bs->file->bs);
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
raw_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
return bdrv_co_create_file(filename, opts, errp);
|
||||
}
|
||||
|
@ -898,10 +898,9 @@ static int coroutine_fn vdi_co_create(BlockdevCreateOptions *create_options,
|
||||
return vdi_co_do_create(create_options, DEFAULT_CLUSTER_SIZE, errp);
|
||||
}
|
||||
|
||||
static int coroutine_fn vdi_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
vdi_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
QDict *qdict = NULL;
|
||||
BlockdevCreateOptions *create_options = NULL;
|
||||
|
@ -2059,10 +2059,9 @@ delete_and_exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
vhdx_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions *create_options = NULL;
|
||||
QDict *qdict;
|
||||
|
63
block/vmdk.c
63
block/vmdk.c
@ -2277,11 +2277,10 @@ exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn vmdk_create_extent(const char *filename,
|
||||
int64_t filesize, bool flat,
|
||||
bool compress, bool zeroed_grain,
|
||||
BlockBackend **pbb,
|
||||
QemuOpts *opts, Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
vmdk_create_extent(const char *filename, int64_t filesize, bool flat,
|
||||
bool compress, bool zeroed_grain, BlockBackend **pbb,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
BlockBackend *blk = NULL;
|
||||
@ -2359,14 +2358,10 @@ static int filename_decompose(const char *filename, char *path, char *prefix,
|
||||
* non-split format.
|
||||
* idx >= 1: get the n-th extent if in a split subformat
|
||||
*/
|
||||
typedef BlockBackend * coroutine_fn (*vmdk_create_extent_fn)(int64_t size,
|
||||
int idx,
|
||||
bool flat,
|
||||
bool split,
|
||||
bool compress,
|
||||
bool zeroed_grain,
|
||||
void *opaque,
|
||||
Error **errp);
|
||||
typedef BlockBackend * coroutine_fn /* GRAPH_RDLOCK */
|
||||
(*vmdk_create_extent_fn)(int64_t size, int idx, bool flat, bool split,
|
||||
bool compress, bool zeroed_grain, void *opaque,
|
||||
Error **errp);
|
||||
|
||||
static void vmdk_desc_add_extent(GString *desc,
|
||||
const char *extent_line_fmt,
|
||||
@ -2379,17 +2374,18 @@ static void vmdk_desc_add_extent(GString *desc,
|
||||
g_free(basename);
|
||||
}
|
||||
|
||||
static int coroutine_fn vmdk_co_do_create(int64_t size,
|
||||
BlockdevVmdkSubformat subformat,
|
||||
BlockdevVmdkAdapterType adapter_type,
|
||||
const char *backing_file,
|
||||
const char *hw_version,
|
||||
const char *toolsversion,
|
||||
bool compat6,
|
||||
bool zeroed_grain,
|
||||
vmdk_create_extent_fn extent_fn,
|
||||
void *opaque,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
vmdk_co_do_create(int64_t size,
|
||||
BlockdevVmdkSubformat subformat,
|
||||
BlockdevVmdkAdapterType adapter_type,
|
||||
const char *backing_file,
|
||||
const char *hw_version,
|
||||
const char *toolsversion,
|
||||
bool compat6,
|
||||
bool zeroed_grain,
|
||||
vmdk_create_extent_fn extent_fn,
|
||||
void *opaque,
|
||||
Error **errp)
|
||||
{
|
||||
int extent_idx;
|
||||
BlockBackend *blk = NULL;
|
||||
@ -2609,10 +2605,10 @@ typedef struct {
|
||||
QemuOpts *opts;
|
||||
} VMDKCreateOptsData;
|
||||
|
||||
static BlockBackend * coroutine_fn vmdk_co_create_opts_cb(int64_t size, int idx,
|
||||
bool flat, bool split, bool compress,
|
||||
bool zeroed_grain, void *opaque,
|
||||
Error **errp)
|
||||
static BlockBackend * coroutine_fn GRAPH_RDLOCK
|
||||
vmdk_co_create_opts_cb(int64_t size, int idx, bool flat, bool split,
|
||||
bool compress, bool zeroed_grain, void *opaque,
|
||||
Error **errp)
|
||||
{
|
||||
BlockBackend *blk = NULL;
|
||||
BlockDriverState *bs = NULL;
|
||||
@ -2651,10 +2647,9 @@ exit:
|
||||
return blk;
|
||||
}
|
||||
|
||||
static int coroutine_fn vmdk_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
vmdk_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
char *desc = NULL;
|
||||
@ -2814,8 +2809,8 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(int64_t size, int idx,
|
||||
return blk;
|
||||
}
|
||||
|
||||
static int coroutine_fn vmdk_co_create(BlockdevCreateOptions *create_options,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
vmdk_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptionsVmdk *opts;
|
||||
|
||||
|
@ -1087,10 +1087,9 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn vpc_co_create_opts(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp)
|
||||
static int coroutine_fn GRAPH_RDLOCK
|
||||
vpc_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
BlockdevCreateOptions *create_options = NULL;
|
||||
QDict *qdict;
|
||||
|
@ -58,13 +58,15 @@ BlockDriver *bdrv_find_protocol(const char *filename,
|
||||
Error **errp);
|
||||
BlockDriver *bdrv_find_format(const char *format_name);
|
||||
|
||||
int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp);
|
||||
int co_wrapper bdrv_create(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp);
|
||||
int coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_co_create(BlockDriver *drv, const char *filename, QemuOpts *opts,
|
||||
Error **errp);
|
||||
|
||||
int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts,
|
||||
Error **errp);
|
||||
int co_wrapper_bdrv_rdlock bdrv_create(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp);
|
||||
|
||||
int coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp);
|
||||
|
||||
BlockDriverState *bdrv_new(void);
|
||||
int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
|
||||
|
@ -246,12 +246,11 @@ struct BlockDriver {
|
||||
Error **errp);
|
||||
void (*bdrv_close)(BlockDriverState *bs);
|
||||
|
||||
int coroutine_fn (*bdrv_co_create)(BlockdevCreateOptions *opts,
|
||||
Error **errp);
|
||||
int coroutine_fn (*bdrv_co_create_opts)(BlockDriver *drv,
|
||||
const char *filename,
|
||||
QemuOpts *opts,
|
||||
Error **errp);
|
||||
int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)(
|
||||
BlockdevCreateOptions *opts, Error **errp);
|
||||
|
||||
int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create_opts)(
|
||||
BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp);
|
||||
|
||||
int (*bdrv_amend_options)(BlockDriverState *bs,
|
||||
QemuOpts *opts,
|
||||
|
Loading…
Reference in New Issue
Block a user