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