From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEzH4-0005Dq-Jy for qemu-devel@nongnu.org; Thu, 29 Aug 2013 06:16:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VEzGy-0007o3-L2 for qemu-devel@nongnu.org; Thu, 29 Aug 2013 06:16:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEzGy-0007nu-CT for qemu-devel@nongnu.org; Thu, 29 Aug 2013 06:16:16 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7TAGFJY015265 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Aug 2013 06:16:15 -0400 From: Max Reitz Date: Thu, 29 Aug 2013 12:16:03 +0200 Message-Id: <1377771363-5198-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH] qcow2-refcount: Snapshot update for zero clusters List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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