xfs/007: fix regressions on V4 filesystems
[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 . ./common/preamble
33 _begin_fstest auto quick clone punch seek
34
35 # Import common functions.
36 . ./common/filter
37 . ./common/reflink
38
39 # real QA test starts here
40 _supported_fs xfs
41 _require_scratch_reflink
42 _require_cp_reflink
43 _require_xfs_io_command "cowextsize"
44 _require_xfs_io_command "fpunch"
45
46 echo "Format and mount"
47 _scratch_mkfs > $seqres.full 2>&1
48 _scratch_mount >> $seqres.full 2>&1
49
50 testdir=$SCRATCH_MNT/test-$seq
51 mkdir $testdir
52
53 blksz=65536
54 nr=8
55 filesize=$((blksz * nr))
56
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
64 _scratch_cycle_mount
65
66 echo "Compare files"
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
72
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 -d -c "pwrite -S 0x63 0 $blksz" $testdir/file2 >> $seqres.full
77 $XFS_IO_PROG -d -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file2 >> $seqres.full
78
79 $XFS_IO_PROG -d -c "pwrite -S 0x63 0 $blksz" $testdir/file3 >> $seqres.full
80 $XFS_IO_PROG -d -c "pwrite -S 0x63 $((blksz * 3)) $blksz" $testdir/file3 >> $seqres.full
81
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
85
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
90
91 echo "Compare files"
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
97
98 echo "sync filesystem" | tee -a $seqres.full
99 sync
100
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
104
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
109
110 echo "Compare files"
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
116
117 echo "Remount" | tee -a $seqres.full
118 _scratch_cycle_mount
119
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
123
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
128
129 echo "Compare files"
130 md5sum $testdir/file1 | _filter_scratch
131 md5sum $testdir/file2 | _filter_scratch
132 md5sum $testdir/file3 | _filter_scratch
133
134 # success, all done
135 status=0
136 exit