Whamcloud - gitweb
a4cbd2c761f86fe4e898bddbec89a083bfdb2960
[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: 3192 15528/3811 16929 9977 15528/11549 18080
7 ALWAYS_EXCEPT="                14b  19         22    28   29          35    $SANITYN_EXCEPT"
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 # bug number for skipped test:                                                    12652 12652
11 grep -q 'Enterprise Server 10' /etc/SuSE-release && ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11    14" || true
12
13 # Tests that fail on uml
14 [ "$UML" = "true" ] && EXCEPT="$EXCEPT 7"
15
16 # It will be ported soon.
17 EXCEPT="$EXCEPT 22"
18
19 SRCDIR=`dirname $0`
20 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
21
22 SIZE=${SIZE:-40960}
23 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
24 GETSTRIPE=${GETSTRIPE:-lfs getstripe}
25 SETSTRIPE=${SETSTRIPE:-lstripe}
26 MCREATE=${MCREATE:-mcreate}
27 OPENFILE=${OPENFILE:-openfile}
28 OPENUNLINK=${OPENUNLINK:-openunlink}
29 TRUNCATE=${TRUNCATE:-truncate}
30 export TMP=${TMP:-/tmp}
31 MOUNT_2=${MOUNT_2:-"yes"}
32 CHECK_GRANT=${CHECK_GRANT:-"yes"}
33 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
34
35 SAVE_PWD=$PWD
36
37 export NAME=${NAME:-local}
38
39 LUSTRE=${LUSTRE:-`dirname $0`/..}
40 . $LUSTRE/tests/test-framework.sh
41 CLEANUP=${CLEANUP:-:}
42 SETUP=${SETUP:-:}
43 init_test_env $@
44 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
45 init_logging
46
47 [ "$SLOW" = "no" ] && EXCEPT_SLOW="12 16 23 33a"
48
49 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
50 FAIL_ON_ERROR=false
51
52 SETUP=${SETUP:-:}
53 TRACE=${TRACE:-""}
54
55 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
56
57 check_and_setup_lustre
58
59 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
60 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
61
62 assert_DIR
63 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
64
65 # $RUNAS_ID may get set incorrectly somewhere else
66 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
67
68 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
69
70 build_test_filter
71
72 mkdir -p $MOUNT2
73 mount_client $MOUNT2
74
75 test_1a() {
76         touch $DIR1/f1
77         [ -f $DIR2/f1 ] || error
78 }
79 run_test 1a "check create on 2 mtpt's =========================="
80
81 test_1b() {
82         chmod 777 $DIR2/f1
83         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
84         chmod a-x $DIR2/f1
85 }
86 run_test 1b "check attribute updates on 2 mtpt's ==============="
87
88 test_1c() {
89         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
90 }
91 run_test 1c "check after remount attribute updates on 2 mtpt's ="
92
93 test_1d() {
94         rm $DIR2/f1
95         $CHECKSTAT -a $DIR1/f1 || error
96 }
97 run_test 1d "unlink on one mountpoint removes file on other ===="
98
99 test_2a() {
100         touch $DIR1/f2a
101         ls -l $DIR2/f2a
102         chmod 777 $DIR2/f2a
103         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
104 }
105 run_test 2a "check cached attribute updates on 2 mtpt's ========"
106
107 test_2b() {
108         touch $DIR1/f2b
109         ls -l $DIR2/f2b
110         chmod 777 $DIR1/f2b
111         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
112 }
113 run_test 2b "check cached attribute updates on 2 mtpt's ========"
114
115 # NEED TO SAVE ROOT DIR MODE
116 test_2c() {
117         chmod 777 $DIR1
118         $CHECKSTAT -t dir -p 0777 $DIR2 || error
119 }
120 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
121
122 test_2d() {
123         chmod 755 $DIR1
124         $CHECKSTAT -t dir -p 0755 $DIR2 || error
125 }
126 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
127
128 test_2e() {
129         chmod 755 $DIR1
130         ls -l $DIR1
131         ls -l $DIR2
132         chmod 777 $DIR1
133         $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 || error
134 }
135 run_test 2e "check chmod on root is propagated to others"
136
137 test_3() {
138         ( cd $DIR1 ; ln -s this/is/good $tfile )
139         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/$tfile'");'`" ] ||
140                 error "link $DIR2/$tfile not as expected"
141 }
142 run_test 3 "symlink on one mtpt, readlink on another ==========="
143
144 test_4() {
145         multifstat $DIR1/f4 $DIR2/f4
146 }
147 run_test 4 "fstat validation on multiple mount points =========="
148
149 test_5() {
150         mcreate $DIR1/f5
151         truncate $DIR2/f5 100
152         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
153         rm $DIR1/f5
154 }
155 run_test 5 "create a file on one mount, truncate it on the other"
156
157 test_6() {
158         openunlink $DIR1/$tfile $DIR2/$tfile || \
159                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
160 }
161 run_test 6 "remove of open file on other node =================="
162
163 test_7() {
164         local dir=d7
165         opendirunlink $DIR1/$dir $DIR2/$dir || \
166                 error "opendirunlink $DIR1/$dir $DIR2/$dir"
167 }
168 run_test 7 "remove of open directory on other node ============="
169
170 test_8() {
171         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
172                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
173 }
174 run_test 8 "remove of open special file on other node =========="
175
176 test_9() {
177         MTPT=1
178         local dir
179         > $DIR2/f9
180         for C in a b c d e f g h i j k l; do
181                 dir=`eval echo \\$DIR$MTPT`
182                 echo -n $C >> $dir/f9
183                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
184         done
185         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
186                 error "`od -a $DIR1/f9` != abcdefghijkl"
187 }
188 run_test 9 "append of file with sub-page size on multiple mounts"
189
190 test_10a() {
191         MTPT=1
192         local dir
193         OFFSET=0
194         > $DIR2/f10
195         for C in a b c d e f g h i j k l; do
196                 dir=`eval echo \\$DIR$MTPT`
197                 echo -n $C | dd of=$dir/f10 bs=1 seek=$OFFSET count=1
198                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
199                 OFFSET=`expr $OFFSET + 1`
200         done
201         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
202                 error "`od -a $DIR1/f10` != abcdefghijkl"
203 }
204 run_test 10a "write of file with sub-page size on multiple mounts "
205
206 test_10b() {
207         # create a seed file
208         yes "R" | head -c 4000 >$TMP/f10b-seed
209         dd if=$TMP/f10b-seed of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
210
211         truncate $DIR1/f10b 4096 || error "truncate 4096"
212
213         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
214
215         # create a test file locally to compare
216         dd if=$TMP/f10b-seed of=$TMP/f10b bs=3k count=1 || error "dd random"
217         truncate $TMP/f10b 4096 || error "truncate 4096"
218         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
219         rm $TMP/f10b $TMP/f10b-lustre $TMP/f10b-seed
220 }
221 run_test 10b "write of file with sub-page size on multiple mounts "
222
223 test_11() {
224         mkdir $DIR1/d11
225         multiop_bg_pause $DIR1/d11/f O_c || return 1
226         MULTIPID=$!
227         cp -p /bin/ls $DIR1/d11/f
228         $DIR2/d11/f
229         RC=$?
230         kill -USR1 $MULTIPID
231         wait $MULTIPID || error
232         [ $RC -eq 0 ] && error || true
233 }
234 run_test 11 "execution of file opened for write should return error ===="
235
236 test_12() {
237        DIR=$DIR DIR2=$DIR2 sh lockorder.sh
238 }
239 run_test 12 "test lock ordering (link, stat, unlink) ==========="
240
241 test_13() {     # bug 2451 - directory coherency
242        rm -rf $DIR1/d13
243        mkdir $DIR1/d13 || error
244        cd $DIR1/d13 || error
245        ls
246        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
247        ls
248        rm -f $DIR2/d13/f13 || error
249        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
250        # need to run it twice
251        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
252        ls
253        rm -f $DIR2/d13/f13 || error
254        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
255 }
256 run_test 13 "test directory page revocation ===================="
257
258 test_14() {
259         mkdir -p $DIR1/$tdir
260         cp -p /bin/ls $DIR1/$tdir/$tfile
261         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
262         MULTIPID=$!
263
264         $DIR2/$tdir/$tfile && error || true
265         kill -USR1 $MULTIPID
266         wait $MULTIPID || return 2
267 }
268 run_test 14 "execution of file open for write returns -ETXTBSY ="
269
270 test_14a() {
271         mkdir -p $DIR1/d14
272         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
273         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
274         MULTIOP_PID=$!
275         multiop $DIR2/d14/multiop Oc && error "expected error, got success"
276         kill -USR1 $MULTIOP_PID || return 2
277         wait $MULTIOP_PID || return 3
278         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
279 }
280 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
281
282 test_14b() { # bug 3192, 7040
283         mkdir -p $DIR1/d14
284         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
285         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
286         MULTIOP_PID=$!
287         truncate $DIR2/d14/multiop 0 && kill -9 $MULTIOP_PID && \
288                 error "expected truncate error, got success"
289         kill -USR1 $MULTIOP_PID || return 2
290         wait $MULTIOP_PID || return 3
291         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
292         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
293 }
294 run_test 14b "truncate of executing file returns -ETXTBSY ======"
295
296 test_14c() { # bug 3430, 7040
297         mkdir -p $DIR1/d14
298         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
299         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
300         MULTIOP_PID=$!
301         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
302         kill -USR1 $MULTIOP_PID || return 2
303         wait $MULTIOP_PID || return 3
304         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
305         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
306 }
307 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
308
309 test_14d() { # bug 10921
310         mkdir -p $DIR1/d14
311         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
312         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
313         MULTIOP_PID=$!
314         log chmod
315         chmod 600 $DIR1/d14/multiop || error "chmod failed"
316         kill -USR1 $MULTIOP_PID || return 2
317         wait $MULTIOP_PID || return 3
318         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
319         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
320 }
321 run_test 14d "chmod of executing file is still possible ========"
322
323 test_15() {     # bug 974 - ENOSPC
324         echo "PATH=$PATH"
325         sh oos2.sh $MOUNT1 $MOUNT2
326         grant_error=`dmesg | grep "> available"`
327         [ -z "$grant_error" ] || error "$grant_error"
328 }
329 run_test 15 "test out-of-space with multiple writers ==========="
330
331 test_16() {
332         rm -f $MOUNT1/fsxfile
333         lfs setstripe $MOUNT1/fsxfile -c -1 # b=10919
334         fsx -c 50 -p 100 -N 2500 -l $((SIZE * 256)) -S 0 $MOUNT1/fsxfile $MOUNT2/fsxfile
335 }
336 run_test 16 "2500 iterations of dual-mount fsx ================="
337
338 test_17() { # bug 3513, 3667
339         remote_ost_nodsh && skip "remote OST with nodsh" && return
340
341         lfs setstripe $DIR1/$tfile -i 0 -c 1
342         cp /etc/termcap $DIR1/$tfile
343         cancel_lru_locks osc > /dev/null
344         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
345         do_facet ost1 lctl set_param fail_loc=0x8000030a
346         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
347         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
348         wait
349         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
350 }
351 run_test 17 "resource creation/LVB creation race ==============="
352
353 test_18() {
354         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2
355         sync; sleep 1; sync
356 }
357 run_test 18 "mmap sanity check ================================="
358
359 test_19() { # bug3811
360         [ -d /proc/fs/lustre/obdfilter ] || return 0
361
362         MAX=`lctl get_param -n obdfilter.*.readcache_max_filesize | head -n 1`
363         lctl set_param -n obdfilter.*OST*.readcache_max_filesize=4096
364         dd if=/dev/urandom of=$TMP/f19b bs=512k count=32
365         SUM=`cksum $TMP/f19b | cut -d" " -f 1,2`
366         cp $TMP/f19b $DIR1/f19b
367         for i in `seq 1 20`; do
368                 [ $((i % 5)) -eq 0 ] && log "test_18 loop $i"
369                 cancel_lru_locks osc > /dev/null
370                 cksum $DIR1/f19b | cut -d" " -f 1,2 > $TMP/sum1 & \
371                 cksum $DIR2/f19b | cut -d" " -f 1,2 > $TMP/sum2
372                 wait
373                 [ "`cat $TMP/sum1`" = "$SUM" ] || \
374                         error "$DIR1/f19b `cat $TMP/sum1` != $SUM"
375                 [ "`cat $TMP/sum2`" = "$SUM" ] || \
376                         error "$DIR2/f19b `cat $TMP/sum2` != $SUM"
377         done
378         lctl set_param -n obdfilter.*OST*.readcache_max_filesize=$MAX
379         rm $DIR1/f19b
380 }
381 run_test 19 "test concurrent uncached read races ==============="
382
383 test_20() {
384         mkdir $DIR1/d20
385         cancel_lru_locks osc
386         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
387         multiop $DIR1/f20 Ow8190c
388         multiop $DIR2/f20 Oz8194w8190c
389         multiop $DIR1/f20 Oz0r8190c
390         cancel_lru_locks osc
391         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
392         [ $CNTD -gt 0 ] && \
393             error $CNTD" page left in cache after lock cancel" || true
394 }
395 run_test 20 "test extra readahead page left in cache ===="
396
397 cleanup_21() {
398         trap 0
399         umount $DIR1/d21
400 }
401
402 test_21() { # Bug 5907
403         mkdir $DIR1/d21
404         mount /etc $DIR1/d21 --bind || error "mount failed" # Poor man's mount.
405         trap cleanup_21 EXIT
406         rmdir -v $DIR1/d21 && error "Removed mounted directory"
407         rmdir -v $DIR2/d21 && echo "Removed mounted directory from another mountpoint, needs to be fixed"
408         test -d $DIR1/d21 || error "Mounted directory disappeared"
409         cleanup_21
410         test -d $DIR2/d21 || test -d $DIR1/d21 && error "Removed dir still visible after umount"
411         true
412 }
413 run_test 21 " Try to remove mountpoint on another dir ===="
414
415 test_23() { # Bug 5972
416         echo "others should see updated atime while another read" > $DIR1/f23
417         
418         # clear the lock(mode: LCK_PW) gotten from creating operation
419         cancel_lru_locks osc
420         
421         time1=`date +%s`        
422         #MAX_ATIME_DIFF 60, we update atime only if older than 60 seconds
423         sleep 61
424         
425         multiop_bg_pause $DIR1/f23 or20_c || return 1
426         # with SOM and opencache enabled, we need to close a file and cancel
427         # open lock to get atime propogated to MDS
428         kill -USR1 $!
429         cancel_lru_locks mdc
430
431         time2=`stat -c "%X" $DIR2/f23`
432
433         if (( $time2 <= $time1 )); then
434                 error "atime doesn't update among nodes"
435         fi
436
437         rm -f $DIR1/f23 || error "rm -f $DIR1/f23 failed"
438         true
439 }
440 run_test 23 " others should see updated atime while another read===="
441
442 test_24a() {
443         touch $DIR1/$tfile
444         lfs df || error "lfs df failed"
445         lfs df -ih || error "lfs df -ih failed"
446         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
447         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
448         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
449         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
450         
451         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
452 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
453         lctl --device %$OSC deactivate
454         lfs df -i || error "lfs df -i with deactivated OSC failed"
455         lctl --device %$OSC recover
456         lfs df || error "lfs df with reactivated OSC failed"
457 }
458 run_test 24a "lfs df [-ih] [path] test ========================="
459
460 test_24b() {
461         touch $DIR1/$tfile
462         fsnum=`lfs df | grep -c "filesystem summary:"`
463         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
464 }
465 run_test 24b "lfs df should show both filesystems ==============="
466
467 test_25() {
468         [ `lctl get_param -n mdc.*-mdc-*.connect_flags | grep -c acl` -lt 2 ] && \
469             skip "must have acl, skipping" && return
470
471         mkdir -p $DIR1/$tdir
472         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
473         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
474
475         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
476         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #1"
477         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
478         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir || error "setfacl $DIR2/$tdir #2"
479         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
480         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #3"
481         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
482         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir || error "setfacl $DIR2/$tdir #4"
483         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
484
485         rm -rf $DIR1/$tdir
486 }
487 run_test 25 "change ACL on one mountpoint be seen on another ==="
488
489 test_26a() {
490         utime $DIR1/f26a -s $DIR2/f26a || error
491 }
492 run_test 26a "allow mtime to get older"
493
494 test_26b() {
495         touch $DIR1/$tfile
496         sleep 1
497         echo "aaa" >> $DIR1/$tfile
498         sleep 1
499         chmod a+x $DIR2/$tfile
500         mt1=`stat -c %Y $DIR1/$tfile`
501         mt2=`stat -c %Y $DIR2/$tfile`
502
503         if [ x"$mt1" != x"$mt2" ]; then
504                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
505         fi
506 }
507 run_test 26b "sync mtime between ost and mds"
508
509 test_27() {
510         cancel_lru_locks osc
511         lctl clear
512         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
513         DD2_PID=$!
514         usleep 50
515         log "dd 1 started"
516         
517         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
518         DD1_PID=$!
519         log "dd 2 started"
520         
521         sleep 1
522         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
523         log "dd 3 finished"
524         lctl set_param -n ldlm.dump_namespaces ""
525         wait $DD1_PID $DD2_PID
526         [ $? -ne 0 ] && lctl dk $TMP/debug || true
527 }
528 run_test 27 "align non-overlapping extent locks from request ==="
529
530 test_28() { # bug 9977
531         ECHO_UUID="ECHO_osc1_UUID"
532         tOST=`$LCTL dl | | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -1`
533
534         lfs setstripe $DIR1/$tfile -s 1048576 -i 0 -c 2
535         tOBJID=`lfs getstripe $DIR1/$tfile |grep "^[[:space:]]\+1" |awk '{print $2}'`
536         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
537
538         $LCTL <<-EOF
539                 newdev
540                 attach echo_client ECHO_osc1 $ECHO_UUID
541                 setup $tOST
542         EOF
543
544         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{print $1}'`
545         $LCTL --device $tECHOID destroy "${tOBJID}:0"
546
547         $LCTL <<-EOF
548                 cfg_device ECHO_osc1
549                 cleanup
550                 detach
551         EOF
552
553         # reading of 1st stripe should pass
554         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
555         # reading of 2nd stripe should fail (this stripe was destroyed)
556         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
557
558         # now, recreating test file
559         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
560         # reading of 1st stripe should pass
561         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
562         # reading of 2nd stripe should pass
563         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
564 }
565 run_test 28 "read/write/truncate file with lost stripes"
566
567 test_29() { # bug 10999
568         touch $DIR1/$tfile
569         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
570         lctl set_param fail_loc=0x8000030f
571         ls -l $DIR2/$tfile &
572         usleep 500
573         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
574         wait
575 }
576 #bug 11549 - permanently turn test off in b1_5
577 run_test 29 "lock put race between glimpse and enqueue ========="
578
579 test_30() { #bug #11110
580     mkdir -p $DIR1/$tdir
581     cp -f /bin/bash $DIR1/$tdir/bash
582     /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
583     err=$($DIR1/$tdir/bash -c 'sleep 2; openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?')
584     wait
585     [ $err -ne 116 ] && error_ignore 12900 "return code ($err) != -ESTALE" && return
586     true
587 }
588
589 run_test 30 "recreate file race ========="
590
591 test_31a() {
592         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
593         writes=`LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile count=1 2>&1 |
594                 awk 'BEGIN { FS="+" } /out/ {print $1}'`
595         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
596         lctl set_param fail_loc=0x314
597         reads=`LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
598                awk 'BEGIN { FS="+" } /in/ {print $1}'`
599         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
600 }
601 run_test 31a "voluntary cancel / blocking ast race=============="
602
603 test_31b() {
604         remote_ost || { skip "local OST" && return 0; }
605         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
606         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
607         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
608         cp /etc/hosts $DIR/$tdir/$tfile
609         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
610         lctl set_param fail_loc=0x314
611         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
612         do_facet ost1 lctl set_param fail_loc=0x316
613         # Don't crash kernel
614         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
615         lctl set_param fail_loc=0
616         do_facet ost1 lctl set_param fail_loc=0
617         # cleanup: reconnect the client back
618         df $DIR2
619 }
620 run_test 31b "voluntary OST cancel / blocking ast race=============="
621
622 # enable/disable lockless truncate feature, depending on the arg 0/1
623 enable_lockless_truncate() {
624         lctl set_param -n osc.*.lockless_truncate $1
625 }
626
627 test_32a() { # bug 11270
628         local p="$TMP/sanityN-$TESTNAME.parameters"
629         save_lustre_params $HOSTNAME osc.*.lockless_truncate > $p
630         cancel_lru_locks osc
631         enable_lockless_truncate 1
632         rm -f $DIR1/$tfile
633         lfs setstripe -c -1 $DIR1/$tfile
634         dd if=/dev/zero of=$DIR1/$tfile count=10 bs=1M > /dev/null 2>&1
635         clear_osc_stats
636
637         log "checking cached lockless truncate"
638         $TRUNCATE $DIR1/$tfile 8000000
639         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
640         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
641                 error "lockless truncate doesn't use cached locks"
642
643         log "checking not cached lockless truncate"
644         $TRUNCATE $DIR2/$tfile 5000000
645         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
646         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
647                 error "not cached trancate isn't lockless"
648
649         log "disabled lockless truncate"
650         enable_lockless_truncate 0
651         clear_osc_stats
652         $TRUNCATE $DIR2/$tfile 3000000
653         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
654         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
655                 error "lockless truncate disabling failed"
656         rm $DIR1/$tfile
657         # restore lockless_truncate default values
658         restore_lustre_params < $p
659         rm -f $p
660 }
661 run_test 32a "lockless truncate"
662
663 test_32b() { # bug 11270
664         remote_ost_nodsh && skip "remote OST with nodsh" && return
665
666         local node
667         local p="$TMP/sanityN-$TESTNAME.parameters"
668         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
669         for node in $(osts_nodes); do
670                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
671                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
672                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
673         done
674         clear_osc_stats
675         # agressive lockless i/o settings
676         for node in $(osts_nodes); do
677                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
678         done
679         lctl set_param -n osc.*.contention_seconds 60
680         for i in $(seq 5); do
681                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
682                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
683         done
684         [ $(calc_osc_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
685         # disable lockless i/o (it is disabled by default)
686         for node in $(osts_nodes); do
687                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
688         done
689         # set contention_seconds to 0 at client too, otherwise Lustre still
690         # remembers lock contention
691         lctl set_param -n osc.*.contention_seconds 0
692         clear_osc_stats
693         for i in $(seq 1); do
694                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
695                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
696         done
697         [ $(calc_osc_stats lockless_write_bytes) -eq 0 ] ||
698                 error "lockless i/o works when disabled"
699         rm -f $DIR1/$tfile
700         restore_lustre_params <$p
701         rm -f $p
702 }
703 run_test 32b "lockless i/o"
704
705 print_jbd_stat () {
706     local dev
707     local mdts=$(get_facets MDS)
708     local varcvs
709     local mds
710
711     local stat=0
712     for mds in ${mdts//,/ }; do
713         varsvc=${mds}_svc
714         dev=$(basename $(do_facet $mds lctl get_param -n osd.${!varsvc}.mntdev))
715         val=$(do_facet $mds "procfile=/proc/fs/jbd/$dev/info;
716 [ -f \\\$procfile ] || procfile=/proc/fs/jbd2/$dev/info;
717 [ -f \\\$procfile ] || procfile=/proc/fs/jbd2/${dev}\:\\\*/info;
718 cat \\\$procfile | head -1;")
719         val=${val%% *};
720         stat=$(( stat + val))
721     done
722     echo $stat
723 }
724
725 # commit on sharing tests
726 test_33a() {
727     remote_mds_nodsh && skip "remote MDS with nodsh" && return
728
729     [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
730     [ $CLIENTCOUNT -ge 2 ] || \
731         { skip "Need two or more clients, have $CLIENTCOUNT" && return 0; }
732
733     local nfiles=${TEST33_NFILES:-10000}
734     local param_file=$TMP/$tfile-params
735
736     save_lustre_params $(comma_list $(mdts_nodes)) "mdt.*.commit_on_sharing" > $param_file
737
738     local COS
739     local jbdold
740     local jbdnew
741     local jbd
742
743     for COS in 0 1; do
744         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
745         avgjbd=0
746         avgtime=0
747         for i in 1 2 3; do
748             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
749
750             jbdold=$(print_jbd_stat)
751             echo "=== START createmany old: $jbdold transaction"
752             local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- -r $DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > /dev/null 2>&1")
753             jbdnew=$(print_jbd_stat)
754             jbd=$(( jbdnew - jbdold ))
755             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
756             avgjbd=$(( avgjbd + jbd ))
757             avgtime=$(( avgtime + elapsed ))
758         done
759         eval cos${COS}_jbd=$((avgjbd / 3))
760         eval cos${COS}_time=$((avgtime / 3))
761     done
762
763     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
764     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
765     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
766     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
767
768     restore_lustre_params < $param_file
769     rm -f $param_file
770     return 0
771 }
772 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
773
774 # End commit on sharing tests
775
776 test_34() { #16129
777         local OPER
778         local lock_in
779         local lock_out
780         for OPER in notimeout timeout ; do
781                 rm $DIR1/$tfile 2>/dev/null
782                 lock_in=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
783                 if [ $OPER == "timeout" ] ; then
784                         for j in `seq $OSTCOUNT`; do
785                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
786                                 do_facet ost$j lctl set_param fail_loc=0x511
787                         done
788                         echo lock should expire
789                 else
790                         for j in `seq $OSTCOUNT`; do
791                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
792                                 do_facet ost$j lctl set_param fail_loc=0x512
793                         done
794                         echo lock should not expire
795                 fi
796                 echo writing on client1
797                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
798                 sync &
799                 echo reading on client2
800                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
801                 # wait for a lock timeout
802                 sleep 4
803                 lock_out=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
804                 if [ $OPER == "timeout" ] ; then
805                         if [ $lock_in == $lock_out ]; then
806                                 error "no lock timeout happened"
807                         else
808                                 echo "success"
809                         fi
810                 else
811                         if [ $lock_in != $lock_out ]; then
812                                 error "lock timeout happened"
813                         else
814                                 echo "success"
815                         fi
816                 fi
817         done
818 }
819 run_test 34 "no lock timeout under IO"
820
821 test_35() { # bug 17645
822         local generation=[]
823         local count=0
824         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
825             g=$(awk '/generation/{print $2}' $imp/import)
826             generation[count]=$g
827             let count=count+1
828         done
829
830         mkdir -p $MOUNT1/$tfile
831         cancel_lru_locks mdc
832
833         # Let's initiate -EINTR situation by setting fail_loc and take
834         # write lock on same file from same client. This will not cause
835         # bl_ast yet as lock is already in local cache.
836 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
837         do_facet client "lctl set_param fail_loc=0x80000317"
838         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
839         let timeout=timeout*3
840         local nr=0
841         while test $nr -lt 10; do
842                 log "Race attempt $nr"
843                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
844                 test "x$blk1" = "x" && blk1=0
845                 createmany -o $MOUNT2/$tfile/a 4000 &
846                 pid1=$!
847                 sleep 1
848
849                 # Let's make conflict and bl_ast
850                 ls -la $MOUNT1/$tfile > /dev/null &
851                 pid2=$!
852
853                 log "Wait for $pid1 $pid2 for $timeout sec..."
854                 sleep $timeout
855                 kill -9 $pid1 $pid2 > /dev/null 2>&1
856                 wait
857                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
858                 test "x$blk2" = "x" && blk2=0
859                 test $blk2 -gt $blk1 && break
860                 rm -fr $MOUNT1/$tfile/*
861                 cancel_lru_locks mdc
862                 let nr=nr+1
863         done
864         do_facet client "lctl set_param fail_loc=0x0"
865         df -h $MOUNT1 $MOUNT2
866         count=0
867         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
868             g=$(awk '/generation/{print $2}' $imp/import)
869             if ! test "$g" -eq "${generation[count]}"; then
870                 error "Eviction happened on import $(basename $imp)"
871             fi
872             let count=count+1
873         done
874 }
875 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
876
877 test_36() { #bug 16417
878     local SIZE
879     local SIZE_B
880     local i
881
882     mkdir -p $DIR1/$tdir
883     $LFS setstripe -c -1 $DIR1/$tdir
884     i=0
885     SIZE=50
886     let SIZE_B=SIZE*1024*1024
887
888     while [ $i -le 10 ]; do
889         lctl mark "start test"
890         local before=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
891         dd if=/dev/zero of=$DIR1/$tdir/file000 bs=1M count=$SIZE
892         sync
893         sleep 1
894         local after_dd=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
895         multiop_bg_pause $DIR2/$tdir/file000 O_r${SIZE_B}c || return 3
896         read_pid=$!
897         rm -f $DIR1/$tdir/file000
898         kill -USR1 $read_pid
899         wait $read_pid
900         sleep 1
901         local after=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
902         echo "*** cycle($i) *** before($before):after_dd($after_dd):after($after)"
903         # this free space! not used
904         if [ $after_dd -ge $after ]; then
905             error "space leaked"
906             return 1;
907         fi
908         let i=i+1
909             done
910 }
911 run_test 36 "handle ESTALE/open-unlink corectly"
912
913 test_37() { # bug 18695
914         mkdir -p $DIR1/$tdir
915         multiop_bg_pause $DIR1/$tdir D_c || return 1
916         MULTIPID=$!
917         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
918         createmany -m $DIR2/$tdir/f 10000
919         # set mtime/atime backward
920         touch -t 198001010000 $DIR2/$tdir
921         kill -USR1 $MULTIPID
922         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
923         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
924
925 }
926 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
927
928 # this should be set to past
929 TEST_39_MTIME=`date -d "1 year ago" +%s`
930
931 # bug 11063
932 test_39a() {
933         local client1=${CLIENT1:-`hostname`}
934         local client2=${CLIENT2:-`hostname`}
935
936         do_node $client1 "touch $DIR1/$tfile"
937
938         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
939         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
940         [ "$mtime1" = $TEST_39_MTIME ] || \
941                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
942
943         local d1=`do_node $client1 date +%s`
944         do_node $client1 'echo hello >> '$DIR1/$tfile
945         local d2=`do_node $client1 date +%s`
946
947         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
948         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
949                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
950
951         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
952
953         for (( i=0; i < 2; i++ )) ; do
954                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
955                 [ "$mtime2" = "$mtime3" ] || \
956                         error "mtime ($mtime2) changed (to $mtime3) on rename"
957
958                 cancel_lru_locks osc
959                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
960         done
961 }
962 run_test 39a "test from 11063 =================================="
963
964 test_39b() {
965         local client1=${CLIENT1:-`hostname`}
966         local client2=${CLIENT2:-`hostname`}
967
968         touch $DIR1/$tfile
969
970         local mtime1=`stat -c %Y $DIR1/$tfile`
971         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
972
973         sleep 1
974         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
975
976         for (( i=0; i < 2; i++ )) ; do
977                 local mtime3=`stat -c %Y $DIR1/$tfile`
978                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
979
980                 [ "$mtime3" = "$mtime4" ] || \
981                         error "different mtime on clients: $mtime3, $mtime4"
982                 [ "$mtime3" = $TEST_39_MTIME ] || \
983                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
984
985                 cancel_lru_locks osc
986                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
987         done
988 }
989 run_test 39b "11063 problem 1 =================================="
990
991 test_39c() {
992         local client1=${CLIENT1:-`hostname`}
993         local client2=${CLIENT2:-`hostname`}
994
995         echo hello > $DIR1/$tfile
996
997         local mtime1=`stat -c %Y $DIR1/$tfile`
998         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
999         [ "$mtime1" = "$mtime2" ] || \
1000                 error "create: different mtime on clients: $mtime1, $mtime2"
1001
1002         sleep 1
1003         $TRUNCATE $DIR1/$tfile 1
1004
1005         for (( i=0; i < 2; i++ )) ; do
1006                 local mtime3=`stat -c %Y $DIR1/$tfile`
1007                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1008
1009                 [ "$mtime3" = "$mtime4" ] || \
1010                         error "different mtime on clients: $mtime3, $mtime4"
1011                 [ "$mtime3" -gt $mtime2 ] || \
1012                         error "truncate did not update mtime: $mtime2, $mtime3"
1013
1014                 cancel_lru_locks osc
1015                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1016         done
1017 }
1018 run_test 39c "check truncate mtime update ======================"
1019
1020 # check that pid exists hence second operation wasn't blocked by first one
1021 # if it is so then there is no conflict, return 0
1022 # else second operation is conflicting with first one, return 1
1023 check_pdo_conflict() {
1024         local pid=$1
1025         local conflict=0
1026         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1027                 conflict=1
1028                 echo "Conflict"
1029         else
1030                 echo "No conflict"
1031         fi
1032         return $conflict
1033 }
1034
1035 # pdirop tests
1036 # test 40: check non-blocking operations
1037 test_40a() {
1038 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1039         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1040         mkdir $DIR1/$tfile &
1041         PID1=$!
1042         sleep 1
1043         touch $DIR2/$tfile-2
1044         check_pdo_conflict $PID1 || error "create is blocked"
1045         mkdir $DIR2/$tfile-3
1046         check_pdo_conflict $PID1 || error "mkdir is blocked"
1047         link $DIR2/$tfile-2 $DIR2/$tfile-4
1048         check_pdo_conflict $PID1 || error "link is blocked"
1049         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1050         check_pdo_conflict $PID1 || error "rename is blocked"
1051         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1052         check_pdo_conflict $PID1 || error "getattr is blocked"
1053         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1054         rmdir $DIR2/$tfile-3
1055         check_pdo_conflict $PID1 || error "unlink is blocked"
1056         # all operations above shouldn't wait the first one
1057         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1058         wait $PID1
1059         rm -r $DIR1/*
1060         return 0
1061 }
1062 run_test 40a "pdirops: create vs others =============="
1063
1064 test_40b() {
1065 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1066         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1067         touch $DIR1/$tfile &
1068         PID1=$!
1069         sleep 1
1070         # open|create
1071         touch $DIR2/$tfile-2
1072         check_pdo_conflict $PID1 || error "create is blocked"
1073         mkdir $DIR2/$tfile-3
1074         check_pdo_conflict $PID1 || error "mkdir is blocked"
1075         link $DIR2/$tfile-2 $DIR2/$tfile-4
1076         check_pdo_conflict $PID1 || error "link is blocked"
1077         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1078         check_pdo_conflict $PID1 || error "rename is blocked"
1079         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1080         check_pdo_conflict $PID1 || error "getattr is blocked"
1081         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1082         rmdir $DIR2/$tfile-3
1083         check_pdo_conflict $PID1 || error "unlink is blocked"
1084         # all operations above shouldn't wait the first one
1085         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1086         wait $PID1
1087         rm -r $DIR1/*
1088         return 0
1089 }
1090 run_test 40b "pdirops: open|create and others =============="
1091
1092 test_40c() {
1093         touch $DIR1/$tfile
1094 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1095         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1096         link $DIR1/$tfile $DIR1/$tfile-0 &
1097         PID1=$!
1098         sleep 1
1099         # open|create
1100         touch $DIR2/$tfile-2
1101         check_pdo_conflict $PID1 || error "create is blocked"
1102         mkdir $DIR2/$tfile-3
1103         check_pdo_conflict $PID1 || error "mkdir is blocked"
1104         link $DIR2/$tfile-2 $DIR2/$tfile-4
1105         check_pdo_conflict $PID1 || error "link is blocked"
1106         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1107         check_pdo_conflict $PID1 || error "rename is blocked"
1108         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1109         check_pdo_conflict $PID1 || error "getattr is blocked"
1110         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1111         rmdir $DIR2/$tfile-3
1112         check_pdo_conflict $PID1 || error "unlink is blocked"
1113         # all operations above shouldn't wait the first one
1114         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1115         wait $PID1
1116         rm -r $DIR1/*
1117         return 0
1118 }
1119 run_test 40c "pdirops: link and others =============="
1120
1121 test_40d() {
1122         touch $DIR1/$tfile
1123 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1124         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1125         rm $DIR1/$tfile &
1126         PID1=$!
1127         sleep 1
1128         # open|create
1129         touch $DIR2/$tfile-2
1130         check_pdo_conflict $PID1 || error "create is blocked"
1131         mkdir $DIR2/$tfile-3
1132         check_pdo_conflict $PID1 || error "mkdir is blocked"
1133         link $DIR2/$tfile-2 $DIR2/$tfile-4
1134         check_pdo_conflict $PID1 || error "link is blocked"
1135         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1136         check_pdo_conflict $PID1 || error "rename is blocked"
1137         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1138         check_pdo_conflict $PID1 || error "getattr is blocked"
1139         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1140         rmdir $DIR2/$tfile-3
1141         check_pdo_conflict $PID1 || error "unlink is blocked"
1142         # all operations above shouldn't wait the first one
1143         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1144         wait $PID1
1145         return 0
1146 }
1147 run_test 40d "pdirops: unlink and others =============="
1148
1149 test_40e() {
1150         touch $DIR1/$tfile
1151 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1152         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1153         mv $DIR1/$tfile $DIR1/$tfile-0 &
1154         PID1=$!
1155         sleep 1
1156         # open|create
1157         touch $DIR2/$tfile-2
1158         check_pdo_conflict $PID1 || error "create is blocked"
1159         mkdir $DIR2/$tfile-3
1160         check_pdo_conflict $PID1 || error "mkdir is blocked"
1161         link $DIR2/$tfile-2 $DIR2/$tfile-4
1162         check_pdo_conflict $PID1 || error "link is blocked"
1163         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1164         check_pdo_conflict $PID1 || error "getattr is blocked"
1165         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1166         rmdir $DIR2/$tfile-3
1167         check_pdo_conflict $PID1 || error "unlink is blocked"
1168         # all operations above shouldn't wait the first one
1169         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1170         wait $PID1
1171         rm -r $DIR1/*
1172         return 0
1173 }
1174 run_test 40e "pdirops: rename and others =============="
1175
1176 # test 41: create blocking operations
1177 test_41a() {
1178 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1179         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1180         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1181         PID1=$!
1182         sleep 1
1183         mkdir $DIR2/$tfile && error "mkdir must fail"
1184         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1185         rm -r $DIR1/*
1186         return 0
1187 }
1188 run_test 41a "pdirops: create vs mkdir =============="
1189
1190 test_41b() {
1191 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1192         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1193         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1194         PID1=$!
1195         sleep 1
1196         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1197         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1198         rm -r $DIR1/*
1199         return 0
1200 }
1201 run_test 41b "pdirops: create vs create =============="
1202
1203 test_41c() {
1204         touch $DIR1/$tfile-2
1205 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1206         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1207         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1208         PID1=$!
1209         sleep 1
1210         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1211         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1212         rm -r $DIR1/*
1213         return 0
1214 }
1215 run_test 41c "pdirops: create vs link =============="
1216
1217 test_41d() {
1218 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1219         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1220         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1221         PID1=$!
1222         sleep 1
1223         rm $DIR2/$tfile || error "unlink must succeed"
1224         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1225         rm -r $DIR1/*
1226         return 0
1227 }
1228 run_test 41d "pdirops: create vs unlink =============="
1229
1230 test_41e() {
1231         touch $DIR1/$tfile-2
1232 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1233         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1234         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1235         PID1=$!
1236         sleep 1
1237         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1238         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1239         rm -r $DIR1/*
1240         return 0
1241 }
1242 run_test 41e "pdirops: create and rename (tgt) =============="
1243
1244 test_41f() {
1245 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1246         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1247         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1248         PID1=$!
1249         sleep 1
1250         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1251         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1252         rm -r $DIR1/*
1253         return 0
1254 }
1255 run_test 41f "pdirops: create and rename (src) =============="
1256
1257 test_41g() {
1258 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1259         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1260         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1261         PID1=$!
1262         sleep 1
1263         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1264         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1265         rm -r $DIR1/*
1266         return 0
1267 }
1268 run_test 41g "pdirops: create vs getattr =============="
1269
1270 test_41h() {
1271 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1272         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1273         multiop $DIR1/$tfile oO_CREAT:O_RDWR:c &
1274         PID1=$!
1275         sleep 1
1276         ls -lia $DIR2/ > /dev/null
1277         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1278         rm -r $DIR1/*
1279         return 0
1280 }
1281 run_test 41h "pdirops: create vs readdir =============="
1282
1283 # test 42: unlink and blocking operations
1284 test_42a() {
1285 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1286         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1287         mkdir $DIR1/$tfile &
1288         PID1=$!
1289         sleep 1
1290         mkdir $DIR2/$tfile && error "mkdir must fail"
1291         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1292         rm -r $DIR1/*
1293         return 0
1294 }
1295 run_test 42a "pdirops: mkdir vs mkdir =============="
1296
1297 test_42b() {
1298 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1299         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1300         mkdir $DIR1/$tfile &
1301         PID1=$!
1302         sleep 1
1303         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1304         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1305         rm -r $DIR1/*
1306         return 0
1307 }
1308 run_test 42b "pdirops: mkdir vs create =============="
1309
1310 test_42c() {
1311         touch $DIR1/$tfile-2
1312 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1313         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1314         mkdir $DIR1/$tfile &
1315         PID1=$!
1316         sleep 1
1317         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1318         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1319         rm -r $DIR1/*
1320         return 0
1321 }
1322 run_test 42c "pdirops: mkdir vs link =============="
1323
1324 test_42d() {
1325 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1326         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1327         mkdir $DIR1/$tfile &
1328         PID1=$!
1329         sleep 1
1330         rmdir $DIR2/$tfile || error "unlink must succeed"
1331         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1332         rm -r $DIR1/*
1333         return 0
1334 }
1335 run_test 42d "pdirops: mkdir vs unlink =============="
1336
1337 test_42e() {
1338         touch $DIR1/$tfile-2
1339 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1340         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1341         mkdir $DIR1/$tfile &
1342         PID1=$!
1343         sleep 1
1344         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1345         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1346         rm -r $DIR1/*
1347         return 0
1348 }
1349 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1350
1351 test_42f() {
1352 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1353         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1354         mkdir $DIR1/$tfile &
1355         PID1=$!
1356         sleep 1
1357         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1358         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1359         rm -r $DIR1/*
1360         return 0
1361 }
1362 run_test 42f "pdirops: mkdir and rename (src) =============="
1363
1364 test_42g() {
1365 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1366         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1367         mkdir $DIR1/$tfile &
1368         PID1=$!
1369         sleep 1
1370         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1371         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1372         rm -r $DIR1/*
1373         return 0
1374 }
1375 run_test 42g "pdirops: mkdir vs getattr =============="
1376
1377 test_42h() {
1378 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1379         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1380         mkdir $DIR1/$tfile &
1381         PID1=$!
1382         sleep 1
1383         ls -lia $DIR2/ > /dev/null
1384         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1385         rm -r $DIR1/*
1386         return 0
1387 }
1388 run_test 42h "pdirops: mkdir vs readdir =============="
1389
1390 # test 43: unlink and blocking operations
1391 test_43a() {
1392         touch $DIR1/$tfile
1393 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1394         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1395         rm $DIR1/$tfile &
1396         PID1=$!
1397         sleep 1
1398         mkdir $DIR2/$tfile || error "mkdir must succeed"
1399         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1400         rm -r $DIR1/*
1401         return 0
1402 }
1403 run_test 43a "pdirops: unlink vs mkdir =============="
1404
1405 test_43b() {
1406         touch $DIR1/$tfile
1407 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1408         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1409         rm $DIR1/$tfile &
1410         PID1=$!
1411         sleep 1
1412         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1413         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1414         rm -r $DIR1/*
1415         return 0
1416 }
1417 run_test 43b "pdirops: unlink vs create =============="
1418
1419 test_43c() {
1420         touch $DIR1/$tfile
1421         touch $DIR1/$tfile-2
1422 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1423         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1424         rm $DIR1/$tfile &
1425         PID1=$!
1426         sleep 1
1427         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1428         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1429         rm -r $DIR1/*
1430         return 0
1431 }
1432 run_test 43c "pdirops: unlink vs link =============="
1433
1434 test_43d() {
1435         touch $DIR1/$tfile
1436 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1437         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1438         rm $DIR1/$tfile &
1439         PID1=$!
1440         sleep 1
1441         rm $DIR2/$tfile && error "unlink must fail"
1442         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1443         rm -r $DIR1/*
1444         return 0
1445 }
1446 run_test 43d "pdirops: unlink vs unlink =============="
1447
1448 test_43e() {
1449         touch $DIR1/$tfile
1450         touch $DIR1/$tfile-2
1451 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1452         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1453         rm $DIR1/$tfile &
1454         PID1=$!
1455         sleep 1
1456         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1457         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1458         rm -r $DIR1/*
1459         return 0
1460 }
1461 run_test 43e "pdirops: unlink and rename (tgt) =============="
1462
1463 test_43f() {
1464         touch $DIR1/$tfile
1465 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1466         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1467         rm $DIR1/$tfile &
1468         PID1=$!
1469         sleep 1
1470         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1471         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1472         rm -r $DIR1/*
1473         return 0
1474 }
1475 run_test 43f "pdirops: unlink and rename (src) =============="
1476
1477 test_43g() {
1478         touch $DIR1/$tfile
1479 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1480         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1481         rm $DIR1/$tfile &
1482         PID1=$!
1483         sleep 1
1484         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1485         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1486         rm -r $DIR1/*
1487         return 0
1488 }
1489 run_test 43g "pdirops: unlink vs getattr =============="
1490
1491 test_43h() {
1492         touch $DIR1/$tfile
1493 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1494         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1495         rm $DIR1/$tfile &
1496         PID1=$!
1497         sleep 1
1498         ls -lia $DIR2/ > /dev/null
1499         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1500         rm -r $DIR1/*
1501         return 0
1502 }
1503 run_test 43h "pdirops: unlink vs readdir =============="
1504
1505 # test 44: rename tgt and blocking operations
1506 test_44a() {
1507         touch $DIR1/$tfile-2
1508 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1509         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1510         mv $DIR1/$tfile-2 $DIR1/$tfile &
1511         PID1=$!
1512         sleep 1
1513         mkdir $DIR2/$tfile && error "mkdir must fail"
1514         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1515         rm -r $DIR1/*
1516         return 0
1517 }
1518 run_test 44a "pdirops: rename tgt vs mkdir =============="
1519
1520 test_44b() {
1521         touch $DIR1/$tfile-2
1522 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1523         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1524         mv $DIR1/$tfile-2 $DIR1/$tfile &
1525         PID1=$!
1526         sleep 1
1527         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1528         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1529         rm -r $DIR1/*
1530         return 0
1531 }
1532 run_test 44b "pdirops: rename tgt vs create =============="
1533
1534 test_44c() {
1535         touch $DIR1/$tfile-2
1536         touch $DIR1/$tfile-3
1537 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1538         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1539         mv $DIR1/$tfile-2 $DIR1/$tfile &
1540         PID1=$!
1541         sleep 1
1542         link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
1543         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1544         rm -r $DIR1/*
1545         return 0
1546 }
1547 run_test 44c "pdirops: rename tgt vs link =============="
1548
1549 test_44d() {
1550         touch $DIR1/$tfile-2
1551 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1552         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1553         mv $DIR1/$tfile-2 $DIR1/$tfile &
1554         PID1=$!
1555         sleep 1
1556         rm $DIR2/$tfile || error "unlink must succeed"
1557         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1558         rm -r $DIR1/*
1559         return 0
1560 }
1561 run_test 44d "pdirops: rename tgt vs unlink =============="
1562
1563 test_44e() {
1564         touch $DIR1/$tfile
1565         touch $DIR1/$tfile-2
1566         touch $DIR1/$tfile-3
1567 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1568         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1569         mv $DIR1/$tfile-2 $DIR1/$tfile &
1570         PID1=$!
1571         sleep 1
1572         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1573         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1574         rm -r $DIR1/*
1575         return 0
1576 }
1577 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
1578
1579 test_44f() {
1580         touch $DIR1/$tfile-2
1581         touch $DIR1/$tfile-3
1582 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1583         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1584         mv $DIR1/$tfile-2 $DIR1/$tfile &
1585         PID1=$!
1586         sleep 1
1587         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1588         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1589         rm -r $DIR1/*
1590         return 0
1591 }
1592 run_test 44f "pdirops: rename tgt and rename (src) =============="
1593
1594 test_44g() {
1595         touch $DIR1/$tfile-2
1596 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1597         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1598         mv $DIR1/$tfile-2 $DIR1/$tfile &
1599         PID1=$!
1600         sleep 1
1601         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1602         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1603         rm -r $DIR1/*
1604         return 0
1605 }
1606 run_test 44g "pdirops: rename tgt vs getattr =============="
1607
1608 test_44h() {
1609         touch $DIR1/$tfile-2
1610 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1611         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1612         mv $DIR1/$tfile-2 $DIR1/$tfile &
1613         PID1=$!
1614         sleep 1
1615         ls -lia $DIR2/ > /dev/null
1616         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1617         rm -r $DIR1/*
1618         return 0
1619 }
1620 run_test 44h "pdirops: rename tgt vs readdir =============="
1621
1622 # test 45: rename src and blocking operations
1623 test_45a() {
1624         touch $DIR1/$tfile
1625 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1626         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1627         mv $DIR1/$tfile $DIR1/$tfile-2 &
1628         PID1=$!
1629         sleep 1
1630         mkdir $DIR2/$tfile || error "mkdir must succeed"
1631         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1632         rm -r $DIR1/*
1633         return 0
1634 }
1635 run_test 45a "pdirops: rename src vs mkdir =============="
1636
1637 test_45b() {
1638         touch $DIR1/$tfile
1639 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1640         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1641         mv $DIR1/$tfile $DIR1/$tfile-2 &
1642         PID1=$!
1643         sleep 1
1644         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1645         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1646         rm -r $DIR1/*
1647         return 0
1648 }
1649 run_test 45b "pdirops: rename src vs create =============="
1650
1651 test_45c() {
1652         touch $DIR1/$tfile
1653         touch $DIR1/$tfile-3
1654 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1655         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1656         mv $DIR1/$tfile $DIR1/$tfile-2 &
1657         PID1=$!
1658         sleep 1
1659         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
1660         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1661         rm -r $DIR1/*
1662         return 0
1663 }
1664 run_test 45c "pdirops: rename src vs link =============="
1665
1666 test_45d() {
1667         touch $DIR1/$tfile
1668 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1669         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1670         mv $DIR1/$tfile $DIR1/$tfile-2 &
1671         PID1=$!
1672         sleep 1
1673         rm $DIR2/$tfile && error "unlink must fail"
1674         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1675         rm -r $DIR1/*
1676         return 0
1677 }
1678 run_test 45d "pdirops: rename src vs unlink =============="
1679
1680 test_45e() {
1681         touch $DIR1/$tfile
1682         touch $DIR1/$tfile-3
1683 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1684         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1685         mv $DIR1/$tfile $DIR1/$tfile-2 &
1686         PID1=$!
1687         sleep 1
1688         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1689         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1690         rm -r $DIR1/*
1691         return 0
1692 }
1693 run_test 45e "pdirops: rename src and rename (tgt) =============="
1694
1695 test_45f() {
1696         touch $DIR1/$tfile
1697 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1698         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1699         mv $DIR1/$tfile $DIR1/$tfile-2 &
1700         PID1=$!
1701         sleep 1
1702         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
1703         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1704         rm -r $DIR1/*
1705         return 0
1706 }
1707 run_test 45f "pdirops: rename src and rename (src) =============="
1708
1709 test_45g() {
1710         touch $DIR1/$tfile
1711 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1712         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1713         mv $DIR1/$tfile $DIR1/$tfile-2 &
1714         PID1=$!
1715         sleep 1
1716         stat $DIR2/$tfile > /dev/null && "stat must fail"
1717         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1718         rm -r $DIR1/*
1719         return 0
1720 }
1721 run_test 45g "pdirops: rename src vs getattr =============="
1722
1723 test_45h() {
1724         touch $DIR1/$tfile
1725 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1726         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1727         mv $DIR1/$tfile $DIR1/$tfile-2 &
1728         PID1=$!
1729         sleep 1
1730         ls -lia $DIR2/ > /dev/null
1731         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1732         rm -r $DIR1/*
1733         return 0
1734 }
1735 run_test 45h "pdirops: unlink vs readdir =============="
1736
1737 # test 46: link and blocking operations
1738 test_46a() {
1739         touch $DIR1/$tfile-2
1740 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1741         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1742         link $DIR1/$tfile-2 $DIR1/$tfile &
1743         PID1=$!
1744         sleep 1
1745         mkdir $DIR2/$tfile && error "mkdir must fail"
1746         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1747         rm -r $DIR1/*
1748         return 0
1749 }
1750 run_test 46a "pdirops: link vs mkdir =============="
1751
1752 test_46b() {
1753         touch $DIR1/$tfile-2
1754 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1755         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1756         link $DIR1/$tfile-2 $DIR1/$tfile &
1757         PID1=$!
1758         sleep 1
1759         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1760         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1761         rm -r $DIR1/*
1762         return 0
1763 }
1764 run_test 46b "pdirops: link vs create =============="
1765
1766 test_46c() {
1767         touch $DIR1/$tfile-2
1768 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1769         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1770         link $DIR1/$tfile-2 $DIR1/$tfile &
1771         PID1=$!
1772         sleep 1
1773         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
1774         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1775         rm -r $DIR1/*
1776         return 0
1777 }
1778 run_test 46c "pdirops: link vs link =============="
1779
1780 test_46d() {
1781         touch $DIR1/$tfile-2
1782 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1783         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1784         link $DIR1/$tfile-2 $DIR1/$tfile &
1785         PID1=$!
1786         sleep 1
1787         rm $DIR2/$tfile || error "unlink must succeed"
1788         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1789         rm -r $DIR1/*
1790         return 0
1791 }
1792 run_test 46d "pdirops: link vs unlink =============="
1793
1794 test_46e() {
1795         touch $DIR1/$tfile-2
1796         touch $DIR1/$tfile-3
1797 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1798         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1799         link $DIR1/$tfile-2 $DIR1/$tfile &
1800         PID1=$!
1801         sleep 1
1802         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1803         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1804         rm -r $DIR1/*
1805         return 0
1806 }
1807 run_test 46e "pdirops: link and rename (tgt) =============="
1808
1809 test_46f() {
1810         touch $DIR1/$tfile-2
1811         touch $DIR1/$tfile-3
1812 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1813         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1814         link $DIR1/$tfile-2 $DIR1/$tfile &
1815         PID1=$!
1816         sleep 1
1817         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1818         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1819         rm -r $DIR1/*
1820         return 0
1821 }
1822 run_test 46f "pdirops: link and rename (src) =============="
1823
1824 test_46g() {
1825         touch $DIR1/$tfile-2
1826 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1827         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1828         link $DIR1/$tfile-2 $DIR1/$tfile &
1829         PID1=$!
1830         sleep 1
1831         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1832         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1833         rm -r $DIR1/*
1834         return 0
1835 }
1836 run_test 46g "pdirops: link vs getattr =============="
1837
1838 test_46h() {
1839         touch $DIR1/$tfile-2
1840 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1841         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1842         link $DIR1/$tfile-2 $DIR1/$tfile &
1843         PID1=$!
1844         sleep 1
1845         ls -lia $DIR2/ > /dev/null
1846         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1847         rm -r $DIR1/*
1848         return 0
1849 }
1850 run_test 46h "pdirops: link vs readdir =============="
1851
1852 test_50() {
1853         trunc_size=4096
1854         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
1855 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
1856         do_facet client "lctl set_param fail_loc=0x410"
1857         $TRUNCATE $DIR2/$tfile $trunc_size
1858         do_facet client "lctl set_param fail_loc=0x0"
1859         sleep 3
1860         size=`stat -c %s $DIR2/$tfile`
1861         [ $size -eq $trunc_size ] || error "wrong size"
1862 }
1863 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
1864
1865 log "cleanup: ======================================================"
1866
1867 [ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
1868 check_and_cleanup_lustre
1869
1870 echo '=========================== finished ==============================='
1871 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
1872 echo "$0: completed"