[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 36/55] qcow2: Update qcow2_get_cluster_offset() to su
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 36/55] qcow2: Update qcow2_get_cluster_offset() to support L2 slices |
Date: |
Tue, 13 Feb 2018 18:05:10 +0100 |
From: Alberto Garcia <address@hidden>
qcow2_get_cluster_offset() checks how many contiguous bytes are
available at a given offset. The returned number of bytes is limited
by the amount that can be addressed without having to load more than
one L2 table.
Since we'll be loading L2 slices instead of full tables this patch
changes the limit accordingly using the size of the L2 slice for the
calculations instead of the full table size.
One consequence of this is that with small L2 slices operations such
as 'qemu-img map' will need to iterate in more steps because each
qcow2_get_cluster_offset() call will potentially return a smaller
number. However the code is already prepared for that so this doesn't
break semantics.
The l2_table variable is also renamed to l2_slice to reflect this, and
offset_to_l2_index() is replaced with offset_to_l2_slice_index().
Signed-off-by: Alberto Garcia <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2-cluster.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index cd1ba40f74..e0eea73297 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -529,8 +529,8 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t
offset,
{
BDRVQcow2State *s = bs->opaque;
unsigned int l2_index;
- uint64_t l1_index, l2_offset, *l2_table;
- int l1_bits, c;
+ uint64_t l1_index, l2_offset, *l2_slice;
+ int c;
unsigned int offset_in_cluster;
uint64_t bytes_available, bytes_needed, nb_clusters;
QCow2ClusterType type;
@@ -539,12 +539,12 @@ int qcow2_get_cluster_offset(BlockDriverState *bs,
uint64_t offset,
offset_in_cluster = offset_into_cluster(s, offset);
bytes_needed = (uint64_t) *bytes + offset_in_cluster;
- l1_bits = s->l2_bits + s->cluster_bits;
-
/* compute how many bytes there are between the start of the cluster
- * containing offset and the end of the l1 entry */
- bytes_available = (1ULL << l1_bits) - (offset & ((1ULL << l1_bits) - 1))
- + offset_in_cluster;
+ * containing offset and the end of the l2 slice that contains
+ * the entry pointing to it */
+ bytes_available =
+ ((uint64_t) (s->l2_slice_size - offset_to_l2_slice_index(s, offset)))
+ << s->cluster_bits;
if (bytes_needed > bytes_available) {
bytes_needed = bytes_available;
@@ -573,17 +573,17 @@ int qcow2_get_cluster_offset(BlockDriverState *bs,
uint64_t offset,
return -EIO;
}
- /* load the l2 table in memory */
+ /* load the l2 slice in memory */
- ret = l2_load(bs, offset, l2_offset, &l2_table);
+ ret = l2_load(bs, offset, l2_offset, &l2_slice);
if (ret < 0) {
return ret;
}
/* find the cluster offset for the given disk offset */
- l2_index = offset_to_l2_index(s, offset);
- *cluster_offset = be64_to_cpu(l2_table[l2_index]);
+ l2_index = offset_to_l2_slice_index(s, offset);
+ *cluster_offset = be64_to_cpu(l2_slice[l2_index]);
nb_clusters = size_to_clusters(s, bytes_needed);
/* bytes_needed <= *bytes + offset_in_cluster, both of which are unsigned
@@ -610,14 +610,14 @@ int qcow2_get_cluster_offset(BlockDriverState *bs,
uint64_t offset,
case QCOW2_CLUSTER_UNALLOCATED:
/* how many empty clusters ? */
c = count_contiguous_clusters_unallocated(nb_clusters,
- &l2_table[l2_index], type);
+ &l2_slice[l2_index], type);
*cluster_offset = 0;
break;
case QCOW2_CLUSTER_ZERO_ALLOC:
case QCOW2_CLUSTER_NORMAL:
/* how many allocated clusters ? */
c = count_contiguous_clusters(nb_clusters, s->cluster_size,
- &l2_table[l2_index], QCOW_OFLAG_ZERO);
+ &l2_slice[l2_index], QCOW_OFLAG_ZERO);
*cluster_offset &= L2E_OFFSET_MASK;
if (offset_into_cluster(s, *cluster_offset)) {
qcow2_signal_corruption(bs, true, -1, -1,
@@ -633,7 +633,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t
offset,
abort();
}
- qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
+ qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice);
bytes_available = (int64_t)c * s->cluster_size;
@@ -651,7 +651,7 @@ out:
return type;
fail:
- qcow2_cache_put(s->l2_table_cache, (void **)&l2_table);
+ qcow2_cache_put(s->l2_table_cache, (void **)&l2_slice);
return ret;
}
--
2.13.6
- [Qemu-block] [PULL 38/55] qcow2: Update handle_copied() to support L2 slices, (continued)
- [Qemu-block] [PULL 38/55] qcow2: Update handle_copied() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 30/55] qcow2: Add offset_to_l2_slice_index(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 27/55] qcow2: Remove BDS parameter from qcow2_cache_is_table_offset(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 31/55] qcow2: Update l2_load() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 32/55] qcow2: Prepare l2_allocate() for adding L2 slice support, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 34/55] qcow2: Refactor get_cluster_table(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 44/55] qcow2: Read refcount before L2 table in expand_zero_clusters_in_l1(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 41/55] qcow2: Update zero_single_l2() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 39/55] qcow2: Update handle_alloc() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 42/55] qcow2: Prepare qcow2_update_snapshot_refcount() for adding L2 slice support, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 36/55] qcow2: Update qcow2_get_cluster_offset() to support L2 slices,
Kevin Wolf <=
- [Qemu-block] [PULL 40/55] qcow2: Update discard_single_l2() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 43/55] qcow2: Update qcow2_update_snapshot_refcount() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 45/55] qcow2: Prepare expand_zero_clusters_in_l1() for adding L2 slice support, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 47/55] qcow2: Update qcow2_truncate() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 46/55] qcow2: Update expand_zero_clusters_in_l1() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 49/55] qcow2: Rename l2_table in count_contiguous_clusters(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 50/55] qcow2: Rename l2_table in count_contiguous_clusters_unallocated(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 51/55] qcow2: Rename l2_table in count_cow_clusters(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 48/55] qcow2: Rename l2_table in qcow2_alloc_compressed_cluster_offset(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 55/55] iotests: Add l2-cache-entry-size to iotest 137, Kevin Wolf, 2018/02/13