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