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