[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 07/47] block: Add bdrv_supports_compressed_writes()
From: |
Max Reitz |
Subject: |
[PATCH v7 07/47] block: Add bdrv_supports_compressed_writes() |
Date: |
Thu, 25 Jun 2020 17:21:35 +0200 |
Filters cannot compress data themselves but they have to implement
.bdrv_co_pwritev_compressed() still (or they cannot forward compressed
writes). Therefore, checking whether
bs->drv->bdrv_co_pwritev_compressed is non-NULL is not sufficient to
know whether the node can actually handle compressed writes. This
function looks down the filter chain to see whether there is a
non-filter that can actually convert the compressed writes into
compressed data (and thus normal writes).
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
include/block/block.h | 1 +
block.c | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/block/block.h b/include/block/block.h
index 0080fe1311..a905a5ec05 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -538,6 +538,7 @@ BlockDriverState *bdrv_next(BdrvNextIterator *it);
void bdrv_next_cleanup(BdrvNextIterator *it);
BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs);
+bool bdrv_supports_compressed_writes(BlockDriverState *bs);
void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
void *opaque, bool read_only);
const char *bdrv_get_node_name(const BlockDriverState *bs);
diff --git a/block.c b/block.c
index 76277ea4e0..6449f3a11d 100644
--- a/block.c
+++ b/block.c
@@ -5044,6 +5044,29 @@ bool bdrv_is_sg(BlockDriverState *bs)
return bs->sg;
}
+/**
+ * Return whether the given node supports compressed writes.
+ */
+bool bdrv_supports_compressed_writes(BlockDriverState *bs)
+{
+ BlockDriverState *filtered;
+
+ if (!bs->drv || !block_driver_can_compress(bs->drv)) {
+ return false;
+ }
+
+ filtered = bdrv_filter_bs(bs);
+ if (filtered) {
+ /*
+ * Filters can only forward compressed writes, so we have to
+ * check the child.
+ */
+ return bdrv_supports_compressed_writes(filtered);
+ }
+
+ return true;
+}
+
const char *bdrv_get_format_name(BlockDriverState *bs)
{
return bs->drv ? bs->drv->format_name : NULL;
--
2.26.2
- [PATCH v7 00/47] block: Deal with filters, Max Reitz, 2020/06/25
- [PATCH v7 01/47] block: Add child access functions, Max Reitz, 2020/06/25
- [PATCH v7 03/47] block: bdrv_cow_child() for bdrv_has_zero_init(), Max Reitz, 2020/06/25
- [PATCH v7 02/47] block: Add chain helper functions, Max Reitz, 2020/06/25
- [PATCH v7 04/47] block: bdrv_set_backing_hd() is about bs->backing, Max Reitz, 2020/06/25
- [PATCH v7 05/47] block: Include filters when freezing backing chain, Max Reitz, 2020/06/25
- [PATCH v7 06/47] block: Drop bdrv_is_encrypted(), Max Reitz, 2020/06/25
- [PATCH v7 07/47] block: Add bdrv_supports_compressed_writes(),
Max Reitz <=
- [PATCH v7 08/47] throttle: Support compressed writes, Max Reitz, 2020/06/25
- [PATCH v7 09/47] copy-on-read: Support compressed writes, Max Reitz, 2020/06/25
- [PATCH v7 11/47] backup-top: Support compressed writes, Max Reitz, 2020/06/25
- [PATCH v7 12/47] block: Use bdrv_filter_(bs|child) where obvious, Max Reitz, 2020/06/25
- [PATCH v7 15/47] block: Use CAFs when working with backing chains, Max Reitz, 2020/06/25
- [PATCH v7 10/47] mirror-top: Support compressed writes, Max Reitz, 2020/06/25
- [PATCH v7 13/47] block: Use CAFs in block status functions, Max Reitz, 2020/06/25
- [PATCH v7 14/47] stream: Deal with filters, Max Reitz, 2020/06/25
- [PATCH v7 16/47] block: Use bdrv_cow_child() in bdrv_co_truncate(), Max Reitz, 2020/06/25
- [PATCH v7 18/47] block: Flush all children in generic code, Max Reitz, 2020/06/25