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