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