From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrey Zhadchenko Date: Wed, 19 Aug 2026 03:07:42 +0300 Subject: [Devel] [PATCH VZ10 v2 4/7] drivers/md/dm-qcow2: fix seek skip to the next L2 table In-Reply-To: <20260819000745.28823-1-andrey.zhadchenko@virtuozzo.com> References: <20260819000745.28823-1-andrey.zhadchenko@virtuozzo.com> Message-ID: <20260819000745.28823-5-andrey.zhadchenko@virtuozzo.com> List-Id: get_next_l2() adds the number of remaining clusters to the current sector, so for a position which is not cluster aligned (e.g. the llseek offset itself) the result overshoots the L2 table boundary by the in-cluster offset. Compute the boundary by simple round_up to the size covered by a single L2 table. Also allow skipping l2 if we have lower delta but range does not exist there (e.g. past the delta end). https://virtuozzo.atlassian.net/browse/VSTOR-139407 Feature: dm-qcow2: block device over QCOW2 files driver Signed-off-by: Andrey Zhadchenko --- v2: - changed l2 calculation to a simplier round_up() - expanded l2 skip for non-existing backing. Updated commit message drivers/md/dm-qcow2-map.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index d6d15b04215c6..43188ceebc9af 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -4405,12 +4405,9 @@ static struct qio *free_seek_qio_ret_higher(struct qio *qio) static inline sector_t get_next_l2(struct qio *qio) { struct qcow2 *qcow2 = qio->qcow2; - loff_t start, add; + u64 l2_cover = to_sector((u64)qcow2->clu_size * qcow2->l2_entries); - start = to_bytes(qio->bi_iter.bi_sector); - add = qcow2->l2_entries - (start / qcow2->clu_size) % qcow2->l2_entries; - - return qio->bi_iter.bi_sector + (qcow2->clu_size / to_bytes(1)) * add; + return round_up(qio->bi_iter.bi_sector + 1, l2_cover); } static inline sector_t get_next_clu(struct qio *qio) @@ -4431,9 +4428,10 @@ static inline void seek_qio_next_clu(struct qio *qio, struct qcow2_map *map) /* * Whole L2 table is unmapped - skip to next l2 table, - * but only if there is no backing image + * but only if there is no backing data */ - if (map && !(map->level & L2_LEVEL) && !qio->qcow2->lower) + if (map && !(map->level & L2_LEVEL) && + !maybe_mapped_in_lower_delta(qio->qcow2, qio)) bi_sector = get_next_l2(qio); else bi_sector = get_next_clu(qio); -- 2.43.5