From 5a6684d2b957f9ec75d7ed7b14332293abec1d6c Mon Sep 17 00:00:00 2001 From: Jeff Cody Date: Wed, 25 Jun 2014 15:40:09 -0400 Subject: 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 Reviewed-by: Eric Blake Signed-off-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- block.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'block.c') diff --git a/block.c b/block.c index c111c29..f45e63c 100644 --- a/block.c +++ b/block.c @@ -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) { -- cgit v1.1