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