[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 27/34] qcow2: Add subcluster support to handle_alloc_space()
From: |
Max Reitz |
Subject: |
[PULL 27/34] qcow2: Add subcluster support to handle_alloc_space() |
Date: |
Tue, 25 Aug 2020 10:33:04 +0200 |
From: Alberto Garcia <berto@igalia.com>
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>
Message-Id:
<b3dc97e8e2240ddb5191a4f930e8fc9653f94621.1594396418.git.berto@igalia.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/qcow2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 60192f1be3..9990535c46 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2421,6 +2421,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;
@@ -2435,16 +2438,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.26.2
- [PULL 08/34] qcow2: Add dummy has_subclusters() function, (continued)
- [PULL 08/34] qcow2: Add dummy has_subclusters() function, Max Reitz, 2020/08/25
- [PULL 15/34] qcow2: Add qcow2_get_subcluster_range_type(), Max Reitz, 2020/08/25
- [PULL 14/34] qcow2: Add QCow2SubclusterType and qcow2_get_subcluster_type(), Max Reitz, 2020/08/25
- [PULL 16/34] qcow2: Add qcow2_cluster_is_allocated(), Max Reitz, 2020/08/25
- [PULL 18/34] qcow2: Replace QCOW2_CLUSTER_* with QCOW2_SUBCLUSTER_*, Max Reitz, 2020/08/25
- [PULL 19/34] qcow2: Handle QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC, Max Reitz, 2020/08/25
- [PULL 22/34] qcow2: Add subcluster support to zero_in_l2_slice(), Max Reitz, 2020/08/25
- [PULL 21/34] qcow2: Add subcluster support to qcow2_get_host_offset(), Max Reitz, 2020/08/25
- [PULL 23/34] qcow2: Add subcluster support to discard_in_l2_slice(), Max Reitz, 2020/08/25
- [PULL 20/34] qcow2: Add subcluster support to calculate_l2_meta(), Max Reitz, 2020/08/25
- [PULL 27/34] qcow2: Add subcluster support to handle_alloc_space(),
Max Reitz <=
- [PULL 25/34] qcow2: Update L2 bitmap in qcow2_alloc_cluster_link_l2(), Max Reitz, 2020/08/25
- [PULL 24/34] qcow2: Add subcluster support to check_refcounts_l2(), Max Reitz, 2020/08/25
- [PULL 28/34] qcow2: Add subcluster support to qcow2_co_pwrite_zeroes(), Max Reitz, 2020/08/25
- [PULL 29/34] qcow2: Add subcluster support to qcow2_measure(), Max Reitz, 2020/08/25
- [PULL 30/34] qcow2: Add prealloc field to QCowL2Meta, Max Reitz, 2020/08/25
- [PULL 32/34] qcow2: Allow preallocation and backing files if extended_l2 is set, Max Reitz, 2020/08/25
- [PULL 31/34] qcow2: Add the 'extended_l2' option and the QCOW2_INCOMPAT_EXTL2 bit, Max Reitz, 2020/08/25
- [PULL 33/34] qcow2: Assert that expand_zero_clusters_in_l1() does not support subclusters, Max Reitz, 2020/08/25
- [PULL 17/34] qcow2: Add cluster type parameter to qcow2_get_host_offset(), Max Reitz, 2020/08/25
- [PULL 34/34] iotests: Add tests for qcow2 images with extended L2 entries, Max Reitz, 2020/08/25