[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 28/55] qcow2: Add offset_to_l1_index()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 28/55] qcow2: Add offset_to_l1_index() |
Date: |
Tue, 13 Feb 2018 18:05:02 +0100 |
From: Alberto Garcia <address@hidden>
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>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2.h | 5 +++++
block/qcow2-cluster.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/block/qcow2.h b/block/qcow2.h
index edc5d8d57d..d9ba57c030 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);
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index ab5715c97e..ce7591dc3d 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -540,7 +540,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;
@@ -663,7 +663,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) {
--
2.13.6
- [Qemu-devel] [PULL 21/55] qcow2: Remove BDS parameter from qcow2_cache_table_release(), (continued)
- [Qemu-devel] [PULL 21/55] qcow2: Remove BDS parameter from qcow2_cache_table_release(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 12/55] gluster: Add preallocated truncation, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 18/55] qcow2: Add table size field to Qcow2Cache, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 19/55] qcow2: Remove BDS parameter from qcow2_cache_get_table_addr(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 23/55] qcow2: Remove BDS parameter from qcow2_cache_put(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 31/55] qcow2: Update l2_load() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 16/55] block: maintain persistent disabled bitmaps, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 30/55] qcow2: Add offset_to_l2_slice_index(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 34/55] qcow2: Refactor get_cluster_table(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 25/55] qcow2: Remove BDS parameter from qcow2_cache_clean_unused(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 28/55] qcow2: Add offset_to_l1_index(),
Kevin Wolf <=
- [Qemu-devel] [PULL 26/55] qcow2: Remove BDS parameter from qcow2_cache_discard(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 37/55] qcow2: Update qcow2_alloc_cluster_link_l2() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 29/55] qcow2: Add l2_slice_size field to BDRVQcow2State, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 27/55] qcow2: Remove BDS parameter from qcow2_cache_is_table_offset(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 24/55] qcow2: Remove BDS parameter from qcow2_cache_destroy(), Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 32/55] qcow2: Prepare l2_allocate() for adding L2 slice support, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 41/55] qcow2: Update zero_single_l2() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 35/55] qcow2: Update get_cluster_table() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 33/55] qcow2: Update l2_allocate() to support L2 slices, Kevin Wolf, 2018/02/13
- [Qemu-devel] [PULL 40/55] qcow2: Update discard_single_l2() to support L2 slices, Kevin Wolf, 2018/02/13