[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 06/16] qcow2: Refactor qcow2_free_any_clusters
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [RFC PATCH 06/16] qcow2: Refactor qcow2_free_any_clusters |
Date: |
Tue, 27 Mar 2012 17:03:25 +0200 |
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 <address@hidden>
---
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
- [Qemu-devel] [RFC PATCH 00/16] qcow2: Basic version 3 support, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 08/16] qcow2: Ignore reserved bits in refcount table entries, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 03/16] qcow2: Ignore reserved bits in count_contiguous_clusters(), Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 05/16] qcow2: Ignore reserved bits in L1/L2 entries, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 12/16] qcow2: Support for feature table header extension, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 01/16] Specification for qcow2 version 3, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 04/16] qcow2: Fail write_compressed when overwriting data, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 06/16] qcow2: Refactor qcow2_free_any_clusters,
Kevin Wolf <=
- [Qemu-devel] [RFC PATCH 09/16] qcow2: Ignore reserved bits in check_refcounts, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 02/16] qcow2: Ignore reserved bits in get_cluster_offset, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 14/16] qemu-iotests: Test COW with zero clusters, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 11/16] qcow2: Support reading zero clusters, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 13/16] qemu-iotests: add a simple test for write_zeroes, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 15/16] qcow2: Zero write support, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 16/16] qemu-iotests: use qcow3, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 10/16] qcow2: Version 3 images, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 07/16] qcow2: Simplify count_cow_clusters, Kevin Wolf, 2012/03/27