xfs: regression test for allocsp handing out stale disk contents
[xfstests-dev.git] / tests / xfs / 107
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 107
6 #
7 # Regression test for commit:
8 #
9 # 983d8e60f508 ("xfs: map unwritten blocks in XFS_IOC_{ALLOC,FREE}SP just like fallocate")
10 #
11 . ./common/preamble
12 _begin_fstest auto quick prealloc
13
14 # Import common functions.
15 . ./common/filter
16
17 # real QA test starts here
18
19 # Modify as appropriate.
20 _supported_fs xfs
21 _require_test
22 _require_scratch
23 _require_test_program allocstale
24
25 size_mb=32
26 # Write a known pattern to the disk so that we can detect stale disk blocks
27 # being mapped into the file.  In the test author's experience, the bug will
28 # reproduce within the first 500KB's worth of ALLOCSP calls, so running up
29 # to 16MB should suffice.
30 $XFS_IO_PROG -d -c "pwrite -S 0x58 -b 8m 0 ${size_mb}m" $SCRATCH_DEV > $seqres.full
31 MKFS_OPTIONS="-K $MKFS_OPTIONS" _scratch_mkfs_sized $((size_mb * 1048576)) >> $seqres.full
32
33 _scratch_mount
34
35 # Force the file to be created on the data device, which we pre-initialized
36 # with a known pattern.  The bug exists in the generic bmap code, so the choice
37 # of backing device does not matter, and ignoring the rt device gets us out of
38 # needing to detect things like rt extent size.
39 _xfs_force_bdev data $SCRATCH_MNT
40 testfile=$SCRATCH_MNT/a
41
42 # Allow the test program to expand the file to consume half the free space.
43 blksz=$(_get_file_block_size $SCRATCH_MNT)
44 iterations=$(( (size_mb / 2) * 1048576 / blksz))
45 echo "Setting up $iterations runs for block size $blksz" >> $seqres.full
46
47 # Run reproducer program and dump file contents if we see stale data.  Full
48 # details are in the source for the C program, but in a nutshell we run ALLOCSP
49 # one block at a time to see if it'll give us blocks full of 'X'es.
50 $here/src/allocstale $testfile $iterations
51 res=$?
52 test $res -eq 2 && od -tx1 -Ad -c $testfile
53
54 # success, all done
55 echo Silence is golden
56 status=0
57 exit