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