mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
block: add helper function to determine if a BDS is in a chain
This is a small helper function, to determine if 'base' is in the chain of BlockDriverState 'top'. It returns true if it is in the chain, and false otherwise. If either argument is NULL, it will also return false. Reviewed-by: Benoit Canet <benoit@irqsave.net> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
fa40e65622
commit
5a6684d2b9
2 changed files with 12 additions and 0 deletions
11
block.c
11
block.c
|
@ -3774,6 +3774,17 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If 'base' is in the same chain as 'top', return true. Otherwise,
|
||||||
|
* return false. If either argument is NULL, return false. */
|
||||||
|
bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base)
|
||||||
|
{
|
||||||
|
while (top && top != base) {
|
||||||
|
top = top->backing_hd;
|
||||||
|
}
|
||||||
|
|
||||||
|
return top != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
BlockDriverState *bdrv_next(BlockDriverState *bs)
|
BlockDriverState *bdrv_next(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
|
|
|
@ -403,6 +403,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(void);
|
||||||
BlockDriverState *bdrv_lookup_bs(const char *device,
|
BlockDriverState *bdrv_lookup_bs(const char *device,
|
||||||
const char *node_name,
|
const char *node_name,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
|
bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base);
|
||||||
BlockDriverState *bdrv_next(BlockDriverState *bs);
|
BlockDriverState *bdrv_next(BlockDriverState *bs);
|
||||||
void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
|
void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
|
||||||
void *opaque);
|
void *opaque);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue