From: Peng Yu <yupeng0921@gmail.com>
To: 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, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, Peng Yu <yupeng0921@gmail.com>
Subject: [PATCH 1/2] dm thin metadata: report uncommitted state and refuse commits after a failure
Date: Tue, 24 Nov 2026 20:33:24 -0800 [thread overview]
Message-ID: <20261125043325.138351-2-yupeng0921@gmail.com> (raw)
In-Reply-To: <20261125043325.138351-1-yupeng0921@gmail.com>
Add two flags for a thin pool:
* commit_failed: Set to true if a commit failed. It is a fact that may
be caused by IO errors.
* refuse_commit_after_failure: Set to true if we enable the
wait_for_commit option. It is selected by a user.
If both of them are true, the user should repair the pool.
Add a new field:
* changed: A new field of struct dm_thin_lookup_result, set by each
lookup that finds a mapping. False means the thin device's metadata
in memory was the same as on disk at the time of the lookup; true
means they may not be the same.
Add some helper functions:
* dm_thin_uncommitted: Return true if the thin device might have
metadata changes that are not on disk yet. When we get a commit
failure, td->changed might be cleared, but the metadata changes are
not on disk due to the commit failure. So when commit_failed is true,
the function will always return true.
* dm_pool_metadata_set_refuse_commit_after_failure: Set the
refuse_commit_after_failure flag.
Signed-off-by: Peng Yu <yupeng0921@gmail.com>
Assisted-by: Claude:claude-opus-5-5 [Claude Code]
Assisted-by: Claude:claude-fable-5-1 [Claude Code]
---
drivers/md/dm-thin-metadata.c | 61 +++++++++++++++++++++++++++++++----
drivers/md/dm-thin-metadata.h | 14 ++++++++
2 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index e60e1326376a..7b56c970a524 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -221,6 +221,9 @@ struct dm_pool_metadata {
*/
bool in_service:1;
+ bool commit_failed;
+ bool refuse_commit_after_failure;
+
/*
* Reading the space map roots can fail, so we read it into these
* buffers before the superblock is locked and updated.
@@ -972,6 +975,8 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
INIT_LIST_HEAD(&pmd->thin_devices);
pmd->fail_io = false;
pmd->in_service = false;
+ pmd->commit_failed = false;
+ pmd->refuse_commit_after_failure = false;
pmd->bdev = bdev;
pmd->data_block_size = data_block_size;
pmd->pre_commit_fn = NULL;
@@ -1020,10 +1025,15 @@ int dm_pool_metadata_close(struct dm_pool_metadata *pmd)
pmd_write_lock_in_core(pmd);
if (!pmd->fail_io && !dm_bm_is_read_only(pmd->bm)) {
- r = __commit_transaction(pmd);
- if (r < 0)
- DMWARN("%s: __commit_transaction() failed, error = %d",
- __func__, r);
+ if (pmd->refuse_commit_after_failure && pmd->commit_failed) {
+ DMERR_LIMIT("%s: refusing to commit after a failed commit",
+ __func__);
+ } else {
+ r = __commit_transaction(pmd);
+ if (r < 0)
+ DMWARN("%s: __commit_transaction() failed, error = %d",
+ __func__, r);
+ }
}
pmd_write_unlock(pmd);
__destroy_persistent_data_objects(pmd, true);
@@ -1351,6 +1361,7 @@ static int __reserve_metadata_snap(struct dm_pool_metadata *pmd)
*/
r = __commit_transaction(pmd);
if (r < 0) {
+ pmd->commit_failed = true;
DMWARN("%s: __commit_transaction() failed, error = %d",
__func__, r);
return r;
@@ -1397,8 +1408,15 @@ int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd)
int r = -EINVAL;
pmd_write_lock(pmd);
- if (!pmd->fail_io)
- r = __reserve_metadata_snap(pmd);
+ if (!pmd->fail_io) {
+ if (pmd->refuse_commit_after_failure && pmd->commit_failed) {
+ DMERR_LIMIT("%s: refusing to commit after a failed commit",
+ __func__);
+ r = -EIO;
+ } else {
+ r = __reserve_metadata_snap(pmd);
+ }
+ }
pmd_write_unlock(pmd);
return r;
@@ -1516,6 +1534,7 @@ static void unpack_lookup_result(struct dm_thin_device *td, __le64 value,
unpack_block_time(block_time, &exception_block, &exception_time);
result->block = exception_block;
result->shared = __snapshotted_since(td, exception_time);
+ result->changed = td->changed || td->pmd->commit_failed;
}
static int __find_block(struct dm_thin_device *td, dm_block_t block,
@@ -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;
+ }
/*
* Open the next transaction.
diff --git a/drivers/md/dm-thin-metadata.h b/drivers/md/dm-thin-metadata.h
index 2f64f48b5f19..d7b149471e0b 100644
--- a/drivers/md/dm-thin-metadata.h
+++ b/drivers/md/dm-thin-metadata.h
@@ -81,9 +81,16 @@ int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
/*
* Commits _all_ metadata changes: device creation, deletion, mapping
* updates.
+ *
+ * Returns -EIO without committing once a commit has failed, if the pool
+ * asked to refuse commits after a failure (see
+ * dm_pool_metadata_set_refuse_commit_after_failure()).
*/
int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
+void dm_pool_metadata_set_refuse_commit_after_failure(struct dm_pool_metadata *pmd,
+ bool refuse_commit_after_failure);
+
/*
* Discards all uncommitted changes. Rereads the superblock, rolling back
* to the last good transaction. Thin devices remain open.
@@ -112,6 +119,10 @@ int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
* operations only. A small performance hit is incurred by providing this
* copy of the metadata to userland due to extra copy-on-write operations
* on the metadata nodes. Release this as soon as you finish with it.
+ *
+ * The reservation commits first, so it returns -EIO once a commit has
+ * failed, if the pool asked to refuse commits after a failure (see
+ * dm_pool_metadata_set_refuse_commit_after_failure()).
*/
int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd);
int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd);
@@ -136,6 +147,7 @@ dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
struct dm_thin_lookup_result {
dm_block_t block;
bool shared:1;
+ bool changed:1;
};
/*
@@ -175,6 +187,8 @@ int dm_thin_remove_range(struct dm_thin_device *td,
*/
bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
+bool dm_thin_uncommitted(struct dm_thin_device *td);
+
bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd);
bool dm_thin_aborted_changes(struct dm_thin_device *td);
--
2.43.0
next prev parent reply other threads:[~2026-11-25 4:33 UTC|newest]
Thread overview: 3+ 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 ` Peng Yu [this message]
2026-11-25 4:33 ` [PATCH 2/2] dm thin: add wait_for_commit pool feature Peng Yu
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=20261125043325.138351-2-yupeng0921@gmail.com \
--to=yupeng0921@gmail.com \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=ejt@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--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