@@ -683,7 +683,8 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
old_cluster[j++] = l2_table[l2_index + i];
l2_table[l2_index + i] = cpu_to_be64((cluster_offset +
- (i << s->cluster_bits)) | QCOW_OFLAG_COPIED);
+ (i << s->cluster_bits)) |
+ (m->oflag_copied ? QCOW_OFLAG_COPIED : 0));
}
@@ -696,7 +697,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
* If this was a COW, we need to decrease the refcount of the old cluster.
* Also flush bs->file to get the right order for L2 and refcount update.
*/
- if (j != 0) {
+ if (!m->overwrite && j != 0) {
for (i = 0; i < j; i++) {
qcow2_free_any_clusters(bs, be64_to_cpu(old_cluster[i]), 1);
}
@@ -922,6 +923,8 @@ again:
*m = (QCowL2Meta) {
.cluster_offset = cluster_offset,
.nb_clusters = 0,
+ .oflag_copied = true,
+ .overwrite = false,
};
qemu_co_queue_init(&m->dependent_requests);
@@ -970,6 +973,8 @@ again:
.n_start = keep_clusters == 0 ? n_start : 0,
.nb_clusters = nb_clusters,
.nb_available = MIN(requested_sectors, avail_sectors),
+ .oflag_copied = true,
+ .overwrite = false,
};
qemu_co_queue_init(&m->dependent_requests);
QLIST_INSERT_HEAD(&s->cluster_allocs, m, next_in_flight);
@@ -776,6 +776,8 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs,
uint8_t *cluster_data = NULL;
QCowL2Meta l2meta = {
.nb_clusters = 0,
+ .oflag_copied = true,
+ .overwrite = false,
};
trace_qcow2_writev_start_req(qemu_coroutine_self(), sector_num,
@@ -231,6 +231,8 @@ typedef struct QCowL2Meta
int n_start;
int nb_available;
int nb_clusters;
+ bool oflag_copied;
+ bool overwrite;
CoQueue dependent_requests;
QLIST_ENTRY(QCowL2Meta) next_in_flight;
Signed-off-by: Benoit Canet <benoit@irqsave.net> --- block/qcow2-cluster.c | 9 +++++++-- block/qcow2.c | 2 ++ block/qcow2.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-)