2 # FS QA Test No. generic/030
4 # Test mapped writes against remap+truncate down/up to ensure we get the data
5 # correctly written. This can expose data corruption bugs on filesystems where
6 # the block size is smaller than the page size.
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-----------------------------------------------------------------------
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # get standard environment, filters and checks
45 # real QA test starts here
47 # Modify as appropriate.
51 _require_xfs_io_command "mremap"
53 testfile=$SCRATCH_MNT/testfile
55 _scratch_mkfs > /dev/null 2>&1
58 # first case is just truncate down/truncate up to check that the mapped
59 # write after the truncate up is correctly handled.
61 -c "truncate 5017k" `# truncate | |` \
62 -c "pwrite -S 0x58 0 5017k" `# write |X...XXX|` \
63 -c "mmap -rw 0 5017k" `# mmap | |` \
64 -c "truncate 5020k" `# truncate up | |` \
65 -c "mremap -m 5020k" `# mremap up | |` \
66 -c "mwrite -S 0x57 5017k 3k" `# mwrite | WWWWWWWWWWWWWWWW|` \
67 -c "mremap 5017k " `# mremap dn | |` \
68 -c "truncate 5017k" `# mremap dn | |` \
69 -c "truncate 5020k" `# truncate up | |` \
70 -c "mremap -m 5020k" `# mremap up | |` \
71 -c "mwrite -S 0x59 5017k 3k" `# mwrite | YYYYYYYYYYYYYYYY|` \
73 $testfile | _filter_xfs_io
75 echo "==== Pre-Remount ==="
78 echo "==== Post-Remount =="
84 # second case is to do a mwrite between the truncate to a block on the
85 # same page we are truncating within the EOF. This checks that a mapped
86 # write between truncate down and truncate up a further mapped
87 # write to the same page into the new space doesn't result in data being lost.
89 -c "truncate 5017k" `# truncate | |` \
90 -c "pwrite -S 0x58 0 5017k" `# write |X...XXX|` \
91 -c "mmap -rw 0 5017k" `# mmap | |` \
92 -c "truncate 5020k" `# truncate up | |` \
93 -c "mremap -m 5020k" `# mremap up | |` \
94 -c "mwrite -S 0x57 5017k 3k" `# mwrite | WWWWWWWWWWWWWWWW|` \
95 -c "mremap 5017k " `# mremap dn | |` \
96 -c "truncate 5017k" `# mremap dn | |` \
97 -c "mwrite -S 0x5a 5016k 1k" `# mwrite | ZZZ |` \
98 -c "truncate 5020k" `# truncate up | |` \
99 -c "mremap -m 5020k" `# mremap up | |` \
100 -c "mwrite -S 0x59 5017k 3k" `# mwrite | YYYYYYYYYYYYYYYY|` \
102 $testfile | _filter_xfs_io
104 echo "==== Pre-Remount ==="
107 echo "==== Post-Remount =="
110 # third case is the same as the first, but this time on unaligned byte
111 # boundaries rather than block boundaries. This mimics the exact mmap write
112 # patterns of the application that exposed the bug in the first place, and
113 # so is somewhat more complex and has repeated operations in it.
115 -c "truncate 5136912" \
116 -c "pwrite -S 0x58 0 5136912" \
117 -c "mmap -rw 0 5136912" \
118 -c "mremap 5136912" \
119 -c "truncate 5136912" \
120 -c "truncate 5139720" \
121 -c "mremap -m 5139720" \
122 -c "mwrite -S 0 5136912 2808" \
123 -c "mwrite -S 0 5136912 2808" \
124 -c "mwrite -S 0 5136912 2808" \
125 -c "mremap 5136912 " \
126 -c "truncate 5136912" \
127 -c "truncate 5139720" \
128 -c "mremap -m 5139720" \
129 -c "mwrite -S 0 5136912 2808" \
130 -c "mwrite -S 0 5136912 2808" \
131 -c "mwrite -S 0x59 5136912 2808" \
132 -c "truncate 5140480" \
133 -c "mremap 5140480" \
134 -c "msync -s 0 5140480" \
135 -c "mremap 5139720" \
138 $testfile | _filter_xfs_io
140 echo "==== Pre-Remount ==="
143 echo "==== Post-Remount =="