[Devel] [PATCH RH9 v2 4/8] dm/dm-qcow2: add calc_front_qio_bytes() helper
Andrey Zhadchenko
andrey.zhadchenko at virtuozzo.com
Wed Aug 16 12:32:51 MSK 2023
Move code that calculates qio front bytes type and amount into a new
helper. It will be used later for llseek_hole()
Feature: dm: implement SEEK_HOLE for dm-qcow2 and dm-ploop
https://jira.vzint.dev/browse/PSBM-145746
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 46 ++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index a779889c6970..8c1620c11137 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -3341,27 +3341,47 @@ static int handle_metadata(struct qcow2 *qcow2, struct qio **qio,
return ret;
}
+struct calc_front_bytes_ret {
+ bool unmapped;
+ bool zeroes;
+ bool try_lower;
+};
+
+static inline u32 calc_front_qio_bytes(struct qcow2 *qcow2, struct qio *qio,
+ struct qcow2_map *map,
+ struct calc_front_bytes_ret *arg)
+{
+ bool zeroes, unmapped = false, try_lower = false;
+ u32 size;
+
+ zeroes = (size = qio_all_zeroes_size(qcow2, qio, map));
+ if (!size)
+ unmapped = (size = qio_unmapped_size(qcow2, qio, map));
+ if (!size)
+ size = qio_mapped_not_zeroes_size(qcow2, qio, map);
+
+ if (unmapped)
+ try_lower = maybe_mapped_in_lower_delta(qcow2, qio);
+
+ arg->unmapped = unmapped;
+ arg->zeroes = zeroes;
+ arg->try_lower = try_lower;
+
+ return size;
+}
+
static void process_read_qio(struct qcow2 *qcow2, struct qio *qio,
struct qcow2_map *map)
{
- bool unmapped, zeroes, try_lower;
+ struct calc_front_bytes_ret arg;
struct qio *split;
u32 size;
do {
- unmapped = try_lower = false;
split = NULL;
+ size = calc_front_qio_bytes(qcow2, qio, map, &arg);
- zeroes = (size = qio_all_zeroes_size(qcow2, qio, map));
- if (!size)
- unmapped = (size = qio_unmapped_size(qcow2, qio, map));
- if (!size)
- size = qio_mapped_not_zeroes_size(qcow2, qio, map);
-
- if (unmapped)
- try_lower = maybe_mapped_in_lower_delta(qcow2, qio);
-
- if (zeroes || (unmapped && !try_lower)) {
+ if (arg.zeroes || (arg.unmapped && !arg.try_lower)) {
/* All zeroes or clu is not allocated */
perform_zero_read(qio, size);
if (size == qio->bi_iter.bi_size) {
@@ -3379,7 +3399,7 @@ static void process_read_qio(struct qcow2 *qcow2, struct qio *qio,
swap(qio, split);
}
- if (unmapped && try_lower) {
+ if (arg.unmapped && arg.try_lower) {
/* Try to read from lower delta */
shorten_and_zero_qio_tail(qcow2->lower, qio);
qio->qcow2 = qcow2->lower;
--
2.39.3
More information about the Devel
mailing list