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 _begin_fstest auto quick rw shutdown
14 # Import common functions.
16 # real QA test starts here
18 # Modify as appropriate.
21 _require_scratch_shutdown
23 # create a small fs and initialize free blocks with a unique pattern
24 _scratch_mkfs_sized $((1024 * 1024 * 100)) >> $seqres.full 2>&1
26 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 100m" -c fsync $SCRATCH_MNT/spc \
28 rm -f $SCRATCH_MNT/spc
29 $XFS_IO_PROG -c fsync $SCRATCH_MNT
31 # Write a couple files with particular writeback sequences. The first writes a
32 # delalloc extent and triggers writeback on the last page. The second triggers
33 # post-eof preallocation (on XFS), write extends into the preallocation and
34 # triggers writeback of the last written page.
35 $XFS_IO_PROG -fc "pwrite 0 256k" -c "sync_range -w 252k 4k" \
36 -c "sync_range -a 252k 4k" $SCRATCH_MNT/file.1 >> $seqres.full 2>&1
37 $XFS_IO_PROG -fc "pwrite 0 260k" -c fsync -c "pwrite 1536k 4k" \
38 -c "sync_range -w 1536k 4k" -c "sync_range -a 1536k 4k" \
39 $SCRATCH_MNT/file.2 >> $seqres.full 2>&1
41 # Shut down before any other writeback completes. Flush the log to persist inode
45 # Now search both files for stale bytes. The region prior to the last page in
46 # the first file should be zero filled. The region between the two writes to the
47 # second file should also be zero filled.
49 echo file.1 | tee -a $seqres.full
50 hexdump $SCRATCH_MNT/file.1 | tee -a $seqres.full | grep ab
51 echo file.2 | tee -a $seqres.full
52 hexdump $SCRATCH_MNT/file.2 | tee -a $seqres.full | grep ab