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.
35 _require_xfs_io_command "mremap"
37 testfile=$SCRATCH_MNT/testfile
39 _scratch_mkfs > /dev/null 2>&1
42 # first case is just truncate down/truncate up to check that the mapped
43 # write after the truncate up is correctly handled.
45 -c "truncate 5017k" `# truncate | |` \
46 -c "pwrite -S 0x58 0 5017k" `# write |X...XXX|` \
47 -c "mmap -rw 0 5017k" `# mmap | |` \
48 -c "truncate 5020k" `# truncate up | |` \
49 -c "mremap -m 5020k" `# mremap up | |` \
50 -c "mwrite -S 0x57 5017k 3k" `# mwrite | WWWWWWWWWWWWWWWW|` \
51 -c "mremap 5017k " `# mremap dn | |` \
52 -c "truncate 5017k" `# mremap dn | |` \
53 -c "truncate 5020k" `# truncate up | |` \
54 -c "mremap -m 5020k" `# mremap up | |` \
55 -c "mwrite -S 0x59 5017k 3k" `# mwrite | YYYYYYYYYYYYYYYY|` \
57 $testfile | _filter_xfs_io
59 echo "==== Pre-Remount ==="
62 echo "==== Post-Remount =="
68 # second case is to do a mwrite between the truncate to a block on the
69 # same page we are truncating within the EOF. This checks that a mapped
70 # write between truncate down and truncate up a further mapped
71 # write to the same page into the new space doesn't result in data being lost.
73 -c "truncate 5017k" `# truncate | |` \
74 -c "pwrite -S 0x58 0 5017k" `# write |X...XXX|` \
75 -c "mmap -rw 0 5017k" `# mmap | |` \
76 -c "truncate 5020k" `# truncate up | |` \
77 -c "mremap -m 5020k" `# mremap up | |` \
78 -c "mwrite -S 0x57 5017k 3k" `# mwrite | WWWWWWWWWWWWWWWW|` \
79 -c "mremap 5017k " `# mremap dn | |` \
80 -c "truncate 5017k" `# mremap dn | |` \
81 -c "mwrite -S 0x5a 5016k 1k" `# mwrite | ZZZ |` \
82 -c "truncate 5020k" `# truncate up | |` \
83 -c "mremap -m 5020k" `# mremap up | |` \
84 -c "mwrite -S 0x59 5017k 3k" `# mwrite | YYYYYYYYYYYYYYYY|` \
86 $testfile | _filter_xfs_io
88 echo "==== Pre-Remount ==="
91 echo "==== Post-Remount =="
94 # third case is the same as the first, but this time on unaligned byte
95 # boundaries rather than block boundaries. This mimics the exact mmap write
96 # patterns of the application that exposed the bug in the first place, and
97 # so is somewhat more complex and has repeated operations in it.
99 -c "truncate 5136912" \
100 -c "pwrite -S 0x58 0 5136912" \
101 -c "mmap -rw 0 5136912" \
102 -c "mremap 5136912" \
103 -c "truncate 5136912" \
104 -c "truncate 5139720" \
105 -c "mremap -m 5139720" \
106 -c "mwrite -S 0 5136912 2808" \
107 -c "mwrite -S 0 5136912 2808" \
108 -c "mwrite -S 0 5136912 2808" \
109 -c "mremap 5136912 " \
110 -c "truncate 5136912" \
111 -c "truncate 5139720" \
112 -c "mremap -m 5139720" \
113 -c "mwrite -S 0 5136912 2808" \
114 -c "mwrite -S 0 5136912 2808" \
115 -c "mwrite -S 0x59 5136912 2808" \
116 -c "truncate 5140480" \
117 -c "mremap 5140480" \
118 -c "msync -s 0 5140480" \
119 -c "mremap 5139720" \
122 $testfile | _filter_xfs_io
124 echo "==== Pre-Remount ==="
127 echo "==== Post-Remount =="