Whamcloud - gitweb
LU-9595 tests: remove sanityn test 18c from ALWAYS_EXCEPT
[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 || error
273        cd $DIR1/d13 || error
274        ls
275        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
276        ls
277        rm -f $DIR2/d13/f13 || error
278        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
279        # need to run it twice
280        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
281        ls
282        rm -f $DIR2/d13/f13 || error
283        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
284 }
285 run_test 13 "test directory page revocation ===================="
286
287 test_14aa() {
288         test_mkdir -p $DIR1/$tdir
289         cp -p /bin/ls $DIR1/$tdir/$tfile
290         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
291         MULTIPID=$!
292
293         $DIR2/$tdir/$tfile && error || true
294         kill -USR1 $MULTIPID
295         wait $MULTIPID || return 2
296 }
297 run_test 14aa "execution of file open for write returns -ETXTBSY"
298
299 test_14ab() {
300         test_mkdir -p $DIR1/d14
301         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
302         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
303         MULTIOP_PID=$!
304         $MULTIOP $DIR2/d14/multiop Oc && error "expected error, got success"
305         kill -USR1 $MULTIOP_PID || return 2
306         wait $MULTIOP_PID || return 3
307         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
308 }
309 run_test 14ab "open(RDWR) of executing file returns -ETXTBSY"
310
311 test_14b() { # bug 3192, 7040
312         test_mkdir -p $DIR1/d14
313         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
314         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
315         MULTIOP_PID=$!
316         $TRUNCATE $DIR2/d14/multiop 0 && kill -9 $MULTIOP_PID && \
317                 error "expected truncate error, got success"
318         kill -USR1 $MULTIOP_PID || return 2
319         wait $MULTIOP_PID || return 3
320         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
321         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
322 }
323 run_test 14b "truncate of executing file returns -ETXTBSY ======"
324
325 test_14c() { # bug 3430, 7040
326         test_mkdir -p $DIR1/d14
327         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
328         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
329         MULTIOP_PID=$!
330         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
331         kill -USR1 $MULTIOP_PID || return 2
332         wait $MULTIOP_PID || return 3
333         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
334         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
335 }
336 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
337
338 test_14d() { # bug 10921
339         test_mkdir -p $DIR1/d14
340         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
341         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
342         MULTIOP_PID=$!
343         log chmod
344         chmod 600 $DIR1/d14/multiop || error "chmod failed"
345         kill -USR1 $MULTIOP_PID || return 2
346         wait $MULTIOP_PID || return 3
347         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
348         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
349 }
350 run_test 14d "chmod of executing file is still possible ========"
351
352 test_15() {     # bug 974 - ENOSPC
353         echo "PATH=$PATH"
354         sh oos2.sh $MOUNT1 $MOUNT2
355         wait_delete_completed
356         grant_error=`dmesg | grep "> available"`
357         [ -z "$grant_error" ] || error "$grant_error"
358 }
359 run_test 15 "test out-of-space with multiple writers ==========="
360
361 COUNT=${COUNT:-2500}
362 # The FSXNUM reduction for ZFS is needed until ORI-487 is fixed.
363 # We don't want to skip it entirely, but ZFS is VERY slow and cannot
364 # pass a 2500 operation dual-mount run within the time limit.
365 if [ "$(facet_fstype ost1)" = "zfs" ]; then
366         FSXNUM=$((COUNT / 5))
367         FSXP=1
368 elif [ "$SLOW" = "yes" ]; then
369         FSXNUM=$((COUNT * 5))
370         FSXP=500
371 else
372         FSXNUM=$COUNT
373         FSXP=100
374 fi
375
376 test_16() {
377         local file1=$DIR1/$tfile
378         local file2=$DIR2/$tfile
379
380         # to allocate grant because it may run out due to test_15.
381         $LFS setstripe -c -1 $file1
382         dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
383         dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
384         rm -f $file1
385
386         $LFS setstripe -c -1 $file1 # b=10919
387         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 \
388                 || error "fsx failed"
389         rm -f $file1
390
391         # O_DIRECT reads and writes must be aligned to the device block size.
392         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 -Z -r 4096 \
393                 -w 4096 $file1 $file2 || error "fsx with O_DIRECT failed."
394 }
395 run_test 16 "$FSXNUM iterations of dual-mount fsx"
396
397 test_17() { # bug 3513, 3667
398         remote_ost_nodsh && skip "remote OST with nodsh" && return
399
400         lfs setstripe $DIR1/$tfile -i 0 -c 1
401         cp $SAMPLE_FILE $DIR1/$tfile
402         cancel_lru_locks osc > /dev/null
403         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
404         do_facet ost1 lctl set_param fail_loc=0x8000030a
405         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
406         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
407         wait
408         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
409 }
410 run_test 17 "resource creation/LVB creation race ==============="
411
412 test_18() {
413         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
414         local idx
415         local excepts=
416         for idx in {a..z}; do
417                 local ptr=EXCEPT_ALWAYS_18$idx
418                 [ x${!ptr} = xtrue ] || continue
419
420                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
421         done
422
423         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
424         sync; sleep 1; sync
425 }
426 run_test 18 "mmap sanity check ================================="
427
428 test_19() { # bug3811
429         local node=$(facet_active_host ost1)
430
431         # check whether obdfilter is cache capable at all
432         if ! get_osd_param $node '' read_cache_enable >/dev/null; then
433                 echo "not cache-capable obdfilter"
434                 return 0
435         fi
436
437         local MAX=$(get_osd_param $node '' readcache_max_filesize | \
438                     head -n 1)
439         set_osd_param $node '' readcache_max_filesize 4096
440         dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
441         local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
442         cp $TMP/$tfile $DIR1/$tfile
443         for i in `seq 1 20`; do
444                 [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
445                 cancel_lru_locks osc > /dev/null
446                 cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
447                 cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
448                 wait
449                 [ "$(cat $TMP/sum1)" = "$SUM" ] || \
450                         error "$DIR1/$tfile $(cat $TMP/sum1) != $SUM"
451                 [ "$(cat $TMP/sum2)" = "$SUM" ] || \
452                         error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
453         done
454         set_osd_param $node '' readcache_max_filesize $MAX
455         rm $DIR1/$tfile
456 }
457 run_test 19 "test concurrent uncached read races ==============="
458
459 test_20() {
460         test_mkdir $DIR1/d20
461         cancel_lru_locks osc
462         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
463         $MULTIOP $DIR1/f20 Ow8190c
464         $MULTIOP $DIR2/f20 Oz8194w8190c
465         $MULTIOP $DIR1/f20 Oz0r8190c
466         cancel_lru_locks osc
467         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
468         [ $CNTD -gt 0 ] && \
469             error $CNTD" page left in cache after lock cancel" || true
470 }
471 run_test 20 "test extra readahead page left in cache ===="
472
473 cleanup_21() {
474         trap 0
475         umount $DIR1/$tdir
476 }
477
478 test_21() { # Bug 5907
479         test_mkdir $DIR1/$tdir
480         mount /etc $DIR1/$tdir --bind || error "mount failed" # Poor man's mount.
481         trap cleanup_21 EXIT
482         rmdir -v $DIR1/$tdir && error "Removed mounted directory"
483         rmdir -v $DIR2/$tdir && echo "Removed mounted directory from another mountpoint, needs to be fixed"
484         test -d $DIR1/$tdir || error "Mounted directory disappeared"
485         cleanup_21
486         test -d $DIR2/$tdir || test -d $DIR1/$tdir && error "Removed dir still visible after umount"
487         true
488 }
489 run_test 21 " Try to remove mountpoint on another dir ===="
490
491 test_23() { # Bug 5972
492         local at_diff=$(do_facet $SINGLEMDS \
493                 $LCTL get_param -n mdd.*MDT0000*.atime_diff | head -n1)
494         echo "atime should be updated while another read" > $DIR1/$tfile
495
496         # clear the lock(mode: LCK_PW) gotten from creating operation
497         cancel_lru_locks osc
498         time1=$(date +%s)
499         echo "now is $time1"
500         sleep $((at_diff + 1))
501
502         echo "starting reads"
503         multiop_bg_pause $DIR1/$tfile or20_c || return 1
504         # with SOM and opencache enabled, we need to close a file and cancel
505         # open lock to get atime propogated to MDS
506         kill -USR1 $! || return 2
507         cancel_lru_locks mdc
508
509         time2=$(stat -c "%X" $DIR/$tfile)
510         echo "new atime is $time2"
511
512         [ $time2 -gt $time1 ] || error "atime was not updated"
513         rm -f $DIR1/$tfile || error "rm -f $DIR1/$tfile failed"
514         true
515 }
516 run_test 23 " others should see updated atime while another read===="
517
518 test_24a() {
519         touch $DIR1/$tfile
520         lfs df || error "lfs df failed"
521         lfs df -ih || error "lfs df -ih failed"
522         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
523         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
524         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
525         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
526
527         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
528 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
529         lctl --device %$OSC deactivate
530         lfs df -i || error "lfs df -i with deactivated OSC failed"
531         lctl --device %$OSC activate
532         lfs df || error "lfs df with reactivated OSC failed"
533 }
534 run_test 24a "lfs df [-ih] [path] test ========================="
535
536 test_24b() {
537         touch $DIR1/$tfile
538         fsnum=$(lfs_df | grep -c "summary")
539         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
540 }
541 run_test 24b "lfs df should show both filesystems ==============="
542
543 test_25a() {
544         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
545                                                                 grep -c acl)
546         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
547
548         mkdir -p $DIR1/$tdir
549         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
550         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
551
552         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
553         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
554                 error "setfacl $DIR2/$tdir #1"
555         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
556         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
557                 error "setfacl $DIR2/$tdir #2"
558         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
559         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
560                 error "setfacl $DIR2/$tdir #3"
561         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
562         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
563                 error "setfacl $DIR2/$tdir #4"
564         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
565
566         rm -rf $DIR1/$tdir
567 }
568 run_test 25a "change ACL on one mountpoint be seen on another ==="
569
570 test_25b() {
571         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
572                                                         grep -c acl)
573         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
574
575         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
576
577         rm -rf $DIR1/$tdir
578         $LFS mkdir -i 1 $DIR1/$tdir
579         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
580         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
581
582         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
583         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
584                 error "setfacl $DIR2/$tdir #1"
585         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
586         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
587                 error "setfacl $DIR2/$tdir #2"
588         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
589         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
590                 error "setfacl $DIR2/$tdir #3"
591         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
592         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
593                 error "setfacl $DIR2/$tdir #4"
594         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
595
596         rm -rf $DIR1/$tdir
597 }
598 run_test 25b "change ACL under remote dir on one mountpoint be seen on another"
599
600 test_26a() {
601         utime $DIR1/f26a -s $DIR2/f26a || error
602 }
603 run_test 26a "allow mtime to get older"
604
605 test_26b() {
606         touch $DIR1/$tfile
607         sleep 1
608         echo "aaa" >> $DIR1/$tfile
609         sleep 1
610         chmod a+x $DIR2/$tfile
611         mt1=`stat -c %Y $DIR1/$tfile`
612         mt2=`stat -c %Y $DIR2/$tfile`
613
614         if [ x"$mt1" != x"$mt2" ]; then
615                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
616         fi
617 }
618 run_test 26b "sync mtime between ost and mds"
619
620 test_27() {
621         cancel_lru_locks osc
622         lctl clear
623         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
624         DD2_PID=$!
625         usleep 50
626         log "dd 1 started"
627
628         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
629         DD1_PID=$!
630         log "dd 2 started"
631
632         sleep 1
633         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
634         log "dd 3 finished"
635         lctl set_param -n ldlm.dump_namespaces ""
636         wait $DD1_PID $DD2_PID
637         [ $? -ne 0 ] && lctl dk $TMP/debug || true
638 }
639 run_test 27 "align non-overlapping extent locks from request ==="
640
641 test_28() { # bug 9977
642         ECHO_UUID="ECHO_osc1_UUID"
643         tOST=$($LCTL dl | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -n1)
644
645         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
646         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
647         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
648
649         $LCTL <<-EOF
650                 newdev
651                 attach echo_client ECHO_osc1 $ECHO_UUID
652                 setup $tOST
653         EOF
654
655         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
656         $LCTL --device $tECHOID destroy "${tOBJID}:0"
657
658         $LCTL <<-EOF
659                 cfg_device ECHO_osc1
660                 cleanup
661                 detach
662         EOF
663
664         # reading of 1st stripe should pass
665         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
666         # reading of 2nd stripe should fail (this stripe was destroyed)
667         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
668
669         # now, recreating test file
670         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
671         # reading of 1st stripe should pass
672         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
673         # reading of 2nd stripe should pass
674         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
675 }
676 run_test 28 "read/write/truncate file with lost stripes"
677
678 test_29() { # bug 10999
679         touch $DIR1/$tfile
680         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
681         lctl set_param fail_loc=0x8000030f
682         ls -l $DIR2/$tfile &
683         usleep 500
684         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
685         wait
686 }
687 #bug 11549 - permanently turn test off in b1_5
688 run_test 29 "lock put race between glimpse and enqueue ========="
689
690 test_30() { #bug #11110, LU-2523
691         test_mkdir -p $DIR1/$tdir
692         cp -f /bin/bash $DIR1/$tdir/bash
693         /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash;
694                     cp /bin/bash $DIR2/$tdir' &
695         $DIR1/$tdir/bash -c 'sleep 2;
696                 openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
697         wait
698         true
699 }
700
701 run_test 30 "recreate file race"
702
703 test_31a() {
704         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
705         local writes=$(LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile \
706                        count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}')
707         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
708         lctl set_param fail_loc=0x314
709         local reads=$(LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
710                       awk 'BEGIN { FS="+" } /in/ {print $1}')
711         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
712 }
713 run_test 31a "voluntary cancel / blocking ast race=============="
714
715 test_31b() {
716         remote_ost || { skip "local OST" && return 0; }
717         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
718
719         # make sure there is no local locks due to destroy
720         wait_mds_ost_sync || error "wait_mds_ost_sync()"
721         wait_delete_completed || error "wait_delete_completed()"
722
723         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
724         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
725         cp /etc/hosts $DIR/$tdir/$tfile
726         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
727         lctl set_param fail_loc=0x314
728         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
729         do_facet ost1 lctl set_param fail_loc=0x316
730         # Don't crash kernel
731         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
732         lctl set_param fail_loc=0
733         do_facet ost1 lctl set_param fail_loc=0
734         # cleanup: reconnect the client back
735         df $DIR2
736 }
737 run_test 31b "voluntary OST cancel / blocking ast race=============="
738
739 # enable/disable lockless truncate feature, depending on the arg 0/1
740 enable_lockless_truncate() {
741         lctl set_param -n osc.*.lockless_truncate $1
742 }
743
744 test_32a() { # bug 11270
745         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
746         save_lustre_params client "osc.*.lockless_truncate" > $p
747         cancel_lru_locks osc
748         enable_lockless_truncate 1
749         rm -f $DIR1/$tfile
750         lfs setstripe -c -1 $DIR1/$tfile
751         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$STRIPE_BYTES > \
752                 /dev/null 2>&1
753         clear_stats osc.*.osc_stats
754
755         log "checking cached lockless truncate"
756         $TRUNCATE $DIR1/$tfile 8000000
757         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
758         [ $(calc_stats osc.*.osc_stats lockless_truncate) -ne 0 ] ||
759                 error "cached truncate isn't lockless"
760
761         log "checking not cached lockless truncate"
762         $TRUNCATE $DIR2/$tfile 5000000
763         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
764         [ $(calc_stats osc.*.osc_stats lockless_truncate) -ne 0 ] ||
765                 error "not cached truncate isn't lockless"
766
767         log "disabled lockless truncate"
768         enable_lockless_truncate 0
769         clear_stats osc.*.osc_stats
770         $TRUNCATE $DIR2/$tfile 3000000
771         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
772         [ $(calc_stats osc.*.osc_stats lockless_truncate) -eq 0 ] ||
773                 error "lockless truncate disabling failed"
774         rm $DIR1/$tfile
775         # restore lockless_truncate default values
776         restore_lustre_params < $p
777         rm -f $p
778 }
779 run_test 32a "lockless truncate"
780
781 test_32b() { # bug 11270
782         remote_ost_nodsh && skip "remote OST with nodsh" && return
783
784         local node
785         local facets=$(get_facets OST)
786         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
787
788         save_lustre_params client "osc.*.contention_seconds" > $p
789         save_lustre_params $facets \
790                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
791         save_lustre_params $facets \
792                 "ldlm.namespaces.filter-*.contended_locks" >> $p
793         save_lustre_params $facets \
794                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
795         clear_stats osc.*.osc_stats
796
797         # agressive lockless i/o settings
798         do_nodes $(comma_list $(osts_nodes)) \
799                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
800                         ldlm.namespaces.filter-*.contended_locks=0 \
801                         ldlm.namespaces.filter-*.contention_seconds=60"
802         lctl set_param -n osc.*.contention_seconds=60
803         for i in {1..5}; do
804                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
805                         /dev/null 2>&1
806                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
807                         /dev/null 2>&1
808         done
809         [ $(calc_stats osc.*.osc_stats lockless_write_bytes) -ne 0 ] ||
810                 error "lockless i/o was not triggered"
811         # disable lockless i/o (it is disabled by default)
812         do_nodes $(comma_list $(osts_nodes)) \
813                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
814                         ldlm.namespaces.filter-*.contended_locks=32 \
815                         ldlm.namespaces.filter-*.contention_seconds=0"
816         # set contention_seconds to 0 at client too, otherwise Lustre still
817         # remembers lock contention
818         lctl set_param -n osc.*.contention_seconds=0
819         clear_stats osc.*.osc_stats
820         for i in {1..1}; do
821                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
822                         /dev/null 2>&1
823                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
824                         /dev/null 2>&1
825         done
826         [ $(calc_stats osc.*.osc_stats lockless_write_bytes) -eq 0 ] ||
827                 error "lockless i/o works when disabled"
828         rm -f $DIR1/$tfile
829         restore_lustre_params <$p
830         rm -f $p
831 }
832 run_test 32b "lockless i/o"
833
834 print_jbd_stat () {
835     local dev
836     local mdts=$(get_facets MDS)
837     local varcvs
838     local mds
839
840     local stat=0
841     for mds in ${mdts//,/ }; do
842         varsvc=${mds}_svc
843         dev=$(basename $(do_facet $mds "lctl get_param -n osd*.${!varsvc}.mntdev|\
844                 xargs readlink -f" ))
845         val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info 2>/dev/null |
846                 head -n1")
847         val=${val%% *};
848         stat=$(( stat + val))
849     done
850     echo $stat
851 }
852
853 # commit on sharing tests
854 test_33a() {
855     remote_mds_nodsh && skip "remote MDS with nodsh" && return
856
857     [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS" && return 0
858     [ $CLIENTCOUNT -lt 2 ] &&
859         skip "Need two or more clients, have $CLIENTCOUNT" && return 0
860
861     local nfiles=${TEST33_NFILES:-10000}
862     local param_file=$TMP/$tfile-params
863     local fstype=$(facet_fstype $SINGLEMDS)
864
865         save_lustre_params $(get_facets MDS) \
866                 "mdt.*.commit_on_sharing" > $param_file
867
868     local COS
869     local jbdold="N/A"
870     local jbdnew="N/A"
871     local jbd
872
873     for COS in 0 1; do
874         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
875         avgjbd=0
876         avgtime=0
877         for i in 1 2 3; do
878             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
879
880             [ $fstype = ldiskfs ] && jbdold=$(print_jbd_stat)
881             echo "=== START createmany old: $jbdold transaction"
882             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")
883             [ $fstype = ldiskfs ] && jbdnew=$(print_jbd_stat)
884             [ $fstype = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
885             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
886             [ $fstype = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
887             avgtime=$(( avgtime + elapsed ))
888         done
889         eval cos${COS}_jbd=$((avgjbd / 3))
890         eval cos${COS}_time=$((avgtime / 3))
891     done
892
893     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
894     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
895     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
896     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
897
898     restore_lustre_params < $param_file
899     rm -f $param_file
900     return 0
901 }
902 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
903
904 # commit on sharing tests
905 test_33b() {
906         remote_mds_nodsh && skip "remote MDS with nodsh" && return
907
908         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
909         [ $CLIENTCOUNT -ge 2 ] ||
910                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
911                                                                 return 0; }
912         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
913
914         local nfiles=${TEST33_NFILES:-10000}
915         local param_file=$TMP/$tfile-params
916
917         save_lustre_params $(get_facets MDS) \
918                 "mdt.*.commit_on_sharing" > $param_file
919
920         local COS
921         local jbdold
922         local jbdnew
923         local jbd
924         local MDTIDX=1
925
926         for COS in 0 1; do
927                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
928                 avgjbd=0
929                 avgtime=0
930                 for i in 1 2 3; do
931                         do_node $CLIENT1 "$LFS mkdir -i $MDTIDX \
932                                           $DIR1/$tdir-\\\$(hostname)-$i"
933
934                         jbdold=$(print_jbd_stat)
935                         echo "=== START createmany old: $jbdold transaction"
936                         local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2\
937                                 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- \
938                                 -r$DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > \
939                                                                 /dev/null 2>&1")
940                         jbdnew=$(print_jbd_stat)
941                         jbd=$(( jbdnew - jbdold ))
942                         echo "=== END   createmany new: $jbdnew transaction : \
943                         $jbd transactions nfiles $nfiles time $elapsed COS=$COS"
944                         avgjbd=$(( avgjbd + jbd ))
945                         avgtime=$(( avgtime + elapsed ))
946                 done
947                 eval cos${COS}_jbd=$((avgjbd / 3))
948                 eval cos${COS}_time=$((avgtime / 3))
949         done
950
951         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
952         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
953         [ "$cos0_jbd" != 0 ] &&
954             echo "COS=1 vs COS=0 jbd: $(((cos1_jbd/cos0_jbd - 1) * 100)) %"
955         [ "$cos0_time" != 0 ] &&
956             echo "COS=1 vs COS=0 time: $(((cos1_time/cos0_time - 1) * 100)) %"
957
958         restore_lustre_params < $param_file
959         rm -f $param_file
960         return 0
961 }
962 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
963
964 test_33c() {
965         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
966         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
967                 skip "DNE CoS not supported" && return
968
969         sync
970
971         mkdir $DIR/$tdir
972         # remote mkdir is done on MDT2, which enqueued lock of $tdir on MDT1
973         $LFS mkdir -i 1 $DIR/$tdir/d1
974         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
975         mkdir $DIR/$tdir/d2
976         local sync_count=$(do_facet mds1 \
977                 "lctl get_param -n mdt.*MDT0000.sync_count")
978         [ $sync_count -eq 1 ] || error "Sync-Lock-Cancel not triggered"
979
980         $LFS mkdir -i 1 $DIR/$tdir/d3
981         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
982         # during sleep remote mkdir should have been committed and canceled
983         # remote lock spontaneously, which shouldn't trigger sync
984         sleep 6
985         mkdir $DIR/$tdir/d4
986         local sync_count=$(do_facet mds1 \
987                 "lctl get_param -n mdt.*MDT0000.sync_count")
988         [ $sync_count -eq 0 ] || error "Sync-Lock-Cancel triggered"
989 }
990 run_test 33c "Cancel cross-MDT lock should trigger Sync-Lock-Cancel"
991
992 ops_do_cos() {
993         local nodes=$(comma_list $(mdts_nodes))
994         do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
995         sh -c "$@"
996         local async_commit_count=$(do_nodes $nodes \
997                 "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
998         [ $async_commit_count -gt 0 ] || error "CoS not triggerred"
999
1000         rm -rf $DIR/$tdir
1001         sync
1002 }
1003
1004 test_33d() {
1005         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1006         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1007                 skip "DNE CoS not supported" && return
1008
1009         sync
1010         # remote directory create
1011         mkdir $DIR/$tdir
1012         ops_do_cos "$LFS mkdir -i 1 $DIR/$tdir/subdir"
1013         # remote directory unlink
1014         $LFS mkdir -i 1 $DIR/$tdir
1015         ops_do_cos "rmdir $DIR/$tdir"
1016         # striped directory create
1017         mkdir $DIR/$tdir
1018         ops_do_cos "$LFS mkdir -c 2 $DIR/$tdir/subdir"
1019         # striped directory setattr
1020         $LFS mkdir -c 2 $DIR/$tdir
1021         touch $DIR/$tdir
1022         ops_do_cos "chmod 713 $DIR/$tdir"
1023         # striped directory unlink
1024         $LFS mkdir -c 2 $DIR/$tdir
1025         touch $DIR/$tdir
1026         ops_do_cos "rmdir $DIR/$tdir"
1027         # cross-MDT link
1028         $LFS mkdir -c 2 $DIR/$tdir
1029         $LFS mkdir -i 0 $DIR/$tdir/d1
1030         $LFS mkdir -i 1 $DIR/$tdir/d2
1031         touch $DIR/$tdir/d1/tgt
1032         ops_do_cos "ln $DIR/$tdir/d1/tgt $DIR/$tdir/d2/src"
1033         # cross-MDT rename
1034         $LFS mkdir -c 2 $DIR/$tdir
1035         $LFS mkdir -i 0 $DIR/$tdir/d1
1036         $LFS mkdir -i 1 $DIR/$tdir/d2
1037         touch $DIR/$tdir/d1/src
1038         ops_do_cos "mv $DIR/$tdir/d1/src $DIR/$tdir/d2/tgt"
1039         # migrate
1040         $LFS mkdir -i 0 $DIR/$tdir
1041         ops_do_cos "$LFS migrate -m 1 $DIR/$tdir"
1042         return 0
1043 }
1044 run_test 33d "DNE distributed operation should trigger COS"
1045
1046 test_33e() {
1047         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
1048         [ $CLIENTCOUNT -ge 2 ] ||
1049                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
1050                                                                 return 0; }
1051         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1052         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1053                 skip "DNE CoS not supported" && return
1054
1055         local client2=${CLIENT2:-$(hostname)}
1056
1057         sync
1058
1059         local nodes=$(comma_list $(mdts_nodes))
1060         do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
1061
1062         $LFS mkdir -c 2 $DIR/$tdir
1063         mkdir $DIR/$tdir/subdir
1064         echo abc > $DIR/$tdir/$tfile
1065         do_node $client2 echo dfg >> $DIR/$tdir/$tfile
1066         do_node $client2 touch $DIR/$tdir/subdir
1067
1068         local async_commit_count=$(do_nodes $nodes \
1069                 "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
1070         [ $async_commit_count -gt 0 ] && error "CoS triggerred"
1071
1072         return 0
1073 }
1074 run_test 33e "DNE local operation shouldn't trigger COS"
1075
1076 # End commit on sharing tests
1077
1078 get_ost_lock_timeouts() {
1079     local nodes=${1:-$(comma_list $(osts_nodes))}
1080
1081     local locks=$(do_nodes $nodes \
1082         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
1083
1084     echo $locks
1085 }
1086
1087 cleanup_34() {
1088         local i
1089         trap 0
1090         do_nodes $(comma_list $(osts_nodes)) \
1091                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1092         for i in $(seq $OSTCOUNT); do
1093                 wait_osc_import_state client ost$i FULL
1094         done
1095 }
1096
1097 test_34() { #16129
1098         remote_ost_nodsh && skip "remote OST with nodsh" && return
1099         local OPER
1100         local lock_in
1101         local lock_out
1102         trap cleanup_34 EXIT RETURN
1103         for OPER in notimeout timeout ; do
1104                 rm $DIR1/$tfile 2>/dev/null
1105                 lock_in=$(get_ost_lock_timeouts)
1106                 if [ $OPER == "timeout" ] ; then
1107                         for j in `seq $OSTCOUNT`; do
1108                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
1109                                 do_facet ost$j lctl set_param fail_loc=0x511
1110                         done
1111                         echo lock should expire
1112                 else
1113                         for j in `seq $OSTCOUNT`; do
1114                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
1115                                 do_facet ost$j lctl set_param fail_loc=0x512
1116                         done
1117                         echo lock should not expire
1118                 fi
1119                 echo writing on client1
1120                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
1121                 sync &
1122                 echo reading on client2
1123                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
1124                 # wait for a lock timeout
1125                 sleep 4
1126                 lock_out=$(get_ost_lock_timeouts)
1127                 if [ $OPER == "timeout" ] ; then
1128                         if [ $lock_in == $lock_out ]; then
1129                                 error "no lock timeout happened"
1130                         else
1131                                 echo "success"
1132                         fi
1133                 else
1134                         if [ $lock_in != $lock_out ]; then
1135                                 error "lock timeout happened"
1136                         else
1137                                 echo "success"
1138                         fi
1139                 fi
1140         done
1141         cleanup_34
1142 }
1143 run_test 34 "no lock timeout under IO"
1144
1145 test_35() { # bug 17645
1146         local generation=[]
1147         local count=0
1148         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1149                 awk '/generation/{print $2}')
1150         for g in $gen; do
1151             generation[count]=$g
1152             let count=count+1
1153         done
1154
1155         test_mkdir -p $MOUNT1/$tfile
1156         cancel_lru_locks mdc
1157
1158         # Let's initiate -EINTR situation by setting fail_loc and take
1159         # write lock on same file from same client. This will not cause
1160         # bl_ast yet as lock is already in local cache.
1161 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
1162         do_facet client "lctl set_param fail_loc=0x80000317"
1163         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
1164         let timeout=timeout*3
1165         local nr=0
1166         while test $nr -lt 10; do
1167                 log "Race attempt $nr"
1168                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1169                 test "x$blk1" = "x" && blk1=0
1170                 createmany -o $MOUNT2/$tfile/a 4000 &
1171                 pid1=$!
1172                 sleep 1
1173
1174                 # Let's make conflict and bl_ast
1175                 ls -la $MOUNT1/$tfile > /dev/null &
1176                 pid2=$!
1177
1178                 log "Wait for $pid1 $pid2 for $timeout sec..."
1179                 sleep $timeout
1180                 kill -9 $pid1 $pid2 > /dev/null 2>&1
1181                 wait
1182                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1183                 test "x$blk2" = "x" && blk2=0
1184                 test $blk2 -gt $blk1 && break
1185                 rm -fr $MOUNT1/$tfile/*
1186                 cancel_lru_locks mdc
1187                 let nr=nr+1
1188         done
1189         do_facet client "lctl set_param fail_loc=0x0"
1190         df -h $MOUNT1 $MOUNT2
1191         count=0
1192         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1193                 awk '/generation/{print $2}')
1194         for g in $gen; do
1195             if ! test "$g" -eq "${generation[count]}"; then
1196                 list=$(lctl list_param mdc.$FSNAME-MDT*-mdc-*.import)
1197                 local c = 0
1198                 for imp in $list; do
1199                         if [ $c = $count ]; then
1200                                 break
1201                         fi
1202                         c=c+1
1203                 done
1204                 imp=$(echo "$imp" | awk -F"." '{print $2}')
1205                 error "Eviction happened on import $imp"
1206             fi
1207             let count=count+1
1208         done
1209 }
1210 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
1211
1212 test_36() { #bug 16417
1213         local SIZE
1214         local SIZE_B
1215         local i
1216
1217         test_mkdir -p $DIR1/$tdir
1218         $LFS setstripe -c -1 $DIR1/$tdir
1219         i=0
1220         SIZE=50
1221         let SIZE_B=SIZE*1024*1024
1222         sync; sleep 2; sync # wait for delete thread
1223         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
1224         wait_destroy_complete || error "wait_destroy_complete failed"
1225
1226         while [ $i -le 10 ]; do
1227                 lctl mark "start test - cycle ($i)"
1228                 local before=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1229                 dd if=/dev/zero of=$DIR1/$tdir/$tfile bs=1M count=$SIZE ||
1230                         error "dd $DIR1/$tdir/$tfile ${SIZE}MB failed"
1231                 sync          # sync data from client cache
1232                 sync_all_data # sync data from server cache (delayed allocation)
1233                 sleep 2
1234                 local after_dd=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1235                 multiop_bg_pause $DIR2/$tdir/$tfile O_r${SIZE_B}c || return 3
1236                 read_pid=$!
1237                 rm -f $DIR1/$tdir/$tfile
1238                 kill -USR1 $read_pid
1239                 wait $read_pid
1240                 sync; sleep 2; sync # Ensure new statfs
1241                 wait_delete_completed
1242                 local after=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1243                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
1244                         "after($after)"
1245                 # this free space! not used
1246                 (( $after_dd <= $after)) ||
1247                         error "space leaked after_dd:$after_dd > after:$after"
1248                 let i=i+1
1249         done
1250 }
1251 run_test 36 "handle ESTALE/open-unlink correctly"
1252
1253 test_37() { # bug 18695
1254         test_mkdir -p $DIR1/$tdir
1255         multiop_bg_pause $DIR1/$tdir D_c || return 1
1256         MULTIPID=$!
1257         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
1258         createmany -m $DIR2/$tdir/f 10000
1259         # set mtime/atime backward
1260         touch -t 198001010000 $DIR2/$tdir
1261         kill -USR1 $MULTIPID
1262         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
1263         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
1264
1265 }
1266 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
1267
1268 # this should be set to past
1269 TEST_39_MTIME=`date -d "1 year ago" +%s`
1270
1271 # bug 11063
1272 test_39a() {
1273         local client1=${CLIENT1:-`hostname`}
1274         local client2=${CLIENT2:-`hostname`}
1275
1276         do_node $client1 "touch $DIR1/$tfile"
1277
1278         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
1279         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1280         [ "$mtime1" = $TEST_39_MTIME ] || \
1281                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
1282
1283         local d1=`do_node $client1 date +%s`
1284         do_node $client1 'echo hello >> '$DIR1/$tfile
1285         local d2=`do_node $client1 date +%s`
1286
1287         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1288         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
1289                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1290
1291         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
1292
1293         for (( i=0; i < 2; i++ )) ; do
1294                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
1295                 [ "$mtime2" = "$mtime3" ] || \
1296                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1297
1298                 cancel_lru_locks osc
1299                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1300         done
1301 }
1302 run_test 39a "test from 11063 =================================="
1303
1304 test_39b() {
1305         local client1=${CLIENT1:-`hostname`}
1306         local client2=${CLIENT2:-`hostname`}
1307
1308         touch $DIR1/$tfile
1309
1310         local mtime1=`stat -c %Y $DIR1/$tfile`
1311         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1312
1313         sleep 1
1314         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1315
1316         for (( i=0; i < 2; i++ )) ; do
1317                 local mtime3=`stat -c %Y $DIR1/$tfile`
1318                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1319
1320                 [ "$mtime3" = "$mtime4" ] || \
1321                         error "different mtime on clients: $mtime3, $mtime4"
1322                 [ "$mtime3" = $TEST_39_MTIME ] || \
1323                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1324
1325                 cancel_lru_locks osc
1326                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1327         done
1328 }
1329 run_test 39b "11063 problem 1 =================================="
1330
1331 test_39c() {
1332         local client1=${CLIENT1:-`hostname`}
1333         local client2=${CLIENT2:-`hostname`}
1334
1335         echo hello > $DIR1/$tfile
1336
1337         local mtime1=`stat -c %Y $DIR1/$tfile`
1338         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1339         [ "$mtime1" = "$mtime2" ] || \
1340                 error "create: different mtime on clients: $mtime1, $mtime2"
1341
1342         sleep 1
1343         $TRUNCATE $DIR1/$tfile 1
1344
1345         for (( i=0; i < 2; i++ )) ; do
1346                 local mtime3=`stat -c %Y $DIR1/$tfile`
1347                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1348
1349                 [ "$mtime3" = "$mtime4" ] || \
1350                         error "different mtime on clients: $mtime3, $mtime4"
1351                 [ "$mtime3" -gt $mtime2 ] || \
1352                         error "truncate did not update mtime: $mtime2, $mtime3"
1353
1354                 cancel_lru_locks osc
1355                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1356         done
1357 }
1358 run_test 39c "check truncate mtime update ======================"
1359
1360 test_39d() { # LU-7310
1361         touch $DIR1/$tfile
1362         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1363
1364         local mtime1=$(stat -c %Y $DIR2/$tfile)
1365         [ "$mtime1" = $TEST_39_MTIME ] ||
1366                 error "mtime: $mtime1, should be $TEST_39_MTIME"
1367
1368         # force sync write
1369         # define OBD_FAIL_OSC_NO_GRANT 0x411
1370         $LCTL set_param fail_loc=0x411
1371
1372         local d1=$(date +%s)
1373         echo hello >> $DIR1/$tfile
1374         local d2=$(date +%s)
1375
1376         $LCTL set_param fail_loc=0
1377
1378         cancel_lru_locks osc
1379
1380         local mtime2=$(stat -c %Y $DIR2/$tfile)
1381         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] ||
1382                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1383 }
1384 run_test 39d "sync write should update mtime"
1385
1386 # check that pid exists hence second operation wasn't blocked by first one
1387 # if it is so then there is no conflict, return 0
1388 # else second operation is conflicting with first one, return 1
1389 check_pdo_conflict() {
1390         local pid=$1
1391         local conflict=0
1392         sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
1393         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1394                 conflict=1
1395                 echo "Conflict"
1396         else
1397                 echo "No conflict"
1398         fi
1399         return $conflict
1400 }
1401
1402 # pdirop tests
1403 # test 40: check non-blocking operations
1404 test_40a() {
1405         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1406 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1407         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1408         touch $DIR2
1409         mkdir $DIR1/$tfile &
1410         PID1=$!
1411         sleep 1
1412         touch $DIR2/$tfile-2
1413         check_pdo_conflict $PID1 || error "create is blocked"
1414         mkdir $DIR2/$tfile-3
1415         check_pdo_conflict $PID1 || error "mkdir is blocked"
1416         link $DIR2/$tfile-2 $DIR2/$tfile-4
1417         check_pdo_conflict $PID1 || error "link is blocked"
1418         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1419         check_pdo_conflict $PID1 || error "rename is blocked"
1420         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1421         check_pdo_conflict $PID1 || error "getattr is blocked"
1422         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1423         rmdir $DIR2/$tfile-3
1424         check_pdo_conflict $PID1 || error "unlink is blocked"
1425
1426         #  all operations above shouldn't wait the first one
1427         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1428         wait $PID1
1429         rm -rf $DIR/$tfile*
1430         return 0
1431 }
1432 run_test 40a "pdirops: create vs others =============="
1433
1434 test_40b() {
1435         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1436 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1437         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1438         touch $DIR1/$tfile &
1439         PID1=$!
1440         sleep 1
1441         # open|create
1442         touch $DIR2/$tfile-2
1443         check_pdo_conflict $PID1 || error "create is blocked"
1444         mkdir $DIR2/$tfile-3
1445         check_pdo_conflict $PID1 || error "mkdir is blocked"
1446         link $DIR2/$tfile-2 $DIR2/$tfile-4
1447         check_pdo_conflict $PID1 || error "link is blocked"
1448         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1449         check_pdo_conflict $PID1 || error "rename is blocked"
1450         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1451         check_pdo_conflict $PID1 || error "getattr is blocked"
1452         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1453         rmdir $DIR2/$tfile-3
1454         check_pdo_conflict $PID1 || error "unlink is blocked"
1455         # all operations above shouldn't wait the first one
1456
1457         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1458         wait $PID1
1459         rm -rf $DIR/$tfile*
1460         return 0
1461 }
1462 run_test 40b "pdirops: open|create and others =============="
1463
1464 test_40c() {
1465         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1466         touch $DIR1/$tfile
1467 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1468         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1469         link $DIR1/$tfile $DIR1/$tfile-0 &
1470         PID1=$!
1471         sleep 1
1472         # open|create
1473         touch $DIR2/$tfile-2
1474         check_pdo_conflict $PID1 || error "create is blocked"
1475         mkdir $DIR2/$tfile-3
1476         check_pdo_conflict $PID1 || error "mkdir is blocked"
1477         link $DIR2/$tfile-2 $DIR2/$tfile-4
1478         check_pdo_conflict $PID1 || error "link is blocked"
1479         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1480         check_pdo_conflict $PID1 || error "rename is blocked"
1481         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1482         check_pdo_conflict $PID1 || error "getattr is blocked"
1483         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1484         rmdir $DIR2/$tfile-3
1485         check_pdo_conflict $PID1 || error "unlink is blocked"
1486
1487         # all operations above shouldn't wait the first one
1488         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1489         wait $PID1
1490         rm -rf $DIR/$tfile*
1491         return 0
1492 }
1493 run_test 40c "pdirops: link and others =============="
1494
1495 test_40d() {
1496         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1497         touch $DIR1/$tfile
1498 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1499         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1500         rm $DIR1/$tfile &
1501         PID1=$!
1502         sleep 1
1503         # open|create
1504         touch $DIR2/$tfile-2
1505         check_pdo_conflict $PID1 || error "create is blocked"
1506         mkdir $DIR2/$tfile-3
1507         check_pdo_conflict $PID1 || error "mkdir is blocked"
1508         link $DIR2/$tfile-2 $DIR2/$tfile-4
1509         check_pdo_conflict $PID1 || error "link is blocked"
1510         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1511         check_pdo_conflict $PID1 || error "rename is blocked"
1512         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1513         check_pdo_conflict $PID1 || error "getattr is blocked"
1514         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1515         rmdir $DIR2/$tfile-3
1516         check_pdo_conflict $PID1 || error "unlink is blocked"
1517
1518         # all operations above shouldn't wait the first one
1519         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1520         wait $PID1
1521         return 0
1522 }
1523 run_test 40d "pdirops: unlink and others =============="
1524
1525 test_40e() {
1526         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1527         touch $DIR1/$tfile
1528 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1529         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1530         mv $DIR1/$tfile $DIR1/$tfile-0 &
1531         PID1=$!
1532         sleep 1
1533         # open|create
1534         touch $DIR2/$tfile-2
1535         check_pdo_conflict $PID1 || error "create is blocked"
1536         mkdir $DIR2/$tfile-3
1537         check_pdo_conflict $PID1 || error "mkdir is blocked"
1538         link $DIR2/$tfile-2 $DIR2/$tfile-4
1539         check_pdo_conflict $PID1 || error "link is blocked"
1540         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1541         check_pdo_conflict $PID1 || error "getattr is blocked"
1542         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1543         rmdir $DIR2/$tfile-3
1544         check_pdo_conflict $PID1 || error "unlink is blocked"
1545
1546        # all operations above shouldn't wait the first one
1547         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1548         wait $PID1
1549         rm -rf $DIR/$tfile*
1550         return 0
1551 }
1552 run_test 40e "pdirops: rename and others =============="
1553
1554 # test 41: create blocking operations
1555 test_41a() {
1556 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1557         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1558         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1559         PID1=$!
1560         sleep 1
1561         mkdir $DIR2/$tfile && error "mkdir must fail"
1562         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1563         rm -rf $DIR/$tfile*
1564         return 0
1565 }
1566 run_test 41a "pdirops: create vs mkdir =============="
1567
1568 test_41b() {
1569 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1570         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1571         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1572         PID1=$!
1573         sleep 1
1574         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1575         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1576         rm -rf $DIR/$tfile*
1577         return 0
1578 }
1579 run_test 41b "pdirops: create vs create =============="
1580
1581 test_41c() {
1582         touch $DIR1/$tfile-2
1583 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1584         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1585         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1586         PID1=$!
1587         sleep 1
1588         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1589         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1590         rm -rf $DIR/$tfile*
1591         return 0
1592 }
1593 run_test 41c "pdirops: create vs link =============="
1594
1595 test_41d() {
1596 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1597         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1598         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1599         PID1=$!
1600         sleep 1
1601         rm $DIR2/$tfile || error "unlink must succeed"
1602         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1603         rm -rf $DIR/$tfile*
1604         return 0
1605 }
1606 run_test 41d "pdirops: create vs unlink =============="
1607
1608 test_41e() {
1609         touch $DIR1/$tfile-2
1610 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1611         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1612         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1613         PID1=$!
1614         sleep 1
1615         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1616         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1617         rm -rf $DIR/$tfile*
1618         return 0
1619 }
1620 run_test 41e "pdirops: create and rename (tgt) =============="
1621
1622 test_41f() {
1623 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1624         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1625         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1626         PID1=$!
1627         sleep 1
1628         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1629         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1630         rm -rf $DIR/$tfile*
1631         return 0
1632 }
1633 run_test 41f "pdirops: create and rename (src) =============="
1634
1635 test_41g() {
1636 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1637         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1638         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1639         PID1=$!
1640         sleep 1
1641         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1642         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1643         rm -rf $DIR/$tfile*
1644         return 0
1645 }
1646 run_test 41g "pdirops: create vs getattr =============="
1647
1648 test_41h() {
1649 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1650         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1651         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1652         PID1=$!
1653         sleep 1
1654         ls -lia $DIR2/ > /dev/null
1655         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1656         rm -rf $DIR/$tfile*
1657         return 0
1658 }
1659 run_test 41h "pdirops: create vs readdir =============="
1660
1661 # test 42: unlink and blocking operations
1662 test_42a() {
1663 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1664         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1665         mkdir $DIR1/$tfile &
1666         PID1=$!
1667         sleep 1
1668         mkdir $DIR2/$tfile && error "mkdir must fail"
1669         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1670         rm -rf $DIR/$tfile*
1671         return 0
1672 }
1673 run_test 42a "pdirops: mkdir vs mkdir =============="
1674
1675 test_42b() {
1676 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1677         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1678         mkdir $DIR1/$tfile &
1679         PID1=$!
1680         sleep 1
1681         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1682         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1683         rm -rf $DIR/$tfile*
1684         return 0
1685 }
1686 run_test 42b "pdirops: mkdir vs create =============="
1687
1688 test_42c() {
1689         touch $DIR1/$tfile-2
1690 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1691         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1692         mkdir $DIR1/$tfile &
1693         PID1=$!
1694         sleep 1
1695         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1696         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1697         rm -rf $DIR/$tfile*
1698         return 0
1699 }
1700 run_test 42c "pdirops: mkdir vs link =============="
1701
1702 test_42d() {
1703 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1704         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1705         mkdir $DIR1/$tfile &
1706         PID1=$!
1707         sleep 1
1708         rmdir $DIR2/$tfile || error "unlink must succeed"
1709         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1710         rm -rf $DIR/$tfile*
1711         return 0
1712 }
1713 run_test 42d "pdirops: mkdir vs unlink =============="
1714
1715 test_42e() {
1716         touch $DIR1/$tfile-2
1717 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1718         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1719         mkdir $DIR1/$tfile &
1720         PID1=$!
1721         sleep 1
1722         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1723         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1724         rm -rf $DIR/$tfile*
1725         return 0
1726 }
1727 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1728
1729 test_42f() {
1730 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1731         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1732         mkdir $DIR1/$tfile &
1733         PID1=$!
1734         sleep 1
1735         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1736         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1737         rm -rf $DIR/$tfile*
1738         return 0
1739 }
1740 run_test 42f "pdirops: mkdir and rename (src) =============="
1741
1742 test_42g() {
1743 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1744         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1745         mkdir $DIR1/$tfile &
1746         PID1=$!
1747         sleep 1
1748         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1749         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1750         rm -rf $DIR/$tfile*
1751         return 0
1752 }
1753 run_test 42g "pdirops: mkdir vs getattr =============="
1754
1755 test_42h() {
1756 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1757         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1758         mkdir $DIR1/$tfile &
1759         PID1=$!
1760         sleep 1
1761         ls -lia $DIR2/ > /dev/null
1762         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1763         rm -rf $DIR/$tfile*
1764         return 0
1765 }
1766 run_test 42h "pdirops: mkdir vs readdir =============="
1767
1768 # test 43: unlink and blocking operations
1769 test_43a() {
1770         touch $DIR1/$tfile
1771 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1772         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1773         rm $DIR1/$tfile &
1774         PID1=$!
1775         sleep 1
1776         mkdir $DIR2/$tfile || error "mkdir must succeed"
1777         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1778         rm -rf $DIR/$tfile*
1779         return 0
1780 }
1781 run_test 43a "pdirops: unlink vs mkdir =============="
1782
1783 test_43b() {
1784         touch $DIR1/$tfile
1785 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1786         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1787         rm $DIR1/$tfile &
1788         PID1=$!
1789         sleep 1
1790         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1791         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1792         rm -rf $DIR/$tfile*
1793         return 0
1794 }
1795 run_test 43b "pdirops: unlink vs create =============="
1796
1797 test_43c() {
1798         touch $DIR1/$tfile
1799         touch $DIR1/$tfile-2
1800 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1801         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1802         rm $DIR1/$tfile &
1803         PID1=$!
1804         sleep 1
1805         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1806         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1807         rm -rf $DIR/$tfile*
1808         return 0
1809 }
1810 run_test 43c "pdirops: unlink vs link =============="
1811
1812 test_43d() {
1813         touch $DIR1/$tfile
1814 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1815         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1816         rm $DIR1/$tfile &
1817         PID1=$!
1818         sleep 1
1819         rm $DIR2/$tfile && error "unlink must fail"
1820         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1821         rm -rf $DIR/$tfile*
1822         return 0
1823 }
1824 run_test 43d "pdirops: unlink vs unlink =============="
1825
1826 test_43e() {
1827         touch $DIR1/$tfile
1828         touch $DIR1/$tfile-2
1829 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1830         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1831         rm $DIR1/$tfile &
1832         PID1=$!
1833         sleep 1
1834         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1835         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1836         rm -rf $DIR/$tfile*
1837         return 0
1838 }
1839 run_test 43e "pdirops: unlink and rename (tgt) =============="
1840
1841 test_43f() {
1842         touch $DIR1/$tfile
1843 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1844         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1845         rm $DIR1/$tfile &
1846         PID1=$!
1847         sleep 1
1848         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1849         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1850         rm -rf $DIR/$tfile*
1851         return 0
1852 }
1853 run_test 43f "pdirops: unlink and rename (src) =============="
1854
1855 test_43g() {
1856         touch $DIR1/$tfile
1857 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1858         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1859         rm $DIR1/$tfile &
1860         PID1=$!
1861         sleep 1
1862         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1863         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1864         rm -rf $DIR/$tfile*
1865         return 0
1866 }
1867 run_test 43g "pdirops: unlink vs getattr =============="
1868
1869 test_43h() {
1870         touch $DIR1/$tfile
1871 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1872         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1873         rm $DIR1/$tfile &
1874         PID1=$!
1875         sleep 1
1876         ls -lia $DIR2/ > /dev/null
1877         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1878         rm -rf $DIR/$tfile*
1879         return 0
1880 }
1881 run_test 43h "pdirops: unlink vs readdir =============="
1882
1883 test_43i() {
1884         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1885         touch $DIR1/$tfile
1886 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1887         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1888         rm $DIR1/$tfile &
1889         PID1=$!
1890         sleep 1
1891         $LFS mkdir -i 1 $DIR2/$tfile || error "remote mkdir must succeed"
1892         check_pdo_conflict $PID1 &&
1893                 { wait $PID1; error "remote mkdir isn't blocked"; }
1894         rm -rf $DIR/$tfile*
1895         return 0
1896 }
1897 run_test 43i "pdirops: unlink vs remote mkdir"
1898
1899 # test 44: rename tgt and blocking operations
1900 test_44a() {
1901         touch $DIR1/$tfile-2
1902 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1903         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1904         mv $DIR1/$tfile-2 $DIR1/$tfile &
1905         PID1=$!
1906         sleep 1
1907         mkdir $DIR2/$tfile && error "mkdir must fail"
1908         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1909         rm -rf $DIR/$tfile*
1910         return 0
1911 }
1912 run_test 44a "pdirops: rename tgt vs mkdir =============="
1913
1914 test_44b() {
1915         touch $DIR1/$tfile-2
1916 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1917         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1918         mv $DIR1/$tfile-2 $DIR1/$tfile &
1919         PID1=$!
1920         sleep 1
1921         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1922         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1923         rm -rf $DIR/$tfile*
1924         return 0
1925 }
1926 run_test 44b "pdirops: rename tgt vs create =============="
1927
1928 test_44c() {
1929         touch $DIR1/$tfile-2
1930         touch $DIR1/$tfile-3
1931 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1932         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1933         mv $DIR1/$tfile-2 $DIR1/$tfile &
1934         PID1=$!
1935         sleep 1
1936         link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
1937         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1938         rm -rf $DIR/$tfile*
1939         return 0
1940 }
1941 run_test 44c "pdirops: rename tgt vs link =============="
1942
1943 test_44d() {
1944         touch $DIR1/$tfile-2
1945 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1946         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1947         mv $DIR1/$tfile-2 $DIR1/$tfile &
1948         PID1=$!
1949         sleep 1
1950         rm $DIR2/$tfile || error "unlink must succeed"
1951         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1952         rm -rf $DIR/$tfile*
1953         return 0
1954 }
1955 run_test 44d "pdirops: rename tgt vs unlink =============="
1956
1957 test_44e() {
1958         touch $DIR1/$tfile
1959         touch $DIR1/$tfile-2
1960         touch $DIR1/$tfile-3
1961 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1962         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1963         mv $DIR1/$tfile-2 $DIR1/$tfile &
1964         PID1=$!
1965         sleep 1
1966         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1967         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1968         rm -rf $DIR/$tfile*
1969         return 0
1970 }
1971 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
1972
1973 test_44f() {
1974         touch $DIR1/$tfile-2
1975         touch $DIR1/$tfile-3
1976 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1977         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1978         mv $DIR1/$tfile-2 $DIR1/$tfile &
1979         PID1=$!
1980         sleep 1
1981         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1982         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1983         rm -rf $DIR/$tfile*
1984         return 0
1985 }
1986 run_test 44f "pdirops: rename tgt and rename (src) =============="
1987
1988 test_44g() {
1989         touch $DIR1/$tfile-2
1990 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1991         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1992         mv $DIR1/$tfile-2 $DIR1/$tfile &
1993         PID1=$!
1994         sleep 1
1995         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1996         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1997         rm -rf $DIR/$tfile*
1998         return 0
1999 }
2000 run_test 44g "pdirops: rename tgt vs getattr =============="
2001
2002 test_44h() {
2003         touch $DIR1/$tfile-2
2004 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2005         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2006         mv $DIR1/$tfile-2 $DIR1/$tfile &
2007         PID1=$!
2008         sleep 1
2009         ls -lia $DIR2/ > /dev/null
2010         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2011         rm -rf $DIR/$tfile*
2012         return 0
2013 }
2014 run_test 44h "pdirops: rename tgt vs readdir =============="
2015
2016 # test 44: rename tgt and blocking operations
2017 test_44i() {
2018         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2019         touch $DIR1/$tfile-2
2020 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2021         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2022         mv $DIR1/$tfile-2 $DIR1/$tfile &
2023         PID1=$!
2024         sleep 1
2025         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
2026         check_pdo_conflict $PID1 && { wait $PID1;
2027                                 error "remote mkdir isn't blocked"; }
2028         rm -rf $DIR/$tfile*
2029         return 0
2030 }
2031 run_test 44i "pdirops: rename tgt vs remote mkdir"
2032
2033 # test 45: rename src and blocking operations
2034 test_45a() {
2035         touch $DIR1/$tfile
2036 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2037         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2038         mv $DIR1/$tfile $DIR1/$tfile-2 &
2039         PID1=$!
2040         sleep 1
2041         mkdir $DIR2/$tfile || error "mkdir must succeed"
2042         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2043         rm -rf $DIR/$tfile*
2044         return 0
2045 }
2046 run_test 45a "pdirops: rename src vs mkdir =============="
2047
2048 test_45b() {
2049         touch $DIR1/$tfile
2050 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2051         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2052         mv $DIR1/$tfile $DIR1/$tfile-2 &
2053         PID1=$!
2054         sleep 1
2055         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
2056         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2057         rm -rf $DIR/$tfile*
2058         return 0
2059 }
2060 run_test 45b "pdirops: rename src vs create =============="
2061
2062 test_45c() {
2063         touch $DIR1/$tfile
2064         touch $DIR1/$tfile-3
2065 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2066         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2067         mv $DIR1/$tfile $DIR1/$tfile-2 &
2068         PID1=$!
2069         sleep 1
2070         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
2071         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2072         rm -rf $DIR/$tfile*
2073         return 0
2074 }
2075 run_test 45c "pdirops: rename src vs link =============="
2076
2077 test_45d() {
2078         touch $DIR1/$tfile
2079 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2080         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2081         mv $DIR1/$tfile $DIR1/$tfile-2 &
2082         PID1=$!
2083         sleep 1
2084         rm $DIR2/$tfile && error "unlink must fail"
2085         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2086         rm -rf $DIR/$tfile*
2087         return 0
2088 }
2089 run_test 45d "pdirops: rename src vs unlink =============="
2090
2091 test_45e() {
2092         touch $DIR1/$tfile
2093         touch $DIR1/$tfile-3
2094 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2095         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2096         mv $DIR1/$tfile $DIR1/$tfile-2 &
2097         PID1=$!
2098         sleep 1
2099         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2100         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2101         rm -rf $DIR/$tfile*
2102         return 0
2103 }
2104 run_test 45e "pdirops: rename src and rename (tgt) =============="
2105
2106 test_45f() {
2107         touch $DIR1/$tfile
2108 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2109         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2110         mv $DIR1/$tfile $DIR1/$tfile-2 &
2111         PID1=$!
2112         sleep 1
2113         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
2114         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2115         rm -rf $DIR/$tfile*
2116         return 0
2117 }
2118 run_test 45f "pdirops: rename src and rename (src) =============="
2119
2120 test_45g() {
2121         touch $DIR1/$tfile
2122 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2123         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2124         mv $DIR1/$tfile $DIR1/$tfile-2 &
2125         PID1=$!
2126         sleep 1
2127         stat $DIR2/$tfile > /dev/null && error "stat must fail"
2128         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2129         rm -rf $DIR/$tfile*
2130         return 0
2131 }
2132 run_test 45g "pdirops: rename src vs getattr =============="
2133
2134 test_45h() {
2135         touch $DIR1/$tfile
2136 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2137         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2138         mv $DIR1/$tfile $DIR1/$tfile-2 &
2139         PID1=$!
2140         sleep 1
2141         ls -lia $DIR2/ > /dev/null
2142         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2143         rm -rf $DIR/$tfile*
2144         return 0
2145 }
2146 run_test 45h "pdirops: unlink vs readdir =============="
2147
2148 test_45i() {
2149         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2150         touch $DIR1/$tfile
2151 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2152         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2153         mv $DIR1/$tfile $DIR1/$tfile-2 &
2154         PID1=$!
2155         sleep 1
2156         $LFS mkdir -i 1 $DIR2/$tfile || error "create remote dir must succeed"
2157         check_pdo_conflict $PID1 && { wait $PID1;
2158                                 error "create remote dir isn't blocked"; }
2159         rm -rf $DIR/$tfile*
2160         return 0
2161 }
2162 run_test 45i "pdirops: rename src vs remote mkdir"
2163
2164 # test 46: link and blocking operations
2165 test_46a() {
2166         touch $DIR1/$tfile-2
2167 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2168         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2169         link $DIR1/$tfile-2 $DIR1/$tfile &
2170         PID1=$!
2171         sleep 1
2172         mkdir $DIR2/$tfile && error "mkdir must fail"
2173         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2174         rm -rf $DIR/$tfile*
2175         return 0
2176 }
2177 run_test 46a "pdirops: link vs mkdir =============="
2178
2179 test_46b() {
2180         touch $DIR1/$tfile-2
2181 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2182         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2183         link $DIR1/$tfile-2 $DIR1/$tfile &
2184         PID1=$!
2185         sleep 1
2186         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2187         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2188         rm -rf $DIR/$tfile*
2189         return 0
2190 }
2191 run_test 46b "pdirops: link vs create =============="
2192
2193 test_46c() {
2194         touch $DIR1/$tfile-2
2195 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2196         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2197         link $DIR1/$tfile-2 $DIR1/$tfile &
2198         PID1=$!
2199         sleep 1
2200         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
2201         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2202         rm -rf $DIR/$tfile*
2203         return 0
2204 }
2205 run_test 46c "pdirops: link vs link =============="
2206
2207 test_46d() {
2208         touch $DIR1/$tfile-2
2209 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2210         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2211         link $DIR1/$tfile-2 $DIR1/$tfile &
2212         PID1=$!
2213         sleep 1
2214         rm $DIR2/$tfile || error "unlink must succeed"
2215         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2216         rm -rf $DIR/$tfile*
2217         return 0
2218 }
2219 run_test 46d "pdirops: link vs unlink =============="
2220
2221 test_46e() {
2222         touch $DIR1/$tfile-2
2223         touch $DIR1/$tfile-3
2224 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2225         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2226         link $DIR1/$tfile-2 $DIR1/$tfile &
2227         PID1=$!
2228         sleep 1
2229         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2230         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2231         rm -rf $DIR/$tfile*
2232         return 0
2233 }
2234 run_test 46e "pdirops: link and rename (tgt) =============="
2235
2236 test_46f() {
2237         touch $DIR1/$tfile-2
2238         touch $DIR1/$tfile-3
2239 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2240         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2241         link $DIR1/$tfile-2 $DIR1/$tfile &
2242         PID1=$!
2243         sleep 1
2244         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
2245         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2246         rm -rf $DIR/$tfile*
2247         return 0
2248 }
2249 run_test 46f "pdirops: link and rename (src) =============="
2250
2251 test_46g() {
2252         touch $DIR1/$tfile-2
2253 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2254         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2255         link $DIR1/$tfile-2 $DIR1/$tfile &
2256         PID1=$!
2257         sleep 1
2258         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2259         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2260         rm -rf $DIR/$tfile*
2261         return 0
2262 }
2263 run_test 46g "pdirops: link vs getattr =============="
2264
2265 test_46h() {
2266         touch $DIR1/$tfile-2
2267 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2268         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2269         link $DIR1/$tfile-2 $DIR1/$tfile &
2270         PID1=$!
2271         sleep 1
2272         ls -lia $DIR2/ > /dev/null
2273         check_pdo_conflict $PID1 && { wait $PID1;
2274                         error "readdir isn't blocked"; }
2275         rm -rf $DIR/$tfile*
2276         return 0
2277 }
2278 run_test 46h "pdirops: link vs readdir =============="
2279
2280 test_46i() {
2281         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2282         touch $DIR1/$tfile-2
2283 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2284         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2285         link $DIR1/$tfile-2 $DIR1/$tfile &
2286         PID1=$!
2287         sleep 1
2288         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
2289         check_pdo_conflict $PID1 && { wait $PID1;
2290                                 error "remote mkdir isn't blocked"; }
2291         rm -rf $DIR/$tfile*
2292         return 0
2293 }
2294 run_test 46i "pdirops: link vs remote mkdir"
2295
2296 # test 47: remote mkdir and blocking operations
2297 test_47a() {
2298 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2299         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2300         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2301         $LFS mkdir -i 1 $DIR1/$tfile &
2302         PID1=$!
2303         sleep 1
2304         mkdir $DIR2/$tfile && error "mkdir must fail"
2305         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2306         rm -rf $DIR/$tfile*
2307         return 0
2308 }
2309 run_test 47a "pdirops: remote mkdir vs mkdir"
2310
2311 test_47b() {
2312 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2313         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2314         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2315         $LFS mkdir -i 1 $DIR1/$tfile &
2316         PID1=$!
2317         sleep 1
2318         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2319         check_pdo_conflict $PID1 && { wait $PID1;
2320                                         error "create isn't blocked"; }
2321         rm -rf $DIR/$tfile*
2322         return 0
2323 }
2324 run_test 47b "pdirops: remote mkdir vs create"
2325
2326 test_47c() {
2327         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2328         touch $DIR1/$tfile-2
2329 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2330         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2331         $LFS mkdir -i 1 $DIR1/$tfile &
2332         PID1=$!
2333         sleep 1
2334         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
2335         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2336         rm -rf $DIR/$tfile*
2337         return 0
2338 }
2339 run_test 47c "pdirops: remote mkdir vs link"
2340
2341 test_47d() {
2342         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2343 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2344         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2345         $LFS mkdir -i 1 $DIR1/$tfile &
2346         PID1=$!
2347         sleep 1
2348         rmdir $DIR2/$tfile || error "unlink must succeed"
2349         check_pdo_conflict $PID1 && { wait $PID1;
2350                                         error "unlink isn't blocked"; }
2351         rm -rf $DIR/$tfile*
2352         return 0
2353 }
2354 run_test 47d "pdirops: remote mkdir vs unlink"
2355
2356 test_47e() {
2357         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2358         touch $DIR1/$tfile-2
2359 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2360         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2361         $LFS mkdir -i 1 $DIR1/$tfile &
2362         PID1=$!
2363         sleep 1
2364         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
2365         check_pdo_conflict $PID1 && { wait $PID1;
2366                                         error "rename isn't blocked"; }
2367         rm -rf $DIR/$tfile*
2368         return 0
2369 }
2370 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2371
2372 test_47f() {
2373         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2374 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2375         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2376         $LFS mkdir -i 1 $DIR1/$tfile &
2377         PID1=$!
2378         sleep 1
2379         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
2380         check_pdo_conflict $PID1 && { wait $PID1;
2381                                         error "rename isn't blocked"; }
2382         rm -rf $DIR/$tfile*
2383         return 0
2384 }
2385 run_test 47f "pdirops: remote mkdir and rename (src)"
2386
2387 test_47g() {
2388         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2389 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2390         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2391         $LFS mkdir -i 1 $DIR1/$tfile &
2392         PID1=$!
2393         sleep 1
2394         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2395         check_pdo_conflict $PID1 && { wait $PID1;
2396                                         error "getattr isn't blocked"; }
2397         rm -rf $DIR/$tfile*
2398         return 0
2399 }
2400 run_test 47g "pdirops: remote mkdir vs getattr"
2401
2402 test_50() {
2403         trunc_size=4096
2404         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2405 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2406         do_facet client "lctl set_param fail_loc=0x410"
2407         $TRUNCATE $DIR2/$tfile $trunc_size
2408         do_facet client "lctl set_param fail_loc=0x0"
2409         sleep 3
2410         size=`stat -c %s $DIR2/$tfile`
2411         [ $size -eq $trunc_size ] || error "wrong size"
2412 }
2413 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2414
2415 test_51a() {
2416         local filesize
2417         local origfile=/etc/hosts
2418
2419         filesize=$(stat -c %s $origfile)
2420
2421         # create an empty file
2422         $MCREATE $DIR1/$tfile || error "can't create $DIR1/$tfile"
2423         # cache layout lock on both mount point
2424         stat $DIR1/$tfile > /dev/null || error "stat $DIR1/$tfile failed"
2425         stat $DIR2/$tfile > /dev/null || error "stat $DIR2/$tfile failed"
2426
2427         # open and sleep 2 seconds then read
2428         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2429         local pid=$!
2430         sleep 1
2431
2432         # create the layout of testing file
2433         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null ||
2434                 error "dd $DIR1/$tfile failed"
2435
2436         # MULTIOP proc should be able to read enough bytes and exit
2437         for ((i = 0; i < 6; i++)); do
2438                 sleep 1
2439                 kill -0 $pid || break
2440         done
2441         kill -0 $pid 2> /dev/null && error "multiop is still there"
2442         cmp $origfile $DIR2/$tfile || error "$origfile and $DIR2/$tfile differs"
2443
2444         rm -f $DIR1/$tfile
2445 }
2446 run_test 51a "layout lock: refresh layout should work"
2447
2448 test_51b() {
2449         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2450                 { skip "Need MDS version at least 2.3.59"; return 0; }
2451
2452         local tmpfile=`mktemp`
2453
2454         # create an empty file
2455         $MCREATE $DIR1/$tfile || error "mcreate $DIR1/$tfile failed"
2456
2457         # delay glimpse so that layout has changed when glimpse finish
2458 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2459         $LCTL set_param fail_loc=0x1404
2460         stat -c %s $DIR2/$tfile |tee $tmpfile &
2461         local pid=$!
2462         sleep 1
2463
2464         # create layout of testing file
2465         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc >/dev/null ||
2466                 error "dd $DIR1/$tfile failed"
2467
2468         wait $pid
2469         local fsize=$(cat $tmpfile)
2470
2471         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2472
2473         rm -f $DIR1/$tfile $tmpfile
2474 }
2475 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2476
2477 test_51c() {
2478         [ $OSTCOUNT -ge 2 ] || { skip "needs >= 2 osts"; return; }
2479
2480         # set default layout to have 1 stripe
2481         mkdir $DIR1/$tdir
2482         $LFS setstripe -c 1 $DIR1/$tdir
2483
2484         # create a file with empty layout
2485         $MCREATE $DIR1/$tdir/$tfile ||
2486                 error "$MCREATE $DIR1/$tdir/$tfile failed"
2487
2488 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2489         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
2490
2491         # change the layout of testing file
2492         echo "Setting layout to have $OSTCOUNT stripes ..."
2493         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
2494         pid=$!
2495         sleep 1
2496
2497         # write something to the file, it should be blocked on fetching layout
2498         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
2499         local stripe_count=$($LFS getstripe -c $DIR2/$tdir/$tfile)
2500         wait $pid
2501
2502         # lod_qos.c::min_stripe_count() allows setstripe with a default stripe
2503         # count to succeed with only 3/4 of the number of stripes (rounded up),
2504         # so creating striped files does not fail if an OST is offline or full
2505         [ $stripe_count -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
2506                 error "bad layout: getstripe -c $stripe_count < $OSTCOUNT * 3/4"
2507
2508         rm -fr $DIR1/$tdir
2509 }
2510 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2511
2512 test_51d() {
2513         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
2514         cancel_lru_locks mdc
2515
2516         # open should grant LAYOUT lock, mmap and read will install pages
2517         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
2518         local PID=$!
2519         sleep 1
2520
2521         # rss before revoking
2522         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2523         echo "Before revoking layout lock: $br KB mapped"
2524
2525         # delete the file will revoke layout lock
2526         rm -f $DIR2/$tfile
2527
2528         # rss after revoking
2529         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2530
2531         kill -USR1 $PID
2532         wait $PID || error
2533
2534         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
2535 }
2536 run_test 51d "layout lock: losing layout lock should clean up memory map region"
2537
2538 test_54_part1()
2539 {
2540         echo "==> rename vs getattr vs setxattr should not deadlock"
2541         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2542
2543         do_facet mds1 $LCTL set_param fail_loc=$1
2544
2545         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2546         PID1=$!
2547         sleep 1
2548
2549         stat $DIR/d1/d2 &
2550         PID2=$!
2551         sleep 1
2552
2553         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
2554         wait $PID1 || error "(3) mv failed"
2555         wait $PID2 || error "(4) stat failed"
2556         echo
2557
2558         rm -rf $DIR/d1
2559 }
2560
2561 test_54_part2() {
2562         echo "==> rename vs getattr vs open vs getattr should not deadlock"
2563         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2564
2565         do_facet mds1 $LCTL set_param fail_loc=$1
2566
2567         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2568         PID1=$!
2569         sleep 1
2570
2571         stat $DIR/d1/d2 &
2572         PID2=$!
2573         sleep 1
2574
2575         $MULTIOP $DIR2/d1/d2 Oc &
2576         PID3=$!
2577         sleep 1
2578
2579         stat $DIR/d1 || error "(2) stat failed"
2580
2581         wait $PID1 || error "(3) mv failed"
2582         wait $PID2 || error "(4) stat failed"
2583         wait $PID3 && error "(5) multiop failed"
2584         echo
2585         rm -rf $DIR/d1
2586 }
2587
2588 test_54() {
2589         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2590         save_lustre_params client "llite.*.xattr_cache" > $p
2591         lctl set_param llite.*.xattr_cache 1 ||
2592                 { skip "xattr cache is not supported"; return 0; }
2593
2594 #define OBD_FAIL_MDS_RENAME              0x153
2595 #define OBD_FAIL_MDS_RENAME2             0x154
2596         test_54_part1 0x80000153 || error 10
2597         test_54_part1 0x80000154 || error 11
2598         test_54_part2 0x80000153 || error 12
2599         test_54_part2 0x80000154 || error 13
2600
2601         restore_lustre_params < $p
2602         rm -f $p
2603 }
2604 run_test 54 "rename locking"
2605
2606 test_55a() {
2607         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2608
2609 #define OBD_FAIL_MDS_RENAME4              0x156
2610         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2611
2612         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2613         PID1=$!
2614         sleep 1
2615
2616         rm -r $DIR2/d3
2617         wait $PID1 && error "(2) mv succeeded"
2618
2619         rm -rf $DIR/d1
2620 }
2621 run_test 55a "rename vs unlink target dir"
2622
2623 test_55b()
2624 {
2625         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2626
2627 #define OBD_FAIL_MDS_RENAME4             0x156
2628         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2629
2630         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2631         PID1=$!
2632         sleep 1
2633
2634         rm -r $DIR2/d1
2635         wait $PID1 && error "(2) mv succeeded"
2636
2637         rm -rf $DIR/d3
2638 }
2639 run_test 55b "rename vs unlink source dir"
2640
2641 test_55c()
2642 {
2643         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2644
2645 #define OBD_FAIL_MDS_RENAME4              0x156
2646         do_facet mds1 $LCTL set_param fail_loc=0x156
2647
2648         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2649         PID1=$!
2650         sleep 1
2651
2652         # while rename is sleeping, open and remove d3
2653         $MULTIOP $DIR2/d3 D_c &
2654         PID2=$!
2655         sleep 1
2656         rm -rf $DIR2/d3
2657         sleep 5
2658
2659         # while rename is sleeping 2nd time, close d3
2660         kill -USR1 $PID2
2661         wait $PID2 || error "(3) multiop failed"
2662
2663         wait $PID1 && error "(2) mv succeeded"
2664
2665         rm -rf $DIR/d1
2666 }
2667 run_test 55c "rename vs unlink orphan target dir"
2668
2669 test_55d()
2670 {
2671         touch $DIR/f1
2672
2673 #define OBD_FAIL_MDS_RENAME3              0x155
2674         do_facet mds1 $LCTL set_param fail_loc=0x155
2675         mv $DIR/f1 $DIR/$tdir &
2676         PID1=$!
2677         sleep 2
2678
2679         # while rename is sleeping, create $tdir, but as a directory
2680         mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
2681
2682         # link in reverse locking order
2683         ln $DIR2/f1 $DIR2/$tdir/
2684
2685         wait $PID1 && error "(2) mv succeeded"
2686         rm -rf $DIR/f1
2687 }
2688 run_test 55d "rename file vs link"
2689
2690 test_60() {
2691         local MDSVER=$(lustre_build_version $SINGLEMDS)
2692         [ $(version_code $MDSVER) -lt $(version_code 2.3.0) ] &&
2693                 skip "MDS version $MDSVER must be >= 2.3.0" && return 0
2694
2695         # Create a file
2696         test_mkdir -p $DIR1/$tdir
2697         file1=$DIR1/$tdir/file
2698         file2=$DIR2/$tdir/file
2699
2700         echo orig > $file2 || error "Could not create $file2"
2701         version=$($LFS data_version $file1)
2702
2703         # Append data
2704         echo append >> $file2 || error "Could not append to $file2"
2705         version2=$($LFS data_version $file1)
2706         [ "$version" != "$version2" ] ||
2707             error "append did not change data version: $version"
2708
2709         # Overwrite data
2710         echo overwrite > $file2 || error "Could not overwrite $file2"
2711         version3=$($LFS data_version $file1)
2712         [ "$version2" != "$version3" ] ||
2713             error "overwrite did not change data version: $version2"
2714
2715         # Truncate before EOF
2716         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2717         version4=$($LFS data_version $file1)
2718         [ "$version3" != "$version4" ] ||
2719             error "truncate did not change data version: $version3"
2720
2721         # Truncate after EOF
2722         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2723         version5=$($LFS data_version $file1)
2724         [ "$version4" != "$version5" ] ||
2725             error "truncate did not change data version: $version4"
2726
2727         # Chmod do not change version
2728         chmod 400 $file2 || error "Could not chmod 400 $file2"
2729         version6=$($LFS data_version $file1)
2730         [ "$version5" == "$version6" ] ||
2731             error "chmod should not change data version: $version5 != $version6"
2732
2733         # Chown do not change version
2734         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
2735         version7=$($LFS data_version $file1)
2736         [ "$version5" == "$version7" ] ||
2737             error "chown should not change data version: $version5 != $version7"
2738 }
2739 run_test 60 "Verify data_version behaviour"
2740
2741 test_70a() {
2742         local test_dir=$tdir/test_dir
2743
2744         mkdir -p $DIR1/$tdir
2745         if [ $MDSCOUNT -ge 2 ]; then
2746                 local MDTIDX=1
2747                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
2748                         error "Create remote directory failed"
2749         else
2750                 mkdir -p $DIR1/$test_dir
2751         fi
2752         cd $DIR2/$test_dir || error "cd directory failed"
2753         rm -rf $DIR1/$test_dir || error "unlink directory failed"
2754
2755         cd $DIR2/$tdir || error "exit directory"
2756 }
2757 run_test 70a "cd directory && rm directory"
2758
2759 test_70b() { # LU-2781
2760         local i
2761         mkdir -p $DIR1/$tdir
2762
2763         touch $DIR1/$tdir/file
2764         for ((i = 0; i < 32; i++)); do
2765             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
2766         done
2767         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2768
2769         touch $DIR1/$tdir/file
2770         $LFS mkdir -i0 $DIR1/$tdir/test_dir
2771         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
2772         rm -rf $DIR1/$tdir/test_dir ||
2773                 error "cannot remove directory after rm_entry"
2774         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2775 }
2776 run_test 70b "remove files after calling rm_entry"
2777
2778 test_71a() {
2779         local server_version=$(lustre_version_code $SINGLEMDS)
2780
2781         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2782                 skip "Need MDS version at least 2.1.6" && return
2783
2784         # Patch not applied to 2.2 and 2.3 branches
2785         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2786         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2787                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
2788                         return
2789
2790         checkfiemap --test ||
2791                 { skip "checkfiemap not runnable: $?" && return; }
2792         # write data this way: hole - data - hole - data
2793         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2794         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tfile) + 1)))" = \
2795                 "zfs" ] &&
2796                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
2797         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2798         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
2799         stat $DIR2/$tfile
2800         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2801         echo $can1
2802         checkfiemap $DIR2/$tfile 81920 ||
2803                 error "data is not flushed from client"
2804         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2805         echo $can2
2806
2807         # common case of "create file, copy file" on a single node
2808         # should not flush data from ost
2809         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2810         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2811         stat $DIR1/$tfile
2812         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2813         echo $can3
2814         checkfiemap $DIR1/$tfile 81920 ||
2815         error 4
2816         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2817         echo $can2
2818         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
2819 }
2820 run_test 71a "correct file map just after write operation is finished"
2821
2822 test_71b() {
2823         local server_version=$(lustre_version_code $SINGLEMDS)
2824
2825         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2826                 skip "Need MDS version at least 2.1.6" && return
2827
2828         # Patch not applied to 2.2 and 2.3 branches
2829         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2830         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2831                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
2832                         return
2833         [[ $OSTCOUNT -ge 2 ]] || { skip "needs >= 2 OSTs"; return; }
2834
2835         checkfiemap --test ||
2836                 { skip "error $?: checkfiemap failed" && return; }
2837
2838         mkdir -p $DIR1/$tdir
2839
2840         $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
2841         dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
2842         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tdir/$tfile) + 1)))" = \
2843                 "zfs" ] &&
2844                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
2845         checkfiemap $DIR1/$tdir/$tfile 40960 || error "checkfiemap failed"
2846 }
2847 run_test 71b "check fiemap support for stripecount > 1"
2848
2849 test_72() {
2850         local p="$TMP/sanityN-$TESTNAME.parameters"
2851         local tlink1
2852         local tlink2
2853         save_lustre_params client "llite.*.xattr_cache" > $p
2854         lctl set_param llite.*.xattr_cache 1 ||
2855                 { skip "xattr cache is not supported"; return 0; }
2856
2857         touch $DIR1/$tfile
2858         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2859                 error "setfattr1 failed"
2860         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
2861                 error "getfattr1 failed"
2862         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
2863                 error "setfattr2 failed"
2864         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
2865                 error "getfattr2 failed"
2866
2867         # check that trusted.link is consistent
2868         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2869         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
2870         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2871         echo "$tlink1 $tlink2"
2872         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
2873
2874         rm -f $DIR2/$tfile
2875
2876         restore_lustre_params < $p
2877         rm -f $p
2878 }
2879 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
2880
2881 test_73() {
2882         local p="$TMP/sanityN-$TESTNAME.parameters"
2883         save_lustre_params client "llite.*.xattr_cache" > $p
2884         lctl set_param llite.*.xattr_cache 1 ||
2885                 { skip "xattr cache is not supported"; return 0; }
2886
2887         touch $DIR1/$tfile
2888         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2889                 error "setfattr1 failed"
2890         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
2891         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
2892         clear_stats llite.*.stats
2893         # PR lock should be cached by now on both clients
2894         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
2895         # 2 hits for getfattr(0)+getfattr(size)
2896         [ $(calc_stats llite.*.stats getxattr_hits) -eq 2 ] ||
2897                 error "not cached in $DIR1"
2898         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
2899         # 4 hits for more getfattr(0)+getfattr(size)
2900         [ $(calc_stats llite.*.stats getxattr_hits) -eq 4 ] ||
2901                 error "not cached in $DIR2"
2902         rm -f $DIR2/$tfile
2903
2904         restore_lustre_params < $p
2905         rm -f $p
2906 }
2907 run_test 73 "getxattr should not cause xattr lock cancellation"
2908
2909 test_74() {
2910         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
2911                 skip "Need MDS version at least 2.4.93" && return
2912
2913         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
2914         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
2915         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
2916 }
2917 run_test 74 "flock deadlock: different mounts =============="
2918
2919 # LU-3889
2920 test_75() {
2921         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
2922         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
2923         cancel_lru_locks osc
2924
2925         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
2926         sync
2927
2928         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
2929         $LCTL set_param fail_loc=0x31d
2930         stat -c %s $DIR1/$tfile &
2931         local pid=$!
2932         sleep 1
2933         kill -9 $pid
2934
2935         # For bad lock error handler we should ASSERT and got kernel panic here
2936         sleep 4
2937         $LCTL set_param fail_loc=0
2938 }
2939 run_test 75 "osc: upcall after unuse lock==================="
2940
2941 test_76() { #LU-946
2942         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
2943                 skip "Need MDS version at least 2.5.53" && return
2944
2945         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2946         local fcount=$((MDSCOUNT * 256))
2947         declare -a fd_list
2948         declare -a fid_list
2949
2950         if remote_mds; then
2951                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
2952         else
2953                 nid="0@lo"
2954         fi
2955
2956         rm -rf $DIR/$tdir
2957         test_mkdir -p $DIR/$tdir
2958
2959         # drop all open locks and close any cached "open" files on the client
2960         cancel_lru_locks mdc
2961
2962         local open_fids_cmd="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
2963         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
2964         local already=${#fid_list[@]}
2965         for (( i = 0; i < $already; i++ )) ; do
2966                 log "already open[$i]: $($LFS fid2path $DIR2 ${fid_list[i]})"
2967         done
2968
2969         echo -n "opening files: "
2970         ulimit -n $((fcount + 50))
2971         for ((i = 0; i < $fcount; i++)); do
2972                 touch $DIR/$tdir/f_$i
2973                 local fd=$(free_fd ${fd_list[i]})
2974                 local open_cmd="exec $fd<$DIR/$tdir/f_$i"
2975                 eval $open_cmd
2976
2977                 fd_list[i]=$fd
2978
2979                 (( $i % 32 == 0 )) && echo -n "."
2980         done
2981         echo
2982
2983         fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
2984
2985         # Possible errors in openfiles FID list.
2986         # 1. Missing FIDs. Check 1
2987         # 2. Extra FIDs. Check 1
2988         # 3. Duplicated FID. Check 2
2989         # 4. Invalid FIDs. Check 2
2990         # 5. Valid FID, points to some other file. Check 3
2991
2992         # Check 1
2993         [ ${#fid_list[@]} -ne $((fcount + already)) ] &&
2994                 error "${#fid_list[@]} != $fcount (+$already old) open files"
2995
2996         echo -n "closing files: "
2997         for (( fd = 0, fid = 0; fd < $fcount; fd++, fid++ )) ; do
2998                 local close_cmd="exec ${fd_list[fd]}<&-"
2999                 eval $close_cmd
3000                 filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3001
3002                 while [[ ! "$filename" =~ "$DIR2/$tdir/f_" ]]; do
3003                         echo "skip old open file $filename"
3004                         ((fid++))
3005                         filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3006                 done
3007
3008                 # Check 2
3009                 rm --interactive=no $filename
3010                 [ $? -ne 0 ] &&
3011                         error "Nonexisting fid ${fid_list[fid]} listed."
3012                 (( $fd % 32 == 0 )) && echo -n "."
3013         done
3014         echo
3015
3016         # Check 3
3017         ls_op=$(ls $DIR2/$tdir | wc -l)
3018         [ $ls_op -ne 0 ] &&
3019                 error "Some openfiles are missing in lproc output"
3020
3021         rm -rf $DIR/$tdir
3022 }
3023 run_test 76 "Verify MDT open_files listing"
3024
3025 nrs_write_read() {
3026         local n=16
3027         local dir=$DIR/$tdir
3028         local myRUNAS="$1"
3029
3030         mkdir $dir || error "mkdir $dir failed"
3031         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3032         chmod 777 $dir
3033
3034         do_nodes $CLIENTS $myRUNAS \
3035                 dd if=/dev/zero of="$dir/nrs_r_$HOSTNAME" bs=1M count=$n ||
3036                 error "dd at 0 on client failed (1)"
3037
3038         for ((i = 0; i < $n; i++)); do
3039                 do_nodes $CLIENTS $myRUNAS dd if=/dev/zero \
3040                         of="$dir/nrs_w_$HOSTNAME" bs=1M seek=$i count=1 ||
3041                          error "dd at ${i}MB on client failed (2)" &
3042                 local pids_w[$i]=$!
3043         done
3044         do_nodes $CLIENTS sync;
3045         cancel_lru_locks osc
3046
3047         for ((i = 0; i < $n; i++)); do
3048                 do_nodes $CLIENTS $myRUNAS dd if="$dir/nrs_w_$HOSTNAME" \
3049                         of=/dev/zero bs=1M seek=$i count=1 > /dev/null ||
3050                         error "dd at ${i}MB on client failed (3)" &
3051                 local pids_r[$i]=$!
3052         done
3053         cancel_lru_locks osc
3054
3055         for ((i = 0; i < $n; i++)); do
3056                 wait ${pids_w[$i]}
3057                 wait ${pids_r[$i]}
3058         done
3059         rm -rf $dir || error "rm -rf $dir failed"
3060 }
3061
3062 test_77a() { #LU-3266
3063         oss=$(comma_list $(osts_nodes))
3064         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo"
3065         nrs_write_read
3066
3067         return 0
3068 }
3069 run_test 77a "check FIFO NRS policy"
3070
3071 test_77b() { #LU-3266
3072         oss=$(comma_list $(osts_nodes))
3073
3074         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3075                            ost.OSS.*.nrs_crrn_quantum=1
3076
3077         echo "policy: crr-n, crrn_quantum 1"
3078         nrs_write_read
3079
3080         do_nodes $oss lctl set_param ost.OSS.*.nrs_crrn_quantum=64
3081
3082         echo "policy: crr-n, crrn_quantum 64"
3083         nrs_write_read
3084
3085         # cleanup
3086         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3087         return 0
3088 }
3089 run_test 77b "check CRR-N NRS policy"
3090
3091 orr_trr() {
3092         local policy=$1
3093
3094         oss=$(comma_list $(osts_nodes))
3095
3096         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3097                                      ost.OSS.*.nrs_"$policy"_quantum=1 \
3098                                      ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3099                                      ost.OSS.*.nrs_"$policy"_supported="reads"
3100
3101         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type physical, ${policy}_supported reads"
3102         nrs_write_read
3103
3104         do_nodes $oss lctl set_param ost.OSS.*.nrs_${policy}_supported="writes" \
3105                                      ost.OSS.*.nrs_${policy}_quantum=64
3106
3107         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type physical, ${policy}_supported writes"
3108         nrs_write_read
3109
3110         do_nodes $oss lctl set_param ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3111                                      ost.OSS.*.nrs_${policy}_offset_type="logical"
3112         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type logical, ${policy}_supported reads_and_writes"
3113         nrs_write_read
3114
3115         # cleanup
3116         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3117         return 0
3118 }
3119
3120 test_77c() { #LU-3266
3121         orr_trr "orr"
3122         return 0
3123 }
3124 run_test 77c "check ORR NRS policy"
3125
3126 test_77d() { #LU-3266
3127         orr_trr "trr"
3128         return 0
3129 }
3130 run_test 77d "check TRR nrs policy"
3131
3132 tbf_rule_operate()
3133 {
3134         local facet=$1
3135         shift 1
3136
3137         do_facet $facet lctl set_param \
3138                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3139         [ $? -ne 0 ] &&
3140                 error "failed to run operate '$*' on TBF rules"
3141 }
3142
3143 cleanup_tbf_verify()
3144 {
3145         local rc=0
3146         trap 0
3147         echo "cleanup_tbf $DIR/$tdir"
3148         rm -rf $DIR/$tdir
3149         rc=$?
3150         wait_delete_completed
3151         return $rc
3152 }
3153
3154 tbf_verify() {
3155         local dir=$DIR/$tdir
3156         local client1=${CLIENT1:-$(hostname)}
3157         local myRUNAS="$3"
3158
3159         mkdir $dir || error "mkdir $dir failed"
3160         $LFS setstripe -c 1 $dir || error "setstripe to $dir failed"
3161         chmod 777 $dir
3162
3163         trap cleanup_tbf_verify EXIT
3164         echo "Limited write rate: $1, read rate: $2"
3165         echo "Verify the write rate is under TBF control"
3166         local runtime=$(do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
3167                 bs=1M count=100 oflag=direct 2>&1 | awk '/bytes/ {print $6}')
3168         local rate=$(bc <<< "scale=6; 100 / $runtime")
3169         echo "Write runtime is $runtime s, speed is $rate IOPS"
3170
3171         # verify the write rate does not exceed 110% of TBF limited rate
3172         [ $(bc <<< "$rate < 1.1 * $1") -eq 1 ] ||
3173                 error "The write rate ($rate) exceeds 110% of preset rate ($1)"
3174
3175         cancel_lru_locks osc
3176
3177         echo "Verify the read rate is under TBF control"
3178         runtime=$(do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
3179                 bs=1M count=100 iflag=direct 2>&1 | awk '/bytes/ {print $6}')
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 110% of TBF limited rate
3184         [ $(bc <<< "$rate < 1.1 * $2") -eq 1 ] ||
3185                 error "The read rate ($rate) exceeds 110% of preset rate ($2)"
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 -p $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