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