config: add check to block layer
RFC v5 7/11 config: add check to block layer
Putting zoned/non-zoned BlockDrivers on top of each other is not allowed.
Signed-off-by Sam Li <[email protected]>
--- block.c | 13 +++++++++++++ block/file-posix.c | 2 ++ block/raw-format.c | 1 + include/block/block_int-common.h | 10 ++++++++++ 4 files changed, 26 insertions(+)
block.c +13 -0
@@ -7947,6 +7947,19 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,return ; } +/* +* Non-zoned block drivers do not follow zoned storage constraints +* (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned +* drivers in a graph. +*/ +if (!parent_bs->drv->supports_zoned_children && child_bs->drv->is_zoned) { +error_setg (errp,"Cannot add a %s child to a %s parent" , + child_bs->drv->is_zoned ?"zoned" :"non-zoned" , + parent_bs->drv->supports_zoned_children ? +"support zoned children" :"not support zoned children" ); +return ; + } +if (!QLIST_EMPTY (&child_bs->parents)) {error_setg (errp,"The node %s already has a parent" , child_bs->node_name);
block/file-posix.c +2 -0
@@ -4023,6 +4023,8 @@ static BlockDriver bdrv_zoned_host_device = { .format_name = "zoned_host_device", .protocol_name = "zoned_host_device", .instance_size = sizeof(BDRVRawState), + .is_zoned = true, + .supports_zoned_children = true, .bdrv_needs_filename = true, .bdrv_probe_device = hdev_probe_device, .bdrv_parse_filename = zoned_host_device_parse_filename,
block/raw-format.c +1 -0
@@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,BlockDriver bdrv_raw = { .format_name ="raw" , .instance_size =sizeof (BDRVRawState), + .supports_zoned_children = true, .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_reopen_commit = &raw_reopen_commit,
include/block/block_int-common.h +10 -0
@@ -126,6 +126,16 @@ struct BlockDriver {*/ bool is_format; +/* +* Set to true if the BlockDriver is a zoned block driver. +*/ +bool is_zoned; + +/* +* Set to true if the BlockDriver supports zoned children. +*/ +bool supports_zoned_children; +/* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their
Signature · 1 line
2.37.1
Quoted 41 lines · Sam Li
Putting zoned/non-zoned BlockDrivers on top of each other is not allowed.
Signed-off-by Sam Li <[email protected]>--- block.c | 13 +++++++++++++ block/file-posix.c | 2 ++ block/raw-format.c | 1 + include/block/block_int-common.h | 10 ++++++++++ 4 files changed, 26 insertions(+)block.c +13
-0@@ -7947,6 +7947,19 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,return ; } +/* +* Non-zoned block drivers do not follow zoned storage constraints +* (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned +* drivers in a graph. +*/ +if (!parent_bs->drv->supports_zoned_children && child_bs->drv->is_zoned) { +error_setg (errp,"Cannot add a %s child to a %s parent" , + child_bs->drv->is_zoned ?"zoned" :"non-zoned" , + parent_bs->drv->supports_zoned_children ? +"support zoned children" :"not support zoned children" ); +return ; + } +if (!QLIST_EMPTY (&child_bs->parents)) {error_setg (errp,"The node %s already has a parent" , child_bs->node_name);block/file-posix.c +0
-0
block/file-posix.c static BlockDriver bdrv_zoned_host_device = { · line 4027
Quoted 5 lines
block/file-posix.c +2
-0@@ -4023,6 +4023,8 @@ static BlockDriver bdrv_zoned_host_device = { .format_name = "zoned_host_device", .protocol_name = "zoned_host_device", .instance_size = sizeof(BDRVRawState), + .is_zoned = true, + .supports_zoned_children = true,
zoned_host_device never has children, so supports_zoned_children should not be set.
Quoted 40 lines
block/file-posix.c +0
-0.bdrv_needs_filename = true, .bdrv_probe_device = hdev_probe_device, .bdrv_parse_filename = zoned_host_device_parse_filename,block/raw-format.c +1
-0@@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,BlockDriver bdrv_raw = { .format_name ="raw" , .instance_size =sizeof (BDRVRawState), + .supports_zoned_children = true, .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_reopen_commit = &raw_reopen_commit,include/block/block_int-common.h +10
-1@@ -126,6 +126,16 @@ struct BlockDriver {*/ bool is_format; +/* +* Set to true if the BlockDriver is a zoned block driver. +*/ +bool is_zoned; + +/* +* Set to true if the BlockDriver supports zoned children. +*/ +bool supports_zoned_children; +/* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their -- 2.37.1