2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
5 # FS QA Test No. generic/030
7 # Test mapped writes against remap+truncate down/up to ensure we get the data
8 # correctly written. This can expose data corruption bugs on filesystems where
9 # the block size is smaller than the page size.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
30 # real QA test starts here
32 # Modify as appropriate.
36 _require_xfs_io_command "mremap"
38 testfile=$SCRATCH_MNT/testfile
40 _scratch_mkfs > /dev/null 2>&1
43 # first case is just truncate down/truncate up to check that the mapped
44 # write after the truncate up is correctly handled.
46 -c "truncate 5017k" `# truncate | |` \
47 -c "pwrite -S 0x58 0 5017k" `# write |X...XXX|` \
48 -c "mmap -rw 0 5017k" `# mmap | |` \
49 -c "truncate 5020k" `# truncate up | |` \
50 -c "mremap -m 5020k" `# mremap up | |` \
51 -c "mwrite -S 0x57 5017k 3k" `# mwrite | WWWWWWWWWWWWWWWW|` \
52 -c "mremap 5017k " `# mremap dn | |` \
53 -c "truncate 5017k" `# mremap dn | |` \
54 -c "truncate 5020k" `# truncate up | |` \
55 -c "mremap -m 5020k" `# mremap up | |` \
56 -c "mwrite -S 0x59 5017k 3k" `# mwrite | YYYYYYYYYYYYYYYY|` \
58 $testfile | _filter_xfs_io
60 echo "==== Pre-Remount ==="
63 echo "==== Post-Remount =="
69 # second case is to do a mwrite between the truncate to a block on the
70 # same page we are truncating within the EOF. This checks that a mapped
71 # write between truncate down and truncate up a further mapped
72 # write to the same page into the new space doesn't result in data being lost.
74 -c "truncate 5017k" `# truncate | |` \
75 -c "pwrite -S 0x58 0 5017k" `# write |X...XXX|` \
76 -c "mmap -rw 0 5017k" `# mmap | |` \
77 -c "truncate 5020k" `# truncate up | |` \
78 -c "mremap -m 5020k" `# mremap up | |` \
79 -c "mwrite -S 0x57 5017k 3k" `# mwrite | WWWWWWWWWWWWWWWW|` \
80 -c "mremap 5017k " `# mremap dn | |` \
81 -c "truncate 5017k" `# mremap dn | |` \
82 -c "mwrite -S 0x5a 5016k 1k" `# mwrite | ZZZ |` \
83 -c "truncate 5020k" `# truncate up | |` \
84 -c "mremap -m 5020k" `# mremap up | |` \
85 -c "mwrite -S 0x59 5017k 3k" `# mwrite | YYYYYYYYYYYYYYYY|` \
87 $testfile | _filter_xfs_io
89 echo "==== Pre-Remount ==="
92 echo "==== Post-Remount =="
95 # third case is the same as the first, but this time on unaligned byte
96 # boundaries rather than block boundaries. This mimics the exact mmap write
97 # patterns of the application that exposed the bug in the first place, and
98 # so is somewhat more complex and has repeated operations in it.
100 -c "truncate 5136912" \
101 -c "pwrite -S 0x58 0 5136912" \
102 -c "mmap -rw 0 5136912" \
103 -c "mremap 5136912" \
104 -c "truncate 5136912" \
105 -c "truncate 5139720" \
106 -c "mremap -m 5139720" \
107 -c "mwrite -S 0 5136912 2808" \
108 -c "mwrite -S 0 5136912 2808" \
109 -c "mwrite -S 0 5136912 2808" \
110 -c "mremap 5136912 " \
111 -c "truncate 5136912" \
112 -c "truncate 5139720" \
113 -c "mremap -m 5139720" \
114 -c "mwrite -S 0 5136912 2808" \
115 -c "mwrite -S 0 5136912 2808" \
116 -c "mwrite -S 0x59 5136912 2808" \
117 -c "truncate 5140480" \
118 -c "mremap 5140480" \
119 -c "msync -s 0 5140480" \
120 -c "mremap 5139720" \
123 $testfile | _filter_xfs_io
125 echo "==== Pre-Remount ==="
128 echo "==== Post-Remount =="