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 _begin_fstest auto quick rw
14 # Import common functions.
17 # real QA test starts here
19 # Modify as appropriate.
23 testfile=$SCRATCH_MNT/testfile
25 _scratch_mkfs > /dev/null 2>&1
28 # first case is just truncate down/truncate up to check that the mapped
29 # write after the truncate up is correctly handled.
31 -c "truncate 5120" `# truncate | |` \
32 -c "pwrite -S 0x58 0 5120" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
33 -c "mmap -rw 0 5120" `# mmap | |` \
34 -c "mwrite -S 0x5a 2048 3072" `# mwrite | ZZZZZZZZZZZZZZ|` \
35 -c "truncate 2048" `# truncate dn | |` \
36 -c "truncate 5120" `# truncate up | |` \
37 -c "mwrite -S 0x59 2048 3072" `# mwrite | YYYYYYYYYYYYYY|` \
39 $testfile | _filter_xfs_io
41 echo "==== Pre-Remount ==="
44 echo "==== Post-Remount =="
50 # second case is to do a mwrite between the truncate to a block on the
51 # same page we are truncating within the EOF. This checks that a mapped
52 # write between truncate down and truncate up a further mapped
53 # write to the same page into the new space doesn't result in data being lost.
55 -c "truncate 5120" `# truncate | |` \
56 -c "pwrite -S 0x58 0 5120" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
57 -c "mmap -rw 0 5120" `# mmap | |` \
58 -c "mwrite -S 0x5a 2048 3072" `# mwrite | ZZZZZZZZZZZZZZ|` \
59 -c "truncate 2048" `# truncate dn | |` \
60 -c "mwrite -S 0x57 1024 1024" `# mwrite | WWWWW |` \
61 -c "truncate 5120" `# truncate up | |` \
62 -c "mwrite -S 0x59 2048 3072" `# mwrite | YYYYYYYYYYYYYY|` \
64 $testfile | _filter_xfs_io
66 echo "==== Pre-Remount ==="
69 echo "==== Post-Remount =="
72 # third case is the same as second case, just with non-1k aligned offsets and
75 -c "truncate 5121" `# truncate | |` \
76 -c "pwrite -S 0x58 0 5121" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
77 -c "mmap -rw 0 5121" `# mmap | |` \
78 -c "mwrite -S 0x5a 2047 3071" `# mwrite | ZZZZZZZZZZZZZZ|` \
79 -c "truncate 2047" `# truncate dn | |` \
80 -c "mwrite -S 0x57 513 1025" `# mwrite | WWWWW |` \
81 -c "truncate 5121" `# truncate up | |` \
82 -c "mwrite -S 0x59 2047 3071" `# mwrite | YYYYYYYYYYYYYY|` \
84 $testfile | _filter_xfs_io
86 echo "==== Pre-Remount ==="
89 echo "==== Post-Remount =="