From: Denis V. Lunev __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. 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 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, rather than moving the decrement past the copy. Dropping it later 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@vger.kernel.org Signed-off-by: Denis V. Lunev --- drivers/md/persistent-data/dm-transaction-manager.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c index 7401add01d12..cf203ebb5110 100644 --- a/drivers/md/persistent-data/dm-transaction-manager.c +++ b/drivers/md/persistent-data/dm-transaction-manager.c @@ -303,7 +303,7 @@ static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, r = dm_bm_read_lock(tm->bm, orig, v, &orig_block); if (r < 0) - return r; + goto out_put_orig; /* * It would be tempting to use dm_bm_unlock_move here, but some @@ -315,13 +315,18 @@ 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_put_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_put_orig: + /* The caller goes on using orig when the shadow fails. */ + dm_sm_inc_block(tm->sm, orig); return r; } -- 2.55.0