All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peng Yu" <yupeng0921@gmail.com>,
	"Alasdair Kergon" <agk@redhat.com>,
	"Mike Snitzer" <snitzer@kernel.org>,
	"Mikulas Patocka" <mpatocka@redhat.com>,
	"Benjamin Marzinski" <bmarzins@redhat.com>
Cc: "Joe Thornber" <ejt@redhat.com>, dm-devel@lists.linux.dev
Subject: Re: [PATCH 1/2] dm thin metadata: report uncommitted state and refuse commits after a failure
Date: Wed, 25 Nov 2026 04:56:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-232598@kernel.org> (raw)
In-Reply-To: <20261125043325.138351-2-yupeng0921@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dm thin metadata: inconsistent td->changed state after
  __commit_transaction()
--

commit 0a571384422ac18472855b719999a78add089dae
Author: Peng Yu <yupeng0921@gmail.com>

dm thin metadata: report uncommitted state and refuse commits after a failure

This commit tracks metadata commit failures via a pool-wide commit_failed
flag, exposes whether a thin device or lookup result has uncommitted
metadata changes, and optionally refuses further commits after a failure.

> diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
> index e60e1326376a0..7b56c970a524d 100644
> --- a/drivers/md/dm-thin-metadata.c
> +++ b/drivers/md/dm-thin-metadata.c

[ ... ]

> @@ -1796,6 +1815,17 @@ bool dm_thin_changed_this_transaction(struct dm_thin_device *td)
>  	return r;
>  }
>  
> +bool dm_thin_uncommitted(struct dm_thin_device *td)
> +{
> +	bool r;
> +
> +	down_read(&td->pmd->root_lock);
> +	r = td->changed || td->pmd->commit_failed;
> +	up_read(&td->pmd->root_lock);
> +
> +	return r;
> +}
> +
>  bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd)
>  {
>  	bool r = false;
> @@ -1836,6 +1866,14 @@ int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result)
>  	return r;
>  }
>  
> +void dm_pool_metadata_set_refuse_commit_after_failure(struct dm_pool_metadata *pmd,
> +						      bool refuse_commit_after_failure)
> +{
> +	pmd_write_lock_in_core(pmd);
> +	pmd->refuse_commit_after_failure = refuse_commit_after_failure;
> +	pmd_write_unlock(pmd);
> +}
> +
>  int dm_pool_commit_metadata(struct dm_pool_metadata *pmd)
>  {
>  	int r = -EINVAL;
> @@ -1848,9 +1886,18 @@ int dm_pool_commit_metadata(struct dm_pool_metadata *pmd)
>  	if (pmd->fail_io)
>  		goto out;
>  
> +	if (pmd->refuse_commit_after_failure && pmd->commit_failed) {
> +		DMERR_LIMIT("%s: refusing to commit after a failed commit",
> +			    __func__);
> +		r = -EIO;
> +		goto out;
> +	}
> +
>  	r = __commit_transaction(pmd);
> -	if (r < 0)
> +	if (r < 0) {
> +		pmd->commit_failed = true;
>  		goto out;
> +	}

[Severity: Medium]
Does setting pmd->commit_failed after __commit_transaction() fails leave
td->changed and td->aborted_with_changes inconsistent with the actual
on-disk state?

Inside __commit_transaction(), __write_changed_details() clears
td->changed = false (and frees closed thin devices) before dm_sm_commit(),
dm_tm_pre_commit(), save_sm_roots(), superblock_lock(), and dm_tm_commit()
run:

drivers/md/dm-thin-metadata.c:__write_changed_details() {
	...
		if (td->open_count)
			td->changed = false;
		else {
			list_del(&td->list);
			kfree(td);
		}
	...
}

When a commit fails in any of those later steps, td->changed is already
false, while dm_thin_changed_this_transaction(),
dm_pool_changed_this_transaction(), and __set_abort_with_changes_flags()
still read td->changed directly:

drivers/md/dm-thin-metadata.c:__set_abort_with_changes_flags() {
	...
	list_for_each_entry(td, &pmd->thin_devices, list)
		td->aborted_with_changes = td->changed;
}

When commit() in drivers/md/dm-thin.c fails and calls
metadata_operation_failed() -> dm_pool_abort_metadata(),
td->aborted_with_changes is set to false.  Subsequent REQ_PREFLUSH and
REQ_FUA bios then see both dm_thin_changed_this_transaction() and
dm_thin_aborted_changes() as false in bio_triggers_commit(), and since
wait_for_commit_write() in commit "dm thin: add wait_for_commit pool
feature" skips op_is_flush(bio->bi_opf), those flush and FUA bios silently
succeed instead of failing with an I/O error.

In addition, when pmd->refuse_commit_after_failure is false,
pmd->commit_failed is never cleared if a later commit or abort succeeds,
leaving result->changed and dm_thin_uncommitted() permanently true across
the pool.  Could __write_changed_details() defer clearing td->changed (and
freeing closed td entries) until dm_tm_commit() succeeds?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125043325.138351-1-yupeng0921@gmail.com?part=1

  reply	other threads:[~2026-11-25  4:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  4:33 [PATCH 0/2] dm thin: complete writes only after the metadata commit Peng Yu
2026-11-25  4:33 ` [PATCH 1/2] dm thin metadata: report uncommitted state and refuse commits after a failure Peng Yu
2026-11-25  4:56   ` sashiko-bot [this message]
2026-11-25  4:33 ` [PATCH 2/2] dm thin: add wait_for_commit pool feature Peng Yu
2026-11-25  5:02   ` sashiko-bot

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-232598@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=sashiko-reviews@lists.linux.dev \
    --cc=snitzer@kernel.org \
    --cc=yupeng0921@gmail.com \
    /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.