[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 05/42] block: Add chain helper functions
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v6 05/42] block: Add chain helper functions |
Date: |
Fri, 9 Aug 2019 18:13:30 +0200 |
Add some helper functions for skipping filters in a chain of block
nodes.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
include/block/block_int.h | 3 +++
block.c | 55 +++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 6c60abc4c3..5bec3361fd 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -1291,6 +1291,9 @@ BdrvChild *bdrv_filtered_child(BlockDriverState *bs);
BdrvChild *bdrv_metadata_child(BlockDriverState *bs);
BdrvChild *bdrv_storage_child(BlockDriverState *bs);
BdrvChild *bdrv_primary_child(BlockDriverState *bs);
+BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs);
+BlockDriverState *bdrv_skip_rw_filters(BlockDriverState *bs);
+BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs);
static inline BlockDriverState *child_bs(BdrvChild *child)
{
diff --git a/block.c b/block.c
index f6c5f8c3eb..bfa5e27850 100644
--- a/block.c
+++ b/block.c
@@ -6655,3 +6655,58 @@ BdrvChild *bdrv_primary_child(BlockDriverState *bs)
{
return bdrv_filtered_rw_child(bs) ?: bs->file;
}
+
+static BlockDriverState *bdrv_skip_filters(BlockDriverState *bs,
+ bool stop_on_explicit_filter)
+{
+ BdrvChild *filtered;
+
+ if (!bs) {
+ return NULL;
+ }
+
+ while (!(stop_on_explicit_filter && !bs->implicit)) {
+ filtered = bdrv_filtered_rw_child(bs);
+ if (!filtered) {
+ break;
+ }
+ bs = filtered->bs;
+ }
+ /*
+ * Note that this treats nodes with bs->drv == NULL as not being
+ * R/W filters (bs->drv == NULL should be replaced by something
+ * else anyway).
+ * The advantage of this behavior is that this function will thus
+ * always return a non-NULL value (given a non-NULL @bs).
+ */
+
+ return bs;
+}
+
+/*
+ * Return the first BDS that has not been added implicitly or that
+ * does not have an RW-filtered child down the chain starting from @bs
+ * (including @bs itself).
+ */
+BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs)
+{
+ return bdrv_skip_filters(bs, true);
+}
+
+/*
+ * Return the first BDS that does not have an RW-filtered child down
+ * the chain starting from @bs (including @bs itself).
+ */
+BlockDriverState *bdrv_skip_rw_filters(BlockDriverState *bs)
+{
+ return bdrv_skip_filters(bs, false);
+}
+
+/*
+ * For a backing chain, return the first non-filter backing image of
+ * the first non-filter image.
+ */
+BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs)
+{
+ return
bdrv_skip_rw_filters(bdrv_filtered_cow_bs(bdrv_skip_rw_filters(bs)));
+}
--
2.21.0
- [Qemu-devel] [PATCH v6 00/42] block: Deal with filters, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 01/42] block: Mark commit and mirror as filter drivers, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 02/42] copy-on-read: Support compressed writes, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 03/42] throttle: Support compressed writes, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 05/42] block: Add chain helper functions,
Max Reitz <=
- [Qemu-devel] [PATCH v6 06/42] qcow2: Implement .bdrv_storage_child(), Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 04/42] block: Add child access functions, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 07/42] block: *filtered_cow_child() for *has_zero_init(), Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 08/42] block: bdrv_set_backing_hd() is about bs->backing, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 10/42] block: Drop bdrv_is_encrypted(), Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 09/42] block: Include filters when freezing backing chain, Max Reitz, 2019/08/09