* add tests for file system on devices using protection information v3
@ 2026-08-31 6:45 Christoph Hellwig
2026-08-31 6:45 ` [PATCH 1/6] common/scsi_debug: don't slow down I/O Christoph Hellwig
` (5 more replies)
0 siblings, 6 replies; 17+ messages in thread
From: Christoph Hellwig @ 2026-08-31 6:45 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
Hi all,
this series adds support to exercise I/O on file systems using protection
information in the device, including that corruption is properly
reported.
The second test requires a patch to inject corruption into scsi_debug
that was posted to the linux-scsi list.
Changes since v2:
- factor out a _bdev_disk_name helper
Changes since v1:
- fix various requirements
- use _exit
- cleanup up the scsi_debug options building
- add a new PI group
- mark one of the new tests dangerous as it can crash Linux 7.2 and earlier
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 1/6] common/scsi_debug: don't slow down I/O
2026-08-31 6:45 add tests for file system on devices using protection information v3 Christoph Hellwig
@ 2026-08-31 6:45 ` Christoph Hellwig
2026-08-31 6:45 ` [PATCH 2/6] common: factor out a _bdev_disk_name helper Christoph Hellwig
` (4 subsequent siblings)
5 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2026-08-31 6:45 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
scsi_debug by defaults delays I/O and doesn't support multi-page I/O.
Flipping these defaults speed up each test using scsi_debug by more than
an order of magnitute on my test systems.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
common/scsi_debug | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/common/scsi_debug b/common/scsi_debug
index c3fe7be623fa..af51905dc4ba 100644
--- a/common/scsi_debug
+++ b/common/scsi_debug
@@ -59,9 +59,19 @@ _get_scsi_debug_dev()
let physical=physical/2
let phys_exp=phys_exp+1
done
- opts="sector_size=$logical physblk_exp=$phys_exp lowest_aligned=$unaligned dev_size_mb=$size $@"
- echo "scsi_debug options $opts" >> $seqres.full
- modprobe scsi_debug $opts
+
+ local opts=(
+ "sector_size=$logical"
+ "physblk_exp=$phys_exp"
+ "lowest_aligned=$unaligned"
+ "dev_size_mb=$size"
+ "delay=0"
+ "clustering=1"
+ )
+ opts+=("$@")
+
+ echo "scsi_debug options ${opts[*]}" >> $seqres.full
+ modprobe scsi_debug "${opts[@]}"
[ $? -eq 0 ] || _fail "scsi_debug modprobe failed"
$UDEV_SETTLE_PROG
device=`grep -wl scsi_debug /sys/block/sd*/device/model | awk -F / '{print $4}'`
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 2/6] common: factor out a _bdev_disk_name helper
2026-08-31 6:45 add tests for file system on devices using protection information v3 Christoph Hellwig
2026-08-31 6:45 ` [PATCH 1/6] common/scsi_debug: don't slow down I/O Christoph Hellwig
@ 2026-08-31 6:45 ` Christoph Hellwig
2026-08-31 17:03 ` Darrick J. Wong
2026-08-31 6:45 ` [PATCH 3/6] common: add a _sysfs_block_integrity_path helper Christoph Hellwig
` (3 subsequent siblings)
5 siblings, 1 reply; 17+ messages in thread
From: Christoph Hellwig @ 2026-08-31 6:45 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
This will be reused to look for the integrity subdirectory soon.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
common/rc | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/common/rc b/common/rc
index 8add0eedf942..2fa7ddebd8fd 100644
--- a/common/rc
+++ b/common/rc
@@ -5233,28 +5233,35 @@ _sysfs_dev()
echo /sys/dev/block/$maj:$min
}
-# Get the sysfs queue path for a block device, handling partitions correctly.
-_sysfs_queue_path()
+#
+# Get the name for the main disk block device given an arbitrary blockdevice
+# /dev/ entry
+#
+_bdev_disk_name()
{
- local dev parent
- dev=$(_short_dev "$1")
+ local dev=$(_short_dev "$1")
# For partitions, queue details are in the parent device's sysfs dir
if [ -e "/sys/class/block/$dev/partition" ]; then
- parent=$(basename "$(readlink -f /sys/class/block/$dev/..)")
- else
- parent="$dev"
+ dev=$(basename "$(readlink -f /sys/class/block/$dev/..)")
fi
- local queue_path="/sys/block/$parent/queue"
+ echo "$dev"
+}
+
+# Get the sysfs queue path for a block device, handling partitions correctly.
+_sysfs_queue_path()
+{
+ local disk=$(_bdev_disk_name "$1")
+ local queue_path="/sys/block/$disk/queue"
# Verify the path exists before returning
if [ -e "$queue_path" ]; then
echo "$queue_path"
return 0
- else
- return 1
fi
+
+ return 1
}
# Get the minimum block size of a file. Usually this is the
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 3/6] common: add a _sysfs_block_integrity_path helper
2026-08-31 6:45 add tests for file system on devices using protection information v3 Christoph Hellwig
2026-08-31 6:45 ` [PATCH 1/6] common/scsi_debug: don't slow down I/O Christoph Hellwig
2026-08-31 6:45 ` [PATCH 2/6] common: factor out a _bdev_disk_name helper Christoph Hellwig
@ 2026-08-31 6:45 ` Christoph Hellwig
2026-08-31 17:03 ` Darrick J. Wong
2026-08-31 6:45 ` [PATCH 4/6] add a "pi" group Christoph Hellwig
` (2 subsequent siblings)
5 siblings, 1 reply; 17+ messages in thread
From: Christoph Hellwig @ 2026-08-31 6:45 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
Add a helper function to find the sysfs integrity directory for a given
block device.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
common/rc | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/common/rc b/common/rc
index 2fa7ddebd8fd..5e709dd79993 100644
--- a/common/rc
+++ b/common/rc
@@ -5264,6 +5264,21 @@ _sysfs_queue_path()
return 1
}
+# Get the sysfs block device integrity/ path for a block device, handling
+# partitions correctly.
+_sysfs_block_integrity_path()
+{
+ local disk=$(_bdev_disk_name "$1")
+ local integrity_path="/sys/block/$disk/integrity"
+
+ if [ -e "$integrity_path" ]; then
+ echo "$integrity_path"
+ return 0
+ fi
+
+ return 1
+}
+
# Get the minimum block size of a file. Usually this is the
# minimum fs block size, but some filesystems (ocfs2) do block
# mappings in larger units.
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 4/6] add a "pi" group
2026-08-31 6:45 add tests for file system on devices using protection information v3 Christoph Hellwig
` (2 preceding siblings ...)
2026-08-31 6:45 ` [PATCH 3/6] common: add a _sysfs_block_integrity_path helper Christoph Hellwig
@ 2026-08-31 6:45 ` Christoph Hellwig
2026-08-31 6:45 ` [PATCH 5/6] generic: test I/O on devices with T10 protection information Christoph Hellwig
2026-08-31 6:45 ` [PATCH 6/6] generic: test corruption detection using " Christoph Hellwig
5 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2026-08-31 6:45 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
Add a group for tests exercising T10 protection information.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
doc/group-names.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/doc/group-names.txt b/doc/group-names.txt
index 424e2c4a1ca6..ef6b8f51cf87 100644
--- a/doc/group-names.txt
+++ b/doc/group-names.txt
@@ -137,6 +137,7 @@ tape dump and restore with a tape
tempfsid temporary fsid
thin thin provisioning
trim FITRIM ioctl
+pi Protection Information
udf UDF functionality tests
union tests from the unionmount test suite
unlink O_TMPFILE unlinked files
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 5/6] generic: test I/O on devices with T10 protection information
2026-08-31 6:45 add tests for file system on devices using protection information v3 Christoph Hellwig
` (3 preceding siblings ...)
2026-08-31 6:45 ` [PATCH 4/6] add a "pi" group Christoph Hellwig
@ 2026-08-31 6:45 ` Christoph Hellwig
2026-09-01 6:38 ` Kanchan Joshi
2026-09-03 6:01 ` Anuj Gupta/Anuj Gupta
2026-08-31 6:45 ` [PATCH 6/6] generic: test corruption detection using " Christoph Hellwig
5 siblings, 2 replies; 17+ messages in thread
From: Christoph Hellwig @ 2026-08-31 6:45 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
Add a test that runs fsx in buffered and direct I/O mode on T10 PI
type 1, 2, 3 with and without strip/insert using scsi_debug.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
tests/generic/2301 | 94 ++++++++++++++++++++++++++++++++++++++++++
tests/generic/2301.out | 73 ++++++++++++++++++++++++++++++++
2 files changed, 167 insertions(+)
create mode 100755 tests/generic/2301
create mode 100644 tests/generic/2301.out
diff --git a/tests/generic/2301 b/tests/generic/2301
new file mode 100755
index 000000000000..6bf026bfeb60
--- /dev/null
+++ b/tests/generic/2301
@@ -0,0 +1,94 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Christoph Hellwig
+#
+# FS QA Test No. 2301
+#
+# Basix FSX sanity check when using T10 protection information
+#
+. ./common/preamble
+_begin_fstest auto rw pi dangerous
+
+_cleanup()
+{
+ cd /
+ rm -r -f $tmp.*
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+. ./common/scsi_debug
+
+_require_debugfs
+_require_scsi_debug
+# If TEST_DEV is block device, make sure current fs is a localfs which can be
+# written on scsi_debug device
+_require_test
+_require_block_device $TEST_DEV
+_require_odirect
+
+_fixed_by_kernel_commit 8a8685b32c07 \
+ "iomap: don't free integrity payload that doesn't exist"
+
+size=$(_small_fs_size_mb 256)
+
+# like run_fsx(), but using a custom path
+fsx_run()
+{
+ _run_fsx_on_file $SCSI_DEBUG_MNT/junk $@ || _exit 1
+}
+
+test_dif()
+{
+ local pi_type=$1
+ local pi_enable="$2"
+
+ scsi_debug_pi_opts="write_same_length=0 dif=${pi_type} dix=1"
+ SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size $scsi_debug_pi_opts`
+
+ SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
+ rm -rf $SCSI_DEBUG_MNT
+ mkdir $SCSI_DEBUG_MNT
+
+ _mkfs_dev $SCSI_DEBUG_DEV || \
+ _fail "Can't make $FSTYP on DIF-enabled scsi_debug device"
+ run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT
+ bsize=$($here/src/min_dio_alignment $SCSI_DEBUG_MNT $SCSI_DEBUG_DEV)
+
+ local integrity_path="$(_sysfs_block_integrity_path $SCSI_DEBUG_DEV)"
+ echo $pi_enable > $integrity_path/read_verify
+ echo $pi_enable > $integrity_path/write_generate
+
+ # fsx load similar to generic/091
+ echo "Testing direct I/O for DIF type $pi_type (enabled: $pi_enable)"
+ local dio_opts="-r PSIZE -t BSIZE -w BSIZE"
+ fsx_run -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+ fsx_run -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+ fsx_run -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+ fsx_run -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+ fsx_run -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+ fsx_run -N 10000 -o 128000 -l 500000 -r BSIZE -w BSIZE -Z -W
+
+ # fsx load similar to generic/091 but using buffered I/O
+ echo "Testing buffered I/O for DIF type $pi_type (enabled: $pi_enable)"
+ fsx_run -N 10000 -l 500000
+ fsx_run -N 10000 -o 8192 -l 500000
+ fsx_run -N 10000 -o 32768 -l 500000
+ fsx_run -N 10000 -o 128000 -l 500000
+
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+# Test with PI fully enabled
+test_dif 1 1
+test_dif 2 1
+test_dif 3 1
+
+# Test with strip / insert in the HBA
+test_dif 1 0
+test_dif 2 0
+test_dif 3 0
+
+# success, all done
+_exit 0
diff --git a/tests/generic/2301.out b/tests/generic/2301.out
new file mode 100644
index 000000000000..dda88676a219
--- /dev/null
+++ b/tests/generic/2301.out
@@ -0,0 +1,73 @@
+QA output created by 2301
+Testing direct I/O for DIF type 1 (enabled: 1)
+fsx -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 128000 -l 500000 -r BSIZE -w BSIZE -Z -W
+Testing buffered I/O for DIF type 1 (enabled: 1)
+fsx -N 10000 -l 500000
+fsx -N 10000 -o 8192 -l 500000
+fsx -N 10000 -o 32768 -l 500000
+fsx -N 10000 -o 128000 -l 500000
+Testing direct I/O for DIF type 2 (enabled: 1)
+fsx -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 128000 -l 500000 -r BSIZE -w BSIZE -Z -W
+Testing buffered I/O for DIF type 2 (enabled: 1)
+fsx -N 10000 -l 500000
+fsx -N 10000 -o 8192 -l 500000
+fsx -N 10000 -o 32768 -l 500000
+fsx -N 10000 -o 128000 -l 500000
+Testing direct I/O for DIF type 3 (enabled: 1)
+fsx -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 128000 -l 500000 -r BSIZE -w BSIZE -Z -W
+Testing buffered I/O for DIF type 3 (enabled: 1)
+fsx -N 10000 -l 500000
+fsx -N 10000 -o 8192 -l 500000
+fsx -N 10000 -o 32768 -l 500000
+fsx -N 10000 -o 128000 -l 500000
+Testing direct I/O for DIF type 1 (enabled: 0)
+fsx -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 128000 -l 500000 -r BSIZE -w BSIZE -Z -W
+Testing buffered I/O for DIF type 1 (enabled: 0)
+fsx -N 10000 -l 500000
+fsx -N 10000 -o 8192 -l 500000
+fsx -N 10000 -o 32768 -l 500000
+fsx -N 10000 -o 128000 -l 500000
+Testing direct I/O for DIF type 2 (enabled: 0)
+fsx -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 128000 -l 500000 -r BSIZE -w BSIZE -Z -W
+Testing buffered I/O for DIF type 2 (enabled: 0)
+fsx -N 10000 -l 500000
+fsx -N 10000 -o 8192 -l 500000
+fsx -N 10000 -o 32768 -l 500000
+fsx -N 10000 -o 128000 -l 500000
+Testing direct I/O for DIF type 3 (enabled: 0)
+fsx -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 8192 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 32768 -l 500000 -r BSIZE -w BSIZE -Z -R -W
+fsx -N 10000 -o 128000 -l 500000 -r BSIZE -w BSIZE -Z -W
+Testing buffered I/O for DIF type 3 (enabled: 0)
+fsx -N 10000 -l 500000
+fsx -N 10000 -o 8192 -l 500000
+fsx -N 10000 -o 32768 -l 500000
+fsx -N 10000 -o 128000 -l 500000
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 6/6] generic: test corruption detection using T10 protection information
2026-08-31 6:45 add tests for file system on devices using protection information v3 Christoph Hellwig
` (4 preceding siblings ...)
2026-08-31 6:45 ` [PATCH 5/6] generic: test I/O on devices with T10 protection information Christoph Hellwig
@ 2026-08-31 6:45 ` Christoph Hellwig
2026-09-03 6:00 ` Anuj Gupta/Anuj Gupta
5 siblings, 1 reply; 17+ messages in thread
From: Christoph Hellwig @ 2026-08-31 6:45 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
Add a test that simulates bit flips in data and misdirected writes and
checks that file systems detect it when run on devices using protection
information.
This requires the new scsi_debug corruption injection.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
tests/generic/2302 | 128 +++++++++++++++++++++++++++++++++++++++++
tests/generic/2302.out | 21 +++++++
2 files changed, 149 insertions(+)
create mode 100755 tests/generic/2302
create mode 100644 tests/generic/2302.out
diff --git a/tests/generic/2302 b/tests/generic/2302
new file mode 100755
index 000000000000..4a9d9165174b
--- /dev/null
+++ b/tests/generic/2302
@@ -0,0 +1,128 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Christoph Hellwig
+#
+# FS QA Test No. 2302
+#
+# Test that T10 DIF detects bitflips and misplaced writes.
+#
+. ./common/preamble
+_begin_fstest auto rw pi
+
+_cleanup()
+{
+ cd /
+ rm -r -f $tmp.*
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+. ./common/scsi_debug
+. ./common/filter
+
+_require_debugfs
+_require_scsi_debug
+# If TEST_DEV is block device, make sure current fs is a localfs which can be
+# written on scsi_debug device
+_require_test
+_require_block_device $TEST_DEV
+_require_xfs_io_command fiemap
+_require_odirect
+
+# FIEMAP on Btrfs returns logical addresses within the filesystem's address
+# space, not physical device offsets. Writing to these offsets on $SCRATCH_DEV
+# would corrupt the filesystem in multi-device setups.
+_exclude_fs btrfs
+
+size=$(_small_fs_size_mb 256)
+
+test_dif()
+{
+ local pi_type=$1
+ local last=$2
+ local bit_errors=$3
+ local reftag_adjust=$4
+
+ echo -n "Testing DIF type $pi_type "
+ if [ "$bit_errors" -gt "0" ]; then
+ echo -n "bit errors ($bit_errors) in "
+ fi
+ if [ "$reftag_adjust" -ne "0" ]; then
+ echo -n "reftag adjustment by $reftag_adjust in "
+ fi
+ if [ "$last" -eq 1 ]; then
+ echo "last sector"
+ else
+ echo "first sector"
+ fi
+
+ scsi_debug_pi_opts="write_same_length=0 dif=${pi_type} dix=1"
+ SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size $scsi_debug_pi_opts`
+
+ SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
+ rm -rf $SCSI_DEBUG_MNT
+ mkdir $SCSI_DEBUG_MNT
+
+ _mkfs_dev $SCSI_DEBUG_DEV || \
+ _fail "Can't make $FSTYP on DIF-enabled scsi_debug device"
+ run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT
+
+ local blksz=$(_get_block_size $SCSI_DEBUG_MNT)
+ local testfile="$SCSI_DEBUG_MNT/test"
+
+ $XFS_IO_PROG -d -f \
+ -c "pwrite -S 0x66 0 $((128 * blksz))" \
+ -c fsync \
+ $testfile >> $seqres.full 2>&1
+
+ local phys_blk=$(_get_file_extent_sector $testfile 0)
+ if [ -z "$phys_blk" ]; then
+ _fail "$test_name: failed to get physical block offset via fiemap"
+ fi
+
+ local dev=$(_short_dev $SCSI_DEBUG_DEV)
+ local debugfs_dir=$(ls /sys/block/$dev/device/scsi_device/)
+ local debugfs_file="/sys/kernel/debug/scsi_debug/$debugfs_dir/corrupt"
+
+ if [ ! -f "$debugfs_file" ]; then
+ _notrun "scsi_debug corruption injection not supported"
+ fi
+
+ if [ "$last" -eq 1 ]; then
+ echo "adding to $phys_blk" >> $seqres.full
+ phys_blk=$((phys_blk + 127))
+ fi
+
+ echo "lba=$phys_blk,num=1,bit_errors=$bit_errors,reftag_adjust=$reftag_adjust" \
+ > $debugfs_file
+
+ $XFS_IO_PROG -d -f \
+ -c "pread 0 $((128 * blksz))" \
+ $testfile
+
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+# test data corruption in first block
+test_dif 1 0 2 0
+test_dif 2 0 2 0
+test_dif 3 0 2 0
+
+# test data corruption in last block
+test_dif 1 1 2 0
+test_dif 2 1 2 0
+test_dif 3 1 2 0
+
+
+# Note: Type 3 doesn't have a refrag, so don't test it
+
+# reftag mismatch in first block
+test_dif 1 0 0 8
+test_dif 2 0 0 8
+
+# reftag mismatch in last block
+test_dif 1 1 0 8
+test_dif 2 1 0 8
+
+_exit 0
diff --git a/tests/generic/2302.out b/tests/generic/2302.out
new file mode 100644
index 000000000000..03b68d904943
--- /dev/null
+++ b/tests/generic/2302.out
@@ -0,0 +1,21 @@
+QA output created by 2302
+Testing DIF type 1 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 3 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 3 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 reftag adjustment by 8 in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 reftag adjustment by 8 in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 reftag adjustment by 8 in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 reftag adjustment by 8 in last sector
+pread: Invalid or incomplete multibyte or wide character
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 2/6] common: factor out a _bdev_disk_name helper
2026-08-31 6:45 ` [PATCH 2/6] common: factor out a _bdev_disk_name helper Christoph Hellwig
@ 2026-08-31 17:03 ` Darrick J. Wong
0 siblings, 0 replies; 17+ messages in thread
From: Darrick J. Wong @ 2026-08-31 17:03 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Zorro Lang, fstests, Martin K. Petersen, Kanchan Joshi,
Anuj Gupta, John Garry, linux-scsi
On Mon, Aug 31, 2026 at 09:45:46AM +0300, Christoph Hellwig wrote:
> This will be reused to look for the integrity subdirectory soon.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good to me, thanks for refactoring this!
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> common/rc | 27 +++++++++++++++++----------
> 1 file changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/common/rc b/common/rc
> index 8add0eedf942..2fa7ddebd8fd 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -5233,28 +5233,35 @@ _sysfs_dev()
> echo /sys/dev/block/$maj:$min
> }
>
> -# Get the sysfs queue path for a block device, handling partitions correctly.
> -_sysfs_queue_path()
> +#
> +# Get the name for the main disk block device given an arbitrary blockdevice
> +# /dev/ entry
> +#
> +_bdev_disk_name()
> {
> - local dev parent
> - dev=$(_short_dev "$1")
> + local dev=$(_short_dev "$1")
>
> # For partitions, queue details are in the parent device's sysfs dir
> if [ -e "/sys/class/block/$dev/partition" ]; then
> - parent=$(basename "$(readlink -f /sys/class/block/$dev/..)")
> - else
> - parent="$dev"
> + dev=$(basename "$(readlink -f /sys/class/block/$dev/..)")
> fi
>
> - local queue_path="/sys/block/$parent/queue"
> + echo "$dev"
> +}
> +
> +# Get the sysfs queue path for a block device, handling partitions correctly.
> +_sysfs_queue_path()
> +{
> + local disk=$(_bdev_disk_name "$1")
> + local queue_path="/sys/block/$disk/queue"
>
> # Verify the path exists before returning
> if [ -e "$queue_path" ]; then
> echo "$queue_path"
> return 0
> - else
> - return 1
> fi
> +
> + return 1
> }
>
> # Get the minimum block size of a file. Usually this is the
> --
> 2.53.0
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] common: add a _sysfs_block_integrity_path helper
2026-08-31 6:45 ` [PATCH 3/6] common: add a _sysfs_block_integrity_path helper Christoph Hellwig
@ 2026-08-31 17:03 ` Darrick J. Wong
0 siblings, 0 replies; 17+ messages in thread
From: Darrick J. Wong @ 2026-08-31 17:03 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Zorro Lang, fstests, Martin K. Petersen, Kanchan Joshi,
Anuj Gupta, John Garry, linux-scsi
On Mon, Aug 31, 2026 at 09:45:47AM +0300, Christoph Hellwig wrote:
> Add a helper function to find the sysfs integrity directory for a given
> block device.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good now,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> common/rc | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/common/rc b/common/rc
> index 2fa7ddebd8fd..5e709dd79993 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -5264,6 +5264,21 @@ _sysfs_queue_path()
> return 1
> }
>
> +# Get the sysfs block device integrity/ path for a block device, handling
> +# partitions correctly.
> +_sysfs_block_integrity_path()
> +{
> + local disk=$(_bdev_disk_name "$1")
> + local integrity_path="/sys/block/$disk/integrity"
> +
> + if [ -e "$integrity_path" ]; then
> + echo "$integrity_path"
> + return 0
> + fi
> +
> + return 1
> +}
> +
> # Get the minimum block size of a file. Usually this is the
> # minimum fs block size, but some filesystems (ocfs2) do block
> # mappings in larger units.
> --
> 2.53.0
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/6] generic: test I/O on devices with T10 protection information
2026-08-31 6:45 ` [PATCH 5/6] generic: test I/O on devices with T10 protection information Christoph Hellwig
@ 2026-09-01 6:38 ` Kanchan Joshi
2026-09-07 5:48 ` Christoph Hellwig
2026-09-03 6:01 ` Anuj Gupta/Anuj Gupta
1 sibling, 1 reply; 17+ messages in thread
From: Kanchan Joshi @ 2026-09-01 6:38 UTC (permalink / raw)
To: Christoph Hellwig, Zorro Lang
Cc: fstests, Martin K. Petersen, Anuj Gupta, John Garry,
Darrick J. Wong, linux-scsi
On 8/31/2026 12:15 PM, Christoph Hellwig wrote:
> +test_dif()
> +{
> + local pi_type=$1
> + local pi_enable="$2"
> +
> + scsi_debug_pi_opts="write_same_length=0 dif=${pi_type} dix=1"
> + SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size $scsi_debug_pi_opts`
> +
> + SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
> + rm -rf $SCSI_DEBUG_MNT
> + mkdir $SCSI_DEBUG_MNT
> +
> + _mkfs_dev $SCSI_DEBUG_DEV || \
> + _fail "Can't make $FSTYP on DIF-enabled scsi_debug device"
> + run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT
> + bsize=$($here/src/min_dio_alignment $SCSI_DEBUG_MNT $SCSI_DEBUG_DEV)
bsize remains unused.
> +
> + local integrity_path="$(_sysfs_block_integrity_path $SCSI_DEBUG_DEV)"
> + echo $pi_enable > $integrity_path/read_verify
> + echo $pi_enable > $integrity_path/write_generate
Can integrity_path be empty when CONFIG_BLK_DEV_INTEGRITY is off?> +
> + # fsx load similar to generic/091
> + echo "Testing direct I/O for DIF type $pi_type (enabled: $pi_enable)"
> + local dio_opts="-r PSIZE -t BSIZE -w BSIZE"
dio_opts is unused.
> + fsx_run -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
Is passing BSIZE correct?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/6] generic: test corruption detection using T10 protection information
2026-08-31 6:45 ` [PATCH 6/6] generic: test corruption detection using " Christoph Hellwig
@ 2026-09-03 6:00 ` Anuj Gupta/Anuj Gupta
2026-09-07 5:49 ` Christoph Hellwig
0 siblings, 1 reply; 17+ messages in thread
From: Anuj Gupta/Anuj Gupta @ 2026-09-03 6:00 UTC (permalink / raw)
To: Christoph Hellwig, Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, John Garry,
Darrick J. Wong, linux-scsi
> + if [ "$last" -eq 1 ]; then
> + echo "adding to $phys_blk" >> $seqres.full
> + phys_blk=$((phys_blk + 127))
last sector for a 4096-byte block size would be 1023 not 127 right?
maybe use something like this to calculate the last sector?
phys_blk=$((phys_blk + (128 * blksz / 512) - 1))
and maybe rename it to phys_sector
> +# Note: Type 3 doesn't have a refrag, so don't test it
s/refrag/reftag
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/6] generic: test I/O on devices with T10 protection information
2026-08-31 6:45 ` [PATCH 5/6] generic: test I/O on devices with T10 protection information Christoph Hellwig
2026-09-01 6:38 ` Kanchan Joshi
@ 2026-09-03 6:01 ` Anuj Gupta/Anuj Gupta
1 sibling, 0 replies; 17+ messages in thread
From: Anuj Gupta/Anuj Gupta @ 2026-09-03 6:01 UTC (permalink / raw)
To: Christoph Hellwig, Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, John Garry,
Darrick J. Wong, linux-scsi
On 8/31/2026 12:15 PM, Christoph Hellwig wrote:
> +#
> +# Basix FSX sanity check when using T10 protection information
> +#
s/Basix/Basic
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/6] generic: test I/O on devices with T10 protection information
2026-09-01 6:38 ` Kanchan Joshi
@ 2026-09-07 5:48 ` Christoph Hellwig
0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2026-09-07 5:48 UTC (permalink / raw)
To: Kanchan Joshi
Cc: Christoph Hellwig, Zorro Lang, fstests, Martin K. Petersen,
Anuj Gupta, John Garry, Darrick J. Wong, linux-scsi
On Tue, Sep 01, 2026 at 12:08:59PM +0530, Kanchan Joshi wrote:
> On 8/31/2026 12:15 PM, Christoph Hellwig wrote:
> > +test_dif()
> > +{
> > + local pi_type=$1
> > + local pi_enable="$2"
> > +
> > + scsi_debug_pi_opts="write_same_length=0 dif=${pi_type} dix=1"
> > + SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size $scsi_debug_pi_opts`
> > +
> > + SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
> > + rm -rf $SCSI_DEBUG_MNT
> > + mkdir $SCSI_DEBUG_MNT
> > +
> > + _mkfs_dev $SCSI_DEBUG_DEV || \
> > + _fail "Can't make $FSTYP on DIF-enabled scsi_debug device"
> > + run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT
> > + bsize=$($here/src/min_dio_alignment $SCSI_DEBUG_MNT $SCSI_DEBUG_DEV)
>
> bsize remains unused.
_run_fsx uses it through the (somewhat odd) BSIZE substitution.
> dio_opts is unused.
Yeah.
>
> > + fsx_run -N 10000 -l 500000 -r BSIZE -w BSIZE -Z -R -W
>
> Is passing BSIZE correct?
See above :)
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/6] generic: test corruption detection using T10 protection information
2026-09-03 6:00 ` Anuj Gupta/Anuj Gupta
@ 2026-09-07 5:49 ` Christoph Hellwig
0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2026-09-07 5:49 UTC (permalink / raw)
To: Anuj Gupta/Anuj Gupta
Cc: Christoph Hellwig, Zorro Lang, fstests, Martin K. Petersen,
Kanchan Joshi, John Garry, Darrick J. Wong, linux-scsi
On Thu, Sep 03, 2026 at 11:30:26AM +0530, Anuj Gupta/Anuj Gupta wrote:
> > + if [ "$last" -eq 1 ]; then
> > + echo "adding to $phys_blk" >> $seqres.full
> > + phys_blk=$((phys_blk + 127))
>
> last sector for a 4096-byte block size would be 1023 not 127 right?
> maybe use something like this to calculate the last sector?
>
> phys_blk=$((phys_blk + (128 * blksz / 512) - 1))
>
> and maybe rename it to phys_sector
Yeah. Currently we force 512 byte blocks when setting up the
scsi_debug device, but it doesn't hurt to be consistent in the
arithmetics.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 6/6] generic: test corruption detection using T10 protection information
2026-09-07 7:58 add tests for file system on devices using protection information v4 Christoph Hellwig
@ 2026-09-07 7:58 ` Christoph Hellwig
2026-09-08 14:36 ` Kanchan Joshi
0 siblings, 1 reply; 17+ messages in thread
From: Christoph Hellwig @ 2026-09-07 7:58 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
Add a test that simulates bit flips in data and misdirected writes and
checks that file systems detect it when run on devices using protection
information.
This requires the new scsi_debug corruption injection.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
tests/generic/2302 | 133 +++++++++++++++++++++++++++++++++++++++++
tests/generic/2302.out | 21 +++++++
2 files changed, 154 insertions(+)
create mode 100755 tests/generic/2302
create mode 100644 tests/generic/2302.out
diff --git a/tests/generic/2302 b/tests/generic/2302
new file mode 100755
index 000000000000..44d779f1d4d9
--- /dev/null
+++ b/tests/generic/2302
@@ -0,0 +1,133 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Christoph Hellwig
+#
+# FS QA Test No. 2302
+#
+# Test that T10 DIF detects bitflips and misplaced writes.
+#
+. ./common/preamble
+_begin_fstest auto rw pi
+
+_cleanup()
+{
+ cd /
+ rm -r -f $tmp.*
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+. ./common/scsi_debug
+. ./common/filter
+
+_require_debugfs
+_require_scsi_debug
+# If TEST_DEV is block device, make sure current fs is a localfs which can be
+# written on scsi_debug device
+_require_test
+_require_block_device $TEST_DEV
+_require_xfs_io_command fiemap
+_require_odirect
+
+# FIEMAP on Btrfs returns logical addresses within the filesystem's address
+# space, not physical device offsets. Writing to these offsets on $SCRATCH_DEV
+# would corrupt the filesystem in multi-device setups.
+_exclude_fs btrfs
+
+size=$(_small_fs_size_mb 256)
+
+test_dif()
+{
+ local pi_type=$1
+ local last=$2
+ local bit_errors=$3
+ local reftag_adjust=$4
+
+ echo -n "Testing DIF type $pi_type "
+ if [ "$bit_errors" -gt "0" ]; then
+ echo -n "bit errors ($bit_errors) in "
+ fi
+ if [ "$reftag_adjust" -ne "0" ]; then
+ echo -n "reftag adjustment by $reftag_adjust in "
+ fi
+ if [ "$last" -eq 1 ]; then
+ echo "last sector"
+ else
+ echo "first sector"
+ fi
+
+ scsi_debug_pi_opts="write_same_length=0 dif=${pi_type} dix=1"
+ SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size $scsi_debug_pi_opts`
+
+ local integrity_path="$(_sysfs_block_integrity_path $SCSI_DEBUG_DEV)"
+ if [ ! -d "$integrity_path" ]; then
+ _notrun "DIF not supported by running kernel"
+ fi
+
+ SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
+ rm -rf $SCSI_DEBUG_MNT
+ mkdir $SCSI_DEBUG_MNT
+
+ _mkfs_dev $SCSI_DEBUG_DEV || \
+ _fail "Can't make $FSTYP on DIF-enabled scsi_debug device"
+ run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT
+
+ local blksz=$(_get_block_size $SCSI_DEBUG_MNT)
+ local testfile="$SCSI_DEBUG_MNT/test"
+
+ $XFS_IO_PROG -d -f \
+ -c "pwrite -S 0x66 0 $((128 * blksz))" \
+ -c fsync \
+ $testfile >> $seqres.full 2>&1
+
+ local phys_sector=$(_get_file_extent_sector $testfile 0)
+ if [ -z "$phys_sector" ]; then
+ _fail "$test_name: failed to get physical block offset via fiemap"
+ fi
+
+ local dev=$(_short_dev $SCSI_DEBUG_DEV)
+ local debugfs_dir=$(ls /sys/block/$dev/device/scsi_device/)
+ local debugfs_file="/sys/kernel/debug/scsi_debug/$debugfs_dir/corrupt"
+
+ if [ ! -f "$debugfs_file" ]; then
+ _notrun "scsi_debug corruption injection not supported"
+ fi
+
+ if [ "$last" -eq 1 ]; then
+ echo "adding to $phys_sector" >> $seqres.full
+ phys_blk=$((phys_blk + (128 * blksz / 512) - 1))
+ fi
+
+ echo "lba=$phys_sector,num=1,bit_errors=$bit_errors,reftag_adjust=$reftag_adjust" \
+ > $debugfs_file
+
+ $XFS_IO_PROG -d -f \
+ -c "pread 0 $((128 * blksz))" \
+ $testfile
+
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+# test data corruption in first block
+test_dif 1 0 2 0
+test_dif 2 0 2 0
+test_dif 3 0 2 0
+
+# test data corruption in last block
+test_dif 1 1 2 0
+test_dif 2 1 2 0
+test_dif 3 1 2 0
+
+
+# Note: Type 3 doesn't have a reftag, so don't test it
+
+# reftag mismatch in first block
+test_dif 1 0 0 8
+test_dif 2 0 0 8
+
+# reftag mismatch in last block
+test_dif 1 1 0 8
+test_dif 2 1 0 8
+
+_exit 0
diff --git a/tests/generic/2302.out b/tests/generic/2302.out
new file mode 100644
index 000000000000..03b68d904943
--- /dev/null
+++ b/tests/generic/2302.out
@@ -0,0 +1,21 @@
+QA output created by 2302
+Testing DIF type 1 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 3 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 3 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 reftag adjustment by 8 in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 reftag adjustment by 8 in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 reftag adjustment by 8 in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 reftag adjustment by 8 in last sector
+pread: Invalid or incomplete multibyte or wide character
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 6/6] generic: test corruption detection using T10 protection information
2026-09-07 7:58 ` [PATCH 6/6] generic: test corruption detection using T10 protection information Christoph Hellwig
@ 2026-09-08 14:36 ` Kanchan Joshi
0 siblings, 0 replies; 17+ messages in thread
From: Kanchan Joshi @ 2026-09-08 14:36 UTC (permalink / raw)
To: Christoph Hellwig, Zorro Lang
Cc: fstests, Martin K. Petersen, Anuj Gupta, John Garry,
Darrick J. Wong, linux-scsi
On 9/7/2026 1:28 PM, Christoph Hellwig wrote:
> + local phys_sector=$(_get_file_extent_sector $testfile 0)
> + if [ -z "$phys_sector" ]; then
> + _fail "$test_name: failed to get physical block offset via fiemap"
> + fi
> +
> + local dev=$(_short_dev $SCSI_DEBUG_DEV)
> + local debugfs_dir=$(ls/sys/block/$dev/device/scsi_device/)
> + local debugfs_file="/sys/kernel/debug/scsi_debug/$debugfs_dir/corrupt"
> +
> + if [ ! -f "$debugfs_file" ]; then
> + _notrun "scsi_debug corruption injection not supported"
> + fi
> +
> + if [ "$last" -eq 1 ]; then
> + echo "adding to $phys_sector" >> $seqres.full
> + phys_blk=$((phys_blk + (128 * blksz / 512) - 1))
Maybe you want this to be phys_sector and not phys_blk.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 6/6] generic: test corruption detection using T10 protection information
2026-09-11 7:08 add tests for file system on devices using protection information v5 Christoph Hellwig
@ 2026-09-11 7:08 ` Christoph Hellwig
0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2026-09-11 7:08 UTC (permalink / raw)
To: Zorro Lang
Cc: fstests, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
John Garry, Darrick J. Wong, linux-scsi
Add a test that simulates bit flips in data and misdirected writes and
checks that file systems detect it when run on devices using protection
information.
This requires the new scsi_debug corruption injection.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
tests/generic/2302 | 133 +++++++++++++++++++++++++++++++++++++++++
tests/generic/2302.out | 21 +++++++
2 files changed, 154 insertions(+)
create mode 100755 tests/generic/2302
create mode 100644 tests/generic/2302.out
diff --git a/tests/generic/2302 b/tests/generic/2302
new file mode 100755
index 000000000000..fd83c64dfff1
--- /dev/null
+++ b/tests/generic/2302
@@ -0,0 +1,133 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Christoph Hellwig
+#
+# FS QA Test No. 2302
+#
+# Test that T10 DIF detects bitflips and misplaced writes.
+#
+. ./common/preamble
+_begin_fstest auto rw pi
+
+_cleanup()
+{
+ cd /
+ rm -r -f $tmp.*
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+. ./common/scsi_debug
+. ./common/filter
+
+_require_debugfs
+_require_scsi_debug
+# If TEST_DEV is block device, make sure current fs is a localfs which can be
+# written on scsi_debug device
+_require_test
+_require_block_device $TEST_DEV
+_require_xfs_io_command fiemap
+_require_odirect
+
+# FIEMAP on Btrfs returns logical addresses within the filesystem's address
+# space, not physical device offsets. Writing to these offsets on $SCRATCH_DEV
+# would corrupt the filesystem in multi-device setups.
+_exclude_fs btrfs
+
+size=$(_small_fs_size_mb 256)
+
+test_dif()
+{
+ local pi_type=$1
+ local last=$2
+ local bit_errors=$3
+ local reftag_adjust=$4
+
+ echo -n "Testing DIF type $pi_type "
+ if [ "$bit_errors" -gt "0" ]; then
+ echo -n "bit errors ($bit_errors) in "
+ fi
+ if [ "$reftag_adjust" -ne "0" ]; then
+ echo -n "reftag adjustment by $reftag_adjust in "
+ fi
+ if [ "$last" -eq 1 ]; then
+ echo "last sector"
+ else
+ echo "first sector"
+ fi
+
+ scsi_debug_pi_opts="write_same_length=0 dif=${pi_type} dix=1"
+ SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size $scsi_debug_pi_opts`
+
+ local integrity_path="$(_sysfs_block_integrity_path $SCSI_DEBUG_DEV)"
+ if [ ! -d "$integrity_path" ]; then
+ _notrun "DIF not supported by running kernel"
+ fi
+
+ SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
+ rm -rf $SCSI_DEBUG_MNT
+ mkdir $SCSI_DEBUG_MNT
+
+ _mkfs_dev $SCSI_DEBUG_DEV || \
+ _fail "Can't make $FSTYP on DIF-enabled scsi_debug device"
+ run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT
+
+ local blksz=$(_get_block_size $SCSI_DEBUG_MNT)
+ local testfile="$SCSI_DEBUG_MNT/test"
+
+ $XFS_IO_PROG -d -f \
+ -c "pwrite -S 0x66 0 $((128 * blksz))" \
+ -c fsync \
+ $testfile >> $seqres.full 2>&1
+
+ local phys_sector=$(_get_file_extent_sector $testfile 0)
+ if [ -z "$phys_sector" ]; then
+ _fail "$test_name: failed to get physical block offset via fiemap"
+ fi
+
+ local dev=$(_short_dev $SCSI_DEBUG_DEV)
+ local debugfs_dir=$(ls /sys/block/$dev/device/scsi_device/)
+ local debugfs_file="/sys/kernel/debug/scsi_debug/$debugfs_dir/corrupt"
+
+ if [ ! -f "$debugfs_file" ]; then
+ _notrun "scsi_debug corruption injection not supported"
+ fi
+
+ if [ "$last" -eq 1 ]; then
+ echo "adding to $phys_sector" >> $seqres.full
+ phys_sector=$((phys_sector + (128 * blksz / 512) - 1))
+ fi
+
+ echo "lba=$phys_sector,num=1,bit_errors=$bit_errors,reftag_adjust=$reftag_adjust" \
+ > $debugfs_file
+
+ $XFS_IO_PROG -d -f \
+ -c "pread 0 $((128 * blksz))" \
+ $testfile
+
+ [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
+ _put_scsi_debug_dev
+}
+
+# test data corruption in first block
+test_dif 1 0 2 0
+test_dif 2 0 2 0
+test_dif 3 0 2 0
+
+# test data corruption in last block
+test_dif 1 1 2 0
+test_dif 2 1 2 0
+test_dif 3 1 2 0
+
+
+# Note: Type 3 doesn't have a reftag, so don't test it
+
+# reftag mismatch in first block
+test_dif 1 0 0 8
+test_dif 2 0 0 8
+
+# reftag mismatch in last block
+test_dif 1 1 0 8
+test_dif 2 1 0 8
+
+_exit 0
diff --git a/tests/generic/2302.out b/tests/generic/2302.out
new file mode 100644
index 000000000000..03b68d904943
--- /dev/null
+++ b/tests/generic/2302.out
@@ -0,0 +1,21 @@
+QA output created by 2302
+Testing DIF type 1 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 3 bit errors (2) in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 3 bit errors (2) in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 reftag adjustment by 8 in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 reftag adjustment by 8 in first sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 1 reftag adjustment by 8 in last sector
+pread: Invalid or incomplete multibyte or wide character
+Testing DIF type 2 reftag adjustment by 8 in last sector
+pread: Invalid or incomplete multibyte or wide character
--
2.53.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-09-11 7:09 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 6:45 add tests for file system on devices using protection information v3 Christoph Hellwig
2026-08-31 6:45 ` [PATCH 1/6] common/scsi_debug: don't slow down I/O Christoph Hellwig
2026-08-31 6:45 ` [PATCH 2/6] common: factor out a _bdev_disk_name helper Christoph Hellwig
2026-08-31 17:03 ` Darrick J. Wong
2026-08-31 6:45 ` [PATCH 3/6] common: add a _sysfs_block_integrity_path helper Christoph Hellwig
2026-08-31 17:03 ` Darrick J. Wong
2026-08-31 6:45 ` [PATCH 4/6] add a "pi" group Christoph Hellwig
2026-08-31 6:45 ` [PATCH 5/6] generic: test I/O on devices with T10 protection information Christoph Hellwig
2026-09-01 6:38 ` Kanchan Joshi
2026-09-07 5:48 ` Christoph Hellwig
2026-09-03 6:01 ` Anuj Gupta/Anuj Gupta
2026-08-31 6:45 ` [PATCH 6/6] generic: test corruption detection using " Christoph Hellwig
2026-09-03 6:00 ` Anuj Gupta/Anuj Gupta
2026-09-07 5:49 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2026-09-07 7:58 add tests for file system on devices using protection information v4 Christoph Hellwig
2026-09-07 7:58 ` [PATCH 6/6] generic: test corruption detection using T10 protection information Christoph Hellwig
2026-09-08 14:36 ` Kanchan Joshi
2026-09-11 7:08 add tests for file system on devices using protection information v5 Christoph Hellwig
2026-09-11 7:08 ` [PATCH 6/6] generic: test corruption detection using T10 protection information Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.