[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 08/13] qcow2: handle_prealloc(): find out if area
From: |
Anton Nefedov |
Subject: |
[Qemu-devel] [PATCH v1 08/13] qcow2: handle_prealloc(): find out if area zeroed by earlier preallocation |
Date: |
Fri, 19 May 2017 12:34:35 +0300 |
Signed-off-by: Anton Nefedov <address@hidden>
Signed-off-by: Denis V. Lunev <address@hidden>
---
block/qcow2-cluster.c | 2 ++
block/qcow2.c | 8 +++++++-
block/qcow2.h | 4 ++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index b2879b9..25210cd 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1143,6 +1143,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t
guest_offset,
uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)
{
BDRVQcow2State *s = bs->opaque;
+ const uint64_t old_data_end = s->data_end;
int l2_index;
uint64_t *l2_table;
uint64_t entry;
@@ -1264,6 +1265,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t
guest_offset,
.alloc_offset = alloc_cluster_offset,
.offset = start_of_cluster(s, guest_offset),
.nb_clusters = nb_clusters,
+ .clusters_are_trailing = alloc_cluster_offset >= old_data_end,
.keep_old_clusters = keep_old_clusters,
diff --git a/block/qcow2.c b/block/qcow2.c
index 503f0dc..97a66a0 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1684,7 +1684,13 @@ restart:
if (end <= bdrv_getlength(file)) {
/* No need to care, file size will not be changed */
- return false;
+
+ /* We're safe to assume that the area is zeroes if the area
+ * was allocated at the end of data (s->data_end).
+ * In this case, the only way for file length to be bigger is that
+ * the area was preallocated by another request.
+ */
+ return m->clusters_are_trailing;
}
meta = g_alloca(sizeof(*meta));
diff --git a/block/qcow2.h b/block/qcow2.h
index e28c54a..2fd8510 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -333,6 +333,10 @@ typedef struct QCowL2Meta
/** Do not free the old clusters */
bool keep_old_clusters;
+ /** True if the area is allocated after the end of data area
+ * (i.e. >= s->data_end), which means that it is zeroed */
+ bool clusters_are_trailing;
+
/**
* Requests that overlap with this allocation and wait to be restarted
* when the allocating request has completed.
--
2.7.4
- Re: [Qemu-devel] [PATCH v1 02/13] qcow2: is_zero_sectors(): return true if area is outside of backing file, (continued)
[Qemu-devel] [PATCH v1 03/13] qcow2: do not COW the empty areas, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 05/13] qcow2: set inactive flag, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 04/13] qcow2: preallocation at image expand, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 06/13] qcow2: truncate preallocated space, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 08/13] qcow2: handle_prealloc(): find out if area zeroed by earlier preallocation,
Anton Nefedov <=
[Qemu-devel] [PATCH v1 09/13] qcow2: fix misleading comment about L2 linking, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 07/13] qcow2: check space leak at the end of the image, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 11/13] qcow2-cluster: make handle_dependencies() logic easier to follow, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 13/13] iotest 046: test simultaneous cluster write error case, Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 10/13] qcow2-cluster: slightly refactor handle_dependencies(), Anton Nefedov, 2017/05/19
[Qemu-devel] [PATCH v1 12/13] qcow2: allow concurrent unaligned writes to the same clusters, Anton Nefedov, 2017/05/19
Re: [Qemu-devel] [PATCH v1 00/13] qcow2: space preallocation and COW improvements, Eric Blake, 2017/05/23