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