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