[PATCH 1/3] dm persistent data: drop the original block only once it is copied
From: Denis V. Lunev
Date: Wed Nov 18 2026 - 06:03:25 EST
From: Denis V. Lunev <den@xxxxxxxxxx>
__shadow_block() releases the original block's reference before it
reads the block, so every error return in between leaves the caller
pointing at a block the space map has given away.
metadata_ll_commit() shows what that costs. It stores the new block in
ll->bitmap_root only when the shadow succeeds, so a failed read leaves
the space map's index root at a block whose count has already reached
zero. Every commit after that shadows the same block, fails to
decrement it, and fails:
device-mapper: space map common: unable to decrement block
device-mapper: era: metadata_commit: pre commit failed
The metadata never recovers. dm-era reports "era Error" and fails the
writes it was tracking, which takes the workload's filesystem
read-only.
A btree caller ends up in a different state. dm_btree_insert()
publishes the new root only on success, so the caller keeps a root
whose count has dropped to zero, and the next dm_tm_shadow_block() of
it finds dm_sm_count_is_more_than_one() false and writes the block in
place instead of copying it.
Decrement the original once the copy holds its contents. A read of a
metadata block can fail for a transient reason, and a single failure is
enough to get here.
Fixes: 3241b1d3e0aa ("dm: add persistent data library")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Denis V. Lunev <den@xxxxxxxxxx>
---
drivers/md/persistent-data/dm-transaction-manager.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c
index 7401add01d12..159aac9da07a 100644
--- a/drivers/md/persistent-data/dm-transaction-manager.c
+++ b/drivers/md/persistent-data/dm-transaction-manager.c
@@ -297,10 +297,6 @@ static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
if (r < 0)
return r;
- r = dm_sm_dec_block(tm->sm, orig);
- if (r < 0)
- return r;
-
r = dm_bm_read_lock(tm->bm, orig, v, &orig_block);
if (r < 0)
return r;
@@ -322,7 +318,14 @@ static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
dm_bm_block_size(tm->bm));
dm_bm_unlock(orig_block);
- return r;
+
+ r = dm_sm_dec_block(tm->sm, orig);
+ if (r < 0) {
+ dm_bm_unlock(*result);
+ return r;
+ }
+
+ return 0;
}
int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
--
2.55.0