aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2-refcount.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2012-03-27 13:09:22 +0200
committerKevin Wolf <kwolf@redhat.com>2012-04-20 15:57:28 +0200
commitc7a4c37a0f768f7ad50f64414d578436019e1e96 (patch)
tree01150a854eab361135a3db2aa78cfb318cedecb9 /block/qcow2-refcount.c
parent8e37f681d58bbe166c20559e77fd55b1cb8e6e4b (diff)
downloadqemu-c7a4c37a0f768f7ad50f64414d578436019e1e96.zip
qemu-c7a4c37a0f768f7ad50f64414d578436019e1e96.tar.gz
qemu-c7a4c37a0f768f7ad50f64414d578436019e1e96.tar.bz2
qcow2: Refactor qcow2_free_any_clusters
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 <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2-refcount.c')
-rw-r--r--block/qcow2-refcount.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 84fa343..909d615 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -679,31 +679,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);
}