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