[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 10/23] qcow2: Update get/set_l2_entry() and add get/set_l2_bi
From: |
Alberto Garcia |
Subject: |
[RFC PATCH 10/23] qcow2: Update get/set_l2_entry() and add get/set_l2_bitmap() |
Date: |
Tue, 15 Oct 2019 18:23:21 +0300 |
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, these functions are no-ops
when used in traditional qcow2 images.
Signed-off-by: Alberto Garcia <address@hidden>
---
block/qcow2.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/block/qcow2.h b/block/qcow2.h
index 9a7648af47..d9fe883fe0 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -504,15 +504,37 @@ 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;
+ }
+}
+
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)
+{
+ if (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
- [RFC PATCH 00/23] Add subcluster allocation to qcow2, Alberto Garcia, 2019/10/15
- [RFC PATCH 10/23] qcow2: Update get/set_l2_entry() and add get/set_l2_bitmap(),
Alberto Garcia <=
- [RFC PATCH 01/23] qcow2: Add calculate_l2_meta(), Alberto Garcia, 2019/10/15
- [RFC PATCH 16/23] qcow2: Add subcluster support to discard_in_l2_slice(), Alberto Garcia, 2019/10/15
- [RFC PATCH 06/23] qcow2: Add dummy has_subclusters() function, Alberto Garcia, 2019/10/15
- [RFC PATCH 12/23] qcow2: Handle QCOW2_CLUSTER_UNALLOCATED_SUBCLUSTER, Alberto Garcia, 2019/10/15
- [RFC PATCH 09/23] qcow2: Add l2_entry_size(), Alberto Garcia, 2019/10/15
- [RFC PATCH 03/23] qcow2: Process QCOW2_CLUSTER_ZERO_ALLOC clusters in handle_copied(), Alberto Garcia, 2019/10/15
- [RFC PATCH 05/23] qcow2: Document the Extended L2 Entries feature, Alberto Garcia, 2019/10/15
- [RFC PATCH 04/23] qcow2: Add get_l2_entry() and set_l2_entry(), Alberto Garcia, 2019/10/15
- [RFC PATCH 23/23] qcow2: Add the 'extended_l2' option and the QCOW2_INCOMPAT_EXTL2 bit, Alberto Garcia, 2019/10/15