From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v7 3/6] dm-qcow2: extend the file in place_r2() before linking the refblock
Date: Mon, 26 Oct 2026 11:52:53 +0100 [thread overview]
Message-ID: <9d9121bf-e06b-48eb-acb2-eecd192b2786@virtuozzo.com> (raw)
In-Reply-To: <20261022145032.2128679-4-alexander.ivanov@virtuozzo.com>
This patch definitely solves the problems but feels too hacky for me. I
think it will be better to step back and rethink why
find_unused_cluster() calls modification function (place_r2) while being
named 'find'. Won't it be better if we can notify allocate_cluster()
that we need new r2 and it will punch space + call place_r2 for us and
then retry find_unused_cluster?
This way we will have all image size metadata bookkeeping in one place
instead of having a secret second 'allocate refcount cluster if we run
out of space'
On 10/22/26 16:50, Alexander Ivanov wrote:
> place_r2() links a new refblock into R1, but moves neither file_size
> nor file_preallocated_area_start. The refblock stays at or above the
> watermark if truncate_prealloc_safe() in allocate_cluster() fails
> after place_r2(), or if a parallel mark_cluster_unused() lowers
> free_cluster_search_pos before the second pass of
> find_unused_cluster(). Truncation of preallocations on suspend then
> cuts the file under the refblock: R1 on disk points past EOF, and
> the next session gets -EIO on allocations in the range it covers.
>
> Extend the file and raise the watermark to the end of the refblock
> before linking it into R1, as allocate_cluster() does for data
> clusters.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
> drivers/md/dm-qcow2-map.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
> index 78ee7cf5e881..810dd22425ae 100644
> --- a/drivers/md/dm-qcow2-map.c
> +++ b/drivers/md/dm-qcow2-map.c
> @@ -82,6 +82,7 @@ struct qcow2_bvec {
> static int qcow2_handle_r1r2_maps(struct qcow2 *qcow2, loff_t pos, struct qio **qio,
> struct qcow2_map_item *r1, struct qcow2_map_item *r2, bool compressed);
> static int qcow2_punch_hole(struct file *file, loff_t pos, loff_t len);
> +static int truncate_prealloc_safe(struct qcow2 *qcow2, loff_t len, const char *func);
> static void handle_cleanup_mask(struct qio *qio);
> static void process_read_qio(struct qcow2 *qcow2, struct qio *qio,
> struct qcow2_map *map);
> @@ -2088,6 +2089,7 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
> struct qcow2_map_item *r2, loff_t r2_pos, struct qio **qio)
> {
> struct dm_target *ti = qcow2->tgt->ti;
> + loff_t end = r2_pos + qcow2->clu_size;
> u64 page_id = r2_pos >> PAGE_SHIFT;
> int ret;
>
> @@ -2100,6 +2102,12 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
> return ret;
> }
>
> + ret = truncate_prealloc_safe(qcow2, end, __func__);
> + if (ret)
> + return ret;
> + if (end > qcow2->file_preallocated_area_start)
> + qcow2->file_preallocated_area_start = end;
> +
> ret = qcow2_alloc_and_insert_md_page(qcow2, page_id, &r2->md);
> if (ret < 0) {
> QC_ERR(ti, "Can't alloc: ret=%d, page_id=%llu", ret, page_id);
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-10-26 10:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 14:50 [Devel] [PATCH hci-8.1 v7 0/6] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-10-22 14:50 ` [Devel] [PATCH hci-8.1 v7 1/6] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
2026-10-22 14:55 ` no-reply
2026-10-22 14:50 ` [Devel] [PATCH hci-8.1 v7 2/6] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages Alexander Ivanov
2026-10-22 14:53 ` no-reply
2026-10-22 14:50 ` [Devel] [PATCH hci-8.1 v7 3/6] dm-qcow2: extend the file in place_r2() before linking the refblock Alexander Ivanov
2026-10-22 14:56 ` no-reply
2026-10-26 10:52 ` Andrey Zhadchenko [this message]
2026-10-22 14:50 ` [Devel] [PATCH hci-8.1 v7 4/6] dm-qcow2: complete wbd before ending the data qio Alexander Ivanov
2026-10-22 14:58 ` no-reply
2026-10-22 14:50 ` [Devel] [PATCH hci-8.1 v7 5/6] dm-qcow2: keep the dirty bit of an image opened dirty Alexander Ivanov
2026-10-22 14:58 ` no-reply
2026-10-22 14:50 ` [Devel] [PATCH hci-8.1 v7 6/6] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-10-22 15:02 ` no-reply
2026-10-23 6:40 ` Alexander Ivanov
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=9d9121bf-e06b-48eb-acb2-eecd192b2786@virtuozzo.com \
--to=andrey.zhadchenko@virtuozzo.com \
--cc=alexander.ivanov@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