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