[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 06/23] qcow2: handle_alloc(): Get rid of nb_c
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [RFC PATCH v2 06/23] qcow2: handle_alloc(): Get rid of nb_clusters parameter |
Date: |
Wed, 13 Feb 2013 14:21:56 +0100 |
We already communicate the same information in *bytes.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-cluster.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 919cb39..2492235 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -873,17 +873,18 @@ static int do_alloc_cluster_offset(BlockDriverState *bs,
uint64_t guest_offset,
*
* -errno: in error cases
*
- * TODO Get rid of nb_clusters, keep_clusters, n_start, n_end
+ * TODO Get rid of keep_clusters, n_start, n_end
* TODO Make *bytes actually behave as specified above
*/
static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m,
- unsigned int nb_clusters, int keep_clusters, int n_start, int n_end)
+ int keep_clusters, int n_start, int n_end)
{
BDRVQcowState *s = bs->opaque;
int l2_index;
uint64_t *l2_table;
uint64_t entry;
+ unsigned int nb_clusters;
int ret;
uint64_t alloc_offset;
@@ -894,6 +895,13 @@ static int handle_alloc(BlockDriverState *bs, uint64_t
guest_offset,
*bytes);
assert(*bytes > 0);
+ /*
+ * Calculate the number of clusters to look for. We stop at L2 table
+ * boundaries to keep things simple.
+ */
+ l2_index = offset_to_l2_index(s, guest_offset);
+ nb_clusters = MIN(size_to_clusters(s, *bytes), s->l2_size - l2_index);
+
/* Find L2 entry for the first involved cluster */
ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index);
if (ret < 0) {
@@ -1100,6 +1108,7 @@ again:
}
cluster_offset &= L2E_OFFSET_MASK;
+ *host_offset = cluster_offset;
/*
* The L2 table isn't used any more after this. As long as the cache works
@@ -1120,11 +1129,14 @@ again:
cur_bytes = nb_clusters * s->cluster_size;
ret = handle_alloc(bs, offset, &cluster_offset, &cur_bytes, m,
- nb_clusters, keep_clusters, n_start, n_end);
+ keep_clusters, n_start, n_end);
if (ret < 0) {
return ret;
}
+ if (!*host_offset) {
+ *host_offset = cluster_offset;
+ }
nb_clusters = size_to_clusters(s, cur_bytes);
/* Some cleanup work */
@@ -1136,7 +1148,6 @@ done:
assert(sectors > n_start);
*num = sectors - n_start;
- *host_offset = cluster_offset;
return 0;
}
--
1.7.6.5
- Re: [Qemu-devel] [RFC PATCH v2 03/23] qcow2: Change handle_dependency to byte granularity, (continued)
- [Qemu-devel] [RFC PATCH v2 05/23] qcow2: Factor out handle_alloc(), Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 04/23] qcow2: Decouple cluster allocation from cluster reuse code, Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 09/23] qcow2: Clean up handle_alloc(), Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 08/23] qcow2: Finalise interface of handle_alloc(), Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 07/23] qcow2: handle_alloc(): Get rid of keep_clusters parameter, Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 12/23] qcow2: handle_copied(): Get rid of keep_clusters parameter, Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 11/23] qcow2: handle_copied(): Get rid of nb_clusters parameter, Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 06/23] qcow2: handle_alloc(): Get rid of nb_clusters parameter,
Kevin Wolf <=
- [Qemu-devel] [RFC PATCH v2 15/23] qcow2: Allow requests with multiple l2metas, Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 10/23] qcow2: Factor out handle_copied(), Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 13/23] qcow2: handle_copied(): Implement non-zero host_offset, Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 16/23] qcow2: Reading from areas not in L2 tables yet, Kevin Wolf, 2013/02/13
- [Qemu-devel] [RFC PATCH v2 18/23] qcow2: Delay the COW, Kevin Wolf, 2013/02/13