* [PATCH v2 1/3] dm persistent data: put back the reference a failed shadow dropped
2026-11-24 12:25 [PATCH v2 0/3] dm era: a metadata device that never comes back Denis V. Lunev
@ 2026-11-24 12:25 ` Denis V. Lunev
2026-11-24 12:26 ` [PATCH v2 2/3] dm era: refuse metadata rpcs once the target is suspended Denis V. Lunev
2026-11-24 12:26 ` [PATCH v2 3/3] dm era: construct the target suspended Denis V. Lunev
2 siblings, 0 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-24 12:25 UTC (permalink / raw)
To: agk, snitzer, mpatocka, dm-devel
Cc: bmarzins, thornber, linux-kernel, stable, den
From: Denis V. Lunev <den@openvz.org>
__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 <den@openvz.org>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/3] dm era: refuse metadata rpcs once the target is suspended
2026-11-24 12:25 [PATCH v2 0/3] dm era: a metadata device that never comes back Denis V. Lunev
2026-11-24 12:25 ` [PATCH v2 1/3] dm persistent data: put back the reference a failed shadow dropped Denis V. Lunev
@ 2026-11-24 12:26 ` Denis V. Lunev
2026-11-24 12:26 ` [PATCH v2 3/3] dm era: construct the target suspended Denis V. Lunev
2 siblings, 0 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-24 12:26 UTC (permalink / raw)
To: agk, snitzer, mpatocka, dm-devel
Cc: bmarzins, thornber, linux-kernel, stable, den
From: Denis V. Lunev <den@openvz.org>
An rpc reaches the worker in two steps: the caller puts it on the rpc
list, then wake_worker() queues the work unless the target is
suspended. stop_worker() raises that flag and drains the workqueue with
no ordering against either step, so an rpc can land on both sides of
the drain.
An rpc queued before the flag is raised, whose wake_worker() runs after
it, is never served. The caller waits for a completion that only the
next resume can deliver, and it waits holding the table srcu, so a
reload blocks in dm_swap_table() and the device can no longer be
reloaded or removed.
An rpc whose wake_worker() read the flag as clear can instead queue the
work after drain_workqueue() has returned. The worker then commits the
metadata beside the commit era_postsuspend() runs in its own thread.
Both commits allocate from the same space map and take the same block,
which corrupts it, and every commit after that fails:
device-mapper: space map common: unable to decrement block
device-mapper: era: metadata_commit: pre commit failed
Add the rpc and queue the work under the rpc lock, take that lock to
raise the flag, and refuse an rpc that arrives once it is raised. An
rpc that made it onto the list is then queued before the drain waits
for it.
Userspace sees one change. A status query on a suspended era device
used to block until the device was resumed, and now reports the target
in error.
Fixes: eec40579d848 ("dm: add era target")
Cc: stable@vger.kernel.org
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-era-target.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c
index ea499adca4ce..29b0602e7849 100644
--- a/drivers/md/dm-era-target.c
+++ b/drivers/md/dm-era-target.c
@@ -1389,10 +1389,14 @@ static int perform_rpc(struct era *era, struct rpc *rpc)
init_completion(&rpc->complete);
spin_lock(&era->rpc_lock);
+ if (atomic_read(&era->suspended)) {
+ spin_unlock(&era->rpc_lock);
+ return -EBUSY;
+ }
list_add(&rpc->list, &era->rpc_calls);
+ queue_work(era->wq, &era->worker);
spin_unlock(&era->rpc_lock);
- wake_worker(era);
wait_for_completion(&rpc->complete);
return rpc->result;
@@ -1427,7 +1431,10 @@ static void start_worker(struct era *era)
static void stop_worker(struct era *era)
{
+ spin_lock(&era->rpc_lock);
atomic_set(&era->suspended, 1);
+ spin_unlock(&era->rpc_lock);
+
drain_workqueue(era->wq);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 3/3] dm era: construct the target suspended
2026-11-24 12:25 [PATCH v2 0/3] dm era: a metadata device that never comes back Denis V. Lunev
2026-11-24 12:25 ` [PATCH v2 1/3] dm persistent data: put back the reference a failed shadow dropped Denis V. Lunev
2026-11-24 12:26 ` [PATCH v2 2/3] dm era: refuse metadata rpcs once the target is suspended Denis V. Lunev
@ 2026-11-24 12:26 ` Denis V. Lunev
2 siblings, 0 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-24 12:26 UTC (permalink / raw)
To: agk, snitzer, mpatocka, dm-devel
Cc: bmarzins, thornber, linux-kernel, stable, den
From: Denis V. Lunev <den@openvz.org>
era_preresume() resizes the era array and commits the metadata in the
thread that resumes the device, and starts the worker only once that is
done. That is safe only while the worker cannot run, and nothing makes
it so: struct era is zeroed, so era->suspended reads as running from
the moment the target is constructed, and an rpc arriving before the
resume wakes the worker alongside the resize. Both allocate from the
same space map and take the same metadata block, which corrupts it:
device-mapper: block manager: validator mismatch (old=array vs new=index)
device-mapper: space map common: unable to decrement block
device-mapper: era: metadata_commit: pre commit failed
Every commit after that fails the same way, the target reports "era
Error", and the writes it tracks fail, which takes the workload's
filesystem read-only.
Userspace gets there without trying. multipathd asks every
device-mapper target appearing on the node for its status, over its own
uevent socket, to learn whether the target is a multipath map, so a
target is asked exactly while it resumes.
Mark the target suspended when it is constructed, which is the state
start_worker() already assumes it is leaving. The resize and the commit
then run with the worker held back, as they must, and a status query in
that window is reported busy rather than served beside them.
Fixes: cca2c6aebe86 ("dm era: only resize metadata in preresume")
Cc: stable@vger.kernel.org # v5.12+
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-era-target.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c
index 29b0602e7849..d40a98169b04 100644
--- a/drivers/md/dm-era-target.c
+++ b/drivers/md/dm-era-target.c
@@ -1557,6 +1557,7 @@ static int era_ctr(struct dm_target *ti, unsigned int argc, char **argv)
spin_lock_init(&era->rpc_lock);
INIT_LIST_HEAD(&era->rpc_calls);
+ atomic_set(&era->suspended, 1);
ti->private = era;
ti->num_flush_bios = 1;
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread