diff options
-rw-r--r-- | block.c | 11 | ||||
-rw-r--r-- | include/block/block.h | 1 |
2 files changed, 12 insertions, 0 deletions
@@ -3774,6 +3774,17 @@ BlockDriverState *bdrv_lookup_bs(const char *device, 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) { if (!bs) { diff --git a/include/block/block.h b/include/block/block.h index 7e92f549fb..29c9e50ddb 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -403,6 +403,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(void); BlockDriverState *bdrv_lookup_bs(const char *device, const char *node_name, Error **errp); +bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base); BlockDriverState *bdrv_next(BlockDriverState *bs); void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void *opaque); |