diff mbox series

[09/13] btrfs: handle RAID56 read repair differently

Message ID 80006286af884f8aec7e53f6a0c87b9f968ef920.1651559986.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: make read repair work in synchronous mode | expand

Commit Message

Qu Wenruo May 3, 2022, 6:49 a.m. UTC
Our current read repair facility does its work completely relying on
mirror number.
And for repaired sector, it will write the correct data back to the bad
mirror.

This works great for mirror based profiles, but for RAID56 it's a
different story.

Partial write in btrfs raid56 will lead to unconditional RMW, completely
ignoring the mirror number (which is to indicate the corrupted data
stripe number).

This will cause us to read back the corrupted data on-disk, and result
further corruption.

To address it, we introduce btrfs_read_repair_ctrl::is_raid56, and for
RAID56 read-repair, we fallback to the tried-and-tree
btrfs_repair_io_failure().

That function handles RAID56 by using MAP_READ for btrfs_map_block() and
directly write the correct data back to disk, avoiding the RMW problem.

Unfortunately we lose the asynchronous bio assembly/submission, but it
should still be more or less acceptable considering RAID56 is really an
odd ball here.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/read-repair.c | 26 ++++++++++++++++++++++++++
 fs/btrfs/read-repair.h |  2 ++
 2 files changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/fs/btrfs/read-repair.c b/fs/btrfs/read-repair.c
index aecdc4ee54ba..e1b11990a480 100644
--- a/fs/btrfs/read-repair.c
+++ b/fs/btrfs/read-repair.c
@@ -55,6 +55,8 @@  void btrfs_read_repair_add_sector(struct inode *inode,
 		ASSERT(ctrl->init_mirror);
 		ctrl->num_copies = btrfs_num_copies(fs_info, ctrl->logical,
 						    sectorsize);
+		ctrl->is_raid56 = btrfs_is_parity_mirror(fs_info,
+						ctrl->logical, sectorsize);
 		init_waitqueue_head(&ctrl->io_wait);
 		atomic_set(&ctrl->io_bytes, 0);
 		/*
@@ -153,6 +155,30 @@  static void read_repair_bio_add_sector(struct btrfs_read_repair_ctrl *ctrl,
 	if (opf == REQ_OP_WRITE) {
 		if (btrfs_repair_one_zone(fs_info, ctrl->logical))
 			return;
+
+		/*
+		 * For RAID56, we can not just write the bad data back, as
+		 * any write will trigger RMW and read back the corrrupted
+		 * on-disk stripe, causing further damage.
+		 * So here we do special repair for raid56.
+		 *
+		 * And unfortunately, this repair is very low level and not
+		 * compatible with the rest of the mirror based repair.
+		 * So it's still done in synchronous mode using
+		 * btrfs_repair_io_failure().
+		 */
+		if (ctrl->is_raid56) {
+			const u64 logical = ctrl->logical +
+					(sector_nr << fs_info->sectorsize_bits);
+			const u64 file_offset = ctrl->file_offset +
+					(sector_nr << fs_info->sectorsize_bits);
+
+			btrfs_repair_io_failure(fs_info,
+					btrfs_ino(BTRFS_I(ctrl->inode)),
+					file_offset, fs_info->sectorsize,
+					logical, page, pgoff, mirror);
+			return;
+		}
 	}
 
 	/* Check if the sector can be added to the last bio */
diff --git a/fs/btrfs/read-repair.h b/fs/btrfs/read-repair.h
index 3e1430489f89..6cc816e2ce4a 100644
--- a/fs/btrfs/read-repair.h
+++ b/fs/btrfs/read-repair.h
@@ -42,6 +42,8 @@  struct btrfs_read_repair_ctrl {
 	 * at bio allocation time.
 	 */
 	bool error;
+
+	bool is_raid56;
 };
 
 int btrfs_read_repair_alloc_bitmaps(struct btrfs_fs_info *fs_info,