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