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