Whamcloud - gitweb
21f56fa66eec22c2516b22d48716c82b73e04b81
[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 LU-1205 15528/3811 16929 9977 15528/11549 18080
7 ALWAYS_EXCEPT="                14b  18c     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 # It will be ported soon.
15 EXCEPT="$EXCEPT 22"
16
17 SRCDIR=`dirname $0`
18 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
19
20 SIZE=${SIZE:-40960}
21 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
22 MCREATE=${MCREATE:-mcreate}
23 OPENFILE=${OPENFILE:-openfile}
24 OPENUNLINK=${OPENUNLINK:-openunlink}
25 export MULTIOP=${MULTIOP:-multiop}
26 export TMP=${TMP:-/tmp}
27 MOUNT_2=${MOUNT_2:-"yes"}
28 CHECK_GRANT=${CHECK_GRANT:-"yes"}
29 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
30
31 SAVE_PWD=$PWD
32
33 export NAME=${NAME:-local}
34
35 LUSTRE=${LUSTRE:-`dirname $0`/..}
36 . $LUSTRE/tests/test-framework.sh
37 CLEANUP=${CLEANUP:-:}
38 SETUP=${SETUP:-:}
39 init_test_env $@
40 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
41 init_logging
42
43 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
44 # bug number for skipped test:        LU-2840 LU-2189 LU-2776
45         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 21      36      51a"
46
47 [ "$SLOW" = "no" ] && EXCEPT_SLOW="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 $DIR/[df].${TESTSUITE}*
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_2f() {
138         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
139         local MDTIDX=1
140         local remote_dir=$tdir/remote_dir
141
142         mkdir -p $DIR1/$tdir
143         $LFS mkdir -i $MDTIDX $DIR1/$remote_dir ||
144                    error "Create remote directory failed"
145
146         touch $DIR1/$remote_dir/$tfile ||
147                 error "Create file under remote directory failed"
148         chmod 777 $DIR1/$remote_dir/$tfile ||
149                 error "Chmod file under remote directory failed"
150
151         $CHECKSTAT -t file -p 0777 $DIR2/$remote_dir/$tfile ||
152                 error "Check attr of file under remote directory failed"
153
154         chown $RUNAS_ID:$RUNAS_GID $DIR1/$remote_dir/$tfile ||
155                 error "Chown file under remote directory failed"
156
157         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR2/$remote_dir/$tfile ||
158                 error "Check owner of file under remote directory failed"
159
160         cd $DIR2/$remote_dir || error "enter remote dir"
161         rm -rf $DIR1/$remote_dir/$tfile ||
162                 error "Unlink remote directory failed"
163
164         $CHECKSTAT -t file $DIR2/$remote_dir/$tfile &&
165                 error "unlink file still exists!"
166
167         cd $DIR2/$tdir || error "exit remote dir"
168         rm -rf $DIR1/$tdir || error "unlink directory failed"
169 }
170 run_test 2f "check attr/owner updates on DNE with 2 mtpt's"
171
172 test_3() {
173         local target="this/is/good"
174         ln -s $target $DIR1/$tfile || error "ln -s $target $DIR1/$tfile failed"
175         [ "$(ls -l $DIR2/$tfile | sed -e 's/.* -> //')" = "$target" ] ||
176                 error "link $DIR2/$tfile not as expected"
177 }
178 run_test 3 "symlink on one mtpt, readlink on another ==========="
179
180 test_4() {
181         multifstat $DIR1/f4 $DIR2/f4
182 }
183 run_test 4 "fstat validation on multiple mount points =========="
184
185 test_5() {
186         mcreate $DIR1/f5
187         $TRUNCATE $DIR2/f5 100
188         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
189         rm $DIR1/f5
190 }
191 run_test 5 "create a file on one mount, truncate it on the other"
192
193 test_6() {
194         openunlink $DIR1/$tfile $DIR2/$tfile || \
195                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
196 }
197 run_test 6 "remove of open file on other node =================="
198
199 test_7() {
200         local dir=d7
201         opendirunlink $DIR1/$dir $DIR2/$dir || \
202                 error "opendirunlink $DIR1/$dir $DIR2/$dir"
203 }
204 run_test 7 "remove of open directory on other node ============="
205
206 test_8() {
207         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
208                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
209 }
210 run_test 8 "remove of open special file on other node =========="
211
212 test_9() {
213         MTPT=1
214         local dir
215         > $DIR2/f9
216         for C in a b c d e f g h i j k l; do
217                 dir=`eval echo \\$DIR$MTPT`
218                 echo -n $C >> $dir/f9
219                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
220         done
221         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
222                 error "`od -a $DIR1/f9` != abcdefghijkl"
223 }
224 run_test 9 "append of file with sub-page size on multiple mounts"
225
226 test_10a() {
227         MTPT=1
228         local dir
229         OFFSET=0
230         > $DIR2/f10
231         for C in a b c d e f g h i j k l; do
232                 dir=`eval echo \\$DIR$MTPT`
233                 echo -n $C | dd of=$dir/f10 bs=1 seek=$OFFSET count=1
234                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
235                 OFFSET=`expr $OFFSET + 1`
236         done
237         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
238                 error "`od -a $DIR1/f10` != abcdefghijkl"
239 }
240 run_test 10a "write of file with sub-page size on multiple mounts "
241
242 test_10b() {
243         # create a seed file
244         yes "R" | head -c 4000 >$TMP/f10b-seed
245         dd if=$TMP/f10b-seed of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
246
247         $TRUNCATE $DIR1/f10b 4096 || error "truncate 4096"
248
249         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
250
251         # create a test file locally to compare
252         dd if=$TMP/f10b-seed of=$TMP/f10b bs=3k count=1 || error "dd random"
253         $TRUNCATE $TMP/f10b 4096 || error "truncate 4096"
254         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
255         rm $TMP/f10b $TMP/f10b-lustre $TMP/f10b-seed
256 }
257 run_test 10b "write of file with sub-page size on multiple mounts "
258
259 test_11() {
260         test_mkdir $DIR1/d11
261         multiop_bg_pause $DIR1/d11/f O_c || return 1
262         MULTIPID=$!
263         cp -p /bin/ls $DIR1/d11/f
264         $DIR2/d11/f
265         RC=$?
266         kill -USR1 $MULTIPID
267         wait $MULTIPID || error
268         [ $RC -eq 0 ] && error || true
269 }
270 run_test 11 "execution of file opened for write should return error ===="
271
272 test_12() {
273        DIR=$DIR DIR2=$DIR2 sh lockorder.sh
274 }
275 run_test 12 "test lock ordering (link, stat, unlink) ==========="
276
277 test_13() {     # bug 2451 - directory coherency
278         test_mkdir $DIR1/d13 || error
279        cd $DIR1/d13 || error
280        ls
281        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
282        ls
283        rm -f $DIR2/d13/f13 || error
284        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
285        # need to run it twice
286        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
287        ls
288        rm -f $DIR2/d13/f13 || error
289        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
290 }
291 run_test 13 "test directory page revocation ===================="
292
293 test_14() {
294         test_mkdir -p $DIR1/$tdir
295         cp -p /bin/ls $DIR1/$tdir/$tfile
296         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
297         MULTIPID=$!
298
299         $DIR2/$tdir/$tfile && error || true
300         kill -USR1 $MULTIPID
301         wait $MULTIPID || return 2
302 }
303 run_test 14 "execution of file open for write returns -ETXTBSY ="
304
305 test_14a() {
306         test_mkdir -p $DIR1/d14
307         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
308         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
309         MULTIOP_PID=$!
310         $MULTIOP $DIR2/d14/multiop Oc && error "expected error, got success"
311         kill -USR1 $MULTIOP_PID || return 2
312         wait $MULTIOP_PID || return 3
313         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
314 }
315 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
316
317 test_14b() { # bug 3192, 7040
318         test_mkdir -p $DIR1/d14
319         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
320         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
321         MULTIOP_PID=$!
322         $TRUNCATE $DIR2/d14/multiop 0 && kill -9 $MULTIOP_PID && \
323                 error "expected truncate error, got success"
324         kill -USR1 $MULTIOP_PID || return 2
325         wait $MULTIOP_PID || return 3
326         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
327         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
328 }
329 run_test 14b "truncate of executing file returns -ETXTBSY ======"
330
331 test_14c() { # bug 3430, 7040
332         test_mkdir -p $DIR1/d14
333         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
334         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
335         MULTIOP_PID=$!
336         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
337         kill -USR1 $MULTIOP_PID || return 2
338         wait $MULTIOP_PID || return 3
339         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
340         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
341 }
342 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
343
344 test_14d() { # bug 10921
345         test_mkdir -p $DIR1/d14
346         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
347         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
348         MULTIOP_PID=$!
349         log chmod
350         chmod 600 $DIR1/d14/multiop || error "chmod failed"
351         kill -USR1 $MULTIOP_PID || return 2
352         wait $MULTIOP_PID || return 3
353         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
354         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
355 }
356 run_test 14d "chmod of executing file is still possible ========"
357
358 test_15() {     # bug 974 - ENOSPC
359         echo "PATH=$PATH"
360         sh oos2.sh $MOUNT1 $MOUNT2
361         wait_delete_completed
362         grant_error=`dmesg | grep "> available"`
363         [ -z "$grant_error" ] || error "$grant_error"
364 }
365 run_test 15 "test out-of-space with multiple writers ==========="
366
367 COUNT=${COUNT:-2500}
368 # The FSXNUM reduction for ZFS is needed until ORI-487 is fixed.
369 # We don't want to skip it entirely, but ZFS is VERY slow and cannot
370 # pass a 2500 operation dual-mount run within the time limit.
371 if [ "$(facet_fstype ost1)" = "zfs" ]; then
372         FSXNUM=$((COUNT / 5))
373         FSXP=1
374 elif [ "$SLOW" = "yes" ]; then
375         FSXNUM=$((COUNT * 5))
376         FSXP=500
377 else
378         FSXNUM=$COUNT
379         FSXP=100
380 fi
381
382 test_16() {
383         local file1=$DIR1/$tfile
384         local file2=$DIR2/$tfile
385
386         # to allocate grant because it may run out due to test_15.
387         lfs setstripe -c -1 $file1
388         dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
389         dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
390         rm -f $file1
391
392         lfs setstripe -c -1 $file1 # b=10919
393         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2
394 }
395 run_test 16 "$FSXNUM iterations of dual-mount fsx"
396
397 test_17() { # bug 3513, 3667
398         remote_ost_nodsh && skip "remote OST with nodsh" && return
399
400         lfs setstripe $DIR1/$tfile -i 0 -c 1
401         cp $SAMPLE_FILE $DIR1/$tfile
402         cancel_lru_locks osc > /dev/null
403         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
404         do_facet ost1 lctl set_param fail_loc=0x8000030a
405         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
406         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
407         wait
408         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
409 }
410 run_test 17 "resource creation/LVB creation race ==============="
411
412 test_18() {
413         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
414         local idx
415         local excepts=
416         for idx in {a..z}; do
417                 local ptr=EXCEPT_ALWAYS_18$idx
418                 [ x${!ptr} = xtrue ] || continue
419
420                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
421         done
422
423         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
424         sync; sleep 1; sync
425 }
426 run_test 18 "mmap sanity check ================================="
427
428 test_19() { # bug3811
429         local node=$(facet_active_host ost1)
430
431         # check whether obdfilter is cache capable at all
432         if ! get_osd_param $node '' read_cache_enable >/dev/null; then
433                 echo "not cache-capable obdfilter"
434                 return 0
435         fi
436
437         local MAX=$(get_osd_param $node '' readcache_max_filesize | \
438                     head -n 1)
439         set_osd_param $node '' readcache_max_filesize 4096
440         dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
441         local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
442         cp $TMP/$tfile $DIR1/$tfile
443         for i in `seq 1 20`; do
444                 [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
445                 cancel_lru_locks osc > /dev/null
446                 cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
447                 cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
448                 wait
449                 [ "$(cat $TMP/sum1)" = "$SUM" ] || \
450                         error "$DIR1/$tfile $(cat $TMP/sum1) != $SUM"
451                 [ "$(cat $TMP/sum2)" = "$SUM" ] || \
452                         error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
453         done
454         set_osd_param $node '' readcache_max_filesize $MAX
455         rm $DIR1/$tfile
456 }
457 run_test 19 "test concurrent uncached read races ==============="
458
459 test_20() {
460         test_mkdir $DIR1/d20
461         cancel_lru_locks osc
462         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
463         $MULTIOP $DIR1/f20 Ow8190c
464         $MULTIOP $DIR2/f20 Oz8194w8190c
465         $MULTIOP $DIR1/f20 Oz0r8190c
466         cancel_lru_locks osc
467         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
468         [ $CNTD -gt 0 ] && \
469             error $CNTD" page left in cache after lock cancel" || true
470 }
471 run_test 20 "test extra readahead page left in cache ===="
472
473 cleanup_21() {
474         trap 0
475         umount $DIR1/$tdir
476 }
477
478 test_21() { # Bug 5907
479         test_mkdir $DIR1/$tdir
480         mount /etc $DIR1/$tdir --bind || error "mount failed" # Poor man's mount.
481         trap cleanup_21 EXIT
482         rmdir -v $DIR1/$tdir && error "Removed mounted directory"
483         rmdir -v $DIR2/$tdir && echo "Removed mounted directory from another mountpoint, needs to be fixed"
484         test -d $DIR1/$tdir || error "Mounted directory disappeared"
485         cleanup_21
486         test -d $DIR2/$tdir || test -d $DIR1/$tdir && error "Removed dir still visible after umount"
487         true
488 }
489 run_test 21 " Try to remove mountpoint on another dir ===="
490
491 test_23() { # Bug 5972
492         local at_diff=$(do_facet $SINGLEMDS $LCTL get_param -n mdd.*.atime_diff)
493         echo "atime should be updated while another read" > $DIR1/$tfile
494
495         # clear the lock(mode: LCK_PW) gotten from creating operation
496         cancel_lru_locks osc
497         time1=$(date +%s)
498         echo "now is $time1"
499         sleep $((at_diff + 1))
500
501         echo "starting reads"
502         multiop_bg_pause $DIR1/$tfile or20_c || return 1
503         # with SOM and opencache enabled, we need to close a file and cancel
504         # open lock to get atime propogated to MDS
505         kill -USR1 $! || return 2
506         cancel_lru_locks mdc
507
508         time2=$(stat -c "%X" $DIR/$tfile)
509         echo "new atime is $time2"
510
511         [ $time2 -gt $time1 ] || error "atime was not updated"
512         rm -f $DIR1/$tfile || error "rm -f $DIR1/$tfile failed"
513         true
514 }
515 run_test 23 " others should see updated atime while another read===="
516
517 test_24a() {
518         touch $DIR1/$tfile
519         lfs df || error "lfs df failed"
520         lfs df -ih || error "lfs df -ih failed"
521         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
522         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
523         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
524         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
525
526         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
527 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
528         lctl --device %$OSC deactivate
529         lfs df -i || error "lfs df -i with deactivated OSC failed"
530         lctl --device %$OSC activate
531         lfs df || error "lfs df with reactivated OSC failed"
532 }
533 run_test 24a "lfs df [-ih] [path] test ========================="
534
535 test_24b() {
536         touch $DIR1/$tfile
537         fsnum=$(lfs_df | grep -c "summary")
538         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
539 }
540 run_test 24b "lfs df should show both filesystems ==============="
541
542 test_25a() {
543         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
544                                                                 grep -c acl)
545         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
546
547         mkdir -p $DIR1/$tdir
548         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
549         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
550
551         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
552         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
553                 error "setfacl $DIR2/$tdir #1"
554         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
555         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
556                 error "setfacl $DIR2/$tdir #2"
557         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
558         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
559                 error "setfacl $DIR2/$tdir #3"
560         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
561         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
562                 error "setfacl $DIR2/$tdir #4"
563         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
564
565         rm -rf $DIR1/$tdir
566 }
567 run_test 25a "change ACL on one mountpoint be seen on another ==="
568
569 test_25b() {
570         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
571                                                         grep -c acl)
572         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
573
574         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
575
576         rm -rf $DIR1/$tdir
577         $LFS mkdir -i 1 $DIR1/$tdir
578         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
579         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
580
581         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
582         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
583                 error "setfacl $DIR2/$tdir #1"
584         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
585         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
586                 error "setfacl $DIR2/$tdir #2"
587         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
588         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
589                 error "setfacl $DIR2/$tdir #3"
590         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
591         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
592                 error "setfacl $DIR2/$tdir #4"
593         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
594
595         rm -rf $DIR1/$tdir
596 }
597 run_test 25b "change ACL under remote dir on one mountpoint be seen on another"
598
599 test_26a() {
600         utime $DIR1/f26a -s $DIR2/f26a || error
601 }
602 run_test 26a "allow mtime to get older"
603
604 test_26b() {
605         touch $DIR1/$tfile
606         sleep 1
607         echo "aaa" >> $DIR1/$tfile
608         sleep 1
609         chmod a+x $DIR2/$tfile
610         mt1=`stat -c %Y $DIR1/$tfile`
611         mt2=`stat -c %Y $DIR2/$tfile`
612
613         if [ x"$mt1" != x"$mt2" ]; then
614                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
615         fi
616 }
617 run_test 26b "sync mtime between ost and mds"
618
619 test_27() {
620         cancel_lru_locks osc
621         lctl clear
622         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
623         DD2_PID=$!
624         usleep 50
625         log "dd 1 started"
626         
627         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
628         DD1_PID=$!
629         log "dd 2 started"
630         
631         sleep 1
632         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
633         log "dd 3 finished"
634         lctl set_param -n ldlm.dump_namespaces ""
635         wait $DD1_PID $DD2_PID
636         [ $? -ne 0 ] && lctl dk $TMP/debug || true
637 }
638 run_test 27 "align non-overlapping extent locks from request ==="
639
640 test_28() { # bug 9977
641         ECHO_UUID="ECHO_osc1_UUID"
642         tOST=`$LCTL dl | | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -1`
643
644         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
645         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
646         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
647
648         $LCTL <<-EOF
649                 newdev
650                 attach echo_client ECHO_osc1 $ECHO_UUID
651                 setup $tOST
652         EOF
653
654         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
655         $LCTL --device $tECHOID destroy "${tOBJID}:0"
656
657         $LCTL <<-EOF
658                 cfg_device ECHO_osc1
659                 cleanup
660                 detach
661         EOF
662
663         # reading of 1st stripe should pass
664         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
665         # reading of 2nd stripe should fail (this stripe was destroyed)
666         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
667
668         # now, recreating test file
669         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
670         # reading of 1st stripe should pass
671         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
672         # reading of 2nd stripe should pass
673         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
674 }
675 run_test 28 "read/write/truncate file with lost stripes"
676
677 test_29() { # bug 10999
678         touch $DIR1/$tfile
679         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
680         lctl set_param fail_loc=0x8000030f
681         ls -l $DIR2/$tfile &
682         usleep 500
683         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
684         wait
685 }
686 #bug 11549 - permanently turn test off in b1_5
687 run_test 29 "lock put race between glimpse and enqueue ========="
688
689 test_30() { #bug #11110, LU-2523
690         test_mkdir -p $DIR1/$tdir
691         cp -f /bin/bash $DIR1/$tdir/bash
692         /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash;
693                     cp /bin/bash $DIR2/$tdir' &
694         $DIR1/$tdir/bash -c 'sleep 2;
695                 openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
696         wait
697         true
698 }
699
700 run_test 30 "recreate file race"
701
702 test_31a() {
703         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
704         local writes=$(LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile \
705                        count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}')
706         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
707         lctl set_param fail_loc=0x314
708         local reads=$(LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
709                       awk 'BEGIN { FS="+" } /in/ {print $1}')
710         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
711 }
712 run_test 31a "voluntary cancel / blocking ast race=============="
713
714 test_31b() {
715         remote_ost || { skip "local OST" && return 0; }
716         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
717
718         # make sure there is no local locks due to destroy
719         wait_mds_ost_sync || error "wait_mds_ost_sync()"
720         wait_delete_completed || error "wait_delete_completed()"
721
722         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
723         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
724         cp /etc/hosts $DIR/$tdir/$tfile
725         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
726         lctl set_param fail_loc=0x314
727         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
728         do_facet ost1 lctl set_param fail_loc=0x316
729         # Don't crash kernel
730         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
731         lctl set_param fail_loc=0
732         do_facet ost1 lctl set_param fail_loc=0
733         # cleanup: reconnect the client back
734         df $DIR2
735 }
736 run_test 31b "voluntary OST cancel / blocking ast race=============="
737
738 # enable/disable lockless truncate feature, depending on the arg 0/1
739 enable_lockless_truncate() {
740         lctl set_param -n osc.*.lockless_truncate $1
741 }
742
743 test_32a() { # bug 11270
744         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
745         save_lustre_params client "osc.*.lockless_truncate" > $p
746         cancel_lru_locks osc
747         enable_lockless_truncate 1
748         rm -f $DIR1/$tfile
749         lfs setstripe -c -1 $DIR1/$tfile
750         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$STRIPE_BYTES > \
751                 /dev/null 2>&1
752         clear_osc_stats
753
754         log "checking cached lockless truncate"
755         $TRUNCATE $DIR1/$tfile 8000000
756         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
757         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
758                 error "lockless truncate doesn't use cached locks"
759
760         log "checking not cached lockless truncate"
761         $TRUNCATE $DIR2/$tfile 5000000
762         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
763         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
764                 error "not cached trancate isn't lockless"
765
766         log "disabled lockless truncate"
767         enable_lockless_truncate 0
768         clear_osc_stats
769         $TRUNCATE $DIR2/$tfile 3000000
770         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
771         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
772                 error "lockless truncate disabling failed"
773         rm $DIR1/$tfile
774         # restore lockless_truncate default values
775         restore_lustre_params < $p
776         rm -f $p
777 }
778 run_test 32a "lockless truncate"
779
780 test_32b() { # bug 11270
781         remote_ost_nodsh && skip "remote OST with nodsh" && return
782
783         local node
784         local facets=$(get_facets OST)
785         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
786
787         save_lustre_params client "osc.*.contention_seconds" > $p
788         save_lustre_params $facets \
789                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
790         save_lustre_params $facets \
791                 "ldlm.namespaces.filter-*.contended_locks" >> $p
792         save_lustre_params $facets \
793                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
794         clear_osc_stats
795
796         # agressive lockless i/o settings
797         for node in $(osts_nodes); do
798                 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'
799         done
800         lctl set_param -n osc.*.contention_seconds 60
801         for i in $(seq 5); do
802                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
803                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
804         done
805         [ $(calc_osc_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
806         # disable lockless i/o (it is disabled by default)
807         for node in $(osts_nodes); do
808                 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'
809         done
810         # set contention_seconds to 0 at client too, otherwise Lustre still
811         # remembers lock contention
812         lctl set_param -n osc.*.contention_seconds 0
813         clear_osc_stats
814         for i in $(seq 1); do
815                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
816                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
817         done
818         [ $(calc_osc_stats lockless_write_bytes) -eq 0 ] ||
819                 error "lockless i/o works when disabled"
820         rm -f $DIR1/$tfile
821         restore_lustre_params <$p
822         rm -f $p
823 }
824 run_test 32b "lockless i/o"
825
826 print_jbd_stat () {
827     local dev
828     local mdts=$(get_facets MDS)
829     local varcvs
830     local mds
831
832     local stat=0
833     for mds in ${mdts//,/ }; do
834         varsvc=${mds}_svc
835         dev=$(basename $(do_facet $mds "lctl get_param -n osd*.${!varsvc}.mntdev|\
836                 xargs readlink -f" ))
837         val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info 2>/dev/null|\
838                 head -1")
839         val=${val%% *};
840         stat=$(( stat + val))
841     done
842     echo $stat
843 }
844
845 # commit on sharing tests
846 test_33a() {
847     remote_mds_nodsh && skip "remote MDS with nodsh" && return
848
849     [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS" && return 0
850     [ $CLIENTCOUNT -lt 2 ] &&
851         skip "Need two or more clients, have $CLIENTCOUNT" && return 0
852
853     local nfiles=${TEST33_NFILES:-10000}
854     local param_file=$TMP/$tfile-params
855     local fstype=$(facet_fstype $SINGLEMDS)
856
857         save_lustre_params $(get_facets MDS) \
858                 "mdt.*.commit_on_sharing" > $param_file
859
860     local COS
861     local jbdold="N/A"
862     local jbdnew="N/A"
863     local jbd
864
865     for COS in 0 1; do
866         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
867         avgjbd=0
868         avgtime=0
869         for i in 1 2 3; do
870             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
871
872             [ $fstype = ldiskfs ] && jbdold=$(print_jbd_stat)
873             echo "=== START createmany old: $jbdold transaction"
874             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")
875             [ $fstype = ldiskfs ] && jbdnew=$(print_jbd_stat)
876             [ $fstype = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
877             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
878             [ $fstype = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
879             avgtime=$(( avgtime + elapsed ))
880         done
881         eval cos${COS}_jbd=$((avgjbd / 3))
882         eval cos${COS}_time=$((avgtime / 3))
883     done
884
885     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
886     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
887     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
888     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
889
890     restore_lustre_params < $param_file
891     rm -f $param_file
892     return 0
893 }
894 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
895
896 # commit on sharing tests
897 test_33b() {
898         remote_mds_nodsh && skip "remote MDS with nodsh" && return
899
900         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
901         [ $CLIENTCOUNT -ge 2 ] ||
902                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
903                                                                 return 0; }
904         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
905
906         local nfiles=${TEST33_NFILES:-10000}
907         local param_file=$TMP/$tfile-params
908
909         save_lustre_params $(get_facets MDS) \
910                 "mdt.*.commit_on_sharing" > $param_file
911
912         local COS
913         local jbdold
914         local jbdnew
915         local jbd
916         local MDTIDX=1
917
918         for COS in 0 1; do
919                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
920                 avgjbd=0
921                 avgtime=0
922                 for i in 1 2 3; do
923                         do_node $CLIENT1 "$LFS mkdir -i $MDTIDX -p \
924                                           $DIR1/$tdir-\\\$(hostname)-$i"
925
926                         jbdold=$(print_jbd_stat)
927                         echo "=== START createmany old: $jbdold transaction"
928                         local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2\
929                                 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- \
930                                 -r $DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > \
931                                                                 /dev/null 2>&1")
932                         jbdnew=$(print_jbd_stat)
933                         jbd=$(( jbdnew - jbdold ))
934                         echo "=== END   createmany new: $jbdnew transaction : \
935                         $jbd transactions nfiles $nfiles time $elapsed COS=$COS"
936                         avgjbd=$(( avgjbd + jbd ))
937                         avgtime=$(( avgtime + elapsed ))
938                 done
939                 eval cos${COS}_jbd=$((avgjbd / 3))
940                 eval cos${COS}_time=$((avgtime / 3))
941         done
942
943         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
944         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
945         [ "$cos0_jbd" != 0 ] &&
946             echo "COS=1 vs COS=0 jbd: $(((cos1_jbd/cos0_jbd - 1) * 100)) %"
947         [ "$cos0_time" != 0 ] &&
948             echo "COS=1 vs COS=0 time: $(((cos1_time/cos0_time - 1) * 100)) %"
949
950         restore_lustre_params < $param_file
951         rm -f $param_file
952         return 0
953 }
954 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
955
956 # End commit on sharing tests
957
958 get_ost_lock_timeouts() {
959     local nodes=${1:-$(comma_list $(osts_nodes))}
960
961     local locks=$(do_nodes $nodes \
962         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
963
964     echo $locks
965 }
966
967 cleanup_34() {
968         local i
969         trap 0
970         do_nodes $(comma_list $(osts_nodes)) \
971                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
972         for i in $(seq $OSTCOUNT); do
973                 wait_osc_import_state client ost$i FULL
974         done
975 }
976
977 test_34() { #16129
978         local OPER
979         local lock_in
980         local lock_out
981         trap cleanup_34 EXIT RETURN
982         for OPER in notimeout timeout ; do
983                 rm $DIR1/$tfile 2>/dev/null
984                 lock_in=$(get_ost_lock_timeouts)
985                 if [ $OPER == "timeout" ] ; then
986                         for j in `seq $OSTCOUNT`; do
987                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
988                                 do_facet ost$j lctl set_param fail_loc=0x511
989                         done
990                         echo lock should expire
991                 else
992                         for j in `seq $OSTCOUNT`; do
993                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
994                                 do_facet ost$j lctl set_param fail_loc=0x512
995                         done
996                         echo lock should not expire
997                 fi
998                 echo writing on client1
999                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
1000                 sync &
1001                 echo reading on client2
1002                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
1003                 # wait for a lock timeout
1004                 sleep 4
1005                 lock_out=$(get_ost_lock_timeouts)
1006                 if [ $OPER == "timeout" ] ; then
1007                         if [ $lock_in == $lock_out ]; then
1008                                 error "no lock timeout happened"
1009                         else
1010                                 echo "success"
1011                         fi
1012                 else
1013                         if [ $lock_in != $lock_out ]; then
1014                                 error "lock timeout happened"
1015                         else
1016                                 echo "success"
1017                         fi
1018                 fi
1019         done
1020         cleanup_34
1021 }
1022 run_test 34 "no lock timeout under IO"
1023
1024 test_35() { # bug 17645
1025         local generation=[]
1026         local count=0
1027         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
1028             g=$(awk '/generation/{print $2}' $imp/import)
1029             generation[count]=$g
1030             let count=count+1
1031         done
1032
1033         test_mkdir -p $MOUNT1/$tfile
1034         cancel_lru_locks mdc
1035
1036         # Let's initiate -EINTR situation by setting fail_loc and take
1037         # write lock on same file from same client. This will not cause
1038         # bl_ast yet as lock is already in local cache.
1039 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
1040         do_facet client "lctl set_param fail_loc=0x80000317"
1041         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
1042         let timeout=timeout*3
1043         local nr=0
1044         while test $nr -lt 10; do
1045                 log "Race attempt $nr"
1046                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1047                 test "x$blk1" = "x" && blk1=0
1048                 createmany -o $MOUNT2/$tfile/a 4000 &
1049                 pid1=$!
1050                 sleep 1
1051
1052                 # Let's make conflict and bl_ast
1053                 ls -la $MOUNT1/$tfile > /dev/null &
1054                 pid2=$!
1055
1056                 log "Wait for $pid1 $pid2 for $timeout sec..."
1057                 sleep $timeout
1058                 kill -9 $pid1 $pid2 > /dev/null 2>&1
1059                 wait
1060                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1061                 test "x$blk2" = "x" && blk2=0
1062                 test $blk2 -gt $blk1 && break
1063                 rm -fr $MOUNT1/$tfile/*
1064                 cancel_lru_locks mdc
1065                 let nr=nr+1
1066         done
1067         do_facet client "lctl set_param fail_loc=0x0"
1068         df -h $MOUNT1 $MOUNT2
1069         count=0
1070         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
1071             g=$(awk '/generation/{print $2}' $imp/import)
1072             if ! test "$g" -eq "${generation[count]}"; then
1073                 error "Eviction happened on import $(basename $imp)"
1074             fi
1075             let count=count+1
1076         done
1077 }
1078 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
1079
1080 test_36() { #bug 16417
1081         local SIZE
1082         local SIZE_B
1083         local i
1084
1085         test_mkdir -p $DIR1/$tdir
1086         $LFS setstripe -c -1 $DIR1/$tdir
1087         i=0
1088         SIZE=50
1089         let SIZE_B=SIZE*1024*1024
1090         sync; sleep 5; sync # wait for delete thread
1091
1092         while [ $i -le 10 ]; do
1093                 lctl mark "start test"
1094                 local before=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1095                 dd if=/dev/zero of=$DIR1/$tdir/$tfile bs=1M count=$SIZE ||
1096                         error "dd $DIR1/$tdir/$tfile ${SIZE}MB failed"
1097                 sync          # sync data from client cache
1098                 sync_all_data # sync data from server cache (delayed allocation)
1099                 sleep 2
1100                 local after_dd=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1101                 multiop_bg_pause $DIR2/$tdir/$tfile O_r${SIZE_B}c || return 3
1102                 read_pid=$!
1103                 rm -f $DIR1/$tdir/$tfile
1104                 kill -USR1 $read_pid
1105                 wait $read_pid
1106                 wait_delete_completed
1107                 local after=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1108                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
1109                         "after($after)"
1110                 # this free space! not used
1111                 (( $after_dd <= $after)) ||
1112                         error "space leaked after_dd:$after_dd > after:$after"
1113                 let i=i+1
1114         done
1115 }
1116 run_test 36 "handle ESTALE/open-unlink correctly"
1117
1118 test_37() { # bug 18695
1119         test_mkdir -p $DIR1/$tdir
1120         multiop_bg_pause $DIR1/$tdir D_c || return 1
1121         MULTIPID=$!
1122         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
1123         createmany -m $DIR2/$tdir/f 10000
1124         # set mtime/atime backward
1125         touch -t 198001010000 $DIR2/$tdir
1126         kill -USR1 $MULTIPID
1127         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
1128         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
1129
1130 }
1131 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
1132
1133 # this should be set to past
1134 TEST_39_MTIME=`date -d "1 year ago" +%s`
1135
1136 # bug 11063
1137 test_39a() {
1138         local client1=${CLIENT1:-`hostname`}
1139         local client2=${CLIENT2:-`hostname`}
1140
1141         do_node $client1 "touch $DIR1/$tfile"
1142
1143         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
1144         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1145         [ "$mtime1" = $TEST_39_MTIME ] || \
1146                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
1147
1148         local d1=`do_node $client1 date +%s`
1149         do_node $client1 'echo hello >> '$DIR1/$tfile
1150         local d2=`do_node $client1 date +%s`
1151
1152         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1153         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
1154                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1155
1156         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
1157
1158         for (( i=0; i < 2; i++ )) ; do
1159                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
1160                 [ "$mtime2" = "$mtime3" ] || \
1161                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1162
1163                 cancel_lru_locks osc
1164                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1165         done
1166 }
1167 run_test 39a "test from 11063 =================================="
1168
1169 test_39b() {
1170         local client1=${CLIENT1:-`hostname`}
1171         local client2=${CLIENT2:-`hostname`}
1172
1173         touch $DIR1/$tfile
1174
1175         local mtime1=`stat -c %Y $DIR1/$tfile`
1176         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1177
1178         sleep 1
1179         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1180
1181         for (( i=0; i < 2; i++ )) ; do
1182                 local mtime3=`stat -c %Y $DIR1/$tfile`
1183                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1184
1185                 [ "$mtime3" = "$mtime4" ] || \
1186                         error "different mtime on clients: $mtime3, $mtime4"
1187                 [ "$mtime3" = $TEST_39_MTIME ] || \
1188                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1189
1190                 cancel_lru_locks osc
1191                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1192         done
1193 }
1194 run_test 39b "11063 problem 1 =================================="
1195
1196 test_39c() {
1197         local client1=${CLIENT1:-`hostname`}
1198         local client2=${CLIENT2:-`hostname`}
1199
1200         echo hello > $DIR1/$tfile
1201
1202         local mtime1=`stat -c %Y $DIR1/$tfile`
1203         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1204         [ "$mtime1" = "$mtime2" ] || \
1205                 error "create: different mtime on clients: $mtime1, $mtime2"
1206
1207         sleep 1
1208         $TRUNCATE $DIR1/$tfile 1
1209
1210         for (( i=0; i < 2; i++ )) ; do
1211                 local mtime3=`stat -c %Y $DIR1/$tfile`
1212                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1213
1214                 [ "$mtime3" = "$mtime4" ] || \
1215                         error "different mtime on clients: $mtime3, $mtime4"
1216                 [ "$mtime3" -gt $mtime2 ] || \
1217                         error "truncate did not update mtime: $mtime2, $mtime3"
1218
1219                 cancel_lru_locks osc
1220                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1221         done
1222 }
1223 run_test 39c "check truncate mtime update ======================"
1224
1225 # check that pid exists hence second operation wasn't blocked by first one
1226 # if it is so then there is no conflict, return 0
1227 # else second operation is conflicting with first one, return 1
1228 check_pdo_conflict() {
1229         local pid=$1
1230         local conflict=0
1231         sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
1232         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1233                 conflict=1
1234                 echo "Conflict"
1235         else
1236                 echo "No conflict"
1237         fi
1238         return $conflict
1239 }
1240
1241 # pdirop tests
1242 # test 40: check non-blocking operations
1243 test_40a() {
1244 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1245         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1246         mkdir $DIR1/$tfile &
1247         PID1=$!
1248         sleep 1
1249         touch $DIR2/$tfile-2
1250         check_pdo_conflict $PID1 || error "create is blocked"
1251         mkdir $DIR2/$tfile-3
1252         check_pdo_conflict $PID1 || error "mkdir is blocked"
1253         link $DIR2/$tfile-2 $DIR2/$tfile-4
1254         check_pdo_conflict $PID1 || error "link is blocked"
1255         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1256         check_pdo_conflict $PID1 || error "rename is blocked"
1257         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1258         check_pdo_conflict $PID1 || error "getattr is blocked"
1259         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1260         rmdir $DIR2/$tfile-3
1261         check_pdo_conflict $PID1 || error "unlink is blocked"
1262
1263         if [ $MDSCOUNT -ge 2 ]; then
1264                 $LFS mkdir -i 1 $DIR2/$tfile-6
1265                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1266         fi
1267
1268         # all operations above shouldn't wait the first one
1269         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1270         wait $PID1
1271         rm -r $DIR1/*
1272         return 0
1273 }
1274 run_test 40a "pdirops: create vs others =============="
1275
1276 test_40b() {
1277 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1278         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1279         touch $DIR1/$tfile &
1280         PID1=$!
1281         sleep 1
1282         # open|create
1283         touch $DIR2/$tfile-2
1284         check_pdo_conflict $PID1 || error "create is blocked"
1285         mkdir $DIR2/$tfile-3
1286         check_pdo_conflict $PID1 || error "mkdir is blocked"
1287         link $DIR2/$tfile-2 $DIR2/$tfile-4
1288         check_pdo_conflict $PID1 || error "link is blocked"
1289         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1290         check_pdo_conflict $PID1 || error "rename is blocked"
1291         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1292         check_pdo_conflict $PID1 || error "getattr is blocked"
1293         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1294         rmdir $DIR2/$tfile-3
1295         check_pdo_conflict $PID1 || error "unlink is blocked"
1296         # all operations above shouldn't wait the first one
1297
1298         if [ $MDSCOUNT -ge 2 ]; then
1299                 $LFS mkdir -i 1 $DIR2/$tfile-6
1300                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1301         fi
1302
1303         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1304         wait $PID1
1305         rm -r $DIR1/*
1306         return 0
1307 }
1308 run_test 40b "pdirops: open|create and others =============="
1309
1310 test_40c() {
1311         touch $DIR1/$tfile
1312 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1313         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1314         link $DIR1/$tfile $DIR1/$tfile-0 &
1315         PID1=$!
1316         sleep 1
1317         # open|create
1318         touch $DIR2/$tfile-2
1319         check_pdo_conflict $PID1 || error "create is blocked"
1320         mkdir $DIR2/$tfile-3
1321         check_pdo_conflict $PID1 || error "mkdir is blocked"
1322         link $DIR2/$tfile-2 $DIR2/$tfile-4
1323         check_pdo_conflict $PID1 || error "link is blocked"
1324         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1325         check_pdo_conflict $PID1 || error "rename is blocked"
1326         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1327         check_pdo_conflict $PID1 || error "getattr is blocked"
1328         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1329         rmdir $DIR2/$tfile-3
1330         check_pdo_conflict $PID1 || error "unlink is blocked"
1331
1332         if [ $MDSCOUNT -ge 2 ]; then
1333                 $LFS mkdir -i 1 $DIR2/$tfile-6
1334                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1335         fi
1336
1337         # all operations above shouldn't wait the first one
1338         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1339         wait $PID1
1340         rm -r $DIR1/*
1341         return 0
1342 }
1343 run_test 40c "pdirops: link and others =============="
1344
1345 test_40d() {
1346         touch $DIR1/$tfile
1347 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1348         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1349         rm $DIR1/$tfile &
1350         PID1=$!
1351         sleep 1
1352         # open|create
1353         touch $DIR2/$tfile-2
1354         check_pdo_conflict $PID1 || error "create is blocked"
1355         mkdir $DIR2/$tfile-3
1356         check_pdo_conflict $PID1 || error "mkdir is blocked"
1357         link $DIR2/$tfile-2 $DIR2/$tfile-4
1358         check_pdo_conflict $PID1 || error "link is blocked"
1359         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1360         check_pdo_conflict $PID1 || error "rename is blocked"
1361         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1362         check_pdo_conflict $PID1 || error "getattr is blocked"
1363         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1364         rmdir $DIR2/$tfile-3
1365         check_pdo_conflict $PID1 || error "unlink is blocked"
1366
1367         if [ $MDSCOUNT -ge 2 ]; then
1368                 $LFS mkdir -i 1 $DIR2/$tfile-6
1369                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1370         fi
1371
1372         # all operations above shouldn't wait the first one
1373         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1374         wait $PID1
1375         return 0
1376 }
1377 run_test 40d "pdirops: unlink and others =============="
1378
1379 test_40e() {
1380         touch $DIR1/$tfile
1381 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1382         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1383         mv $DIR1/$tfile $DIR1/$tfile-0 &
1384         PID1=$!
1385         sleep 1
1386         # open|create
1387         touch $DIR2/$tfile-2
1388         check_pdo_conflict $PID1 || error "create is blocked"
1389         mkdir $DIR2/$tfile-3
1390         check_pdo_conflict $PID1 || error "mkdir is blocked"
1391         link $DIR2/$tfile-2 $DIR2/$tfile-4
1392         check_pdo_conflict $PID1 || error "link is blocked"
1393         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1394         check_pdo_conflict $PID1 || error "getattr is blocked"
1395         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1396         rmdir $DIR2/$tfile-3
1397         check_pdo_conflict $PID1 || error "unlink is blocked"
1398
1399         if [ $MDSCOUNT -ge 2 ]; then
1400                 $LFS mkdir -i 1 $DIR2/$tfile-6
1401                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1402         fi
1403
1404        # all operations above shouldn't wait the first one
1405         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1406         wait $PID1
1407         rm -r $DIR1/*
1408         return 0
1409 }
1410 run_test 40e "pdirops: rename and others =============="
1411
1412 # test 41: create blocking operations
1413 test_41a() {
1414 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1415         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1416         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1417         PID1=$!
1418         sleep 1
1419         mkdir $DIR2/$tfile && error "mkdir must fail"
1420         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1421         rm -r $DIR1/*
1422         return 0
1423 }
1424 run_test 41a "pdirops: create vs mkdir =============="
1425
1426 test_41b() {
1427 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1428         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1429         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1430         PID1=$!
1431         sleep 1
1432         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1433         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1434         rm -r $DIR1/*
1435         return 0
1436 }
1437 run_test 41b "pdirops: create vs create =============="
1438
1439 test_41c() {
1440         touch $DIR1/$tfile-2
1441 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1442         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1443         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1444         PID1=$!
1445         sleep 1
1446         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1447         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1448         rm -r $DIR1/*
1449         return 0
1450 }
1451 run_test 41c "pdirops: create vs link =============="
1452
1453 test_41d() {
1454 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1455         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1456         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1457         PID1=$!
1458         sleep 1
1459         rm $DIR2/$tfile || error "unlink must succeed"
1460         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1461         rm -r $DIR1/*
1462         return 0
1463 }
1464 run_test 41d "pdirops: create vs unlink =============="
1465
1466 test_41e() {
1467         touch $DIR1/$tfile-2
1468 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1469         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1470         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1471         PID1=$!
1472         sleep 1
1473         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1474         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1475         rm -r $DIR1/*
1476         return 0
1477 }
1478 run_test 41e "pdirops: create and rename (tgt) =============="
1479
1480 test_41f() {
1481 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1482         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1483         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1484         PID1=$!
1485         sleep 1
1486         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1487         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1488         rm -r $DIR1/*
1489         return 0
1490 }
1491 run_test 41f "pdirops: create and rename (src) =============="
1492
1493 test_41g() {
1494 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1495         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1496         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1497         PID1=$!
1498         sleep 1
1499         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1500         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1501         rm -r $DIR1/*
1502         return 0
1503 }
1504 run_test 41g "pdirops: create vs getattr =============="
1505
1506 test_41h() {
1507 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1508         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1509         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1510         PID1=$!
1511         sleep 1
1512         ls -lia $DIR2/ > /dev/null
1513         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1514         rm -r $DIR1/*
1515         return 0
1516 }
1517 run_test 41h "pdirops: create vs readdir =============="
1518
1519 # test 42: unlink and blocking operations
1520 test_42a() {
1521 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1522         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1523         mkdir $DIR1/$tfile &
1524         PID1=$!
1525         sleep 1
1526         mkdir $DIR2/$tfile && error "mkdir must fail"
1527         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1528         rm -r $DIR1/*
1529         return 0
1530 }
1531 run_test 42a "pdirops: mkdir vs mkdir =============="
1532
1533 test_42b() {
1534 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1535         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1536         mkdir $DIR1/$tfile &
1537         PID1=$!
1538         sleep 1
1539         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1540         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1541         rm -r $DIR1/*
1542         return 0
1543 }
1544 run_test 42b "pdirops: mkdir vs create =============="
1545
1546 test_42c() {
1547         touch $DIR1/$tfile-2
1548 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1549         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1550         mkdir $DIR1/$tfile &
1551         PID1=$!
1552         sleep 1
1553         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1554         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1555         rm -r $DIR1/*
1556         return 0
1557 }
1558 run_test 42c "pdirops: mkdir vs link =============="
1559
1560 test_42d() {
1561 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1562         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1563         mkdir $DIR1/$tfile &
1564         PID1=$!
1565         sleep 1
1566         rmdir $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 42d "pdirops: mkdir vs unlink =============="
1572
1573 test_42e() {
1574         touch $DIR1/$tfile-2
1575 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1576         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1577         mkdir $DIR1/$tfile &
1578         PID1=$!
1579         sleep 1
1580         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1581         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1582         rm -r $DIR1/*
1583         return 0
1584 }
1585 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1586
1587 test_42f() {
1588 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1589         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1590         mkdir $DIR1/$tfile &
1591         PID1=$!
1592         sleep 1
1593         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1594         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1595         rm -r $DIR1/*
1596         return 0
1597 }
1598 run_test 42f "pdirops: mkdir and rename (src) =============="
1599
1600 test_42g() {
1601 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1602         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1603         mkdir $DIR1/$tfile &
1604         PID1=$!
1605         sleep 1
1606         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1607         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1608         rm -r $DIR1/*
1609         return 0
1610 }
1611 run_test 42g "pdirops: mkdir vs getattr =============="
1612
1613 test_42h() {
1614 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1615         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1616         mkdir $DIR1/$tfile &
1617         PID1=$!
1618         sleep 1
1619         ls -lia $DIR2/ > /dev/null
1620         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1621         rm -r $DIR1/*
1622         return 0
1623 }
1624 run_test 42h "pdirops: mkdir vs readdir =============="
1625
1626 # test 43: unlink and blocking operations
1627 test_43a() {
1628         touch $DIR1/$tfile
1629 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1630         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1631         rm $DIR1/$tfile &
1632         PID1=$!
1633         sleep 1
1634         mkdir $DIR2/$tfile || error "mkdir must succeed"
1635         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1636         rm -r $DIR1/*
1637         return 0
1638 }
1639 run_test 43a "pdirops: unlink vs mkdir =============="
1640
1641 test_43b() {
1642         touch $DIR1/$tfile
1643 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1644         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1645         rm $DIR1/$tfile &
1646         PID1=$!
1647         sleep 1
1648         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1649         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1650         rm -r $DIR1/*
1651         return 0
1652 }
1653 run_test 43b "pdirops: unlink vs create =============="
1654
1655 test_43c() {
1656         touch $DIR1/$tfile
1657         touch $DIR1/$tfile-2
1658 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1659         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1660         rm $DIR1/$tfile &
1661         PID1=$!
1662         sleep 1
1663         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1664         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1665         rm -r $DIR1/*
1666         return 0
1667 }
1668 run_test 43c "pdirops: unlink vs link =============="
1669
1670 test_43d() {
1671         touch $DIR1/$tfile
1672 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1673         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1674         rm $DIR1/$tfile &
1675         PID1=$!
1676         sleep 1
1677         rm $DIR2/$tfile && error "unlink must fail"
1678         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1679         rm -r $DIR1/*
1680         return 0
1681 }
1682 run_test 43d "pdirops: unlink vs unlink =============="
1683
1684 test_43e() {
1685         touch $DIR1/$tfile
1686         touch $DIR1/$tfile-2
1687 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1688         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1689         rm $DIR1/$tfile &
1690         PID1=$!
1691         sleep 1
1692         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1693         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1694         rm -r $DIR1/*
1695         return 0
1696 }
1697 run_test 43e "pdirops: unlink and rename (tgt) =============="
1698
1699 test_43f() {
1700         touch $DIR1/$tfile
1701 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1702         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1703         rm $DIR1/$tfile &
1704         PID1=$!
1705         sleep 1
1706         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1707         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1708         rm -r $DIR1/*
1709         return 0
1710 }
1711 run_test 43f "pdirops: unlink and rename (src) =============="
1712
1713 test_43g() {
1714         touch $DIR1/$tfile
1715 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1716         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1717         rm $DIR1/$tfile &
1718         PID1=$!
1719         sleep 1
1720         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1721         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1722         rm -r $DIR1/*
1723         return 0
1724 }
1725 run_test 43g "pdirops: unlink vs getattr =============="
1726
1727 test_43h() {
1728         touch $DIR1/$tfile
1729 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1730         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1731         rm $DIR1/$tfile &
1732         PID1=$!
1733         sleep 1
1734         ls -lia $DIR2/ > /dev/null
1735         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1736         rm -r $DIR1/*
1737         return 0
1738 }
1739 run_test 43h "pdirops: unlink vs readdir =============="
1740
1741 test_43i() {
1742         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1743         touch $DIR1/$tfile
1744 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1745         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1746         rm $DIR1/$tfile &
1747         PID1=$!
1748         sleep 1
1749         $LFS mkdir -i 1 $DIR2/$tfile || error "remote mkdir must succeed"
1750         check_pdo_conflict $PID1 &&
1751                 { wait $PID1; error "remote mkdir isn't blocked"; }
1752         rm -r $DIR1/*
1753         return 0
1754 }
1755 run_test 43i "pdirops: unlink vs remote mkdir"
1756
1757 # test 44: rename tgt and blocking operations
1758 test_44a() {
1759         touch $DIR1/$tfile-2
1760 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1761         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1762         mv $DIR1/$tfile-2 $DIR1/$tfile &
1763         PID1=$!
1764         sleep 1
1765         mkdir $DIR2/$tfile && error "mkdir must fail"
1766         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1767         rm -r $DIR1/*
1768         return 0
1769 }
1770 run_test 44a "pdirops: rename tgt vs mkdir =============="
1771
1772 test_44b() {
1773         touch $DIR1/$tfile-2
1774 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1775         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1776         mv $DIR1/$tfile-2 $DIR1/$tfile &
1777         PID1=$!
1778         sleep 1
1779         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1780         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1781         rm -r $DIR1/*
1782         return 0
1783 }
1784 run_test 44b "pdirops: rename tgt vs create =============="
1785
1786 test_44c() {
1787         touch $DIR1/$tfile-2
1788         touch $DIR1/$tfile-3
1789 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1790         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1791         mv $DIR1/$tfile-2 $DIR1/$tfile &
1792         PID1=$!
1793         sleep 1
1794         link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
1795         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1796         rm -r $DIR1/*
1797         return 0
1798 }
1799 run_test 44c "pdirops: rename tgt vs link =============="
1800
1801 test_44d() {
1802         touch $DIR1/$tfile-2
1803 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1804         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1805         mv $DIR1/$tfile-2 $DIR1/$tfile &
1806         PID1=$!
1807         sleep 1
1808         rm $DIR2/$tfile || error "unlink must succeed"
1809         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1810         rm -r $DIR1/*
1811         return 0
1812 }
1813 run_test 44d "pdirops: rename tgt vs unlink =============="
1814
1815 test_44e() {
1816         touch $DIR1/$tfile
1817         touch $DIR1/$tfile-2
1818         touch $DIR1/$tfile-3
1819 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1820         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1821         mv $DIR1/$tfile-2 $DIR1/$tfile &
1822         PID1=$!
1823         sleep 1
1824         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1825         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1826         rm -r $DIR1/*
1827         return 0
1828 }
1829 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
1830
1831 test_44f() {
1832         touch $DIR1/$tfile-2
1833         touch $DIR1/$tfile-3
1834 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1835         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1836         mv $DIR1/$tfile-2 $DIR1/$tfile &
1837         PID1=$!
1838         sleep 1
1839         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1840         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1841         rm -r $DIR1/*
1842         return 0
1843 }
1844 run_test 44f "pdirops: rename tgt and rename (src) =============="
1845
1846 test_44g() {
1847         touch $DIR1/$tfile-2
1848 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1849         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1850         mv $DIR1/$tfile-2 $DIR1/$tfile &
1851         PID1=$!
1852         sleep 1
1853         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1854         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1855         rm -r $DIR1/*
1856         return 0
1857 }
1858 run_test 44g "pdirops: rename tgt vs getattr =============="
1859
1860 test_44h() {
1861         touch $DIR1/$tfile-2
1862 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1863         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1864         mv $DIR1/$tfile-2 $DIR1/$tfile &
1865         PID1=$!
1866         sleep 1
1867         ls -lia $DIR2/ > /dev/null
1868         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1869         rm -r $DIR1/*
1870         return 0
1871 }
1872 run_test 44h "pdirops: rename tgt vs readdir =============="
1873
1874 # test 44: rename tgt and blocking operations
1875 test_44i() {
1876         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1877         touch $DIR1/$tfile-2
1878 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1879         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1880         mv $DIR1/$tfile-2 $DIR1/$tfile &
1881         PID1=$!
1882         sleep 1
1883         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
1884         check_pdo_conflict $PID1 && { wait $PID1;
1885                                 error "remote mkdir isn't blocked"; }
1886         rm -r $DIR1/*
1887         return 0
1888 }
1889 run_test 44i "pdirops: rename tgt vs remote mkdir"
1890
1891 # test 45: rename src and blocking operations
1892 test_45a() {
1893         touch $DIR1/$tfile
1894 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1895         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1896         mv $DIR1/$tfile $DIR1/$tfile-2 &
1897         PID1=$!
1898         sleep 1
1899         mkdir $DIR2/$tfile || error "mkdir must succeed"
1900         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1901         rm -r $DIR1/*
1902         return 0
1903 }
1904 run_test 45a "pdirops: rename src vs mkdir =============="
1905
1906 test_45b() {
1907         touch $DIR1/$tfile
1908 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1909         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1910         mv $DIR1/$tfile $DIR1/$tfile-2 &
1911         PID1=$!
1912         sleep 1
1913         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1914         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1915         rm -r $DIR1/*
1916         return 0
1917 }
1918 run_test 45b "pdirops: rename src vs create =============="
1919
1920 test_45c() {
1921         touch $DIR1/$tfile
1922         touch $DIR1/$tfile-3
1923 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1924         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1925         mv $DIR1/$tfile $DIR1/$tfile-2 &
1926         PID1=$!
1927         sleep 1
1928         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
1929         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1930         rm -r $DIR1/*
1931         return 0
1932 }
1933 run_test 45c "pdirops: rename src vs link =============="
1934
1935 test_45d() {
1936         touch $DIR1/$tfile
1937 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1938         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1939         mv $DIR1/$tfile $DIR1/$tfile-2 &
1940         PID1=$!
1941         sleep 1
1942         rm $DIR2/$tfile && error "unlink must fail"
1943         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1944         rm -r $DIR1/*
1945         return 0
1946 }
1947 run_test 45d "pdirops: rename src vs unlink =============="
1948
1949 test_45e() {
1950         touch $DIR1/$tfile
1951         touch $DIR1/$tfile-3
1952 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1953         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1954         mv $DIR1/$tfile $DIR1/$tfile-2 &
1955         PID1=$!
1956         sleep 1
1957         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1958         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1959         rm -r $DIR1/*
1960         return 0
1961 }
1962 run_test 45e "pdirops: rename src and rename (tgt) =============="
1963
1964 test_45f() {
1965         touch $DIR1/$tfile
1966 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1967         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1968         mv $DIR1/$tfile $DIR1/$tfile-2 &
1969         PID1=$!
1970         sleep 1
1971         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
1972         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1973         rm -r $DIR1/*
1974         return 0
1975 }
1976 run_test 45f "pdirops: rename src and rename (src) =============="
1977
1978 test_45g() {
1979         touch $DIR1/$tfile
1980 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1981         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1982         mv $DIR1/$tfile $DIR1/$tfile-2 &
1983         PID1=$!
1984         sleep 1
1985         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1986         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1987         rm -r $DIR1/*
1988         return 0
1989 }
1990 run_test 45g "pdirops: rename src vs getattr =============="
1991
1992 test_45h() {
1993         touch $DIR1/$tfile
1994 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1995         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1996         mv $DIR1/$tfile $DIR1/$tfile-2 &
1997         PID1=$!
1998         sleep 1
1999         ls -lia $DIR2/ > /dev/null
2000         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2001         rm -r $DIR1/*
2002         return 0
2003 }
2004 run_test 45h "pdirops: unlink vs readdir =============="
2005
2006 test_45i() {
2007         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2008         touch $DIR1/$tfile
2009 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2010         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2011         mv $DIR1/$tfile $DIR1/$tfile-2 &
2012         PID1=$!
2013         sleep 1
2014         $LFS mkdir -i 1 $DIR2/$tfile || error "create remote dir must succeed"
2015         check_pdo_conflict $PID1 && { wait $PID1;
2016                                 error "create remote dir isn't blocked"; }
2017         rm -r $DIR1/*
2018         return 0
2019 }
2020 run_test 45i "pdirops: rename src vs remote mkdir"
2021
2022 # test 46: link and blocking operations
2023 test_46a() {
2024         touch $DIR1/$tfile-2
2025 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2026         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2027         link $DIR1/$tfile-2 $DIR1/$tfile &
2028         PID1=$!
2029         sleep 1
2030         mkdir $DIR2/$tfile && error "mkdir must fail"
2031         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2032         rm -r $DIR1/*
2033         return 0
2034 }
2035 run_test 46a "pdirops: link vs mkdir =============="
2036
2037 test_46b() {
2038         touch $DIR1/$tfile-2
2039 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2040         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2041         link $DIR1/$tfile-2 $DIR1/$tfile &
2042         PID1=$!
2043         sleep 1
2044         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2045         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2046         rm -r $DIR1/*
2047         return 0
2048 }
2049 run_test 46b "pdirops: link vs create =============="
2050
2051 test_46c() {
2052         touch $DIR1/$tfile-2
2053 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2054         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2055         link $DIR1/$tfile-2 $DIR1/$tfile &
2056         PID1=$!
2057         sleep 1
2058         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
2059         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2060         rm -r $DIR1/*
2061         return 0
2062 }
2063 run_test 46c "pdirops: link vs link =============="
2064
2065 test_46d() {
2066         touch $DIR1/$tfile-2
2067 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2068         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2069         link $DIR1/$tfile-2 $DIR1/$tfile &
2070         PID1=$!
2071         sleep 1
2072         rm $DIR2/$tfile || error "unlink must succeed"
2073         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2074         rm -r $DIR1/*
2075         return 0
2076 }
2077 run_test 46d "pdirops: link vs unlink =============="
2078
2079 test_46e() {
2080         touch $DIR1/$tfile-2
2081         touch $DIR1/$tfile-3
2082 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2083         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2084         link $DIR1/$tfile-2 $DIR1/$tfile &
2085         PID1=$!
2086         sleep 1
2087         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2088         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2089         rm -r $DIR1/*
2090         return 0
2091 }
2092 run_test 46e "pdirops: link and rename (tgt) =============="
2093
2094 test_46f() {
2095         touch $DIR1/$tfile-2
2096         touch $DIR1/$tfile-3
2097 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2098         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2099         link $DIR1/$tfile-2 $DIR1/$tfile &
2100         PID1=$!
2101         sleep 1
2102         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
2103         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2104         rm -r $DIR1/*
2105         return 0
2106 }
2107 run_test 46f "pdirops: link and rename (src) =============="
2108
2109 test_46g() {
2110         touch $DIR1/$tfile-2
2111 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2112         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2113         link $DIR1/$tfile-2 $DIR1/$tfile &
2114         PID1=$!
2115         sleep 1
2116         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2117         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2118         rm -r $DIR1/*
2119         return 0
2120 }
2121 run_test 46g "pdirops: link vs getattr =============="
2122
2123 test_46h() {
2124         touch $DIR1/$tfile-2
2125 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2126         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2127         link $DIR1/$tfile-2 $DIR1/$tfile &
2128         PID1=$!
2129         sleep 1
2130         ls -lia $DIR2/ > /dev/null
2131         check_pdo_conflict $PID1 && { wait $PID1;
2132                         error "readdir isn't blocked"; }
2133         rm -r $DIR1/*
2134         return 0
2135 }
2136 run_test 46h "pdirops: link vs readdir =============="
2137
2138 test_46i() {
2139         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2140         touch $DIR1/$tfile-2
2141 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2142         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2143         link $DIR1/$tfile-2 $DIR1/$tfile &
2144         PID1=$!
2145         sleep 1
2146         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
2147         check_pdo_conflict $PID1 && { wait $PID1;
2148                                 error "remote mkdir isn't blocked"; }
2149         rm -r $DIR1/*
2150         return 0
2151 }
2152 run_test 46i "pdirops: link vs remote mkdir"
2153
2154 # test 47: remote mkdir and blocking operations
2155 test_47a() {
2156 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2157         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2158         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2159         $LFS mkdir -i 1 $DIR1/$tfile &
2160         PID1=$!
2161         sleep 1
2162         mkdir $DIR2/$tfile && error "mkdir must fail"
2163         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2164         rm -r $DIR1/*
2165         return 0
2166 }
2167 run_test 47a "pdirops: remote mkdir vs mkdir"
2168
2169 test_47b() {
2170 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2171         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2172         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2173         $LFS mkdir -i 1 $DIR1/$tfile &
2174         PID1=$!
2175         sleep 1
2176         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2177         check_pdo_conflict $PID1 && { wait $PID1;
2178                                         error "create isn't blocked"; }
2179         rm -r $DIR1/*
2180         return 0
2181 }
2182 run_test 47b "pdirops: remote mkdir vs create"
2183
2184 test_47c() {
2185         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2186         touch $DIR1/$tfile-2
2187 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2188         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2189         $LFS mkdir -i 1 $DIR1/$tfile &
2190         PID1=$!
2191         sleep 1
2192         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
2193         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2194         rm -r $DIR1/*
2195         return 0
2196 }
2197 run_test 47c "pdirops: remote mkdir vs link"
2198
2199 test_47d() {
2200         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2201 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2202         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2203         $LFS mkdir -i 1 $DIR1/$tfile &
2204         PID1=$!
2205         sleep 1
2206         rmdir $DIR2/$tfile || error "unlink must succeed"
2207         check_pdo_conflict $PID1 && { wait $PID1;
2208                                         error "unlink isn't blocked"; }
2209         rm -r $DIR1/*
2210         return 0
2211 }
2212 run_test 47d "pdirops: remote mkdir vs unlink"
2213
2214 test_47e() {
2215         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2216         touch $DIR1/$tfile-2
2217 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2218         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2219         $LFS mkdir -i 1 $DIR1/$tfile &
2220         PID1=$!
2221         sleep 1
2222         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
2223         check_pdo_conflict $PID1 && { wait $PID1;
2224                                         error "rename isn't blocked"; }
2225         rm -r $DIR1/*
2226         return 0
2227 }
2228 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2229
2230 test_47f() {
2231         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2232 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2233         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2234         $LFS mkdir -i 1 $DIR1/$tfile &
2235         PID1=$!
2236         sleep 1
2237         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
2238         check_pdo_conflict $PID1 && { wait $PID1;
2239                                         error "rename isn't blocked"; }
2240         rm -r $DIR1/*
2241         return 0
2242 }
2243 run_test 47f "pdirops: remote mkdir and rename (src)"
2244
2245 test_47g() {
2246         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2247 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2248         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2249         $LFS mkdir -i 1 $DIR1/$tfile &
2250         PID1=$!
2251         sleep 1
2252         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2253         check_pdo_conflict $PID1 && { wait $PID1;
2254                                         error "getattr isn't blocked"; }
2255         rm -r $DIR1/*
2256         return 0
2257 }
2258 run_test 47g "pdirops: remote mkdir vs getattr"
2259
2260 test_50() {
2261         trunc_size=4096
2262         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2263 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2264         do_facet client "lctl set_param fail_loc=0x410"
2265         $TRUNCATE $DIR2/$tfile $trunc_size
2266         do_facet client "lctl set_param fail_loc=0x0"
2267         sleep 3
2268         size=`stat -c %s $DIR2/$tfile`
2269         [ $size -eq $trunc_size ] || error "wrong size"
2270 }
2271 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2272
2273 test_51a() {
2274         local filesize
2275         local origfile=/etc/hosts
2276
2277         filesize=`stat -c %s $origfile`
2278
2279         # create an empty file
2280         $MCREATE $DIR1/$tfile
2281         # cache layout lock on both mount point
2282         stat $DIR1/$tfile > /dev/null
2283         stat $DIR2/$tfile > /dev/null
2284
2285         # open and sleep 2 seconds then read
2286         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2287         local pid=$!
2288         sleep 1
2289
2290         # create the layout of testing file
2291         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null
2292
2293         # MULTIOP proc should be able to read enough bytes and exit
2294         sleep 2
2295         kill -0 $pid && error "multiop is still there"
2296         cmp $origfile $DIR2/$tfile || error "$MCREATE and $DIR2/$tfile differs"
2297
2298         rm -f $DIR1/$tfile
2299 }
2300 run_test 51a "layout lock: refresh layout should work"
2301
2302 test_51b() {
2303         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2304                 { skip "Need MDS version at least 2.3.59"; return 0; }
2305
2306         local tmpfile=`mktemp`
2307
2308         # create an empty file
2309         $MCREATE $DIR1/$tfile
2310
2311         # delay glimpse so that layout has changed when glimpse finish
2312 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2313         $LCTL set_param fail_loc=0x1404
2314         stat -c %s $DIR2/$tfile |tee $tmpfile &
2315         local pid=$!
2316         sleep 1
2317
2318         # create layout of testing file
2319         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc > /dev/null
2320
2321         wait $pid
2322         local fsize=`cat $tmpfile`
2323
2324         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2325
2326         rm -f $DIR1/$tfile $tmpfile
2327 }
2328 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2329
2330 test_51c() {
2331         # create an empty file
2332         $MCREATE $DIR1/$tfile
2333
2334 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2335         $LCTL set_param fail_loc=0x172
2336
2337         # change the layout of testing file
2338         echo "Setting layout ..."
2339         $LFS setstripe -c $OSTCOUNT $DIR1/$tfile &
2340         pid=$!
2341         sleep 1
2342
2343         # get layout of this file should wait until dd is finished
2344         local stripecnt=`$LFS getstripe -c $DIR2/$tfile`
2345         [ $stripecnt -eq $OSTCOUNT ] || error "layout wrong"
2346
2347         rm -f $DIR1/$tfile
2348 }
2349 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2350
2351 test_60() {
2352         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
2353         { skip "Need MDS version at least 2.3.0"; return; }
2354         # Create a file
2355         test_mkdir -p $DIR1/$tdir
2356         file1=$DIR1/$tdir/file
2357         file2=$DIR2/$tdir/file
2358
2359         echo orig > $file2 || error "Could not create $file2"
2360         version=$($LFS data_version $file1)
2361
2362         # Append data
2363         echo append >> $file2 || error "Could not append to $file2"
2364         version2=$($LFS data_version $file1)
2365         [ "$version" != "$version2" ] ||
2366             error "append did not change data version: $version"
2367
2368         # Overwrite data
2369         echo overwrite > $file2 || error "Could not overwrite $file2"
2370         version3=$($LFS data_version $file1)
2371         [ "$version2" != "$version3" ] ||
2372             error "overwrite did not change data version: $version2"
2373
2374         # Truncate before EOF
2375         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2376         version4=$($LFS data_version $file1)
2377         [ "$version3" != "$version4" ] ||
2378             error "truncate did not change data version: $version3"
2379
2380         # Truncate after EOF
2381         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2382         version5=$($LFS data_version $file1)
2383         [ "$version4" != "$version5" ] ||
2384             error "truncate did not change data version: $version4"
2385
2386         # Chmod do not change version
2387         chmod 400 $file2 || error "Could not chmod 400 $file2"
2388         version6=$($LFS data_version $file1)
2389         [ "$version5" == "$version6" ] ||
2390             error "chmod should not change data version: $version5 != $version6"
2391
2392         # Chown do not change version
2393         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
2394         version7=$($LFS data_version $file1)
2395         [ "$version5" == "$version7" ] ||
2396             error "chown should not change data version: $version5 != $version7"
2397 }
2398 run_test 60 "Verify data_version behaviour"
2399
2400 test_70a() {
2401         local test_dir=$tdir/test_dir
2402
2403         mkdir -p $DIR1/$tdir
2404         if [ $MDSCOUNT -ge 2 ]; then
2405                 local MDTIDX=1
2406                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
2407                         error "Create remote directory failed"
2408         else
2409                 mkdir -p $DIR1/$test_dir
2410         fi
2411         cd $DIR2/$test_dir || error "cd directory failed"
2412         rm -rf $DIR1/$test_dir || error "unlink directory failed"
2413
2414         cd $DIR2/$tdir || error "exit directory"
2415 }
2416 run_test 70a "cd directory && rm directory"
2417
2418 test_70b() { # LU-2781
2419         local i
2420         mkdir -p $DIR1/$tdir
2421
2422         touch $DIR1/$tdir/file
2423         for ((i = 0; i < 32; i++)); do
2424             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
2425         done
2426         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2427
2428         touch $DIR1/$tdir/file
2429         $LFS mkdir -i0 $DIR1/$tdir/test_dir
2430         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
2431         rm -rf $DIR1/$tdir/test_dir ||
2432                 error "cannot remove directory after rm_entry"
2433         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2434 }
2435 run_test 70b "remove files after calling rm_entry"
2436
2437 test_71() {
2438         local server_version=$(lustre_version_code $SINGLEMDS)
2439
2440         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2441                 skip "Need MDS version at least 2.1.6" && return
2442
2443         # Patch not applied to 2.2 and 2.3 branches
2444         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2445         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2446                 skip "Need MDS version at least 2.4.0" && return
2447
2448         checkfiemap --test ||
2449                 { skip "checkfiemap not runnable: $?" && return; }
2450         # write data this way: hole - data - hole - data
2451         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2452         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tfile) + 1)))" = \
2453                 "zfs" ] &&
2454                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
2455         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2456         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
2457         stat $DIR2/$tfile
2458         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2459         echo $can1
2460         checkfiemap $DIR2/$tfile 81920 ||
2461                 error "data is not flushed from client"
2462         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2463         echo $can2
2464
2465         # common case of "create file, copy file" on a single node
2466         # should not flush data from ost
2467         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2468         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2469         stat $DIR1/$tfile
2470         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2471         echo $can3
2472         checkfiemap $DIR1/$tfile 81920 ||
2473         error 4
2474         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2475         echo $can2
2476         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
2477 }
2478 run_test 71 "correct file map just after write operation is finished"
2479
2480 test_72() {
2481         local p="$TMP/sanityN-$TESTNAME.parameters"
2482         local tlink1
2483         local tlink2
2484         save_lustre_params client "llite.*.xattr_cache" > $p
2485         lctl set_param llite.*.xattr_cache 1 ||
2486                 { skip "xattr cache is not supported"; return 0; }
2487
2488         touch $DIR1/$tfile
2489         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2490                 error "setfattr1 failed"
2491         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
2492                 error "getfattr1 failed"
2493         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
2494                 error "setfattr2 failed"
2495         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
2496                 error "getfattr2 failed"
2497
2498         # check that trusted.link is consistent
2499         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2500         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
2501         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2502         echo "$tlink1 $tlink2"
2503         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
2504
2505         rm -f $DIR2/$tfile
2506
2507         restore_lustre_params < $p
2508         rm -f $p
2509 }
2510 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
2511
2512 test_73() {
2513         local p="$TMP/sanityN-$TESTNAME.parameters"
2514         save_lustre_params client "llite.*.xattr_cache" > $p
2515         lctl set_param llite.*.xattr_cache 1 ||
2516                 { skip "xattr cache is not supported"; return 0; }
2517
2518         touch $DIR1/$tfile
2519         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2520                 error "setfattr1 failed"
2521         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
2522         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
2523         clear_llite_stats
2524         # PR lock should be cached by now on both clients
2525         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
2526         # 2 hits for getfattr(0)+getfattr(size)
2527         [ $(calc_llite_stats getxattr_hits) -eq 2 ] || error "not cached in $DIR1"
2528         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
2529         # 4 hits for more getfattr(0)+getfattr(size)
2530         [ $(calc_llite_stats getxattr_hits) -eq 4 ] || error "not cached in $DIR2"
2531         rm -f $DIR2/$tfile
2532
2533         restore_lustre_params < $p
2534         rm -f $p
2535 }
2536 run_test 73 "getxattr should not cause xattr lock cancellation"
2537
2538 test_74() {
2539         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
2540         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
2541         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
2542 }
2543 run_test 74 "flock deadlock: different mounts =============="
2544
2545 log "cleanup: ======================================================"
2546
2547 [ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
2548
2549 complete $SECONDS
2550 check_and_cleanup_lustre
2551 exit_status