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