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