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