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