[PATCH 2/2] dm-integrity: don't mark the bitmap clean on a failed target

From: Genjian

Date: Mon Nov 23 2026 - 07:43:27 EST


From: Genjian Zhang <zhanggenjian@xxxxxxxxxx>

In bitmap mode, dm_integrity_postsuspend() clears SB_FLAG_DIRTY_BITMAP
and writes the superblock even when the target has already failed. If
resume rejected a changed superblock, this write can overwrite it with
the constructor's saved copy.

Check the target's failure state after init_journal() so that a journal
write error during initialization also prevents the bitmap from being
marked clean.

Fixes: 468dfca38b1a ("dm integrity: add a bitmap mode")
Signed-off-by: Genjian Zhang <zhanggenjian@xxxxxxxxxx>
---
drivers/md/dm-integrity.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index b17bb9da9195..0964d21c3c44 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -3852,10 +3852,12 @@ static void dm_integrity_postsuspend(struct dm_target *ti)
#if 1
/* set to 0 to test bitmap replay code */
init_journal(ic, 0, ic->journal_sections, 0);
- ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
- r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
- if (unlikely(r))
- dm_integrity_io_error(ic, "writing superblock", r);
+ if (!dm_integrity_failed(ic)) {
+ ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
+ r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
+ if (unlikely(r))
+ dm_integrity_io_error(ic, "writing superblock", r);
+ }
#endif
}

--
2.25.1