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