xfs/004: don't fail test due to realtime files
[xfstests-dev.git] / tests / xfs / 421
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 421
6 #
7 # Test SEEK_HOLE/SEEK_DATA into a region that is marked CoW'd for
8 # speculative preallocation in the CoW fork and isn't backed by
9 # data fork extents.
10 #
11 # - Set a huge cowextsize hint.
12 # - Create a file "DD      " (two data blocks, six hole blocks)
13 # - Reflink copy this file to a second file.
14 # - dio write to the first block of the second file to create a single
15 #   large CoW reservation covering the whole file.
16 # - dio write to block 3, which should be a hole in the data fork.
17 # - Display the SEEK_HOLE/SEEK_DATA info for the second file to confirm
18 #   that we see the data in blocks 0-1, the hole at block 2, the data
19 #   at block 3, and the hole for the rest of the file.
20 #
21 # Basically we want to create a file with the following data/CoW forks:
22 #
23 # data: DD------
24 #  cow: dddddddd
25 #       ^--^---------- these blocks are dirty
26 #
27 # And then check that SEEK_HOLE and SEEK_DATA actually find that second
28 # dirty block even though we've never had a data fork extent mapping the
29 # second dirty block.  We need the huge cowextsize so that the hole
30 # area receives preallocation in the CoW fork.
31 #
32 seq=`basename $0`
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
35
36 here=`pwd`
37 tmp=/tmp/$$
38 status=1    # failure is the default!
39 trap "_cleanup; exit \$status" 0 1 2 3 15
40
41 _cleanup()
42 {
43         cd /
44         rm -rf $tmp.*
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50 . ./common/reflink
51
52 # real QA test starts here
53 _supported_fs xfs
54 _require_scratch_reflink
55 _require_cp_reflink
56 _require_xfs_io_command "cowextsize"
57 _require_xfs_io_command "fpunch"
58
59 rm -f $seqres.full
60
61 echo "Format and mount"
62 _scratch_mkfs > $seqres.full 2>&1
63 _scratch_mount >> $seqres.full 2>&1
64
65 testdir=$SCRATCH_MNT/test-$seq
66 mkdir $testdir
67
68 blksz=65536
69 nr=8
70 filesize=$((blksz * nr))
71
72 echo "Create the original files"
73 $XFS_IO_PROG -c "cowextsize" $testdir >> $seqres.full
74 $XFS_IO_PROG -c "cowextsize $filesize" $testdir >> $seqres.full
75 $XFS_IO_PROG -c "cowextsize" $testdir >> $seqres.full
76 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 $((blksz * 2))" -c "truncate $filesize" -c "fpunch $((blksz * 2)) $((blksz * (nr - 2) ))" $testdir/file1 >> $seqres.full
77 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
78 $XFS_IO_PROG -f -c "pwrite -S 0 0 $filesize" -c "pwrite -S 0x61 0 $((blksz * 2))" $testdir/file3 >> $seqres.full
79 _scratch_cycle_mount
80
81 echo "Compare files"
82 md5sum $testdir/file1 | _filter_scratch
83 md5sum $testdir/file2 | _filter_scratch
84 md5sum $testdir/file3 | _filter_scratch
85 # drop caches to make sure the page cache for the unwritten extents is clean
86 echo 1 > /proc/sys/vm/drop_caches
87
88 echo "CoW the shared part then write into the empty part" | tee -a $seqres.full
89 $XFS_IO_PROG -c "cowextsize" $testdir/file1 >> $seqres.full
90 $XFS_IO_PROG -c "cowextsize" $testdir/file2 >> $seqres.full
91 $XFS_IO_PROG -d -c "pwrite -S 0x63 0 $blksz" $testdir/file2 >> $seqres.full
92 $XFS_IO_PROG -d -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file2 >> $seqres.full
93
94 $XFS_IO_PROG -d -c "pwrite -S 0x63 0 $blksz" $testdir/file3 >> $seqres.full
95 $XFS_IO_PROG -d -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file3 >> $seqres.full
96
97 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
98 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
99 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
100
101 echo "Seek holes and data in file1"
102 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
103 echo "Seek holes and data in file2"
104 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
105
106 echo "Compare files"
107 md5sum $testdir/file1 | _filter_scratch
108 md5sum $testdir/file2 | _filter_scratch
109 md5sum $testdir/file3 | _filter_scratch
110 # drop caches to make sure the page cache for the unwritten extents is clean
111 echo 1 > /proc/sys/vm/drop_caches
112
113 echo "sync filesystem" | tee -a $seqres.full
114 sync
115
116 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
117 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
118 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
119
120 echo "Seek holes and data in file1"
121 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
122 echo "Seek holes and data in file2"
123 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
124
125 echo "Compare files"
126 md5sum $testdir/file1 | _filter_scratch
127 md5sum $testdir/file2 | _filter_scratch
128 md5sum $testdir/file3 | _filter_scratch
129 # drop caches to make sure the page cache for the unwritten extents is clean
130 echo 1 > /proc/sys/vm/drop_caches
131
132 echo "Remount" | tee -a $seqres.full
133 _scratch_cycle_mount
134
135 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
136 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
137 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
138
139 echo "Seek holes and data in file1"
140 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
141 echo "Seek holes and data in file2"
142 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
143
144 echo "Compare files"
145 md5sum $testdir/file1 | _filter_scratch
146 md5sum $testdir/file2 | _filter_scratch
147 md5sum $testdir/file3 | _filter_scratch
148
149 # success, all done
150 status=0
151 exit