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