Browse Source

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>
pull/307/head
Eric Blake 11 months ago
committed by Kevin Wolf
parent
commit
1bd7bfbc2b
  1. 4
      block.c
  2. 2
      block/crypto.c
  3. 2
      block/parallels.c
  4. 2
      block/qcow.c
  5. 4
      block/qcow2.c
  6. 2
      block/qed.c
  7. 2
      block/raw-format.c
  8. 2
      block/vdi.c
  9. 2
      block/vhdx.c
  10. 2
      block/vmdk.c
  11. 2
      block/vpc.c
  12. 3
      include/block/block-global-state.h

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;
}

2
block/crypto.c

@ -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;
}

2
block/parallels.c

@ -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;
}

2
block/qcow.c

@ -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;
}

4
block/qcow2.c

@ -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;
}

2
block/qed.c

@ -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;
}

2
block/raw-format.c

@ -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,

2
block/vdi.c

@ -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;
}

2
block/vhdx.c

@ -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;
}

2
block/vmdk.c

@ -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;
}

2
block/vpc.c

@ -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;
}

3
include/block/block-global-state.h

@ -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,

Loading…
Cancel
Save