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