[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v9 27/34] qcow2: Add subcluster support to handle_alloc_space()
From: |
Alberto Garcia |
Subject: |
[PATCH v9 27/34] qcow2: Add subcluster support to handle_alloc_space() |
Date: |
Sun, 28 Jun 2020 13:02:36 +0200 |
The bdrv_co_pwrite_zeroes() call here fills complete clusters with
zeroes, but it can happen that some subclusters are not part of the
write request or the copy-on-write. This patch makes sure that only
the affected subclusters are overwritten.
A potential improvement would be to also fill with zeroes the other
subclusters if we can guarantee that we are not overwriting existing
data. However this would waste more disk space, so we should first
evaluate if it's really worth doing.
Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/qcow2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index a3481cd85b..86258fbc22 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2411,6 +2411,9 @@ static int handle_alloc_space(BlockDriverState *bs,
QCowL2Meta *l2meta)
for (m = l2meta; m != NULL; m = m->next) {
int ret;
+ uint64_t start_offset = m->alloc_offset + m->cow_start.offset;
+ unsigned nb_bytes = m->cow_end.offset + m->cow_end.nb_bytes -
+ m->cow_start.offset;
if (!m->cow_start.nb_bytes && !m->cow_end.nb_bytes) {
continue;
@@ -2425,16 +2428,14 @@ static int handle_alloc_space(BlockDriverState *bs,
QCowL2Meta *l2meta)
* efficiently zero out the whole clusters
*/
- ret = qcow2_pre_write_overlap_check(bs, 0, m->alloc_offset,
- m->nb_clusters * s->cluster_size,
+ ret = qcow2_pre_write_overlap_check(bs, 0, start_offset, nb_bytes,
true);
if (ret < 0) {
return ret;
}
BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE);
- ret = bdrv_co_pwrite_zeroes(s->data_file, m->alloc_offset,
- m->nb_clusters * s->cluster_size,
+ ret = bdrv_co_pwrite_zeroes(s->data_file, start_offset, nb_bytes,
BDRV_REQ_NO_FALLBACK);
if (ret < 0) {
if (ret != -ENOTSUP && ret != -EAGAIN) {
--
2.20.1
- [PATCH v9 16/34] qcow2: Add qcow2_cluster_is_allocated(), (continued)
- [PATCH v9 16/34] qcow2: Add qcow2_cluster_is_allocated(), Alberto Garcia, 2020/06/28
- [PATCH v9 11/34] qcow2: Add offset_into_subcluster() and size_to_subclusters(), Alberto Garcia, 2020/06/28
- [PATCH v9 29/34] qcow2: Add subcluster support to qcow2_measure(), Alberto Garcia, 2020/06/28
- [PATCH v9 22/34] qcow2: Add subcluster support to zero_in_l2_slice(), Alberto Garcia, 2020/06/28
- [PATCH v9 25/34] qcow2: Update L2 bitmap in qcow2_alloc_cluster_link_l2(), Alberto Garcia, 2020/06/28
- [PATCH v9 01/34] qcow2: Make Qcow2AioTask store the full host offset, Alberto Garcia, 2020/06/28
- [PATCH v9 33/34] qcow2: Assert that expand_zero_clusters_in_l1() does not support subclusters, Alberto Garcia, 2020/06/28
- [PATCH v9 15/34] qcow2: Add qcow2_get_subcluster_range_type(), Alberto Garcia, 2020/06/28
- [PATCH v9 23/34] qcow2: Add subcluster support to discard_in_l2_slice(), Alberto Garcia, 2020/06/28
- [PATCH v9 20/34] qcow2: Add subcluster support to calculate_l2_meta(), Alberto Garcia, 2020/06/28
- [PATCH v9 27/34] qcow2: Add subcluster support to handle_alloc_space(),
Alberto Garcia <=
- [PATCH v9 30/34] qcow2: Add prealloc field to QCowL2Meta, Alberto Garcia, 2020/06/28
- [PATCH v9 32/34] qcow2: Allow preallocation and backing files if extended_l2 is set, Alberto Garcia, 2020/06/28
- [PATCH v9 18/34] qcow2: Replace QCOW2_CLUSTER_* with QCOW2_SUBCLUSTER_*, Alberto Garcia, 2020/06/28
- [PATCH v9 14/34] qcow2: Add QCow2SubclusterType and qcow2_get_subcluster_type(), Alberto Garcia, 2020/06/28
- [PATCH v9 12/34] qcow2: Add l2_entry_size(), Alberto Garcia, 2020/06/28
- [PATCH v9 17/34] qcow2: Add cluster type parameter to qcow2_get_host_offset(), Alberto Garcia, 2020/06/28
- [PATCH v9 28/34] qcow2: Add subcluster support to qcow2_co_pwrite_zeroes(), Alberto Garcia, 2020/06/28
- [PATCH v9 21/34] qcow2: Add subcluster support to qcow2_get_host_offset(), Alberto Garcia, 2020/06/28
- [PATCH v9 34/34] iotests: Add tests for qcow2 images with extended L2 entries, Alberto Garcia, 2020/06/28
- [PATCH v9 31/34] qcow2: Add the 'extended_l2' option and the QCOW2_INCOMPAT_EXTL2 bit, Alberto Garcia, 2020/06/28