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