From: no-reply@sashiko.virtuozzo.com
To: den@virtuozzo.com, Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v2 2/6] dm-qcow2: truncate unused tail of image on suspend
Date: Thu, 8 Oct 2026 07:44:35 +0000 [thread overview]
Message-ID: <010701a11a789fc7-2d4a8875-d039-4ea1-ab34-47641da991a5-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261008073837.510678-3-alexander.ivanov@virtuozzo.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] dm-qcow2: qcow2_calc_used_end() can return an end beyond file_size, so suspend grows the file
- [Low] dm-qcow2: duplicated prefix in used-end error message in qcow2_truncate_preallocations()
--
commit ce35554959d7d4a8d76e3913a469c5465e287b33
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
dm-qcow2: truncate unused tail of image on suspend
This patch adds qcow2_calc_used_end(), which scans refcount blocks
backward from file_preallocated_area_start and returns the end of the
last cluster with a non-zero refcount. On postsuspend the image file is
then truncated to that end instead of only to
file_preallocated_area_start. The scan is skipped if md writeback
failed, and the old behaviour is used if the scan fails.
Link: https://virtuozzo.atlassian.net/browse/VSTOR-148171
> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
> --- a/drivers/md/dm-qcow2-map.c
> +++ b/drivers/md/dm-qcow2-map.c
[ ... ]
> +loff_t qcow2_calc_used_end(struct qcow2 *qcow2)
> +{
> + u32 clu_size = qcow2->clu_size;
> + struct qcow2_map_item r1, r2;
> + struct md_page *r1_md = NULL;
> + loff_t pos;
> + s32 i;
> + int ret;
> +
> + pos = round_down(qcow2->file_preallocated_area_start - 1, clu_size);
[ ... ]
> + for (i = r2.index_in_page; i >= 0; i--, pos -= clu_size) {
> + if (get_r2_entry(qcow2, r2.md, i))
> + return pos + clu_size;
> + }
[Severity: Medium]
Can the value returned here exceed qcow2->file_size?
file_preallocated_area_start is only page aligned after
qcow2_parse_metadata(), not aligned to clu_size. When clu_size is larger
than PAGE_SIZE and the file ends in the middle of a cluster, the first
cluster examined starts below file_preallocated_area_start but extends
past it.
If that cluster has a non-zero refcount, the function returns
pos + clu_size, which is greater than file_size.
> diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
> --- a/drivers/md/dm-qcow2-target.c
> +++ b/drivers/md/dm-qcow2-target.c
> @@ -1042,11 +1042,21 @@ static void qcow2_truncate_preallocations(struct dm_target *ti)
[ ... ]
> + /* Refcounts on disk are stale after failed md writeback */
> + if (!tgt->md_writeback_error) {
> + used_end = qcow2_calc_used_end(qcow2);
> + if (used_end < 0)
> + QC_ERR(ti, "dm-qcow2: Can't find used end: %lld", used_end);
> + else
> + end = used_end;
> + }
> +
> if (end == qcow2->file_size)
> return;
>
> ret = qcow2_truncate_safe(qcow2->file, end);
[Severity: Medium]
Is the check against file_size sufficient here?
Only end == qcow2->file_size is tested, so with used_end greater than
file_size the code goes on to call qcow2_truncate_safe(), and ftruncate
extends the file. qcow2->file_size and file_preallocated_area_start are
then set to the larger value, although this patch is meant only to shrink
the image.
The growth is at most one cluster, but would it make sense to clamp with
min(used_end, qcow2->file_size), or to use end >= qcow2->file_size for the
early return?
[Severity: Low]
This isn't a bug, but QC_ERR already adds the "dm-qcow2: " prefix through
QCOW2_FMT, so this message prints the prefix twice:
dm-qcow2: <dev>: dm-qcow2: Can't find used end: -5
The raw negative errno is also printed with %lld. Neighbouring messages in
the same function repeat the prefix as well.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261008073837.510678-1-alexander.ivanov@virtuozzo.com?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-10-08 7:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 7:38 [Devel] [PATCH hci-8.1 v2 0/6] truncate unused tail of images " Alexander Ivanov
2026-10-08 7:38 ` [Devel] [PATCH hci-8.1 v2 1/6] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
2026-10-08 7:43 ` no-reply
2026-10-08 7:38 ` [Devel] [PATCH hci-8.1 v2 2/6] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-10-08 7:44 ` no-reply [this message]
2026-10-08 9:50 ` Alexander Ivanov
2026-10-08 7:38 ` [Devel] [PATCH hci-8.1 v2 3/6] dm-ploop: set delta is_raw before applying its mappings Alexander Ivanov
2026-10-08 7:46 ` no-reply
2026-10-08 10:42 ` Alexander Ivanov
2026-10-08 7:38 ` [Devel] [PATCH hci-8.1 v2 4/6] dm-ploop: factor out ploop_read_delta() from ploop_add_delta() Alexander Ivanov
2026-10-08 7:46 ` no-reply
2026-10-08 7:38 ` [Devel] [PATCH hci-8.1 v2 5/6] dm-ploop: reload metadata on resume Alexander Ivanov
2026-10-08 7:54 ` no-reply
2026-10-08 11:46 ` Alexander Ivanov
2026-10-08 7:38 ` [Devel] [PATCH hci-8.1 v2 6/6] dm-ploop: truncate unused tail of top delta on suspend Alexander Ivanov
2026-10-08 7:52 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=010701a11a789fc7-2d4a8875-d039-4ea1-ab34-47641da991a5-000000@eu-central-1.amazonses.com \
--to=no-reply@sashiko.virtuozzo.com \
--cc=alexander.ivanov@virtuozzo.com \
--cc=den@virtuozzo.com \
--cc=devel@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.