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