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.
37 _require_scratch_shutdown
39 # create a small fs and initialize free blocks with a unique pattern
40 _scratch_mkfs_sized $((1024 * 1024 * 100)) >> $seqres.full 2>&1
42 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 100m" -c fsync $SCRATCH_MNT/spc \
44 rm -f $SCRATCH_MNT/spc
45 $XFS_IO_PROG -c fsync $SCRATCH_MNT
47 # Write a couple files with particular writeback sequences. The first writes a
48 # delalloc extent and triggers writeback on the last page. The second triggers
49 # post-eof preallocation (on XFS), write extends into the preallocation and
50 # triggers writeback of the last written page.
51 $XFS_IO_PROG -fc "pwrite 0 256k" -c "sync_range -w 252k 4k" \
52 -c "sync_range -a 252k 4k" $SCRATCH_MNT/file.1 >> $seqres.full 2>&1
53 $XFS_IO_PROG -fc "pwrite 0 260k" -c fsync -c "pwrite 1536k 4k" \
54 -c "sync_range -w 1536k 4k" -c "sync_range -a 1536k 4k" \
55 $SCRATCH_MNT/file.2 >> $seqres.full 2>&1
57 # Shut down before any other writeback completes. Flush the log to persist inode
61 # Now search both files for stale bytes. The region prior to the last page in
62 # the first file should be zero filled. The region between the two writes to the
63 # second file should also be zero filled.
65 echo file.1 | tee -a $seqres.full
66 hexdump $SCRATCH_MNT/file.1 | tee -a $seqres.full | grep ab
67 echo file.2 | tee -a $seqres.full
68 hexdump $SCRATCH_MNT/file.2 | tee -a $seqres.full | grep ab