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