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