[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 02/10] block: add helper function to determine if
From: |
Jeff Cody |
Subject: |
[Qemu-devel] [PATCH v5 02/10] block: add helper function to determine if a BDS is in a chain |
Date: |
Fri, 13 Jun 2014 14:52:30 -0400 |
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Jeff Cody <address@hidden>
---
block.c | 11 +++++++++++
include/block/block.h | 1 +
2 files changed, 12 insertions(+)
diff --git a/block.c b/block.c
index fd43016..f9ea1b4 100644
--- a/block.c
+++ b/block.c
@@ -3822,6 +3822,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 7d86e29..08fe1ac 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -404,6 +404,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);
--
1.8.3.1
- [Qemu-devel] [PATCH v5 00/10] Modify block jobs to use node-names, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 01/10] block: Auto-generate node_names for each BDS entry, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 02/10] block: add helper function to determine if a BDS is in a chain,
Jeff Cody <=
- [Qemu-devel] [PATCH v5 03/10] block: simplify bdrv_find_base() and bdrv_find_overlay(), Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 04/10] block: make 'top' argument to block-commit optional, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 06/10] block: extend block-commit to accept a string for the backing file, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 05/10] block: Accept node-name arguments for block-commit, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 07/10] block: add ability for block-stream to use node-name, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 08/10] block: add backing-file option to block-stream, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 09/10] block: Add QMP documentation for block-stream, Jeff Cody, 2014/06/13