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