block: Make format drivers use child_of_bds
Commonly, they need to pass the BDRV_CHILD_IMAGE set as the BdrvChildRole; but there are exceptions for drivers with external data files (qcow2 and vmdk). Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20200513110544.176672-26-mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
ff3541c4e2
commit
8b1869daad
@ -110,8 +110,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -218,8 +218,8 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
|
|||||||
unsigned int cflags = 0;
|
unsigned int cflags = 0;
|
||||||
QDict *cryptoopts = NULL;
|
QDict *cryptoopts = NULL;
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -439,8 +439,8 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -739,8 +739,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -130,8 +130,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
qdict_extract_subqdict(options, &encryptopts, "encrypt.");
|
qdict_extract_subqdict(options, &encryptopts, "encrypt.");
|
||||||
encryptfmt = qdict_get_try_str(encryptopts, "format");
|
encryptfmt = qdict_get_try_str(encryptopts, "format");
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -1590,8 +1590,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Open external data file */
|
/* Open external data file */
|
||||||
s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file,
|
s->data_file = bdrv_open_child(NULL, options, "data-file", bs,
|
||||||
0, true, &local_err);
|
&child_of_bds, BDRV_CHILD_DATA,
|
||||||
|
true, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
@ -1601,8 +1602,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
|
|||||||
if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) {
|
if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) {
|
||||||
if (!s->data_file && s->image_data_file) {
|
if (!s->data_file && s->image_data_file) {
|
||||||
s->data_file = bdrv_open_child(s->image_data_file, options,
|
s->data_file = bdrv_open_child(s->image_data_file, options,
|
||||||
"data-file", bs, &child_file, 0,
|
"data-file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_DATA, false, errp);
|
||||||
if (!s->data_file) {
|
if (!s->data_file) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -1613,6 +1614,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
|
|||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* No data here */
|
||||||
|
bs->file->role &= ~BDRV_CHILD_DATA;
|
||||||
|
|
||||||
|
/* Must succeed because we have given up permissions if anything */
|
||||||
|
bdrv_child_refresh_perms(bs, bs->file, &error_abort);
|
||||||
} else {
|
} else {
|
||||||
if (s->data_file) {
|
if (s->data_file) {
|
||||||
error_setg(errp, "'data-file' can only be set for images with an "
|
error_setg(errp, "'data-file' can only be set for images with an "
|
||||||
@ -1863,8 +1870,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
.ret = -EINPROGRESS
|
.ret = -EINPROGRESS
|
||||||
};
|
};
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -547,8 +547,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
.ret = -EINPROGRESS
|
.ret = -EINPROGRESS
|
||||||
};
|
};
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -378,8 +378,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
QemuUUID uuid_link, uuid_parent;
|
QemuUUID uuid_link, uuid_parent;
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -996,8 +996,8 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
uint64_t signature;
|
uint64_t signature;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
20
block/vmdk.c
20
block/vmdk.c
@ -1089,6 +1089,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|||||||
char *desc_file_dir = NULL;
|
char *desc_file_dir = NULL;
|
||||||
char *extent_path;
|
char *extent_path;
|
||||||
BdrvChild *extent_file;
|
BdrvChild *extent_file;
|
||||||
|
BdrvChildRole extent_role;
|
||||||
BDRVVmdkState *s = bs->opaque;
|
BDRVVmdkState *s = bs->opaque;
|
||||||
VmdkExtent *extent;
|
VmdkExtent *extent;
|
||||||
char extent_opt_prefix[32];
|
char extent_opt_prefix[32];
|
||||||
@ -1151,8 +1152,15 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|||||||
ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents);
|
ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents);
|
||||||
assert(ret < 32);
|
assert(ret < 32);
|
||||||
|
|
||||||
|
extent_role = BDRV_CHILD_DATA;
|
||||||
|
if (strcmp(type, "FLAT") != 0 && strcmp(type, "VMFS") != 0) {
|
||||||
|
/* non-flat extents have metadata */
|
||||||
|
extent_role |= BDRV_CHILD_METADATA;
|
||||||
|
}
|
||||||
|
|
||||||
extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix,
|
extent_file = bdrv_open_child(extent_path, options, extent_opt_prefix,
|
||||||
bs, &child_file, 0, false, &local_err);
|
bs, &child_of_bds, extent_role, false,
|
||||||
|
&local_err);
|
||||||
g_free(extent_path);
|
g_free(extent_path);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
@ -1257,8 +1265,8 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -1277,6 +1285,12 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
s->desc_offset = 0x200;
|
s->desc_offset = 0x200;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
/* No data in the descriptor file */
|
||||||
|
bs->file->role &= ~BDRV_CHILD_DATA;
|
||||||
|
|
||||||
|
/* Must succeed because we have given up permissions if anything */
|
||||||
|
bdrv_child_refresh_perms(bs, bs->file, &error_abort);
|
||||||
|
|
||||||
ret = vmdk_open_desc_file(bs, flags, buf, options, errp);
|
ret = vmdk_open_desc_file(bs, flags, buf, options, errp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -228,8 +228,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
|
|||||||
int ret;
|
int ret;
|
||||||
int64_t bs_size;
|
int64_t bs_size;
|
||||||
|
|
||||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
|
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||||
false, errp);
|
BDRV_CHILD_IMAGE, false, errp);
|
||||||
if (!bs->file) {
|
if (!bs->file) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user