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