1.1.0 release
[xfstests-dev.git] / 243
1 #! /bin/bash
2 # FS QA Test No. 243
3 #
4 # Test to ensure that the EOFBLOCK_FL gets set/unset correctly.
5 #
6 # As found by Theodore Ts'o:
7 # If a 128K file is falloc'ed using the KEEP_SIZE flag, and then
8 # write exactly 128K, the EOFBLOCK_FL doesn't get cleared correctly.
9 # This is bad since it forces e2fsck to complain about that inode.
10 # If you have a large number of inodes that are written with fallocate
11 # using KEEP_SIZE, and then fill them up to their expected size,
12 # e2fsck will potentially complain about a _huge_ number of inodes.
13 # This would also cause a huge increase in the time taken by e2fsck
14 # to complete its check.
15 #
16 # Test scenarios covered:
17 # 1. Fallocating X bytes and writing Y (Y<X) (buffered and direct io)
18 # 2. Fallocating X bytes and writing Y (Y=X) (buffered and direct io)
19 # 3. Fallocating X bytes and writing Y (Y>X) (buffered and direct io)
20 #
21 # These test cases exercise the normal and edge case conditions using
22 # falloc (and KEEP_SIZE).
23 #
24 # Ref: http://thread.gmane.org/gmane.comp.file-systems.ext4/20682
25 #
26 #-----------------------------------------------------------------------
27 # Copyright (c) 2010 Google, Inc.  All Rights Reserved.
28 #
29 # This program is free software; you can redistribute it and/or
30 # modify it under the terms of the GNU General Public License as
31 # published by the Free Software Foundation.
32 #
33 # This program is distributed in the hope that it would be useful,
34 # but WITHOUT ANY WARRANTY; without even the implied warranty of
35 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36 # GNU General Public License for more details.
37 #
38 # You should have received a copy of the GNU General Public License
39 # along with this program; if not, write the Free Software Foundation,
40 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
41 #-----------------------------------------------------------------------
42 #
43 # creator
44 owner=alal@google.com
45
46 seq=`basename $0`
47 echo "QA output created by $seq"
48
49 here=`pwd`
50 tmp=/tmp/$$
51 status=1        # failure is the default!
52 trap "_cleanup; exit \$status" 0 1 2 3 15
53
54 # Test specific macros.
55 BIT_NOT_SET=0   # inode flag - 0x400000 bit is not set.
56 BIT_SET=1       # inode flag - 0x400000 bit is set.
57
58 # Generic test cleanup function.
59 _cleanup()
60 {
61   cd /
62   rm -f $tmp.*
63 }
64
65 # Ext4 uses the EOFBLOCKS_FL bit when fallocating blocks with KEEP_SIZE
66 # enabled. The only time this bit should be set is when extending the allocated
67 # blocks further than what the i_size represents. In the situations wherein the
68 # i_size covers all allocated blocks, this bit should be cleared.
69
70 # Checks the state of the sample file in the filesystem and returns whether
71 # the inode flag 0x400000 is set or not.
72 _check_ext4_eof_flag()
73 {
74   # Check whether EOFBLOCK_FL is set.
75   # For ext4 filesystems: use debugfs to check if EOFBLOCKS_FL is set.
76   # Other filesystems: do nothing. The default fsck at the end of the test
77   # should catch any potential errors.
78   if [ "${FSTYP}" == "ext4" ]; then
79     bit_set=1
80
81     # Unmount the ${TEST_DEV}
82     umount ${TEST_DEV}
83
84     # Run debugfs to gather file_parameters - specifically iflags.
85     file_params=`debugfs ${TEST_DEV} -R "stat ${1}" 2>&1 | grep -e Flags:`
86     iflags=${file_params#*Flags: }
87
88     # Ensure that the iflags value was parsed correctly.
89     if [ -z ${iflags} ]; then
90       echo "iFlags value was not parsed successfully." >> $seq.full
91       status=1
92       exit ${status}
93     fi
94
95     # Check if EOFBLOCKS_FL is set.
96     if ((${iflags} & 0x400000)); then
97       echo "EOFBLOCK_FL bit is set." >> $seq.full
98       bit_set=1
99     else
100       echo "EOFBLOCK_FL bit is not set." >> $seq.full
101       bit_set=0
102     fi
103
104     # Check current bit state to expected value.
105     if [ ${bit_set} -ne ${2} ]; then
106       echo "Error: Current bit state incorrect." >> $seq.full
107       status=1
108       exit ${status}
109     fi
110
111     # Mount the ${TEST_DEV}
112     mount ${TEST_DEV} -t ${FSTYP} ${TEST_DIR}
113   fi
114 }
115
116 # Get standard environment, filters and checks.
117 . ./common.rc
118 . ./common.filter
119
120 # Prerequisites for the test run.
121 _supported_fs ext4 xfs btrfs gfs2
122 _supported_os Linux
123 _require_xfs_io_falloc
124
125 # Real QA test starts here.
126 rm -f $seq.full
127
128 # Remove any leftover files from last run.
129 rm -f ${TEST_DIR}/test_?
130
131 # Begin test cases.
132 echo "Test 1: Fallocate 40960 bytes and write 4096 bytes (buffered io)." \
133     >> $seq.full
134 ${XFS_IO_PROG} -F -f                    \
135     -c 'falloc -k 0 40960'              \
136     -c 'pwrite 0 4096'                  \
137     ${TEST_DIR}/test_1 | _filter_xfs_io_unique
138 _check_ext4_eof_flag test_1 ${BIT_SET}
139
140 echo "Test 2: Fallocate 40960 bytes and write 4096 bytes (direct io)." \
141     >> $seq.full
142 ${XFS_IO_PROG} -F -f -d                 \
143     -c 'falloc -k 0 40960'              \
144     -c 'pwrite 0 4096'                  \
145     ${TEST_DIR}/test_2 | _filter_xfs_io_unique
146 _check_ext4_eof_flag test_2 ${BIT_SET}
147
148 echo "Test 3: Fallocate 40960 bytes and write 40960 bytes (buffered io)." \
149     >> $seq.full
150 ${XFS_IO_PROG} -F -f                    \
151     -c 'falloc -k 0 40960'              \
152     -c 'pwrite 0 40960'                 \
153     ${TEST_DIR}/test_3 | _filter_xfs_io_unique
154 _check_ext4_eof_flag test_3 ${BIT_NOT_SET}
155
156 echo "Test 4: Fallocate 40960 bytes and write 40960 bytes (direct io)." \
157     >> $seq.full
158 ${XFS_IO_PROG} -F -f -d                 \
159     -c 'falloc -k 0 40960'              \
160     -c 'pwrite 0 40960'                 \
161     ${TEST_DIR}/test_4 | _filter_xfs_io_unique
162 _check_ext4_eof_flag test_4 ${BIT_NOT_SET}
163
164 echo "Test 5: Fallocate 128k, seek 256k and write 4k block (buffered io)." \
165     >> $seq.full
166 ${XFS_IO_PROG} -F -f                    \
167     -c 'falloc -k 0 128k'               \
168     -c 'pwrite 256k 4k'                 \
169     ${TEST_DIR}/test_5 | _filter_xfs_io_unique
170 _check_ext4_eof_flag test_5 ${BIT_NOT_SET}
171
172 echo "Test 6: Fallocate 128k, seek to 256k and write a 4k block (direct io)." \
173     >> $seq.full
174 ${XFS_IO_PROG} -F -f -d                 \
175     -c 'falloc -k 0 128k'               \
176     -c 'pwrite 256k 4k'                 \
177     ${TEST_DIR}/test_6 | _filter_xfs_io_unique
178 _check_ext4_eof_flag test_6 ${BIT_NOT_SET}
179
180 status=0
181 exit ${status}