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