[PATCH 2/2] btrfs: Allow error injection on btrfs_data_csum_ok
From: Song Chen
Date: Wed Jul 01 2026 - 22:39:52 EST
btrfs_data_csum_ok validates the checksum of a data block
after a read I/O completes. A mismatch between the on-disk
checksum and the one computed from the read data indicates
silent data corruption, which can be caused by bit flips due
to DRAM errors, storage media degradation, or bus transmission
faults.
Testing the error handling path that responds to such
corruption, including any warning output and uspace
notification, normally requires reproducing the hardware
fault, which is not always feasible.
Mark btrfs_data_csum_ok with ALLOW_ERROR_INJECTION so that
the fail_function infrastructure can override its return value
to false, simulating a checksum mismatch without requiring
actual data corruption. This enables validation of the full
error detection and reporting path in a controlled environment.
Usage:
cd /sys/kernel/debug/fail_function
echo btrfs_data_csum_ok > inject
echo 0 > btrfs_data_csum_ok/retval
echo 100 > probability
echo N > times
Signed-off-by: Song Chen <chensong_2000@xxxxxxx>
---
fs/btrfs/inode.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 906d5c21ebc4..6be3e920b954 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3574,6 +3574,7 @@ bool btrfs_data_csum_ok(struct btrfs_bio *bbio, struct btrfs_device *dev,
memzero_page(phys_to_page(paddrs[i]), offset_in_page(paddrs[i]), step);
return false;
}
+ALLOW_ERROR_INJECTION(btrfs_data_csum_ok, FALSE);
/*
* Perform a delayed iput on @inode.
--
2.43.0