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