overlay: run unionmount testsuite test cases
[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_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 # drop caches to make sure the page cache for the unwritten extents is clean
87 echo 1 > /proc/sys/vm/drop_caches
88
89 echo "CoW the shared part then write into the empty part" | tee -a $seqres.full
90 $XFS_IO_PROG -c "cowextsize" $testdir/file1 >> $seqres.full
91 $XFS_IO_PROG -c "cowextsize" $testdir/file2 >> $seqres.full
92 $XFS_IO_PROG -d -c "pwrite -S 0x63 0 $blksz" $testdir/file2 >> $seqres.full
93 $XFS_IO_PROG -d -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file2 >> $seqres.full
94
95 $XFS_IO_PROG -d -c "pwrite -S 0x63 0 $blksz" $testdir/file3 >> $seqres.full
96 $XFS_IO_PROG -d -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file3 >> $seqres.full
97
98 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
99 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
100 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
101
102 echo "Seek holes and data in file1"
103 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
104 echo "Seek holes and data in file2"
105 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
106
107 echo "Compare files"
108 md5sum $testdir/file1 | _filter_scratch
109 md5sum $testdir/file2 | _filter_scratch
110 md5sum $testdir/file3 | _filter_scratch
111 # drop caches to make sure the page cache for the unwritten extents is clean
112 echo 1 > /proc/sys/vm/drop_caches
113
114 echo "sync filesystem" | tee -a $seqres.full
115 sync
116
117 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
118 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
119 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
120
121 echo "Seek holes and data in file1"
122 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
123 echo "Seek holes and data in file2"
124 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
125
126 echo "Compare files"
127 md5sum $testdir/file1 | _filter_scratch
128 md5sum $testdir/file2 | _filter_scratch
129 md5sum $testdir/file3 | _filter_scratch
130 # drop caches to make sure the page cache for the unwritten extents is clean
131 echo 1 > /proc/sys/vm/drop_caches
132
133 echo "Remount" | tee -a $seqres.full
134 _scratch_cycle_mount
135
136 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
137 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
138 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
139
140 echo "Seek holes and data in file1"
141 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
142 echo "Seek holes and data in file2"
143 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
144
145 echo "Compare files"
146 md5sum $testdir/file1 | _filter_scratch
147 md5sum $testdir/file2 | _filter_scratch
148 md5sum $testdir/file3 | _filter_scratch
149
150 # success, all done
151 status=0
152 exit