26d2d4a7ec892fff0a21c902608572ffc4d89fcb
[xfstests-dev.git] / tests / generic / 310
1 #! /bin/bash
2 # FS QA Test No. 310
3 #
4 # Check if there are two threads,one keeps calling read() or lseek(), and
5 # the other calling readdir(), both on the same directory fd.
6 #
7 # Testing on ext3: with dir_index disabled results in the following
8 # dmesg output: (also occurs when testing ext2 and ext4)
9 #
10 # EXT3-fs error (device sdb): ext3_readdir: bad entry in directory #1134241:
11 # rec_len % 4 != 0 - offset=2704, inode=16973836, rec_len=12850, name_len=52
12 # EXT3-fs error (device sdb): ext3_readdir: bad entry in directory #1134241:
13 # directory entry across blocks - offset=1672, inode=16973836, rec_len=14132,
14 # name_len=57
15 #
16 # The filesystem mount option 'errors=' will define the behavior
17 # when an error is encountered. (see mount manpage)
18 #
19 # The test is based on a testcase from Li Zefan <lizefan@huawei.com>.
20 #
21 # http://marc.info/?l=linux-kernel&m=136123703211869&w=2
22 #
23 #-----------------------------------------------------------------------
24 # Copyright (c) 2013 HuaWei. All Rights Reserved.
25 #
26 # This program is free software; you can redistribute it and/or
27 # modify it under the terms of the GNU General Public License as
28 # published by the Free Software Foundation.
29 #
30 # This program is distributed in the hope that it would be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 # GNU General Public License for more details.
34 #
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write the Free Software Foundation,
37 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
38 #-----------------------------------------------------------------------
39 #
40
41 seq=`basename $0`
42 seqres=$RESULT_DIR/$seq
43 echo "QA output created by $seq"
44
45 status=1        # failure is the default!
46
47 _cleanup()
48 {
49         rm -rf $TEST_DIR/tmp
50 }
51 trap "_cleanup; exit \$status" 0 1 2 3 15
52
53 # get standard environment, filters and checks
54 . ./common/rc
55 . ./common/filter
56
57 # real QA test starts here
58 _supported_fs generic
59 _supported_os Linux
60
61 dmesg -c > /dev/null
62
63 nr_bug=`dmesg | grep -c "kernel BUG"`
64 nr_error=`dmesg | grep -c "error"`
65 nr_null=`dmesg | grep -c "kernel NULL pointer dereference"`
66 nr_warning=`dmesg | grep -c "^WARNING"`
67 nr_lockdep=`dmesg | grep -c "possible recursive locking detected"`
68
69 #check if some kind of kernel bug happened
70 check_kernel_bug()
71 {
72         new_bug=`dmesg | grep -c "kernel BUG"`
73         new_error=`dmesg | grep -c "error"`
74         new_null=`dmesg | grep -c "kernel NULL pointer dereference"`
75         new_warning=`dmesg | grep -c "^WARNING"`
76         new_lockdep=`dmesg | grep -c "possible recursive locking detected"`
77
78         # no kernel bug is detected
79         if [ $new_bug -eq $nr_bug -a $new_error -eq $nr_error -a \
80              $new_null -eq $nr_null -a $new_warning -eq $nr_warning -a \
81              $new_lockdep -eq $nr_lockdep ]; then
82                 return 0
83         fi
84
85         nr_bug=$new_bug
86         nr_error=$new_error
87         nr_null=$new_null
88         nr_warning=$new_warning
89         nr_lockdep=$new_lockdep
90         return 1
91 }
92
93 RUN_TIME=$((30 * $TIME_FACTOR))
94
95 SEQ_DIR=$TEST_DIR/$seq
96 mkdir -p $SEQ_DIR
97 for n in {1..4096}; do
98         touch $SEQ_DIR/$n
99 done
100
101 _test_read()
102 {
103         src/t_readdir_1 $SEQ_DIR &
104         sleep $RUN_TIME
105         killall src/t_readdir_1
106         check_kernel_bug
107         if [ $? -ne 0 ]; then
108                 _fatal "kernel bug detected, check dmesg for more infomation."
109         fi
110 }
111
112 _test_lseek()
113 {
114         src/t_readdir_2 $SEQ_DIR &
115         sleep $RUN_TIME
116         killall src/t_readdir_2
117         check_kernel_bug
118         if [ $? -ne 0 ]; then
119                 _fatal "kernel bug detected, check dmesg for more infomation."
120         fi
121 }
122
123 _test_read
124 _test_lseek
125
126 # success, all done
127 echo "*** done"
128 status=0
129 exit