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