From: Darrick J. Wong <djwong@xxxxxxxxxx> This test sets up scsi_debug so that we can test the fs and block layer code for hardware-accelerated atomic writes (and not just a software fallback). However, the userspace ABI for detecting atomic write geometry has changed since the start of development (to include said software fallback) so we must add some extra code to find the real hardware capabilities, and base the write sizes based on that. This fixes a test failure with 32k blocksizes because the advertised atomic_write_unit_max is 128M and fallocate quickly runs out of space. While we're at it fix a stupid variable usage bug in the loop. Cc: <fstests@xxxxxxxxxxxxxxx> # v2025.07.13 Fixes: fa8694c823d853 ("generic: various atomic write tests with hardware and scsi_debug") Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --- common/atomicwrites | 6 ++++++ tests/generic/767 | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/atomicwrites b/common/atomicwrites index 95d545a67cadda..33526399d2e980 100644 --- a/common/atomicwrites +++ b/common/atomicwrites @@ -18,6 +18,12 @@ _get_atomic_write_unit_max() grep -w atomic_write_unit_max | grep -o '[0-9]\+' } +_get_atomic_write_unit_max_opt() +{ + $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ + grep -w atomic_write_unit_max_opt | grep -o '[0-9]\+' +} + _get_atomic_write_segments_max() { $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $1 | \ diff --git a/tests/generic/767 b/tests/generic/767 index 31d599eacfd63b..161fef03825db4 100755 --- a/tests/generic/767 +++ b/tests/generic/767 @@ -61,8 +61,18 @@ $XFS_IO_PROG -c "statx -r -m $STATX_WRITE_ATOMIC" $testfile >> $seqres.full sector_size=$(blockdev --getss $SCRATCH_DEV) min_awu=$(_get_atomic_write_unit_min $testfile) max_awu=$(_get_atomic_write_unit_max $testfile) +opt_awu=$(_get_atomic_write_unit_max_opt $testfile) -$XFS_IO_PROG -f -c "falloc 0 $((max_awu * 2))" -c fsync $testfile +echo "min:$min_awu max:$max_awu opt:$opt_awu" >> $seqres.full + +# We want to test hardware support, so use that if detected +if [ -n "$opt_awu" ] && [ "$opt_awu" != "0" ]; then + write_size="$opt_awu" +else + write_size="$max_awu" +fi + +$XFS_IO_PROG -f -c "falloc 0 $((write_size * 2))" -c fsync $testfile # try outside the advertised sizes echo "two EINVAL for unsupported sizes" @@ -73,8 +83,8 @@ _simple_atomic_write $max_i $max_i $testfile -d # try all of the advertised sizes echo "all should work" -for ((i = min_awu; i <= max_awu; i *= 2)); do - $XFS_IO_PROG -f -c "falloc 0 $((max_awu * 2))" -c fsync $testfile +for ((i = min_awu; i <= write_size; i *= 2)); do + $XFS_IO_PROG -f -c "falloc 0 $((write_size * 2))" -c fsync $testfile _test_atomic_file_writes $i $testfile done