@@ -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,
@@ -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));
@@ -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.