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