[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 04/15] block: Add chain helper functions
From: |
Andrey Shinkevich |
Subject: |
[PATCH v3 04/15] block: Add chain helper functions |
Date: |
Tue, 12 May 2020 17:53:05 +0300 |
From: Max Reitz <address@hidden>
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>
---
block.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++
include/block/block_int.h | 3 +++
2 files changed, 58 insertions(+)
diff --git a/block.c b/block.c
index b2aae2e..5b4ebfe 100644
--- a/block.c
+++ b/block.c
@@ -6863,3 +6863,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)));
+}
diff --git a/include/block/block_int.h b/include/block/block_int.h
index dca59e9..86f7666 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -1347,6 +1347,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)
{
--
1.8.3.1
- [PATCH v3 00/15] Apply COR-filter to the block-stream permanently, Andrey Shinkevich, 2020/05/12
- [PATCH v3 04/15] block: Add chain helper functions,
Andrey Shinkevich <=
- [PATCH v3 11/15] copy-on-read: Support preadv/pwritev_part functions, Andrey Shinkevich, 2020/05/12
- [PATCH v3 09/15] block: prepare block-stream for using COR-filter, Andrey Shinkevich, 2020/05/12
- [PATCH v3 08/15] block: Use CAFs when working with backing chains, Andrey Shinkevich, 2020/05/12
- [PATCH v3 02/15] copy-on-read: Support compressed writes, Andrey Shinkevich, 2020/05/12
- [PATCH v3 07/15] commit: Deal with filters when blocking intermediate nodes, Andrey Shinkevich, 2020/05/12
- [PATCH v3 12/15] copy-on-read: add filter append/drop functions, Andrey Shinkevich, 2020/05/12
- [PATCH v3 01/15] block: Mark commit and mirror as filter drivers, Andrey Shinkevich, 2020/05/12
- [PATCH v3 13/15] qapi: add filter-node-name to block-stream, Andrey Shinkevich, 2020/05/12
- [PATCH v3 06/15] block: Use CAFs in block status functions, Andrey Shinkevich, 2020/05/12
- [PATCH v3 15/15] block: apply COR-filter to block-stream jobs, Andrey Shinkevich, 2020/05/12