generic/395: remove workarounds for wrong error codes
[xfstests-dev.git] / tests / generic / 030
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/030
6 #
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.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22     cd /
23     rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31
32 # Modify as appropriate.
33 _supported_fs generic
34 _require_scratch
35 _require_xfs_io_command "mremap"
36
37 testfile=$SCRATCH_MNT/testfile
38
39 _scratch_mkfs > /dev/null 2>&1
40 _scratch_mount
41
42 # first case is just truncate down/truncate up to check that the mapped
43 # write after the truncate up is correctly handled.
44 $XFS_IO_PROG -t -f \
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|` \
56 -c "close"      \
57 $testfile | _filter_xfs_io
58
59 echo "==== Pre-Remount ==="
60 hexdump -C $testfile
61 _scratch_cycle_mount
62 echo "==== Post-Remount =="
63 hexdump -C $testfile
64
65 rm -f $testfile
66 sync
67
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.
72 $XFS_IO_PROG -t -f \
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|` \
85 -c "close"      \
86 $testfile | _filter_xfs_io
87
88 echo "==== Pre-Remount ==="
89 hexdump -C $testfile
90 _scratch_cycle_mount
91 echo "==== Post-Remount =="
92 hexdump -C $testfile
93
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. 
98 $XFS_IO_PROG -t -f \
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" \
120 -c "munmap" \
121 -c "close" \
122 $testfile | _filter_xfs_io
123
124 echo "==== Pre-Remount ==="
125 hexdump -C $testfile
126 _scratch_cycle_mount
127 echo "==== Post-Remount =="
128 hexdump -C $testfile
129
130 status=0
131 exit
132