[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/7] qcow2: zero_l2_subclusters: fall through to discard operatio
From: |
Andrey Drobyshev |
Subject: |
[PATCH 5/7] qcow2: zero_l2_subclusters: fall through to discard operation when requested |
Date: |
Sat, 21 Oct 2023 00:56:20 +0300 |
When zeroizing subclusters within single cluster, detect usage of the
BDRV_REQ_MAY_UNMAP flag and fall through to the subcluster-based discard
operation, much like it's done with the cluster-based discards. That
way subcluster-aligned operations "qemu-io -c 'write -z -u ...'" will
lead to actual unmap.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
block/qcow2-cluster.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index cf40f2dc12..040251f2c3 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -2242,7 +2242,7 @@ zero_l2_subclusters(BlockDriverState *bs, uint64_t offset,
unsigned nb_subclusters, int flags)
{
BDRVQcow2State *s = bs->opaque;
- uint64_t new_l2_bitmap;
+ uint64_t new_l2_bitmap, l2_bitmap_mask;
int ret, sc = offset_to_sc_index(s, offset);
SubClusterRangeInfo scri = { 0 };
@@ -2251,9 +2251,10 @@ zero_l2_subclusters(BlockDriverState *bs, uint64_t
offset,
goto out;
}
+ l2_bitmap_mask = QCOW_OFLAG_SUB_ALLOC_RANGE(sc, sc + nb_subclusters);
new_l2_bitmap = scri.l2_bitmap;
- new_l2_bitmap |= QCOW_OFLAG_SUB_ZERO_RANGE(sc, sc + nb_subclusters);
- new_l2_bitmap &= ~QCOW_OFLAG_SUB_ALLOC_RANGE(sc, sc + nb_subclusters);
+ new_l2_bitmap |= QCOW_OFLAG_SUB_ZERO_RANGE(sc, sc + nb_subclusters);
+ new_l2_bitmap &= ~l2_bitmap_mask;
/*
* If there're no non-zero subclusters left, we might as well zeroize
@@ -2266,6 +2267,16 @@ zero_l2_subclusters(BlockDriverState *bs, uint64_t
offset,
1, flags);
}
+ /*
+ * If the request allows discarding subclusters and they're actually
+ * allocated, we go down the discard path since after the discard
+ * operation the subclusters are going to be read as zeroes anyway.
+ */
+ if ((flags & BDRV_REQ_MAY_UNMAP) && (scri.l2_bitmap & l2_bitmap_mask)) {
+ return discard_l2_subclusters(bs, offset, nb_subclusters,
+ QCOW2_DISCARD_REQUEST, false, &scri);
+ }
+
if (new_l2_bitmap != scri.l2_bitmap) {
set_l2_bitmap(s, scri.l2_slice, scri.l2_index, new_l2_bitmap);
qcow2_cache_entry_mark_dirty(s->l2_table_cache, scri.l2_slice);
--
2.39.3
- [PATCH 0/7] qcow2: make subclusters discardable, Andrey Drobyshev, 2023/10/20
- [PATCH 3/7] qcow2: zeroize the entire cluster when there're no non-zero subclusters, Andrey Drobyshev, 2023/10/20
- [PATCH 5/7] qcow2: zero_l2_subclusters: fall through to discard operation when requested,
Andrey Drobyshev <=
- [PATCH 7/7] iotests/271: check disk usage on subcluster-based discard/unmap, Andrey Drobyshev, 2023/10/20
- [PATCH 2/7] qcow2: add get_sc_range_info() helper for working with subcluster ranges, Andrey Drobyshev, 2023/10/20
- [PATCH 6/7] iotests/common.rc: add disk_usage function, Andrey Drobyshev, 2023/10/20
- [PATCH 4/7] qcow2: make subclusters discardable, Andrey Drobyshev, 2023/10/20
- [PATCH 1/7] qcow2: make function update_refcount_discard() global, Andrey Drobyshev, 2023/10/20