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