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 # - 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.
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
54 _require_scratch_reflink
56 _require_xfs_io_command "cowextsize"
57 _require_xfs_io_command "fpunch"
61 echo "Format and mount"
62 _scratch_mkfs > $seqres.full 2>&1
63 _scratch_mount >> $seqres.full 2>&1
65 testdir=$SCRATCH_MNT/test-$seq
70 filesize=$((blksz * nr))
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
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
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
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
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
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
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
113 echo "sync filesystem" | tee -a $seqres.full
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
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
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
132 echo "Remount" | tee -a $seqres.full
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
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
145 md5sum $testdir/file1 | _filter_scratch
146 md5sum $testdir/file2 | _filter_scratch
147 md5sum $testdir/file3 | _filter_scratch