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