]> git.proxmox.com Git - mirror_qemu.git/commitdiff
block: add helper function to determine if a BDS is in a chain
authorJeff Cody <jcody@redhat.com>
Wed, 25 Jun 2014 19:40:09 +0000 (15:40 -0400)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 1 Jul 2014 08:47:01 +0000 (10:47 +0200)
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>
block.c
include/block/block.h

diff --git a/block.c b/block.c
index c111c297f738cdde08999622a5dd38dbbe7df403..f45e63c88ba5681beb44ecc8a8b480b69a3178d7 100644 (file)
--- 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) {
index 7e92f549fb2a6759540fe8546e0f2e919123da44..29c9e50ddbf44b174fc11e7938b96e498c7a3f46 100644 (file)
@@ -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);