[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 12/39] qcow2: Add offset_to_l1_index()
From: |
Alberto Garcia |
Subject: |
[Qemu-devel] [PATCH v4 12/39] qcow2: Add offset_to_l1_index() |
Date: |
Mon, 5 Feb 2018 16:33:12 +0200 |
Similar to offset_to_l2_index(), this function returns the index in
the L1 table for a given guest offset. This is only used in a couple
of places and it's not a particularly complex calculation, but it
makes the code a bit more readable.
Although in the qcow2_get_cluster_offset() case the old code was
taking advantage of the l1_bits variable, we're going to get rid of
the other uses of l1_bits in a later patch anyway, so it doesn't make
sense to keep it just for this.
Signed-off-by: Alberto Garcia <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block/qcow2-cluster.c | 4 ++--
block/qcow2.h | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 4a7b46038b..6369a74efe 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -541,7 +541,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t
offset,
/* seek to the l2 offset in the l1 table */
- l1_index = offset >> l1_bits;
+ l1_index = offset_to_l1_index(s, offset);
if (l1_index >= s->l1_size) {
type = QCOW2_CLUSTER_UNALLOCATED;
goto out;
@@ -664,7 +664,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t
offset,
/* seek to the l2 offset in the l1 table */
- l1_index = offset >> (s->l2_bits + s->cluster_bits);
+ l1_index = offset_to_l1_index(s, offset);
if (l1_index >= s->l1_size) {
ret = qcow2_grow_l1_table(bs, l1_index + 1, false);
if (ret < 0) {
diff --git a/block/qcow2.h b/block/qcow2.h
index cb8dd784fa..0559afbc63 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -463,6 +463,11 @@ static inline int64_t size_to_l1(BDRVQcow2State *s,
int64_t size)
return (size + (1ULL << shift) - 1) >> shift;
}
+static inline int offset_to_l1_index(BDRVQcow2State *s, uint64_t offset)
+{
+ return offset >> (s->l2_bits + s->cluster_bits);
+}
+
static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset)
{
return (offset >> s->cluster_bits) & (s->l2_size - 1);
--
2.11.0
- [Qemu-devel] [PATCH v4 04/39] qcow2: Remove BDS parameter from qcow2_cache_get_table_idx(), (continued)
- [Qemu-devel] [PATCH v4 04/39] qcow2: Remove BDS parameter from qcow2_cache_get_table_idx(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 06/39] qcow2: Remove BDS parameter from qcow2_cache_entry_mark_dirty(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 08/39] qcow2: Remove BDS parameter from qcow2_cache_destroy(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 35/39] qcow2: Rename l2_table in count_cow_clusters(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 10/39] qcow2: Remove BDS parameter from qcow2_cache_discard(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 07/39] qcow2: Remove BDS parameter from qcow2_cache_put(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 15/39] qcow2: Update l2_load() to support L2 slices, Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 20/39] qcow2: Update qcow2_get_cluster_offset() to support L2 slices, Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 13/39] qcow2: Add l2_slice_size field to BDRVQcow2State, Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 11/39] qcow2: Remove BDS parameter from qcow2_cache_is_table_offset(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 12/39] qcow2: Add offset_to_l1_index(),
Alberto Garcia <=
- [Qemu-devel] [PATCH v4 03/39] qcow2: Remove BDS parameter from qcow2_cache_get_table_addr(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 01/39] qcow2: Fix documentation of get_cluster_table(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 09/39] qcow2: Remove BDS parameter from qcow2_cache_clean_unused(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 02/39] qcow2: Add table size field to Qcow2Cache, Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 37/39] iotests: Test valid values of l2-cache-entry-size, Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 34/39] qcow2: Rename l2_table in count_contiguous_clusters_unallocated(), Alberto Garcia, 2018/02/05
- [Qemu-devel] [PATCH v4 38/39] iotests: Test downgrading an image using a small L2 slice size, Alberto Garcia, 2018/02/05