From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCXsi-0001Xn-Ii for qemu-devel@nongnu.org; Tue, 27 Mar 2012 11:00:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCXsY-0007GL-Gk for qemu-devel@nongnu.org; Tue, 27 Mar 2012 11:00:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCXsY-0007FW-8W for qemu-devel@nongnu.org; Tue, 27 Mar 2012 11:00:10 -0400 From: Kevin Wolf Date: Tue, 27 Mar 2012 17:03:25 +0200 Message-Id: <1332860615-3047-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1332860615-3047-1-git-send-email-kwolf@redhat.com> References: <1332860615-3047-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [RFC PATCH 06/16] qcow2: Refactor qcow2_free_any_clusters List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@gmail.com Zero clusters will add another cluster type. Refactor the open-coded cluster type detection into a switch of QCOW2_CLUSTER_* options so that the detection is in a single place. This makes it easier to add new cluster types. Signed-off-by: Kevin Wolf --- block/qcow2-refcount.c | 41 ++++++++++++++++++++++------------------- 1 files changed, 22 insertions(+), 19 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 7c95fe3..2ec3aa7 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -673,31 +673,34 @@ void qcow2_free_clusters(BlockDriverState *bs, } /* - * free_any_clusters - * - * free clusters according to its type: compressed or not - * + * Free a cluster using its L2 entry (handles clusters of all types, e.g. + * normal cluster, compressed cluster, etc.) */ - void qcow2_free_any_clusters(BlockDriverState *bs, - uint64_t cluster_offset, int nb_clusters) + uint64_t l2_entry, int nb_clusters) { BDRVQcowState *s = bs->opaque; - /* free the cluster */ - - if (cluster_offset & QCOW_OFLAG_COMPRESSED) { - int nb_csectors; - nb_csectors = ((cluster_offset >> s->csize_shift) & - s->csize_mask) + 1; - qcow2_free_clusters(bs, - (cluster_offset & s->cluster_offset_mask) & ~511, - nb_csectors * 512); - return; + switch (qcow2_get_cluster_type(l2_entry)) { + case QCOW2_CLUSTER_COMPRESSED: + { + int nb_csectors; + nb_csectors = ((l2_entry >> s->csize_shift) & + s->csize_mask) + 1; + qcow2_free_clusters(bs, + (l2_entry & s->cluster_offset_mask) & ~511, + nb_csectors * 512); + } + break; + case QCOW2_CLUSTER_NORMAL: + qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK, + nb_clusters << s->cluster_bits); + break; + case QCOW2_CLUSTER_UNALLOCATED: + break; + default: + abort(); } - - qcow2_free_clusters(bs, cluster_offset & L2E_OFFSET_MASK, - nb_clusters << s->cluster_bits); } -- 1.7.6.5