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