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