2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle. All Rights Reserved.
7 # Regression test for commit:
9 # 983d8e60f508 ("xfs: map unwritten blocks in XFS_IOC_{ALLOC,FREE}SP just like fallocate")
12 _begin_fstest auto quick prealloc
14 # Import common functions.
17 # real QA test starts here
19 # Modify as appropriate.
23 _require_xfs_io_command allocsp # detect presence of ALLOCSP ioctl
24 _require_test_program allocstale
26 # Create a 256MB filesystem to avoid running into mkfs problems with too-small
30 # Write a known pattern to the disk so that we can detect stale disk blocks
31 # being mapped into the file. In the test author's experience, the bug will
32 # reproduce within the first 500KB's worth of ALLOCSP calls, so running up
33 # to 16MB should suffice.
34 $XFS_IO_PROG -d -c "pwrite -S 0x58 -b 8m 0 ${size_mb}m" $SCRATCH_DEV > $seqres.full
35 MKFS_OPTIONS="-K $MKFS_OPTIONS" _scratch_mkfs_sized $((size_mb * 1048576)) >> $seqres.full
39 # Force the file to be created on the data device, which we pre-initialized
40 # with a known pattern. The bug exists in the generic bmap code, so the choice
41 # of backing device does not matter, and ignoring the rt device gets us out of
42 # needing to detect things like rt extent size.
43 _xfs_force_bdev data $SCRATCH_MNT
44 testfile=$SCRATCH_MNT/a
46 # Allow the test program to expand the file to 32MB. If we can't find any
47 # stale blocks at that point, the kernel has probably been patched.
48 blksz=$(_get_file_block_size $SCRATCH_MNT)
49 iterations=$(( (size_mb / 16) * 1048576 / blksz))
50 echo "Setting up $iterations runs for block size $blksz" >> $seqres.full
52 # Run reproducer program and dump file contents if we see stale data. Full
53 # details are in the source for the C program, but in a nutshell we run ALLOCSP
54 # one block at a time to see if it'll give us blocks full of 'X'es.
55 $here/src/allocstale $testfile $iterations
57 test $res -eq 2 && od -tx1 -Ad -c $testfile
60 echo Silence is golden