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