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