2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates. All Rights Reserved.
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
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.
21 # Basically we want to create a file with the following data/CoW forks:
25 # ^--^---------- these blocks are dirty
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.
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
38 status=1 # failure is the default!
39 trap "_cleanup; exit \$status" 0 1 2 3 15
47 # get standard environment, filters and checks
52 # real QA test starts here
55 _require_scratch_reflink
57 _require_xfs_io_command "cowextsize"
58 _require_xfs_io_command "fpunch"
62 echo "Format and mount"
63 _scratch_mkfs > $seqres.full 2>&1
64 _scratch_mount >> $seqres.full 2>&1
66 testdir=$SCRATCH_MNT/test-$seq
71 filesize=$((blksz * nr))
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
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
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 -c "pwrite -S 0x63 0 $blksz" $testdir/file2 >> $seqres.full
93 $XFS_IO_PROG -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file2 >> $seqres.full
95 $XFS_IO_PROG -c "pwrite -S 0x63 0 $blksz" $testdir/file3 >> $seqres.full
96 $XFS_IO_PROG -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file3 >> $seqres.full
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
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
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
114 echo "sync filesystem" | tee -a $seqres.full
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
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
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
133 echo "Remount" | tee -a $seqres.full
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
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
146 md5sum $testdir/file1 | _filter_scratch
147 md5sum $testdir/file2 | _filter_scratch
148 md5sum $testdir/file3 | _filter_scratch