mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00
block: Add child access functions
There are BDS children that the general block layer code can access, namely bs->file and bs->backing. Since the introduction of filters and external data files, their meaning is not quite clear. bs->backing can be a COW source, or it can be a filtered child; bs->file can be a filtered child, it can be data and metadata storage, or it can be just metadata storage. This overloading really is not helpful. This patch adds functions that retrieve the correct child for each exact purpose. Later patches in this series will make use of them. Doing so will allow us to handle filter nodes in a meaningful way. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
This commit is contained in:
parent
b111b3fcde
commit
9a6fc88799
2 changed files with 132 additions and 3 deletions
|
@ -92,9 +92,17 @@ struct BlockDriver {
|
|||
int instance_size;
|
||||
|
||||
/* set to true if the BlockDriver is a block filter. Block filters pass
|
||||
* certain callbacks that refer to data (see block.c) to their bs->file if
|
||||
* the driver doesn't implement them. Drivers that do not wish to forward
|
||||
* must implement them and return -ENOTSUP.
|
||||
* certain callbacks that refer to data (see block.c) to their bs->file
|
||||
* or bs->backing (whichever one exists) if the driver doesn't implement
|
||||
* them. Drivers that do not wish to forward must implement them and return
|
||||
* -ENOTSUP.
|
||||
* Note that filters are not allowed to modify data.
|
||||
*
|
||||
* Filters generally cannot have more than a single filtered child,
|
||||
* because the data they present must at all times be the same as
|
||||
* that on their filtered child. That would be impossible to
|
||||
* achieve for multiple filtered children.
|
||||
* (And this filtered child must then be bs->file or bs->backing.)
|
||||
*/
|
||||
bool is_filter;
|
||||
/*
|
||||
|
@ -1382,4 +1390,34 @@ BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,
|
|||
BlockDriverState **bitmap_bs,
|
||||
Error **errp);
|
||||
|
||||
BdrvChild *bdrv_cow_child(BlockDriverState *bs);
|
||||
BdrvChild *bdrv_filter_child(BlockDriverState *bs);
|
||||
BdrvChild *bdrv_filter_or_cow_child(BlockDriverState *bs);
|
||||
BdrvChild *bdrv_primary_child(BlockDriverState *bs);
|
||||
|
||||
static inline BlockDriverState *child_bs(BdrvChild *child)
|
||||
{
|
||||
return child ? child->bs : NULL;
|
||||
}
|
||||
|
||||
static inline BlockDriverState *bdrv_cow_bs(BlockDriverState *bs)
|
||||
{
|
||||
return child_bs(bdrv_cow_child(bs));
|
||||
}
|
||||
|
||||
static inline BlockDriverState *bdrv_filter_bs(BlockDriverState *bs)
|
||||
{
|
||||
return child_bs(bdrv_filter_child(bs));
|
||||
}
|
||||
|
||||
static inline BlockDriverState *bdrv_filter_or_cow_bs(BlockDriverState *bs)
|
||||
{
|
||||
return child_bs(bdrv_filter_or_cow_child(bs));
|
||||
}
|
||||
|
||||
static inline BlockDriverState *bdrv_primary_bs(BlockDriverState *bs)
|
||||
{
|
||||
return child_bs(bdrv_primary_child(bs));
|
||||
}
|
||||
|
||||
#endif /* BLOCK_INT_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue