[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/20] qcow2: Factor out count_cow_clusters
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 14/20] qcow2: Factor out count_cow_clusters |
Date: |
Mon, 12 Mar 2012 16:19:45 +0100 |
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
block/qcow2-cluster.c | 55 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index a791bbe..903454d 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -677,6 +677,41 @@ err:
}
/*
+ * Returns the number of contiguous clusters that can be used for an allocating
+ * write, but require COW to be performed (this includes yet unallocated space,
+ * which must copy from the backing file)
+ */
+static int count_cow_clusters(BDRVQcowState *s, int nb_clusters,
+ uint64_t *l2_table, int l2_index)
+{
+ int i = 0;
+ uint64_t cluster_offset;
+
+ while (i < nb_clusters) {
+ i += count_contiguous_clusters(nb_clusters - i, s->cluster_size,
+ &l2_table[l2_index], i, 0);
+ if ((i >= nb_clusters) || be64_to_cpu(l2_table[l2_index + i])) {
+ break;
+ }
+
+ i += count_contiguous_free_clusters(nb_clusters - i,
+ &l2_table[l2_index + i]);
+ if (i >= nb_clusters) {
+ break;
+ }
+
+ cluster_offset = be64_to_cpu(l2_table[l2_index + i]);
+
+ if ((cluster_offset & QCOW_OFLAG_COPIED) ||
+ (cluster_offset & QCOW_OFLAG_COMPRESSED))
+ break;
+ }
+
+ assert(i <= nb_clusters);
+ return i;
+}
+
+/*
* alloc_cluster_offset
*
* For a given offset of the disk image, return cluster offset in qcow2 file.
@@ -739,25 +774,7 @@ again:
/* how many available clusters ? */
- while (i < nb_clusters) {
- i += count_contiguous_clusters(nb_clusters - i, s->cluster_size,
- &l2_table[l2_index], i, 0);
- if ((i >= nb_clusters) || be64_to_cpu(l2_table[l2_index + i])) {
- break;
- }
-
- i += count_contiguous_free_clusters(nb_clusters - i,
- &l2_table[l2_index + i]);
- if (i >= nb_clusters) {
- break;
- }
-
- cluster_offset = be64_to_cpu(l2_table[l2_index + i]);
-
- if ((cluster_offset & QCOW_OFLAG_COPIED) ||
- (cluster_offset & QCOW_OFLAG_COMPRESSED))
- break;
- }
+ i = count_cow_clusters(s, nb_clusters, l2_table, l2_index);
assert(i <= nb_clusters);
nb_clusters = i;
--
1.7.6.5
- [Qemu-devel] [PATCH 02/20] qed: do not evict in-use L2 table cache entries, (continued)
- [Qemu-devel] [PATCH 02/20] qed: do not evict in-use L2 table cache entries, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 01/20] Group snapshot: Fix format name for backing file, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 16/20] qcow2: Reduce number of I/O requests, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 03/20] qcow2: Add some tracing, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 17/20] coroutine: adding sigaltstack method (.c source), Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 18/20] coroutine: adding configure choose mechanism for coroutine backend, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 10/20] qapi: complete implementation of unions, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 04/20] block: handle -EBUSY in bdrv_commit_all(), Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 20/20] test-coroutine: add performance test for nesting, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 07/20] make check: Add qemu-iotests subset, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 14/20] qcow2: Factor out count_cow_clusters,
Kevin Wolf <=
- [Qemu-devel] [PATCH 09/20] use QSIMPLEQ_FOREACH_SAFE when freeing list elements, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 12/20] add mode field to blockdev-snapshot-sync transaction item, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 19/20] coroutine: adding configure option for sigaltstack coroutine backend, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 13/20] qmp: convert blockdev-snapshot-sync to a wrapper around transactions, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 11/20] rename blockdev-group-snapshot-sync, Kevin Wolf, 2012/03/12
- [Qemu-devel] [PATCH 15/20] qcow2: Add qcow2_alloc_clusters_at(), Kevin Wolf, 2012/03/12
- Re: [Qemu-devel] [PULL 00/20] Block patches, Anthony Liguori, 2012/03/12