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.
36 testfile=$SCRATCH_MNT/testfile
38 _scratch_mkfs > /dev/null 2>&1
41 # first case is just truncate down/truncate up to check that the mapped
42 # write after the truncate up is correctly handled.
44 -c "truncate 5120" `# truncate | |` \
45 -c "pwrite -S 0x58 0 5120" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
46 -c "mmap -rw 0 5120" `# mmap | |` \
47 -c "mwrite -S 0x5a 2048 3072" `# mwrite | ZZZZZZZZZZZZZZ|` \
48 -c "truncate 2048" `# truncate dn | |` \
49 -c "truncate 5120" `# truncate up | |` \
50 -c "mwrite -S 0x59 2048 3072" `# mwrite | YYYYYYYYYYYYYY|` \
52 $testfile | _filter_xfs_io
54 echo "==== Pre-Remount ==="
57 echo "==== Post-Remount =="
63 # second case is to do a mwrite between the truncate to a block on the
64 # same page we are truncating within the EOF. This checks that a mapped
65 # write between truncate down and truncate up a further mapped
66 # write to the same page into the new space doesn't result in data being lost.
68 -c "truncate 5120" `# truncate | |` \
69 -c "pwrite -S 0x58 0 5120" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
70 -c "mmap -rw 0 5120" `# mmap | |` \
71 -c "mwrite -S 0x5a 2048 3072" `# mwrite | ZZZZZZZZZZZZZZ|` \
72 -c "truncate 2048" `# truncate dn | |` \
73 -c "mwrite -S 0x57 1024 1024" `# mwrite | WWWWW |` \
74 -c "truncate 5120" `# truncate up | |` \
75 -c "mwrite -S 0x59 2048 3072" `# mwrite | YYYYYYYYYYYYYY|` \
77 $testfile | _filter_xfs_io
79 echo "==== Pre-Remount ==="
82 echo "==== Post-Remount =="
85 # third case is the same as second case, just with non-1k aligned offsets and
88 -c "truncate 5121" `# truncate | |` \
89 -c "pwrite -S 0x58 0 5121" `# write |XXXXXXXXXXXXXXXXXXXXXXXX|` \
90 -c "mmap -rw 0 5121" `# mmap | |` \
91 -c "mwrite -S 0x5a 2047 3071" `# mwrite | ZZZZZZZZZZZZZZ|` \
92 -c "truncate 2047" `# truncate dn | |` \
93 -c "mwrite -S 0x57 513 1025" `# mwrite | WWWWW |` \
94 -c "truncate 5121" `# truncate up | |` \
95 -c "mwrite -S 0x59 2047 3071" `# mwrite | YYYYYYYYYYYYYY|` \
97 $testfile | _filter_xfs_io
99 echo "==== Pre-Remount ==="
102 echo "==== Post-Remount =="