[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 17/26] qcow2-refcount: Snapshot update for zero clust
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 17/26] qcow2-refcount: Snapshot update for zero clusters |
Date: |
Fri, 30 Aug 2013 16:30:42 +0200 |
From: Max Reitz <address@hidden>
Account for all cluster types in qcow2_update_snapshot_refcounts;
this prevents this function from updating the refcount of unallocated
zero clusters which effectively led to wrong adjustments of the refcount
of cluster 0 (the main qcow2 header). This in turn resulted in images
with (unallocated) zero clusters having a cluster 0 refcount greater
than one after creating a snapshot.
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-refcount.c | 52 +++++++++++++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 1244693..a61224a 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -861,11 +861,14 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
}
for(j = 0; j < s->l2_size; j++) {
+ uint64_t cluster_index;
+
offset = be64_to_cpu(l2_table[j]);
- if (offset != 0) {
- old_offset = offset;
- offset &= ~QCOW_OFLAG_COPIED;
- if (offset & QCOW_OFLAG_COMPRESSED) {
+ old_offset = offset;
+ offset &= ~QCOW_OFLAG_COPIED;
+
+ switch (qcow2_get_cluster_type(offset)) {
+ case QCOW2_CLUSTER_COMPRESSED:
nb_csectors = ((offset >> s->csize_shift) &
s->csize_mask) + 1;
if (addend != 0) {
@@ -880,8 +883,16 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
}
/* compressed clusters are never modified */
refcount = 2;
- } else {
- uint64_t cluster_index = (offset & L2E_OFFSET_MASK) >>
s->cluster_bits;
+ break;
+
+ case QCOW2_CLUSTER_NORMAL:
+ case QCOW2_CLUSTER_ZERO:
+ cluster_index = (offset & L2E_OFFSET_MASK) >>
s->cluster_bits;
+ if (!cluster_index) {
+ /* unallocated */
+ refcount = 0;
+ break;
+ }
if (addend != 0) {
refcount = update_cluster_refcount(bs,
cluster_index, addend,
QCOW2_DISCARD_SNAPSHOT);
@@ -893,19 +904,26 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
ret = refcount;
goto fail;
}
- }
+ break;
- if (refcount == 1) {
- offset |= QCOW_OFLAG_COPIED;
- }
- if (offset != old_offset) {
- if (addend > 0) {
- qcow2_cache_set_dependency(bs, s->l2_table_cache,
- s->refcount_block_cache);
- }
- l2_table[j] = cpu_to_be64(offset);
- qcow2_cache_entry_mark_dirty(s->l2_table_cache,
l2_table);
+ case QCOW2_CLUSTER_UNALLOCATED:
+ refcount = 0;
+ break;
+
+ default:
+ abort();
+ }
+
+ if (refcount == 1) {
+ offset |= QCOW_OFLAG_COPIED;
+ }
+ if (offset != old_offset) {
+ if (addend > 0) {
+ qcow2_cache_set_dependency(bs, s->l2_table_cache,
+ s->refcount_block_cache);
}
+ l2_table[j] = cpu_to_be64(offset);
+ qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
}
}
--
1.8.1.4
- [Qemu-devel] [PULL 08/26] raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev(), (continued)
- [Qemu-devel] [PULL 08/26] raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev(), Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 09/26] raw_bsd: add raw_create(), Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 10/26] raw_bsd: introduce "special members", Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 11/26] raw_bsd: add raw_create_options, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 12/26] raw_bsd: register bdrv_raw, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 13/26] switch raw block driver from "raw.o" to "raw_bsd.o", Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 14/26] block: Remove old raw driver, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 16/26] option: Add assigned flag to QEMUOptionParameter, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 18/26] qemu-iotests: Snapshotting zero clusters, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 15/26] gluster: Abort on AIO completion failure, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 17/26] qcow2-refcount: Snapshot update for zero clusters,
Kevin Wolf <=
- [Qemu-devel] [PULL 20/26] qcow2: Metadata overlap checks, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 19/26] qcow2: Add corrupt bit, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 22/26] qcow2-refcount: Move OFLAG_COPIED checks, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 21/26] qcow2: Employ metadata overlap checks, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 23/26] qcow2-refcount: Repair OFLAG_COPIED errors, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 24/26] qcow2-refcount: Repair shared refcount blocks, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 25/26] qcow2_check: Mark image consistent, Kevin Wolf, 2013/08/30
- [Qemu-devel] [PULL 26/26] qemu-iotests: Overlapping cluster allocations, Kevin Wolf, 2013/08/30
- Re: [Qemu-devel] [PULL 00/26] Block patches, Anthony Liguori, 2013/08/30