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