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