2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc. All Rights Reserved.
7 # Test a some write patterns for stale data exposure after a crash. XFS is
8 # historically susceptible to this problem in the window between delalloc to
9 # physical extent conversion and writeback completion.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
29 # remove previous $seqres.full before test
32 # real QA test starts here
34 # Modify as appropriate.
38 _require_scratch_shutdown
40 # create a small fs and initialize free blocks with a unique pattern
41 _scratch_mkfs_sized $((1024 * 1024 * 100)) >> $seqres.full 2>&1
43 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 100m" -c fsync $SCRATCH_MNT/spc \
45 rm -f $SCRATCH_MNT/spc
46 $XFS_IO_PROG -c fsync $SCRATCH_MNT
48 # Write a couple files with particular writeback sequences. The first writes a
49 # delalloc extent and triggers writeback on the last page. The second triggers
50 # post-eof preallocation (on XFS), write extends into the preallocation and
51 # triggers writeback of the last written page.
52 $XFS_IO_PROG -fc "pwrite 0 256k" -c "sync_range -w 252k 4k" \
53 -c "sync_range -a 252k 4k" $SCRATCH_MNT/file.1 >> $seqres.full 2>&1
54 $XFS_IO_PROG -fc "pwrite 0 260k" -c fsync -c "pwrite 1536k 4k" \
55 -c "sync_range -w 1536k 4k" -c "sync_range -a 1536k 4k" \
56 $SCRATCH_MNT/file.2 >> $seqres.full 2>&1
58 # Shut down before any other writeback completes. Flush the log to persist inode
62 # Now search both files for stale bytes. The region prior to the last page in
63 # the first file should be zero filled. The region between the two writes to the
64 # second file should also be zero filled.
66 echo file.1 | tee -a $seqres.full
67 hexdump $SCRATCH_MNT/file.1 | tee -a $seqres.full | grep ab
68 echo file.2 | tee -a $seqres.full
69 hexdump $SCRATCH_MNT/file.2 | tee -a $seqres.full | grep ab