[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 10/15] qcow2: handle_prealloc(): find out if area
From: |
Anton Nefedov |
Subject: |
[Qemu-devel] [PATCH v2 10/15] qcow2: handle_prealloc(): find out if area zeroed by earlier preallocation |
Date: |
Thu, 1 Jun 2017 18:14:28 +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 c39e825..ed65961 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 809102a..92d0af6 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1686,7 +1686,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 v2 01/15] block: introduce BDRV_REQ_ALLOCATE flag, (continued)
- [Qemu-devel] [PATCH v2 04/15] qcow2: alloc space for COW in one chunk, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 05/15] qcow2: do not COW the empty areas, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 03/15] blkdebug: support BDRV_REQ_ALLOCATE, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 07/15] qcow2: set inactive flag, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 10/15] qcow2: handle_prealloc(): find out if area zeroed by earlier preallocation,
Anton Nefedov <=
- [Qemu-devel] [PATCH v2 06/15] qcow2: preallocation at image expand, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 08/15] qcow2: truncate preallocated space, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 09/15] qcow2: check space leak at the end of the image, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 11/15] qcow2: fix misleading comment about L2 linking, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 12/15] qcow2-cluster: slightly refactor handle_dependencies(), Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 13/15] qcow2-cluster: make handle_dependencies() logic easier to follow, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 15/15] iotest 046: test simultaneous cluster write error case, Anton Nefedov, 2017/06/01
- [Qemu-devel] [PATCH v2 14/15] qcow2: allow concurrent unaligned writes to the same clusters, Anton Nefedov, 2017/06/01
- Re: [Qemu-devel] [PATCH v2 00/15] qcow2: space preallocation and COW improvements, John Snow, 2017/06/01