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