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