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