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