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 _begin_fstest auto quick clone punch seek
35 # Import common functions.
39 # real QA test starts here
41 _require_scratch_reflink
43 _require_xfs_io_command "cowextsize"
44 _require_xfs_io_command "fpunch"
46 echo "Format and mount"
47 _scratch_mkfs > $seqres.full 2>&1
48 _scratch_mount >> $seqres.full 2>&1
50 testdir=$SCRATCH_MNT/test-$seq
55 filesize=$((blksz * nr))
57 echo "Create the original files"
58 $XFS_IO_PROG -c "cowextsize" $testdir >> $seqres.full
59 $XFS_IO_PROG -c "cowextsize $filesize" $testdir >> $seqres.full
60 $XFS_IO_PROG -c "cowextsize" $testdir >> $seqres.full
61 $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
62 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
63 $XFS_IO_PROG -f -c "pwrite -S 0 0 $filesize" -c "pwrite -S 0x61 0 $((blksz * 2))" $testdir/file3 >> $seqres.full
67 md5sum $testdir/file1 | _filter_scratch
68 md5sum $testdir/file2 | _filter_scratch
69 md5sum $testdir/file3 | _filter_scratch
70 # drop caches to make sure the page cache for the unwritten extents is clean
71 echo 1 > /proc/sys/vm/drop_caches
73 echo "CoW the shared part then write into the empty part" | tee -a $seqres.full
74 $XFS_IO_PROG -c "cowextsize" $testdir/file1 >> $seqres.full
75 $XFS_IO_PROG -c "cowextsize" $testdir/file2 >> $seqres.full
76 $XFS_IO_PROG -c "pwrite -S 0x63 0 $blksz" $testdir/file2 >> $seqres.full
77 $XFS_IO_PROG -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file2 >> $seqres.full
79 $XFS_IO_PROG -c "pwrite -S 0x63 0 $blksz" $testdir/file3 >> $seqres.full
80 $XFS_IO_PROG -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file3 >> $seqres.full
82 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
83 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
84 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
86 echo "Seek holes and data in file1"
87 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
88 echo "Seek holes and data in file2"
89 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
92 md5sum $testdir/file1 | _filter_scratch
93 md5sum $testdir/file2 | _filter_scratch
94 md5sum $testdir/file3 | _filter_scratch
95 # drop caches to make sure the page cache for the unwritten extents is clean
96 echo 1 > /proc/sys/vm/drop_caches
98 echo "sync filesystem" | tee -a $seqres.full
101 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
102 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
103 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
105 echo "Seek holes and data in file1"
106 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
107 echo "Seek holes and data in file2"
108 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
111 md5sum $testdir/file1 | _filter_scratch
112 md5sum $testdir/file2 | _filter_scratch
113 md5sum $testdir/file3 | _filter_scratch
114 # drop caches to make sure the page cache for the unwritten extents is clean
115 echo 1 > /proc/sys/vm/drop_caches
117 echo "Remount" | tee -a $seqres.full
120 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file1 >> $seqres.full 2>&1
121 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file2 >> $seqres.full 2>&1
122 $XFS_IO_PROG -c "bmap -ev" -c "bmap -cv" $testdir/file3 >> $seqres.full 2>&1
124 echo "Seek holes and data in file1"
125 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file1
126 echo "Seek holes and data in file2"
127 $XFS_IO_PROG -c "seek -a -r 0" $testdir/file2
130 md5sum $testdir/file1 | _filter_scratch
131 md5sum $testdir/file2 | _filter_scratch
132 md5sum $testdir/file3 | _filter_scratch