mirror of https://github.com/xemu-project/xemu.git
block: move supports_backing check to bdrv_set_file_or_backing_noperm()
Move supports_backing check of bdrv_reopen_parse_backing to called (through bdrv_set_backing_noperm()) bdrv_set_file_or_backing_noperm() function. The check applies to general case, so it's appropriate for bdrv_set_file_or_backing_noperm(). We have to declare backing support for two test drivers, otherwise new check fails. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20210610120537.196183-7-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
cbfdb98ce2
commit
25f78d9e2d
29
block.c
29
block.c
|
@ -3152,6 +3152,14 @@ static int bdrv_set_file_or_backing_noperm(BlockDriverState *parent_bs,
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_backing && !parent_bs->drv->is_filter &&
|
||||||
|
!parent_bs->drv->supports_backing)
|
||||||
|
{
|
||||||
|
error_setg(errp, "Driver '%s' of node '%s' does not support backing "
|
||||||
|
"files", parent_bs->drv->format_name, parent_bs->node_name);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (parent_bs->drv->is_filter) {
|
if (parent_bs->drv->is_filter) {
|
||||||
role = BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY;
|
role = BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY;
|
||||||
} else if (is_backing) {
|
} else if (is_backing) {
|
||||||
|
@ -4278,20 +4286,13 @@ static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (bs->drv->is_filter && !bs->backing) {
|
||||||
* Ensure that @bs can really handle backing files, because we are
|
/*
|
||||||
* about to give it one (or swap the existing one)
|
* Filters always have a file or a backing child, so we are trying to
|
||||||
*/
|
* change wrong child
|
||||||
if (bs->drv->is_filter) {
|
*/
|
||||||
/* Filters always have a file or a backing child */
|
error_setg(errp, "'%s' is a %s filter node that does not support a "
|
||||||
if (!bs->backing) {
|
"backing child", bs->node_name, bs->drv->format_name);
|
||||||
error_setg(errp, "'%s' is a %s filter node that does not support a "
|
|
||||||
"backing child", bs->node_name, bs->drv->format_name);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
} else if (!bs->drv->supports_backing) {
|
|
||||||
error_setg(errp, "Driver '%s' of node '%s' does not support backing "
|
|
||||||
"files", bs->drv->format_name, bs->node_name);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ static int bdrv_test_change_backing_file(BlockDriverState *bs,
|
||||||
static BlockDriver bdrv_test = {
|
static BlockDriver bdrv_test = {
|
||||||
.format_name = "test",
|
.format_name = "test",
|
||||||
.instance_size = sizeof(BDRVTestState),
|
.instance_size = sizeof(BDRVTestState),
|
||||||
|
.supports_backing = true,
|
||||||
|
|
||||||
.bdrv_close = bdrv_test_close,
|
.bdrv_close = bdrv_test_close,
|
||||||
.bdrv_co_preadv = bdrv_test_co_preadv,
|
.bdrv_co_preadv = bdrv_test_co_preadv,
|
||||||
|
|
|
@ -41,6 +41,7 @@ static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c,
|
||||||
|
|
||||||
static BlockDriver bdrv_no_perm = {
|
static BlockDriver bdrv_no_perm = {
|
||||||
.format_name = "no-perm",
|
.format_name = "no-perm",
|
||||||
|
.supports_backing = true,
|
||||||
.bdrv_child_perm = no_perm_default_perms,
|
.bdrv_child_perm = no_perm_default_perms,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue