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