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