mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
	dm-devel@lists.linux.dev
Cc: bmarzins@redhat.com, thornber@redhat.com,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	den@openvz.org
Subject: [PATCH 1/3] dm persistent data: drop the original block only once it is copied
Date: Wed, 18 Nov 2026 12:02:37 +0100	[thread overview]
Message-ID: <20261118110239.2910290-2-den@openvz.org> (raw)
In-Reply-To: <20261118110239.2910290-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

__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@vger.kernel.org
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 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


  reply	other threads:[~2026-11-18 11:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 11:02 [PATCH 0/3] dm era: a metadata device that never comes back Denis V. Lunev
2026-11-18 11:02 ` Denis V. Lunev [this message]
2026-11-18 11:02 ` [PATCH 2/3] dm era: refuse metadata rpcs once the target is suspended Denis V. Lunev
2026-11-18 11:02 ` [PATCH 3/3] dm era: construct the target suspended Denis V. Lunev

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=20261118110239.2910290-2-den@openvz.org \
    --to=den@openvz.org \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=thornber@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®