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