Whamcloud - gitweb
d09a62f573139598127529be071904b365b7f664
[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 # test 42: unlink and blocking operations
1877 test_42a() {
1878         pdo_lru_clear
1879 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1880         do_nodes $(comma_list $(mdts_nodes)) \
1881                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1882         mkdir $DIR1/$tfile &
1883         PID1=$! ; pdo_sched
1884         mkdir $DIR2/$tfile &
1885         PID2=$! ; pdo_sched
1886         do_nodes $(comma_list $(mdts_nodes)) \
1887                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1888         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1889         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
1890         rm -rf $DIR/$tfile*
1891         return 0
1892 }
1893 run_test 42a "pdirops: mkdir vs mkdir =============="
1894
1895 test_42b() {
1896         pdo_lru_clear
1897 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1898         do_nodes $(comma_list $(mdts_nodes)) \
1899                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1900         mkdir $DIR1/$tfile &
1901         PID1=$! ; pdo_sched
1902         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1903         PID2=$! ; pdo_sched
1904         do_nodes $(comma_list $(mdts_nodes)) \
1905                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1906         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1907         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
1908         rm -rf $DIR/$tfile*
1909         return 0
1910 }
1911 run_test 42b "pdirops: mkdir vs create =============="
1912
1913 test_42c() {
1914         pdo_lru_clear
1915         touch $DIR1/$tfile-2
1916 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1917         do_nodes $(comma_list $(mdts_nodes)) \
1918                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1919         mkdir $DIR1/$tfile &
1920         PID1=$! ; pdo_sched
1921         link $DIR2/$tfile-2 $DIR2/$tfile &
1922         PID2=$! ; pdo_sched
1923         do_nodes $(comma_list $(mdts_nodes)) \
1924                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1925         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1926         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
1927         rm -rf $DIR/$tfile*
1928         return 0
1929 }
1930 run_test 42c "pdirops: mkdir vs link =============="
1931
1932 test_42d() {
1933         pdo_lru_clear
1934 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1935         do_nodes $(comma_list $(mdts_nodes)) \
1936                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1937         mkdir $DIR1/$tfile &
1938         PID1=$! ; pdo_sched
1939         rmdir $DIR2/$tfile &
1940         PID2=$! ; pdo_sched
1941         do_nodes $(comma_list $(mdts_nodes)) \
1942                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1943         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1944         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
1945         rm -rf $DIR/$tfile*
1946         return 0
1947 }
1948 run_test 42d "pdirops: mkdir vs unlink =============="
1949
1950 test_42e() {
1951         pdo_lru_clear
1952         touch $DIR1/$tfile-2
1953 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1954         do_nodes $(comma_list $(mdts_nodes)) \
1955                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1956         mkdir $DIR1/$tfile &
1957         PID1=$! ; pdo_sched
1958         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
1959         PID2=$! ; pdo_sched
1960         do_nodes $(comma_list $(mdts_nodes)) \
1961                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1962         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1963         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
1964         rm -rf $DIR/$tfile*
1965         return 0
1966 }
1967 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1968
1969 test_42f() {
1970         pdo_lru_clear
1971 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1972         do_nodes $(comma_list $(mdts_nodes)) \
1973                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1974         mkdir $DIR1/$tfile &
1975         PID1=$! ; pdo_sched
1976         mv $DIR2/$tfile $DIR2/$tfile-2 &
1977         PID2=$! ; pdo_sched
1978         do_nodes $(comma_list $(mdts_nodes)) \
1979                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1980         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1981         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1982         rm -rf $DIR/$tfile*
1983         return 0
1984 }
1985 run_test 42f "pdirops: mkdir and rename (src) =============="
1986
1987 test_42g() {
1988         pdo_lru_clear
1989 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1990         do_nodes $(comma_list $(mdts_nodes)) \
1991                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1992         mkdir $DIR1/$tfile &
1993         PID1=$! ; pdo_sched
1994         stat $DIR2/$tfile > /dev/null &
1995         PID2=$! ; pdo_sched
1996         do_nodes $(comma_list $(mdts_nodes)) \
1997                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1998         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1999         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2000         rm -rf $DIR/$tfile*
2001         return 0
2002 }
2003 run_test 42g "pdirops: mkdir vs getattr =============="
2004
2005 test_42h() {
2006         pdo_lru_clear
2007 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2008         do_nodes $(comma_list $(mdts_nodes)) \
2009                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2010         mkdir $DIR1/$tfile &
2011         PID1=$! ; pdo_sched
2012         ls -lia $DIR2/ > /dev/null &
2013         PID2=$! ; pdo_sched
2014         do_nodes $(comma_list $(mdts_nodes)) \
2015                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2016         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2017         wait $PID2
2018         rm -rf $DIR/$tfile*
2019         return 0
2020 }
2021 run_test 42h "pdirops: mkdir vs readdir =============="
2022
2023 # test 43: rmdir,mkdir won't return -EEXIST
2024 test_43a() {
2025         for i in {1..1000}; do
2026                 mkdir $DIR1/$tdir || error "mkdir $tdir failed"
2027                 rmdir $DIR2/$tdir || error "rmdir $tdir failed"
2028         done
2029         return 0
2030 }
2031 run_test 43a "rmdir,mkdir doesn't return -EEXIST =============="
2032
2033 test_43b() {
2034         pdo_lru_clear
2035         touch $DIR1/$tfile
2036 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2037         do_nodes $(comma_list $(mdts_nodes)) \
2038                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2039         rm $DIR1/$tfile &
2040         PID1=$! ; pdo_sched
2041         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2042         PID2=$! ; pdo_sched
2043         do_nodes $(comma_list $(mdts_nodes)) \
2044                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2045         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2046         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
2047         rm -rf $DIR/$tfile*
2048         return 0
2049 }
2050 run_test 43b "pdirops: unlink vs create =============="
2051
2052 test_43c() {
2053         pdo_lru_clear
2054         touch $DIR1/$tfile
2055         touch $DIR1/$tfile-2
2056 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2057         do_nodes $(comma_list $(mdts_nodes)) \
2058                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2059         rm $DIR1/$tfile &
2060         PID1=$! ; pdo_sched
2061         link $DIR2/$tfile-2 $DIR2/$tfile &
2062         PID2=$! ; pdo_sched
2063         do_nodes $(comma_list $(mdts_nodes)) \
2064                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2065         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2066         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
2067         rm -rf $DIR/$tfile*
2068         return 0
2069 }
2070 run_test 43c "pdirops: unlink vs link =============="
2071
2072 test_43d() {
2073         pdo_lru_clear
2074         touch $DIR1/$tfile
2075 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2076         do_nodes $(comma_list $(mdts_nodes)) \
2077                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2078         rm $DIR1/$tfile &
2079         PID1=$! ; pdo_sched
2080         rm $DIR2/$tfile &
2081         PID2=$! ; pdo_sched
2082         do_nodes $(comma_list $(mdts_nodes)) \
2083                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2084         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2085         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
2086         rm -rf $DIR/$tfile*
2087         return 0
2088 }
2089 run_test 43d "pdirops: unlink vs unlink =============="
2090
2091 test_43e() {
2092         pdo_lru_clear
2093         touch $DIR1/$tfile
2094         touch $DIR1/$tfile-2
2095 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2096         do_nodes $(comma_list $(mdts_nodes)) \
2097                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2098         rm $DIR1/$tfile &
2099         PID1=$! ; pdo_sched
2100         mv -u $DIR2/$tfile-2 $DIR2/$tfile &
2101         PID2=$! ; pdo_sched
2102         do_nodes $(comma_list $(mdts_nodes)) \
2103                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2104         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2105         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2106         rm -rf $DIR/$tfile*
2107         return 0
2108 }
2109 run_test 43e "pdirops: unlink and rename (tgt) =============="
2110
2111 test_43f() {
2112         pdo_lru_clear
2113         touch $DIR1/$tfile
2114 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2115         do_nodes $(comma_list $(mdts_nodes)) \
2116                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2117         rm $DIR1/$tfile &
2118         PID1=$! ; pdo_sched
2119         mv $DIR2/$tfile $DIR2/$tfile-2 &
2120         PID2=$! ; pdo_sched
2121         do_nodes $(comma_list $(mdts_nodes)) \
2122                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2123         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2124         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2125         rm -rf $DIR/$tfile*
2126         return 0
2127 }
2128 run_test 43f "pdirops: unlink and rename (src) =============="
2129
2130 test_43g() {
2131         pdo_lru_clear
2132         touch $DIR1/$tfile
2133 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2134         do_nodes $(comma_list $(mdts_nodes)) \
2135                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2136         rm $DIR1/$tfile &
2137         PID1=$! ; pdo_sched
2138         stat $DIR2/$tfile > /dev/null &
2139         PID2=$! ; pdo_sched
2140         do_nodes $(comma_list $(mdts_nodes)) \
2141                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2142         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2143         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
2144         rm -rf $DIR/$tfile*
2145         return 0
2146 }
2147 run_test 43g "pdirops: unlink vs getattr =============="
2148
2149 test_43h() {
2150         pdo_lru_clear
2151         touch $DIR1/$tfile
2152 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2153         do_nodes $(comma_list $(mdts_nodes)) \
2154                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2155         rm $DIR1/$tfile &
2156         PID1=$! ; pdo_sched
2157         ls -lia $DIR2/ > /dev/null &
2158         PID2=$! ; pdo_sched
2159         do_nodes $(comma_list $(mdts_nodes)) \
2160                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2161         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2162         wait $PID2
2163         rm -rf $DIR/$tfile*
2164         return 0
2165 }
2166 run_test 43h "pdirops: unlink vs readdir =============="
2167
2168 test_43i() {
2169         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2170         pdo_lru_clear
2171         touch $DIR1/$tfile
2172 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2173         do_nodes $(comma_list $(mdts_nodes)) \
2174                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2175         rm $DIR1/$tfile &
2176         PID1=$! ; pdo_sched
2177         $LFS mkdir -i 1 $DIR2/$tfile &
2178         PID2=$! ; pdo_sched
2179         do_nodes $(comma_list $(mdts_nodes)) \
2180                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2181         check_pdo_conflict $PID1 &&
2182                 { wait $PID1; error "remote mkdir isn't blocked"; }
2183         wait $PID2 ; [ $? -eq 0 ] || error "remote mkdir must succeed"
2184         rm -rf $DIR/$tfile*
2185         return 0
2186 }
2187 run_test 43i "pdirops: unlink vs remote mkdir"
2188
2189 test_43j() {
2190         [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] &&
2191                 skip "Need MDS version newer than 2.13.52"
2192
2193         for i in {1..100}; do
2194 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_CREATE_RACE         0x167
2195                 do_nodes $(comma_list $(mdts_nodes)) \
2196                         "lctl set_param -n fail_loc=0x80000167 2>/dev/null ||
2197                                 true"
2198                 OK=0
2199                 mkdir $DIR1/$tdir &
2200                 PID1=$!
2201                 mkdir $DIR2/$tdir && ((OK++))
2202                 wait $PID1 && ((OK++))
2203                 (( OK == 1 )) || error "exactly one mkdir should succeed"
2204
2205                 rmdir $DIR1/$tdir || error "rmdir failed"
2206         done
2207         return 0
2208 }
2209 run_test 43j "racy mkdir return EEXIST =============="
2210
2211 # test 44: rename tgt and blocking operations
2212 test_44a() {
2213         pdo_lru_clear
2214         touch $DIR1/$tfile-2
2215 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2216         do_nodes $(comma_list $(mdts_nodes)) \
2217                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2218         mv $DIR1/$tfile-2 $DIR1/$tfile &
2219         PID1=$! ; pdo_sched
2220         mkdir $DIR2/$tfile &
2221         PID2=$! ; pdo_sched
2222         do_nodes $(comma_list $(mdts_nodes)) \
2223                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2224         check_pdo_conflict $PID1 && { wait $PID1; date;error "mkdir isn't blocked"; }
2225         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2226         date
2227         rm -rf $DIR/$tfile*
2228         return 0
2229 }
2230 run_test 44a "pdirops: rename tgt vs mkdir =============="
2231
2232 test_44b() {
2233         pdo_lru_clear
2234         touch $DIR1/$tfile-2
2235 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2236         do_nodes $(comma_list $(mdts_nodes)) \
2237                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2238         mv $DIR1/$tfile-2 $DIR1/$tfile &
2239         PID1=$! ; pdo_sched
2240         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2241         PID2=$! ; pdo_sched
2242         do_nodes $(comma_list $(mdts_nodes)) \
2243                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2244         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2245         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2246         rm -rf $DIR/$tfile*
2247         return 0
2248 }
2249 run_test 44b "pdirops: rename tgt vs create =============="
2250
2251 test_44c() {
2252         pdo_lru_clear
2253         touch $DIR1/$tfile-2
2254         touch $DIR1/$tfile-3
2255 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2256         do_nodes $(comma_list $(mdts_nodes)) \
2257                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2258         mv $DIR1/$tfile-2 $DIR1/$tfile &
2259         PID1=$! ; pdo_sched
2260         link $DIR2/$tfile-3 $DIR2/$tfile &
2261         PID2=$! ; pdo_sched
2262         do_nodes $(comma_list $(mdts_nodes)) \
2263                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2264         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2265         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2266         rm -rf $DIR/$tfile*
2267         return 0
2268 }
2269 run_test 44c "pdirops: rename tgt vs link =============="
2270
2271 test_44d() {
2272         pdo_lru_clear
2273         touch $DIR1/$tfile-2
2274 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2275         do_nodes $(comma_list $(mdts_nodes)) \
2276                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2277         mv $DIR1/$tfile-2 $DIR1/$tfile &
2278         PID1=$! ; pdo_sched
2279         rm $DIR2/$tfile &
2280         PID2=$! ; pdo_sched
2281         do_nodes $(comma_list $(mdts_nodes)) \
2282                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2283         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2284         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2285         rm -rf $DIR/$tfile*
2286         return 0
2287 }
2288 run_test 44d "pdirops: rename tgt vs unlink =============="
2289
2290 test_44e() {
2291         pdo_lru_clear
2292         touch $DIR1/$tfile
2293         touch $DIR1/$tfile-2
2294         touch $DIR1/$tfile-3
2295 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2296         do_nodes $(comma_list $(mdts_nodes)) \
2297                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2298         mv $DIR1/$tfile-2 $DIR1/$tfile &
2299         PID1=$! ; pdo_sched
2300         mv $DIR2/$tfile-3 $DIR2/$tfile &
2301         PID2=$! ; pdo_sched
2302         do_nodes $(comma_list $(mdts_nodes)) \
2303                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2304         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2305         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2306         rm -rf $DIR/$tfile*
2307         return 0
2308 }
2309 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
2310
2311 test_44f() {
2312         pdo_lru_clear
2313         touch $DIR1/$tfile-2
2314         touch $DIR1/$tfile-3
2315 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2316         do_nodes $(comma_list $(mdts_nodes)) \
2317                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2318         mv $DIR1/$tfile-2 $DIR1/$tfile &
2319         PID1=$! ; pdo_sched
2320         mv $DIR2/$tfile $DIR2/$tfile-3 &
2321         PID2=$! ; pdo_sched
2322         do_nodes $(comma_list $(mdts_nodes)) \
2323                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2324         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2325         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2326         rm -rf $DIR/$tfile*
2327         return 0
2328 }
2329 run_test 44f "pdirops: rename tgt and rename (src) =============="
2330
2331 test_44g() {
2332         pdo_lru_clear
2333         touch $DIR1/$tfile-2
2334 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2335         do_nodes $(comma_list $(mdts_nodes)) \
2336                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2337         mv $DIR1/$tfile-2 $DIR1/$tfile &
2338         PID1=$! ; pdo_sched
2339         stat $DIR2/$tfile > /dev/null &
2340         PID2=$! ; pdo_sched
2341         do_nodes $(comma_list $(mdts_nodes)) \
2342                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2343         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2344         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2345         rm -rf $DIR/$tfile*
2346         return 0
2347 }
2348 run_test 44g "pdirops: rename tgt vs getattr =============="
2349
2350 test_44h() {
2351         pdo_lru_clear
2352         touch $DIR1/$tfile-2
2353 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2354         do_nodes $(comma_list $(mdts_nodes)) \
2355                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2356         mv $DIR1/$tfile-2 $DIR1/$tfile &
2357         PID1=$! ; pdo_sched
2358         ls -lia $DIR2/ > /dev/null &
2359         PID2=$! ; pdo_sched
2360         do_nodes $(comma_list $(mdts_nodes)) \
2361                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2362         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2363         wait $PID2
2364         rm -rf $DIR/$tfile*
2365         return 0
2366 }
2367 run_test 44h "pdirops: rename tgt vs readdir =============="
2368
2369 # test 44: rename tgt and blocking operations
2370 test_44i() {
2371         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2372         pdo_lru_clear
2373         touch $DIR1/$tfile-2
2374 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2375         do_nodes $(comma_list $(mdts_nodes)) \
2376                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2377         mv $DIR1/$tfile-2 $DIR1/$tfile &
2378         PID1=$! ; pdo_sched
2379         $LFS mkdir -i 1 $DIR2/$tfile &
2380         PID2=$! ; pdo_sched
2381         do_nodes $(comma_list $(mdts_nodes)) \
2382                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2383         check_pdo_conflict $PID1 && { wait $PID1;
2384                                 error "remote mkdir isn't blocked"; }
2385         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2386         rm -rf $DIR/$tfile*
2387         return 0
2388 }
2389 run_test 44i "pdirops: rename tgt vs remote mkdir"
2390
2391 # test 45: rename,mkdir doesn't fail with -EEXIST
2392 test_45a() {
2393         for i in {1..1000}; do
2394                 mkdir $DIR1/$tdir || error "mkdir $tdir failed"
2395                 mrename $DIR2/$tdir $DIR2/$tdir.$i > /dev/null ||
2396                         error "mrename to $tdir.$i failed"
2397         done
2398         rm -rf $DIR/$tdir*
2399         return 0
2400 }
2401 run_test 45a "rename,mkdir doesn't return -EEXIST =============="
2402
2403 test_45b() {
2404         pdo_lru_clear
2405         touch $DIR1/$tfile
2406 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2407         do_nodes $(comma_list $(mdts_nodes)) \
2408                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2409         mv $DIR1/$tfile $DIR1/$tfile-2 &
2410         PID1=$! ; pdo_sched
2411         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2412         PID2=$! ; pdo_sched
2413         do_nodes $(comma_list $(mdts_nodes)) \
2414                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2415         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2416         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
2417         rm -rf $DIR/$tfile*
2418         return 0
2419 }
2420 run_test 45b "pdirops: rename src vs create =============="
2421
2422 test_45c() {
2423         pdo_lru_clear
2424         touch $DIR1/$tfile
2425         touch $DIR1/$tfile-3
2426 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2427         do_nodes $(comma_list $(mdts_nodes)) \
2428                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2429         mv $DIR1/$tfile $DIR1/$tfile-2 &
2430         PID1=$! ; pdo_sched
2431         link $DIR2/$tfile-3 $DIR2/$tfile &
2432         PID2=$! ; pdo_sched
2433         do_nodes $(comma_list $(mdts_nodes)) \
2434                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2435         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2436         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
2437         rm -rf $DIR/$tfile*
2438         return 0
2439 }
2440 run_test 45c "pdirops: rename src vs link =============="
2441
2442 test_45d() {
2443         pdo_lru_clear
2444         touch $DIR1/$tfile
2445 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2446         do_nodes $(comma_list $(mdts_nodes)) \
2447                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2448         mv $DIR1/$tfile $DIR1/$tfile-2 &
2449         PID1=$! ; pdo_sched
2450         rm $DIR2/$tfile &
2451         PID2=$! ; pdo_sched
2452         do_nodes $(comma_list $(mdts_nodes)) \
2453                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2454         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2455         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
2456         rm -rf $DIR/$tfile*
2457         return 0
2458 }
2459 run_test 45d "pdirops: rename src vs unlink =============="
2460
2461 test_45e() {
2462         pdo_lru_clear
2463         touch $DIR1/$tfile
2464         touch $DIR1/$tfile-3
2465 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2466         do_nodes $(comma_list $(mdts_nodes)) \
2467                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2468         mv $DIR1/$tfile $DIR1/$tfile-2 &
2469         PID1=$! ; pdo_sched
2470         mv $DIR2/$tfile-3 $DIR2/$tfile &
2471         PID2=$! ; pdo_sched
2472         do_nodes $(comma_list $(mdts_nodes)) \
2473                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2474         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2475         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2476         rm -rf $DIR/$tfile*
2477         return 0
2478 }
2479 run_test 45e "pdirops: rename src and rename (tgt) =============="
2480
2481 test_45f() {
2482         pdo_lru_clear
2483         touch $DIR1/$tfile
2484 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2485         do_nodes $(comma_list $(mdts_nodes)) \
2486                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2487         mv $DIR1/$tfile $DIR1/$tfile-2 &
2488         PID1=$! ; pdo_sched
2489         mv $DIR2/$tfile $DIR2/$tfile-3 &
2490         PID2=$! ; pdo_sched
2491         do_nodes $(comma_list $(mdts_nodes)) \
2492                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2493         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2494         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2495         rm -rf $DIR/$tfile*
2496         return 0
2497 }
2498 run_test 45f "pdirops: rename src and rename (src) =============="
2499
2500 test_45g() {
2501         pdo_lru_clear
2502         touch $DIR1/$tfile
2503 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2504         do_nodes $(comma_list $(mdts_nodes)) \
2505                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2506         mv $DIR1/$tfile $DIR1/$tfile-2 &
2507         PID1=$! ; pdo_sched
2508         stat $DIR2/$tfile > /dev/null &
2509         PID2=$! ; pdo_sched
2510         do_nodes $(comma_list $(mdts_nodes)) \
2511                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2512         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2513         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
2514         rm -rf $DIR/$tfile*
2515         return 0
2516 }
2517 run_test 45g "pdirops: rename src vs getattr =============="
2518
2519 test_45h() {
2520         pdo_lru_clear
2521         touch $DIR1/$tfile
2522 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2523         do_nodes $(comma_list $(mdts_nodes)) \
2524                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2525         mv $DIR1/$tfile $DIR1/$tfile-2 &
2526         PID1=$! ; pdo_sched
2527         ls -lia $DIR2/ > /dev/null &
2528         do_nodes $(comma_list $(mdts_nodes)) \
2529                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2530         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2531         wait $PID2
2532         rm -rf $DIR/$tfile*
2533         return 0
2534 }
2535 run_test 45h "pdirops: unlink vs readdir =============="
2536
2537 test_45i() {
2538         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2539         pdo_lru_clear
2540         touch $DIR1/$tfile
2541 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2542         do_nodes $(comma_list $(mdts_nodes)) \
2543                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2544         mv $DIR1/$tfile $DIR1/$tfile-2 &
2545         PID1=$! ; pdo_sched
2546         $LFS mkdir -i 1 $DIR2/$tfile &
2547         PID2=$! ; pdo_sched
2548         do_nodes $(comma_list $(mdts_nodes)) \
2549                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2550         check_pdo_conflict $PID1 && { wait $PID1;
2551                                 error "create remote dir isn't blocked"; }
2552         wait $PID2 ; [ $? -eq 0 ] || error "create remote dir must succeed"
2553         rm -rf $DIR/$tfile*
2554         return 0
2555 }
2556 run_test 45i "pdirops: rename src vs remote mkdir"
2557
2558 # test 46: link and blocking operations
2559 test_46a() {
2560         pdo_lru_clear
2561         touch $DIR1/$tfile-2
2562 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2563         do_nodes $(comma_list $(mdts_nodes)) \
2564                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2565         link $DIR1/$tfile-2 $DIR1/$tfile &
2566         PID1=$! ; pdo_sched
2567         mkdir $DIR2/$tfile &
2568         PID2=$! ; pdo_sched
2569         do_nodes $(comma_list $(mdts_nodes)) \
2570                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2571         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2572         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2573         rm -rf $DIR/$tfile*
2574         return 0
2575 }
2576 run_test 46a "pdirops: link vs mkdir =============="
2577
2578 test_46b() {
2579         pdo_lru_clear
2580         touch $DIR1/$tfile-2
2581 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2582         do_nodes $(comma_list $(mdts_nodes)) \
2583                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2584         link $DIR1/$tfile-2 $DIR1/$tfile &
2585         PID1=$! ; pdo_sched
2586         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2587         PID2=$! ; pdo_sched
2588         do_nodes $(comma_list $(mdts_nodes)) \
2589                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2590         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2591         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2592         rm -rf $DIR/$tfile*
2593         return 0
2594 }
2595 run_test 46b "pdirops: link vs create =============="
2596
2597 test_46c() {
2598         pdo_lru_clear
2599         touch $DIR1/$tfile-2
2600 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2601         do_nodes $(comma_list $(mdts_nodes)) \
2602                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2603         link $DIR1/$tfile-2 $DIR1/$tfile &
2604         PID1=$! ; pdo_sched
2605         link $DIR2/$tfile $DIR2/$tfile &
2606         PID2=$! ; pdo_sched
2607         do_nodes $(comma_list $(mdts_nodes)) \
2608                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2609         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2610         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2611         rm -rf $DIR/$tfile*
2612         return 0
2613 }
2614 run_test 46c "pdirops: link vs link =============="
2615
2616 test_46d() {
2617         pdo_lru_clear
2618         touch $DIR1/$tfile-2
2619 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2620         do_nodes $(comma_list $(mdts_nodes)) \
2621                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2622         link $DIR1/$tfile-2 $DIR1/$tfile &
2623         PID1=$! ; pdo_sched
2624         rm $DIR2/$tfile &
2625         PID2=$! ; pdo_sched
2626         do_nodes $(comma_list $(mdts_nodes)) \
2627                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2628         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2629         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2630         rm -rf $DIR/$tfile*
2631         return 0
2632 }
2633 run_test 46d "pdirops: link vs unlink =============="
2634
2635 test_46e() {
2636         pdo_lru_clear
2637         touch $DIR1/$tfile-2
2638         touch $DIR1/$tfile-3
2639 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2640         do_nodes $(comma_list $(mdts_nodes)) \
2641                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2642         link $DIR1/$tfile-2 $DIR1/$tfile &
2643         PID1=$! ; pdo_sched
2644         mv $DIR2/$tfile-3 $DIR2/$tfile &
2645         PID2=$! ; pdo_sched
2646         do_nodes $(comma_list $(mdts_nodes)) \
2647                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2648         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2649         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2650         rm -rf $DIR/$tfile*
2651         return 0
2652 }
2653 run_test 46e "pdirops: link and rename (tgt) =============="
2654
2655 test_46f() {
2656         pdo_lru_clear
2657         touch $DIR1/$tfile-2
2658         touch $DIR1/$tfile-3
2659 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2660         do_nodes $(comma_list $(mdts_nodes)) \
2661                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2662         link $DIR1/$tfile-2 $DIR1/$tfile &
2663         PID1=$! ; pdo_sched
2664         mv $DIR2/$tfile $DIR2/$tfile-3 &
2665         PID2=$! ; pdo_sched
2666         do_nodes $(comma_list $(mdts_nodes)) \
2667                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2668         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2669         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2670         rm -rf $DIR/$tfile*
2671         return 0
2672 }
2673 run_test 46f "pdirops: link and rename (src) =============="
2674
2675 test_46g() {
2676         pdo_lru_clear
2677         touch $DIR1/$tfile-2
2678 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2679         do_nodes $(comma_list $(mdts_nodes)) \
2680                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2681         link $DIR1/$tfile-2 $DIR1/$tfile &
2682         PID1=$! ; pdo_sched
2683         stat $DIR2/$tfile > /dev/null &
2684         PID2=$! ; pdo_sched
2685         do_nodes $(comma_list $(mdts_nodes)) \
2686                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2687         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2688         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2689         rm -rf $DIR/$tfile*
2690         return 0
2691 }
2692 run_test 46g "pdirops: link vs getattr =============="
2693
2694 test_46h() {
2695         pdo_lru_clear
2696         touch $DIR1/$tfile-2
2697 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2698         do_nodes $(comma_list $(mdts_nodes)) \
2699                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2700         link $DIR1/$tfile-2 $DIR1/$tfile &
2701         PID1=$! ; pdo_sched
2702         ls -lia $DIR2/ > /dev/null &
2703         PID2=$! ; pdo_sched
2704         do_nodes $(comma_list $(mdts_nodes)) \
2705                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2706         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2707         wait $PID2
2708         rm -rf $DIR/$tfile*
2709         return 0
2710 }
2711 run_test 46h "pdirops: link vs readdir =============="
2712
2713 test_46i() {
2714         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2715         pdo_lru_clear
2716         touch $DIR1/$tfile-2
2717 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2718         do_nodes $(comma_list $(mdts_nodes)) \
2719                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2720         link $DIR1/$tfile-2 $DIR1/$tfile &
2721         PID1=$! ; pdo_sched
2722         $LFS mkdir -i 1 $DIR2/$tfile &
2723         PID2=$! ; pdo_sched
2724         do_nodes $(comma_list $(mdts_nodes)) \
2725                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2726         check_pdo_conflict $PID1 && { wait $PID1;
2727                                 error "remote mkdir isn't blocked"; }
2728         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2729         rm -rf $DIR/$tfile*
2730         return 0
2731 }
2732 run_test 46i "pdirops: link vs remote mkdir"
2733
2734 # test 47: remote mkdir and blocking operations
2735 test_47a() {
2736 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2737         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2738         pdo_lru_clear
2739         do_nodes $(comma_list $(mdts_nodes)) \
2740                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2741         $LFS mkdir -i 1 $DIR1/$tfile &
2742         PID1=$! ; pdo_sched
2743         mkdir $DIR2/$tfile &
2744         PID2=$! ; pdo_sched
2745         do_nodes $(comma_list $(mdts_nodes)) \
2746                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2747         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2748         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2749         rm -rf $DIR/$tfile*
2750         return 0
2751 }
2752 run_test 47a "pdirops: remote mkdir vs mkdir"
2753
2754 test_47b() {
2755 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2756         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2757         pdo_lru_clear
2758         do_nodes $(comma_list $(mdts_nodes)) \
2759                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2760         $LFS mkdir -i 1 $DIR1/$tfile &
2761         PID1=$! ; pdo_sched
2762         sleep 1 # please do not remove this sleep, see LU-10754
2763         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c &
2764         PID2=$! ; pdo_sched
2765         do_nodes $(comma_list $(mdts_nodes)) \
2766                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2767         check_pdo_conflict $PID1 && { wait $PID1;
2768                                         error "create isn't blocked"; }
2769         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2770         rm -rf $DIR/$tfile*
2771         return 0
2772 }
2773 run_test 47b "pdirops: remote mkdir vs create"
2774
2775 test_47c() {
2776         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2777         pdo_lru_clear
2778         touch $DIR1/$tfile-2
2779 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2780         do_nodes $(comma_list $(mdts_nodes)) \
2781                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2782         $LFS mkdir -i 1 $DIR1/$tfile &
2783         PID1=$! ; pdo_sched
2784         link $DIR2/$tfile-2 $DIR2/$tfile &
2785         PID2=$! ; pdo_sched
2786         do_nodes $(comma_list $(mdts_nodes)) \
2787                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2788         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2789         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2790         rm -rf $DIR/$tfile*
2791         return 0
2792 }
2793 run_test 47c "pdirops: remote mkdir vs link"
2794
2795 test_47d() {
2796         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2797         pdo_lru_clear
2798 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2799         do_nodes $(comma_list $(mdts_nodes)) \
2800                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2801         $LFS mkdir -i 1 $DIR1/$tfile &
2802         PID1=$! ; pdo_sched
2803         rmdir $DIR2/$tfile &
2804         PID2=$! ; pdo_sched
2805         do_nodes $(comma_list $(mdts_nodes)) \
2806                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2807         check_pdo_conflict $PID1 && { wait $PID1;
2808                                         error "unlink isn't blocked"; }
2809         wait $PID2 ; [ $? -eq 0 ] || error "rmdir must succeed"
2810         rm -rf $DIR/$tfile*
2811         return 0
2812 }
2813 run_test 47d "pdirops: remote mkdir vs unlink"
2814
2815 test_47e() {
2816         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2817         pdo_lru_clear
2818         touch $DIR1/$tfile-2
2819 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2820         do_nodes $(comma_list $(mdts_nodes)) \
2821                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2822         $LFS mkdir -i 1 $DIR1/$tfile &
2823         PID1=$! ; pdo_sched
2824         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
2825         PID2=$! ; pdo_sched
2826         do_nodes $(comma_list $(mdts_nodes)) \
2827                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2828         check_pdo_conflict $PID1 && { wait $PID1;
2829                                         error "rename isn't blocked"; }
2830         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2831         rm -rf $DIR/$tfile*
2832         return 0
2833 }
2834 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2835
2836 test_47f() {
2837         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2838         pdo_lru_clear
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         $LFS mkdir -i 1 $DIR1/$tfile &
2843         PID1=$! ; pdo_sched
2844         mv $DIR2/$tfile $DIR2/$tfile-2 &
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;
2849                                         error "rename isn't blocked"; }
2850         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2851         rm -rf $DIR/$tfile*
2852         return 0
2853 }
2854 run_test 47f "pdirops: remote mkdir and rename (src)"
2855
2856 test_47g() {
2857         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2858         sync
2859         sync_all_data
2860         pdo_lru_clear
2861 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2862         do_nodes $(comma_list $(mdts_nodes)) \
2863                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2864         $LFS mkdir -i 1 $DIR1/$tfile &
2865         PID1=$! ; pdo_sched
2866         stat $DIR2/$tfile > /dev/null &
2867         PID2=$! ; pdo_sched
2868         do_nodes $(comma_list $(mdts_nodes)) \
2869                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2870         check_pdo_conflict $PID1 && { wait $PID1;
2871                                         error "getattr isn't blocked"; }
2872         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2873         rm -rf $DIR/$tfile*
2874         return 0
2875 }
2876 run_test 47g "pdirops: remote mkdir vs getattr"
2877
2878 test_50() {
2879         trunc_size=4096
2880         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2881 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2882         do_facet client "lctl set_param fail_loc=0x410"
2883         $TRUNCATE $DIR2/$tfile $trunc_size
2884         do_facet client "lctl set_param fail_loc=0x0"
2885         sleep 3
2886         size=`stat -c %s $DIR2/$tfile`
2887         [ $size -eq $trunc_size ] || error "wrong size"
2888 }
2889 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2890
2891 test_51a() {
2892         local filesize
2893         local origfile=/etc/hosts
2894
2895         filesize=$(stat -c %s $origfile)
2896
2897         # create an empty file
2898         $MCREATE $DIR1/$tfile || error "can't create $DIR1/$tfile"
2899         # cache layout lock on both mount point
2900         stat $DIR1/$tfile > /dev/null || error "stat $DIR1/$tfile failed"
2901         stat $DIR2/$tfile > /dev/null || error "stat $DIR2/$tfile failed"
2902
2903         # open and sleep 2 seconds then read
2904         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2905         local pid=$!
2906         sleep 1
2907
2908         # create the layout of testing file
2909         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null ||
2910                 error "dd $DIR1/$tfile failed"
2911
2912         # MULTIOP proc should be able to read enough bytes and exit
2913         for ((i = 0; i < 6; i++)); do
2914                 sleep 1
2915                 kill -0 $pid || break
2916         done
2917         kill -0 $pid 2> /dev/null && error "multiop is still there"
2918         cmp $origfile $DIR2/$tfile || error "$origfile and $DIR2/$tfile differs"
2919
2920         rm -f $DIR1/$tfile
2921 }
2922 run_test 51a "layout lock: refresh layout should work"
2923
2924 test_51b() {
2925         [[ "$MDS1_VERSION" -ge $(version_code 2.3.59) ]] ||
2926                 skip "Need MDS version at least 2.3.59"
2927
2928         local tmpfile=`mktemp`
2929
2930         $LFS setstripe -E 1M -c 1 -E -1 --extension-size 64M $DIR1/$tfile ||
2931                 error "Create $DIR1/$tfile failed"
2932
2933         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc ||
2934                 error "dd $DIR1/$tfile failed"
2935
2936         # delay glimpse so that layout has changed when glimpse finish
2937 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2938         $LCTL set_param fail_loc=0x1404 fail_val=4
2939         stat -c %s $DIR2/$tfile |tee $tmpfile &
2940         local pid=$!
2941         sleep 0.2
2942
2943         # extend layout of testing file
2944         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=1 seek=2 conv=notrunc ||
2945                 error "dd $DIR1/$tfile failed"
2946
2947         wait $pid
2948         local fsize=$(cat $tmpfile)
2949
2950         [ x$fsize = x3145728 ] || error "file size is $fsize, should be 3145728"
2951
2952         rm -f $DIR1/$tfile $tmpfile
2953 }
2954 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2955
2956 test_51c() {
2957         [ $OSTCOUNT -ge 2 ] || { skip "needs >= 2 osts"; return; }
2958
2959         # set default layout to have 1 stripe
2960         mkdir $DIR1/$tdir
2961         $LFS setstripe -c 1 $DIR1/$tdir
2962
2963         # create a file with empty layout
2964         $MCREATE $DIR1/$tdir/$tfile ||
2965                 error "$MCREATE $DIR1/$tdir/$tfile failed"
2966
2967 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2968         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
2969
2970         # change the layout of testing file
2971         echo "Setting layout to have $OSTCOUNT stripes ..."
2972         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
2973         pid=$!
2974         sleep 1
2975
2976         # write something to the file, it should be blocked on fetching layout
2977         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
2978         local stripe_count=$($LFS getstripe -c $DIR2/$tdir/$tfile)
2979         wait $pid
2980
2981         # lod_qos.c::min_stripe_count() allows setstripe with a default stripe
2982         # count to succeed with only 3/4 of the number of stripes (rounded up),
2983         # so creating striped files does not fail if an OST is offline or full
2984         [ $stripe_count -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
2985                 error "bad layout: getstripe -c $stripe_count < $OSTCOUNT * 3/4"
2986
2987         rm -fr $DIR1/$tdir
2988 }
2989 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2990
2991 test_51d() {
2992         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
2993         cancel_lru_locks mdc
2994
2995         # open should grant LAYOUT lock, mmap and read will install pages
2996         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
2997         local PID=$!
2998         sleep 1
2999
3000         # rss before revoking
3001         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
3002         echo "Before revoking layout lock: $br KB mapped"
3003
3004         # cancel layout lock manually
3005         cancel_lru_locks mdc
3006
3007         # rss after revoking
3008         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
3009
3010         kill -USR1 $PID
3011         wait $PID || error "wait PID $PID failed"
3012
3013         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
3014 }
3015 run_test 51d "layout lock: losing layout lock should clean up memory map region"
3016
3017 test_51e() {
3018         local pid
3019
3020         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eW_E+eUc &
3021         pid=$!
3022         sleep 1
3023
3024         $LFS getstripe $DIR2/$tfile
3025         kill -USR1 $pid
3026         wait $pid || error "multiop failed"
3027
3028         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
3029         pid=$!
3030         sleep 1
3031
3032         $LFS getstripe $DIR2/$tfile
3033         kill -USR1 $pid
3034         wait $pid || error "multiop failed"
3035 }
3036 run_test 51e "lfs getstripe does not break leases, part 2"
3037
3038 test_54_part1()
3039 {
3040         echo "==> rename vs getattr vs setxattr should not deadlock"
3041         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
3042
3043         do_facet mds1 $LCTL set_param fail_loc=$1
3044
3045         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
3046         PID1=$!
3047         sleep 1
3048
3049         stat $DIR/d1/d2 &
3050         PID2=$!
3051         sleep 1
3052
3053         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
3054         wait $PID1 || error "(3) mv failed"
3055         wait $PID2 || error "(4) stat failed"
3056         echo
3057
3058         rm -rf $DIR/d1
3059 }
3060
3061 test_54_part2() {
3062         echo "==> rename vs getattr vs open vs getattr should not deadlock"
3063         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
3064
3065         do_facet mds1 $LCTL set_param fail_loc=$1
3066
3067         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
3068         PID1=$!
3069         sleep 1
3070
3071         stat $DIR/d1/d2 &
3072         PID2=$!
3073         sleep 1
3074
3075         $MULTIOP $DIR2/d1/d2 Oc &
3076         PID3=$!
3077         sleep 1
3078
3079         stat $DIR/d1 || error "(2) stat failed"
3080
3081         wait $PID1 || error "(3) mv failed"
3082         wait $PID2 || error "(4) stat failed"
3083         wait $PID3 && error "(5) multiop failed"
3084         echo
3085         rm -rf $DIR/d1
3086 }
3087
3088 test_54() {
3089         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
3090         save_lustre_params client "llite.*.xattr_cache" > $p
3091         lctl set_param llite.*.xattr_cache 1 ||
3092                 { skip "xattr cache is not supported"; return 0; }
3093
3094 #define OBD_FAIL_MDS_RENAME              0x153
3095 #define OBD_FAIL_MDS_RENAME2             0x154
3096         test_54_part1 0x80000153 || error 10
3097         test_54_part1 0x80000154 || error 11
3098         test_54_part2 0x80000153 || error 12
3099         test_54_part2 0x80000154 || error 13
3100
3101         restore_lustre_params < $p
3102         rm -f $p
3103 }
3104 run_test 54 "rename locking"
3105
3106 test_55a() {
3107         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
3108
3109 #define OBD_FAIL_MDS_RENAME4              0x156
3110         do_facet mds1 $LCTL set_param fail_loc=0x80000156
3111
3112         mv -T $DIR/d1/d2 $DIR/d3/d2 &
3113         PID1=$!
3114         sleep 1
3115
3116         rm -r $DIR2/d3
3117         wait $PID1 && error "(2) mv succeeded"
3118
3119         rm -rf $DIR/d1
3120 }
3121 run_test 55a "rename vs unlink target dir"
3122
3123 test_55b()
3124 {
3125         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
3126
3127 #define OBD_FAIL_MDS_RENAME4             0x156
3128         do_facet mds1 $LCTL set_param fail_loc=0x80000156
3129
3130         mv -T $DIR/d1/d2 $DIR/d3/d2 &
3131         PID1=$!
3132         sleep 1
3133
3134         rm -r $DIR2/d1
3135         wait $PID1 && error "(2) mv succeeded"
3136
3137         rm -rf $DIR/d3
3138 }
3139 run_test 55b "rename vs unlink source dir"
3140
3141 test_55c()
3142 {
3143         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
3144
3145 #define OBD_FAIL_MDS_RENAME4              0x156
3146         do_facet mds1 $LCTL set_param fail_loc=0x156
3147
3148         mv -T $DIR/d1/d2 $DIR/d3/d2 &
3149         PID1=$!
3150         sleep 1
3151
3152         # while rename is sleeping, open and remove d3
3153         $MULTIOP $DIR2/d3 D_c &
3154         PID2=$!
3155         sleep 1
3156         rm -rf $DIR2/d3
3157         sleep 5
3158
3159         # while rename is sleeping 2nd time, close d3
3160         kill -USR1 $PID2
3161         wait $PID2 || error "(3) multiop failed"
3162
3163         wait $PID1 && error "(2) mv succeeded"
3164
3165         rm -rf $DIR/d1
3166 }
3167 run_test 55c "rename vs unlink orphan target dir"
3168
3169 test_55d()
3170 {
3171         touch $DIR/f1
3172
3173 #define OBD_FAIL_MDS_RENAME3              0x155
3174         do_facet mds1 $LCTL set_param fail_loc=0x155
3175         mv $DIR/f1 $DIR/$tdir &
3176         PID1=$!
3177         sleep 2
3178
3179         # while rename is sleeping, create $tdir, but as a directory
3180         mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
3181
3182         # link in reverse locking order
3183         ln $DIR2/f1 $DIR2/$tdir/
3184
3185         wait $PID1 && error "(2) mv succeeded"
3186         rm -rf $DIR/f1
3187 }
3188 run_test 55d "rename file vs link"
3189
3190 test_60() {
3191         [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
3192                 skip "MDS version must be >= 2.3.0"
3193
3194         # Create a file
3195         test_mkdir $DIR1/$tdir
3196         file1=$DIR1/$tdir/file
3197         file2=$DIR2/$tdir/file
3198
3199         echo orig > $file2 || error "Could not create $file2"
3200         version=$($LFS data_version $file1)
3201
3202         # Append data
3203         echo append >> $file2 || error "Could not append to $file2"
3204         version2=$($LFS data_version $file1)
3205         [ "$version" != "$version2" ] ||
3206             error "append did not change data version: $version"
3207
3208         # Overwrite data
3209         echo overwrite > $file2 || error "Could not overwrite $file2"
3210         version3=$($LFS data_version $file1)
3211         [ "$version2" != "$version3" ] ||
3212             error "overwrite did not change data version: $version2"
3213
3214         # Truncate before EOF
3215         $TRUNCATE $file2 3 || error "Could not truncate $file2"
3216         version4=$($LFS data_version $file1)
3217         [ "$version3" != "$version4" ] ||
3218             error "truncate did not change data version: $version3"
3219
3220         # Truncate after EOF
3221         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
3222         version5=$($LFS data_version $file1)
3223         [ "$version4" != "$version5" ] ||
3224             error "truncate did not change data version: $version4"
3225
3226         # Chmod do not change version
3227         chmod 400 $file2 || error "Could not chmod 400 $file2"
3228         version6=$($LFS data_version $file1)
3229         [ "$version5" == "$version6" ] ||
3230             error "chmod should not change data version: $version5 != $version6"
3231
3232         # Chown do not change version
3233         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
3234         version7=$($LFS data_version $file1)
3235         [ "$version5" == "$version7" ] ||
3236             error "chown should not change data version: $version5 != $version7"
3237 }
3238 run_test 60 "Verify data_version behaviour"
3239
3240 test_70a() {
3241         local test_dir=$tdir/test_dir
3242
3243         mkdir -p $DIR1/$tdir
3244         if [ $MDSCOUNT -ge 2 ]; then
3245                 local MDTIDX=1
3246                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
3247                         error "Create remote directory failed"
3248         else
3249                 mkdir -p $DIR1/$test_dir
3250         fi
3251         cd $DIR2/$test_dir || error "cd directory failed"
3252         rm -rf $DIR1/$test_dir || error "unlink directory failed"
3253
3254         cd $DIR2/$tdir || error "exit directory"
3255 }
3256 run_test 70a "cd directory && rm directory"
3257
3258 test_70b() { # LU-2781
3259         local i
3260         mkdir -p $DIR1/$tdir
3261
3262         touch $DIR1/$tdir/file
3263         for ((i = 0; i < 32; i++)); do
3264             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
3265         done
3266         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
3267
3268         touch $DIR1/$tdir/file
3269         $LFS mkdir -i0 $DIR1/$tdir/test_dir
3270         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
3271         rm -rf $DIR1/$tdir/test_dir ||
3272                 error "cannot remove directory after rm_entry"
3273         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
3274 }
3275 run_test 70b "remove files after calling rm_entry"
3276
3277 test_71a() {
3278         [[ "$MDS1_VERSION" -lt $(version_code 2.1.6) ]] &&
3279                 skip "Need MDS version at least 2.1.6"
3280
3281         # Patch not applied to 2.2 and 2.3 branches
3282         [[ "$MDS1_VERSION" -ge $(version_code 2.2.0) ]] &&
3283         [[ "$MDS1_VERSION" -lt $(version_code 2.4.0) ]] &&
3284                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0"
3285
3286         checkfiemap --test ||
3287                 skip "checkfiemap not runnable: $?"
3288         # write data this way: hole - data - hole - data
3289         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
3290         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tfile) + 1)))" = \
3291                 "zfs" ] &&
3292                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3293         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3294         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
3295         stat $DIR2/$tfile
3296         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3297         echo $can1
3298         checkfiemap $DIR2/$tfile 81920 ||
3299                 error "data is not flushed from client"
3300         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3301         echo $can2
3302
3303         # common case of "create file, copy file" on a single node
3304         # should not flush data from ost
3305         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
3306         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3307         stat $DIR1/$tfile
3308         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3309         echo $can3
3310         checkfiemap $DIR1/$tfile 81920 ||
3311         error 4
3312         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3313         echo $can2
3314         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
3315 }
3316 run_test 71a "correct file map just after write operation is finished"
3317
3318 test_71b() {
3319         [[ "$MDS1_VERSION" -lt $(version_code 2.1.6) ]] &&
3320                 skip "Need MDS version at least 2.1.6"
3321
3322         # Patch not applied to 2.2 and 2.3 branches
3323         [[ "$MDS1_VERSION" -ge $(version_code 2.2.0) ]] &&
3324         [[ "$MDS1_VERSION" -lt $(version_code 2.4.0) ]] &&
3325                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0"
3326         [[ $OSTCOUNT -ge 2 ]] || skip "needs >= 2 OSTs"
3327
3328         checkfiemap --test ||
3329                 skip "error $?: checkfiemap failed"
3330
3331         mkdir -p $DIR1/$tdir
3332
3333         $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
3334         dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
3335         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tdir/$tfile) + 1)))" = \
3336                 "zfs" ] &&
3337                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3338         checkfiemap $DIR1/$tdir/$tfile 40960 || error "checkfiemap failed"
3339 }
3340 run_test 71b "check fiemap support for stripecount > 1"
3341
3342 test_72() {
3343         local p="$TMP/sanityN-$TESTNAME.parameters"
3344         local tlink1
3345         local tlink2
3346         save_lustre_params client "llite.*.xattr_cache" > $p
3347         lctl set_param llite.*.xattr_cache 1 ||
3348                 { skip "xattr cache is not supported"; return 0; }
3349
3350         touch $DIR1/$tfile
3351         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3352                 error "setfattr1 failed"
3353         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
3354                 error "getfattr1 failed"
3355         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
3356                 error "setfattr2 failed"
3357         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
3358                 error "getfattr2 failed"
3359
3360         # check that trusted.link is consistent
3361         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3362         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
3363         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3364         echo "$tlink1 $tlink2"
3365         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
3366
3367         rm -f $DIR2/$tfile
3368
3369         restore_lustre_params < $p
3370         rm -f $p
3371 }
3372 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
3373
3374 test_73() {
3375         local p="$TMP/sanityN-$TESTNAME.parameters"
3376         save_lustre_params client "llite.*.xattr_cache" > $p
3377         lctl set_param llite.*.xattr_cache 1 ||
3378                 { skip "xattr cache is not supported"; return 0; }
3379
3380         touch $DIR1/$tfile
3381         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3382                 error "setfattr1 failed"
3383         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
3384         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
3385         clear_stats llite.*.stats
3386         # PR lock should be cached by now on both clients
3387         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
3388         # 2 hits for getfattr(0)+getfattr(size)
3389         [ $(calc_stats llite.*.stats getxattr_hits) -eq 2 ] ||
3390                 error "not cached in $DIR1"
3391         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
3392         # 4 hits for more getfattr(0)+getfattr(size)
3393         [ $(calc_stats llite.*.stats getxattr_hits) -eq 4 ] ||
3394                 error "not cached in $DIR2"
3395         rm -f $DIR2/$tfile
3396
3397         restore_lustre_params < $p
3398         rm -f $p
3399 }
3400 run_test 73 "getxattr should not cause xattr lock cancellation"
3401
3402 test_74() {
3403         [ "$MDS1_VERSION" -lt $(version_code 2.4.93) ] &&
3404                 skip "Need MDS version at least 2.4.93"
3405
3406         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
3407         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
3408         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
3409 }
3410 run_test 74 "flock deadlock: different mounts =============="
3411
3412 # LU-3889
3413 test_75() {
3414         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
3415         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
3416         cancel_lru_locks osc
3417
3418         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
3419         sync
3420
3421         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
3422         $LCTL set_param fail_loc=0x31d
3423         stat -c %s $DIR1/$tfile &
3424         local pid=$!
3425         sleep 1
3426         kill -9 $pid
3427
3428         # For bad lock error handler we should ASSERT and got kernel panic here
3429         sleep 4
3430         $LCTL set_param fail_loc=0
3431 }
3432 run_test 75 "osc: upcall after unuse lock==================="
3433
3434 test_76() { #LU-946
3435         [[ "$MDS1_VERSION" -lt $(version_code 2.5.53) ]] &&
3436                 skip "Need MDS version at least 2.5.53"
3437
3438         remote_mds_nodsh && skip "remote MDS with nodsh"
3439         local fcount=$((MDSCOUNT * 256))
3440         declare -a fd_list
3441         declare -a fid_list
3442
3443         if remote_mds; then
3444                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
3445         else
3446                 nid="0@lo"
3447         fi
3448
3449         rm -rf $DIR/$tdir
3450         test_mkdir $DIR/$tdir
3451
3452         # drop all open locks and close any cached "open" files on the client
3453         cancel_lru_locks mdc
3454
3455         local open_fids_cmd="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
3456         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3457         local already=${#fid_list[@]}
3458         for (( i = 0; i < $already; i++ )) ; do
3459                 log "already open[$i]: $($LFS fid2path $DIR2 ${fid_list[i]})"
3460         done
3461
3462         echo -n "opening files: "
3463         ulimit -n $((fcount + 50))
3464         for ((i = 0; i < $fcount; i++)); do
3465                 touch $DIR/$tdir/f_$i
3466                 local fd=$(free_fd ${fd_list[i]})
3467                 local open_cmd="exec $fd<$DIR/$tdir/f_$i"
3468                 eval $open_cmd
3469
3470                 fd_list[i]=$fd
3471
3472                 (( $i % 32 == 0 )) && echo -n "."
3473         done
3474         echo
3475
3476         fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3477
3478         # Possible errors in openfiles FID list.
3479         # 1. Missing FIDs. Check 1
3480         # 2. Extra FIDs. Check 1
3481         # 3. Duplicated FID. Check 2
3482         # 4. Invalid FIDs. Check 2
3483         # 5. Valid FID, points to some other file. Check 3
3484
3485         # Check 1
3486         [ ${#fid_list[@]} -ne $((fcount + already)) ] &&
3487                 error "${#fid_list[@]} != $fcount (+$already old) open files"
3488
3489         echo -n "closing files: "
3490         for (( fd = 0, fid = 0; fd < $fcount; fd++, fid++ )) ; do
3491                 local close_cmd="exec ${fd_list[fd]}<&-"
3492                 eval $close_cmd
3493                 filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3494
3495                 while [[ ! "$filename" =~ "$DIR2/$tdir/f_" ]]; do
3496                         echo "skip old open file $filename"
3497                         ((fid++))
3498                         filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3499                 done
3500
3501                 # Check 2
3502                 rm --interactive=no $filename
3503                 [ $? -ne 0 ] &&
3504                         error "Nonexisting fid ${fid_list[fid]} listed."
3505                 (( $fd % 32 == 0 )) && echo -n "."
3506         done
3507         echo
3508
3509         # Check 3
3510         ls_op=$(ls $DIR2/$tdir | wc -l)
3511         [ $ls_op -ne 0 ] &&
3512                 error "Some openfiles are missing in lproc output"
3513
3514         rm -rf $DIR/$tdir
3515 }
3516 run_test 76 "Verify MDT open_files listing"
3517
3518 nrs_write_read() {
3519         local n=16
3520         local dir=$DIR/$tdir
3521         local myRUNAS="$1"
3522
3523         mkdir $dir || error "mkdir $dir failed"
3524         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3525         chmod 777 $dir
3526
3527         do_nodes $CLIENTS $myRUNAS \
3528                 dd if=/dev/zero of="$dir/nrs_r_\$HOSTNAME" bs=1M count=$n ||
3529                 error "dd at 0 on client failed (1)"
3530
3531         do_nodes $CLIENTS $myRUNAS \
3532                 "declare -a pids_w;
3533                 for ((i = 0; i < $n; i++)); do
3534                         dd if=/dev/zero of=$dir/nrs_w_\$HOSTNAME bs=1M \
3535 seek=\\\$i count=1 conv=notrunc &
3536                         pids_w[\\\$i]=\\\$!;
3537                 done;
3538                 rc_w=0;
3539                 for ((i = 0; i < $n; i++)); do
3540                         wait \\\${pids_w[\\\$i]};
3541                         newrc=\\\$?;
3542                         [ \\\$newrc -gt \\\$rc_w ] && rc_w=\\\$newrc;
3543                 done;
3544                 exit \\\$rc_w" &
3545         local pid_w=$!
3546         do_nodes $CLIENTS sync;
3547         cancel_lru_locks osc
3548
3549         do_nodes $CLIENTS $myRUNAS \
3550                 "declare -a pids_r;
3551                 for ((i = 0; i < $n; i++)); do
3552                         dd if=$dir/nrs_r_\$HOSTNAME bs=1M of=/dev/null \
3553 seek=\\\$i count=1 &
3554                         pids_r[\\\$i]=\\\$!;
3555                 done;
3556                 rc_r=0;
3557                 for ((i = 0; i < $n; i++)); do
3558                         wait \\\${pids_r[\\\$i]};
3559                         newrc=\\\$?;
3560                         [ \\\$newrc -gt \\\$rc_r ] && rc_r=\\\$newrc;
3561                 done;
3562                 exit \\\$rc_r" &
3563         local pid_r=$!
3564         cancel_lru_locks osc
3565
3566         wait $pid_w || error "dd (write) failed (2)"
3567         wait $pid_r || error "dd (read) failed (3)"
3568         rm -rvf $dir || error "rm -rf $dir failed"
3569 }
3570
3571 test_77a() { #LU-3266
3572         local rc
3573
3574         oss=$(comma_list $(osts_nodes))
3575         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo" ||
3576                 rc=$?
3577         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3578         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3579         nrs_write_read
3580
3581         return 0
3582 }
3583 run_test 77a "check FIFO NRS policy"
3584
3585 test_77b() { #LU-3266
3586         local rc
3587
3588         oss=$(comma_list $(osts_nodes))
3589
3590         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3591                 ost.OSS.*.nrs_crrn_quantum=1 || rc=$?
3592         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3593         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 1"
3594
3595         echo "policy: crr-n, crrn_quantum 1"
3596         nrs_write_read
3597
3598         do_nodes $oss lctl set_param \
3599                 ost.OSS.*.nrs_crrn_quantum=64 || rc=$?
3600         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 64"
3601
3602         echo "policy: crr-n, crrn_quantum 64"
3603         nrs_write_read
3604
3605         # cleanup
3606         do_nodes $oss lctl set_param \
3607                 ost.OSS.ost_io.nrs_policies="fifo" || rc=$?
3608         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3609         return 0
3610 }
3611 run_test 77b "check CRR-N NRS policy"
3612
3613 orr_trr() {
3614         local policy=$1
3615
3616         oss=$(comma_list $(osts_nodes))
3617
3618         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3619                 ost.OSS.*.nrs_"$policy"_quantum=1 \
3620                 ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3621                 ost.OSS.*.nrs_"$policy"_supported="reads" || return $?
3622
3623         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type " \
3624                 "physical, ${policy}_supported reads"
3625         nrs_write_read
3626
3627         do_nodes $oss lctl set_param \
3628                 ost.OSS.*.nrs_${policy}_supported="writes" \
3629                 ost.OSS.*.nrs_${policy}_quantum=64 || return $?
3630
3631         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3632                 "physical, ${policy}_supported writes"
3633         nrs_write_read
3634
3635         do_nodes $oss lctl set_param \
3636                 ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3637                 ost.OSS.*.nrs_${policy}_offset_type="logical" || return $?
3638         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3639                 "logical, ${policy}_supported reads_and_writes"
3640         nrs_write_read
3641
3642         # cleanup
3643         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo" ||
3644                 return $?
3645         return 0
3646 }
3647
3648 test_77c() { #LU-3266
3649         local rc
3650         orr_trr "orr" || rc=$?
3651         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3652         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3653         return 0
3654 }
3655 run_test 77c "check ORR NRS policy"
3656
3657 test_77d() { #LU-3266
3658         local rc
3659         orr_trr "trr" || rc=$?
3660         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3661         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3662         return 0
3663 }
3664 run_test 77d "check TRR nrs policy"
3665
3666 tbf_rule_operate()
3667 {
3668         local facet=$1
3669         shift 1
3670
3671         do_facet $facet lctl set_param \
3672                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3673         [ $? -ne 0 ] &&
3674                 error "failed to run operate '$*' on TBF rules"
3675 }
3676
3677 cleanup_tbf_verify()
3678 {
3679         local rc=0
3680         trap 0
3681         echo "cleanup_tbf $DIR/$tdir"
3682         rm -rf $DIR/$tdir
3683         rc=$?
3684         wait_delete_completed
3685         return $rc
3686 }
3687
3688 tbf_verify() {
3689         local dir=$DIR/$tdir
3690         local client1=${CLIENT1:-$(hostname)}
3691         local myRUNAS="$3"
3692
3693         local np=$(check_cpt_number ost1)
3694         [ $np -gt 0 ] || error "CPU partitions should not be $np."
3695         echo "cpu_npartitions on ost1 is $np"
3696
3697         mkdir $dir || error "mkdir $dir failed"
3698         $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
3699         chmod 777 $dir
3700
3701         trap cleanup_tbf_verify EXIT
3702         echo "Limited write rate: $1, read rate: $2"
3703         echo "Verify the write rate is under TBF control"
3704         local start=$SECONDS
3705         do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
3706                 bs=1M count=100 oflag=direct 2>&1
3707         local runtime=$((SECONDS - start + 1))
3708         local rate=$(bc <<< "scale=6; 100 / $runtime")
3709         echo "Write runtime is $runtime s, speed is $rate IOPS"
3710
3711         # verify the write rate does not exceed TBF rate limit
3712         [ $(bc <<< "$rate < 1.1 * $np * $1") -eq 1 ] ||
3713                 error "The write rate ($rate) exceeds 110% of rate limit ($1 * $np)"
3714
3715         cancel_lru_locks osc
3716
3717         echo "Verify the read rate is under TBF control"
3718         start=$SECONDS
3719         do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
3720                 bs=1M count=100 iflag=direct 2>&1
3721         runtime=$((SECONDS - start + 1))
3722         rate=$(bc <<< "scale=6; 100 / $runtime")
3723         echo "Read runtime is $runtime s, speed is $rate IOPS"
3724
3725         # verify the read rate does not exceed TBF rate limit
3726         [ $(bc <<< "$rate < 1.1 * $np * $2") -eq 1 ] ||
3727                 error "The read rate ($rate) exceeds 110% of rate limit ($2 * $np)"
3728
3729         cancel_lru_locks osc
3730         cleanup_tbf_verify || error "rm -rf $dir failed"
3731 }
3732
3733 test_77e() {
3734         local rc
3735
3736         oss=$(comma_list $(osts_nodes))
3737
3738         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3739                 rc=$?
3740         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3741         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3742
3743         local idis
3744         local rateis
3745         if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
3746                 idis="nid="
3747                 rateis="rate="
3748         fi
3749
3750         # Only operate rules on ost1 since OSTs might run on the same OSS
3751         # Add some rules
3752         tbf_rule_operate ost1 "start\ localhost\ ${idis}{0@lo}\ ${rateis}1000"
3753         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3754         local client_nids=$(nids_list $address "\\")
3755         tbf_rule_operate ost1 "start\ clients\ ${idis}{$client_nids}\ ${rateis}100"
3756         tbf_rule_operate ost1 "start\ others\ ${idis}{*.*.*.*@$NETTYPE}\ ${rateis}50"
3757         nrs_write_read
3758
3759         # Change the rules
3760         tbf_rule_operate ost1 "change\ localhost\ ${rateis}1001"
3761         tbf_rule_operate ost1 "change\ clients\ ${rateis}101"
3762         tbf_rule_operate ost1 "change\ others\ ${rateis}51"
3763         nrs_write_read
3764
3765         # Stop the rules
3766         tbf_rule_operate ost1 "stop\ localhost"
3767         tbf_rule_operate ost1 "stop\ clients"
3768         tbf_rule_operate ost1 "stop\ others"
3769         nrs_write_read
3770
3771         # Cleanup the TBF policy
3772         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3773         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3774         nrs_write_read
3775         return 0
3776 }
3777 run_test 77e "check TBF NID nrs policy"
3778
3779 test_77f() {
3780         local rc
3781
3782         oss=$(comma_list $(osts_nodes))
3783
3784         do_nodes $oss $LCTL set_param \
3785                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3786         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3787         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3788
3789         # Configure jobid_var
3790         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3791         rc=$?
3792         [[ $rc -eq 3 ]] && skip "jobid_var not found" && return
3793         [[ $rc -ne 0 ]] && error "failed to get param jobid_var"
3794         if [ $saved_jobid_var != procname_uid ]; then
3795                 set_persistent_param_and_check client \
3796                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3797         fi
3798
3799         local idis
3800         local rateis
3801         if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
3802                 idis="jobid="
3803                 rateis="rate="
3804         fi
3805
3806         # Only operate rules on ost1 since OSTs might run on the same OSS
3807         # Add some rules
3808         tbf_rule_operate ost1 "start\ runas\ ${idis}{iozone.$RUNAS_ID\ dd.$RUNAS_ID\ tiotest.$RUNAS_ID}\ ${rateis}1000"
3809         tbf_rule_operate ost1 "start\ iozone_runas\ ${idis}{iozone.$RUNAS_ID}\ ${rateis}100"
3810         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3811         nrs_write_read "$RUNAS"
3812
3813         # Change the rules
3814         tbf_rule_operate ost1 "change\ runas\ ${rateis}1001"
3815         tbf_rule_operate ost1 "change\ iozone_runas\ ${rateis}101"
3816         tbf_rule_operate ost1 "change\ dd_runas\ ${rateis}51"
3817         nrs_write_read "$RUNAS"
3818
3819         # Stop the rules
3820         tbf_rule_operate ost1 "stop\ runas"
3821         tbf_rule_operate ost1 "stop\ iozone_runas"
3822         tbf_rule_operate ost1 "stop\ dd_runas"
3823         nrs_write_read "$RUNAS"
3824
3825         # Cleanup the TBF policy
3826         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3827         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3828         nrs_write_read "$RUNAS"
3829
3830         local current_jobid_var=$($LCTL get_param -n jobid_var)
3831         [[ $? -ne 0 ]] && error "failed to get param jobid_var"
3832         if [ $saved_jobid_var != $current_jobid_var ]; then
3833                 set_persistent_param_and_check client \
3834                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3835         fi
3836         return 0
3837 }
3838 run_test 77f "check TBF JobID nrs policy"
3839
3840 test_77g() {
3841         local rc=0
3842
3843         oss=$(comma_list $(osts_nodes))
3844
3845         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3846                 rc=$?
3847         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3848         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3849
3850         do_nodes $oss lctl set_param \
3851                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3852         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3853
3854         local idis
3855         local rateis
3856         if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
3857                 idis="jobid="
3858                 rateis="rate="
3859         fi
3860
3861         # Add a rule that only valid for Jobid TBF. If direct change between
3862         # TBF types is not supported, this operation will fail.
3863         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3864
3865         # Cleanup the TBF policy
3866         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3867         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3868         return 0
3869 }
3870 run_test 77g "Change TBF type directly"
3871
3872 test_77h() {
3873         [ "$OST1_VERSION" -ge $(version_code 2.8.55) ] ||
3874                 skip "Need OST version at least 2.8.55"
3875
3876         local old_policy=$(do_facet ost1 \
3877                 lctl get_param ost.OSS.ost_io.nrs_policies)
3878         local new_policy
3879
3880         do_facet ost1 lctl set_param \
3881                 ost.OSS.ost_io.nrs_policies="abc"
3882         [ $? -eq 0 ] && error "should return error"
3883
3884         do_facet ost1 lctl set_param \
3885                 ost.OSS.ost_io.nrs_policies="tbf\ abc"
3886         [ $? -eq 0 ] && error "should return error"
3887
3888         do_facet ost1 lctl set_param \
3889                 ost.OSS.ost_io.nrs_policies="tbf\ reg\ abc"
3890         [ $? -eq 0 ] && error "should return error"
3891
3892         do_facet ost1 lctl set_param \
3893                 ost.OSS.ost_io.nrs_policies="tbf\ abc\ efg"
3894         [ $? -eq 0 ] && error "should return error"
3895
3896         new_policy=$(do_facet ost1 lctl get_param ost.OSS.ost_io.nrs_policies)
3897         [ $? -eq 0 ] || error "shouldn't LBUG"
3898
3899         [ "$old_policy" = "$new_policy" ] || error "NRS policy should be same"
3900
3901         return 0
3902 }
3903 run_test 77h "Wrong policy name should report error, not LBUG"
3904
3905 tbf_rule_check()
3906 {
3907         local facet=$1
3908         local expected=$2
3909         local error_message=$3
3910         local rule_number=0
3911         for rule in $expected; do
3912                 rule_number=$((rule_number + 1))
3913         done
3914         local stop_line=$(($rule_number + 3))
3915         local awk_command="awk 'NR >= 4 && NR <= $stop_line {print \$1}'"
3916
3917         local output=$(do_facet $facet lctl get_param \
3918                 ost.OSS.ost_io.nrs_tbf_rule |
3919                 eval $awk_command |
3920                 tr "\n" " " |
3921                 sed 's/[ ]*$//')
3922         if [ "$output" != "$expected" ]; then
3923                 error "$error_message, expected '$expected', got '$output'"
3924         fi
3925 }
3926
3927 test_77i() {
3928         [ "$OST1_VERSION" -ge $(version_code 2.8.55) ] ||
3929                 skip "Need OST version at least 2.8.55"
3930
3931         for i in $(seq 1 $OSTCOUNT)
3932         do
3933                 do_facet ost"$i" lctl set_param \
3934                         ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3935                 [ $? -ne 0 ] &&
3936                         error "failed to set TBF policy"
3937         done
3938
3939         tbf_rule_check ost1 "default" "error before inserting any rule"
3940
3941         tbf_rule_operate ost1 "start\ before\ jobid={jobid}\ rate=1000"
3942         tbf_rule_check ost1 "before default" \
3943                 "error when inserting rule 'before'"
3944
3945         tbf_rule_operate ost1 "start\ after\ jobid={jobid}\ rate=1000\ rank=default"
3946         tbf_rule_check ost1 "before after default" \
3947                 "error when inserting rule 'after'"
3948
3949         tbf_rule_operate ost1 "start\ target\ jobid={jobid}\ rate=1000\ rank=after"
3950         tbf_rule_check ost1 "before target after default" \
3951                 "error when inserting rule 'target'"
3952
3953         echo "Move before itself"
3954         tbf_rule_operate ost1 "change\ target\ rank=target"
3955         tbf_rule_check ost1 "before target after default" \
3956                 "error when moving before itself"
3957
3958         echo "Move to higher rank"
3959         tbf_rule_operate ost1 "change\ target\ rank=before"
3960         tbf_rule_check ost1 "target before after default" \
3961                 "error when moving to higher rank"
3962
3963         echo "Move to lower rank"
3964         tbf_rule_operate ost1 "change\ target\ rank=after"
3965         tbf_rule_check ost1 "before target after default" \
3966                 "error when moving to lower rank"
3967
3968         echo "Move before default"
3969         tbf_rule_operate ost1 "change\ target\ rank=default"
3970         tbf_rule_check ost1 "before after target default" \
3971                 error "error when moving before default"
3972
3973         # Cleanup the TBF policy
3974         do_nodes $(comma_list $(osts_nodes)) \
3975                 $LCTL set_param ost.OSS.ost_io.nrs_policies=fifo
3976         return 0
3977 }
3978 run_test 77i "Change rank of TBF rule"
3979
3980 test_77j() {
3981         local idis
3982         local rateis
3983
3984         [ "$OST1_VERSION" -ge $(version_code 2.9.53) ] ||
3985                 skip "Need OST version at least 2.9.53"
3986         if [ "$OST1_VERSION" -ge $(version_code 2.8.60) ]; then
3987                 idis="opcode="
3988                 rateis="rate="
3989         fi
3990
3991         do_nodes $(comma_list $(osts_nodes)) \
3992                 lctl set_param jobid_var=procname_uid \
3993                         ost.OSS.ost_io.nrs_policies="tbf\ opcode" \
3994                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_r\ ${idis}{ost_read}\ ${rateis}5" \
3995                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_w\ ${idis}{ost_write}\ ${rateis}20"
3996         [ $? -ne 0 ] && error "failed to set TBF OPCode policy"
3997
3998         nrs_write_read
3999         tbf_verify 20 5
4000
4001         do_nodes $(comma_list $(osts_nodes)) \
4002                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_r" \
4003                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_w" \
4004                         ost.OSS.ost_io.nrs_policies="fifo"
4005
4006         # sleep 3 seconds to wait the tbf policy stop completely,
4007         # or the next test case is possible get -EAGAIN when
4008         # setting the tbf policy
4009         sleep 3
4010 }
4011 run_test 77j "check TBF-OPCode NRS policy"
4012
4013 test_id() {
4014         local idstr="${1}id"
4015         local policy="${idstr}={$2}"
4016         local rate="rate=$3"
4017
4018         do_nodes $(comma_list $(osts_nodes)) \
4019                 lctl set_param jobid_var=procname_uid \
4020                         ost.OSS.ost_io.nrs_policies="tbf\ ${idstr}" \
4021                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_${idstr}\ ${policy}\ ${rate}"
4022         [ $? -ne 0 ] && error "failed to set tbf ${idstr} policy"
4023
4024         nrs_write_read "runas $4"
4025         tbf_verify $3 $3 "runas $4"
4026
4027         do_nodes $(comma_list $(osts_nodes)) \
4028                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
4029                         ost.OSS.ost_io.nrs_policies="fifo"
4030
4031         # sleep 3 seconds to wait the tbf policy stop completely,
4032         # or the next test case is possible get -eagain when
4033         # setting the tbf policy
4034         sleep 3
4035 }
4036
4037 test_77ja(){
4038         if [ "$OST1_VERSION" -lt $(version_code 2.11.50) ]; then
4039                 skip "Need OST version at least 2.11.50"
4040         fi
4041
4042         test_id "u" "500" "5" "-u 500"
4043         test_id "g" "500" "5" "-u 500 -g 500"
4044 }
4045 run_test 77ja "check TBF-UID/GID NRS policy"
4046
4047 cleanup_77k()
4048 {
4049         local rule_lists=$1
4050         local old_nrs=$2
4051
4052         trap 0
4053         for rule in $rule_lists; do
4054                 do_nodes $(comma_list $(osts_nodes)) \
4055                         lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ $rule"
4056         done
4057
4058         do_nodes $(comma_list $(osts_nodes)) \
4059                 lctl set_param ost.OSS.ost_io.nrs_policies="$old_nrs"
4060
4061         sleep 3
4062 }
4063
4064 test_77k() {
4065         [[ "$OST1_VERSION" -ge $(version_code 2.9.53) ]] ||
4066                 skip "Need OST version at least 2.9.53"
4067
4068         do_nodes $(comma_list $(osts_nodes)) \
4069                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf" \
4070                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ jobid={dd.$RUNAS_ID}\&opcode={ost_write}\ rate=20" \
4071                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ jobid={dd.$RUNAS_ID}\&opcode={ost_read}\ rate=10"
4072
4073         nrs_write_read "$RUNAS"
4074         tbf_verify 20 10 "$RUNAS"
4075
4076         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
4077         local client_nids=$(nids_list $address "\\")
4078         do_nodes $(comma_list $(osts_nodes)) \
4079                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
4080                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
4081                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ nid={0@lo\ $client_nids}\&opcode={ost_write}\ rate=20" \
4082                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ nid={0@lo\ $client_nids}\&opcode={ost_read}\ rate=10"
4083
4084         nrs_write_read
4085         tbf_verify 20 10
4086
4087         do_nodes $(comma_list $(osts_nodes)) \
4088                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
4089                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
4090                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext\ nid={0@lo\ $client_nids}\&jobid={dd.$RUNAS_ID}\ rate=20"
4091
4092         nrs_write_read "$RUNAS"
4093         tbf_verify 20 20 "$RUNAS"
4094
4095         do_nodes $(comma_list $(osts_nodes)) \
4096                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext" \
4097                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ jobid={dd.$RUNAS_ID},opcode={ost_write}\ rate=20" \
4098                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ jobid={dd.$RUNAS_ID},opcode={ost_read}\ rate=10"
4099
4100         nrs_write_read "$RUNAS"
4101         # with parameter "RUNAS", it will match the latest rule
4102         # "ext_b" first, so the limited write rate is 10.
4103         tbf_verify 10 10 "$RUNAS"
4104         tbf_verify 20 10
4105
4106         trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
4107
4108         [[ "$OST1_VERSION" -ge $(version_code 2.10.58) ]] ||
4109                 skip "Need OST version at least 2.10.58"
4110
4111         do_nodes $(comma_list $(osts_nodes)) \
4112                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_a" \
4113                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_b" \
4114                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={500}\&gid={1000}\ rate=5"
4115         nrs_write_read "runas -u 500 -g 1000"
4116         tbf_verify 5 5 "runas -u 500 -g 1000"
4117
4118         do_nodes $(comma_list $(osts_nodes)) \
4119                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ug" \
4120                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={500}\&opcode={ost_write}\ rate=20" \
4121                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={500}\&opcode={ost_read}\ rate=10"
4122
4123         nrs_write_read "runas -u 500"
4124         tbf_verify 20 10 "runas -u 500"
4125
4126         do_nodes $(comma_list $(osts_nodes)) \
4127                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_uw" \
4128                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ur" \
4129                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={500},opcode={ost_write}\ rate=20" \
4130                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={500},opcode={ost_read}\ rate=10"
4131         nrs_write_read "runas -u 500"
4132         tbf_verify 10 10 "runas -u 500"
4133         tbf_verify 20 10 "runas -u 500"
4134         cleanup_77k "ext_a ext_b" "fifo"
4135 }
4136 run_test 77k "check TBF policy with NID/JobID/OPCode expression"
4137
4138 test_77l() {
4139         [[ "$OST1_VERSION" -ge $(version_code 2.10.56) ]] ||
4140                 skip "Need OST version at least 2.10.56"
4141
4142         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
4143         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf"
4144
4145         local output=$(do_facet ost1 lctl get_param \
4146                         ost.OSS.ost_io.nrs_policies | \
4147                         awk '/name: tbf/ {print;exit}' | \
4148                         awk -F ': ' '{print $2}')
4149
4150         if [ "$output" != "tbf" ]; then
4151                 error "The generic TBF output is '$output', not 'tbf'"
4152         fi
4153
4154         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4155 }
4156 run_test 77l "check the output of NRS policies for generic TBF"
4157
4158 test_77m() {
4159         if [ "$OST1_VERSION" -lt $(version_code 2.9.54) ]; then
4160                 skip "Need OST version at least 2.9.54"
4161         fi
4162
4163         local dir=$DIR/$tdir
4164
4165         mkdir $dir || error "mkdir $dir failed"
4166         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
4167         chmod 777 $dir
4168
4169         local nodes=$(comma_list $(osts_nodes))
4170         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies=delay \
4171                                        ost.OSS.ost_io.nrs_delay_min=4 \
4172                                        ost.OSS.ost_io.nrs_delay_max=4 \
4173                                        ost.OSS.ost_io.nrs_delay_pct=100
4174         [ $? -ne 0 ] && error "Failed to set delay policy"
4175
4176         local start=$SECONDS
4177         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
4178                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=1 \
4179                    oflag=direct conv=fdatasync ||
4180                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4181                   error "dd on client failed (1)"; }
4182         local elapsed=$((SECONDS - start))
4183
4184         # NRS delay doesn't do sub-second timing, so a request enqueued at
4185         # 0.9 seconds can be dequeued at 4.0
4186         [ $elapsed -lt 3 ] &&
4187                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4188                   error "Single 1M write should take at least 3 seconds"; }
4189
4190         start=$SECONDS
4191         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
4192                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=10 \
4193                    oflag=direct conv=fdatasync ||
4194                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4195                   error "dd on client failed (2)"; }
4196         elapsed=$((SECONDS - start))
4197
4198         [ $elapsed -lt 30 ] &&
4199                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4200                   error "Ten 1M writes should take at least 30 seconds"; }
4201
4202         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4203         [ $? -ne 0 ] && error "failed to set policy back to fifo"
4204
4205         return 0
4206 }
4207 run_test 77m "check NRS Delay slows write RPC processing"
4208
4209 test_77n() { #LU-10802
4210         if [ "$OST1_VERSION" -lt $(version_code 2.10.58) ]; then
4211                 skip "Need OST version at least 2.10.58"
4212         fi
4213
4214         # Configure jobid_var
4215         local saved_jobid_var=$($LCTL get_param -n jobid_var)
4216         if [ $saved_jobid_var != procname_uid ]; then
4217                 set_persistent_param_and_check client \
4218                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
4219         fi
4220
4221         do_nodes $(comma_list $(osts_nodes)) \
4222                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid" \
4223                         ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4224                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={*.$RUNAS_ID}\ rate=20"
4225
4226         nrs_write_read
4227         tbf_verify 20 20 "$RUNAS"
4228
4229         do_nodes $(comma_list $(osts_nodes)) \
4230                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4231                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={dd.*}\ rate=20"
4232
4233         nrs_write_read
4234         tbf_verify 20 20
4235
4236         do_nodes $(comma_list $(osts_nodes)) \
4237                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4238                         ost.OSS.ost_io.nrs_policies="fifo"
4239
4240         sleep 3
4241
4242         local current_jobid_var=$($LCTL get_param -n jobid_var)
4243         if [ $saved_jobid_var != $current_jobid_var ]; then
4244                 set_persistent_param_and_check client \
4245                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
4246         fi
4247 }
4248 run_test 77n "check wildcard support for TBF JobID NRS policy"
4249
4250 test_78() { #LU-6673
4251         local rc
4252
4253         oss=$(comma_list $(osts_nodes))
4254         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
4255         do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
4256         rc=$?
4257         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
4258         # Valid return codes are:
4259         # 0: Tuning succeeded
4260         # ENODEV: Policy is still stopped
4261         # EAGAIN: Policy is being initialized
4262         [ $rc -eq 0 -o $rc -eq 19 -o $rc -eq 11 ] ||
4263                 error "Expected set_param to return 0|ENODEV|EAGAIN"
4264
4265         # Cleanup the ORR policy
4266         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4267         [ $? -ne 0 ] && error "failed to set policy back to fifo"
4268         return 0
4269 }
4270 run_test 78 "Enable policy and specify tunings right away"
4271
4272 test_79() {
4273         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4274         test_mkdir $DIR/$tdir
4275
4276         # Prevent interference from layout intent RPCs due to
4277         # asynchronous writeback. These will be tested in 130c below.
4278         do_nodes ${CLIENTS:-$HOSTNAME} sync
4279
4280         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
4281                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
4282
4283 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
4284         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
4285         local facet=mds$((mdtidx + 1))
4286         stat $DIR/$tdir
4287         set_nodes_failloc $(facet_active_host $facet) 0x80000160
4288         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null  &
4289         local pid=$!
4290         sleep 2
4291
4292 #define OBD_FAIL_MDS_GETXATTR_PACK       0x131
4293         set_nodes_failloc $(facet_active_host $facet) 0x80000131
4294
4295         wait $pid
4296         return 0
4297 }
4298 run_test 79 "xattr: intent error"
4299
4300 test_80a() {
4301         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4302         local MDTIDX=1
4303         local mdt_index
4304         local i
4305         local file
4306         local pid
4307
4308         mkdir -p $DIR1/$tdir/dir
4309         createmany -o $DIR1/$tdir/dir/f 10 ||
4310                 error "create files under remote dir failed $i"
4311
4312         cp /etc/passwd $DIR1/$tdir/$tfile
4313
4314         #migrate open file should fails
4315         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
4316         pid=$!
4317         # give multiop a chance to open
4318         sleep 1
4319
4320         $LFS migrate -m $MDTIDX $DIR1/$tdir &&
4321                 error "migrate open files should failed with open files"
4322
4323         kill -USR1 $pid
4324
4325         $LFS migrate -m $MDTIDX $DIR1/$tdir ||
4326                         error "migrate remote dir error"
4327
4328         echo "Finish migration, then checking.."
4329         for file in $(find $DIR1/$tdir); do
4330                 mdt_index=$($LFS getstripe -m $file)
4331                 [ $mdt_index == $MDTIDX ] ||
4332                         error "$file is not on MDT${MDTIDX}"
4333         done
4334
4335         diff /etc/passwd $DIR1/$tdir/$tfile ||
4336                 error "file different after migration"
4337
4338         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
4339 }
4340 run_test 80a "migrate directory when some children is being opened"
4341
4342 cleanup_80b() {
4343         trap 0
4344         kill -9 $migrate_pid
4345 }
4346
4347 test_80b() {
4348         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4349         local migrate_dir1=$DIR1/$tdir/migrate_dir
4350         local migrate_dir2=$DIR2/$tdir/migrate_dir
4351         local migrate_run=$LUSTRE/tests/migrate.sh
4352         local start_time
4353         local end_time
4354         local show_time=1
4355         local mdt_idx
4356         local rc=0
4357         local rc1=0
4358
4359         trap cleanup_80b EXIT
4360         #prepare migrate directory
4361         mkdir -p $migrate_dir1
4362         for F in {1,2,3,4,5}; do
4363                 echo "$F$F$F$F$F" > $migrate_dir1/file$F
4364                 echo "$F$F$F$F$F" > $DIR/$tdir/file$F
4365         done
4366
4367         #migrate the directories among MDTs
4368         (
4369                 while true; do
4370                         mdt_idx=$((RANDOM % MDSCOUNT))
4371                         $LFS migrate -m $mdt_idx $migrate_dir1 &>/dev/null ||
4372                                 rc=$?
4373                         [ $rc -ne 0 -o $rc -ne 16 ] || break
4374                 done
4375         ) &
4376         migrate_pid=$!
4377
4378         echo "start migration thread $migrate_pid"
4379         #Access the files at the same time
4380         start_time=$(date +%s)
4381         echo "accessing the migrating directory for 5 minutes..."
4382         while true; do
4383                 ls $migrate_dir2 > /dev/null || {
4384                         echo "read dir fails"
4385                         break
4386                 }
4387                 diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
4388                         echo "access file1 fails"
4389                         break
4390                 }
4391
4392                 cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
4393                         echo "access file2/3 fails"
4394                         break
4395                 }
4396
4397                 echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
4398                         echo "access file4 fails"
4399                         break
4400                 }
4401
4402                 stat $migrate_dir2/file5 > /dev/null || {
4403                         echo "stat file5 fails"
4404                         break
4405                 }
4406
4407                 touch $migrate_dir2/source_file > /dev/null || rc1=$?
4408                 [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4409                         echo "touch file failed with $rc1"
4410                         break;
4411                 }
4412
4413                 if [ -e $migrate_dir2/source_file ]; then
4414                         ln $migrate_dir2/source_file $migrate_dir2/link_file \
4415                                         &>/dev/null || rc1=$?
4416                         if [ -e $migrate_dir2/link_file ]; then
4417                                 rm -rf $migrate_dir2/link_file
4418                         fi
4419
4420                         mrename $migrate_dir2/source_file \
4421                                 $migrate_dir2/target_file &>/dev/null || rc1=$?
4422                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4423                                 echo "rename failed with $rc1"
4424                                 break
4425                         }
4426
4427                         if [ -e $migrate_dir2/target_file ]; then
4428                                 rm -rf $migrate_dir2/target_file &>/dev/null ||
4429                                                                 rc1=$?
4430                         else
4431                                 rm -rf $migrate_dir2/source_file &>/dev/null ||
4432                                                                 rc1=$?
4433                         fi
4434                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4435                                 echo "unlink failed with $rc1"
4436                                 break
4437                         }
4438                 fi
4439
4440                 end_time=$(date +%s)
4441                 duration=$((end_time - start_time))
4442                 if [ $((duration % 10)) -eq 0 ]; then
4443                         if [ $show_time -eq 1 ]; then
4444                                 echo "...$duration seconds"
4445                                 show_time=0
4446                         fi
4447                 else
4448                         show_time=1
4449                 fi
4450
4451                 kill -0 $migrate_pid || {
4452                         echo "migration stopped 1"
4453                         break
4454                 }
4455
4456                 [ $duration -ge 300 ] && break
4457         done
4458
4459         #check migration are still there
4460         kill -0 $migrate_pid || error "migration stopped 2"
4461         cleanup_80b
4462 }
4463 run_test 80b "Accessing directory during migration"
4464
4465 test_81a() {
4466         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4467
4468         rm -rf $DIR1/$tdir
4469
4470         mkdir -p $DIR1/$tdir
4471
4472         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
4473         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
4474
4475         cd $DIR1/$tdir
4476         touch d0/0      || error "create 0 failed"
4477         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
4478         stat d0/0       && error "stat mv filed succeed"
4479         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || error "rename d1/0 d0/0 failed"
4480         stat d0/0       || error "stat failed"
4481
4482         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
4483
4484         if [ $t -ne 3 ]; then
4485                 ls -ai $DIR1/$tdir/d0
4486                 error "expect 3 get $t"
4487         fi
4488
4489         return 0
4490 }
4491 run_test 81a "rename and stat under striped directory"
4492
4493 test_81b() {
4494         [ $MDSCOUNT -lt 2 ] &&
4495                 skip "We need at least 2 MDTs for this test"
4496
4497         local total
4498         local setattr_pid
4499
4500         total=1000
4501
4502         $LFS mkdir -c $MDSCOUNT $DIR1/$tdir || error "$LFS mkdir"
4503         createmany -o $DIR1/$tdir/$tfile. $total || error "createmany"
4504
4505         (
4506                 while true; do
4507                         touch $DIR1/$tdir
4508                 done
4509         ) &
4510         setattr_pid=$!
4511
4512         for i in $(seq $total); do
4513                 mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
4514                         > /dev/null
4515         done
4516
4517         kill -9 $setattr_pid
4518 }
4519 run_test 81b "rename under striped directory doesn't deadlock"
4520
4521 test_81c() {
4522         [ $MDSCOUNT -lt 4 ] && skip_env "needs >= 4 MDTs"
4523         [ $MDS1_VERSION -lt $(version_code 2.13.52) ] &&
4524                 skip "Need MDS version at least 2.13.52"
4525
4526         # source is local, source parent is remote
4527         $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4528         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4529         $LFS mkdir -i 3 $DIR1/${tdir}_src/sub || error "mkdir sub"
4530         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4531         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4532         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4533         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
4534         rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
4535
4536         # source is remote, source parent is local
4537         $LFS mkdir -i 3 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4538         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4539         $LFS mkdir -i 0 $DIR1/${tdir}_src/sub || error "mkdir sub"
4540         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4541         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4542         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4543         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
4544         rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
4545
4546         # source and source parent are remote
4547         $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4548         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4549         mkdir $DIR1/${tdir}_src/sub || error "mkdir sub"
4550         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4551         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4552         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4553         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
4554         rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
4555
4556         # source and source parent are remote, and source is remote object
4557         $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4558         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4559         $LFS mkdir -i 2 $DIR1/${tdir}_src/sub || error "mkdir sub"
4560         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4561         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4562         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4563         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone" || true
4564 }
4565 run_test 81c "rename revoke LOOKUP lock for remote object"
4566
4567 test_82() {
4568         [[ "$MDS1_VERSION" -gt $(version_code 2.6.91) ]] ||
4569                 skip "Need MDS version at least 2.6.92"
4570
4571         # Client 1 creates a file.
4572         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
4573         pid1=$!
4574         # Client 2 opens the file.
4575         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
4576         pid2=$!
4577         # Client 1 makes the file an orphan.
4578         rm $DIR1/$tfile || error "rm"
4579         # Client 2 sets EA "user.multiop".
4580         kill -s USR1 $pid2
4581         wait $pid2 || error "multiop 2"
4582         # Client 1 gets EA "user.multiop".  This used to fail because the EA
4583         # cache refill would get "trusted.link" from mdd_xattr_list() but
4584         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
4585         # 102q.
4586         kill -s USR1 $pid1
4587         wait $pid1 || error "multiop 1"
4588 }
4589 run_test 82 "fsetxattr and fgetxattr on orphan files"
4590
4591 test_83() {
4592         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4593         local pid1
4594         local pid2
4595
4596         (
4597                 cd $DIR1
4598                 while true; do
4599                         $LFS mkdir -i1 -c2 $tdir
4600                         rmdir $tdir
4601                 done
4602         ) &
4603         pid1=$!
4604         echo "start pid $pid1 to create/unlink striped directory"
4605
4606         # Access the directory at the same time
4607         (
4608                 cd $DIR2
4609                 while true; do
4610                         stat $tdir > /dev/null 2>&1
4611                 done
4612         ) &
4613         pid2=$!
4614         echo "start pid $pid2 to stat striped directory"
4615
4616         sleep 120
4617         kill $pid1 $pid2
4618         wait $pid1 $pid2
4619
4620         return 0
4621 }
4622 run_test 83 "access striped directory while it is being created/unlinked"
4623
4624 test_84() {
4625         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
4626                 skip "lustre < 2.12.55 does not contain LU-12485 fix"
4627
4628         local mtime
4629
4630         $MULTIOP $DIR/$tfile oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
4631                 error "create $tfile failed"
4632         mtime=$(stat -c%Y $DIR/$tfile)
4633         mtime=$((mtime + 200))
4634
4635         #define OBD_FAIL_OBD_0NLINK_RACE  0x60b
4636         do_facet mds1 $LCTL set_param fail_loc=0x8000060b
4637
4638         touch -c -m $mtime $DIR/$tfile &
4639         setattr_pid=$!
4640         # sleep a while to let 'touch' run first
4641         sleep 5
4642         rm -f $DIR2/$tfile || error "unlink $tfile failed"
4643
4644         # touch may fail
4645         wait $setattr_pid || true
4646 }
4647 run_test 84 "0-nlink race in lu_object_find()"
4648
4649 test_90() {
4650         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4651         local pid1
4652         local pid2
4653         local duration=180
4654
4655         [ "$SLOW" = "yes" ] && duration=600
4656         # Open/Create under striped directory
4657         (
4658                 cd $DIR1
4659                 while true; do
4660                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4661                         touch $tdir/f{0..3} > /dev/null 2>&1
4662                 done
4663         ) &
4664         pid1=$!
4665         echo "start pid $pid1 to open/create under striped directory"
4666
4667         # unlink the striped directory at the same time
4668         (
4669                 cd $DIR2
4670                 while true; do
4671                         rm -rf $tdir > /dev/null 2>&1
4672                 done
4673         ) &
4674         pid2=$!
4675         echo "start pid $pid2 to unlink striped directory"
4676
4677         sleep $duration
4678
4679         kill $pid1 $pid2
4680         wait $pid1 $pid2
4681
4682         return 0
4683 }
4684 run_test 90 "open/create and unlink striped directory"
4685
4686 test_91() {
4687         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4688         local pid1
4689         local pid2
4690         local duration=180
4691
4692         [ "$SLOW" = "yes" ] && duration=600
4693         # chmod striped directory
4694         (
4695                 cd $DIR1
4696                 while true; do
4697                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4698                         chmod go+w $tdir > /dev/null 2>&1
4699                 done
4700         ) &
4701         pid1=$!
4702         echo "start pid $pid1 to chmod striped directory"
4703
4704         # unlink the striped directory at the same time
4705         (
4706                 cd $DIR2
4707                 while true; do
4708                         rm -rf $tdir > /dev/null 2>&1
4709                 done
4710         ) &
4711         pid2=$!
4712         echo "start pid $pid2 to unlink striped directory"
4713
4714         sleep $duration
4715
4716         kill $pid1 $pid2
4717         wait $pid1 $pid2
4718
4719         return 0
4720 }
4721 run_test 91 "chmod and unlink striped directory"
4722
4723 test_92() {
4724         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4725
4726         local fd=$(free_fd)
4727         local cmd="exec $fd<$DIR1/$tdir"
4728         $LFS setdirstripe -c$MDSCOUNT $DIR1/$tdir || error "mkdir $tdir fails"
4729         eval $cmd
4730         cmd="exec $fd<&-"
4731         trap "eval $cmd" EXIT
4732         cd $DIR1/$tdir || error "cd $DIR1/$tdir fails"
4733         rmdir ../$tdir || error "rmdir ../$tdir fails"
4734
4735         #define OBD_FAIL_LLITE_NO_CHECK_DEAD  0x1408
4736         $LCTL set_param fail_loc=0x1408
4737         mkdir $DIR2/$tdir/dir && error "create dir succeeds"
4738         $LFS setdirstripe -i1 $DIR2/$tdir/remote_dir &&
4739                 error "create remote dir succeeds"
4740         $LCTL set_param fail_loc=0
4741         eval $cmd
4742         return 0
4743 }
4744 run_test 92 "create remote directory under orphan directory"
4745
4746 test_93() {
4747         local rc1=0
4748         local rc2=0
4749         local old_rr
4750
4751         mkdir -p $DIR1/$tfile-1/
4752         mkdir -p $DIR2/$tfile-2/
4753         local old_rr=$(do_facet $SINGLEMDS "$LCTL get_param -n \
4754                 lod.$FSNAME-MDT0000-*/qos_threshold_rr" | sed -e 's/%//')
4755         do_facet $SINGLEMDS "$LCTL set_param -n \
4756                 lod.$FSNAME-MDT0000-*/qos_threshold_rr=100"
4757         #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
4758         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x00000163"
4759
4760         $LFS setstripe -c -1 $DIR1/$tfile-1/file1 &
4761         local PID1=$!
4762         sleep 1
4763         $LFS setstripe -c -1 $DIR2/$tfile-2/file2 &
4764         local PID2=$!
4765         wait $PID2
4766         wait $PID1
4767         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
4768         do_facet $SINGLEMDS "$LCTL set_param -n \
4769                 lod.$FSNAME-MDT0000-*/qos_threshold_rr=$old_rr"
4770
4771         $LFS getstripe $DIR1/$tfile-1/file1
4772         rc1=$($LFS getstripe -q $DIR1/$tfile-1/file1 |
4773                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4774         $LFS getstripe $DIR2/$tfile-2/file2
4775         rc2=$($LFS getstripe -q $DIR2/$tfile-2/file2 |
4776                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4777         echo "rc1=$rc1 and rc2=$rc2 "
4778         [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
4779                 error "object allocate on same ost detected"
4780 }
4781 run_test 93 "alloc_rr should not allocate on same ost"
4782
4783 test_94() {
4784         $LCTL set_param osc.*.idle_timeout=0
4785         dd if=/dev/zero of=$DIR2/$tfile bs=4k count=2 conv=fsync
4786
4787         local before=$(date +%s)
4788         local evict
4789
4790         $LCTL mark write
4791 #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
4792         $LCTL set_param fail_val=5 fail_loc=0x80000312
4793         dd if=/dev/zero of=$DIR/$tfile conv=notrunc oflag=append bs=4k count=1 &
4794         local pid=$!
4795         sleep 2
4796
4797 #define OBD_FAIL_LDLM_PAUSE_CANCEL_LOCAL 0x329
4798         $LCTL set_param fail_val=6 fail_loc=0x80000329
4799         $LCTL mark kill $pid
4800         kill -ALRM $pid
4801
4802         dd if=/dev/zero of=$DIR2/$tfile conv=notrunc oflag=append bs=4k count=1
4803
4804         wait $pid
4805         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 conv=fsync
4806
4807         evict=$(do_facet client $LCTL get_param \
4808                 osc.$FSNAME-OST*-osc-*/state |
4809             awk -F"[ [,]" '/EVICTED ]$/ { if (t<$5) {t=$5;} } END { print t }')
4810
4811         [ -z "$evict" ] || [[ $evict -le $before ]] ||
4812                 (do_facet client $LCTL get_param \
4813                         osc.$FSNAME-OST*-osc-*/state;
4814                     error "eviction happened: $evict before:$before")
4815         $LCTL set_param osc.*.idle_timeout=debug
4816 }
4817 run_test 94 "signal vs CP callback race"
4818
4819 # Data-on-MDT tests
4820 test_100a() {
4821         skip "Reserved for glimpse-ahead" && return
4822         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
4823                 skip "Need MDS version at least 2.10.55"
4824
4825         mkdir -p $DIR/$tdir
4826
4827         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4828
4829         lctl set_param -n mdc.*.stats=clear
4830         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4831
4832         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4833         # first stat from server should return size data and save glimpse
4834         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4835         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
4836         # second stat to check size is NOT cached on client without IO lock
4837         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4838
4839         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4840         [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
4841         rm -f $dom
4842 }
4843 run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
4844
4845 test_100b() {
4846         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
4847                 skip "Need MDS version at least 2.10.55"
4848
4849         mkdir -p $DIR/$tdir
4850
4851         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4852
4853         lctl set_param -n mdc.*.stats=clear
4854         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4855         cancel_lru_locks mdc
4856         # first stat data from server should have size
4857         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4858         # second stat to check size is cached on client
4859         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4860
4861         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4862         # both stats should cause no glimpse requests
4863         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
4864         rm -f $dom
4865 }
4866 run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
4867
4868 test_100c() {
4869         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
4870                 skip "Need MDS version at least 2.10.55"
4871
4872         mkdir -p $DIR/$tdir
4873
4874         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4875
4876         lctl set_param -n mdc.*.stats=clear
4877         lctl set_param -n osc.*.stats=clear
4878         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4879
4880         # check that size is merged from MDT and OST correctly
4881         $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
4882                 error "Wrong size from stat #1"
4883
4884         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4885         [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
4886
4887         rm -f $dom
4888 }
4889 run_test 100c "DoM: write vs stat without IO lock (combined file)"
4890
4891 test_100d() {
4892         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
4893                 skip "Need MDS version at least 2.10.55"
4894
4895         mkdir -p $DIR/$tdir
4896
4897         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4898
4899
4900         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4901         lctl set_param -n mdc.*.stats=clear
4902         $TRUNCATE $DIR2/$tdir/dom 4096
4903
4904         # check that reported size is valid after file grows to OST and
4905         # is truncated back to MDT stripe size
4906         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
4907                 error "Wrong size from stat #1"
4908
4909         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4910         [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
4911
4912         rm -f $dom
4913 }
4914 run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
4915
4916 test_100e() {
4917         [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
4918                 skip "Need MDS version at least 2.11.50"
4919
4920         local dom=$DIR/$tdir/dom
4921         local dom2=$DIR2/$tdir/dom
4922         mkdir -p $DIR/$tdir
4923
4924         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
4925
4926         cancel_lru_locks mdc
4927         dd if=/dev/urandom of=$dom bs=12000 count=1
4928         $TRUNCATE $dom2 6000
4929         cancel_lru_locks mdc
4930         lctl set_param -n mdc.*.stats=clear
4931         # expect read-on-open to return all data before write
4932         cat /etc/hosts >> $dom
4933         local read=$(lctl get_param -n mdc.*.stats | grep -c ost_read)
4934         [[ $read -eq 0 ]] || error "Unexpected $read READ RPCs"
4935 }
4936 run_test 100e "DoM: read on open and file size"
4937
4938 test_101a() {
4939         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
4940                 skip "Need MDS version at least 2.10.55"
4941
4942         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4943         # to get layout
4944         $CHECKSTAT -t file $DIR1/$tfile
4945
4946         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4947         sysctl -wq vm.dirty_writeback_centisecs=0
4948
4949         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4950
4951         # open + IO lock
4952         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
4953                 error_noexit "Write fails"
4954         # must discard pages
4955         lctl set_param -n mdc.*.stats=clear
4956         rm $DIR2/$tfile || error "Unlink fails"
4957
4958         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4959         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4960 }
4961 run_test 101a "Discard DoM data on unlink"
4962
4963 test_101b() {
4964         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
4965                 skip "Need MDS version at least 2.10.55"
4966
4967         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4968         touch $DIR1/${tfile}_2
4969         # to get layout
4970         $CHECKSTAT -t file $DIR1/$tfile
4971
4972         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4973         sysctl -wq vm.dirty_writeback_centisecs=0
4974
4975         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4976
4977         # open + IO lock
4978         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4979         # must discard pages
4980         lctl set_param -n mdc.*.stats=clear
4981         mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
4982
4983         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4984         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4985 }
4986 run_test 101b "Discard DoM data on rename"
4987
4988 test_101c() {
4989         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
4990                 skip "Need MDS version at least 2.10.55"
4991
4992         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4993         # to get layout
4994         $CHECKSTAT -t file $DIR1/$tfile
4995
4996         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4997         sysctl -wq vm.dirty_writeback_centisecs=0
4998
4999         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
5000
5001         # open + IO lock
5002         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
5003         $MULTIOP $DIR1/$tfile O_c &
5004         MULTIOP_PID=$!
5005         sleep 1
5006         lctl set_param -n mdc.*.stats=clear
5007         rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
5008         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
5009
5010         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
5011         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
5012 }
5013 run_test 101c "Discard DoM data on close-unlink"
5014
5015 # test to verify file handle related system calls
5016 # (name_to_handle_at/open_by_handle_at)
5017 # The new system calls are supported in glibc >= 2.14.
5018
5019 # test to verify we can open by handle an unlinked file from > 1 client
5020 # This test opens the file normally on $DIR1, which is on one mount, and then
5021 # opens it by handle on $DIR2, which is on a different mount.
5022 test_102() {
5023         [ "$MDS1_VERSION" -lt $(version_code 2.11.57) ] &&
5024                 skip "Needs MDS version 2.11.57 or later"
5025
5026         echo "Test file_handle syscalls" > $DIR/$tfile ||
5027                 error "write failed"
5028         check_fhandle_syscalls $DIR/$tfile $DIR2 ||
5029                 error "check_fhandle_syscalls failed"
5030         rm -f $DIR2/$tfile
5031 }
5032 run_test 102 "Test open by handle of unlinked file"
5033
5034 # Compare file size between first & second mount, ensuring the client correctly
5035 # glimpses even with unused speculative locks - LU-11670
5036 test_103() {
5037         [ $OST1_VERSION -lt $(version_code 2.10.50) ] &&
5038                 skip "Lockahead needs OST version at least 2.10.50"
5039
5040         local locktest=23
5041
5042         test_mkdir -p $DIR/$tdir
5043
5044         # Force file on to OST0
5045         $LFS setstripe -i 0 $DIR/$tdir
5046
5047         # Do not check multiple locks on glimpse
5048         # OBD_FAIL_OSC_NO_SIZE_DATA 0x415
5049         $LCTL set_param fail_loc=0x415
5050
5051         # Delay write commit by 2 seconds to guarantee glimpse wins race
5052         # The same fail_loc is used on client & server so it can work in the
5053         # single node sanity setup
5054         do_facet ost1 $LCTL set_param fail_loc=0x415 fail_val=2
5055
5056         echo "Incorrect size expected (no glimpse fix):"
5057         lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $locktest -f $tfile
5058         rc=$?
5059         if [ $rc -eq 0 ]; then
5060                 echo "This doesn't work 100%, but this is just reproducing the bug, not testing the fix, so OK to not fail test."
5061         fi
5062
5063         # guarantee write commit timeout has expired
5064         sleep 2
5065
5066         # Clear fail_loc on client
5067         $LCTL set_param fail_loc=0
5068
5069         # Delay write commit by 2 seconds to guarantee glimpse wins race
5070         # OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
5071         do_facet ost1 $LCTL set_param fail_loc=0x214 fail_val=2
5072
5073         # Write commit is still delayed by 2 seconds
5074         lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $locktest -f $tfile
5075         rc=$?
5076         [ $rc -eq 0 ] || error "Lockahead test$locktest failed, $rc"
5077
5078         # guarantee write commit timeout has expired
5079         sleep 2
5080
5081         rm -f $DIR/$tfile || error "unable to delete $DIR/$tfile"
5082 }
5083 run_test 103 "Test size correctness with lockahead"
5084
5085 get_stat_xtimes()
5086 {
5087         local xtimes
5088
5089         xtimes=$(stat -c "%X %Y %Z" $DIR/$tfile)
5090
5091         echo ${xtimes[*]}
5092 }
5093
5094 get_mdt_xtimes()
5095 {
5096         local mdtdev=$1
5097         local output
5098         local xtimes
5099
5100         output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
5101         ((xtimes[0]=$(awk -F ':' /atime/'{ print $2 }' <<< "$output")))
5102         ((xtimes[1]=$(awk -F ':' /mtime/'{ print $2 }' <<< "$output")))
5103         ((xtimes[2]=$(awk -F ':' /ctime/'{ print $2 }' <<< "$output")))
5104
5105         echo ${xtimes[*]}
5106 }
5107
5108 check_mdt_xtimes()
5109 {
5110         local mdtdev=$1
5111         local xtimes=($(get_stat_xtimes))
5112         local mdt_xtimes=($(get_mdt_xtimes $mdtdev))
5113
5114         echo "STAT a|m|ctime ${xtimes[*]}"
5115         echo "MDT a|m|ctime ${mdt_xtimes[*]}"
5116         [[ ${xtimes[0]} == ${mdt_xtimes[0]} ]] ||
5117                 error "$DIR/$tfile atime (${xtimes[0]}:${mdt_xtimes[0]}) diff"
5118         [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
5119                 error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
5120         [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
5121                 error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
5122 }
5123
5124 test_104() {
5125         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip_env "ldiskfs only test"
5126         [ $MDS1_VERSION -lt $(version_code 2.12.4) ] &&
5127                 skip "Need MDS version at least 2.12.4"
5128
5129         local pid
5130         local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
5131         local atime_diff=$(do_facet $SINGLEMDS \
5132                 lctl get_param -n mdd.*MDT0000*.atime_diff)
5133
5134         do_facet $SINGLEMDS \
5135                 lctl set_param -n mdd.*MDT0000*.atime_diff=0
5136
5137         stack_trap "do_facet $SINGLEMDS \
5138                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff" EXIT
5139
5140         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5141         check_mdt_xtimes $mdtdev
5142         sleep 2
5143
5144         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5145         check_mdt_xtimes $mdtdev
5146         sleep 2
5147         $MULTIOP $DIR2/$tfile Oz8192w8192_c &
5148         pid=$!
5149         sleep 2
5150         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5151         sleep 2
5152         kill -USR1 $pid && wait $pid || error "multiop failure"
5153         check_mdt_xtimes $mdtdev
5154
5155         local xtimes
5156         local mdt_xtimes
5157
5158         # Verify mtime/ctime is NOT upated on MDS when there is no modification
5159         # on the client side
5160         xtimes=($(get_stat_xtimes))
5161         $MULTIOP $DIR/$tfile O_c &
5162         pid=$!
5163         sleep 2
5164         kill -USR1 $pid && wait $pid || error "multiop failure"
5165         mdt_xtimes=($(get_mdt_xtimes $mdtdev))
5166         [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
5167                 error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
5168         [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
5169                 error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
5170         check_mdt_xtimes $mdtdev
5171
5172         sleep 2
5173         # Change ctime via chmod
5174         $MULTIOP $DIR/$tfile o_tc &
5175         pid=$!
5176         sleep 2
5177         kill -USR1 $pid && wait $pid || error "multiop failure"
5178         check_mdt_xtimes $mdtdev
5179 }
5180 run_test 104 "Verify that MDS stores atime/mtime/ctime during close"
5181
5182 test_105() {
5183         test_mkdir -p $DIR/$tdir
5184         echo test > $DIR/$tdir/$tfile
5185         $LCTL set_param fail_loc=0x416
5186         cancel_lru_locks osc & sleep 1
5187         fsize1=$(stat -c %s $DIR2/$tdir/$tfile)
5188         wait
5189         [[ $fsize1 = 5 ]] ||  error "Glimpse returned wrong file size $fsize1"
5190 }
5191 run_test 105 "Glimpse and lock cancel race"
5192
5193 test_106a() {
5194         [ "$mds1_FSTYPE" == "ldiskfs" ] && statx_supported ||
5195                 skip_env "Test only for ldiskfs and statx() supported"
5196
5197         local btime
5198         local mdt_btime
5199         local output
5200         local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
5201
5202         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5203         btime=$($STATX -c %W $DIR/$tfile)
5204         output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
5205         echo $output
5206         ((mdt_btime=$(awk -F ':' /crtime/'{ print $2 }' <<< "$output")))
5207         [[ $btime == $mdt_btime ]] ||
5208                 error "$DIR/$tfile btime ($btime:$mdt_btime) diff"
5209
5210 }
5211 run_test 106a "Verify the btime via statx()"
5212
5213 test_106b() {
5214         statx_supported || skip_env "statx() only test"
5215
5216         local rpcs_before
5217         local rpcs_after
5218
5219         $LFS setstripe -c 1 $DIR/$tfile || error "$DIR/$tfile setstripe failed"
5220         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5221         cancel_lru_locks $OSC
5222         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5223         $STATX $DIR/$tfile
5224         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5225         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5226                 error "$STATX should send 1 glimpse RPC to $OSC"
5227
5228         cancel_lru_locks $OSC
5229         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5230         # %n: FILENAME; %i: STATX_INO; %A STATX_MODE; %h STATX_NLINK;
5231         # %u: STATX_UID; %g: STATX_GID; %W STATX_BTIME; %X STATX_ATIME;
5232         # %Z: STATX_CTIME
5233         $STATX -c "%n %i %A %h %u %g %W %X %Z" $DIR/$tfile
5234         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5235         [ $rpcs_after -eq $rpcs_before ] ||
5236                 error "$STATX should not send glimpse RPCs to $OSC"
5237
5238         cancel_lru_locks $OSC
5239         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5240         $STATX --cached=always $DIR/$tfile
5241         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5242         [ $rpcs_after -eq $rpcs_before ] ||
5243                 error "$STATX should not send glimpse RPCs to $OSC"
5244
5245         cancel_lru_locks $OSC
5246         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5247         $STATX -c %Y $DIR/$tfile
5248         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5249         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5250                 error "$STATX -c %Y should send 1 glimpse RPC to $OSC"
5251
5252         cancel_lru_locks $OSC
5253         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5254         $STATX -c %s $DIR/$tfile
5255         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5256         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5257                 error "$STATX -c %s should send 1 glimpse RPC to $OSC"
5258
5259         cancel_lru_locks $OSC
5260         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5261         $STATX -c %b $DIR/$tfile
5262         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5263         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5264                 error "$STATX -c %b should send 1 glimpse RPC to $OSC"
5265 }
5266 run_test 106b "Glimpse RPCs test for statx"
5267
5268 test_106c() {
5269         statx_supported || skip_env "statx() only test"
5270
5271         local mask
5272
5273         touch $DIR/$tfile
5274         # Mask supported in stx_attributes by Lustre is
5275         # STATX_ATTR_IMMUTABLE(0x10) | STATX_ATTR_APPEND(0x20) : (0x30).
5276         mask=$($STATX -c %p $DIR/$tfile)
5277         [[ $mask == "30" ]] ||
5278                 error "supported stx_attributes: got '$mask', expected '30'"
5279         chattr +i $DIR/$tfile || error "chattr +i $DIR/$tfile failed"
5280         mask=$($STATX -c %r $DIR/$tfile)
5281         [[ $mask == "10" ]] ||
5282                 error "got immutable flags '$mask', expected '10'"
5283         chattr -i $DIR/$tfile || error "chattr -i $DIR/$tfile failed"
5284         mask=$($STATX -c %r $DIR/$tfile)
5285         [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
5286         chattr +a $DIR/$tfile || error "chattr +a $DIR/$tfile failed"
5287         mask=$($STATX -c %r $DIR/$tfile)
5288         [[ $mask == "20" ]] || error "got flags '$mask', expected '20'"
5289         chattr -a $DIR/$tfile || error "chattr -a $DIR/$tfile failed"
5290         mask=$($STATX -c %r $DIR/$tfile)
5291         [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
5292         chattr +ia $DIR/$tfile || error "chattr +ia $DIR/$tfile failed"
5293         mask=$($STATX -c %r $DIR/$tfile)
5294         [[ $mask == "30" ]] || error "got flags '$mask', expected '30'"
5295         chattr -ia $DIR/$tfile || error "chattr -ia $DIR/$tfile failed"
5296         mask=$($STATX -c %r $DIR/$tfile)
5297         [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
5298 }
5299 run_test 106c "Verify statx attributes mask"
5300
5301 test_107a() { # LU-1031
5302         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
5303         local gid1=14091995
5304         local gid2=16022000
5305
5306         $LFS getstripe $DIR1/$tfile
5307
5308         multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
5309         local MULTIPID1=$!
5310         multiop_bg_pause $DIR2/$tfile O_G${gid2}r10g${gid2}c || return 2
5311         local MULTIPID2=$!
5312         kill -USR1 $MULTIPID2
5313         sleep 2
5314         if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
5315                 error "First grouplock does not block second one"
5316         else
5317                 echo "First grouplock blocks second one"
5318         fi
5319         kill -USR1 $MULTIPID1
5320         wait $MULTIPID1
5321         wait $MULTIPID2
5322 }
5323 run_test 107a "Basic grouplock conflict"
5324
5325 test_107b() {
5326         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
5327         local gid1=14091995
5328         local gid2=16022000
5329
5330         $LFS getstripe $DIR1/$tfile
5331
5332         multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
5333         local MULTIPID1=$!
5334         multiop $DIR2/$tfile Or10c &
5335         local MULTIPID2=$!
5336         sleep 2
5337
5338         if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
5339                 error "Grouplock does not block IO"
5340         else
5341                 echo "Grouplock blocks IO"
5342         fi
5343
5344         multiop $DIR2/$tfile OG${gid2}_g${gid2}c &
5345         local MULTIPID3=$!
5346         sleep 2
5347         if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
5348                 error "First grouplock does not block second one"
5349         else
5350                 echo "First grouplock blocks second one"
5351         fi
5352
5353         kill -USR1 $MULTIPID1
5354         sleep 2
5355
5356         if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
5357                 error "Second grouplock thread disappeared"
5358         fi
5359
5360         if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
5361                 error "Second grouplock does not block IO"
5362         else
5363                 echo "Second grouplock blocks IO"
5364         fi
5365
5366         kill -USR1 $MULTIPID3
5367         wait $MULTIPID1
5368         wait $MULTIPID2
5369         wait $MULTIPID3
5370 }
5371 run_test 107b "Grouplock is added to the head of waiting list"
5372
5373 test_108a() {
5374         local offset
5375
5376         $LFS setstripe -E 1M -c 1 -E -1 $DIR1/$tfile ||
5377                 error "Create $DIR1/$tfile failed"
5378
5379         dd if=/dev/zero of=$DIR1/$tfile bs=10000 count=1 ||
5380                 error "dd $DIR1/$tfile failed"
5381         offset=$(lseek_test -d 5000 $DIR2/$tfile)
5382         [[ $offset == 5000 ]] || error "offset $offset != 5000"
5383
5384         $TRUNCATE $DIR1/$tfile 2000
5385         offset=$(lseek_test -l 1000 $DIR2/$tfile)
5386         [[ $offset == 2000 ]] || error "offset $offset != 2000"
5387
5388         #define OBD_FAIL_OSC_DELAY_IO 0x414
5389         $LCTL set_param fail_val=4 fail_loc=0x80000414
5390         dd if=/dev/zero of=$DIR1/$tfile count=1 bs=8M conv=notrunc oflag=dsync &
5391         local pid=$!
5392         sleep 2
5393
5394         offset=$(lseek_test -l 8000 $DIR2/$tfile)
5395         wait $pid
5396         [[ $offset == 8388608 ]] || error "offset $offset != 8388608"
5397 }
5398 run_test 108a "lseek: parallel updates"
5399
5400 log "cleanup: ======================================================"
5401
5402 # kill and wait in each test only guarentee script finish, but command in script
5403 # like 'rm' 'chmod' may still be running, wait for all commands to finish
5404 # otherwise umount below will fail
5405 [ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
5406         true
5407
5408 complete $SECONDS
5409 rm -f $SAMPLE_FILE
5410 check_and_cleanup_lustre
5411 exit_status