2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
5 # FS QA Test No. generic/029
7 # Test mapped writes against 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.
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 5120" `# truncate | |` \
46 -c "pwrite -S 0x58 0 5120" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
47 -c "mmap -rw 0 5120" `# mmap | |` \
48 -c "mwrite -S 0x5a 2048 3072" `# mwrite | ZZZZZZZZZZZZZZ|` \
49 -c "truncate 2048" `# truncate dn | |` \
50 -c "truncate 5120" `# truncate up | |` \
51 -c "mwrite -S 0x59 2048 3072" `# mwrite | YYYYYYYYYYYYYY|` \
53 $testfile | _filter_xfs_io
55 echo "==== Pre-Remount ==="
58 echo "==== Post-Remount =="
64 # second case is to do a mwrite between the truncate to a block on the
65 # same page we are truncating within the EOF. This checks that a mapped
66 # write between truncate down and truncate up a further mapped
67 # write to the same page into the new space doesn't result in data being lost.
69 -c "truncate 5120" `# truncate | |` \
70 -c "pwrite -S 0x58 0 5120" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
71 -c "mmap -rw 0 5120" `# mmap | |` \
72 -c "mwrite -S 0x5a 2048 3072" `# mwrite | ZZZZZZZZZZZZZZ|` \
73 -c "truncate 2048" `# truncate dn | |` \
74 -c "mwrite -S 0x57 1024 1024" `# mwrite | WWWWW |` \
75 -c "truncate 5120" `# truncate up | |` \
76 -c "mwrite -S 0x59 2048 3072" `# mwrite | YYYYYYYYYYYYYY|` \
78 $testfile | _filter_xfs_io
80 echo "==== Pre-Remount ==="
83 echo "==== Post-Remount =="
86 # third case is the same as second case, just with non-1k aligned offsets and
89 -c "truncate 5121" `# truncate | |` \
90 -c "pwrite -S 0x58 0 5121" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
91 -c "mmap -rw 0 5121" `# mmap | |` \
92 -c "mwrite -S 0x5a 2047 3071" `# mwrite | ZZZZZZZZZZZZZZ|` \
93 -c "truncate 2047" `# truncate dn | |` \
94 -c "mwrite -S 0x57 513 1025" `# mwrite | WWWWW |` \
95 -c "truncate 5121" `# truncate up | |` \
96 -c "mwrite -S 0x59 2047 3071" `# mwrite | YYYYYYYYYYYYYY|` \
98 $testfile | _filter_xfs_io
100 echo "==== Pre-Remount ==="
103 echo "==== Post-Remount =="