Whamcloud - gitweb
b=1719
[fs/lustre-release.git] / lustre / tests / sanityN.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"8"} # bug 1557
7
8 SRCDIR=`dirname $0`
9 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
10
11 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
12 CREATETEST=${CREATETEST:-createtest}
13 LFIND=${LFIND:-lfind}
14 LSTRIPE=${LSTRIPE:-lstripe}
15 LCTL=${LCTL:-lctl}
16 MCREATE=${MCREATE:-mcreate}
17 OPENFILE=${OPENFILE:-openfile}
18 OPENUNLINK=${OPENUNLINK:-openunlink}
19 TOEXCL=${TOEXCL:-toexcl}
20 TRUNCATE=${TRUNCATE:-truncate}
21
22 if [ $UID -ne 0 ]; then
23         RUNAS_ID="$UID"
24         RUNAS=""
25 else
26         RUNAS_ID=${RUNAS_ID:-500}
27         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
28 fi
29
30 export NAME=${NAME:-mount2}
31
32 SAVE_PWD=$PWD
33
34 clean() {
35         echo -n "cln.."
36         sh llmountcleanup.sh > /dev/null || exit 20
37 }
38 CLEAN=${CLEAN:-clean}
39
40 start() {
41         echo -n "mnt.."
42         sh llrmount.sh > /dev/null || exit 10
43         echo "done"
44 }
45 START=${START:-start}
46
47 log() {
48         echo "$*"
49         lctl mark "$*" 2> /dev/null || true
50 }
51
52 run_one() {
53         if ! mount | grep -q $DIR1; then
54                 $START
55         fi
56         log "== test $1: $2"
57         test_$1 || error "test_$1: $?"
58         pass
59         cd $SAVE_PWD
60         $CLEAN
61 }
62
63 run_test() {
64         for O in $ONLY; do
65                 if [ "`echo $1 | grep '\<'$O'[a-z]*\>'`" ]; then
66                         echo ""
67                         run_one $1 "$2"
68                         return $?
69                 else
70                         echo -n "."
71                 fi
72         done
73         for X in $EXCEPT $ALWAYS_EXCEPT; do
74                 if [ "`echo $1 | grep '\<'$X'[a-z]*\>'`" ]; then
75                         echo "skipping excluded test $1"
76                         return 0
77                 fi
78         done
79         if [ -z "$ONLY" ]; then
80                 run_one $1 "$2"
81                 return $?
82         fi
83 }
84
85 error () {
86         log "FAIL: $@"
87         exit 1
88 }
89
90 pass() {
91         echo PASS
92 }
93
94 MOUNT1=`mount| awk '/ lustre/ { print $3 }'| head -1`
95 MOUNT2=`mount| awk '/ lustre/ { print $3 }'| tail -1`
96 [ -z "$MOUNT1" ] && error "NAME=$NAME not mounted once"
97 [ "$MOUNT1" = "$MOUNT2" ] && error "NAME=$NAME not mounted twice"
98 [ `mount| awk '/ lustre/ { print $3 }'| wc -l` -ne 2 ] && \
99         error "NAME=$NAME mounted more than twice"
100
101 DIR1=${DIR1:-$MOUNT1}
102 DIR2=${DIR2:-$MOUNT2}
103 [ -z "`echo $DIR1 | grep $MOUNT1`" ] && echo "$DIR1 not in $MOUNT1" && exit 96
104 [ -z "`echo $DIR2 | grep $MOUNT2`" ] && echo "$DIR2 not in $MOUNT2" && exit 95
105
106 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
107
108 test_1a() {
109         touch $DIR1/f1
110         [ -f $DIR2/f1 ] || error
111 }
112 run_test 1a "check create on 2 mtpt's =========================="
113
114 test_1b() {
115         chmod 777 $DIR2/f1
116         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
117         chmod a-x $DIR2/f1
118 }
119 run_test 1b "check attribute updates on 2 mtpt's ==============="
120
121 test_1c() {
122         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
123 }
124 run_test 1c "check after remount attribute updates on 2 mtpt's ="
125
126 test_1d() {
127         rm $DIR2/f1
128         $CHECKSTAT -a $DIR1/f1 || error
129 }
130 run_test 1d "unlink on one mountpoint removes file on other ===="
131
132 test_2a() {
133         touch $DIR1/f2a
134         ls -l $DIR2/f2a
135         chmod 777 $DIR2/f2a
136         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
137 }
138 run_test 2a "check cached attribute updates on 2 mtpt's ========"
139
140 test_2b() {
141         touch $DIR1/f2b
142         ls -l $DIR2/f2b
143         chmod 777 $DIR1/f2b
144         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
145 }
146 run_test 2b "check cached attribute updates on 2 mtpt's ========"
147
148 # NEED TO SAVE ROOT DIR MODE
149 test_2c() {
150         chmod 777 $DIR1
151         $CHECKSTAT -t dir -p 0777 $DIR2 || error
152 }
153 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
154
155 test_2d() {
156         chmod 755 $DIR1
157         $CHECKSTAT -t dir -p 0755 $DIR2 || error
158 }
159 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
160
161 test_3() {
162         ( cd $DIR1 ; ln -s this/is/good lnk )
163         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
164                 error
165 }
166 run_test 3 "symlink on one mtpt, readlink on another ==========="
167
168 test_4() {
169         ./multifstat $DIR1/f4 $DIR2/f4
170 }
171 run_test 4 "fstat validation on multiple mount points =========="
172
173 test_5() {
174         mcreate $DIR1/f5
175         truncate $DIR2/f5 100
176         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
177         rm $DIR1/f5
178 }
179 run_test 5 "create a file on one mount, truncate it on the other"
180
181 test_6() {
182         ./openunlink $DIR1/f6 $DIR2/f6 || error
183 }
184 run_test 6 "remove of open file on other node =================="
185
186 test_7() {
187         ./opendirunlink $DIR1/d7 $DIR2/d7 || error
188 }
189 run_test 7 "remove of open directory on other node ============="
190
191 test_8() {
192         ./opendevunlink $DIR1/dev8 $DIR2/dev8 || error
193 }
194 run_test 8 "remove of open special file on other node =========="
195
196 test_9() {
197         MTPT=1
198         > $DIR2/f9
199         for C in a b c d e f g h i j k l; do
200                 DIR=`eval echo \\$DIR$MTPT`
201                 echo -n $C >> $DIR/f9
202                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
203         done
204         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
205                 error "`od -a $DIR1/f10` != abcdefghijkl"
206 }
207 run_test 9 "append of file with sub-page size on multiple mounts"
208
209 test_10() {
210         MTPT=1
211         OFFSET=0
212         > $DIR2/f10
213         for C in a b c d e f g h i j k l; do
214                 DIR=`eval echo \\$DIR$MTPT`
215                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
216                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
217                 OFFSET=`expr $OFFSET + 1`
218         done
219         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
220                 error "`od -a $DIR1/f10` != abcdefghijkl"
221 }
222 run_test 10 "write of file with sub-page size on multiple mounts "
223
224 test_11() {
225         mkdir $DIR1/d11
226         multiop $DIR1/d11/f O_c &
227         MULTIPID=$!
228         cp -p /bin/ls $DIR1/d11/f
229         $DIR2/d11/f
230         RC=$?
231         kill -USR1 $MULTIPID
232         wait $MULTIPID || error
233         [ $RC -eq 0 ] && error || true
234 }
235 run_test 11 "execution of file opened for write should return error ===="
236
237 test_12() {
238        sh lockorder.sh
239 }
240 run_test 12 "test lock ordering (link, stat, unlink) ==========="
241
242 log "cleanup: ======================================================"
243 rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true
244 echo '=========================== finished ==============================='