From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Cc: den@virtuozzo.com, devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1] drivers/md/dm-qcow2: truncate unused tail of image on suspend
Date: Tue, 06 Oct 2026 17:52:46 +0200 [thread overview]
Message-ID: <179130196660.914346.14420180134509591837.b4-review@b4> (raw)
In-Reply-To: <20261006144428.341824-1-alexander.ivanov@virtuozzo.com>
> drivers/md/dm-qcow2: truncate unused tail of image on suspend
...
> Truncate the file to min(file_preallocated_area_start, used end).
> Skip the scan if md writeback failed, as refcounts on disk are stale
> then, and fall back to the old behaviour on scan error.
There is one more case of stale refcounts on disk: an image with
INCOMPATIBLE_FEATURES_DIRTY_BIT set. qcow2_check_convert_hdr() accepts it
(the check is commented out), and with qemu lazy refcounts that bit means
refcounts were not written for the last allocations, so they are too low.
Today such an image loses data only when the allocator hands out a
cluster whose refcount is zero but which L2 still references. After this
patch the first suspend truncates live clusters at the tail without a
single write to the device. The image is already invalid per spec, so
this is not a regression in the strict sense, but either the commit
message should say that a dirty image is not supported, or the dirty-bit
check in qcow2_check_convert_hdr() should come back.
> +static int get_md_page_sync(struct qcow2 *qcow2, u64 id, struct md_page **md)
> +{
> + int ret;
> +
> + spin_lock_irq(&qcow2->md_pages_lock);
> + *md = qcow2_md_page_find_or_postpone(qcow2, id, NULL);
> + spin_unlock_irq(&qcow2->md_pages_lock);
> + if (*md)
> + return 0;
> +
> + ret = qcow2_alloc_and_insert_md_page(qcow2, id, md);
> + if (ret)
> + return ret;
> +
> + ret = qcow2_rw_page_sync(READ, qcow2, id, (*md)->page);
qcow2_attach_file() does the same alloc + qcow2_rw_page_sync(READ) +
MD_UPTODATE sequence by hand for page 0, minus the erase on failure. If
this helper lives in dm-qcow2-target.c next to the other md page helpers
and is exported through dm-qcow2.h, that call site can use it as well.
> + pos = round_down(qcow2->file_size - 1, clu_size);
> + while (pos >= 0) {
Everything at or above file_preallocated_area_start is unused by
construction: allocate_cluster() moves it past every cluster it hands
out, and relocate_refcount_table() goes through truncate_prealloc_safe(),
which sets it to the requested length. Starting from file_size scans the
R2 entries covering the preallocated area (up to PREALLOC_SIZE) on every
suspend for nothing. Start from file_preallocated_area_start - 1 instead.
--
Konstantin Khorenko <khorenko@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-10-06 15:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 14:44 Alexander Ivanov
2026-10-06 14:45 ` Denis V. Lunev
2026-10-06 14:49 ` no-reply
2026-10-06 15:52 ` Konstantin Khorenko [this message]
2026-10-06 15:56 ` Denis V. Lunev
2026-10-06 17:39 ` Konstantin Khorenko
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=179130196660.914346.14420180134509591837.b4-review@b4 \
--to=khorenko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox