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:
Kevin Wolf 2023-02-03 16:21:55 +01:00
parent 7b9e8b22bc
commit 4ec8df0183
16 changed files with 84 additions and 90 deletions

View File

@ -533,6 +533,7 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename,
int ret; int ret;
GLOBAL_STATE_CODE(); GLOBAL_STATE_CODE();
ERRP_GUARD(); ERRP_GUARD();
assert_bdrv_graph_readable();
if (!drv->bdrv_co_create_opts) { if (!drv->bdrv_co_create_opts) {
error_setg(errp, "Driver '%s' does not support image creation", error_setg(errp, "Driver '%s' does not support image creation",

View File

@ -43,6 +43,7 @@ static int coroutine_fn blockdev_create_run(Job *job, Error **errp)
int ret; int ret;
GLOBAL_STATE_CODE(); GLOBAL_STATE_CODE();
GRAPH_RDLOCK_GUARD();
job_progress_set_remaining(&s->common, 1); job_progress_set_remaining(&s->common, 1);
ret = s->drv->bdrv_co_create(s->opts, errp); ret = s->drv->bdrv_co_create(s->opts, errp);
@ -59,6 +60,12 @@ static const JobDriver blockdev_create_job_driver = {
.run = blockdev_create_run, .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, void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
Error **errp) 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 */ /* 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"); error_setg(errp, "Driver does not support blockdev-create");
return; return;
} }

View File

@ -664,10 +664,9 @@ fail:
return ret; return ret;
} }
static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
QCryptoBlockCreateOptions *create_opts = NULL; QCryptoBlockCreateOptions *create_opts = NULL;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;

View File

@ -2607,10 +2607,9 @@ out:
return result; return result;
} }
static int coroutine_fn raw_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, raw_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
BlockdevCreateOptions options; BlockdevCreateOptions options;
int64_t total_size = 0; int64_t total_size = 0;

View File

@ -613,10 +613,9 @@ static int raw_co_create(BlockdevCreateOptions *options, Error **errp)
return 0; return 0;
} }
static int coroutine_fn raw_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, raw_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
BlockdevCreateOptions options; BlockdevCreateOptions options;
int64_t total_size = 0; int64_t total_size = 0;

View File

@ -622,10 +622,9 @@ exit:
goto out; goto out;
} }
static int coroutine_fn parallels_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, parallels_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;

View File

@ -921,9 +921,9 @@ exit:
return ret; return ret;
} }
static int coroutine_fn qcow_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, qcow_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, Error **errp) QemuOpts *opts, Error **errp)
{ {
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;

View File

@ -3816,10 +3816,9 @@ out:
return ret; return ret;
} }
static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts,
QemuOpts *opts, Error **errp)
Error **errp)
{ {
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;
QDict *qdict; QDict *qdict;

View File

@ -754,10 +754,9 @@ out:
return ret; return ret;
} }
static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;
QDict *qdict; QDict *qdict;

View File

@ -430,10 +430,9 @@ static int raw_has_zero_init(BlockDriverState *bs)
return bdrv_has_zero_init(bs->file->bs); return bdrv_has_zero_init(bs->file->bs);
} }
static int coroutine_fn raw_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, raw_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
return bdrv_co_create_file(filename, opts, errp); return bdrv_co_create_file(filename, opts, errp);
} }

View File

@ -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); return vdi_co_do_create(create_options, DEFAULT_CLUSTER_SIZE, errp);
} }
static int coroutine_fn vdi_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, vdi_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
QDict *qdict = NULL; QDict *qdict = NULL;
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;

View File

@ -2059,10 +2059,9 @@ delete_and_exit:
return ret; return ret;
} }
static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, vhdx_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;
QDict *qdict; QDict *qdict;

View File

@ -2277,11 +2277,10 @@ exit:
return ret; return ret;
} }
static int coroutine_fn vmdk_create_extent(const char *filename, static int coroutine_fn GRAPH_RDLOCK
int64_t filesize, bool flat, vmdk_create_extent(const char *filename, int64_t filesize, bool flat,
bool compress, bool zeroed_grain, bool compress, bool zeroed_grain, BlockBackend **pbb,
BlockBackend **pbb, QemuOpts *opts, Error **errp)
QemuOpts *opts, Error **errp)
{ {
int ret; int ret;
BlockBackend *blk = NULL; BlockBackend *blk = NULL;
@ -2359,14 +2358,10 @@ static int filename_decompose(const char *filename, char *path, char *prefix,
* non-split format. * non-split format.
* idx >= 1: get the n-th extent if in a split subformat * idx >= 1: get the n-th extent if in a split subformat
*/ */
typedef BlockBackend * coroutine_fn (*vmdk_create_extent_fn)(int64_t size, typedef BlockBackend * coroutine_fn /* GRAPH_RDLOCK */
int idx, (*vmdk_create_extent_fn)(int64_t size, int idx, bool flat, bool split,
bool flat, bool compress, bool zeroed_grain, void *opaque,
bool split, Error **errp);
bool compress,
bool zeroed_grain,
void *opaque,
Error **errp);
static void vmdk_desc_add_extent(GString *desc, static void vmdk_desc_add_extent(GString *desc,
const char *extent_line_fmt, const char *extent_line_fmt,
@ -2379,17 +2374,18 @@ static void vmdk_desc_add_extent(GString *desc,
g_free(basename); g_free(basename);
} }
static int coroutine_fn vmdk_co_do_create(int64_t size, static int coroutine_fn GRAPH_RDLOCK
BlockdevVmdkSubformat subformat, vmdk_co_do_create(int64_t size,
BlockdevVmdkAdapterType adapter_type, BlockdevVmdkSubformat subformat,
const char *backing_file, BlockdevVmdkAdapterType adapter_type,
const char *hw_version, const char *backing_file,
const char *toolsversion, const char *hw_version,
bool compat6, const char *toolsversion,
bool zeroed_grain, bool compat6,
vmdk_create_extent_fn extent_fn, bool zeroed_grain,
void *opaque, vmdk_create_extent_fn extent_fn,
Error **errp) void *opaque,
Error **errp)
{ {
int extent_idx; int extent_idx;
BlockBackend *blk = NULL; BlockBackend *blk = NULL;
@ -2609,10 +2605,10 @@ typedef struct {
QemuOpts *opts; QemuOpts *opts;
} VMDKCreateOptsData; } VMDKCreateOptsData;
static BlockBackend * coroutine_fn vmdk_co_create_opts_cb(int64_t size, int idx, static BlockBackend * coroutine_fn GRAPH_RDLOCK
bool flat, bool split, bool compress, vmdk_co_create_opts_cb(int64_t size, int idx, bool flat, bool split,
bool zeroed_grain, void *opaque, bool compress, bool zeroed_grain, void *opaque,
Error **errp) Error **errp)
{ {
BlockBackend *blk = NULL; BlockBackend *blk = NULL;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
@ -2651,10 +2647,9 @@ exit:
return blk; return blk;
} }
static int coroutine_fn vmdk_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, vmdk_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
Error *local_err = NULL; Error *local_err = NULL;
char *desc = NULL; char *desc = NULL;
@ -2814,8 +2809,8 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(int64_t size, int idx,
return blk; return blk;
} }
static int coroutine_fn vmdk_co_create(BlockdevCreateOptions *create_options, static int coroutine_fn GRAPH_RDLOCK
Error **errp) vmdk_co_create(BlockdevCreateOptions *create_options, Error **errp)
{ {
BlockdevCreateOptionsVmdk *opts; BlockdevCreateOptionsVmdk *opts;

View File

@ -1087,10 +1087,9 @@ out:
return ret; return ret;
} }
static int coroutine_fn vpc_co_create_opts(BlockDriver *drv, static int coroutine_fn GRAPH_RDLOCK
const char *filename, vpc_co_create_opts(BlockDriver *drv, const char *filename,
QemuOpts *opts, QemuOpts *opts, Error **errp)
Error **errp)
{ {
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;
QDict *qdict; QDict *qdict;

View File

@ -58,13 +58,15 @@ BlockDriver *bdrv_find_protocol(const char *filename,
Error **errp); Error **errp);
BlockDriver *bdrv_find_format(const char *format_name); BlockDriver *bdrv_find_format(const char *format_name);
int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename, int coroutine_fn GRAPH_RDLOCK
QemuOpts *opts, Error **errp); bdrv_co_create(BlockDriver *drv, const char *filename, QemuOpts *opts,
int co_wrapper bdrv_create(BlockDriver *drv, const char *filename, Error **errp);
QemuOpts *opts, Error **errp);
int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts, int co_wrapper_bdrv_rdlock bdrv_create(BlockDriver *drv, const char *filename,
Error **errp); QemuOpts *opts, Error **errp);
int coroutine_fn GRAPH_RDLOCK
bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp);
BlockDriverState *bdrv_new(void); BlockDriverState *bdrv_new(void);
int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,

View File

@ -246,12 +246,11 @@ struct BlockDriver {
Error **errp); Error **errp);
void (*bdrv_close)(BlockDriverState *bs); void (*bdrv_close)(BlockDriverState *bs);
int coroutine_fn (*bdrv_co_create)(BlockdevCreateOptions *opts, int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)(
Error **errp); BlockdevCreateOptions *opts, Error **errp);
int coroutine_fn (*bdrv_co_create_opts)(BlockDriver *drv,
const char *filename, int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create_opts)(
QemuOpts *opts, BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp);
Error **errp);
int (*bdrv_amend_options)(BlockDriverState *bs, int (*bdrv_amend_options)(BlockDriverState *bs,
QemuOpts *opts, QemuOpts *opts,