fstests: use _require_symlinks on all necessary tests
[xfstests-dev.git] / tests / generic / 536
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 536
6 #
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.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33
34 # Modify as appropriate.
35 _supported_fs generic
36 _supported_os Linux
37 _require_scratch
38 _require_scratch_shutdown
39
40 # create a small fs and initialize free blocks with a unique pattern
41 _scratch_mkfs_sized $((1024 * 1024 * 100)) >> $seqres.full 2>&1
42 _scratch_mount
43 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 100m" -c fsync $SCRATCH_MNT/spc \
44         >> $seqres.full 2>&1
45 rm -f $SCRATCH_MNT/spc
46 $XFS_IO_PROG -c fsync $SCRATCH_MNT
47
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
57
58 # Shut down before any other writeback completes. Flush the log to persist inode
59 # size updates.
60 _scratch_shutdown -f
61
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.
65 _scratch_cycle_mount
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
70
71 status=0
72 exit