All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
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 v8 5/6] dm-qcow2: keep the dirty bit of an image opened dirty
Date: Wed, 28 Oct 2026 12:59:24 +0100	[thread overview]
Message-ID: <da87c80f-7c86-4a09-b3ef-91a4bef4f2d6@virtuozzo.com> (raw)
In-Reply-To: <20261026144223.2787145-6-alexander.ivanov@virtuozzo.com>

1. Get rid of useless comments (which is all comments in this patch)
2. kernel_dirty_bit should be kernel_dirty_bit_set because without set 
it makes no sense.
3. Commit message should be reworded to include the following very 
important information:
  - kernel_sets_dirty_bit is a module parameter
  - we do not set it in Virtuozzo
  - ploop sets this from userspace itself (so this is rather a hardening 
patch)

On 10/26/26 15:42, Alexander Ivanov wrote:
> With kernel_sets_dirty_bit, postsuspend clears the dirty bit
> unconditionally. An image that is dirty at open, e.g. after a crash,
> has unrepaired refcounts, which may be below real usage, yet it is
> marked clean on disk after the first suspend. A userspace check before
> the next open then has no reason to repair it.
> 
> Clear the bit only if the image was clean before the kernel set it.
> The parsed header can't tell this: it is reread on every preresume and
> may carry the kernel's own bit, e.g. on the lower image of a backward
> merge cancelled by suspend in waiting_completion or of a merge with
> depth > 0. So track two flags per image: kernel_dirty_bit is set only
> while the last header write was a successful set and the reread header
> still has the bit, opened_dirty is set when the header has the bit and
> kernel_dirty_bit is not set. Clearing the bit of an image opened dirty
> is left to userspace check.
> 
> After a failed write the bit found on disk is taken as opened dirty,
> which costs an extra check, rather than as the kernel's, which could
> clear a bit set by userspace while the device was suspended.
> 
> This only preserves the on-disk marker. The driver still accepts a
> dirty image read-write and allocates from its refcounts, so
> find_unused_cluster() may hand out clusters that L2 still references
> until the image is checked.

Completely irrelevant paragraph

> 
> 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 | 15 +++++++++++++--
>   drivers/md/dm-qcow2.h        |  2 ++
>   2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
> index b667adb5472a..2d69e39a3530 100644
> --- a/drivers/md/dm-qcow2-target.c
> +++ b/drivers/md/dm-qcow2-target.c
> @@ -659,6 +659,7 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty)
>   	struct QCowHeader *raw_hdr;
>   	struct md_page *md;
>   	bool is_ro;
> +	int ret;
>   
>   	if (qcow2->hdr.version ==  2)
>   		return 0;
> @@ -676,12 +677,15 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty)
>   	if (kernel_sets_dirty_bit) {
>   		if (dirty)
>   			raw_hdr->incompatible_features |= dirty_mask;
> -		else
> +		else if (!qcow2->opened_dirty)
>   			raw_hdr->incompatible_features &= ~dirty_mask;
>   	}
>   	kunmap(md->page);
>   
> -	return qcow2_rw_page_sync(WRITE, qcow2, md->id, md->page);
> +	ret = qcow2_rw_page_sync(WRITE, qcow2, md->id, md->page);
> +	if (kernel_sets_dirty_bit)
> +		qcow2->kernel_dirty_bit = dirty && !ret;
> +	return ret;
>   }
>   ALLOW_ERROR_INJECTION(qcow2_set_image_file_features, ERRNO);
>   
> @@ -903,6 +907,13 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
>   		goto out;
>   
>   	qcow2_calc_cached_parameters(qcow2, hdr);
> +	/* The header is reread on resume and may carry our own dirty bit */
> +	if (!(hdr->incompatible_features & INCOMPATIBLE_FEATURES_DIRTY_BIT)) {
> +		qcow2->opened_dirty = false;
> +		qcow2->kernel_dirty_bit = false;
> +	} else if (!qcow2->kernel_dirty_bit) {
> +		qcow2->opened_dirty = true;
> +	}
>   	ret = -EOPNOTSUPP;
>   	if (qcow2->clu_size < PAGE_SIZE ||
>   	    (qcow2->ext_l2 && qcow2->clu_size < PAGE_SIZE * 32))
> diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
> index 69d3ae6fca8a..a2d951ee5541 100644
> --- a/drivers/md/dm-qcow2.h
> +++ b/drivers/md/dm-qcow2.h
> @@ -257,6 +257,8 @@ struct qcow2 {
>   	u32 refblock_bits;
>   	u32 refblock_entries;
>   	bool ext_l2;
> +	bool opened_dirty; /* Dirty bit was set before we set it */> +	bool kernel_dirty_bit; /* We set the dirty bit on disk */
>   
>   	bool pause_submitting_qios; /* This is used only on top qcow2 image */
>   	bool backward_merge_in_process;

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-10-28 12:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 14:42 [Devel] [PATCH hci-8.1 v8 0/6] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-10-26 14:42 ` [Devel] [PATCH hci-8.1 v8 1/6] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
2026-10-26 14:42 ` [Devel] [PATCH hci-8.1 v8 2/6] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages Alexander Ivanov
2026-10-26 14:42 ` [Devel] [PATCH hci-8.1 v8 3/6] dm-qcow2: extend the file for a new refblock in allocate_cluster() Alexander Ivanov
2026-10-26 14:42 ` [Devel] [PATCH hci-8.1 v8 4/6] dm-qcow2: complete wbd before ending the data qio Alexander Ivanov
2026-10-26 14:42 ` [Devel] [PATCH hci-8.1 v8 5/6] dm-qcow2: keep the dirty bit of an image opened dirty Alexander Ivanov
2026-10-28 11:59   ` Andrey Zhadchenko [this message]
2026-10-26 14:42 ` [Devel] [PATCH hci-8.1 v8 6/6] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-10-28 12:41   ` Andrey Zhadchenko
2026-10-28 15:08     ` 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=da87c80f-7c86-4a09-b3ef-91a4bef4f2d6@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 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.