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