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