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