Whamcloud - gitweb
b=3918
[fs/lustre-release.git] / lustre / tests / sanityN.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 # bug number for skipped test: 1768 3192
7 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"4   14b"}
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
11
12 SRCDIR=`dirname $0`
13 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
14
15 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
16 CREATETEST=${CREATETEST:-createtest}
17 LFIND=${LFIND:-lfind}
18 LSTRIPE=${LSTRIPE:-lstripe}
19 LCTL=${LCTL:-lctl}
20 MCREATE=${MCREATE:-mcreate}
21 OPENFILE=${OPENFILE:-openfile}
22 OPENUNLINK=${OPENUNLINK:-openunlink}
23 TOEXCL=${TOEXCL:-toexcl}
24 TRUNCATE=${TRUNCATE:-truncate}
25
26 if [ $UID -ne 0 ]; then
27         RUNAS_ID="$UID"
28         RUNAS=""
29 else
30         RUNAS_ID=${RUNAS_ID:-500}
31         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
32 fi
33
34 SAVE_PWD=$PWD
35
36 clean() {
37         echo -n "cln.."
38         sh llmountcleanup.sh > /dev/null || exit 20
39 }
40 CLEAN=${CLEAN:-}
41
42 start() {
43         echo -n "mnt.."
44         sh llrmount.sh > /dev/null || exit 10
45         echo "done"
46 }
47 START=${START:-}
48
49 log() {
50         echo "$*"
51         lctl mark "$*" 2> /dev/null || true
52 }
53
54 run_one() {
55         if ! mount | grep -q $DIR1; then
56                 $START
57         fi
58         log "== test $1: $2"
59         export TESTNAME=test_$1
60         test_$1 || error "test_$1: exit with rc=$?"
61         unset TESTNAME
62         pass
63         cd $SAVE_PWD
64         $CLEAN
65 }
66
67 run_test() {
68         for O in $ONLY; do
69                 if [ "`echo $1 | grep '\<'$O'[a-z]*\>'`" ]; then
70                         echo ""
71                         run_one $1 "$2"
72                         return $?
73                 else
74                         echo -n "."
75                 fi
76         done
77         for X in $EXCEPT $ALWAYS_EXCEPT; do
78                 if [ "`echo $1 | grep '\<'$X'[a-z]*\>'`" ]; then
79                         echo "skipping excluded test $1"
80                         return 0
81                 fi
82         done
83         if [ -z "$ONLY" ]; then
84                 run_one $1 "$2"
85                 return $?
86         fi
87 }
88
89 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
90
91 error () {
92         log "FAIL: $TESTNAME $@"
93         if [ "$SANITYLOG" ]; then
94                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
95         else
96                 exit 1
97         fi
98 }
99
100 pass() {
101         echo PASS
102 }
103
104 export MOUNT1=`mount| awk '/ lustre/ { print $3 }'| head -n 1`
105 export MOUNT2=`mount| awk '/ lustre/ { print $3 }'| tail -n 1`
106 [ -z "$MOUNT1" ] && error "NAME=$NAME not mounted once"
107 [ "$MOUNT1" = "$MOUNT2" ] && error "NAME=$NAME not mounted twice"
108 [ `mount| awk '/ lustre/ { print $3 }'| wc -l` -ne 2 ] && \
109         error "NAME=$NAME mounted more than twice"
110
111 export DIR1=${DIR1:-$MOUNT1}
112 export DIR2=${DIR2:-$MOUNT2}
113 [ -z "`echo $DIR1 | grep $MOUNT1`" ] && echo "$DIR1 not in $MOUNT1" && exit 96
114 [ -z "`echo $DIR2 | grep $MOUNT2`" ] && echo "$DIR2 not in $MOUNT2" && exit 95
115
116 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
117
118 test_1a() {
119         touch $DIR1/f1
120         [ -f $DIR2/f1 ] || error
121 }
122 run_test 1a "check create on 2 mtpt's =========================="
123
124 test_1b() {
125         chmod 777 $DIR2/f1
126         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
127         chmod a-x $DIR2/f1
128 }
129 run_test 1b "check attribute updates on 2 mtpt's ==============="
130
131 test_1c() {
132         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
133 }
134 run_test 1c "check after remount attribute updates on 2 mtpt's ="
135
136 test_1d() {
137         rm $DIR2/f1
138         $CHECKSTAT -a $DIR1/f1 || error
139 }
140 run_test 1d "unlink on one mountpoint removes file on other ===="
141
142 test_2a() {
143         touch $DIR1/f2a
144         ls -l $DIR2/f2a
145         chmod 777 $DIR2/f2a
146         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
147 }
148 run_test 2a "check cached attribute updates on 2 mtpt's ========"
149
150 test_2b() {
151         touch $DIR1/f2b
152         ls -l $DIR2/f2b
153         chmod 777 $DIR1/f2b
154         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
155 }
156 run_test 2b "check cached attribute updates on 2 mtpt's ========"
157
158 # NEED TO SAVE ROOT DIR MODE
159 test_2c() {
160         chmod 777 $DIR1
161         $CHECKSTAT -t dir -p 0777 $DIR2 || error
162 }
163 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
164
165 test_2d() {
166         chmod 755 $DIR1
167         $CHECKSTAT -t dir -p 0755 $DIR2 || error
168 }
169 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
170
171 test_3() {
172         ( cd $DIR1 ; ln -s this/is/good lnk )
173         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
174                 error
175 }
176 run_test 3 "symlink on one mtpt, readlink on another ==========="
177
178 test_4() {
179         multifstat $DIR1/f4 $DIR2/f4
180 }
181 run_test 4 "fstat validation on multiple mount points =========="
182
183 test_5() {
184         mcreate $DIR1/f5
185         truncate $DIR2/f5 100
186         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
187         rm $DIR1/f5
188 }
189 run_test 5 "create a file on one mount, truncate it on the other"
190
191 test_6() {
192         openunlink $DIR1/f6 $DIR2/f6 || error
193 }
194 run_test 6 "remove of open file on other node =================="
195
196 test_7() {
197         opendirunlink $DIR1/d7 $DIR2/d7 || error
198 }
199 run_test 7 "remove of open directory on other node ============="
200
201 test_8() {
202         opendevunlink $DIR1/dev8 $DIR2/dev8 || error
203 }
204 run_test 8 "remove of open special file on other node =========="
205
206 test_9() {
207         MTPT=1
208         > $DIR2/f9
209         for C in a b c d e f g h i j k l; do
210                 DIR=`eval echo \\$DIR$MTPT`
211                 echo -n $C >> $DIR/f9
212                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
213         done
214         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
215                 error "`od -a $DIR1/f9` != abcdefghijkl"
216 }
217 run_test 9 "append of file with sub-page size on multiple mounts"
218
219 test_10a() {
220         MTPT=1
221         OFFSET=0
222         > $DIR2/f10
223         for C in a b c d e f g h i j k l; do
224                 DIR=`eval echo \\$DIR$MTPT`
225                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
226                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
227                 OFFSET=`expr $OFFSET + 1`
228         done
229         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
230                 error "`od -a $DIR1/f10` != abcdefghijkl"
231 }
232 run_test 10a "write of file with sub-page size on multiple mounts "
233
234 test_10b() {
235         yes "R" | dd of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
236
237         truncate $DIR1/f10b 4096 || error "truncate 4096"
238
239         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
240
241         # create a test file locally to compare
242         yes "R" | dd of=$TMP/f10b bs=3k count=1 || error "dd random"
243         truncate $TMP/f10b 4096 || error "truncate 4096"
244         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
245 }
246 run_test 10b "write of file with sub-page size on multiple mounts "
247
248 test_11() {
249         mkdir $DIR1/d11
250         multiop $DIR1/d11/f O_c &
251         MULTIPID=$!
252         usleep 200
253         cp -p /bin/ls $DIR1/d11/f
254         $DIR2/d11/f
255         RC=$?
256         kill -USR1 $MULTIPID
257         wait $MULTIPID || error
258         [ $RC -eq 0 ] && error || true
259 }
260 run_test 11 "execution of file opened for write should return error ===="
261
262 test_12() {
263        sh lockorder.sh
264 }
265 run_test 12 "test lock ordering (link, stat, unlink) ==========="
266
267 test_13() {     # bug 2451 - directory coherency
268        rm -rf $DIR1/d13
269        mkdir $DIR1/d13 || error
270        cd $DIR1/d13 || error
271        ls
272        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
273        ls
274        rm -f $DIR2/d13/f13 || error
275        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
276        # need to run it twice
277        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
278        ls
279        rm -f $DIR2/d13/f13 || error
280        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
281 }
282 run_test 13 "test directory page revocation ===================="
283
284 test_14() {
285         mkdir $DIR1/d14
286         cp -p /bin/ls $DIR1/d14/ls
287         exec 100>> $DIR1/d14/ls
288         $DIR2/d14/ls && error || true
289         exec 100<&-
290 }
291 run_test 14 "execution of file open for write returns -ETXTBSY ="
292
293 test_14a() {
294         mkdir -p $DIR1/d14
295         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
296         $DIR1/d14/multiop $TMP/test14.junk O_c &
297         MULTIPID=$!
298         sleep 1
299         multiop $DIR2/d14/multiop Oc && error "expected error, got success"
300         kill -USR1 $MULTIPID || return 2
301         wait $MULTIPID || return 3
302 }
303 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
304
305 test_14b() { # bug 3192
306         mkdir -p $DIR1/d14
307         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
308         $DIR1/d14/multiop $TMP/test14.junk O_c &
309         MULTIPID=$!
310         sleep 1
311         truncate $DIR2/d14/multiop 0 && error "expected error, got success"
312         kill -USR1 $MULTIPID || return 2
313         wait $MULTIPID || return 3
314 }
315 run_test 14b "truncate of executing file returns -ETXTBSY ======"
316
317 test_14c() { # bug 3430
318         mkdir -p $DIR1/d14
319         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
320         $DIR1/d14/multiop $TMP/test14.junk O_c &
321         MULTIPID=$!
322         sleep 1
323         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
324         kill -USR1 $MULTIPID || return 2
325         wait $MULTIPID || return 3
326         #cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
327 }
328 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
329
330 test_15() {     # bug 974 - ENOSPC
331         echo $PATH
332         sh oos2.sh $MOUNT1 $MOUNT2
333 }
334 run_test 15 "test out-of-space with multiple writers ==========="
335
336 test_16() {
337         fsx -R -W -c 50 -p 100 -N 2500 $MOUNT1/fsxfile $MOUNT2/fsxfile
338 }
339 run_test 16 "2500 iterations of dual-mount fsx ================="
340
341 cancel_lru_locks() {
342         for d in /proc/fs/lustre/ldlm/namespaces/$1*; do
343                 echo clear > $d/lru_size
344         done
345         grep [0-9] /proc/fs/lustre/ldlm/namespaces/$1*/lock_unused_count /dev/null
346 }
347
348 test_17() { # bug 3513, 3667
349         [ ! -d /proc/fs/lustre/ost ] && echo "skipping OST-only test" && return
350
351         cp /etc/termcap $DIR1/f17
352         cancel_lru_locks OSC > /dev/null
353         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
354         echo 0x8000030a > /proc/sys/lustre/fail_loc
355         ls -ls $DIR1/f17 | awk '{ print $1,$6 }' > $DIR1/f17-1 & \
356         ls -ls $DIR2/f17 | awk '{ print $1,$6 }' > $DIR2/f17-2
357         wait
358         diff -u $DIR1/f17-1 $DIR2/f17-2 || error "files are different"
359 }
360 run_test 17 "resource creation/LVB creation race ==============="
361
362 log "cleanup: ======================================================"
363 rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true
364
365 echo '=========================== finished ==============================='
366 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true