aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorJeff Cody <jcody@redhat.com>2014-06-25 15:40:09 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2014-07-01 10:47:01 +0200
commit5a6684d2b957f9ec75d7ed7b14332293abec1d6c (patch)
treea48d938dc87ab82353945528d368d2d700da339e /block.c
parentfa40e65622352012dccd435147f28161375a6815 (diff)
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>
Diffstat (limited to 'block.c')
-rw-r--r--block.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/block.c b/block.c
index c111c297f7..f45e63c88b 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) {