xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 420
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. 420
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 # - Write to the first block of the second file to create a single
15 #   large CoW reservation covering the whole file.
16 # - 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_os Linux
54 _supported_fs xfs
55 _require_scratch_reflink
56 _require_cp_reflink
57 _require_xfs_io_command "cowextsize"
58 _require_xfs_io_command "fpunch"
59
60 rm -f $seqres.full
61
62 echo "Format and mount"
63 _scratch_mkfs > $seqres.full 2>&1
64 _scratch_mount >> $seqres.full 2>&1
65
66 testdir=$SCRATCH_MNT/test-$seq
67 mkdir $testdir
68
69 blksz=65536
70 nr=8
71 filesize=$((blksz * nr))
72
73 echo "Create the original files"
74 $XFS_IO_PROG -c "cowextsize" $testdir >> $seqres.full
75 $XFS_IO_PROG -c "cowextsize $filesize" $testdir >> $seqres.full
76 $XFS_IO_PROG -c "cowextsize" $testdir >> $seqres.full
77 $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
78 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
79 $XFS_IO_PROG -f -c "pwrite -S 0 0 $filesize" -c "pwrite -S 0x61 0 $((blksz * 2))" $testdir/file3 >> $seqres.full
80 _scratch_cycle_mount
81
82 echo "Compare files"
83 md5sum $testdir/file1 | _filter_scratch
84 md5sum $testdir/file2 | _filter_scratch
85 md5sum $testdir/file3 | _filter_scratch
86
87 echo "CoW the shared part then write into the empty part" | tee -a $seqres.full
88 $XFS_IO_PROG -c "cowextsize" $testdir/file1 >> $seqres.full
89 $XFS_IO_PROG -c "cowextsize" $testdir/file2 >> $seqres.full
90 $XFS_IO_PROG -c "pwrite -S 0x63 0 $blksz" $testdir/file2 >> $seqres.full
91 $XFS_IO_PROG -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file2 >> $seqres.full
92
93 $XFS_IO_PROG -c "pwrite -S 0x63 0 $blksz" $testdir/file3 >> $seqres.full
94 $XFS_IO_PROG -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file3 >> $seqres.full
95
96 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
97 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
98 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
99
100 echo "Seek holes and data in file1"
101 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
102 echo "Seek holes and data in file2"
103 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
104
105 echo "Compare files"
106 md5sum $testdir/file1 | _filter_scratch
107 md5sum $testdir/file2 | _filter_scratch
108 md5sum $testdir/file3 | _filter_scratch
109
110 echo "sync filesystem" | tee -a $seqres.full
111 sync
112
113 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
114 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
115 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
116
117 echo "Seek holes and data in file1"
118 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
119 echo "Seek holes and data in file2"
120 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
121
122 echo "Compare files"
123 md5sum $testdir/file1 | _filter_scratch
124 md5sum $testdir/file2 | _filter_scratch
125 md5sum $testdir/file3 | _filter_scratch
126
127 echo "Remount" | tee -a $seqres.full
128 _scratch_cycle_mount
129
130 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
131 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
132 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
133
134 echo "Seek holes and data in file1"
135 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
136 echo "Seek holes and data in file2"
137 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
138
139 echo "Compare files"
140 md5sum $testdir/file1 | _filter_scratch
141 md5sum $testdir/file2 | _filter_scratch
142 md5sum $testdir/file3 | _filter_scratch
143
144 # success, all done
145 status=0
146 exit