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