mirror of
https://github.com/qemu/qemu.git
synced 2026-02-04 05:35:39 +00:00
block: Allow drivers to control protocol prefix at creation
This patch is pure refactoring: instead of hard-coding permission to use a protocol prefix when creating an image, the drivers can now pass in a parameter, comparable to what they could already do for opening a pre-existing image. This patch is purely mechanical (all drivers pass in true for now), but it will enable the next patch to cater to drivers that want to differ in behavior for the primary image vs. any secondary images that are opened at the same time as creating the primary image. Signed-off-by: Eric Blake <eblake@redhat.com> Message-ID: <20250915213919.3121401-5-eblake@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
4
block.c
4
block.c
@@ -693,7 +693,7 @@ out:
|
||||
}
|
||||
|
||||
int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts,
|
||||
Error **errp)
|
||||
bool allow_protocol_prefix, Error **errp)
|
||||
{
|
||||
QemuOpts *protocol_opts;
|
||||
BlockDriver *drv;
|
||||
@@ -702,7 +702,7 @@ int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts,
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
drv = bdrv_find_protocol(filename, true, errp);
|
||||
drv = bdrv_find_protocol(filename, allow_protocol_prefix, errp);
|
||||
if (drv == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
@@ -835,7 +835,7 @@ block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename,
|
||||
}
|
||||
|
||||
/* Create protocol layer */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -1117,7 +1117,7 @@ parallels_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
}
|
||||
|
||||
/* Create and open the file (protocol layer) */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -978,7 +978,7 @@ qcow_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
}
|
||||
|
||||
/* Create and open the file (protocol layer) */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -3956,7 +3956,7 @@ qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts,
|
||||
}
|
||||
|
||||
/* Create and open the file (protocol layer) */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto finish;
|
||||
}
|
||||
@@ -3971,7 +3971,7 @@ qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts,
|
||||
/* Create and open an external data file (protocol layer) */
|
||||
val = qdict_get_try_str(qdict, BLOCK_OPT_DATA_FILE);
|
||||
if (val) {
|
||||
ret = bdrv_co_create_file(val, opts, errp);
|
||||
ret = bdrv_co_create_file(val, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@@ -788,7 +788,7 @@ bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
}
|
||||
|
||||
/* Create and open the file (protocol layer) */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ static int coroutine_fn GRAPH_UNLOCKED
|
||||
raw_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp)
|
||||
{
|
||||
return bdrv_co_create_file(filename, opts, errp);
|
||||
return bdrv_co_create_file(filename, opts, true, errp);
|
||||
}
|
||||
|
||||
static int raw_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
@@ -938,7 +938,7 @@ vdi_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
qdict = qemu_opts_to_qdict_filtered(opts, NULL, &vdi_create_opts, true);
|
||||
|
||||
/* Create and open the file (protocol layer) */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -2096,7 +2096,7 @@ vhdx_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
}
|
||||
|
||||
/* Create and open the file (protocol layer) */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -2334,7 +2334,7 @@ vmdk_create_extent(const char *filename, int64_t filesize, bool flat,
|
||||
int ret;
|
||||
BlockBackend *blk = NULL;
|
||||
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -1118,7 +1118,7 @@ vpc_co_create_opts(BlockDriver *drv, const char *filename,
|
||||
}
|
||||
|
||||
/* Create and open the file (protocol layer) */
|
||||
ret = bdrv_co_create_file(filename, opts, errp);
|
||||
ret = bdrv_co_create_file(filename, opts, true, errp);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,8 @@ int co_wrapper bdrv_create(BlockDriver *drv, const char *filename,
|
||||
QemuOpts *opts, Error **errp);
|
||||
|
||||
int coroutine_fn GRAPH_UNLOCKED
|
||||
bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp);
|
||||
bdrv_co_create_file(const char *filename, QemuOpts *opts,
|
||||
bool allow_protocol_prefix, Error **errp);
|
||||
|
||||
BlockDriverState *bdrv_new(void);
|
||||
int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
|
||||
|
||||
Reference in New Issue
Block a user