qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qcow2-refcount: Snapshot update for zero clusters
@ 2013-08-29 10:16 Max Reitz
  2013-08-29 12:30 ` Eric Blake
  2013-08-29 12:33 ` Kevin Wolf
  0 siblings, 2 replies; 9+ messages in thread
From: Max Reitz @ 2013-08-29 10:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz

Do not try to update the refcount for zero clusters in
qcow2_update_snapshot_refcount.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/qcow2-refcount.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 1244693..7555242 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -863,9 +863,13 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
             for(j = 0; j < s->l2_size; j++) {
                 offset = be64_to_cpu(l2_table[j]);
                 if (offset != 0) {
+                    uint64_t cluster_index;
+
                     old_offset = offset;
                     offset &= ~QCOW_OFLAG_COPIED;
-                    if (offset & QCOW_OFLAG_COMPRESSED) {
+
+                    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 +884,10 @@ 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:
+                        cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
                         if (addend != 0) {
                             refcount = update_cluster_refcount(bs, cluster_index, addend,
                                                                QCOW2_DISCARD_SNAPSHOT);
@@ -893,6 +899,10 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
                             ret = refcount;
                             goto fail;
                         }
+                        break;
+
+                    default:
+                        refcount = 0;
                     }
 
                     if (refcount == 1) {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-08-29 13:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-29 10:16 [Qemu-devel] [PATCH] qcow2-refcount: Snapshot update for zero clusters Max Reitz
2013-08-29 12:30 ` Eric Blake
2013-08-29 12:35   ` Max Reitz
2013-08-29 12:33 ` Kevin Wolf
2013-08-29 12:38   ` Max Reitz
2013-08-29 12:53     ` Kevin Wolf
2013-08-29 12:56       ` Max Reitz
2013-08-29 13:04         ` Kevin Wolf
2013-08-29 13:06           ` Max Reitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).