[PATCH v3 1/3] dm persistent data: put back the reference a failed shadow dropped

From: Denis V. Lunev

Date: Mon Nov 30 2026 - 13:27:15 EST


From: Denis V. Lunev <den@xxxxxxxxxx>

__shadow_block() drops the original block's reference before it reads
the block, and every error return after that leaves the caller pointing
at a block the space map has given away. The block allocated for the
copy is lost on those same paths.

metadata_ll_commit() shows what the dropped reference 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 read of a metadata block can fail for a transient reason,
and one failure is enough to get here.

Take the reference back where the shadow fails and release the copy's
block, the way dm_tm_new_block() above already does.

The decrement of the original stays where it was. Moving it past the
copy would hold the copy's write lock across dm_sm_dec_block(), which
starts by shadowing a bitmap block of its own and so takes two more
locks, and the targets size their dm-bufio reserve for the peak
without them: commit 490ae017f54e ("dm thin metadata:
THIN_MAX_CONCURRENT_LOCKS should be 6") set thin's budget to exactly
what rebalance3() reaches today.

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, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c
index 7401add01d12..90d0a95d940c 100644
--- a/drivers/md/persistent-data/dm-transaction-manager.c
+++ b/drivers/md/persistent-data/dm-transaction-manager.c
@@ -299,11 +299,11 @@ static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,

r = dm_sm_dec_block(tm->sm, orig);
if (r < 0)
- return r;
+ goto out_free_new;

r = dm_bm_read_lock(tm->bm, orig, v, &orig_block);
if (r < 0)
- return r;
+ goto out_inc_orig;

/*
* It would be tempting to use dm_bm_unlock_move here, but some
@@ -315,13 +315,20 @@ static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
r = dm_bm_write_lock_zero(tm->bm, new, v, result);
if (r) {
dm_bm_unlock(orig_block);
- return r;
+ goto out_inc_orig;
}

memcpy(dm_block_data(*result), dm_block_data(orig_block),
dm_bm_block_size(tm->bm));

dm_bm_unlock(orig_block);
+ return 0;
+
+out_inc_orig:
+ /* The caller goes on using orig when the shadow fails. */
+ dm_sm_inc_block(tm->sm, orig);
+out_free_new:
+ dm_sm_dec_block(tm->sm, new);
return r;
}

--
2.55.0