[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v9 13/34] qcow2: Update get/set_l2_entry() and add get/set_l2_bit
From: |
Alberto Garcia |
Subject: |
[PATCH v9 13/34] qcow2: Update get/set_l2_entry() and add get/set_l2_bitmap() |
Date: |
Sun, 28 Jun 2020 13:02:22 +0200 |
Extended L2 entries are 128-bit wide: 64 bits for the entry itself and
64 bits for the subcluster allocation bitmap.
In order to support them correctly get/set_l2_entry() need to be
updated so they take the entry width into account in order to
calculate the correct offset.
This patch also adds the get/set_l2_bitmap() functions that are
used to access the bitmaps. For convenience we allow calling
get_l2_bitmap() on images without subclusters. In this case the
returned value is always 0 and has no meaning.
Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
block/qcow2.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/block/qcow2.h b/block/qcow2.h
index 46b351229a..82b86f6cec 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -533,15 +533,36 @@ static inline size_t l2_entry_size(BDRVQcow2State *s)
static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice,
int idx)
{
+ idx *= l2_entry_size(s) / sizeof(uint64_t);
return be64_to_cpu(l2_slice[idx]);
}
+static inline uint64_t get_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice,
+ int idx)
+{
+ if (has_subclusters(s)) {
+ idx *= l2_entry_size(s) / sizeof(uint64_t);
+ return be64_to_cpu(l2_slice[idx + 1]);
+ } else {
+ return 0; /* For convenience only; this value has no meaning. */
+ }
+}
+
static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice,
int idx, uint64_t entry)
{
+ idx *= l2_entry_size(s) / sizeof(uint64_t);
l2_slice[idx] = cpu_to_be64(entry);
}
+static inline void set_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice,
+ int idx, uint64_t bitmap)
+{
+ assert(has_subclusters(s));
+ idx *= l2_entry_size(s) / sizeof(uint64_t);
+ l2_slice[idx + 1] = cpu_to_be64(bitmap);
+}
+
static inline bool has_data_file(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
--
2.20.1
- [PATCH v9 00/34] Add subcluster allocation to qcow2, Alberto Garcia, 2020/06/28
- [PATCH v9 10/34] qcow2: Add offset_to_sc_index(), Alberto Garcia, 2020/06/28
- [PATCH v9 07/34] qcow2: Document the Extended L2 Entries feature, Alberto Garcia, 2020/06/28
- [PATCH v9 08/34] qcow2: Add dummy has_subclusters() function, Alberto Garcia, 2020/06/28
- [PATCH v9 26/34] qcow2: Clear the L2 bitmap when allocating a compressed cluster, Alberto Garcia, 2020/06/28
- [PATCH v9 03/34] qcow2: Add calculate_l2_meta(), Alberto Garcia, 2020/06/28
- [PATCH v9 06/34] qcow2: Add get_l2_entry() and set_l2_entry(), Alberto Garcia, 2020/06/28
- [PATCH v9 02/34] qcow2: Convert qcow2_get_cluster_offset() into qcow2_get_host_offset(), Alberto Garcia, 2020/06/28
- [PATCH v9 05/34] qcow2: Process QCOW2_CLUSTER_ZERO_ALLOC clusters in handle_copied(), Alberto Garcia, 2020/06/28
- [PATCH v9 04/34] qcow2: Split cluster_needs_cow() out of count_cow_clusters(), Alberto Garcia, 2020/06/28
- [PATCH v9 13/34] qcow2: Update get/set_l2_entry() and add get/set_l2_bitmap(),
Alberto Garcia <=
- [PATCH v9 24/34] qcow2: Add subcluster support to check_refcounts_l2(), Alberto Garcia, 2020/06/28
- [PATCH v9 19/34] qcow2: Handle QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC, Alberto Garcia, 2020/06/28
- [PATCH v9 09/34] qcow2: Add subcluster-related fields to BDRVQcow2State, Alberto Garcia, 2020/06/28
- [PATCH v9 16/34] qcow2: Add qcow2_cluster_is_allocated(), Alberto Garcia, 2020/06/28
- [PATCH v9 11/34] qcow2: Add offset_into_subcluster() and size_to_subclusters(), Alberto Garcia, 2020/06/28
- [PATCH v9 29/34] qcow2: Add subcluster support to qcow2_measure(), Alberto Garcia, 2020/06/28
- [PATCH v9 22/34] qcow2: Add subcluster support to zero_in_l2_slice(), Alberto Garcia, 2020/06/28
- [PATCH v9 25/34] qcow2: Update L2 bitmap in qcow2_alloc_cluster_link_l2(), Alberto Garcia, 2020/06/28
- [PATCH v9 01/34] qcow2: Make Qcow2AioTask store the full host offset, Alberto Garcia, 2020/06/28
- [PATCH v9 33/34] qcow2: Assert that expand_zero_clusters_in_l1() does not support subclusters, Alberto Garcia, 2020/06/28