All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@virtuozzo.com>
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>, den@openvz.org
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v3 1/3] dm-qcow2: add qcow2_md_page_read_sync() helper
Date: Thu, 8 Oct 2026 12:57:46 +0200	[thread overview]
Message-ID: <682d6456-160e-4003-bc56-5eefb5f952b2@virtuozzo.com> (raw)
In-Reply-To: <20261008100449.550882-2-alexander.ivanov@virtuozzo.com>

On 10/8/26 12:04, Alexander Ivanov wrote:
> Add a helper, which returns an up to date md page from md cache,
> or allocates a new one, inserts it and reads it synchronously.
> On read failure the page is erased from cache and freed.
>
> Use it in qcow2_parse_header() instead of open-coded allocation
> and read of page 0. It will also be used by the next patch.
>
> 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-target.c | 36 +++++++++++++++++++++++++++++++-----
>  drivers/md/dm-qcow2.h        |  2 ++
>  2 files changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
> index be09615eb8e2..3e47e66b4007 100644
> --- a/drivers/md/dm-qcow2-target.c
> +++ b/drivers/md/dm-qcow2-target.c
> @@ -418,6 +418,36 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_pag
>  }
>  ALLOW_ERROR_INJECTION(qcow2_alloc_and_insert_md_page, ERRNO);
>  
> +/*
> + * Returns up to date md page from cache, or allocates
> + * a new one and reads it synchronously.
> + */
> +int qcow2_md_page_read_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);
> +	spin_lock_irq(&qcow2->md_pages_lock);
> +	if (ret)
> +		qcow2_md_page_erase(qcow2, *md);
> +	else
> +		(*md)->status |= MD_UPTODATE;
> +	spin_unlock_irq(&qcow2->md_pages_lock);
> +	if (ret)
> +		qcow2_free_md_page(*md);
> +	return ret;
> +}
> +

The comment on qcow2_md_page_read_sync() says it returns
an up-to-date page, but that depends on no read being in flight.
If a page is cached but not MD_UPTODATE,
qcow2_md_page_find_or_postpone() returns NULL and the insert
that follows fails.

This can't happen on a suspended device, but
the comment should state the assumption.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-10-08 10:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 10:04 [Devel] [PATCH hci-8.1 v3 0/3] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-10-08 10:04 ` [Devel] [PATCH hci-8.1 v3 1/3] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
2026-10-08 10:09   ` no-reply
2026-10-08 10:57   ` Denis V. Lunev [this message]
2026-10-08 10:04 ` [Devel] [PATCH hci-8.1 v3 2/3] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages Alexander Ivanov
2026-10-08 10:07   ` no-reply
2026-10-08 10:04 ` [Devel] [PATCH hci-8.1 v3 3/3] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-10-08 10:11   ` no-reply
2026-10-08 10:58   ` Denis V. Lunev
2026-10-08 10:59 ` [Devel] [PATCH hci-8.1 v3 0/3] " Denis V. Lunev

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=682d6456-160e-4003-bc56-5eefb5f952b2@virtuozzo.com \
    --to=den@virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=den@openvz.org \
    --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.