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