Skip to content
/ linux Public

Commit fb49f20

Browse files
Mikulas PatockaSasha Levin
authored andcommitted
dm-integrity: fix recalculation in bitmap mode
[ Upstream commit 118ba36 ] There's a logic quirk in the handling of suspend in the bitmap mode: This is the sequence of calls if we are reloading a dm-integrity table: * dm_integrity_ctr reads a superblock with the flag SB_FLAG_DIRTY_BITMAP set. * dm_integrity_postsuspend initializes a journal and clears the flag SB_FLAG_DIRTY_BITMAP. * dm_integrity_resume sees the superblock with SB_FLAG_DIRTY_BITMAP set - thus it interprets the journal as if it were a bitmap. This quirk causes recalculation problem if the user increases the size of the device in the bitmap mode. Fix this by reading a fresh copy on the superblock in dm_integrity_resume. This commit also fixes another logic quirk - the branch that sets bitmap bits if the device was extended should only be executed if the flag SB_FLAG_DIRTY_BITMAP is set. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Tested-by: Ondrej Kozina <okozina@redhat.com> Fixes: 468dfca ("dm integrity: add a bitmap mode") Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent de79346 commit fb49f20

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/md/dm-integrity.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,14 +3258,27 @@ static void dm_integrity_resume(struct dm_target *ti)
32583258
struct dm_integrity_c *ic = ti->private;
32593259
__u64 old_provided_data_sectors = le64_to_cpu(ic->sb->provided_data_sectors);
32603260
int r;
3261+
__le32 flags;
32613262

32623263
DEBUG_print("resume\n");
32633264

32643265
ic->wrote_to_journal = false;
32653266

3267+
flags = ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING);
3268+
r = sync_rw_sb(ic, REQ_OP_READ);
3269+
if (r)
3270+
dm_integrity_io_error(ic, "reading superblock", r);
3271+
if ((ic->sb->flags & flags) != flags) {
3272+
ic->sb->flags |= flags;
3273+
r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
3274+
if (unlikely(r))
3275+
dm_integrity_io_error(ic, "writing superblock", r);
3276+
}
3277+
32663278
if (ic->provided_data_sectors != old_provided_data_sectors) {
32673279
if (ic->provided_data_sectors > old_provided_data_sectors &&
32683280
ic->mode == 'B' &&
3281+
ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP) &&
32693282
ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit) {
32703283
rw_journal_sectors(ic, REQ_OP_READ, 0,
32713284
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);

0 commit comments

Comments
 (0)