Whamcloud - gitweb
LU-10059 tests: sanityn 32a restore parameters
[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         for ((i = 0; i < $n; i++)); do
3130                 do_nodes $CLIENTS $myRUNAS dd if=/dev/zero \
3131                         of="$dir/nrs_w_$HOSTNAME" bs=1M seek=$i count=1 ||
3132                          error "dd at ${i}MB on client failed (2)" &
3133                 local pids_w[$i]=$!
3134         done
3135         do_nodes $CLIENTS sync;
3136         cancel_lru_locks osc
3137
3138         for ((i = 0; i < $n; i++)); do
3139                 do_nodes $CLIENTS $myRUNAS dd if="$dir/nrs_w_$HOSTNAME" \
3140                         of=/dev/zero bs=1M seek=$i count=1 > /dev/null ||
3141                         error "dd at ${i}MB on client failed (3)" &
3142                 local pids_r[$i]=$!
3143         done
3144         cancel_lru_locks osc
3145
3146         for ((i = 0; i < $n; i++)); do
3147                 wait ${pids_w[$i]}
3148                 wait ${pids_r[$i]}
3149         done
3150         rm -rf $dir || error "rm -rf $dir failed"
3151 }
3152
3153 test_77a() { #LU-3266
3154         local rc
3155
3156         oss=$(comma_list $(osts_nodes))
3157         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo" ||
3158                 rc=$?
3159         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3160         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3161         nrs_write_read
3162
3163         return 0
3164 }
3165 run_test 77a "check FIFO NRS policy"
3166
3167 test_77b() { #LU-3266
3168         local rc
3169
3170         oss=$(comma_list $(osts_nodes))
3171
3172         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3173                 ost.OSS.*.nrs_crrn_quantum=1 || rc=$?
3174         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3175         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 1"
3176
3177         echo "policy: crr-n, crrn_quantum 1"
3178         nrs_write_read
3179
3180         do_nodes $oss lctl set_param \
3181                 ost.OSS.*.nrs_crrn_quantum=64 || rc=$?
3182         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 64"
3183
3184         echo "policy: crr-n, crrn_quantum 64"
3185         nrs_write_read
3186
3187         # cleanup
3188         do_nodes $oss lctl set_param \
3189                 ost.OSS.ost_io.nrs_policies="fifo" || rc=$?
3190         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3191         return 0
3192 }
3193 run_test 77b "check CRR-N NRS policy"
3194
3195 orr_trr() {
3196         local policy=$1
3197
3198         oss=$(comma_list $(osts_nodes))
3199
3200         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3201                 ost.OSS.*.nrs_"$policy"_quantum=1 \
3202                 ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3203                 ost.OSS.*.nrs_"$policy"_supported="reads" || return $?
3204
3205         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type " \
3206                 "physical, ${policy}_supported reads"
3207         nrs_write_read
3208
3209         do_nodes $oss lctl set_param \
3210                 ost.OSS.*.nrs_${policy}_supported="writes" \
3211                 ost.OSS.*.nrs_${policy}_quantum=64 || return $?
3212
3213         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3214                 "physical, ${policy}_supported writes"
3215         nrs_write_read
3216
3217         do_nodes $oss lctl set_param \
3218                 ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3219                 ost.OSS.*.nrs_${policy}_offset_type="logical" || return $?
3220         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3221                 "logical, ${policy}_supported reads_and_writes"
3222         nrs_write_read
3223
3224         # cleanup
3225         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo" ||
3226                 return $?
3227         return 0
3228 }
3229
3230 test_77c() { #LU-3266
3231         local rc
3232         orr_trr "orr" || rc=$?
3233         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3234         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3235         return 0
3236 }
3237 run_test 77c "check ORR NRS policy"
3238
3239 test_77d() { #LU-3266
3240         local rc
3241         orr_trr "trr" || rc=$?
3242         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3243         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3244         return 0
3245 }
3246 run_test 77d "check TRR nrs policy"
3247
3248 tbf_rule_operate()
3249 {
3250         local facet=$1
3251         shift 1
3252
3253         do_facet $facet lctl set_param \
3254                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3255         [ $? -ne 0 ] &&
3256                 error "failed to run operate '$*' on TBF rules"
3257 }
3258
3259 cleanup_tbf_verify()
3260 {
3261         local rc=0
3262         trap 0
3263         echo "cleanup_tbf $DIR/$tdir"
3264         rm -rf $DIR/$tdir
3265         rc=$?
3266         wait_delete_completed
3267         return $rc
3268 }
3269
3270 tbf_verify() {
3271         local dir=$DIR/$tdir
3272         local client1=${CLIENT1:-$(hostname)}
3273         local myRUNAS="$3"
3274
3275         local np=$(check_cpt_number ost1)
3276         [ $np -gt 0 ] || error "CPU partitions should not be $np."
3277         echo "cpu_npartitions on ost1 is $np"
3278
3279         mkdir $dir || error "mkdir $dir failed"
3280         $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
3281         chmod 777 $dir
3282
3283         trap cleanup_tbf_verify EXIT
3284         echo "Limited write rate: $1, read rate: $2"
3285         echo "Verify the write rate is under TBF control"
3286         local start=$SECONDS
3287         do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
3288                 bs=1M count=100 oflag=direct 2>&1
3289         local runtime=$((SECONDS - start + 1))
3290         local rate=$(bc <<< "scale=6; 100 / $runtime")
3291         echo "Write runtime is $runtime s, speed is $rate IOPS"
3292
3293         # verify the write rate does not exceed TBF rate limit
3294         [ $(bc <<< "$rate < 1.1 * $np * $1") -eq 1 ] ||
3295                 error "The write rate ($rate) exceeds 110% of rate limit ($1 * $np)"
3296
3297         cancel_lru_locks osc
3298
3299         echo "Verify the read rate is under TBF control"
3300         start=$SECONDS
3301         do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
3302                 bs=1M count=100 iflag=direct 2>&1
3303         runtime=$((SECONDS - start + 1))
3304         rate=$(bc <<< "scale=6; 100 / $runtime")
3305         echo "Read runtime is $runtime s, speed is $rate IOPS"
3306
3307         # verify the read rate does not exceed TBF rate limit
3308         [ $(bc <<< "$rate < 1.1 * $np * $2") -eq 1 ] ||
3309                 error "The read rate ($rate) exceeds 110% of rate limit ($2 * $np)"
3310
3311         cancel_lru_locks osc
3312         cleanup_tbf_verify || error "rm -rf $dir failed"
3313 }
3314
3315 test_77e() {
3316         local rc
3317
3318         oss=$(comma_list $(osts_nodes))
3319
3320         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3321                 rc=$?
3322         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3323         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3324
3325         local idis
3326         local rateis
3327         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3328                 idis="nid="
3329                 rateis="rate="
3330         fi
3331
3332         # Only operate rules on ost1 since OSTs might run on the same OSS
3333         # Add some rules
3334         tbf_rule_operate ost1 "start\ localhost\ ${idis}{0@lo}\ ${rateis}1000"
3335         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3336         local client_nids=$(nids_list $address "\\")
3337         tbf_rule_operate ost1 "start\ clients\ ${idis}{$client_nids}\ ${rateis}100"
3338         tbf_rule_operate ost1 "start\ others\ ${idis}{*.*.*.*@$NETTYPE}\ ${rateis}50"
3339         nrs_write_read
3340
3341         # Change the rules
3342         tbf_rule_operate ost1 "change\ localhost\ ${rateis}1001"
3343         tbf_rule_operate ost1 "change\ clients\ ${rateis}101"
3344         tbf_rule_operate ost1 "change\ others\ ${rateis}51"
3345         nrs_write_read
3346
3347         # Stop the rules
3348         tbf_rule_operate ost1 "stop\ localhost"
3349         tbf_rule_operate ost1 "stop\ clients"
3350         tbf_rule_operate ost1 "stop\ others"
3351         nrs_write_read
3352
3353         # Cleanup the TBF policy
3354         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3355         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3356         nrs_write_read
3357         return 0
3358 }
3359 run_test 77e "check TBF NID nrs policy"
3360
3361 test_77f() {
3362         local rc
3363
3364         oss=$(comma_list $(osts_nodes))
3365
3366         do_nodes $oss $LCTL set_param \
3367                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3368         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3369         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3370
3371         # Configure jobid_var
3372         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3373         rc=$?
3374         [[ $rc -eq 3 ]] && skip "jobid_var not found" && return
3375         [[ $rc -ne 0 ]] && error "failed to get param jobid_var"
3376         if [ $saved_jobid_var != procname_uid ]; then
3377                 set_persistent_param_and_check client \
3378                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3379         fi
3380
3381         local idis
3382         local rateis
3383         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3384                 idis="jobid="
3385                 rateis="rate="
3386         fi
3387
3388         # Only operate rules on ost1 since OSTs might run on the same OSS
3389         # Add some rules
3390         tbf_rule_operate ost1 "start\ runas\ ${idis}{iozone.$RUNAS_ID\ dd.$RUNAS_ID\ tiotest.$RUNAS_ID}\ ${rateis}1000"
3391         tbf_rule_operate ost1 "start\ iozone_runas\ ${idis}{iozone.$RUNAS_ID}\ ${rateis}100"
3392         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3393         nrs_write_read "$RUNAS"
3394
3395         # Change the rules
3396         tbf_rule_operate ost1 "change\ runas\ ${rateis}1001"
3397         tbf_rule_operate ost1 "change\ iozone_runas\ ${rateis}101"
3398         tbf_rule_operate ost1 "change\ dd_runas\ ${rateis}51"
3399         nrs_write_read "$RUNAS"
3400
3401         # Stop the rules
3402         tbf_rule_operate ost1 "stop\ runas"
3403         tbf_rule_operate ost1 "stop\ iozone_runas"
3404         tbf_rule_operate ost1 "stop\ dd_runas"
3405         nrs_write_read "$RUNAS"
3406
3407         # Cleanup the TBF policy
3408         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3409         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3410         nrs_write_read "$RUNAS"
3411
3412         local current_jobid_var=$($LCTL get_param -n jobid_var)
3413         [[ $? -ne 0 ]] && error "failed to get param jobid_var"
3414         if [ $saved_jobid_var != $current_jobid_var ]; then
3415                 set_persistent_param_and_check client \
3416                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3417         fi
3418         return 0
3419 }
3420 run_test 77f "check TBF JobID nrs policy"
3421
3422 test_77g() {
3423         local rc=0
3424
3425         oss=$(comma_list $(osts_nodes))
3426
3427         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3428                 rc=$?
3429         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3430         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3431
3432         do_nodes $oss lctl set_param \
3433                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3434         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3435
3436         local idis
3437         local rateis
3438         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3439                 idis="jobid="
3440                 rateis="rate="
3441         fi
3442
3443         # Add a rule that only valid for Jobid TBF. If direct change between
3444         # TBF types is not supported, this operation will fail.
3445         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3446
3447         # Cleanup the TBF policy
3448         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3449         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3450         return 0
3451 }
3452 run_test 77g "Change TBF type directly"
3453
3454 test_77h() {
3455         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3456                 { skip "Need OST version at least 2.8.55"; return 0; }
3457
3458         local old_policy=$(do_facet ost1 \
3459                 lctl get_param ost.OSS.ost_io.nrs_policies)
3460         local new_policy
3461
3462         do_facet ost1 lctl set_param \
3463                 ost.OSS.ost_io.nrs_policies="abc"
3464         [ $? -eq 0 ] && error "should return error"
3465
3466         do_facet ost1 lctl set_param \
3467                 ost.OSS.ost_io.nrs_policies="tbf\ abc"
3468         [ $? -eq 0 ] && error "should return error"
3469
3470         do_facet ost1 lctl set_param \
3471                 ost.OSS.ost_io.nrs_policies="tbf\ reg\ abc"
3472         [ $? -eq 0 ] && error "should return error"
3473
3474         do_facet ost1 lctl set_param \
3475                 ost.OSS.ost_io.nrs_policies="tbf\ abc\ efg"
3476         [ $? -eq 0 ] && error "should return error"
3477
3478         new_policy=$(do_facet ost1 lctl get_param ost.OSS.ost_io.nrs_policies)
3479         [ $? -eq 0 ] || error "shouldn't LBUG"
3480
3481         [ "$old_policy" = "$new_policy" ] || error "NRS policy should be same"
3482
3483         return 0
3484 }
3485 run_test 77h "Wrong policy name should report error, not LBUG"
3486
3487 tbf_rule_check()
3488 {
3489         local facet=$1
3490         local expected=$2
3491         local error_message=$3
3492         local rule_number=0
3493         for rule in $expected; do
3494                 rule_number=$((rule_number + 1))
3495         done
3496         local stop_line=$(($rule_number + 3))
3497         local awk_command="awk 'NR >= 4 && NR <= $stop_line {print \$1}'"
3498
3499         local output=$(do_facet $facet lctl get_param \
3500                 ost.OSS.ost_io.nrs_tbf_rule |
3501                 eval $awk_command |
3502                 tr "\n" " " |
3503                 sed 's/[ ]*$//')
3504         if [ "$output" != "$expected" ]; then
3505                 error "$error_message, expected '$expected', got '$output'"
3506         fi
3507 }
3508
3509 test_77i() {
3510         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3511                 { skip "Need OST version at least 2.8.55"; return 0; }
3512
3513         for i in $(seq 1 $OSTCOUNT)
3514         do
3515                 do_facet ost"$i" lctl set_param \
3516                         ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3517                 [ $? -ne 0 ] &&
3518                         error "failed to set TBF policy"
3519         done
3520
3521         tbf_rule_check ost1 "default" "error before inserting any rule"
3522
3523         tbf_rule_operate ost1 "start\ before\ jobid={jobid}\ rate=1000"
3524         tbf_rule_check ost1 "before default" \
3525                 "error when inserting rule 'before'"
3526
3527         tbf_rule_operate ost1 "start\ after\ jobid={jobid}\ rate=1000\ rank=default"
3528         tbf_rule_check ost1 "before after default" \
3529                 "error when inserting rule 'after'"
3530
3531         tbf_rule_operate ost1 "start\ target\ jobid={jobid}\ rate=1000\ rank=after"
3532         tbf_rule_check ost1 "before target after default" \
3533                 "error when inserting rule 'target'"
3534
3535         echo "Move before itself"
3536         tbf_rule_operate ost1 "change\ target\ rank=target"
3537         tbf_rule_check ost1 "before target after default" \
3538                 "error when moving before itself"
3539
3540         echo "Move to higher rank"
3541         tbf_rule_operate ost1 "change\ target\ rank=before"
3542         tbf_rule_check ost1 "target before after default" \
3543                 "error when moving to higher rank"
3544
3545         echo "Move to lower rank"
3546         tbf_rule_operate ost1 "change\ target\ rank=after"
3547         tbf_rule_check ost1 "before target after default" \
3548                 "error when moving to lower rank"
3549
3550         echo "Move before default"
3551         tbf_rule_operate ost1 "change\ target\ rank=default"
3552         tbf_rule_check ost1 "before after target default" \
3553                 error "error when moving before default"
3554
3555         # Cleanup the TBF policy
3556         do_nodes $(comma_list $(osts_nodes)) \
3557                 $LCTL set_param ost.OSS.ost_io.nrs_policies=fifo
3558         return 0
3559 }
3560 run_test 77i "Change rank of TBF rule"
3561
3562 test_77j() {
3563         local idis
3564         local rateis
3565         local ost_version=$(lustre_version_code ost1)
3566
3567         [ $ost_version -ge $(version_code 2.9.53) ] ||
3568                 { skip "Need OST version at least 2.9.53"; return 0; }
3569         if [ $ost_version -ge $(version_code 2.8.60) ]; then
3570                 idis="opcode="
3571                 rateis="rate="
3572         fi
3573
3574         do_nodes $(comma_list $(osts_nodes)) \
3575                 lctl set_param jobid_var=procname_uid \
3576                         ost.OSS.ost_io.nrs_policies="tbf\ opcode" \
3577                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_r\ ${idis}{ost_read}\ ${rateis}5" \
3578                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_w\ ${idis}{ost_write}\ ${rateis}20"
3579         [ $? -ne 0 ] && error "failed to set TBF OPCode policy"
3580
3581         nrs_write_read
3582         tbf_verify 20 5
3583
3584         do_nodes $(comma_list $(osts_nodes)) \
3585                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_r" \
3586                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_w" \
3587                         ost.OSS.ost_io.nrs_policies="fifo"
3588
3589         # sleep 3 seconds to wait the tbf policy stop completely,
3590         # or the next test case is possible get -EAGAIN when
3591         # setting the tbf policy
3592         sleep 3
3593 }
3594 run_test 77j "check TBF-OPCode NRS policy"
3595
3596 test_id() {
3597         local idstr="${1}id"
3598         local policy="${idstr}={$2}"
3599         local rate="rate=$3"
3600
3601         do_nodes $(comma_list $(osts_nodes)) \
3602                 lctl set_param jobid_var=procname_uid \
3603                         ost.OSS.ost_io.nrs_policies="tbf\ ${idstr}" \
3604                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_${idstr}\ ${policy}\ ${rate}"
3605         [ $? -ne 0 ] && error "failed to set tbf ${idstr} policy"
3606
3607         nrs_write_read "runas $4"
3608         tbf_verify $3 $3 "runas $4"
3609
3610         do_nodes $(comma_list $(osts_nodes)) \
3611                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
3612                         ost.OSS.ost_io.nrs_policies="fifo"
3613
3614         # sleep 3 seconds to wait the tbf policy stop completely,
3615         # or the next test case is possible get -eagain when
3616         # setting the tbf policy
3617         sleep 3
3618 }
3619
3620 test_77ja(){
3621         if [ $(lustre_version_code ost1) -lt $(version_code 2.11.50) ]; then
3622                 skip "Need OST version at least 2.11.50"
3623                 return 0
3624         fi
3625         test_id "u" "500" "5" "-u 500"
3626         test_id "g" "500" "5" "-u 500 -g 500"
3627 }
3628 run_test 77ja "check TBF-UID/GID NRS policy"
3629
3630 cleanup_77k()
3631 {
3632         local rule_lists=$1
3633         local old_nrs=$2
3634
3635         trap 0
3636         for rule in $rule_lists; do
3637                 do_nodes $(comma_list $(osts_nodes)) \
3638                         lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ $rule"
3639         done
3640
3641         do_nodes $(comma_list $(osts_nodes)) \
3642                 lctl set_param ost.OSS.ost_io.nrs_policies="$old_nrs"
3643
3644         sleep 3
3645 }
3646
3647 test_77k() {
3648         [[ $(lustre_version_code ost1) -ge $(version_code 2.9.53) ]] ||
3649                 { skip "Need OST version at least 2.9.53"; return 0; }
3650
3651         do_nodes $(comma_list $(osts_nodes)) \
3652                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf" \
3653                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ jobid={dd.$RUNAS_ID}\&opcode={ost_write}\ rate=20" \
3654                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ jobid={dd.$RUNAS_ID}\&opcode={ost_read}\ rate=10"
3655
3656         nrs_write_read "$RUNAS"
3657         tbf_verify 20 10 "$RUNAS"
3658
3659         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3660         local client_nids=$(nids_list $address "\\")
3661         do_nodes $(comma_list $(osts_nodes)) \
3662                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3663                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3664                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ nid={0@lo\ $client_nids}\&opcode={ost_write}\ rate=20" \
3665                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ nid={0@lo\ $client_nids}\&opcode={ost_read}\ rate=10"
3666
3667         nrs_write_read
3668         tbf_verify 20 10
3669
3670         do_nodes $(comma_list $(osts_nodes)) \
3671                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3672                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3673                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext\ nid={0@lo\ $client_nids}\&jobid={dd.$RUNAS_ID}\ rate=20"
3674
3675         nrs_write_read "$RUNAS"
3676         tbf_verify 20 20 "$RUNAS"
3677
3678         do_nodes $(comma_list $(osts_nodes)) \
3679                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext" \
3680                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ jobid={dd.$RUNAS_ID},opcode={ost_write}\ rate=20" \
3681                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ jobid={dd.$RUNAS_ID},opcode={ost_read}\ rate=10"
3682
3683         nrs_write_read "$RUNAS"
3684         # with parameter "RUNAS", it will match the latest rule
3685         # "ext_b" first, so the limited write rate is 10.
3686         tbf_verify 10 10 "$RUNAS"
3687         tbf_verify 20 10
3688
3689         trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
3690
3691         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.58) ]] ||
3692                 { skip "Need OST version at least 2.10.58"; return 0; }
3693
3694         do_nodes $(comma_list $(osts_nodes)) \
3695                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_a" \
3696                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_b" \
3697                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={500}\&gid={1000}\ rate=5"
3698         nrs_write_read "runas -u 500 -g 1000"
3699         tbf_verify 5 5 "runas -u 500 -g 1000"
3700
3701         do_nodes $(comma_list $(osts_nodes)) \
3702                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ug" \
3703                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={500}\&opcode={ost_write}\ rate=20" \
3704                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={500}\&opcode={ost_read}\ rate=10"
3705
3706         nrs_write_read "runas -u 500"
3707         tbf_verify 20 10 "runas -u 500"
3708
3709         do_nodes $(comma_list $(osts_nodes)) \
3710                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_uw" \
3711                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ur" \
3712                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={500},opcode={ost_write}\ rate=20" \
3713                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={500},opcode={ost_read}\ rate=10"
3714         nrs_write_read "runas -u 500"
3715         tbf_verify 10 10 "runas -u 500"
3716         tbf_verify 20 10 "runas -u 500"
3717         cleanup_77k "ext_a ext_b" "fifo"
3718 }
3719 run_test 77k "check TBF policy with NID/JobID/OPCode expression"
3720
3721 test_77l() {
3722         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.56) ]] ||
3723                 { skip "Need OST version at least 2.10.56"; return 0; }
3724
3725         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
3726         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf"
3727
3728         local output=$(do_facet ost1 lctl get_param \
3729                         ost.OSS.ost_io.nrs_policies | \
3730                         awk '/name: tbf/ {print;exit}' | \
3731                         awk -F ': ' '{print $2}')
3732
3733         if [ "$output" != "tbf" ]; then
3734                 error "The generic TBF output is '$output', not 'tbf'"
3735         fi
3736
3737         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3738 }
3739 run_test 77l "check the output of NRS policies for generic TBF"
3740
3741 test_77m() {
3742         if [ $(lustre_version_code ost1) -lt $(version_code 2.9.54) ]; then
3743                 skip "Need OST version at least 2.9.54"
3744                 return 0
3745         fi
3746
3747         local dir=$DIR/$tdir
3748
3749         mkdir $dir || error "mkdir $dir failed"
3750         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3751         chmod 777 $dir
3752
3753         local nodes=$(comma_list $(osts_nodes))
3754         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies=delay \
3755                                        ost.OSS.ost_io.nrs_delay_min=4 \
3756                                        ost.OSS.ost_io.nrs_delay_max=4 \
3757                                        ost.OSS.ost_io.nrs_delay_pct=100
3758         [ $? -ne 0 ] && error "Failed to set delay policy"
3759
3760         local start=$SECONDS
3761         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3762                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=1 \
3763                    oflag=direct conv=fdatasync ||
3764                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3765                   error "dd on client failed (1)"; }
3766         local elapsed=$((SECONDS - start))
3767
3768         # NRS delay doesn't do sub-second timing, so a request enqueued at
3769         # 0.9 seconds can be dequeued at 4.0
3770         [ $elapsed -lt 3 ] &&
3771                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3772                   error "Single 1M write should take at least 3 seconds"; }
3773
3774         start=$SECONDS
3775         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3776                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=10 \
3777                    oflag=direct conv=fdatasync ||
3778                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3779                   error "dd on client failed (2)"; }
3780         elapsed=$((SECONDS - start))
3781
3782         [ $elapsed -lt 30 ] &&
3783                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3784                   error "Ten 1M writes should take at least 30 seconds"; }
3785
3786         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3787         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3788
3789         return 0
3790 }
3791 run_test 77m "check NRS Delay slows write RPC processing"
3792
3793 test_77n() { #LU-10802
3794         if [ $(lustre_version_code ost1) -lt $(version_code 2.10.58) ]; then
3795                 skip "Need OST version at least 2.10.58"
3796                 return 0
3797         fi
3798
3799         # Configure jobid_var
3800         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3801         if [ $saved_jobid_var != procname_uid ]; then
3802                 set_persistent_param_and_check client \
3803                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3804         fi
3805
3806         do_nodes $(comma_list $(osts_nodes)) \
3807                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid" \
3808                         ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3809                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={*.$RUNAS_ID}\ rate=20"
3810
3811         nrs_write_read
3812         tbf_verify 20 20 "$RUNAS"
3813
3814         do_nodes $(comma_list $(osts_nodes)) \
3815                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3816                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={dd.*}\ rate=20"
3817
3818         nrs_write_read
3819         tbf_verify 20 20
3820
3821         do_nodes $(comma_list $(osts_nodes)) \
3822                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3823                         ost.OSS.ost_io.nrs_policies="fifo"
3824
3825         sleep 3
3826
3827         local current_jobid_var=$($LCTL get_param -n jobid_var)
3828         if [ $saved_jobid_var != $current_jobid_var ]; then
3829                 set_persistent_param_and_check client \
3830                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3831         fi
3832 }
3833 run_test 77n "check wildcard support for TBF JobID NRS policy"
3834
3835 test_78() { #LU-6673
3836         local rc
3837
3838         oss=$(comma_list $(osts_nodes))
3839         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
3840         do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
3841         rc=$?
3842         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3843         # Valid return codes are:
3844         # 0: Tuning succeeded
3845         # ENODEV: Policy is still stopped
3846         # EAGAIN: Policy is being initialized
3847         [ $rc -eq 0 -o $rc -eq 19 -o $rc -eq 11 ] ||
3848                 error "Expected set_param to return 0|ENODEV|EAGAIN"
3849
3850         # Cleanup the ORR policy
3851         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3852         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3853         return 0
3854 }
3855 run_test 78 "Enable policy and specify tunings right away"
3856
3857 test_79() {
3858         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3859         test_mkdir $DIR/$tdir
3860
3861         # Prevent interference from layout intent RPCs due to
3862         # asynchronous writeback. These will be tested in 130c below.
3863         do_nodes ${CLIENTS:-$HOSTNAME} sync
3864
3865         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
3866                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
3867
3868 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
3869         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
3870         local facet=mds$((mdtidx + 1))
3871         stat $DIR/$tdir
3872         set_nodes_failloc $(facet_active_host $facet) 0x80000160
3873         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null  &
3874         local pid=$!
3875         sleep 2
3876
3877 #define OBD_FAIL_MDS_GETXATTR_PACK       0x131
3878         set_nodes_failloc $(facet_active_host $facet) 0x80000131
3879
3880         wait $pid
3881         return 0
3882 }
3883 run_test 79 "xattr: intent error"
3884
3885 test_80a() {
3886         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3887         local MDTIDX=1
3888         local mdt_index
3889         local i
3890         local file
3891         local pid
3892
3893         mkdir -p $DIR1/$tdir/dir
3894         createmany -o $DIR1/$tdir/dir/f 10 ||
3895                 error "create files under remote dir failed $i"
3896
3897         cp /etc/passwd $DIR1/$tdir/$tfile
3898
3899         #migrate open file should fails
3900         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
3901         pid=$!
3902         # give multiop a chance to open
3903         sleep 1
3904
3905         $LFS migrate -m $MDTIDX $DIR1/$tdir &&
3906                 error "migrate open files should failed with open files"
3907
3908         kill -USR1 $pid
3909
3910         $LFS migrate -m $MDTIDX $DIR1/$tdir ||
3911                         error "migrate remote dir error"
3912
3913         echo "Finish migration, then checking.."
3914         for file in $(find $DIR1/$tdir); do
3915                 mdt_index=$($LFS getstripe -m $file)
3916                 [ $mdt_index == $MDTIDX ] ||
3917                         error "$file is not on MDT${MDTIDX}"
3918         done
3919
3920         diff /etc/passwd $DIR1/$tdir/$tfile ||
3921                 error "file different after migration"
3922
3923         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
3924 }
3925 run_test 80a "migrate directory when some children is being opened"
3926
3927 cleanup_80b() {
3928         trap 0
3929         kill -9 $migrate_pid
3930 }
3931
3932 test_80b() {
3933         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3934         local migrate_dir1=$DIR1/$tdir/migrate_dir
3935         local migrate_dir2=$DIR2/$tdir/migrate_dir
3936         local migrate_run=$LUSTRE/tests/migrate.sh
3937         local start_time
3938         local end_time
3939         local show_time=1
3940         local mdt_idx
3941         local rc=0
3942         local rc1=0
3943
3944         trap cleanup_80b EXIT
3945         #prepare migrate directory
3946         mkdir -p $migrate_dir1
3947         for F in {1,2,3,4,5}; do
3948                 echo "$F$F$F$F$F" > $migrate_dir1/file$F
3949                 echo "$F$F$F$F$F" > $DIR/$tdir/file$F
3950         done
3951
3952         #migrate the directories among MDTs
3953         (
3954                 while true; do
3955                         mdt_idx=$((RANDOM % MDSCOUNT))
3956                         $LFS migrate -m $mdt_idx $migrate_dir1 &>/dev/null ||
3957                                 rc=$?
3958                         [ $rc -ne 0 -o $rc -ne 16 ] || break
3959                 done
3960         ) &
3961         migrate_pid=$!
3962
3963         echo "start migration thread $migrate_pid"
3964         #Access the files at the same time
3965         start_time=$(date +%s)
3966         echo "accessing the migrating directory for 5 minutes..."
3967         while true; do
3968                 ls $migrate_dir2 > /dev/null || {
3969                         echo "read dir fails"
3970                         break
3971                 }
3972                 diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
3973                         echo "access file1 fails"
3974                         break
3975                 }
3976
3977                 cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
3978                         echo "access file2/3 fails"
3979                         break
3980                 }
3981
3982                 echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
3983                         echo "access file4 fails"
3984                         break
3985                 }
3986
3987                 stat $migrate_dir2/file5 > /dev/null || {
3988                         echo "stat file5 fails"
3989                         break
3990                 }
3991
3992                 touch $migrate_dir2/source_file > /dev/null || rc1=$?
3993                 [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
3994                         echo "touch file failed with $rc1"
3995                         break;
3996                 }
3997
3998                 if [ -e $migrate_dir2/source_file ]; then
3999                         ln $migrate_dir2/source_file $migrate_dir2/link_file \
4000                                         &>/dev/null || rc1=$?
4001                         if [ -e $migrate_dir2/link_file ]; then
4002                                 rm -rf $migrate_dir2/link_file
4003                         fi
4004
4005                         mrename $migrate_dir2/source_file \
4006                                 $migrate_dir2/target_file &>/dev/null || rc1=$?
4007                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4008                                 echo "rename failed with $rc1"
4009                                 break
4010                         }
4011
4012                         if [ -e $migrate_dir2/target_file ]; then
4013                                 rm -rf $migrate_dir2/target_file &>/dev/null ||
4014                                                                 rc1=$?
4015                         else
4016                                 rm -rf $migrate_dir2/source_file &>/dev/null ||
4017                                                                 rc1=$?
4018                         fi
4019                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4020                                 echo "unlink failed with $rc1"
4021                                 break
4022                         }
4023                 fi
4024
4025                 end_time=$(date +%s)
4026                 duration=$((end_time - start_time))
4027                 if [ $((duration % 10)) -eq 0 ]; then
4028                         if [ $show_time -eq 1 ]; then
4029                                 echo "...$duration seconds"
4030                                 show_time=0
4031                         fi
4032                 else
4033                         show_time=1
4034                 fi
4035
4036                 kill -0 $migrate_pid || {
4037                         echo "migration stopped 1"
4038                         break
4039                 }
4040
4041                 [ $duration -ge 300 ] && break
4042         done
4043
4044         #check migration are still there
4045         kill -0 $migrate_pid || error "migration stopped 2"
4046         cleanup_80b
4047 }
4048 run_test 80b "Accessing directory during migration"
4049
4050 test_81a() {
4051         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4052
4053         rm -rf $DIR1/$tdir
4054
4055         mkdir -p $DIR1/$tdir
4056
4057         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
4058         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
4059
4060         cd $DIR1/$tdir
4061         touch d0/0      || error "create 0 failed"
4062         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
4063         stat d0/0       && error "stat mv filed succeed"
4064         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || error "rename d1/0 d0/0 failed"
4065         stat d0/0       || error "stat failed"
4066
4067         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
4068
4069         if [ $t -ne 3 ]; then
4070                 ls -ai $DIR1/$tdir/d0
4071                 error "expect 3 get $t"
4072         fi
4073
4074         return 0
4075 }
4076 run_test 81a "rename and stat under striped directory"
4077
4078 test_81b() {
4079         [ $MDSCOUNT -lt 2 ] &&
4080                 skip "We need at least 2 MDTs for this test"
4081
4082         local total
4083         local setattr_pid
4084
4085         total=1000
4086
4087         $LFS mkdir -c $MDSCOUNT $DIR1/$tdir || error "$LFS mkdir"
4088         createmany -o $DIR1/$tdir/$tfile. $total || error "createmany"
4089
4090         (
4091                 while true; do
4092                         touch $DIR1/$tdir
4093                 done
4094         ) &
4095         setattr_pid=$!
4096
4097         for i in $(seq $total); do
4098                 mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
4099                         > /dev/null
4100         done
4101
4102         kill -9 $setattr_pid
4103 }
4104 run_test 81b "rename under striped directory doesn't deadlock"
4105
4106 test_82() {
4107         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
4108                 { skip "Need MDS version at least 2.6.92"; return 0; }
4109
4110         # Client 1 creates a file.
4111         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
4112         pid1=$!
4113         # Client 2 opens the file.
4114         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
4115         pid2=$!
4116         # Client 1 makes the file an orphan.
4117         rm $DIR1/$tfile || error "rm"
4118         # Client 2 sets EA "user.multiop".
4119         kill -s USR1 $pid2
4120         wait $pid2 || error "multiop 2"
4121         # Client 1 gets EA "user.multiop".  This used to fail because the EA
4122         # cache refill would get "trusted.link" from mdd_xattr_list() but
4123         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
4124         # 102q.
4125         kill -s USR1 $pid1
4126         wait $pid1 || error "multiop 1"
4127 }
4128 run_test 82 "fsetxattr and fgetxattr on orphan files"
4129
4130 test_83() {
4131         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4132         local pid1
4133         local pid2
4134
4135         (
4136                 cd $DIR1
4137                 while true; do
4138                         $LFS mkdir -i1 -c2 $tdir
4139                         rmdir $tdir
4140                 done
4141         ) &
4142         pid1=$!
4143         echo "start pid $pid1 to create/unlink striped directory"
4144
4145         # Access the directory at the same time
4146         (
4147                 cd $DIR2
4148                 while true; do
4149                         stat $tdir > /dev/null 2>&1
4150                 done
4151         ) &
4152         pid2=$!
4153         echo "start pid $pid2 to stat striped directory"
4154
4155         sleep 120
4156         kill $pid1 $pid2
4157         wait $pid1 $pid2
4158
4159         return 0
4160 }
4161 run_test 83 "access striped directory while it is being created/unlinked"
4162
4163 test_90() {
4164         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4165         local pid1
4166         local pid2
4167         local duration=180
4168
4169         [ "$SLOW" = "yes" ] && duration=600
4170         # Open/Create under striped directory
4171         (
4172                 cd $DIR1
4173                 while true; do
4174                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4175                         touch $tdir/f{0..3} > /dev/null 2>&1
4176                 done
4177         ) &
4178         pid1=$!
4179         echo "start pid $pid1 to open/create under striped directory"
4180
4181         # unlink the striped directory at the same time
4182         (
4183                 cd $DIR2
4184                 while true; do
4185                         rm -rf $tdir > /dev/null 2>&1
4186                 done
4187         ) &
4188         pid2=$!
4189         echo "start pid $pid2 to unlink striped directory"
4190
4191         sleep $duration
4192
4193         kill $pid1 $pid2
4194         wait $pid1 $pid2
4195
4196         return 0
4197 }
4198 run_test 90 "open/create and unlink striped directory"
4199
4200 test_91() {
4201         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4202         local pid1
4203         local pid2
4204         local duration=180
4205
4206         [ "$SLOW" = "yes" ] && duration=600
4207         # chmod striped directory
4208         (
4209                 cd $DIR1
4210                 while true; do
4211                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4212                         chmod go+w $tdir > /dev/null 2>&1
4213                 done
4214         ) &
4215         pid1=$!
4216         echo "start pid $pid1 to chmod striped directory"
4217
4218         # unlink the striped directory at the same time
4219         (
4220                 cd $DIR2
4221                 while true; do
4222                         rm -rf $tdir > /dev/null 2>&1
4223                 done
4224         ) &
4225         pid2=$!
4226         echo "start pid $pid2 to unlink striped directory"
4227
4228         sleep $duration
4229
4230         kill $pid1 $pid2
4231         wait $pid1 $pid2
4232
4233         return 0
4234 }
4235 run_test 91 "chmod and unlink striped directory"
4236
4237 test_92() {
4238         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4239
4240         local fd=$(free_fd)
4241         local cmd="exec $fd<$DIR1/$tdir"
4242         $LFS setdirstripe -c$MDSCOUNT $DIR1/$tdir || error "mkdir $tdir fails"
4243         eval $cmd
4244         cmd="exec $fd<&-"
4245         trap "eval $cmd" EXIT
4246         cd $DIR1/$tdir || error "cd $DIR1/$tdir fails"
4247         rmdir ../$tdir || error "rmdir ../$tdir fails"
4248
4249         #define OBD_FAIL_LLITE_NO_CHECK_DEAD  0x1408
4250         $LCTL set_param fail_loc=0x1408
4251         mkdir $DIR2/$tdir/dir && error "create dir succeeds"
4252         $LFS setdirstripe -i1 $DIR2/$tdir/remote_dir &&
4253                 error "create remote dir succeeds"
4254         $LCTL set_param fail_loc=0
4255         eval $cmd
4256         return 0
4257 }
4258 run_test 92 "create remote directory under orphan directory"
4259
4260 test_93() {
4261         local rc1=0
4262         local rc2=0
4263         local old_rr
4264
4265         mkdir -p $DIR1/$tfile-1/
4266         mkdir -p $DIR2/$tfile-2/
4267         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
4268                 'lod.lustre-MDT*/qos_threshold_rr' | sed -e 's/%//')
4269         do_facet $SINGLEMDS lctl set_param -n \
4270                 'lod.lustre-MDT*/qos_threshold_rr' 100
4271         #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
4272         do_facet $SINGLEMDS "lctl set_param fail_loc=0x00000163"
4273
4274         $LFS setstripe -c -1 $DIR1/$tfile-1/file1 &
4275         local PID1=$!
4276         sleep 1
4277         $LFS setstripe -c -1 $DIR2/$tfile-2/file2 &
4278         local PID2=$!
4279         wait $PID2
4280         wait $PID1
4281         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
4282         do_facet $SINGLEMDS "lctl set_param -n \
4283                 'lod.lustre-MDT*/qos_threshold_rr' $old_rr"
4284
4285         $LFS getstripe $DIR1/$tfile-1/file1
4286         rc1=$($LFS getstripe -q $DIR1/$tfile-1/file1 |
4287                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4288         $LFS getstripe $DIR2/$tfile-2/file2
4289         rc2=$($LFS getstripe -q $DIR2/$tfile-2/file2 |
4290                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4291         echo "rc1=$rc1 and rc2=$rc2 "
4292         [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
4293                 error "object allocate on same ost detected"
4294 }
4295 run_test 93 "alloc_rr should not allocate on same ost"
4296
4297 # Data-on-MDT tests
4298 test_100a() {
4299         skip "Reserved for glimpse-ahead" && return
4300         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4301                 skip "Need MDS version at least 2.10.55" && return
4302
4303         mkdir -p $DIR/$tdir
4304
4305         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4306
4307         lctl set_param -n mdc.*.stats=clear
4308         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4309
4310         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4311         # first stat from server should return size data and save glimpse
4312         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4313         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
4314         # second stat to check size is NOT cached on client without IO lock
4315         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4316
4317         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4318         [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
4319         rm -f $dom
4320 }
4321 run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
4322
4323 test_100b() {
4324         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4325                 skip "Need MDS version at least 2.10.55" && return
4326
4327         mkdir -p $DIR/$tdir
4328
4329         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4330
4331         lctl set_param -n mdc.*.stats=clear
4332         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4333         cancel_lru_locks mdc
4334         # first stat data from server should have size
4335         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4336         # second stat to check size is cached on client
4337         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4338
4339         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4340         # both stats should cause no glimpse requests
4341         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
4342         rm -f $dom
4343 }
4344 run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
4345
4346 test_100c() {
4347         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4348                 skip "Need MDS version at least 2.10.55" && return
4349
4350         mkdir -p $DIR/$tdir
4351
4352         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4353
4354         lctl set_param -n mdc.*.stats=clear
4355         lctl set_param -n osc.*.stats=clear
4356         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4357
4358         # check that size is merged from MDT and OST correctly
4359         $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
4360                 error "Wrong size from stat #1"
4361
4362         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4363         [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
4364
4365         rm -f $dom
4366 }
4367 run_test 100c "DoM: write vs stat without IO lock (combined file)"
4368
4369 test_100d() {
4370         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4371                 skip "Need MDS version at least 2.10.55" && return
4372
4373         mkdir -p $DIR/$tdir
4374
4375         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4376
4377
4378         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4379         lctl set_param -n mdc.*.stats=clear
4380         $TRUNCATE $DIR2/$tdir/dom 4096
4381
4382         # check that reported size is valid after file grows to OST and
4383         # is truncated back to MDT stripe size
4384         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
4385                 error "Wrong size from stat #1"
4386
4387         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4388         [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
4389
4390         rm -f $dom
4391 }
4392 run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
4393
4394 test_101a() {
4395         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4396                 skip "Need MDS version at least 2.10.55" && return
4397
4398         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4399         # to get layout
4400         $CHECKSTAT -t file $DIR1/$tfile
4401
4402         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4403         sysctl -wq vm.dirty_writeback_centisecs=0
4404
4405         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4406
4407         # open + IO lock
4408         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
4409                 error_noexit "Write fails"
4410         # must discard pages
4411         lctl set_param -n mdc.*.stats=clear
4412         rm $DIR2/$tfile || error "Unlink fails"
4413
4414         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4415         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4416 }
4417 run_test 101a "Discard DoM data on unlink"
4418
4419 test_101b() {
4420         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4421                 skip "Need MDS version at least 2.10.55" && return
4422
4423         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4424         touch $DIR1/${tfile}_2
4425         # to get layout
4426         $CHECKSTAT -t file $DIR1/$tfile
4427
4428         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4429         sysctl -wq vm.dirty_writeback_centisecs=0
4430
4431         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4432
4433         # open + IO lock
4434         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4435         # must discard pages
4436         lctl set_param -n mdc.*.stats=clear
4437         mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
4438
4439         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4440         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4441 }
4442 run_test 101b "Discard DoM data on rename"
4443
4444 test_101c() {
4445         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4446                 skip "Need MDS version at least 2.10.55" && return
4447
4448         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4449         # to get layout
4450         $CHECKSTAT -t file $DIR1/$tfile
4451
4452         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4453         sysctl -wq vm.dirty_writeback_centisecs=0
4454
4455         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4456
4457         # open + IO lock
4458         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4459         $MULTIOP $DIR1/$tfile O_c &
4460         MULTIOP_PID=$!
4461         sleep 1
4462         lctl set_param -n mdc.*.stats=clear
4463         rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
4464         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
4465
4466         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4467         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4468 }
4469 run_test 101c "Discard DoM data on close-unlink"
4470
4471 # test to verify file handle related system calls
4472 # (name_to_handle_at/open_by_handle_at)
4473 # The new system calls are supported in glibc >= 2.14.
4474
4475 # test to verify we can open by handle an unlinked file from > 1 client
4476 # This test opens the file normally on $DIR1, which is on one mount, and then
4477 # opens it by handle on $DIR2, which is on a different mount.
4478 test_102() {
4479         echo "Test file_handle syscalls" > $DIR/$tfile ||
4480                 error "write failed"
4481         check_fhandle_syscalls $DIR/$tfile $DIR2 ||
4482                 error "check_fhandle_syscalls failed"
4483         rm -f $DIR2/$tfile
4484 }
4485 run_test 102 "Test open by handle of unlinked file"
4486
4487 log "cleanup: ======================================================"
4488
4489 # kill and wait in each test only guarentee script finish, but command in script
4490 # like 'rm' 'chmod' may still be running, wait for all commands to finish
4491 # otherwise umount below will fail
4492 [ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
4493         true
4494
4495 complete $SECONDS
4496 rm -f $SAMPLE_FILE
4497 check_and_cleanup_lustre
4498 exit_status