From: sashiko-bot@kernel.org
To: "Ronnie Sahlberg" <ronniesahlberg@gmail.com>, dm-devel@lists.linux.dev
Cc: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
bmarzins@redhat.com, ejt@redhat.com
Subject: Re: [PATCH v2] dm era: add lazy mode
Date: Tue, 24 Nov 2026 23:29:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-232230@kernel.org> (raw)
In-Reply-To: <20261124230651.494303-1-ronniesahlberg@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] dm era: incomplete metadata snapshot in metadata_take_snap()
- [Medium] dm era: premature clearing of invalidation flags in
metadata_era_rollover()
--
commit c7e0d839221a7af599bacfffe68cbee06cb7fae0
Author: Ronnie Sahlberg <ronniesahlberg@gmail.com>
dm era: add lazy mode
This commit adds an optional "lazy" feature mode to dm-era that records newly
written blocks in memory and flushes them on later metadata commits while
marking the on-disk superblock dirty until all pending bits are persisted.
> diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c
> index ea499adca4ce2..298b376ff785b 100644
> --- a/drivers/md/dm-era-target.c
> +++ b/drivers/md/dm-era-target.c
[ ... ]
> @@ -946,7 +1053,47 @@ static int metadata_new_era(struct era_metadata *md)
> return 0;
> }
>
> -static int metadata_era_rollover(struct era_metadata *md)
> +/*
> + * era_map() sets bits without the worker in lazy mode, so switch it to the
> + * new writeset before archiving the old one.
> + */
> +static int metadata_era_rollover_lazy(struct era_metadata *md)
> +{
> + int r;
> + struct writeset *old_writeset = md->current_writeset;
> + struct writeset *new_writeset = next_writeset(md);
> +
> + r = writeset_init(&md->bitset_info, new_writeset, md->nr_blocks,
> + md->needs_invalidate);
> + if (r) {
> + DMERR("%s: writeset_init failed", __func__);
> + return r;
> + }
> +
> + swap_writeset(md, new_writeset);
> +
> + if (old_writeset->md.root != INVALID_WRITESET_ROOT) {
> + r = writeset_sync_pending(md, old_writeset);
> + if (!r)
> + r = __metadata_era_archive(md, old_writeset,
> + md->current_era);
> + if (r) {
> + DMERR("%s: couldn't archive era %u", __func__,
> + md->current_era);
> + md->tracking_lost = true;
> + dm_disk_bitset_init(md->tm, &md->bitset_info);
> + dm_bitset_del(&md->bitset_info, old_writeset->md.root);
> + old_writeset->md.root = INVALID_WRITESET_ROOT;
> + return r;
> + }
> + }
> +
> + md->current_era++;
> +
> + return 0;
> +}
[Severity: Medium]
Can metadata_take_snap() capture an incomplete metadata snapshot after an
archive failure here?
When archiving old_writeset fails, new_writeset (initialized with all bits
clear) has already been swapped into md->current_writeset and old_writeset is
deleted. If the next rollover is triggered by take_metadata_snap,
metadata_era_rollover() sets md->needs_invalidate = true and calls
metadata_era_rollover_lazy(), which archives that incomplete writeset into
md->writeset_tree_root and puts the all-ones invalidation writeset into the
new md->current_writeset.
Because a metadata snapshot only includes writeset_tree_root and
era_array_root (and not current_writeset), the snapshot misses both the writes
from the failed archive and the all-ones invalidation writeset, while
metadata_era_rollover() clears needs_invalidate and tracking_lost before the
snapshot commit.
[ ... ]
> @@ -969,6 +1116,28 @@ static int metadata_era_rollover(struct era_metadata *md)
> return 0;
> }
>
> +static int metadata_era_rollover(struct era_metadata *md)
> +{
> + int r;
> +
> + /* Writes may have been lost, so mark every block in the new era. */
> + if (md->tracking_lost)
> + md->needs_invalidate = true;
> +
> + if (md->lazy)
> + r = metadata_era_rollover_lazy(md);
> + else
> + r = __metadata_era_rollover(md);
> +
> + /* Cleared before the commit, which marks the metadata clean. */
> + if (!r && md->needs_invalidate) {
> + md->needs_invalidate = false;
> + md->tracking_lost = false;
> + }
> +
> + return r;
> +}
[Severity: Medium]
If the caller's metadata_commit() fails after metadata_era_rollover() clears
md->needs_invalidate and md->tracking_lost, is the invalidation state lost?
process_rpc_calls() and metadata_take_snap() call metadata_commit() after
metadata_era_rollover() returns, without restoring needs_invalidate or
tracking_lost on commit failure. In addition, when a non-lazy target opens
dirty metadata (setting needs_invalidate) and rolls over on preresume, a later
metadata_era_archive() failure in era_postsuspend() only sets tracking_lost if
era->md->lazy is true, so the following metadata_commit() writes a clean
version 1 superblock even though the invalidated era was not archived.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124230651.494303-1-ronniesahlberg@gmail.com?part=1
prev parent reply other threads:[~2026-11-24 23:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 23:06 [PATCH v2] dm era: add lazy mode Ronnie Sahlberg
2026-11-24 23:29 ` sashiko-bot [this message]
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=sashiko-outbox-232230@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=ejt@redhat.com \
--cc=mpatocka@redhat.com \
--cc=ronniesahlberg@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=snitzer@kernel.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