generic/405: test mkfs against thin provision device
[xfstests-dev.git] / tests / generic / 029
1 #! /bin/bash
2 # FS QA Test No. generic/029
3 #
4 # Test mapped writes against truncate down/up to ensure we get the data
5 # correctly written. This can expose data corruption bugs on filesystems where
6 # the block size is smaller than the page size.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46
47 # Modify as appropriate.
48 _supported_fs generic
49 _supported_os IRIX Linux
50 _require_scratch
51
52 testfile=$SCRATCH_MNT/testfile
53
54 _scratch_mkfs > /dev/null 2>&1
55 _scratch_mount
56
57 # first case is just truncate down/truncate up to check that the mapped
58 # write after the truncate up is correctly handled.
59 $XFS_IO_PROG -t -f \
60 -c "truncate 5120"              `# truncate     |                        |` \
61 -c "pwrite -S 0x58 0 5120"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
62 -c "mmap -rw 0 5120"            `# mmap         |                        |` \
63 -c "mwrite -S 0x5a 2048 3072"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
64 -c "truncate 2048"              `# truncate dn  |         |` \
65 -c "truncate 5120"              `# truncate up  |                        |` \
66 -c "mwrite -S 0x59 2048 3072"   `# mwrite       |          YYYYYYYYYYYYYY|` \
67 -c "close"      \
68 $testfile | _filter_xfs_io
69
70 echo "==== Pre-Remount ==="
71 hexdump -C $testfile
72 _scratch_cycle_mount
73 echo "==== Post-Remount =="
74 hexdump -C $testfile
75
76 rm -f $testfile
77 sync
78
79 # second case is to do a mwrite between the truncate to a block on the
80 # same page we are truncating within the EOF. This checks that a mapped
81 # write between truncate down and truncate up a further mapped
82 # write to the same page into the new space doesn't result in data being lost.
83 $XFS_IO_PROG -t -f \
84 -c "truncate 5120"              `# truncate     |                        |` \
85 -c "pwrite -S 0x58 0 5120"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
86 -c "mmap -rw 0 5120"            `# mmap         |                        |` \
87 -c "mwrite -S 0x5a 2048 3072"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
88 -c "truncate 2048"              `# truncate dn  |         |` \
89 -c "mwrite -S 0x57 1024 1024"   `# mwrite       |     WWWWW              |` \
90 -c "truncate 5120"              `# truncate up  |                        |` \
91 -c "mwrite -S 0x59 2048 3072"   `# mwrite       |          YYYYYYYYYYYYYY|` \
92 -c "close"      \
93 $testfile | _filter_xfs_io
94  
95 echo "==== Pre-Remount ==="
96 hexdump -C $testfile
97 _scratch_cycle_mount
98 echo "==== Post-Remount =="
99 hexdump -C $testfile
100
101 # third case is the same as second case, just with non-1k aligned offsets and
102 # sizes.
103 $XFS_IO_PROG -t -f \
104 -c "truncate 5121"              `# truncate     |                        |` \
105 -c "pwrite -S 0x58 0 5121"      `# write        |XXXXXXXXXXXXXXXXXXXXXXXX|` \
106 -c "mmap -rw 0 5121"            `# mmap         |                        |` \
107 -c "mwrite -S 0x5a 2047 3071"   `# mwrite       |          ZZZZZZZZZZZZZZ|` \
108 -c "truncate 2047"              `# truncate dn  |         |` \
109 -c "mwrite -S 0x57 513 1025"    `# mwrite       |  WWWWW                 |` \
110 -c "truncate 5121"              `# truncate up  |                        |` \
111 -c "mwrite -S 0x59 2047 3071"   `# mwrite       |          YYYYYYYYYYYYYY|` \
112 -c "close"      \
113 $testfile | _filter_xfs_io
114  
115 echo "==== Pre-Remount ==="
116 hexdump -C $testfile
117 _scratch_cycle_mount
118 echo "==== Post-Remount =="
119 hexdump -C $testfile
120
121 status=0
122 exit
123