Whamcloud - gitweb
LU-5814 lov: move LSM to LOV layer
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19 SRCDIR=$(cd $(dirname $0); echo $PWD)
20 export PATH=$PATH:/sbin
21
22 TMP=${TMP:-/tmp}
23
24 CC=${CC:-cc}
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
27 LFS=${LFS:-lfs}
28 LFIND=${LFIND:-"$LFS find"}
29 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
30 LCTL=${LCTL:-lctl}
31 OPENFILE=${OPENFILE:-openfile}
32 OPENUNLINK=${OPENUNLINK:-openunlink}
33 export MULTIOP=${MULTIOP:-multiop}
34 READS=${READS:-"reads"}
35 MUNLINK=${MUNLINK:-munlink}
36 SOCKETSERVER=${SOCKETSERVER:-socketserver}
37 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
38 MEMHOG=${MEMHOG:-memhog}
39 DIRECTIO=${DIRECTIO:-directio}
40 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
41 UMOUNT=${UMOUNT:-"umount -d"}
42 STRIPES_PER_OBJ=-1
43 CHECK_GRANT=${CHECK_GRANT:-"yes"}
44 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
45 export PARALLEL=${PARALLEL:-"no"}
46
47 export NAME=${NAME:-local}
48
49 SAVE_PWD=$PWD
50
51 CLEANUP=${CLEANUP:-:}
52 SETUP=${SETUP:-:}
53 TRACE=${TRACE:-""}
54 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
55 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
56 . $LUSTRE/tests/test-framework.sh
57 init_test_env $@
58 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
59 init_logging
60
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24D 27m 64b 68 71 77f 78 115 124b 230d"
62
63 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
64         # bug number for skipped test: LU-4536 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180     184c"
66         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
67 fi
68
69 FAIL_ON_ERROR=false
70
71 cleanup() {
72         echo -n "cln.."
73         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
74         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
75 }
76 setup() {
77         echo -n "mnt.."
78         load_modules
79         setupall || exit 10
80         echo "done"
81 }
82
83 check_swap_layouts_support()
84 {
85         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
86                 { skip "Does not support layout lock."; return 0; }
87         return 1
88 }
89
90 check_and_setup_lustre
91
92 DIR=${DIR:-$MOUNT}
93 assert_DIR
94
95 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
96         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
97 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
98 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
99 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
100 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
101 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
102 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
103
104 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
105 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
106 rm -rf $DIR/[Rdfs][0-9]*
107
108 # $RUNAS_ID may get set incorrectly somewhere else
109 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
110
111 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
112
113 build_test_filter
114
115 if [ "${ONLY}" = "MOUNT" ] ; then
116         echo "Lustre is up, please go on"
117         exit
118 fi
119
120 echo "preparing for tests involving mounts"
121 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
122 touch $EXT2_DEV
123 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
124 echo # add a newline after mke2fs.
125
126 umask 077
127
128 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
129 lctl set_param debug=-1 2> /dev/null || true
130 test_0a() {
131         touch $DIR/$tfile
132         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
133         rm $DIR/$tfile
134         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
135 }
136 run_test 0a "touch; rm ====================="
137
138 test_0b() {
139         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
140         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
141 }
142 run_test 0b "chmod 0755 $DIR ============================="
143
144 test_0c() {
145         $LCTL get_param mdc.*.import | grep "state: FULL" ||
146                 error "import not FULL"
147         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
148                 error "bad target"
149 }
150 run_test 0c "check import proc ============================="
151
152 test_1() {
153         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
154         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
155         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
156         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
157         rmdir $DIR/$tdir/d2
158         rmdir $DIR/$tdir
159         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
160 }
161 run_test 1 "mkdir; remkdir; rmdir =============================="
162
163 test_2() {
164         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
165         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
166         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
167         rm -r $DIR/$tdir
168         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
169 }
170 run_test 2 "mkdir; touch; rmdir; check file ===================="
171
172 test_3() {
173         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
174         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
175         touch $DIR/$tdir/$tfile
176         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
177         rm -r $DIR/$tdir
178         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
179 }
180 run_test 3 "mkdir; touch; rmdir; check dir ====================="
181
182 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
183 test_4() {
184         local MDTIDX=1
185
186         test_mkdir $DIR/$tdir ||
187                 error "Create remote directory failed"
188
189         touch $DIR/$tdir/$tfile ||
190                 error "Create file under remote directory failed"
191
192         rmdir $DIR/$tdir &&
193                 error "Expect error removing in-use dir $DIR/$tdir"
194
195         test -d $DIR/$tdir || error "Remote directory disappeared"
196
197         rm -rf $DIR/$tdir || error "remove remote dir error"
198 }
199 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
200
201 test_5() {
202         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
203         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
204         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
205         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
206         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
207 }
208 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
209
210 test_6a() {
211         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
212         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
213         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
214                 error "$tfile does not have perm 0666 or UID $UID"
215         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
216         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
217                 error "$tfile should be 0666 and owned by UID $UID"
218 }
219 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
220
221 test_6c() {
222         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
223         touch $DIR/$tfile
224         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
225         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
226                 error "$tfile should be owned by UID $RUNAS_ID"
227         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
228         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
229                 error "$tfile should be owned by UID $RUNAS_ID"
230 }
231 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
232
233 test_6e() {
234         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
235         touch $DIR/$tfile
236         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
237         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
238                 error "$tfile should be owned by GID $UID"
239         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
240         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
241                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
242 }
243 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
244
245 test_6g() {
246         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
247         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
248         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
249         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
250         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
251         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
252         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
253                 error "$tdir/d/subdir should be GID $RUNAS_GID"
254 }
255 run_test 6g "Is new dir in sgid dir inheriting group?"
256
257 test_6h() { # bug 7331
258         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
259         touch $DIR/$tfile || error "touch failed"
260         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
261         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
262                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
263         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
264                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
265 }
266 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
267
268 test_7a() {
269         test_mkdir $DIR/$tdir
270         $MCREATE $DIR/$tdir/$tfile
271         chmod 0666 $DIR/$tdir/$tfile
272         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
273                 error "$tdir/$tfile should be mode 0666"
274 }
275 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
276
277 test_7b() {
278         if [ ! -d $DIR/$tdir ]; then
279                 mkdir $DIR/$tdir
280         fi
281         $MCREATE $DIR/$tdir/$tfile
282         echo -n foo > $DIR/$tdir/$tfile
283         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
284         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
285 }
286 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
287
288 test_8() {
289         test_mkdir $DIR/$tdir
290         touch $DIR/$tdir/$tfile
291         chmod 0666 $DIR/$tdir/$tfile
292         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
293                 error "$tfile mode not 0666"
294 }
295 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
296
297 test_9() {
298         test_mkdir $DIR/$tdir
299         test_mkdir $DIR/$tdir/d2
300         test_mkdir $DIR/$tdir/d2/d3
301         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
302 }
303 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
304
305 test_10() {
306         test_mkdir $DIR/$tdir
307         test_mkdir $DIR/$tdir/d2
308         touch $DIR/$tdir/d2/$tfile
309         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
310                 error "$tdir/d2/$tfile not a file"
311 }
312 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
313
314 test_11() {
315         test_mkdir $DIR/$tdir
316         test_mkdir $DIR/$tdir/d2
317         chmod 0666 $DIR/$tdir/d2
318         chmod 0705 $DIR/$tdir/d2
319         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
320                 error "$tdir/d2 mode not 0705"
321 }
322 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
323
324 test_12() {
325         test_mkdir $DIR/$tdir
326         touch $DIR/$tdir/$tfile
327         chmod 0666 $DIR/$tdir/$tfile
328         chmod 0654 $DIR/$tdir/$tfile
329         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
330                 error "$tdir/d2 mode not 0654"
331 }
332 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
333
334 test_13() {
335         test_mkdir $DIR/$tdir
336         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
337         >  $DIR/$tdir/$tfile
338         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
339                 error "$tdir/$tfile size not 0 after truncate"
340 }
341 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
342
343 test_14() {
344         test_mkdir $DIR/$tdir
345         touch $DIR/$tdir/$tfile
346         rm $DIR/$tdir/$tfile
347         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
348 }
349 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
350
351 test_15() {
352         test_mkdir $DIR/$tdir
353         touch $DIR/$tdir/$tfile
354         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
355         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
356                 error "$tdir/${tfile_2} not a file after rename"
357 }
358 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
359
360 test_16() {
361         test_mkdir $DIR/$tdir
362         touch $DIR/$tdir/$tfile
363         rm -rf $DIR/$tdir/$tfile
364         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
365 }
366 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
367
368 test_17a() {
369         test_mkdir -p $DIR/$tdir
370         touch $DIR/$tdir/$tfile
371         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
372         ls -l $DIR/$tdir
373         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
374                 error "$tdir/l-exist not a symlink"
375         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
376                 error "$tdir/l-exist not referencing a file"
377         rm -f $DIR/$tdir/l-exist
378         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
379 }
380 run_test 17a "symlinks: create, remove (real) =================="
381
382 test_17b() {
383         test_mkdir -p $DIR/$tdir
384         ln -s no-such-file $DIR/$tdir/l-dangle
385         ls -l $DIR/$tdir
386         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
387                 error "$tdir/l-dangle not referencing no-such-file"
388         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
389                 error "$tdir/l-dangle not referencing non-existent file"
390         rm -f $DIR/$tdir/l-dangle
391         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
392 }
393 run_test 17b "symlinks: create, remove (dangling) =============="
394
395 test_17c() { # bug 3440 - don't save failed open RPC for replay
396         test_mkdir -p $DIR/$tdir
397         ln -s foo $DIR/$tdir/$tfile
398         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
399 }
400 run_test 17c "symlinks: open dangling (should return error) ===="
401
402 test_17d() {
403         test_mkdir -p $DIR/$tdir
404         ln -s foo $DIR/$tdir/$tfile
405         touch $DIR/$tdir/$tfile || error "creating to new symlink"
406 }
407 run_test 17d "symlinks: create dangling ========================"
408
409 test_17e() {
410         test_mkdir -p $DIR/$tdir
411         local foo=$DIR/$tdir/$tfile
412         ln -s $foo $foo || error "create symlink failed"
413         ls -l $foo || error "ls -l failed"
414         ls $foo && error "ls not failed" || true
415 }
416 run_test 17e "symlinks: create recursive symlink (should return error) ===="
417
418 test_17f() {
419         test_mkdir -p $DIR/$tdir
420         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
421         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
422         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
423         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
424         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
425         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/$tdir/666
426         ls -l  $DIR/$tdir
427 }
428 run_test 17f "symlinks: long and very long symlink name ========================"
429
430 # str_repeat(S, N) generate a string that is string S repeated N times
431 str_repeat() {
432         local s=$1
433         local n=$2
434         local ret=''
435         while [ $((n -= 1)) -ge 0 ]; do
436                 ret=$ret$s
437         done
438         echo $ret
439 }
440
441 # Long symlinks and LU-2241
442 test_17g() {
443         test_mkdir -p $DIR/$tdir
444         local TESTS="59 60 61 4094 4095"
445
446         # Fix for inode size boundary in 2.1.4
447         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
448                 TESTS="4094 4095"
449
450         # Patch not applied to 2.2 or 2.3 branches
451         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
452         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
453                 TESTS="4094 4095"
454
455         # skip long symlink name for rhel6.5.
456         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
457         grep -q '6.5' /etc/redhat-release &>/dev/null &&
458                 TESTS="59 60 61 4062 4063"
459
460         for i in $TESTS; do
461                 local SYMNAME=$(str_repeat 'x' $i)
462                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
463                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
464         done
465 }
466 run_test 17g "symlinks: really long symlink name and inode boundaries"
467
468 test_17h() { #bug 17378
469         remote_mds_nodsh && skip "remote MDS with nodsh" && return
470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
471         local mdt_idx
472         test_mkdir -p $DIR/$tdir
473         if [[ $MDSCOUNT -gt 1 ]]; then
474                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
475         else
476                 mdt_idx=0
477         fi
478         $SETSTRIPE -c -1 $DIR/$tdir
479 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
480         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
481         touch $DIR/$tdir/$tfile || true
482 }
483 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
484
485 test_17i() { #bug 20018
486         remote_mds_nodsh && skip "remote MDS with nodsh" && return
487         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
488         test_mkdir -c1 $DIR/$tdir
489         local foo=$DIR/$tdir/$tfile
490         local mdt_idx
491         if [[ $MDSCOUNT -gt 1 ]]; then
492                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
493         else
494                 mdt_idx=0
495         fi
496         ln -s $foo $foo || error "create symlink failed"
497 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
498         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
499         ls -l $foo && error "error not detected"
500         return 0
501 }
502 run_test 17i "don't panic on short symlink"
503
504 test_17k() { #bug 22301
505         [[ -z "$(which rsync 2>/dev/null)" ]] &&
506                 skip "no rsync command" && return 0
507         rsync --help | grep -q xattr ||
508                 skip_env "$(rsync --version | head -n1) does not support xattrs"
509         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
510         test_mkdir -p $DIR/$tdir
511         test_mkdir -p $DIR/$tdir.new
512         touch $DIR/$tdir/$tfile
513         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
514         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
515                 error "rsync failed with xattrs enabled"
516 }
517 run_test 17k "symlinks: rsync with xattrs enabled ========================="
518
519 test_17l() { # LU-279
520         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
521                 skip "no getfattr command" && return 0
522         mkdir -p $DIR/$tdir
523         touch $DIR/$tdir/$tfile
524         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
525         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
526                 # -h to not follow symlinks. -m '' to list all the xattrs.
527                 # grep to remove first line: '# file: $path'.
528                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
529                 do
530                         lgetxattr_size_check $path $xattr ||
531                                 error "lgetxattr_size_check $path $xattr failed"
532                 done
533         done
534 }
535 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
536
537 # LU-1540
538 test_17m() {
539         local short_sym="0123456789"
540         local WDIR=$DIR/${tdir}m
541         local mds_index
542         local devname
543         local cmd
544         local i
545         local rc=0
546
547         remote_mds_nodsh && skip "remote MDS with nodsh" && return
548         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
549         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
550                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
551
552         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
553                 skip "only for ldiskfs MDT" && return 0
554
555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
556
557         mkdir -p $WDIR
558         long_sym=$short_sym
559         # create a long symlink file
560         for ((i = 0; i < 4; ++i)); do
561                 long_sym=${long_sym}${long_sym}
562         done
563
564         echo "create 512 short and long symlink files under $WDIR"
565         for ((i = 0; i < 256; ++i)); do
566                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
567                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
568         done
569
570         echo "erase them"
571         rm -f $WDIR/*
572         sync
573         wait_delete_completed
574
575         echo "recreate the 512 symlink files with a shorter string"
576         for ((i = 0; i < 512; ++i)); do
577                 # rewrite the symlink file with a shorter string
578                 ln -sf ${long_sym} $WDIR/long-$i
579                 ln -sf ${short_sym} $WDIR/short-$i
580         done
581
582         mds_index=$($LFS getstripe -M $WDIR)
583         mds_index=$((mds_index+1))
584         devname=$(mdsdevname $mds_index)
585         cmd="$E2FSCK -fnvd $devname"
586
587         echo "stop and checking mds${mds_index}: $cmd"
588         # e2fsck should not return error
589         stop mds${mds_index}
590         do_facet mds${mds_index} $cmd || rc=$?
591
592         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
593         df $MOUNT > /dev/null 2>&1
594         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
595                 "short/long symlink MDT: rc=$rc"
596         return $rc
597 }
598 run_test 17m "run e2fsck against MDT which contains short/long symlink"
599
600 check_fs_consistency_17n() {
601         local mdt_index
602         local devname
603         local cmd
604         local rc=0
605
606         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
607         # so it only check MDT1/MDT2 instead of all of MDTs.
608         for mdt_index in $(seq 1 2); do
609                 devname=$(mdsdevname $mdt_index)
610                 cmd="$E2FSCK -fnvd $devname"
611
612                 echo "stop and checking mds${mdt_index}: $cmd"
613                 # e2fsck should not return error
614                 stop mds${mdt_index}
615                 do_facet mds${mdt_index} $cmd || rc=$?
616
617                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
618                         error "mount mds${mdt_index} failed"
619                 df $MOUNT > /dev/null 2>&1
620                 [ $rc -ne 0 ] && break
621         done
622         return $rc
623 }
624
625 test_17n() {
626         local i
627
628         remote_mds_nodsh && skip "remote MDS with nodsh" && return
629         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
630         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
631                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
632
633         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
634                 skip "only for ldiskfs MDT" && return 0
635
636         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
637
638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
639
640         mkdir $DIR/$tdir
641         for ((i=0; i<10; i++)); do
642                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
643                         error "create remote dir error $i"
644                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
645                         error "create files under remote dir failed $i"
646         done
647
648         check_fs_consistency_17n ||
649                 error "e2fsck report error after create files under remote dir"
650
651         for ((i = 0; i < 10; i++)); do
652                 rm -rf $DIR/$tdir/remote_dir_${i} ||
653                         error "destroy remote dir error $i"
654         done
655
656         check_fs_consistency_17n ||
657                 error "e2fsck report error after unlink files under remote dir"
658
659         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
660                 skip "lustre < 2.4.50 does not support migrate mv " && return
661
662         for ((i = 0; i < 10; i++)); do
663                 mkdir -p $DIR/$tdir/remote_dir_${i}
664                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
665                         error "create files under remote dir failed $i"
666                 $LFS mv --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
667                         error "migrate remote dir error $i"
668         done
669         check_fs_consistency_17n || error "e2fsck report error after migration"
670
671         for ((i = 0; i < 10; i++)); do
672                 rm -rf $DIR/$tdir/remote_dir_${i} ||
673                         error "destroy remote dir error $i"
674         done
675
676         check_fs_consistency_17n || error "e2fsck report error after unlink"
677 }
678 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
679
680 test_17o() {
681         remote_mds_nodsh && skip "remote MDS with nodsh" && return
682         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
683                 skip "Need MDS version at least 2.3.64" && return
684
685         local WDIR=$DIR/${tdir}o
686         local mdt_index
687         local mdtdevname
688         local rc=0
689
690         mkdir -p $WDIR
691         mdt_index=$($LFS getstripe -M $WDIR)
692         mdt_index=$((mdt_index+1))
693         mdtdevname=$(mdsdevname $mdt_index)
694
695         touch $WDIR/$tfile
696         stop mds${mdt_index}
697         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS ||
698                 error "mount mds${mdt_index} failed"
699
700         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
701         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
702         ls -l $WDIR/$tfile && rc=1
703         do_facet mds${mdt_index} lctl set_param fail_loc=0
704         [[ $rc -ne 0 ]] && error "stat file should fail"
705         true
706 }
707 run_test 17o "stat file with incompat LMA feature"
708
709 test_18() {
710         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
711         ls $DIR || error "Failed to ls $DIR: $?"
712 }
713 run_test 18 "touch .../f ; ls ... =============================="
714
715 test_19a() {
716         touch $DIR/$tfile
717         ls -l $DIR
718         rm $DIR/$tfile
719         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
720 }
721 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
722
723 test_19b() {
724         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
725 }
726 run_test 19b "ls -l .../f19 (should return error) =============="
727
728 test_19c() {
729         [ $RUNAS_ID -eq $UID ] &&
730                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
731         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
732 }
733 run_test 19c "$RUNAS touch .../f19 (should return error) =="
734
735 test_19d() {
736         cat $DIR/f19 && error || true
737 }
738 run_test 19d "cat .../f19 (should return error) =============="
739
740 test_20() {
741         touch $DIR/$tfile
742         rm $DIR/$tfile
743         log "1 done"
744         touch $DIR/$tfile
745         rm $DIR/$tfile
746         log "2 done"
747         touch $DIR/$tfile
748         rm $DIR/$tfile
749         log "3 done"
750         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
751 }
752 run_test 20 "touch .../f ; ls -l ... ==========================="
753
754 test_21() {
755         test_mkdir -p $DIR/$tdir
756         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
757         ln -s dangle $DIR/$tdir/link
758         echo foo >> $DIR/$tdir/link
759         cat $DIR/$tdir/dangle
760         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
761         $CHECKSTAT -f -t file $DIR/$tdir/link ||
762                 error "$tdir/link not linked to a file"
763 }
764 run_test 21 "write to dangling link ============================"
765
766 test_22() {
767         WDIR=$DIR/$tdir
768         test_mkdir -p $DIR/$tdir
769         chown $RUNAS_ID:$RUNAS_GID $WDIR
770         (cd $WDIR || error "cd $WDIR failed";
771         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
772         $RUNAS tar xf -)
773         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
774         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
775         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
776 }
777 run_test 22 "unpack tar archive as non-root user ==============="
778
779 # was test_23
780 test_23a() {
781         test_mkdir -p $DIR/$tdir
782         local file=$DIR/$tdir/$tfile
783
784         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
785         openfile -f O_CREAT:O_EXCL $file &&
786                 error "$file recreate succeeded" || true
787 }
788 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
789
790 test_23b() { # bug 18988
791         test_mkdir -p $DIR/$tdir
792         local file=$DIR/$tdir/$tfile
793
794         rm -f $file
795         echo foo > $file || error "write filed"
796         echo bar >> $file || error "append filed"
797         $CHECKSTAT -s 8 $file || error "wrong size"
798         rm $file
799 }
800 run_test 23b "O_APPEND check =========================="
801
802 # rename sanity
803 test_24a() {
804         echo '-- same directory rename'
805         test_mkdir $DIR/$tdir
806         touch $DIR/$tdir/$tfile.1
807         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
808         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
809 }
810 run_test 24a "rename file to non-existent target"
811
812 test_24b() {
813         test_mkdir $DIR/$tdir
814         touch $DIR/$tdir/$tfile.{1,2}
815         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
816         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
817         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
818 }
819 run_test 24b "rename file to existing target"
820
821 test_24c() {
822         test_mkdir $DIR/$tdir
823         test_mkdir $DIR/$tdir/d$testnum.1
824         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
825         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
826         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
827 }
828 run_test 24c "rename directory to non-existent target"
829
830 test_24d() {
831         test_mkdir -c1 $DIR/$tdir
832         test_mkdir -c1 $DIR/$tdir/d$testnum.1
833         test_mkdir -c1 $DIR/$tdir/d$testnum.2
834         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
835         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
836         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
837 }
838 run_test 24d "rename directory to existing target"
839
840 test_24e() {
841         echo '-- cross directory renames --'
842         test_mkdir $DIR/R5a
843         test_mkdir $DIR/R5b
844         touch $DIR/R5a/f
845         mv $DIR/R5a/f $DIR/R5b/g
846         $CHECKSTAT -a $DIR/R5a/f || error
847         $CHECKSTAT -t file $DIR/R5b/g || error
848 }
849 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
850
851 test_24f() {
852         test_mkdir $DIR/R6a
853         test_mkdir $DIR/R6b
854         touch $DIR/R6a/f $DIR/R6b/g
855         mv $DIR/R6a/f $DIR/R6b/g
856         $CHECKSTAT -a $DIR/R6a/f || error
857         $CHECKSTAT -t file $DIR/R6b/g || error
858 }
859 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
860
861 test_24g() {
862         test_mkdir $DIR/R7a
863         test_mkdir $DIR/R7b
864         test_mkdir $DIR/R7a/d
865         mv $DIR/R7a/d $DIR/R7b/e
866         $CHECKSTAT -a $DIR/R7a/d || error
867         $CHECKSTAT -t dir $DIR/R7b/e || error
868 }
869 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
870
871 test_24h() {
872         test_mkdir -c1 $DIR/R8a
873         test_mkdir -c1 $DIR/R8b
874         test_mkdir -c1 $DIR/R8a/d
875         test_mkdir -c1 $DIR/R8b/e
876         mrename $DIR/R8a/d $DIR/R8b/e
877         $CHECKSTAT -a $DIR/R8a/d || error
878         $CHECKSTAT -t dir $DIR/R8b/e || error
879 }
880 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
881
882 test_24i() {
883         echo "-- rename error cases"
884         test_mkdir $DIR/R9
885         test_mkdir $DIR/R9/a
886         touch $DIR/R9/f
887         mrename $DIR/R9/f $DIR/R9/a
888         $CHECKSTAT -t file $DIR/R9/f || error
889         $CHECKSTAT -t dir  $DIR/R9/a || error
890         $CHECKSTAT -a $DIR/R9/a/f || error
891 }
892 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
893
894 test_24j() {
895         test_mkdir $DIR/R10
896         mrename $DIR/R10/f $DIR/R10/g
897         $CHECKSTAT -t dir $DIR/R10 || error
898         $CHECKSTAT -a $DIR/R10/f || error
899         $CHECKSTAT -a $DIR/R10/g || error
900 }
901 run_test 24j "source does not exist ============================"
902
903 test_24k() {
904         test_mkdir $DIR/R11a
905         test_mkdir $DIR/R11a/d
906         touch $DIR/R11a/f
907         mv $DIR/R11a/f $DIR/R11a/d
908         $CHECKSTAT -a $DIR/R11a/f || error
909         $CHECKSTAT -t file $DIR/R11a/d/f || error
910 }
911 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
912
913 # bug 2429 - rename foo foo foo creates invalid file
914 test_24l() {
915         f="$DIR/f24l"
916         $MULTIOP $f OcNs || error
917 }
918 run_test 24l "Renaming a file to itself ========================"
919
920 test_24m() {
921         f="$DIR/f24m"
922         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
923         # on ext3 this does not remove either the source or target files
924         # though the "expected" operation would be to remove the source
925         $CHECKSTAT -t file ${f} || error "${f} missing"
926         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
927 }
928 run_test 24m "Renaming a file to a hard link to itself ========="
929
930 test_24n() {
931     f="$DIR/f24n"
932     # this stats the old file after it was renamed, so it should fail
933     touch ${f}
934     $CHECKSTAT ${f}
935     mv ${f} ${f}.rename
936     $CHECKSTAT ${f}.rename
937     $CHECKSTAT -a ${f}
938 }
939 run_test 24n "Statting the old file after renaming (Posix rename 2)"
940
941 test_24o() {
942         test_mkdir -p $DIR/d24o
943         rename_many -s random -v -n 10 $DIR/d24o
944 }
945 run_test 24o "rename of files during htree split ==============="
946
947 test_24p() {
948         test_mkdir $DIR/R12a
949         test_mkdir $DIR/R12b
950         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
951         mrename $DIR/R12a $DIR/R12b
952         $CHECKSTAT -a $DIR/R12a || error
953         $CHECKSTAT -t dir $DIR/R12b || error
954         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
955         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
956 }
957 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
958
959 cleanup_multiop_pause() {
960         trap 0
961         kill -USR1 $MULTIPID
962 }
963
964 test_24q() {
965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
966         test_mkdir $DIR/R13a
967         test_mkdir $DIR/R13b
968         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
969         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
970         MULTIPID=$!
971
972         trap cleanup_multiop_pause EXIT
973         mrename $DIR/R13a $DIR/R13b
974         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
975         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
976         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
977         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
978         cleanup_multiop_pause
979         wait $MULTIPID || error "multiop close failed"
980 }
981 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
982
983 test_24r() { #bug 3789
984         test_mkdir $DIR/R14a
985         test_mkdir $DIR/R14a/b
986         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
987         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
988         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
989 }
990 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
991
992 test_24s() {
993         test_mkdir $DIR/R15a
994         test_mkdir $DIR/R15a/b
995         test_mkdir $DIR/R15a/b/c
996         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
997         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
998         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
999 }
1000 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1001 test_24t() {
1002         test_mkdir $DIR/R16a
1003         test_mkdir $DIR/R16a/b
1004         test_mkdir $DIR/R16a/b/c
1005         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1006         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1007         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1008 }
1009 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1010
1011 test_24u() { # bug12192
1012         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1013         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1014 }
1015 run_test 24u "create stripe file"
1016
1017 page_size() {
1018         getconf PAGE_SIZE
1019 }
1020
1021 simple_cleanup_common() {
1022         trap 0
1023         rm -rf $DIR/$tdir
1024         wait_delete_completed
1025 }
1026
1027 max_pages_per_rpc() {
1028         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1029 }
1030
1031 test_24v() {
1032         local NRFILES=100000
1033         local FREE_INODES=$(mdt_free_inodes 0)
1034         [[ $FREE_INODES -lt $NRFILES ]] &&
1035                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1036                 return
1037
1038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1039         trap simple_cleanup_common EXIT
1040
1041         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1042         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1043
1044         mkdir -p $DIR/$tdir
1045         createmany -m $DIR/$tdir/$tfile $NRFILES
1046
1047         cancel_lru_locks mdc
1048         lctl set_param mdc.*.stats clear
1049
1050         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1051
1052         # LU-5 large readdir
1053         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1054         #               8 bytes for name(filename is mostly 5 in this test) +
1055         #               8 bytes for luda_type
1056         # take into account of overhead in lu_dirpage header and end mark in
1057         # each page, plus one in RPC_NUM calculation.
1058         DIRENT_SIZE=48
1059         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1060         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1061         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1062                                 awk '/^mds_readpage/ {print $2}')
1063         [[ $mds_readpage -gt $RPC_NUM ]] &&
1064                 error "large readdir doesn't take effect"
1065
1066         simple_cleanup_common
1067 }
1068 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1069
1070 test_24w() { # bug21506
1071         SZ1=234852
1072         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1073         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1074         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1075         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1076         [[ "$SZ1" -eq "$SZ2" ]] ||
1077                 error "Error reading at the end of the file $tfile"
1078 }
1079 run_test 24w "Reading a file larger than 4Gb"
1080
1081 test_24x() {
1082         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1084         local MDTIDX=1
1085         local remote_dir=$DIR/$tdir/remote_dir
1086
1087         mkdir -p $DIR/$tdir
1088         $LFS mkdir -i $MDTIDX $remote_dir ||
1089                 error "create remote directory failed"
1090
1091         mkdir -p $DIR/$tdir/src_dir
1092         touch $DIR/$tdir/src_file
1093         mkdir -p $remote_dir/tgt_dir
1094         touch $remote_dir/tgt_file
1095
1096         mrename $remote_dir $DIR/ &&
1097                 error "rename dir cross MDT works!"
1098
1099         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1100                 error "rename dir cross MDT works!"
1101
1102         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1103                 error "rename file cross MDT works!"
1104
1105         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1106                 error "ln file cross MDT should not work!"
1107
1108         rm -rf $DIR/$tdir || error "Can not delete directories"
1109 }
1110 run_test 24x "cross rename/link should be failed"
1111
1112 test_24y() {
1113         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1114         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1115         local MDTIDX=1
1116         local remote_dir=$DIR/$tdir/remote_dir
1117
1118         mkdir -p $DIR/$tdir
1119         $LFS mkdir -i $MDTIDX $remote_dir ||
1120                    error "create remote directory failed"
1121
1122         mkdir -p $remote_dir/src_dir
1123         touch $remote_dir/src_file
1124         mkdir -p $remote_dir/tgt_dir
1125         touch $remote_dir/tgt_file
1126
1127         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1128                 error "rename subdir in the same remote dir failed!"
1129
1130         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1131                 error "rename files in the same remote dir failed!"
1132
1133         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1134                 error "link files in the same remote dir failed!"
1135
1136         rm -rf $DIR/$tdir || error "Can not delete directories"
1137 }
1138 run_test 24y "rename/link on the same dir should succeed"
1139
1140 test_24z() {
1141         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1142         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1143         local MDTIDX=1
1144         local remote_src=$DIR/$tdir/remote_dir
1145         local remote_tgt=$DIR/$tdir/remote_tgt
1146
1147         mkdir -p $DIR/$tdir
1148         $LFS mkdir -i $MDTIDX $remote_src ||
1149                    error "create remote directory failed"
1150
1151         $LFS mkdir -i $MDTIDX $remote_tgt ||
1152                    error "create remote directory failed"
1153
1154         mrename $remote_src $remote_tgt &&
1155                 error "rename remote dirs should not work!"
1156
1157         # If target dir does not exists, it should succeed
1158         rm -rf $remote_tgt
1159         mrename $remote_src $remote_tgt ||
1160                 error "rename remote dirs(tgt dir does not exists) failed!"
1161
1162         rm -rf $DIR/$tdir || error "Can not delete directories"
1163 }
1164 run_test 24z "rename one remote dir to another remote dir should fail"
1165
1166 test_24A() { # LU-3182
1167         local NFILES=5000
1168
1169         rm -rf $DIR/$tdir
1170         mkdir -p $DIR/$tdir
1171         createmany -m $DIR/$tdir/$tfile $NFILES
1172         local t=$(ls $DIR/$tdir | wc -l)
1173         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1174         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1175         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1176                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1177         fi
1178
1179         rm -rf $DIR/$tdir || error "Can not delete directories"
1180 }
1181 run_test 24A "readdir() returns correct number of entries."
1182
1183 test_24B() { # LU-4805
1184         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1185         local count
1186
1187         mkdir $DIR/$tdir
1188         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1189                 error "create striped dir failed"
1190
1191         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1192         [ $count -eq 2 ] || error "Expected 2, got $count"
1193
1194         touch $DIR/$tdir/striped_dir/a
1195
1196         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1197         [ $count -eq 3 ] || error "Expected 3, got $count"
1198
1199         touch $DIR/$tdir/striped_dir/.f
1200
1201         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1202         [ $count -eq 4 ] || error "Expected 4, got $count"
1203
1204         rm -rf $DIR/$tdir || error "Can not delete directories"
1205 }
1206 run_test 24B "readdir for striped dir return correct number of entries"
1207
1208 test_24C() {
1209         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1210
1211         mkdir $DIR/$tdir
1212         mkdir $DIR/$tdir/d0
1213         mkdir $DIR/$tdir/d1
1214
1215         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1216                 error "create striped dir failed"
1217
1218         cd $DIR/$tdir/d0/striped_dir
1219
1220         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1221         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1222         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1223
1224         [ "$d0_ino" = "$parent_ino" ] ||
1225                 error ".. wrong, expect $d0_ino, get $parent_ino"
1226
1227         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1228                 error "mv striped dir failed"
1229
1230         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1231
1232         [ "$d1_ino" = "$parent_ino" ] ||
1233                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1234 }
1235 run_test 24C "check .. in striped dir"
1236
1237 test_24D() { # LU-6101
1238         local NFILES=50000
1239
1240         rm -rf $DIR/$tdir
1241         mkdir -p $DIR/$tdir
1242         createmany -m $DIR/$tdir/$tfile $NFILES
1243         local t=$(ls $DIR/$tdir | wc -l)
1244         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1245         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1246         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1247                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1248         fi
1249
1250         rm -rf $DIR/$tdir || error "Can not delete directories"
1251 }
1252 run_test 24D "readdir() returns correct number of entries after cursor reload"
1253
1254 test_25a() {
1255         echo '== symlink sanity ============================================='
1256
1257         test_mkdir $DIR/d25
1258         ln -s d25 $DIR/s25
1259         touch $DIR/s25/foo || error
1260 }
1261 run_test 25a "create file in symlinked directory ==============="
1262
1263 test_25b() {
1264         [ ! -d $DIR/d25 ] && test_25a
1265         $CHECKSTAT -t file $DIR/s25/foo || error
1266 }
1267 run_test 25b "lookup file in symlinked directory ==============="
1268
1269 test_26a() {
1270         test_mkdir $DIR/d26
1271         test_mkdir $DIR/d26/d26-2
1272         ln -s d26/d26-2 $DIR/s26
1273         touch $DIR/s26/foo || error
1274 }
1275 run_test 26a "multiple component symlink ======================="
1276
1277 test_26b() {
1278         test_mkdir -p $DIR/d26b/d26-2
1279         ln -s d26b/d26-2/foo $DIR/s26-2
1280         touch $DIR/s26-2 || error
1281 }
1282 run_test 26b "multiple component symlink at end of lookup ======"
1283
1284 test_26c() {
1285         test_mkdir $DIR/d26.2
1286         touch $DIR/d26.2/foo
1287         ln -s d26.2 $DIR/s26.2-1
1288         ln -s s26.2-1 $DIR/s26.2-2
1289         ln -s s26.2-2 $DIR/s26.2-3
1290         chmod 0666 $DIR/s26.2-3/foo
1291 }
1292 run_test 26c "chain of symlinks ================================"
1293
1294 # recursive symlinks (bug 439)
1295 test_26d() {
1296         ln -s d26-3/foo $DIR/d26-3
1297 }
1298 run_test 26d "create multiple component recursive symlink ======"
1299
1300 test_26e() {
1301         [ ! -h $DIR/d26-3 ] && test_26d
1302         rm $DIR/d26-3
1303 }
1304 run_test 26e "unlink multiple component recursive symlink ======"
1305
1306 # recursive symlinks (bug 7022)
1307 test_26f() {
1308         test_mkdir -p $DIR/$tdir
1309         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1310         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1311         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1312         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1313         cd $tfile                || error "cd $tfile failed"
1314         ln -s .. dotdot          || error "ln dotdot failed"
1315         ln -s dotdot/lndir lndir || error "ln lndir failed"
1316         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1317         output=`ls $tfile/$tfile/lndir/bar1`
1318         [ "$output" = bar1 ] && error "unexpected output"
1319         rm -r $tfile             || error "rm $tfile failed"
1320         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1321 }
1322 run_test 26f "rm -r of a directory which has recursive symlink ="
1323
1324 test_27a() {
1325         echo '== stripe sanity =============================================='
1326         test_mkdir -p $DIR/d27 || error "mkdir failed"
1327         $GETSTRIPE $DIR/d27
1328         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1329         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1330         log "== test_27a: write to one stripe file ========================="
1331         cp /etc/hosts $DIR/d27/f0 || error
1332 }
1333 run_test 27a "one stripe file =================================="
1334
1335 test_27b() {
1336         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1337         test_mkdir -p $DIR/d27
1338         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1339         $GETSTRIPE -c $DIR/d27/f01
1340         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1341                 error "two-stripe file doesn't have two stripes"
1342
1343         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1344 }
1345 run_test 27b "create and write to two stripe file"
1346
1347 test_27d() {
1348         test_mkdir -p $DIR/d27
1349         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1350         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1351         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1352 }
1353 run_test 27d "create file with default settings ================"
1354
1355 test_27e() {
1356         test_mkdir -p $DIR/d27
1357         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1358         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1359         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1360 }
1361 run_test 27e "setstripe existing file (should return error) ======"
1362
1363 test_27f() {
1364         test_mkdir $DIR/$tdir
1365         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1366                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1367         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1368                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1369         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1370         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1371 }
1372 run_test 27f "setstripe with bad stripe size (should return error)"
1373
1374 test_27g() {
1375         test_mkdir -p $DIR/d27
1376         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1377         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1378                 error "$DIR/d27/fnone has object"
1379 }
1380 run_test 27g "$GETSTRIPE with no objects"
1381
1382 test_27i() {
1383         test_mkdir $DIR/$tdir
1384         touch $DIR/$tdir/$tfile || error "touch failed"
1385         [[ $($GETSTRIPE -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1386                 error "missing objects"
1387 }
1388 run_test 27i "$GETSTRIPE with some objects"
1389
1390 test_27j() {
1391         test_mkdir -p $DIR/d27
1392         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1393 }
1394 run_test 27j "setstripe with bad stripe offset (should return error)"
1395
1396 test_27k() { # bug 2844
1397         test_mkdir -p $DIR/d27
1398         FILE=$DIR/d27/f27k
1399         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1400         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1401         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1402         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1403         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1404         dd if=/dev/zero of=$FILE bs=4k count=1
1405         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1406         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1407 }
1408 run_test 27k "limit i_blksize for broken user apps ============="
1409
1410 test_27l() {
1411         test_mkdir -p $DIR/d27
1412         mcreate $DIR/f27l || error "creating file"
1413         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1414                 error "setstripe should have failed" || true
1415 }
1416 run_test 27l "check setstripe permissions (should return error)"
1417
1418 test_27m() {
1419         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1420                 return
1421         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1422                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1423                 return
1424         fi
1425         trap simple_cleanup_common EXIT
1426         test_mkdir -p $DIR/$tdir
1427         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1428         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1429                 error "dd should fill OST0"
1430         i=2
1431         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1432                 i=$((i + 1))
1433                 [ $i -gt 256 ] && break
1434         done
1435         i=$((i + 1))
1436         touch $DIR/$tdir/f27m_$i
1437         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1438                 error "OST0 was full but new created file still use it"
1439         i=$((i + 1))
1440         touch $DIR/$tdir/f27m_$i
1441         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1442                 error "OST0 was full but new created file still use it"
1443         simple_cleanup_common
1444 }
1445 run_test 27m "create file while OST0 was full =================="
1446
1447 sleep_maxage() {
1448         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1449         sleep $DELAY
1450 }
1451
1452 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1453 # if the OST isn't full anymore.
1454 reset_enospc() {
1455         local OSTIDX=${1:-""}
1456
1457         local list=$(comma_list $(osts_nodes))
1458         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1459
1460         do_nodes $list lctl set_param fail_loc=0
1461         sync    # initiate all OST_DESTROYs from MDS to OST
1462         sleep_maxage
1463 }
1464
1465 exhaust_precreations() {
1466         local OSTIDX=$1
1467         local FAILLOC=$2
1468         local FAILIDX=${3:-$OSTIDX}
1469         local ofacet=ost$((OSTIDX + 1))
1470
1471         test_mkdir -p -c1 $DIR/$tdir
1472         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1473         local mfacet=mds$((mdtidx + 1))
1474         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1475
1476         local OST=$(ostname_from_index $OSTIDX)
1477
1478         # on the mdt's osc
1479         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1480         local last_id=$(do_facet $mfacet lctl get_param -n \
1481                         osc.$mdtosc_proc1.prealloc_last_id)
1482         local next_id=$(do_facet $mfacet lctl get_param -n \
1483                         osc.$mdtosc_proc1.prealloc_next_id)
1484
1485         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1486         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1487
1488         test_mkdir -p $DIR/$tdir/${OST}
1489         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1490 #define OBD_FAIL_OST_ENOSPC              0x215
1491         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1492         echo "Creating to objid $last_id on ost $OST..."
1493         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1494         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1495         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1496         sleep_maxage
1497 }
1498
1499 exhaust_all_precreations() {
1500         local i
1501         for (( i=0; i < OSTCOUNT; i++ )) ; do
1502                 exhaust_precreations $i $1 -1
1503         done
1504 }
1505
1506 test_27n() {
1507         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1508         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1509         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1510         remote_ost_nodsh && skip "remote OST with nodsh" && return
1511
1512         reset_enospc
1513         rm -f $DIR/$tdir/$tfile
1514         exhaust_precreations 0 0x80000215
1515         $SETSTRIPE -c -1 $DIR/$tdir
1516         touch $DIR/$tdir/$tfile || error
1517         $GETSTRIPE $DIR/$tdir/$tfile
1518         reset_enospc
1519 }
1520 run_test 27n "create file with some full OSTs =================="
1521
1522 test_27o() {
1523         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1524         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1525         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1526         remote_ost_nodsh && skip "remote OST with nodsh" && return
1527
1528         reset_enospc
1529         rm -f $DIR/$tdir/$tfile
1530         exhaust_all_precreations 0x215
1531
1532         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1533
1534         reset_enospc
1535         rm -rf $DIR/$tdir/*
1536 }
1537 run_test 27o "create file with all full OSTs (should error) ===="
1538
1539 test_27p() {
1540         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1542         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1543         remote_ost_nodsh && skip "remote OST with nodsh" && return
1544
1545         reset_enospc
1546         rm -f $DIR/$tdir/$tfile
1547         test_mkdir -p $DIR/$tdir
1548
1549         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1550         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1551         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1552
1553         exhaust_precreations 0 0x80000215
1554         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1555         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1556         $GETSTRIPE $DIR/$tdir/$tfile
1557
1558         reset_enospc
1559 }
1560 run_test 27p "append to a truncated file with some full OSTs ==="
1561
1562 test_27q() {
1563         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1564         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1565         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1566         remote_ost_nodsh && skip "remote OST with nodsh" && return
1567
1568         reset_enospc
1569         rm -f $DIR/$tdir/$tfile
1570
1571         test_mkdir -p $DIR/$tdir
1572         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1573         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1574         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1575
1576         exhaust_all_precreations 0x215
1577
1578         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1579         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1580
1581         reset_enospc
1582 }
1583 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1584
1585 test_27r() {
1586         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1588         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1589         remote_ost_nodsh && skip "remote OST with nodsh" && return
1590
1591         reset_enospc
1592         rm -f $DIR/$tdir/$tfile
1593         exhaust_precreations 0 0x80000215
1594
1595         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1596
1597         reset_enospc
1598 }
1599 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1600
1601 test_27s() { # bug 10725
1602         test_mkdir -p $DIR/$tdir
1603         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1604         local stripe_count=0
1605         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1606         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1607                 error "stripe width >= 2^32 succeeded" || true
1608
1609 }
1610 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1611
1612 test_27t() { # bug 10864
1613         WDIR=$(pwd)
1614         WLFS=$(which lfs)
1615         cd $DIR
1616         touch $tfile
1617         $WLFS getstripe $tfile
1618         cd $WDIR
1619 }
1620 run_test 27t "check that utils parse path correctly"
1621
1622 test_27u() { # bug 4900
1623         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1624         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1625         local index
1626         local list=$(comma_list $(mdts_nodes))
1627
1628 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1629         do_nodes $list $LCTL set_param fail_loc=0x139
1630         test_mkdir -p $DIR/$tdir
1631         rm -rf $DIR/$tdir/*
1632         createmany -o $DIR/$tdir/t- 1000
1633         do_nodes $list $LCTL set_param fail_loc=0
1634
1635         TLOG=$DIR/$tfile.getstripe
1636         $GETSTRIPE $DIR/$tdir > $TLOG
1637         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1638         unlinkmany $DIR/$tdir/t- 1000
1639         [[ $OBJS -gt 0 ]] &&
1640                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1641 }
1642 run_test 27u "skip object creation on OSC w/o objects =========="
1643
1644 test_27v() { # bug 4900
1645         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1647         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1648         remote_ost_nodsh && skip "remote OST with nodsh" && return
1649
1650         exhaust_all_precreations 0x215
1651         reset_enospc
1652
1653         test_mkdir -p $DIR/$tdir
1654         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1655
1656         touch $DIR/$tdir/$tfile
1657         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1658         # all except ost1
1659         for (( i=1; i < OSTCOUNT; i++ )); do
1660                 do_facet ost$i lctl set_param fail_loc=0x705
1661         done
1662         local START=`date +%s`
1663         createmany -o $DIR/$tdir/$tfile 32
1664
1665         local FINISH=`date +%s`
1666         local TIMEOUT=`lctl get_param -n timeout`
1667         local PROCESS=$((FINISH - START))
1668         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1669                error "$FINISH - $START >= $TIMEOUT / 2"
1670         sleep $((TIMEOUT / 2 - PROCESS))
1671         reset_enospc
1672 }
1673 run_test 27v "skip object creation on slow OST ================="
1674
1675 test_27w() { # bug 10997
1676         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1677         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1678         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1679                 error "stripe size $size != 65536" || true
1680         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1681                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1682 }
1683 run_test 27w "check $SETSTRIPE -S option"
1684
1685 test_27wa() {
1686         [[ $OSTCOUNT -lt 2 ]] &&
1687                 skip_env "skipping multiple stripe count/offset test" && return
1688
1689         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1690         for i in $(seq 1 $OSTCOUNT); do
1691                 offset=$((i - 1))
1692                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1693                         error "setstripe -c $i -i $offset failed"
1694                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1695                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1696                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1697                 [ $index -ne $offset ] &&
1698                         error "stripe offset $index != $offset" || true
1699         done
1700 }
1701 run_test 27wa "check $SETSTRIPE -c -i options"
1702
1703 test_27x() {
1704         remote_ost_nodsh && skip "remote OST with nodsh" && return
1705         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1707         OFFSET=$(($OSTCOUNT - 1))
1708         OSTIDX=0
1709         local OST=$(ostname_from_index $OSTIDX)
1710
1711         test_mkdir -p $DIR/$tdir
1712         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1713         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1714         sleep_maxage
1715         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1716         for i in `seq 0 $OFFSET`; do
1717                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1718                 error "OST0 was degraded but new created file still use it"
1719         done
1720         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1721 }
1722 run_test 27x "create files while OST0 is degraded"
1723
1724 test_27y() {
1725         [[ $OSTCOUNT -lt 2 ]] &&
1726                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1727         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1728         remote_ost_nodsh && skip "remote OST with nodsh" && return
1729         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1730
1731         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1732         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1733             osc.$mdtosc.prealloc_last_id)
1734         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1735             osc.$mdtosc.prealloc_next_id)
1736         local fcount=$((last_id - next_id))
1737         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1738         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1739
1740         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1741                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1742         local OST_DEACTIVE_IDX=-1
1743         local OSC
1744         local OSTIDX
1745         local OST
1746
1747         for OSC in $MDS_OSCS; do
1748                 OST=$(osc_to_ost $OSC)
1749                 OSTIDX=$(index_from_ostuuid $OST)
1750                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1751                         OST_DEACTIVE_IDX=$OSTIDX
1752                 fi
1753                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1754                         echo $OSC "is Deactivated:"
1755                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1756                 fi
1757         done
1758
1759         OSTIDX=$(index_from_ostuuid $OST)
1760         mkdir -p $DIR/$tdir
1761         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1762
1763         for OSC in $MDS_OSCS; do
1764                 OST=$(osc_to_ost $OSC)
1765                 OSTIDX=$(index_from_ostuuid $OST)
1766                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1767                         echo $OST "is degraded:"
1768                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1769                                                 obdfilter.$OST.degraded=1
1770                 fi
1771         done
1772
1773         sleep_maxage
1774         createmany -o $DIR/$tdir/$tfile $fcount
1775
1776         for OSC in $MDS_OSCS; do
1777                 OST=$(osc_to_ost $OSC)
1778                 OSTIDX=$(index_from_ostuuid $OST)
1779                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1780                         echo $OST "is recovered from degraded:"
1781                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1782                                                 obdfilter.$OST.degraded=0
1783                 else
1784                         do_facet $SINGLEMDS lctl --device %$OSC activate
1785                 fi
1786         done
1787
1788         # all osp devices get activated, hence -1 stripe count restored
1789         local stripecnt=0
1790
1791         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1792         # devices get activated.
1793         sleep_maxage
1794         $SETSTRIPE -c -1 $DIR/$tfile
1795         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1796         rm -f $DIR/$tfile
1797         [ $stripecnt -ne $OSTCOUNT ] &&
1798                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1799         return 0
1800 }
1801 run_test 27y "create files while OST0 is degraded and the rest inactive"
1802
1803 check_seq_oid()
1804 {
1805         log "check file $1"
1806
1807         lmm_count=$($GETSTRIPE -c $1)
1808         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1809         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1810
1811         local old_ifs="$IFS"
1812         IFS=$'[:]'
1813         fid=($($LFS path2fid $1))
1814         IFS="$old_ifs"
1815
1816         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1817         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1818
1819         # compare lmm_seq and lu_fid->f_seq
1820         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1821         # compare lmm_object_id and lu_fid->oid
1822         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1823
1824         # check the trusted.fid attribute of the OST objects of the file
1825         local have_obdidx=false
1826         local stripe_nr=0
1827         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1828                 # skip lines up to and including "obdidx"
1829                 [ -z "$obdidx" ] && break
1830                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1831                 $have_obdidx || continue
1832
1833                 local ost=$((obdidx + 1))
1834                 local dev=$(ostdevname $ost)
1835                 local oid_hex
1836
1837                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1838
1839                 seq=$(echo $seq | sed -e "s/^0x//g")
1840                 if [ $seq == 0 ]; then
1841                         oid_hex=$(echo $oid)
1842                 else
1843                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1844                 fi
1845                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1846
1847                 local ff
1848                 #
1849                 # Don't unmount/remount the OSTs if we don't need to do that.
1850                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1851                 # update too, until that use mount/ll_decode_filter_fid/mount.
1852                 # Re-enable when debugfs will understand new filter_fid.
1853                 #
1854                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1855                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1856                                 $dev 2>/dev/null" | grep "parent=")
1857                 else
1858                         stop ost$ost
1859                         mount_fstype ost$ost
1860                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1861                                 $(facet_mntpt ost$ost)/$obj_file)
1862                         unmount_fstype ost$ost
1863                         start ost$ost $dev $OST_MOUNT_OPTS
1864                 fi
1865
1866                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1867
1868                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1869
1870                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1871                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1872                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1873                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1874                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1875                 local ff_pstripe
1876                 if echo $ff_parent | grep -q 'stripe='; then
1877                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1878                 else
1879                         #
1880                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1881                         # into f_ver in this case.  See the comment on
1882                         # ff_parent.
1883                         #
1884                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1885                                 sed -e 's/\]//')
1886                 fi
1887
1888                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1889                 [ $ff_pseq = $lmm_seq ] ||
1890                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1891                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1892                 [ $ff_poid = $lmm_oid ] ||
1893                         error "FF parent OID $ff_poid != $lmm_oid"
1894                 (($ff_pstripe == $stripe_nr)) ||
1895                         error "FF stripe $ff_pstripe != $stripe_nr"
1896
1897                 stripe_nr=$((stripe_nr + 1))
1898         done
1899 }
1900
1901 test_27z() {
1902         remote_ost_nodsh && skip "remote OST with nodsh" && return
1903         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1904         test_mkdir -p $DIR/$tdir
1905
1906         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1907                 { error "setstripe -c -1 failed"; return 1; }
1908         # We need to send a write to every object to get parent FID info set.
1909         # This _should_ also work for setattr, but does not currently.
1910         # touch $DIR/$tdir/$tfile-1 ||
1911         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1912                 { error "dd $tfile-1 failed"; return 2; }
1913         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1914                 { error "setstripe -c -1 failed"; return 3; }
1915         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1916                 { error "dd $tfile-2 failed"; return 4; }
1917
1918         # make sure write RPCs have been sent to OSTs
1919         sync; sleep 5; sync
1920
1921         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1922         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1923 }
1924 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1925
1926 test_27A() { # b=19102
1927         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1928         local restore_size=$($GETSTRIPE -S $MOUNT)
1929         local restore_count=$($GETSTRIPE -c $MOUNT)
1930         local restore_offset=$($GETSTRIPE -i $MOUNT)
1931         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1932         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1933                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1934         local default_size=$($GETSTRIPE -S $MOUNT)
1935         local default_offset=$($GETSTRIPE -i $MOUNT)
1936         local dsize=$((1024 * 1024))
1937         [ $default_size -eq $dsize ] ||
1938                 error "stripe size $default_size != $dsize"
1939         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1940         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1941 }
1942 run_test 27A "check filesystem-wide default LOV EA values"
1943
1944 test_27B() { # LU-2523
1945         test_mkdir -p $DIR/$tdir
1946         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1947         touch $DIR/$tdir/f0
1948         # open f1 with O_LOV_DELAY_CREATE
1949         # rename f0 onto f1
1950         # call setstripe ioctl on open file descriptor for f1
1951         # close
1952         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1953                 $DIR/$tdir/f0
1954
1955         rm -f $DIR/$tdir/f1
1956         # open f1 with O_LOV_DELAY_CREATE
1957         # unlink f1
1958         # call setstripe ioctl on open file descriptor for f1
1959         # close
1960         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1961
1962         # Allow multiop to fail in imitation of NFS's busted semantics.
1963         true
1964 }
1965 run_test 27B "call setstripe on open unlinked file/rename victim"
1966
1967 test_27C() { #LU-2871
1968         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1969
1970         declare -a ost_idx
1971         local index
1972         local found
1973         local i
1974         local j
1975
1976         test_mkdir -p $DIR/$tdir
1977         cd $DIR/$tdir
1978         for i in $(seq 0 $((OSTCOUNT - 1))); do
1979                 # set stripe across all OSTs starting from OST$i
1980                 $SETSTRIPE -i $i -c -1 $tfile$i
1981                 # get striping information
1982                 ost_idx=($($GETSTRIPE $tfile$i |
1983                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1984                 echo ${ost_idx[@]}
1985
1986                 # check the layout
1987                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1988                         error "${#ost_idx[@]} != $OSTCOUNT"
1989
1990                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1991                         found=0
1992                         for j in $(echo ${ost_idx[@]}); do
1993                                 if [ $index -eq $j ]; then
1994                                         found=1
1995                                         break
1996                                 fi
1997                         done
1998                         [ $found = 1 ] ||
1999                                 error "Can not find $index in ${ost_idx[@]}"
2000                 done
2001         done
2002 }
2003 run_test 27C "check full striping across all OSTs"
2004
2005 test_27D() {
2006         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2007         local POOL=${POOL:-testpool}
2008         local first_ost=0
2009         local last_ost=$(($OSTCOUNT - 1))
2010         local ost_step=1
2011         local ost_list=$(seq $first_ost $ost_step $last_ost)
2012         local ost_range="$first_ost $last_ost $ost_step"
2013
2014         mkdir -p $DIR/$tdir
2015         pool_add $POOL || error "pool_add failed"
2016         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2017         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2018                 error "llapi_layout_test failed"
2019         cleanup_pools || error "cleanup_pools failed"
2020 }
2021 run_test 27D "validate llapi_layout API"
2022
2023 # Verify that default_easize is increased from its initial value after
2024 # accessing a widely striped file.
2025 test_27E() {
2026         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2027
2028         # 72 bytes is the minimum space required to store striping
2029         # information for a file striped across one OST:
2030         # (sizeof(struct lov_user_md_v3) +
2031         #  sizeof(struct lov_user_ost_data_v1))
2032         local min_easize=72
2033         $LCTL set_param -n llite.*.default_easize $min_easize ||
2034                 error "lctl set_param failed"
2035         local easize=$($LCTL get_param -n llite.*.default_easize)
2036
2037         [ $easize -eq $min_easize ] ||
2038                 error "failed to set default_easize"
2039
2040         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2041                 error "setstripe failed"
2042         cat $DIR/$tfile
2043         rm $DIR/$tfile
2044
2045         easize=$($LCTL get_param -n llite.*.default_easize)
2046
2047         [ $easize -gt $min_easize ] ||
2048                 error "default_easize not updated"
2049 }
2050 run_test 27E "check that default extended attribute size properly increases"
2051
2052 # createtest also checks that device nodes are created and
2053 # then visible correctly (#2091)
2054 test_28() { # bug 2091
2055         test_mkdir $DIR/d28
2056         $CREATETEST $DIR/d28/ct || error
2057 }
2058 run_test 28 "create/mknod/mkdir with bad file types ============"
2059
2060 test_29() {
2061         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2062         cancel_lru_locks mdc
2063         test_mkdir $DIR/d29
2064         touch $DIR/d29/foo
2065         log 'first d29'
2066         ls -l $DIR/d29
2067
2068         declare -i LOCKCOUNTORIG=0
2069         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2070                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2071         done
2072         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2073
2074         declare -i LOCKUNUSEDCOUNTORIG=0
2075         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2076                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2077         done
2078
2079         log 'second d29'
2080         ls -l $DIR/d29
2081         log 'done'
2082
2083         declare -i LOCKCOUNTCURRENT=0
2084         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2085                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2086         done
2087
2088         declare -i LOCKUNUSEDCOUNTCURRENT=0
2089         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2090                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2091         done
2092
2093         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2094                 $LCTL set_param -n ldlm.dump_namespaces ""
2095                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2096                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2097                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2098                 return 2
2099         fi
2100         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2101                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2102                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2103                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2104                 return 3
2105         fi
2106 }
2107 run_test 29 "IT_GETATTR regression  ============================"
2108
2109 test_30a() { # was test_30
2110         cp $(which ls) $DIR || cp /bin/ls $DIR
2111         $DIR/ls / || error
2112         rm $DIR/ls
2113 }
2114 run_test 30a "execute binary from Lustre (execve) =============="
2115
2116 test_30b() {
2117         cp `which ls` $DIR || cp /bin/ls $DIR
2118         chmod go+rx $DIR/ls
2119         $RUNAS $DIR/ls / || error
2120         rm $DIR/ls
2121 }
2122 run_test 30b "execute binary from Lustre as non-root ==========="
2123
2124 test_30c() { # b=22376
2125         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2126         cp `which ls` $DIR || cp /bin/ls $DIR
2127         chmod a-rw $DIR/ls
2128         cancel_lru_locks mdc
2129         cancel_lru_locks osc
2130         $RUNAS $DIR/ls / || error
2131         rm -f $DIR/ls
2132 }
2133 run_test 30c "execute binary from Lustre without read perms ===="
2134
2135 test_31a() {
2136         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2137         $CHECKSTAT -a $DIR/f31 || error
2138 }
2139 run_test 31a "open-unlink file =================================="
2140
2141 test_31b() {
2142         touch $DIR/f31 || error
2143         ln $DIR/f31 $DIR/f31b || error
2144         $MULTIOP $DIR/f31b Ouc || error
2145         $CHECKSTAT -t file $DIR/f31 || error
2146 }
2147 run_test 31b "unlink file with multiple links while open ======="
2148
2149 test_31c() {
2150         touch $DIR/f31 || error
2151         ln $DIR/f31 $DIR/f31c || error
2152         multiop_bg_pause $DIR/f31 O_uc || return 1
2153         MULTIPID=$!
2154         $MULTIOP $DIR/f31c Ouc
2155         kill -USR1 $MULTIPID
2156         wait $MULTIPID
2157 }
2158 run_test 31c "open-unlink file with multiple links ============="
2159
2160 test_31d() {
2161         opendirunlink $DIR/d31d $DIR/d31d || error
2162         $CHECKSTAT -a $DIR/d31d || error
2163 }
2164 run_test 31d "remove of open directory ========================="
2165
2166 test_31e() { # bug 2904
2167         openfilleddirunlink $DIR/d31e || error
2168 }
2169 run_test 31e "remove of open non-empty directory ==============="
2170
2171 test_31f() { # bug 4554
2172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2173         set -vx
2174         test_mkdir $DIR/d31f
2175         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2176         cp /etc/hosts $DIR/d31f
2177         ls -l $DIR/d31f
2178         $GETSTRIPE $DIR/d31f/hosts
2179         multiop_bg_pause $DIR/d31f D_c || return 1
2180         MULTIPID=$!
2181
2182         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2183         test_mkdir $DIR/d31f
2184         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2185         cp /etc/hosts $DIR/d31f
2186         ls -l $DIR/d31f
2187         $GETSTRIPE $DIR/d31f/hosts
2188         multiop_bg_pause $DIR/d31f D_c || return 1
2189         MULTIPID2=$!
2190
2191         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2192         wait $MULTIPID || error "first opendir $MULTIPID failed"
2193
2194         sleep 6
2195
2196         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2197         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2198         set +vx
2199 }
2200 run_test 31f "remove of open directory with open-unlink file ==="
2201
2202 test_31g() {
2203         echo "-- cross directory link --"
2204         test_mkdir -c1 $DIR/${tdir}ga
2205         test_mkdir -c1 $DIR/${tdir}gb
2206         touch $DIR/${tdir}ga/f
2207         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2208         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2209         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2210         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2211         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2212 }
2213 run_test 31g "cross directory link==============="
2214
2215 test_31h() {
2216         echo "-- cross directory link --"
2217         test_mkdir -c1 $DIR/${tdir}
2218         test_mkdir -c1 $DIR/${tdir}/dir
2219         touch $DIR/${tdir}/f
2220         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2221         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2222         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2223         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2224         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2225 }
2226 run_test 31h "cross directory link under child==============="
2227
2228 test_31i() {
2229         echo "-- cross directory link --"
2230         test_mkdir -c1 $DIR/$tdir
2231         test_mkdir -c1 $DIR/$tdir/dir
2232         touch $DIR/$tdir/dir/f
2233         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2234         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2235         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2236         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2237         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2238 }
2239 run_test 31i "cross directory link under parent==============="
2240
2241 test_31j() {
2242         test_mkdir -c1 -p $DIR/$tdir
2243         test_mkdir -c1 -p $DIR/$tdir/dir1
2244         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2245         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2246         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2247         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2248         return 0
2249 }
2250 run_test 31j "link for directory==============="
2251
2252 test_31k() {
2253         test_mkdir -c1 -p $DIR/$tdir
2254         touch $DIR/$tdir/s
2255         touch $DIR/$tdir/exist
2256         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2257         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2258         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2259         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2260         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2261         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2262         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2263         return 0
2264 }
2265 run_test 31k "link to file: the same, non-existing, dir==============="
2266
2267 test_31m() {
2268         mkdir $DIR/d31m
2269         touch $DIR/d31m/s
2270         mkdir $DIR/d31m2
2271         touch $DIR/d31m2/exist
2272         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2273         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2274         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2275         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2276         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2277         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2278         return 0
2279 }
2280 run_test 31m "link to file: the same, non-existing, dir==============="
2281
2282 test_31n() {
2283         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2284         nlink=$(stat --format=%h $DIR/$tfile)
2285         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2286         local fd=$(free_fd)
2287         local cmd="exec $fd<$DIR/$tfile"
2288         eval $cmd
2289         cmd="exec $fd<&-"
2290         trap "eval $cmd" EXIT
2291         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2292         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2293         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2294         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2295         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2296         eval $cmd
2297 }
2298 run_test 31n "check link count of unlinked file"
2299
2300 link_one() {
2301         local TEMPNAME=$(mktemp $1_XXXXXX)
2302         mlink $TEMPNAME $1 2> /dev/null &&
2303                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2304         munlink $TEMPNAME
2305 }
2306
2307 test_31o() { # LU-2901
2308         mkdir -p $DIR/$tdir
2309         for LOOP in $(seq 100); do
2310                 rm -f $DIR/$tdir/$tfile*
2311                 for THREAD in $(seq 8); do
2312                         link_one $DIR/$tdir/$tfile.$LOOP &
2313                 done
2314                 wait
2315                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2316                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2317                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2318                         break || true
2319         done
2320 }
2321 run_test 31o "duplicate hard links with same filename"
2322
2323 test_31p() {
2324         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2325
2326         mkdir $DIR/$tdir
2327         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2328         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2329
2330         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2331                 error "open unlink test1 failed"
2332         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2333                 error "open unlink test2 failed"
2334
2335         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2336                 error "test1 still exists"
2337         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2338                 error "test2 still exists"
2339 }
2340 run_test 31p "remove of open striped directory"
2341
2342 cleanup_test32_mount() {
2343         trap 0
2344         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2345 }
2346
2347 test_32a() {
2348         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2349         echo "== more mountpoints and symlinks ================="
2350         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2351         trap cleanup_test32_mount EXIT
2352         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2353         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2354         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2355         cleanup_test32_mount
2356 }
2357 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2358
2359 test_32b() {
2360         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2361         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2362         trap cleanup_test32_mount EXIT
2363         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2364         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2365         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2366         cleanup_test32_mount
2367 }
2368 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2369
2370 test_32c() {
2371         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2372         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2373         trap cleanup_test32_mount EXIT
2374         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2375         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2376         test_mkdir -p $DIR/$tdir/d2/test_dir
2377         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2378         cleanup_test32_mount
2379 }
2380 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2381
2382 test_32d() {
2383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2384         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2385         trap cleanup_test32_mount EXIT
2386         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2387         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2388         test_mkdir -p $DIR/$tdir/d2/test_dir
2389         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2390         cleanup_test32_mount
2391 }
2392 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2393
2394 test_32e() {
2395         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2396         test_mkdir -p $DIR/d32e/tmp
2397         TMP_DIR=$DIR/d32e/tmp
2398         ln -s $DIR/d32e $TMP_DIR/symlink11
2399         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2400         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2401         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2402 }
2403 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2404
2405 test_32f() {
2406         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2407         test_mkdir -p $DIR/d32f/tmp
2408         TMP_DIR=$DIR/d32f/tmp
2409         ln -s $DIR/d32f $TMP_DIR/symlink11
2410         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2411         ls $DIR/d32f/tmp/symlink11  || error
2412         ls $DIR/d32f/symlink01 || error
2413 }
2414 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2415
2416 test_32g() {
2417         TMP_DIR=$DIR/$tdir/tmp
2418         test_mkdir -p $DIR/$tdir/tmp
2419         test_mkdir $DIR/${tdir}2
2420         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2421         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2422         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2423         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2424         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2425         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2426 }
2427 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2428
2429 test_32h() {
2430         rm -fr $DIR/$tdir $DIR/${tdir}2
2431         TMP_DIR=$DIR/$tdir/tmp
2432         test_mkdir -p $DIR/$tdir/tmp
2433         test_mkdir $DIR/${tdir}2
2434         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2435         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2436         ls $TMP_DIR/symlink12 || error
2437         ls $DIR/$tdir/symlink02  || error
2438 }
2439 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2440
2441 test_32i() {
2442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2443         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2444         trap cleanup_test32_mount EXIT
2445         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2446         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2447         touch $DIR/$tdir/test_file
2448         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2449         cleanup_test32_mount
2450 }
2451 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2452
2453 test_32j() {
2454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2455         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2456         trap cleanup_test32_mount EXIT
2457         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2458         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2459         touch $DIR/$tdir/test_file
2460         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2461         cleanup_test32_mount
2462 }
2463 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2464
2465 test_32k() {
2466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2467         rm -fr $DIR/$tdir
2468         trap cleanup_test32_mount EXIT
2469         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2470         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2471         test_mkdir -p $DIR/$tdir/d2
2472         touch $DIR/$tdir/d2/test_file || error
2473         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2474         cleanup_test32_mount
2475 }
2476 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2477
2478 test_32l() {
2479         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2480         rm -fr $DIR/$tdir
2481         trap cleanup_test32_mount EXIT
2482         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2483         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2484         test_mkdir -p $DIR/$tdir/d2
2485         touch $DIR/$tdir/d2/test_file
2486         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2487         cleanup_test32_mount
2488 }
2489 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2490
2491 test_32m() {
2492         rm -fr $DIR/d32m
2493         test_mkdir -p $DIR/d32m/tmp
2494         TMP_DIR=$DIR/d32m/tmp
2495         ln -s $DIR $TMP_DIR/symlink11
2496         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2497         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2498         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2499 }
2500 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2501
2502 test_32n() {
2503         rm -fr $DIR/d32n
2504         test_mkdir -p $DIR/d32n/tmp
2505         TMP_DIR=$DIR/d32n/tmp
2506         ln -s $DIR $TMP_DIR/symlink11
2507         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2508         ls -l $DIR/d32n/tmp/symlink11  || error
2509         ls -l $DIR/d32n/symlink01 || error
2510 }
2511 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2512
2513 test_32o() {
2514         touch $DIR/$tfile
2515         test_mkdir -p $DIR/d32o/tmp
2516         TMP_DIR=$DIR/d32o/tmp
2517         ln -s $DIR/$tfile $TMP_DIR/symlink12
2518         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2519         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2520         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2521         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2522         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2523 }
2524 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2525
2526 test_32p() {
2527     log 32p_1
2528         rm -fr $DIR/d32p
2529     log 32p_2
2530         rm -f $DIR/$tfile
2531     log 32p_3
2532         touch $DIR/$tfile
2533     log 32p_4
2534         test_mkdir -p $DIR/d32p/tmp
2535     log 32p_5
2536         TMP_DIR=$DIR/d32p/tmp
2537     log 32p_6
2538         ln -s $DIR/$tfile $TMP_DIR/symlink12
2539     log 32p_7
2540         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2541     log 32p_8
2542         cat $DIR/d32p/tmp/symlink12 || error
2543     log 32p_9
2544         cat $DIR/d32p/symlink02 || error
2545     log 32p_10
2546 }
2547 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2548
2549 cleanup_testdir_mount() {
2550         trap 0
2551         $UMOUNT -d $DIR/$tdir
2552 }
2553
2554 test_32q() {
2555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2556         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2557         trap cleanup_testdir_mount EXIT
2558         test_mkdir -p $DIR/$tdir
2559         touch $DIR/$tdir/under_the_mount
2560         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2561         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2562         cleanup_testdir_mount
2563 }
2564 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2565
2566 test_32r() {
2567         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2568         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2569         trap cleanup_testdir_mount EXIT
2570         test_mkdir -p $DIR/$tdir
2571         touch $DIR/$tdir/under_the_mount
2572         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2573         ls $DIR/$tdir | grep -q under_the_mount && error || true
2574         cleanup_testdir_mount
2575 }
2576 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2577
2578 test_33aa() {
2579         rm -f $DIR/$tfile
2580         touch $DIR/$tfile
2581         chmod 444 $DIR/$tfile
2582         chown $RUNAS_ID $DIR/$tfile
2583         log 33_1
2584         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2585         log 33_2
2586 }
2587 run_test 33aa "write file with mode 444 (should return error) ===="
2588
2589 test_33a() {
2590         rm -fr $DIR/d33
2591         test_mkdir -p $DIR/d33
2592         chown $RUNAS_ID $DIR/d33
2593         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2594         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2595                 error "open RDWR" || true
2596 }
2597 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2598
2599 test_33b() {
2600         rm -fr $DIR/d33
2601         test_mkdir -p $DIR/d33
2602         chown $RUNAS_ID $DIR/d33
2603         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2604 }
2605 run_test 33b "test open file with malformed flags (No panic)"
2606
2607 test_33c() {
2608         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2609         local ostnum
2610         local ostname
2611         local write_bytes
2612         local all_zeros
2613
2614         remote_ost_nodsh && skip "remote OST with nodsh" && return
2615         all_zeros=:
2616         rm -fr $DIR/d33
2617         test_mkdir -p $DIR/d33
2618         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2619
2620         sync
2621         for ostnum in $(seq $OSTCOUNT); do
2622                 # test-framework's OST numbering is one-based, while Lustre's
2623                 # is zero-based
2624                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2625                 # Parsing llobdstat's output sucks; we could grep the /proc
2626                 # path, but that's likely to not be as portable as using the
2627                 # llobdstat utility.  So we parse lctl output instead.
2628                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2629                         obdfilter/$ostname/stats |
2630                         awk '/^write_bytes/ {print $7}' )
2631                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2632                 if (( ${write_bytes:-0} > 0 ))
2633                 then
2634                         all_zeros=false
2635                         break;
2636                 fi
2637         done
2638
2639         $all_zeros || return 0
2640
2641         # Write four bytes
2642         echo foo > $DIR/d33/bar
2643         # Really write them
2644         sync
2645
2646         # Total up write_bytes after writing.  We'd better find non-zeros.
2647         for ostnum in $(seq $OSTCOUNT); do
2648                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2649                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2650                         obdfilter/$ostname/stats |
2651                         awk '/^write_bytes/ {print $7}' )
2652                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2653                 if (( ${write_bytes:-0} > 0 ))
2654                 then
2655                         all_zeros=false
2656                         break;
2657                 fi
2658         done
2659
2660         if $all_zeros
2661         then
2662                 for ostnum in $(seq $OSTCOUNT); do
2663                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2664                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2665                         do_facet ost$ostnum lctl get_param -n \
2666                                 obdfilter/$ostname/stats
2667                 done
2668                 error "OST not keeping write_bytes stats (b22312)"
2669         fi
2670 }
2671 run_test 33c "test llobdstat and write_bytes"
2672
2673 test_33d() {
2674         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2675         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2676         local MDTIDX=1
2677         local remote_dir=$DIR/$tdir/remote_dir
2678
2679         mkdir -p $DIR/$tdir
2680         $LFS mkdir -i $MDTIDX $remote_dir ||
2681                 error "create remote directory failed"
2682
2683         touch $remote_dir/$tfile
2684         chmod 444 $remote_dir/$tfile
2685         chown $RUNAS_ID $remote_dir/$tfile
2686
2687         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2688
2689         chown $RUNAS_ID $remote_dir
2690         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2691                                         error "create" || true
2692         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2693                                     error "open RDWR" || true
2694         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2695                                     error "create" || true
2696 }
2697 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2698
2699 test_33e() {
2700         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2701
2702         mkdir $DIR/$tdir
2703
2704         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2705         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2706         mkdir $DIR/$tdir/local_dir
2707
2708         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2709         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2710         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2711
2712         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2713                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2714
2715         rmdir $DIR/$tdir/* || error "rmdir failed"
2716
2717         umask 777
2718         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2719         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2720         mkdir $DIR/$tdir/local_dir
2721
2722         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2723         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2724         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2725
2726         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2727                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2728
2729         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2730
2731         umask 000
2732         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2733         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2734         mkdir $DIR/$tdir/local_dir
2735
2736         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2737         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2738         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2739
2740         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2741                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2742 }
2743 run_test 33e "mkdir and striped directory should have same mode"
2744
2745 cleanup_33f() {
2746         trap 0
2747         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2748 }
2749
2750 test_33f() {
2751         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2752
2753         mkdir $DIR/$tdir
2754         chmod go+rwx $DIR/$tdir
2755         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2756         trap cleanup_33f EXIT
2757
2758         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2759                 error "cannot create striped directory"
2760
2761         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2762                 error "cannot create files in striped directory"
2763
2764         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2765                 error "cannot remove files in striped directory"
2766
2767         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2768                 error "cannot remove striped directory"
2769
2770         cleanup_33f
2771 }
2772 run_test 33f "nonroot user can create, access, and remove a striped directory"
2773
2774 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2775 test_34a() {
2776         rm -f $DIR/f34
2777         $MCREATE $DIR/f34 || error
2778         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2779         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2780         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2781         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2782 }
2783 run_test 34a "truncate file that has not been opened ==========="
2784
2785 test_34b() {
2786         [ ! -f $DIR/f34 ] && test_34a
2787         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2788         $OPENFILE -f O_RDONLY $DIR/f34
2789         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2790         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2791 }
2792 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2793
2794 test_34c() {
2795         [ ! -f $DIR/f34 ] && test_34a
2796         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2797         $OPENFILE -f O_RDWR $DIR/f34
2798         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2799         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2800 }
2801 run_test 34c "O_RDWR opening file-with-size works =============="
2802
2803 test_34d() {
2804         [ ! -f $DIR/f34 ] && test_34a
2805         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2806         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2807         rm $DIR/f34
2808 }
2809 run_test 34d "write to sparse file ============================="
2810
2811 test_34e() {
2812         rm -f $DIR/f34e
2813         $MCREATE $DIR/f34e || error
2814         $TRUNCATE $DIR/f34e 1000 || error
2815         $CHECKSTAT -s 1000 $DIR/f34e || error
2816         $OPENFILE -f O_RDWR $DIR/f34e
2817         $CHECKSTAT -s 1000 $DIR/f34e || error
2818 }
2819 run_test 34e "create objects, some with size and some without =="
2820
2821 test_34f() { # bug 6242, 6243
2822         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2823         SIZE34F=48000
2824         rm -f $DIR/f34f
2825         $MCREATE $DIR/f34f || error
2826         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2827         dd if=$DIR/f34f of=$TMP/f34f
2828         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2829         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2830         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2831         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2832         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2833 }
2834 run_test 34f "read from a file with no objects until EOF ======="
2835
2836 test_34g() {
2837         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2838         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2839         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2840         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2841         cancel_lru_locks osc
2842         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2843                 error "wrong size after lock cancel"
2844
2845         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2846         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2847                 error "expanding truncate failed"
2848         cancel_lru_locks osc
2849         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2850                 error "wrong expanded size after lock cancel"
2851 }
2852 run_test 34g "truncate long file ==============================="
2853
2854 test_34h() {
2855         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2856         local gid=10
2857         local sz=1000
2858
2859         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2860         sync # Flush the cache so that multiop below does not block on cache
2861              # flush when getting the group lock
2862         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2863         MULTIPID=$!
2864
2865         # Since just timed wait is not good enough, let's do a sync write
2866         # that way we are sure enough time for a roundtrip + processing
2867         # passed + 2 seconds of extra margin.
2868         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2869         rm $DIR/${tfile}-1
2870         sleep 2
2871
2872         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2873                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2874                 kill -9 $MULTIPID
2875         fi
2876         wait $MULTIPID
2877         local nsz=`stat -c %s $DIR/$tfile`
2878         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2879 }
2880 run_test 34h "ftruncate file under grouplock should not block"
2881
2882 test_35a() {
2883         cp /bin/sh $DIR/f35a
2884         chmod 444 $DIR/f35a
2885         chown $RUNAS_ID $DIR/f35a
2886         $RUNAS $DIR/f35a && error || true
2887         rm $DIR/f35a
2888 }
2889 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2890
2891 test_36a() {
2892         rm -f $DIR/f36
2893         utime $DIR/f36 || error
2894 }
2895 run_test 36a "MDS utime check (mknod, utime) ==================="
2896
2897 test_36b() {
2898         echo "" > $DIR/f36
2899         utime $DIR/f36 || error
2900 }
2901 run_test 36b "OST utime check (open, utime) ===================="
2902
2903 test_36c() {
2904         rm -f $DIR/d36/f36
2905         test_mkdir $DIR/d36
2906         chown $RUNAS_ID $DIR/d36
2907         $RUNAS utime $DIR/d36/f36 || error
2908 }
2909 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2910
2911 test_36d() {
2912         [ ! -d $DIR/d36 ] && test_36c
2913         echo "" > $DIR/d36/f36
2914         $RUNAS utime $DIR/d36/f36 || error
2915 }
2916 run_test 36d "non-root OST utime check (open, utime) ==========="
2917
2918 test_36e() {
2919         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2920         test_mkdir -p $DIR/$tdir
2921         touch $DIR/$tdir/$tfile
2922         $RUNAS utime $DIR/$tdir/$tfile && \
2923                 error "utime worked, expected failure" || true
2924 }
2925 run_test 36e "utime on non-owned file (should return error) ===="
2926
2927 subr_36fh() {
2928         local fl="$1"
2929         local LANG_SAVE=$LANG
2930         local LC_LANG_SAVE=$LC_LANG
2931         export LANG=C LC_LANG=C # for date language
2932
2933         DATESTR="Dec 20  2000"
2934         test_mkdir -p $DIR/$tdir
2935         lctl set_param fail_loc=$fl
2936         date; date +%s
2937         cp /etc/hosts $DIR/$tdir/$tfile
2938         sync & # write RPC generated with "current" inode timestamp, but delayed
2939         sleep 1
2940         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2941         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2942         cancel_lru_locks osc
2943         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2944         date; date +%s
2945         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2946                 echo "BEFORE: $LS_BEFORE" && \
2947                 echo "AFTER : $LS_AFTER" && \
2948                 echo "WANT  : $DATESTR" && \
2949                 error "$DIR/$tdir/$tfile timestamps changed" || true
2950
2951         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2952 }
2953
2954 test_36f() {
2955         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2956         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2957         subr_36fh "0x80000214"
2958 }
2959 run_test 36f "utime on file racing with OST BRW write =========="
2960
2961 test_36g() {
2962         remote_ost_nodsh && skip "remote OST with nodsh" && return
2963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2964         local fmd_max_age
2965         local fmd_before
2966         local fmd_after
2967
2968         test_mkdir -p $DIR/$tdir
2969         fmd_max_age=$(do_facet ost1 \
2970                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2971                 head -n 1")
2972
2973         fmd_before=$(do_facet ost1 \
2974                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2975         touch $DIR/$tdir/$tfile
2976         sleep $((fmd_max_age + 12))
2977         fmd_after=$(do_facet ost1 \
2978                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2979
2980         echo "fmd_before: $fmd_before"
2981         echo "fmd_after: $fmd_after"
2982         [[ $fmd_after -gt $fmd_before ]] &&
2983                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2984                 error "fmd didn't expire after ping" || true
2985 }
2986 run_test 36g "filter mod data cache expiry ====================="
2987
2988 test_36h() {
2989         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2990         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2991         subr_36fh "0x80000227"
2992 }
2993 run_test 36h "utime on file racing with OST BRW write =========="
2994
2995 test_36i() {
2996         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2997
2998         mkdir $DIR/$tdir
2999         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3000
3001         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3002         local new_mtime=$((mtime + 200))
3003
3004         #change Modify time of striped dir
3005         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3006                         error "change mtime failed"
3007
3008         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3009
3010         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3011 }
3012 run_test 36i "change mtime on striped directory"
3013
3014 # test_37 - duplicate with tests 32q 32r
3015
3016 test_38() {
3017         local file=$DIR/$tfile
3018         touch $file
3019         openfile -f O_DIRECTORY $file
3020         local RC=$?
3021         local ENOTDIR=20
3022         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3023         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3024 }
3025 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3026
3027 test_39() {
3028         touch $DIR/$tfile
3029         touch $DIR/${tfile}2
3030 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3031 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3032 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3033         sleep 2
3034         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3035         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3036                 echo "mtime"
3037                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3038                 echo "atime"
3039                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3040                 echo "ctime"
3041                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3042                 error "O_TRUNC didn't change timestamps"
3043         fi
3044 }
3045 run_test 39 "mtime changed on create ==========================="
3046
3047 test_39b() {
3048         test_mkdir -p -c1 $DIR/$tdir
3049         cp -p /etc/passwd $DIR/$tdir/fopen
3050         cp -p /etc/passwd $DIR/$tdir/flink
3051         cp -p /etc/passwd $DIR/$tdir/funlink
3052         cp -p /etc/passwd $DIR/$tdir/frename
3053         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3054
3055         sleep 1
3056         echo "aaaaaa" >> $DIR/$tdir/fopen
3057         echo "aaaaaa" >> $DIR/$tdir/flink
3058         echo "aaaaaa" >> $DIR/$tdir/funlink
3059         echo "aaaaaa" >> $DIR/$tdir/frename
3060
3061         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3062         local link_new=`stat -c %Y $DIR/$tdir/flink`
3063         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3064         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3065
3066         cat $DIR/$tdir/fopen > /dev/null
3067         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3068         rm -f $DIR/$tdir/funlink2
3069         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3070
3071         for (( i=0; i < 2; i++ )) ; do
3072                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3073                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3074                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3075                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3076
3077                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3078                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3079                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3080                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3081
3082                 cancel_lru_locks osc
3083                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3084         done
3085 }
3086 run_test 39b "mtime change on open, link, unlink, rename  ======"
3087
3088 # this should be set to past
3089 TEST_39_MTIME=`date -d "1 year ago" +%s`
3090
3091 # bug 11063
3092 test_39c() {
3093         touch $DIR1/$tfile
3094         sleep 2
3095         local mtime0=`stat -c %Y $DIR1/$tfile`
3096
3097         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3098         local mtime1=`stat -c %Y $DIR1/$tfile`
3099         [ "$mtime1" = $TEST_39_MTIME ] || \
3100                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3101
3102         local d1=`date +%s`
3103         echo hello >> $DIR1/$tfile
3104         local d2=`date +%s`
3105         local mtime2=`stat -c %Y $DIR1/$tfile`
3106         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3107                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3108
3109         mv $DIR1/$tfile $DIR1/$tfile-1
3110
3111         for (( i=0; i < 2; i++ )) ; do
3112                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3113                 [ "$mtime2" = "$mtime3" ] || \
3114                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3115
3116                 cancel_lru_locks osc
3117                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3118         done
3119 }
3120 run_test 39c "mtime change on rename ==========================="
3121
3122 # bug 21114
3123 test_39d() {
3124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3125         touch $DIR1/$tfile
3126
3127         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3128
3129         for (( i=0; i < 2; i++ )) ; do
3130                 local mtime=`stat -c %Y $DIR1/$tfile`
3131                 [ $mtime = $TEST_39_MTIME ] || \
3132                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3133
3134                 cancel_lru_locks osc
3135                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3136         done
3137 }
3138 run_test 39d "create, utime, stat =============================="
3139
3140 # bug 21114
3141 test_39e() {
3142         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3143         touch $DIR1/$tfile
3144         local mtime1=`stat -c %Y $DIR1/$tfile`
3145
3146         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3147
3148         for (( i=0; i < 2; i++ )) ; do
3149                 local mtime2=`stat -c %Y $DIR1/$tfile`
3150                 [ $mtime2 = $TEST_39_MTIME ] || \
3151                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3152
3153                 cancel_lru_locks osc
3154                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3155         done
3156 }
3157 run_test 39e "create, stat, utime, stat ========================"
3158
3159 # bug 21114
3160 test_39f() {
3161         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3162         touch $DIR1/$tfile
3163         mtime1=`stat -c %Y $DIR1/$tfile`
3164
3165         sleep 2
3166         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3167
3168         for (( i=0; i < 2; i++ )) ; do
3169                 local mtime2=`stat -c %Y $DIR1/$tfile`
3170                 [ $mtime2 = $TEST_39_MTIME ] || \
3171                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3172
3173                 cancel_lru_locks osc
3174                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3175         done
3176 }
3177 run_test 39f "create, stat, sleep, utime, stat ================="
3178
3179 # bug 11063
3180 test_39g() {
3181         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3182         echo hello >> $DIR1/$tfile
3183         local mtime1=`stat -c %Y $DIR1/$tfile`
3184
3185         sleep 2
3186         chmod o+r $DIR1/$tfile
3187
3188         for (( i=0; i < 2; i++ )) ; do
3189                 local mtime2=`stat -c %Y $DIR1/$tfile`
3190                 [ "$mtime1" = "$mtime2" ] || \
3191                         error "lost mtime: $mtime2, should be $mtime1"
3192
3193                 cancel_lru_locks osc
3194                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3195         done
3196 }
3197 run_test 39g "write, chmod, stat ==============================="
3198
3199 # bug 11063
3200 test_39h() {
3201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3202         touch $DIR1/$tfile
3203         sleep 1
3204
3205         local d1=`date`
3206         echo hello >> $DIR1/$tfile
3207         local mtime1=`stat -c %Y $DIR1/$tfile`
3208
3209         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3210         local d2=`date`
3211         if [ "$d1" != "$d2" ]; then
3212                 echo "write and touch not within one second"
3213         else
3214                 for (( i=0; i < 2; i++ )) ; do
3215                         local mtime2=`stat -c %Y $DIR1/$tfile`
3216                         [ "$mtime2" = $TEST_39_MTIME ] || \
3217                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3218
3219                         cancel_lru_locks osc
3220                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3221                 done
3222         fi
3223 }
3224 run_test 39h "write, utime within one second, stat ============="
3225
3226 test_39i() {
3227         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3228         touch $DIR1/$tfile
3229         sleep 1
3230
3231         echo hello >> $DIR1/$tfile
3232         local mtime1=`stat -c %Y $DIR1/$tfile`
3233
3234         mv $DIR1/$tfile $DIR1/$tfile-1
3235
3236         for (( i=0; i < 2; i++ )) ; do
3237                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3238
3239                 [ "$mtime1" = "$mtime2" ] || \
3240                         error "lost mtime: $mtime2, should be $mtime1"
3241
3242                 cancel_lru_locks osc
3243                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3244         done
3245 }
3246 run_test 39i "write, rename, stat =============================="
3247
3248 test_39j() {
3249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3250         start_full_debug_logging
3251         touch $DIR1/$tfile
3252         sleep 1
3253
3254         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3255         lctl set_param fail_loc=0x80000412
3256         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3257                 error "multiop failed"
3258         local multipid=$!
3259         local mtime1=`stat -c %Y $DIR1/$tfile`
3260
3261         mv $DIR1/$tfile $DIR1/$tfile-1
3262
3263         kill -USR1 $multipid
3264         wait $multipid || error "multiop close failed"
3265
3266         for (( i=0; i < 2; i++ )) ; do
3267                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3268                 [ "$mtime1" = "$mtime2" ] ||
3269                         error "mtime is lost on close: $mtime2, " \
3270                               "should be $mtime1"
3271
3272                 cancel_lru_locks osc
3273                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3274         done
3275         lctl set_param fail_loc=0
3276         stop_full_debug_logging
3277 }
3278 run_test 39j "write, rename, close, stat ======================="
3279
3280 test_39k() {
3281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3282         touch $DIR1/$tfile
3283         sleep 1
3284
3285         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3286         local multipid=$!
3287         local mtime1=`stat -c %Y $DIR1/$tfile`
3288
3289         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3290
3291         kill -USR1 $multipid
3292         wait $multipid || error "multiop close failed"
3293
3294         for (( i=0; i < 2; i++ )) ; do
3295                 local mtime2=`stat -c %Y $DIR1/$tfile`
3296
3297                 [ "$mtime2" = $TEST_39_MTIME ] || \
3298                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3299
3300                 cancel_lru_locks osc
3301                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3302         done
3303 }
3304 run_test 39k "write, utime, close, stat ========================"
3305
3306 # this should be set to future
3307 TEST_39_ATIME=`date -d "1 year" +%s`
3308
3309 test_39l() {
3310         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3311         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3312         local atime_diff=$(do_facet $SINGLEMDS \
3313                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3314         rm -rf $DIR/$tdir
3315         mkdir -p $DIR/$tdir
3316
3317         # test setting directory atime to future
3318         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3319         local atime=$(stat -c %X $DIR/$tdir)
3320         [ "$atime" = $TEST_39_ATIME ] || \
3321                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3322
3323         # test setting directory atime from future to now
3324         local d1=$(date +%s)
3325         ls $DIR/$tdir
3326         local d2=$(date +%s)
3327
3328         cancel_lru_locks mdc
3329         atime=$(stat -c %X $DIR/$tdir)
3330         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3331                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3332
3333         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3334         sleep 3
3335
3336         # test setting directory atime when now > dir atime + atime_diff
3337         d1=$(date +%s)
3338         ls $DIR/$tdir
3339         d2=$(date +%s)
3340         cancel_lru_locks mdc
3341         atime=$(stat -c %X $DIR/$tdir)
3342         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3343                 error "atime is not updated  : $atime, should be $d2"
3344
3345         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3346         sleep 3
3347
3348         # test not setting directory atime when now < dir atime + atime_diff
3349         ls $DIR/$tdir
3350         cancel_lru_locks mdc
3351         atime=$(stat -c %X $DIR/$tdir)
3352         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3353                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3354
3355         do_facet $SINGLEMDS \
3356                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3357 }
3358 run_test 39l "directory atime update ==========================="
3359
3360 test_39m() {
3361         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3362         touch $DIR1/$tfile
3363         sleep 2
3364         local far_past_mtime=$(date -d "May 29 1953" +%s)
3365         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3366
3367         touch -m -d @$far_past_mtime $DIR1/$tfile
3368         touch -a -d @$far_past_atime $DIR1/$tfile
3369
3370         for (( i=0; i < 2; i++ )) ; do
3371                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3372                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3373                         error "atime or mtime set incorrectly"
3374
3375                 cancel_lru_locks osc
3376                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3377         done
3378 }
3379 run_test 39m "test atime and mtime before 1970"
3380
3381 test_39n() { # LU-3832
3382         local atime_diff=$(do_facet $SINGLEMDS \
3383                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3384         local atime0
3385         local atime1
3386         local atime2
3387
3388         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3389
3390         rm -rf $DIR/$tfile
3391         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3392         atime0=$(stat -c %X $DIR/$tfile)
3393
3394         sleep 5
3395         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3396         atime1=$(stat -c %X $DIR/$tfile)
3397
3398         sleep 5
3399         cancel_lru_locks mdc
3400         cancel_lru_locks osc
3401         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3402         atime2=$(stat -c %X $DIR/$tfile)
3403
3404         do_facet $SINGLEMDS \
3405                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3406
3407         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3408         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3409 }
3410 run_test 39n "check that O_NOATIME is honored"
3411
3412 test_39o() {
3413         TESTDIR=$DIR/$tdir/$tfile
3414         [ -e $TESTDIR ] && rm -rf $TESTDIR
3415         test_mkdir -p $TESTDIR
3416         cd $TESTDIR
3417         links1=2
3418         ls
3419         mkdir a b
3420         ls
3421         links2=$(stat -c %h .)
3422         [ $(($links1 + 2)) != $links2 ] &&
3423                 error "wrong links count $(($links1 + 2)) != $links2"
3424         rmdir b
3425         links3=$(stat -c %h .)
3426         [ $(($links1 + 1)) != $links3 ] &&
3427                 error "wrong links count $links1 != $links3"
3428         return 0
3429 }
3430 run_test 39o "directory cached attributes updated after create ========"
3431
3432 test_39p() {
3433         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3434         local MDTIDX=1
3435         TESTDIR=$DIR/$tdir/$tfile
3436         [ -e $TESTDIR ] && rm -rf $TESTDIR
3437         mkdir -p $TESTDIR
3438         cd $TESTDIR
3439         links1=2
3440         ls
3441         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3442         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3443         ls
3444         links2=$(stat -c %h .)
3445         [ $(($links1 + 2)) != $links2 ] &&
3446                 error "wrong links count $(($links1 + 2)) != $links2"
3447         rmdir remote_dir2
3448         links3=$(stat -c %h .)
3449         [ $(($links1 + 1)) != $links3 ] &&
3450                 error "wrong links count $links1 != $links3"
3451         return 0
3452 }
3453 run_test 39p "remote directory cached attributes updated after create ========"
3454
3455
3456 test_40() {
3457         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3458         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3459                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3460         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3461                 error "$tfile is not 4096 bytes in size"
3462 }
3463 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3464
3465 test_41() {
3466         # bug 1553
3467         small_write $DIR/f41 18
3468 }
3469 run_test 41 "test small file write + fstat ====================="
3470
3471 count_ost_writes() {
3472         lctl get_param -n osc.*.stats |
3473                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3474                         END { printf("%0.0f", writes) }'
3475 }
3476
3477 # decent default
3478 WRITEBACK_SAVE=500
3479 DIRTY_RATIO_SAVE=40
3480 MAX_DIRTY_RATIO=50
3481 BG_DIRTY_RATIO_SAVE=10
3482 MAX_BG_DIRTY_RATIO=25
3483
3484 start_writeback() {
3485         trap 0
3486         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3487         # dirty_ratio, dirty_background_ratio
3488         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3489                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3490                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3491                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3492         else
3493                 # if file not here, we are a 2.4 kernel
3494                 kill -CONT `pidof kupdated`
3495         fi
3496 }
3497
3498 stop_writeback() {
3499         # setup the trap first, so someone cannot exit the test at the
3500         # exact wrong time and mess up a machine
3501         trap start_writeback EXIT
3502         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3503         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3504                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3505                 sysctl -w vm.dirty_writeback_centisecs=0
3506                 sysctl -w vm.dirty_writeback_centisecs=0
3507                 # save and increase /proc/sys/vm/dirty_ratio
3508                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3509                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3510                 # save and increase /proc/sys/vm/dirty_background_ratio
3511                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3512                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3513         else
3514                 # if file not here, we are a 2.4 kernel
3515                 kill -STOP `pidof kupdated`
3516         fi
3517 }
3518
3519 # ensure that all stripes have some grant before we test client-side cache
3520 setup_test42() {
3521         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3522                 dd if=/dev/zero of=$i bs=4k count=1
3523                 rm $i
3524         done
3525 }
3526
3527 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3528 # file truncation, and file removal.
3529 test_42a() {
3530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3531         setup_test42
3532         cancel_lru_locks osc
3533         stop_writeback
3534         sync; sleep 1; sync # just to be safe
3535         BEFOREWRITES=`count_ost_writes`
3536         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3537         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3538         AFTERWRITES=`count_ost_writes`
3539         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3540                 error "$BEFOREWRITES < $AFTERWRITES"
3541         start_writeback
3542 }
3543 run_test 42a "ensure that we don't flush on close =============="
3544
3545 test_42b() {
3546         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3547         setup_test42
3548         cancel_lru_locks osc
3549         stop_writeback
3550         sync
3551         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3552         BEFOREWRITES=$(count_ost_writes)
3553         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3554         AFTERWRITES=$(count_ost_writes)
3555         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3556                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3557         fi
3558         BEFOREWRITES=$(count_ost_writes)
3559         sync || error "sync: $?"
3560         AFTERWRITES=$(count_ost_writes)
3561         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3562                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3563         fi
3564         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3565         start_writeback
3566         return 0
3567 }
3568 run_test 42b "test destroy of file with cached dirty data ======"
3569
3570 # if these tests just want to test the effect of truncation,
3571 # they have to be very careful.  consider:
3572 # - the first open gets a {0,EOF}PR lock
3573 # - the first write conflicts and gets a {0, count-1}PW
3574 # - the rest of the writes are under {count,EOF}PW
3575 # - the open for truncate tries to match a {0,EOF}PR
3576 #   for the filesize and cancels the PWs.
3577 # any number of fixes (don't get {0,EOF} on open, match
3578 # composite locks, do smarter file size management) fix
3579 # this, but for now we want these tests to verify that
3580 # the cancellation with truncate intent works, so we
3581 # start the file with a full-file pw lock to match against
3582 # until the truncate.
3583 trunc_test() {
3584         test=$1
3585         file=$DIR/$test
3586         offset=$2
3587         cancel_lru_locks osc
3588         stop_writeback
3589         # prime the file with 0,EOF PW to match
3590         touch $file
3591         $TRUNCATE $file 0
3592         sync; sync
3593         # now the real test..
3594         dd if=/dev/zero of=$file bs=1024 count=100
3595         BEFOREWRITES=`count_ost_writes`
3596         $TRUNCATE $file $offset
3597         cancel_lru_locks osc
3598         AFTERWRITES=`count_ost_writes`
3599         start_writeback
3600 }
3601
3602 test_42c() {
3603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3604         trunc_test 42c 1024
3605         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3606             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3607         rm $file
3608 }
3609 run_test 42c "test partial truncate of file with cached dirty data"
3610
3611 test_42d() {
3612         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3613         trunc_test 42d 0
3614         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3615             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3616         rm $file
3617 }
3618 run_test 42d "test complete truncate of file with cached dirty data"
3619
3620 test_42e() { # bug22074
3621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3622         local TDIR=$DIR/${tdir}e
3623         local pagesz=$(page_size)
3624         local pages=16 # hardcoded 16 pages, don't change it.
3625         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3626         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3627         local max_dirty_mb
3628         local warmup_files
3629
3630         test_mkdir -p $DIR/${tdir}e
3631         $SETSTRIPE -c 1 $TDIR
3632         createmany -o $TDIR/f $files
3633
3634         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3635
3636         # we assume that with $OSTCOUNT files, at least one of them will
3637         # be allocated on OST0.
3638         warmup_files=$((OSTCOUNT * max_dirty_mb))
3639         createmany -o $TDIR/w $warmup_files
3640
3641         # write a large amount of data into one file and sync, to get good
3642         # avail_grant number from OST.
3643         for ((i=0; i<$warmup_files; i++)); do
3644                 idx=$($GETSTRIPE -i $TDIR/w$i)
3645                 [ $idx -ne 0 ] && continue
3646                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3647                 break
3648         done
3649         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3650         sync
3651         $LCTL get_param $proc_osc0/cur_dirty_bytes
3652         $LCTL get_param $proc_osc0/cur_grant_bytes
3653
3654         # create as much dirty pages as we can while not to trigger the actual
3655         # RPCs directly. but depends on the env, VFS may trigger flush during this
3656         # period, hopefully we are good.
3657         for ((i=0; i<$warmup_files; i++)); do
3658                 idx=$($GETSTRIPE -i $TDIR/w$i)
3659                 [ $idx -ne 0 ] && continue
3660                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3661         done
3662         $LCTL get_param $proc_osc0/cur_dirty_bytes
3663         $LCTL get_param $proc_osc0/cur_grant_bytes
3664
3665         # perform the real test
3666         $LCTL set_param $proc_osc0/rpc_stats 0
3667         for ((;i<$files; i++)); do
3668                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3669                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3670         done
3671         sync
3672         $LCTL get_param $proc_osc0/rpc_stats
3673
3674         local percent=0
3675         local have_ppr=false
3676         $LCTL get_param $proc_osc0/rpc_stats |
3677                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3678                         # skip lines until we are at the RPC histogram data
3679                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3680                         $have_ppr || continue
3681
3682                         # we only want the percent stat for < 16 pages
3683                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3684
3685                         percent=$((percent + WPCT))
3686                         if [[ $percent -gt 15 ]]; then
3687                                 error "less than 16-pages write RPCs" \
3688                                       "$percent% > 15%"
3689                                 break
3690                         fi
3691                 done
3692         rm -rf $TDIR
3693 }
3694 run_test 42e "verify sub-RPC writes are not done synchronously"
3695
3696 test_43() {
3697         test_mkdir -p $DIR/$tdir
3698         cp -p /bin/ls $DIR/$tdir/$tfile
3699         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3700         pid=$!
3701         # give multiop a chance to open
3702         sleep 1
3703
3704         $DIR/$tdir/$tfile && error || true
3705         kill -USR1 $pid
3706 }
3707 run_test 43 "execution of file opened for write should return -ETXTBSY"
3708
3709 test_43a() {
3710         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3711         test_mkdir -p $DIR/$tdir
3712         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3713                         cp -p multiop $DIR/$tdir/multiop
3714         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3715                         return 1
3716         MULTIOP_PID=$!
3717         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3718         kill -USR1 $MULTIOP_PID || return 2
3719         wait $MULTIOP_PID || return 3
3720         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3721 }
3722 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3723
3724 test_43b() {
3725         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3726         test_mkdir -p $DIR/$tdir
3727         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3728                         cp -p multiop $DIR/$tdir/multiop
3729         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3730                         return 1
3731         MULTIOP_PID=$!
3732         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3733         kill -USR1 $MULTIOP_PID || return 2
3734         wait $MULTIOP_PID || return 3
3735         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3736 }
3737 run_test 43b "truncate of file being executed should return -ETXTBSY"
3738
3739 test_43c() {
3740         local testdir="$DIR/$tdir"
3741         test_mkdir -p $DIR/$tdir
3742         cp $SHELL $testdir/
3743         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3744                 ( cd $testdir && md5sum -c)
3745 }
3746 run_test 43c "md5sum of copy into lustre========================"
3747
3748 test_44() {
3749         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3750         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3751         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3752 }
3753 run_test 44 "zero length read from a sparse stripe ============="
3754
3755 test_44a() {
3756         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3757                 awk '{ print $2 }')
3758         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3759         [[ $nstripe -gt $OSTCOUNT ]] &&
3760             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3761             return
3762         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3763                 awk '{ print $2 }')
3764         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3765                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3766                         awk '{ print $2 }')
3767         fi
3768
3769         OFFSETS="0 $((stride/2)) $((stride-1))"
3770         for offset in $OFFSETS; do
3771                 for i in $(seq 0 $((nstripe-1))); do
3772                         local GLOBALOFFSETS=""
3773                         # size in Bytes
3774                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3775                         local myfn=$DIR/d44a-$size
3776                         echo "--------writing $myfn at $size"
3777                         ll_sparseness_write $myfn $size ||
3778                                 error "ll_sparseness_write"
3779                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3780                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3781                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3782
3783                         for j in $(seq 0 $((nstripe-1))); do
3784                                 # size in Bytes
3785                                 size=$((((j + $nstripe )*$stride + $offset)))
3786                                 ll_sparseness_write $myfn $size ||
3787                                         error "ll_sparseness_write"
3788                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3789                         done
3790                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3791                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3792                         rm -f $myfn
3793                 done
3794         done
3795 }
3796 run_test 44a "test sparse pwrite ==============================="
3797
3798 dirty_osc_total() {
3799         tot=0
3800         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3801                 tot=$(($tot + $d))
3802         done
3803         echo $tot
3804 }
3805 do_dirty_record() {
3806         before=`dirty_osc_total`
3807         echo executing "\"$*\""
3808         eval $*
3809         after=`dirty_osc_total`
3810         echo before $before, after $after
3811 }
3812 test_45() {
3813         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3814         f="$DIR/f45"
3815         # Obtain grants from OST if it supports it
3816         echo blah > ${f}_grant
3817         stop_writeback
3818         sync
3819         do_dirty_record "echo blah > $f"
3820         [[ $before -eq $after ]] && error "write wasn't cached"
3821         do_dirty_record "> $f"
3822         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3823         do_dirty_record "echo blah > $f"
3824         [[ $before -eq $after ]] && error "write wasn't cached"
3825         do_dirty_record "sync"
3826         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3827         do_dirty_record "echo blah > $f"
3828         [[ $before -eq $after ]] && error "write wasn't cached"
3829         do_dirty_record "cancel_lru_locks osc"
3830         [[ $before -gt $after ]] ||
3831                 error "lock cancellation didn't lower dirty count"
3832         start_writeback
3833 }
3834 run_test 45 "osc io page accounting ============================"
3835
3836 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3837 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3838 # objects offset and an assert hit when an rpc was built with 1023's mapped
3839 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3840 test_46() {
3841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3842         f="$DIR/f46"
3843         stop_writeback
3844         sync
3845         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3846         sync
3847         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3848         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3849         sync
3850         start_writeback
3851 }
3852 run_test 46 "dirtying a previously written page ================"
3853
3854 # test_47 is removed "Device nodes check" is moved to test_28
3855
3856 test_48a() { # bug 2399
3857         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3858         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3859                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3860                 return
3861         test_mkdir $DIR/$tdir
3862         cd $DIR/$tdir
3863         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3864         test_mkdir $DIR/$tdir || error "recreate directory failed"
3865         touch foo || error "'touch foo' failed after recreating cwd"
3866         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3867         touch .foo || error "'touch .foo' failed after recreating cwd"
3868         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3869         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3870         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3871         cd . || error "'cd .' failed after recreating cwd"
3872         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3873         rmdir . && error "'rmdir .' worked after recreating cwd"
3874         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3875         cd .. || error "'cd ..' failed after recreating cwd"
3876 }
3877 run_test 48a "Access renamed working dir (should return errors)="
3878
3879 test_48b() { # bug 2399
3880         rm -rf $DIR/$tdir
3881         test_mkdir $DIR/$tdir
3882         cd $DIR/$tdir
3883         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3884         touch foo && error "'touch foo' worked after removing cwd"
3885         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3886         touch .foo && error "'touch .foo' worked after removing cwd"
3887         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3888         ls . > /dev/null && error "'ls .' worked after removing cwd"
3889         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3890         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3891         test_mkdir . && error "'mkdir .' worked after removing cwd"
3892         rmdir . && error "'rmdir .' worked after removing cwd"
3893         ln -s . foo && error "'ln -s .' worked after removing cwd"
3894         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3895 }
3896 run_test 48b "Access removed working dir (should return errors)="
3897
3898 test_48c() { # bug 2350
3899         #lctl set_param debug=-1
3900         #set -vx
3901         rm -rf $DIR/$tdir
3902         test_mkdir -p $DIR/$tdir/dir
3903         cd $DIR/$tdir/dir
3904         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3905         $TRACE touch foo && error "touch foo worked after removing cwd"
3906         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3907         touch .foo && error "touch .foo worked after removing cwd"
3908         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3909         $TRACE ls . && error "'ls .' worked after removing cwd"
3910         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3911         is_patchless || ( $TRACE cd . &&
3912                         error "'cd .' worked after removing cwd" )
3913         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3914         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3915         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3916         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3917 }
3918 run_test 48c "Access removed working subdir (should return errors)"
3919
3920 test_48d() { # bug 2350
3921         #lctl set_param debug=-1
3922         #set -vx
3923         rm -rf $DIR/$tdir
3924         test_mkdir -p $DIR/$tdir/dir
3925         cd $DIR/$tdir/dir
3926         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3927         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3928         $TRACE touch foo && error "'touch foo' worked after removing parent"
3929         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3930         touch .foo && error "'touch .foo' worked after removing parent"
3931         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3932         $TRACE ls . && error "'ls .' worked after removing parent"
3933         $TRACE ls .. && error "'ls ..' worked after removing parent"
3934         is_patchless || ( $TRACE cd . &&
3935                         error "'cd .' worked after recreate parent" )
3936         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3937         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3938         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3939         is_patchless || ( $TRACE cd .. &&
3940                         error "'cd ..' worked after removing parent" || true )
3941 }
3942 run_test 48d "Access removed parent subdir (should return errors)"
3943
3944 test_48e() { # bug 4134
3945         #lctl set_param debug=-1
3946         #set -vx
3947         rm -rf $DIR/$tdir
3948         test_mkdir -p $DIR/$tdir/dir
3949         cd $DIR/$tdir/dir
3950         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3951         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3952         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3953         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3954         # On a buggy kernel addition of "touch foo" after cd .. will
3955         # produce kernel oops in lookup_hash_it
3956         touch ../foo && error "'cd ..' worked after recreate parent"
3957         cd $DIR
3958         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3959 }
3960 run_test 48e "Access to recreated parent subdir (should return errors)"
3961
3962 test_49() { # LU-1030
3963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3964         # get ost1 size - lustre-OST0000
3965         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3966                 awk '{ print $4 }')
3967         # write 800M at maximum
3968         [[ $ost1_size -lt 2 ]] && ost1_size=2
3969         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3970
3971         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3972         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3973         local dd_pid=$!
3974
3975         # change max_pages_per_rpc while writing the file
3976         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3977         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3978         # loop until dd process exits
3979         while ps ax -opid | grep -wq $dd_pid; do
3980                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3981                 sleep $((RANDOM % 5 + 1))
3982         done
3983         # restore original max_pages_per_rpc
3984         $LCTL set_param $osc1_mppc=$orig_mppc
3985         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3986 }
3987 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3988
3989 test_50() {
3990         # bug 1485
3991         test_mkdir $DIR/$tdir
3992         cd $DIR/$tdir
3993         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3994 }
3995 run_test 50 "special situations: /proc symlinks  ==============="
3996
3997 test_51a() {    # was test_51
3998         # bug 1516 - create an empty entry right after ".." then split dir
3999         test_mkdir -c1 $DIR/$tdir
4000         touch $DIR/$tdir/foo
4001         $MCREATE $DIR/$tdir/bar
4002         rm $DIR/$tdir/foo
4003         createmany -m $DIR/$tdir/longfile 201
4004         FNUM=202
4005         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4006                 $MCREATE $DIR/$tdir/longfile$FNUM
4007                 FNUM=$(($FNUM + 1))
4008                 echo -n "+"
4009         done
4010         echo
4011         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4012 }
4013 run_test 51a "special situations: split htree with empty entry =="
4014
4015 export NUMTEST=70000
4016 test_51b() {
4017         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4018         local BASE=$DIR/d${base}.${TESTSUITE}
4019
4020         # cleanup the directory
4021         rm -fr $BASE
4022
4023         test_mkdir -p -c1 $BASE
4024
4025         $LFS df
4026         $LFS df -i
4027         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4028         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4029         [[ $numfree -lt 21000 ]] &&
4030                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4031                 return
4032
4033         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4034                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4035
4036         # need to check free space for the directories as well
4037         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4038         numfree=$((blkfree / 4))
4039         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4040                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4041
4042         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4043         {
4044                 $LFS df
4045                 $LFS df -i
4046                 echo "failed" > $BASE/fnum
4047                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4048         }
4049 }
4050 run_test 51b "exceed 64k subdirectory nlink limit"
4051
4052 test_51ba() { # LU-993
4053         local BASE=$DIR/d${base}.${TESTSUITE}
4054         # unlink all but 100 subdirectories, then check it still works
4055         local LEFT=100
4056         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4057
4058         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4059         local DELETE=$((NUMTEST - LEFT))
4060
4061         # continue on to run this test even if 51b didn't finish,
4062         # just to delete the many subdirectories created.
4063         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4064
4065         # for ldiskfs the nlink count should be 1, but this is OSD specific
4066         # and so this is listed for informational purposes only
4067         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4068         unlinkmany -d $BASE/d $DELETE
4069         RC=$?
4070
4071         if [ $RC -ne 0 ]; then
4072                 if [ "$NUMPREV" == "failed" ]; then
4073                         skip "previous setup failed"
4074                         return 0
4075                 else
4076                         error "unlink of first $DELETE subdirs failed"
4077                         return $RC
4078                 fi
4079         fi
4080
4081         echo "nlink between: $(stat -c %h $BASE)"
4082         # trim the first line of ls output
4083         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4084         [ $FOUND -ne $LEFT ] &&
4085                 error "can't find subdirs: found only $FOUND/$LEFT"
4086
4087         unlinkmany -d $BASE/d $DELETE $LEFT ||
4088                 error "unlink of second $LEFT subdirs failed"
4089         # regardless of whether the backing filesystem tracks nlink accurately
4090         # or not, the nlink count shouldn't be more than "." and ".." here
4091         local AFTER=$(stat -c %h $BASE)
4092         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4093                 echo "nlink after: $AFTER"
4094 }
4095 run_test 51ba "verify nlink for many subdirectory cleanup"
4096
4097 test_51d() {
4098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4099         [[ $OSTCOUNT -lt 3 ]] &&
4100                 skip_env "skipping test with few OSTs" && return
4101         test_mkdir -p $DIR/$tdir
4102         createmany -o $DIR/$tdir/t- 1000
4103         $GETSTRIPE $DIR/$tdir > $TMP/files
4104         for N in $(seq 0 $((OSTCOUNT - 1))); do
4105                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4106                         END { printf("%0.0f", objs) }' $TMP/files)
4107                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4108                         '($1 == '$N') { objs += 1 } \
4109                         END { printf("%0.0f", objs) }')
4110                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4111         done
4112         unlinkmany $DIR/$tdir/t- 1000
4113
4114         NLAST=0
4115         for N in $(seq 1 $((OSTCOUNT - 1))); do
4116                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4117                         error "OST $N has less objects vs OST $NLAST" \
4118                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4119                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4120                         error "OST $N has less objects vs OST $NLAST" \
4121                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4122
4123                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4124                         error "OST $N has less #0 objects vs OST $NLAST" \
4125                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4126                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4127                         error "OST $N has less #0 objects vs OST $NLAST" \
4128                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4129                 NLAST=$N
4130         done
4131 }
4132 run_test 51d "check object distribution ===================="
4133
4134 test_51e() {
4135         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4136                 skip "Only applicable to ldiskfs-based MDTs"
4137                 return
4138         fi
4139
4140         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4141         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4142
4143         touch $DIR/$tdir/d0/foo
4144         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4145                 error "file exceed 65000 nlink limit!"
4146         unlinkmany $DIR/$tdir/d0/f- 65001
4147         return 0
4148 }
4149 run_test 51e "check file nlink limit"
4150
4151 test_52a() {
4152         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4153         test_mkdir -p $DIR/$tdir
4154         touch $DIR/$tdir/foo
4155         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4156         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4157         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4158         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4159         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4160                                         error "link worked"
4161         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4162         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4163         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4164                                                      error "lsattr"
4165         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4166         cp -r $DIR/$tdir /tmp/
4167         rm -fr $DIR/$tdir || error "cleanup rm failed"
4168 }
4169 run_test 52a "append-only flag test (should return errors) ====="
4170
4171 test_52b() {
4172         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4173         test_mkdir -p $DIR/$tdir
4174         touch $DIR/$tdir/foo
4175         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4176         cat test > $DIR/$tdir/foo && error "cat test worked"
4177         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4178         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4179         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4180                                         error "link worked"
4181         echo foo >> $DIR/$tdir/foo && error "echo worked"
4182         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4183         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4184         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4185         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4186                                                         error "lsattr"
4187         chattr -i $DIR/$tdir/foo || error "chattr failed"
4188
4189         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4190 }
4191 run_test 52b "immutable flag test (should return errors) ======="
4192
4193 test_53() {
4194         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4195         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4196         remote_ost_nodsh && skip "remote OST with nodsh" && return
4197
4198         local param
4199         local param_seq
4200         local ostname
4201         local mds_last
4202         local mds_last_seq
4203         local ost_last
4204         local ost_last_seq
4205         local ost_last_id
4206         local ostnum
4207         local node
4208         local found=false
4209         local support_last_seq=true
4210
4211         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4212                 support_last_seq=false
4213
4214         # only test MDT0000
4215         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4216         local value
4217         for value in $(do_facet $SINGLEMDS \
4218                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4219                 param=$(echo ${value[0]} | cut -d "=" -f1)
4220                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4221
4222                 if $support_last_seq; then
4223                         param_seq=$(echo $param |
4224                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4225                         mds_last_seq=$(do_facet $SINGLEMDS \
4226                                        $LCTL get_param -n $param_seq)
4227                 fi
4228                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4229
4230                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4231                 node=$(facet_active_host ost$((ostnum+1)))
4232                 param="obdfilter.$ostname.last_id"
4233                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4234                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4235                         ost_last_id=$ost_last
4236
4237                         if $support_last_seq; then
4238                                 ost_last_id=$(echo $ost_last |
4239                                               awk -F':' '{print $2}' |
4240                                               sed -e "s/^0x//g")
4241                                 ost_last_seq=$(echo $ost_last |
4242                                                awk -F':' '{print $1}')
4243                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4244                         fi
4245
4246                         if [[ $ost_last_id != $mds_last ]]; then
4247                                 error "$ost_last_id != $mds_last"
4248                         else
4249                                 found=true
4250                                 break
4251                         fi
4252                 done
4253         done
4254         $found || error "can not match last_seq/last_id for $mdtosc"
4255         return 0
4256 }
4257 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4258
4259 test_54a() {
4260         $SOCKETSERVER $DIR/socket ||
4261                 error "$SOCKETSERVER $DIR/socket failed: $?"
4262         $SOCKETCLIENT $DIR/socket ||
4263                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4264         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4265 }
4266 run_test 54a "unix domain socket test =========================="
4267
4268 test_54b() {
4269         f="$DIR/f54b"
4270         mknod $f c 1 3
4271         chmod 0666 $f
4272         dd if=/dev/zero of=$f bs=$(page_size) count=1
4273 }
4274 run_test 54b "char device works in lustre ======================"
4275
4276 find_loop_dev() {
4277         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4278         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4279         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4280
4281         for i in $(seq 3 7); do
4282                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4283                 LOOPDEV=$LOOPBASE$i
4284                 LOOPNUM=$i
4285                 break
4286         done
4287 }
4288
4289 cleanup_54c() {
4290         loopdev="$DIR/loop54c"
4291
4292         trap 0
4293         $UMOUNT -d $DIR/$tdir || rc=$?
4294         losetup -d $loopdev || true
4295         losetup -d $LOOPDEV || true
4296         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4297         return $rc
4298 }
4299
4300 test_54c() {
4301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4302         loopdev="$DIR/loop54c"
4303
4304         find_loop_dev
4305         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4306         trap cleanup_54c EXIT
4307         mknod $loopdev b 7 $LOOPNUM
4308         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4309         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4310         losetup $loopdev $DIR/$tfile ||
4311                 error "can't set up $loopdev for $DIR/$tfile"
4312         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4313         test_mkdir -p $DIR/$tdir
4314         mount -t ext2 $loopdev $DIR/$tdir ||
4315                 error "error mounting $loopdev on $DIR/$tdir"
4316         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4317                 error "dd write"
4318         df $DIR/$tdir
4319         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4320                 error "dd read"
4321         cleanup_54c
4322 }
4323 run_test 54c "block device works in lustre ====================="
4324
4325 test_54d() {
4326         f="$DIR/f54d"
4327         string="aaaaaa"
4328         mknod $f p
4329         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4330 }
4331 run_test 54d "fifo device works in lustre ======================"
4332
4333 test_54e() {
4334         f="$DIR/f54e"
4335         string="aaaaaa"
4336         cp -aL /dev/console $f
4337         echo $string > $f || error "echo $string to $f failed"
4338 }
4339 run_test 54e "console/tty device works in lustre ======================"
4340
4341 #The test_55 used to be iopen test and it was removed by bz#24037.
4342 #run_test 55 "check iopen_connect_dentry() ======================"
4343
4344 test_56a() {    # was test_56
4345         rm -rf $DIR/$tdir
4346         $SETSTRIPE -d $DIR
4347         test_mkdir -p $DIR/$tdir/dir
4348         NUMFILES=3
4349         NUMFILESx2=$(($NUMFILES * 2))
4350         for i in $(seq 1 $NUMFILES); do
4351                 touch $DIR/$tdir/file$i
4352                 touch $DIR/$tdir/dir/file$i
4353         done
4354
4355         # test lfs getstripe with --recursive
4356         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4357         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4358                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4359         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4360         [[ $FILENUM -eq $NUMFILES ]] ||
4361                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4362         echo "$GETSTRIPE --recursive passed."
4363
4364         # test lfs getstripe with file instead of dir
4365         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4366         [[ $FILENUM -eq 1 ]] ||
4367                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4368         echo "$GETSTRIPE file1 passed."
4369
4370         #test lfs getstripe with --verbose
4371         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4372                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4373                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4374         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4375                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4376         echo "$GETSTRIPE --verbose passed."
4377
4378         #test lfs getstripe with --obd
4379         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4380                 grep -q "unknown obduuid" ||
4381                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4382
4383         [[ $OSTCOUNT -lt 2 ]] &&
4384                 skip_env "skipping other $GETSTRIPE --obd test" && return
4385
4386         OSTIDX=1
4387         OBDUUID=$(ostuuid_from_index $OSTIDX)
4388         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4389         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4390         [[ $FOUND -eq $FILENUM ]] ||
4391                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4392         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4393                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4394                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4395                 error "$GETSTRIPE --obd: should not show file on other obd"
4396         echo "$GETSTRIPE --obd passed"
4397 }
4398 run_test 56a "check $GETSTRIPE"
4399
4400 NUMFILES=3
4401 NUMDIRS=3
4402 setup_56() {
4403         local LOCAL_NUMFILES="$1"
4404         local LOCAL_NUMDIRS="$2"
4405         local MKDIR_PARAMS="$3"
4406         local DIR_STRIPE_PARAMS="$4"
4407
4408         if [ ! -d "$TDIR" ] ; then
4409                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4410                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4411                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4412                         touch $TDIR/file$i
4413                 done
4414                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4415                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4416                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4417                                 touch $TDIR/dir$i/file$j
4418                         done
4419                 done
4420         fi
4421 }
4422
4423 setup_56_special() {
4424         LOCAL_NUMFILES=$1
4425         LOCAL_NUMDIRS=$2
4426         setup_56 $1 $2
4427         if [ ! -e "$TDIR/loop1b" ] ; then
4428                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4429                         mknod $TDIR/loop${i}b b 7 $i
4430                         mknod $TDIR/null${i}c c 1 3
4431                         ln -s $TDIR/file1 $TDIR/link${i}l
4432                 done
4433                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4434                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4435                         mknod $TDIR/dir$i/null${i}c c 1 3
4436                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4437                 done
4438         fi
4439 }
4440
4441 test_56g() {
4442         $SETSTRIPE -d $DIR
4443
4444         TDIR=$DIR/${tdir}g
4445         setup_56 $NUMFILES $NUMDIRS
4446
4447         EXPECTED=$(($NUMDIRS + 2))
4448         # test lfs find with -name
4449         for i in $(seq 1 $NUMFILES) ; do
4450                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4451                 [ $NUMS -eq $EXPECTED ] ||
4452                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4453                               "found $NUMS, expected $EXPECTED"
4454         done
4455 }
4456 run_test 56g "check lfs find -name ============================="
4457
4458 test_56h() {
4459         $SETSTRIPE -d $DIR
4460
4461         TDIR=$DIR/${tdir}g
4462         setup_56 $NUMFILES $NUMDIRS
4463
4464         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4465         # test lfs find with ! -name
4466         for i in $(seq 1 $NUMFILES) ; do
4467                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4468                 [ $NUMS -eq $EXPECTED ] ||
4469                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4470                               "found $NUMS, expected $EXPECTED"
4471         done
4472 }
4473 run_test 56h "check lfs find ! -name ============================="
4474
4475 test_56i() {
4476        tdir=${tdir}i
4477        test_mkdir -p $DIR/$tdir
4478        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4479        CMD="$LFIND -ost $UUID $DIR/$tdir"
4480        OUT=$($CMD)
4481        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4482 }
4483 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4484
4485 test_56j() {
4486         TDIR=$DIR/${tdir}g
4487         setup_56_special $NUMFILES $NUMDIRS
4488
4489         EXPECTED=$((NUMDIRS + 1))
4490         CMD="$LFIND -type d $TDIR"
4491         NUMS=$($CMD | wc -l)
4492         [ $NUMS -eq $EXPECTED ] ||
4493                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4494 }
4495 run_test 56j "check lfs find -type d ============================="
4496
4497 test_56k() {
4498         TDIR=$DIR/${tdir}g
4499         setup_56_special $NUMFILES $NUMDIRS
4500
4501         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4502         CMD="$LFIND -type f $TDIR"
4503         NUMS=$($CMD | wc -l)
4504         [ $NUMS -eq $EXPECTED ] ||
4505                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4506 }
4507 run_test 56k "check lfs find -type f ============================="
4508
4509 test_56l() {
4510         TDIR=$DIR/${tdir}g
4511         setup_56_special $NUMFILES $NUMDIRS
4512
4513         EXPECTED=$((NUMDIRS + NUMFILES))
4514         CMD="$LFIND -type b $TDIR"
4515         NUMS=$($CMD | wc -l)
4516         [ $NUMS -eq $EXPECTED ] ||
4517                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4518 }
4519 run_test 56l "check lfs find -type b ============================="
4520
4521 test_56m() {
4522         TDIR=$DIR/${tdir}g
4523         setup_56_special $NUMFILES $NUMDIRS
4524
4525         EXPECTED=$((NUMDIRS + NUMFILES))
4526         CMD="$LFIND -type c $TDIR"
4527         NUMS=$($CMD | wc -l)
4528         [ $NUMS -eq $EXPECTED ] ||
4529                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4530 }
4531 run_test 56m "check lfs find -type c ============================="
4532
4533 test_56n() {
4534         TDIR=$DIR/${tdir}g
4535         setup_56_special $NUMFILES $NUMDIRS
4536
4537         EXPECTED=$((NUMDIRS + NUMFILES))
4538         CMD="$LFIND -type l $TDIR"
4539         NUMS=$($CMD | wc -l)
4540         [ $NUMS -eq $EXPECTED ] ||
4541                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4542 }
4543 run_test 56n "check lfs find -type l ============================="
4544
4545 test_56o() {
4546         TDIR=$DIR/${tdir}o
4547         setup_56 $NUMFILES $NUMDIRS
4548         utime $TDIR/file1 > /dev/null || error "utime (1)"
4549         utime $TDIR/file2 > /dev/null || error "utime (2)"
4550         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4551         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4552         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4553         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4554
4555         EXPECTED=4
4556         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4557         [ $NUMS -eq $EXPECTED ] || \
4558                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4559
4560         EXPECTED=12
4561         CMD="$LFIND -mtime 0 $TDIR"
4562         NUMS=$($CMD | wc -l)
4563         [ $NUMS -eq $EXPECTED ] ||
4564                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4565 }
4566 run_test 56o "check lfs find -mtime for old files =========================="
4567
4568 test_56p() {
4569         [ $RUNAS_ID -eq $UID ] &&
4570                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4571
4572         TDIR=$DIR/${tdir}p
4573         setup_56 $NUMFILES $NUMDIRS
4574
4575         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4576         EXPECTED=$NUMFILES
4577         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4578         NUMS=$($CMD | wc -l)
4579         [ $NUMS -eq $EXPECTED ] || \
4580                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4581
4582         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4583         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4584         NUMS=$($CMD | wc -l)
4585         [ $NUMS -eq $EXPECTED ] || \
4586                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4587 }
4588 run_test 56p "check lfs find -uid and ! -uid ==============================="
4589
4590 test_56q() {
4591         [ $RUNAS_ID -eq $UID ] &&
4592                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4593
4594         TDIR=$DIR/${tdir}q
4595         setup_56 $NUMFILES $NUMDIRS
4596
4597         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4598
4599         EXPECTED=$NUMFILES
4600         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4601         NUMS=$($CMD | wc -l)
4602         [ $NUMS -eq $EXPECTED ] ||
4603                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4604
4605         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4606         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4607         NUMS=$($CMD | wc -l)
4608         [ $NUMS -eq $EXPECTED ] ||
4609                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4610 }
4611 run_test 56q "check lfs find -gid and ! -gid ==============================="
4612
4613 test_56r() {
4614         TDIR=$DIR/${tdir}r
4615         setup_56 $NUMFILES $NUMDIRS
4616
4617         EXPECTED=12
4618         CMD="$LFIND -size 0 -type f $TDIR"
4619         NUMS=$($CMD | wc -l)
4620         [ $NUMS -eq $EXPECTED ] ||
4621                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4622         EXPECTED=0
4623         CMD="$LFIND ! -size 0 -type f $TDIR"
4624         NUMS=$($CMD | wc -l)
4625         [ $NUMS -eq $EXPECTED ] ||
4626                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4627         echo "test" > $TDIR/$tfile
4628         echo "test2" > $TDIR/$tfile.2 && sync
4629         EXPECTED=1
4630         CMD="$LFIND -size 5 -type f $TDIR"
4631         NUMS=$($CMD | wc -l)
4632         [ $NUMS -eq $EXPECTED ] ||
4633                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4634         EXPECTED=1
4635         CMD="$LFIND -size +5 -type f $TDIR"
4636         NUMS=$($CMD | wc -l)
4637         [ $NUMS -eq $EXPECTED ] ||
4638                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4639         EXPECTED=2
4640         CMD="$LFIND -size +0 -type f $TDIR"
4641         NUMS=$($CMD | wc -l)
4642         [ $NUMS -eq $EXPECTED ] ||
4643                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4644         EXPECTED=2
4645         CMD="$LFIND ! -size -5 -type f $TDIR"
4646         NUMS=$($CMD | wc -l)
4647         [ $NUMS -eq $EXPECTED ] ||
4648                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4649         EXPECTED=12
4650         CMD="$LFIND -size -5 -type f $TDIR"
4651         NUMS=$($CMD | wc -l)
4652         [ $NUMS -eq $EXPECTED ] ||
4653                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4654 }
4655 run_test 56r "check lfs find -size works =========================="
4656
4657 test_56s() { # LU-611
4658         TDIR=$DIR/${tdir}s
4659         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4660
4661         if [[ $OSTCOUNT -gt 1 ]]; then
4662                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4663                 ONESTRIPE=4
4664                 EXTRA=4
4665         else
4666                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4667                 EXTRA=0
4668         fi
4669
4670         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4671         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4672         NUMS=$($CMD | wc -l)
4673         [ $NUMS -eq $EXPECTED ] || {
4674                 $GETSTRIPE -R $TDIR
4675                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4676         }
4677
4678         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4679         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4680         NUMS=$($CMD | wc -l)
4681         [ $NUMS -eq $EXPECTED ] || {
4682                 $GETSTRIPE -R $TDIR
4683                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4684         }
4685
4686         EXPECTED=$ONESTRIPE
4687         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4688         NUMS=$($CMD | wc -l)
4689         [ $NUMS -eq $EXPECTED ] || {
4690                 $GETSTRIPE -R $TDIR
4691                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4692         }
4693
4694         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4695         NUMS=$($CMD | wc -l)
4696         [ $NUMS -eq $EXPECTED ] || {
4697                 $GETSTRIPE -R $TDIR
4698                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4699         }
4700
4701         EXPECTED=0
4702         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4703         NUMS=$($CMD | wc -l)
4704         [ $NUMS -eq $EXPECTED ] || {
4705                 $GETSTRIPE -R $TDIR
4706                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4707         }
4708 }
4709 run_test 56s "check lfs find -stripe-count works"
4710
4711 test_56t() { # LU-611
4712         TDIR=$DIR/${tdir}t
4713         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4714
4715         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4716
4717         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4718         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4719         NUMS=$($CMD | wc -l)
4720         [ $NUMS -eq $EXPECTED ] ||
4721                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4722
4723         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4724         NUMS=$($CMD | wc -l)
4725         [ $NUMS -eq $EXPECTED ] ||
4726                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4727
4728         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4729         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4730         NUMS=$($CMD | wc -l)
4731         [ $NUMS -eq $EXPECTED ] ||
4732                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4733
4734         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4735         NUMS=$($CMD | wc -l)
4736         [ $NUMS -eq $EXPECTED ] ||
4737                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4738
4739         EXPECTED=4
4740         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4741         NUMS=$($CMD | wc -l)
4742         [ $NUMS -eq $EXPECTED ] ||
4743                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4744
4745         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4746         NUMS=$($CMD | wc -l)
4747         [ $NUMS -eq $EXPECTED ] ||
4748                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4749
4750         EXPECTED=0
4751         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4752         NUMS=$($CMD | wc -l)
4753         [ $NUMS -eq $EXPECTED ] ||
4754                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4755 }
4756 run_test 56t "check lfs find -stripe-size works"
4757
4758 test_56u() { # LU-611
4759         TDIR=$DIR/${tdir}u
4760         setup_56 $NUMFILES $NUMDIRS "-i 0"
4761
4762         if [[ $OSTCOUNT -gt 1 ]]; then
4763                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4764                 ONESTRIPE=4
4765         else
4766                 ONESTRIPE=0
4767         fi
4768
4769         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4770         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4771         NUMS=$($CMD | wc -l)
4772         [ $NUMS -eq $EXPECTED ] ||
4773                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4774
4775         EXPECTED=$ONESTRIPE
4776         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4777         NUMS=$($CMD | wc -l)
4778         [ $NUMS -eq $EXPECTED ] ||
4779                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4780
4781         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4782         NUMS=$($CMD | wc -l)
4783         [ $NUMS -eq $EXPECTED ] ||
4784                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4785
4786         EXPECTED=0
4787         # This should produce an error and not return any files
4788         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4789         NUMS=$($CMD 2>/dev/null | wc -l)
4790         [ $NUMS -eq $EXPECTED ] ||
4791                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4792
4793         if [[ $OSTCOUNT -gt 1 ]]; then
4794                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4795                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4796                 NUMS=$($CMD | wc -l)
4797                 [ $NUMS -eq $EXPECTED ] ||
4798                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4799         fi
4800 }
4801 run_test 56u "check lfs find -stripe-index works"
4802
4803 test_56v() {
4804     local MDT_IDX=0
4805
4806     TDIR=$DIR/${tdir}v
4807     rm -rf $TDIR
4808     setup_56 $NUMFILES $NUMDIRS
4809
4810     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4811     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4812
4813     for file in $($LFIND -mdt $UUID $TDIR); do
4814         file_mdt_idx=$($GETSTRIPE -M $file)
4815         [ $file_mdt_idx -eq $MDT_IDX ] ||
4816             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4817     done
4818 }
4819 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4820
4821 test_56w() {
4822         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4823                 return
4824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4825         TDIR=$DIR/${tdir}w
4826
4827     rm -rf $TDIR || error "remove $TDIR failed"
4828     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4829
4830     local stripe_size
4831     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4832         error "$GETSTRIPE -S -d $TDIR failed"
4833     stripe_size=${stripe_size%% *}
4834
4835     local file_size=$((stripe_size * OSTCOUNT))
4836     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4837     local required_space=$((file_num * file_size))
4838     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4839     [[ $free_space -le $((required_space / 1024)) ]] &&
4840         skip_env "need at least $required_space bytes free space," \
4841                  "have $free_space kbytes" && return
4842
4843     local dd_bs=65536
4844     local dd_count=$((file_size / dd_bs))
4845
4846     # write data into the files
4847     local i
4848     local j
4849     local file
4850     for i in $(seq 1 $NUMFILES); do
4851         file=$TDIR/file$i
4852         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4853             error "write data into $file failed"
4854     done
4855     for i in $(seq 1 $NUMDIRS); do
4856         for j in $(seq 1 $NUMFILES); do
4857             file=$TDIR/dir$i/file$j
4858             yes | dd bs=$dd_bs count=$dd_count of=$file \
4859                 >/dev/null 2>&1 ||
4860                 error "write data into $file failed"
4861         done
4862     done
4863
4864     local expected=-1
4865     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4866
4867     # lfs_migrate file
4868     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4869     echo "$cmd"
4870     eval $cmd || error "$cmd failed"
4871
4872     check_stripe_count $TDIR/file1 $expected
4873
4874         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4875         then
4876                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4877                 # OST 1 if it is on OST 0. This file is small enough to
4878                 # be on only one stripe.
4879                 file=$TDIR/migr_1_ost
4880                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4881                         error "write data into $file failed"
4882                 local obdidx=$($LFS getstripe -i $file)
4883                 local oldmd5=$(md5sum $file)
4884                 local newobdidx=0
4885                 [[ $obdidx -eq 0 ]] && newobdidx=1
4886                 cmd="$LFS migrate -i $newobdidx $file"
4887                 echo $cmd
4888                 eval $cmd || error "$cmd failed"
4889                 local realobdix=$($LFS getstripe -i $file)
4890                 local newmd5=$(md5sum $file)
4891                 [[ $newobdidx -ne $realobdix ]] &&
4892                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4893                 [[ "$oldmd5" != "$newmd5" ]] &&
4894                         error "md5sum differ: $oldmd5, $newmd5"
4895         fi
4896
4897     # lfs_migrate dir
4898     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4899     echo "$cmd"
4900     eval $cmd || error "$cmd failed"
4901
4902     for j in $(seq 1 $NUMFILES); do
4903         check_stripe_count $TDIR/dir1/file$j $expected
4904     done
4905
4906     # lfs_migrate works with lfs find
4907     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4908          $LFS_MIGRATE -y -c $expected"
4909     echo "$cmd"
4910     eval $cmd || error "$cmd failed"
4911
4912     for i in $(seq 2 $NUMFILES); do
4913         check_stripe_count $TDIR/file$i $expected
4914     done
4915     for i in $(seq 2 $NUMDIRS); do
4916         for j in $(seq 1 $NUMFILES); do
4917             check_stripe_count $TDIR/dir$i/file$j $expected
4918         done
4919     done
4920 }
4921 run_test 56w "check lfs_migrate -c stripe_count works"
4922
4923 test_56x() {
4924         check_swap_layouts_support && return 0
4925         [[ $OSTCOUNT -lt 2 ]] &&
4926                 skip_env "need 2 OST, skipping test" && return
4927
4928         local dir0=$DIR/$tdir/$testnum
4929         mkdir -p $dir0 || error "creating dir $dir0"
4930
4931         local ref1=/etc/passwd
4932         local file1=$dir0/file1
4933
4934         $SETSTRIPE -c 2 $file1
4935         cp $ref1 $file1
4936         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4937         stripe=$($GETSTRIPE -c $file1)
4938         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4939         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4940
4941         # clean up
4942         rm -f $file1
4943 }
4944 run_test 56x "lfs migration support"
4945
4946 test_56y() {
4947         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4948                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4949                 return
4950
4951         local res=""
4952         local dir0=$DIR/$tdir/$testnum
4953         mkdir -p $dir0 || error "creating dir $dir0"
4954         local f1=$dir0/file1
4955         local f2=$dir0/file2
4956
4957         touch $f1 || error "creating std file $f1"
4958         $MULTIOP $f2 H2c || error "creating released file $f2"
4959
4960         # a directory can be raid0, so ask only for files
4961         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4962         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4963
4964         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4965         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4966
4967         # only files can be released, so no need to force file search
4968         res=$($LFIND $dir0 -L released)
4969         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4970
4971         res=$($LFIND $dir0 \! -L released)
4972         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4973
4974 }
4975 run_test 56y "lfs find -L raid0|released"
4976
4977 test_56z() { # LU-4824
4978         # This checks to make sure 'lfs find' continues after errors
4979         # There are two classes of errors that should be caught:
4980         # - If multiple paths are provided, all should be searched even if one
4981         #   errors out
4982         # - If errors are encountered during the search, it should not terminate
4983         #   early
4984         local i
4985         test_mkdir $DIR/$tdir
4986         for i in d{0..9}; do
4987                 test_mkdir $DIR/$tdir/$i
4988         done
4989         touch $DIR/$tdir/d{0..9}/$tfile
4990         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4991                 error "$LFS find did not return an error"
4992         # Make a directory unsearchable. This should NOT be the last entry in
4993         # directory order.  Arbitrarily pick the 6th entry
4994         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
4995         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4996         # The user should be able to see 10 directories and 9 files
4997         [ $count == 19 ] || error "$LFS find did not continue after error"
4998 }
4999 run_test 56z "lfs find should continue after an error"
5000
5001 test_56aa() { # LU-5937
5002         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5003
5004         mkdir $DIR/$tdir
5005         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5006
5007         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5008         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5009
5010         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5011 }
5012 run_test 56aa "lfs find --size under striped dir"
5013
5014 test_57a() {
5015         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5016         # note test will not do anything if MDS is not local
5017         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5018                 skip "Only applicable to ldiskfs-based MDTs"
5019                 return
5020         fi
5021
5022         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5023         local MNTDEV="osd*.*MDT*.mntdev"
5024         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5025         [ -z "$DEV" ] && error "can't access $MNTDEV"
5026         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5027                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5028                         error "can't access $DEV"
5029                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5030                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5031                 rm $TMP/t57a.dump
5032         done
5033 }
5034 run_test 57a "verify MDS filesystem created with large inodes =="
5035
5036 test_57b() {
5037         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5038         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5039                 skip "Only applicable to ldiskfs-based MDTs"
5040                 return
5041         fi
5042
5043         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5044         local dir=$DIR/$tdir
5045
5046         local FILECOUNT=100
5047         local FILE1=$dir/f1
5048         local FILEN=$dir/f$FILECOUNT
5049
5050         rm -rf $dir || error "removing $dir"
5051         test_mkdir -p -c1 $dir || error "creating $dir"
5052         local mdtidx=$($LFS getstripe -M $dir)
5053         local mdtname=MDT$(printf %04x $mdtidx)
5054         local facet=mds$((mdtidx + 1))
5055
5056         echo "mcreating $FILECOUNT files"
5057         createmany -m $dir/f 1 $FILECOUNT || \
5058                 error "creating files in $dir"
5059
5060         # verify that files do not have EAs yet
5061         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5062         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5063
5064         sync
5065         sleep 1
5066         df $dir  #make sure we get new statfs data
5067         local MDSFREE=$(do_facet $facet \
5068                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5069         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5070         echo "opening files to create objects/EAs"
5071         local FILE
5072         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5073                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5074         done
5075
5076         # verify that files have EAs now
5077         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5078         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5079
5080         sleep 1  #make sure we get new statfs data
5081         df $dir
5082         local MDSFREE2=$(do_facet $facet \
5083                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5084         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5085         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5086                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5087                         error "MDC before $MDCFREE != after $MDCFREE2"
5088                 else
5089                         echo "MDC before $MDCFREE != after $MDCFREE2"
5090                         echo "unable to confirm if MDS has large inodes"
5091                 fi
5092         fi
5093         rm -rf $dir
5094 }
5095 run_test 57b "default LOV EAs are stored inside large inodes ==="
5096
5097 test_58() {
5098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5099         [ -z "$(which wiretest 2>/dev/null)" ] &&
5100                         skip_env "could not find wiretest" && return
5101         wiretest
5102 }
5103 run_test 58 "verify cross-platform wire constants =============="
5104
5105 test_59() {
5106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5107         echo "touch 130 files"
5108         createmany -o $DIR/f59- 130
5109         echo "rm 130 files"
5110         unlinkmany $DIR/f59- 130
5111         sync
5112         # wait for commitment of removal
5113         wait_delete_completed
5114 }
5115 run_test 59 "verify cancellation of llog records async ========="
5116
5117 TEST60_HEAD="test_60 run $RANDOM"
5118 test_60a() {
5119         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5120         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5121         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5122                 skip_env "missing subtest run-llog.sh" && return
5123         log "$TEST60_HEAD - from kernel mode"
5124         do_facet mgs sh run-llog.sh
5125 }
5126 run_test 60a "llog sanity tests run from kernel module =========="
5127
5128 test_60b() { # bug 6411
5129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5130         dmesg > $DIR/$tfile
5131         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5132                                  /llog.test/ {
5133                                          if (marker)
5134                                                  from_marker++
5135                                          from_begin++
5136                                  }
5137                                  END {
5138                                          if (marker)
5139                                                  print from_marker
5140                                          else
5141                                                  print from_begin
5142                                  }"`
5143         [[ $LLOG_COUNT -gt 50 ]] &&
5144                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5145 }
5146 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5147
5148 test_60c() {
5149         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5150         echo "create 5000 files"
5151         createmany -o $DIR/f60c- 5000
5152 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5153         lctl set_param fail_loc=0x80000137
5154         unlinkmany $DIR/f60c- 5000
5155         lctl set_param fail_loc=0
5156 }
5157 run_test 60c "unlink file when mds full"
5158
5159 test_60d() {
5160         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5161         SAVEPRINTK=$(lctl get_param -n printk)
5162
5163         # verify "lctl mark" is even working"
5164         MESSAGE="test message ID $RANDOM $$"
5165         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5166         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5167
5168         lctl set_param printk=0 || error "set lnet.printk failed"
5169         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5170         MESSAGE="new test message ID $RANDOM $$"
5171         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5172         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5173         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5174
5175         lctl set_param -n printk="$SAVEPRINTK"
5176 }
5177 run_test 60d "test printk console message masking"
5178
5179 test_61() {
5180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5181         f="$DIR/f61"
5182         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5183         cancel_lru_locks osc
5184         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5185         sync
5186 }
5187 run_test 61 "mmap() writes don't make sync hang ================"
5188
5189 # bug 2330 - insufficient obd_match error checking causes LBUG
5190 test_62() {
5191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5192         f="$DIR/f62"
5193         echo foo > $f
5194         cancel_lru_locks osc
5195         lctl set_param fail_loc=0x405
5196         cat $f && error "cat succeeded, expect -EIO"
5197         lctl set_param fail_loc=0
5198 }
5199 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5200 # match every page all of the time.
5201 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5202
5203 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5204 # Though this test is irrelevant anymore, it helped to reveal some
5205 # other grant bugs (LU-4482), let's keep it.
5206 test_63a() {   # was test_63
5207         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5208         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5209         for i in `seq 10` ; do
5210                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5211                 sleep 5
5212                 kill $!
5213                 sleep 1
5214         done
5215
5216         rm -f $DIR/f63 || true
5217 }
5218 run_test 63a "Verify oig_wait interruption does not crash ======="
5219
5220 # bug 2248 - async write errors didn't return to application on sync
5221 # bug 3677 - async write errors left page locked
5222 test_63b() {
5223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5224         debugsave
5225         lctl set_param debug=-1
5226
5227         # ensure we have a grant to do async writes
5228         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5229         rm $DIR/$tfile
5230
5231         sync    # sync lest earlier test intercept the fail_loc
5232
5233         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5234         lctl set_param fail_loc=0x80000406
5235         $MULTIOP $DIR/$tfile Owy && \
5236                 error "sync didn't return ENOMEM"
5237         sync; sleep 2; sync     # do a real sync this time to flush page
5238         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5239                 error "locked page left in cache after async error" || true
5240         debugrestore
5241 }
5242 run_test 63b "async write errors should be returned to fsync ==="
5243
5244 test_64a () {
5245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5246         df $DIR
5247         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5248 }
5249 run_test 64a "verify filter grant calculations (in kernel) ====="
5250
5251 test_64b () {
5252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5253         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5254 }
5255 run_test 64b "check out-of-space detection on client ==========="
5256
5257 test_64c() {
5258         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5259 }
5260 run_test 64c "verify grant shrink ========================------"
5261
5262 # bug 1414 - set/get directories' stripe info
5263 test_65a() {
5264         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5265         test_mkdir -p $DIR/$tdir
5266         touch $DIR/$tdir/f1
5267         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5268 }
5269 run_test 65a "directory with no stripe info ===================="
5270
5271 test_65b() {
5272         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5273         test_mkdir -p $DIR/$tdir
5274         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5275                                                 error "setstripe"
5276         touch $DIR/$tdir/f2
5277         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5278 }
5279 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5280
5281 test_65c() {
5282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5283         if [[ $OSTCOUNT -gt 1 ]]; then
5284                 test_mkdir -p $DIR/$tdir
5285                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5286                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5287                 touch $DIR/$tdir/f3
5288                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5289         fi
5290 }
5291 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5292
5293 test_65d() {
5294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5295         test_mkdir -p $DIR/$tdir
5296         if [[ $STRIPECOUNT -le 0 ]]; then
5297                 sc=1
5298         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5299 #LOV_MAX_STRIPE_COUNT is 2000
5300                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5301         else
5302                 sc=$(($STRIPECOUNT - 1))
5303         fi
5304         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5305         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5306         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5307                 error "lverify failed"
5308 }
5309 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5310
5311 test_65e() {
5312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5313         test_mkdir -p $DIR/$tdir
5314
5315         $SETSTRIPE $DIR/$tdir || error "setstripe"
5316         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5317                                         error "no stripe info failed"
5318         touch $DIR/$tdir/f6
5319         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5320 }
5321 run_test 65e "directory setstripe defaults ======================="
5322
5323 test_65f() {
5324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5325         test_mkdir -p $DIR/${tdir}f
5326         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5327 }
5328 run_test 65f "dir setstripe permission (should return error) ==="
5329
5330 test_65g() {
5331         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5332         test_mkdir -p $DIR/$tdir
5333         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5334                                                         error "setstripe"
5335         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5336         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5337                 error "delete default stripe failed"
5338 }
5339 run_test 65g "directory setstripe -d ==========================="
5340
5341 test_65h() {
5342         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5343         test_mkdir -p $DIR/$tdir
5344         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5345                                                         error "setstripe"
5346         test_mkdir -p $DIR/$tdir/dd1
5347         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5348                 error "stripe info inherit failed"
5349 }
5350 run_test 65h "directory stripe info inherit ===================="
5351
5352 test_65i() { # bug6367
5353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5354         $SETSTRIPE -S 65536 -c -1 $MOUNT
5355 }
5356 run_test 65i "set non-default striping on root directory (bug 6367)="
5357
5358 test_65ia() { # bug12836
5359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5360         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5361 }
5362 run_test 65ia "getstripe on -1 default directory striping"
5363
5364 test_65ib() { # bug12836
5365         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5366         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5367 }
5368 run_test 65ib "getstripe -v on -1 default directory striping"
5369
5370 test_65ic() { # bug12836
5371         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5372         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5373 }
5374 run_test 65ic "new find on -1 default directory striping"
5375
5376 test_65j() { # bug6367
5377         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5378         sync; sleep 1
5379         # if we aren't already remounting for each test, do so for this test
5380         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5381                 cleanup || error "failed to unmount"
5382                 setup
5383         fi
5384         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5385 }
5386 run_test 65j "set default striping on root directory (bug 6367)="
5387
5388 test_65k() { # bug11679
5389         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5390         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5391         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5392
5393     echo "Check OST status: "
5394     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5395               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5396
5397     for OSC in $MDS_OSCS; do
5398         echo $OSC "is activate"
5399         do_facet $SINGLEMDS lctl --device %$OSC activate
5400     done
5401
5402     mkdir -p $DIR/$tdir
5403     for INACTIVE_OSC in $MDS_OSCS; do
5404         echo "Deactivate: " $INACTIVE_OSC
5405         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5406         for STRIPE_OSC in $MDS_OSCS; do
5407             OST=`osc_to_ost $STRIPE_OSC`
5408             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5409                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5410
5411             [ -f $DIR/$tdir/$IDX ] && continue
5412             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5413             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5414             RC=$?
5415             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5416         done
5417         rm -f $DIR/$tdir/*
5418         echo $INACTIVE_OSC "is Activate."
5419         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5420     done
5421 }
5422 run_test 65k "validate manual striping works properly with deactivated OSCs"
5423
5424 test_65l() { # bug 12836
5425         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5426         test_mkdir -p $DIR/$tdir/test_dir
5427         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5428         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5429 }
5430 run_test 65l "lfs find on -1 stripe dir ========================"
5431
5432 # bug 2543 - update blocks count on client
5433 test_66() {
5434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5435         COUNT=${COUNT:-8}
5436         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5437         sync; sync_all_data; sync; sync_all_data
5438         cancel_lru_locks osc
5439         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5440         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5441 }
5442 run_test 66 "update inode blocks count on client ==============="
5443
5444 LLOOP=
5445 LLITELOOPLOAD=
5446 cleanup_68() {
5447         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5448         trap 0
5449         if [ ! -z "$LLOOP" ]; then
5450                 if swapon -s | grep -q $LLOOP; then
5451                         swapoff $LLOOP || error "swapoff failed"
5452                 fi
5453
5454                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5455                 rm -f $LLOOP
5456                 unset LLOOP
5457         fi
5458         if [ ! -z "$LLITELOOPLOAD" ]; then
5459                 rmmod llite_lloop
5460                 unset LLITELOOPLOAD
5461         fi
5462         rm -f $DIR/f68*
5463 }
5464
5465 meminfo() {
5466         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5467 }
5468
5469 swap_used() {
5470         swapon -s | awk '($1 == "'$1'") { print $4 }'
5471 }
5472
5473 # test case for lloop driver, basic function
5474 test_68a() {
5475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5476         [ "$UID" != 0 ] && skip_env "must run as root" && return
5477         llite_lloop_enabled || \
5478                 { skip_env "llite_lloop module disabled" && return; }
5479
5480         trap cleanup_68 EXIT
5481
5482         if ! module_loaded llite_lloop; then
5483                 if load_module llite/llite_lloop; then
5484                         LLITELOOPLOAD=yes
5485                 else
5486                         skip_env "can't find module llite_lloop"
5487                         return
5488                 fi
5489         fi
5490
5491         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5492         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5493         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5494
5495         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5496         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5497
5498         cleanup_68
5499 }
5500 run_test 68a "lloop driver - basic test ========================"
5501
5502 # excercise swapping to lustre by adding a high priority swapfile entry
5503 # and then consuming memory until it is used.
5504 test_68b() {  # was test_68
5505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5506         [ "$UID" != 0 ] && skip_env "must run as root" && return
5507         lctl get_param -n devices | grep -q obdfilter && \
5508                 skip "local OST" && return
5509
5510         grep -q llite_lloop /proc/modules
5511         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5512
5513         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5514                 skip "can't reliably test swap with TCP" && return
5515
5516         MEMTOTAL=`meminfo MemTotal`
5517         NR_BLOCKS=$((MEMTOTAL>>8))
5518         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5519
5520         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5521         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5522         mkswap $DIR/f68b
5523
5524         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5525
5526         trap cleanup_68 EXIT
5527
5528         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5529
5530         echo "before: `swapon -s | grep $LLOOP`"
5531         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5532         echo "after: `swapon -s | grep $LLOOP`"
5533         SWAPUSED=`swap_used $LLOOP`
5534
5535         cleanup_68
5536
5537         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5538 }
5539 run_test 68b "support swapping to Lustre ========================"
5540
5541 # bug5265, obdfilter oa2dentry return -ENOENT
5542 # #define OBD_FAIL_OST_ENOENT 0x217
5543 test_69() {
5544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5545         remote_ost_nodsh && skip "remote OST with nodsh" && return
5546
5547         f="$DIR/$tfile"
5548         $SETSTRIPE -c 1 -i 0 $f
5549
5550         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5551
5552         do_facet ost1 lctl set_param fail_loc=0x217
5553         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5554         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5555
5556         do_facet ost1 lctl set_param fail_loc=0
5557         $DIRECTIO write $f 0 2 || error "write error"
5558
5559         cancel_lru_locks osc
5560         $DIRECTIO read $f 0 1 || error "read error"
5561
5562         do_facet ost1 lctl set_param fail_loc=0x217
5563         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5564
5565         do_facet ost1 lctl set_param fail_loc=0
5566         rm -f $f
5567 }
5568 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5569
5570 test_71() {
5571     test_mkdir -p $DIR/$tdir
5572     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5573 }
5574 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5575
5576 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5578         [ "$RUNAS_ID" = "$UID" ] &&
5579                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5580
5581         # Check that testing environment is properly set up. Skip if not
5582         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5583                 skip_env "User $RUNAS_ID does not exist - skipping"
5584                 return 0
5585         }
5586         touch $DIR/$tfile
5587         chmod 777 $DIR/$tfile
5588         chmod ug+s $DIR/$tfile
5589         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5590                 error "$RUNAS dd $DIR/$tfile failed"
5591         # See if we are still setuid/sgid
5592         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5593                 error "S/gid is not dropped on write"
5594         # Now test that MDS is updated too
5595         cancel_lru_locks mdc
5596         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5597                 error "S/gid is not dropped on MDS"
5598         rm -f $DIR/$tfile
5599 }
5600 run_test 72a "Test that remove suid works properly (bug5695) ===="
5601
5602 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5603         local perm
5604
5605         [ "$RUNAS_ID" = "$UID" ] && \
5606                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5607         [ "$RUNAS_ID" -eq 0 ] && \
5608                 skip_env "RUNAS_ID = 0 -- skipping" && return
5609
5610         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5611         # Check that testing environment is properly set up. Skip if not
5612         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5613                 skip_env "User $RUNAS_ID does not exist - skipping"
5614                 return 0
5615         }
5616         touch $DIR/${tfile}-f{g,u}
5617         test_mkdir $DIR/${tfile}-dg
5618         test_mkdir $DIR/${tfile}-du
5619         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5620         chmod g+s $DIR/${tfile}-{f,d}g
5621         chmod u+s $DIR/${tfile}-{f,d}u
5622         for perm in 777 2777 4777; do
5623                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5624                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5625                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5626                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5627         done
5628         true
5629 }
5630 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5631
5632 # bug 3462 - multiple simultaneous MDC requests
5633 test_73() {
5634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5635         test_mkdir $DIR/d73-1
5636         test_mkdir $DIR/d73-2
5637         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5638         pid1=$!
5639
5640         lctl set_param fail_loc=0x80000129
5641         $MULTIOP $DIR/d73-1/f73-2 Oc &
5642         sleep 1
5643         lctl set_param fail_loc=0
5644
5645         $MULTIOP $DIR/d73-2/f73-3 Oc &
5646         pid3=$!
5647
5648         kill -USR1 $pid1
5649         wait $pid1 || return 1
5650
5651         sleep 25
5652
5653         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5654         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5655         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5656
5657         rm -rf $DIR/d73-*
5658 }
5659 run_test 73 "multiple MDC requests (should not deadlock)"
5660
5661 test_74a() { # bug 6149, 6184
5662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5663         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5664         #
5665         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5666         # will spin in a tight reconnection loop
5667         touch $DIR/f74a
5668         $LCTL set_param fail_loc=0x8000030e
5669         # get any lock that won't be difficult - lookup works.
5670         ls $DIR/f74a
5671         $LCTL set_param fail_loc=0
5672         rm -f $DIR/f74a
5673         true
5674 }
5675 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5676
5677 test_74b() { # bug 13310
5678         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5679         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5680         #
5681         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5682         # will spin in a tight reconnection loop
5683         $LCTL set_param fail_loc=0x8000030e
5684         # get a "difficult" lock
5685         touch $DIR/f74b
5686         $LCTL set_param fail_loc=0
5687         rm -f $DIR/f74b
5688         true
5689 }
5690 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5691
5692 test_74c() {
5693         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5694         #define OBD_FAIL_LDLM_NEW_LOCK
5695         $LCTL set_param fail_loc=0x319
5696         touch $DIR/$tfile && error "touch successful"
5697         $LCTL set_param fail_loc=0
5698         true
5699 }
5700 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5701
5702 num_inodes() {
5703         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5704 }
5705
5706 get_inode_slab_tunables() {
5707         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5708 }
5709
5710 set_inode_slab_tunables() {
5711         echo "lustre_inode_cache $1" > /proc/slabinfo
5712 }
5713
5714 test_76() { # Now for bug 20433, added originally in bug 1443
5715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5716         local SLAB_SETTINGS=`get_inode_slab_tunables`
5717         local CPUS=`getconf _NPROCESSORS_ONLN`
5718         # we cannot set limit below 1 which means 1 inode in each
5719         # per-cpu cache is still allowed
5720         set_inode_slab_tunables "1 1 0"
5721         cancel_lru_locks osc
5722         BEFORE_INODES=$(num_inodes)
5723         echo "before inodes: $BEFORE_INODES"
5724         local COUNT=1000
5725         [ "$SLOW" = "no" ] && COUNT=100
5726         for i in $(seq $COUNT); do
5727                 touch $DIR/$tfile
5728                 rm -f $DIR/$tfile
5729         done
5730         cancel_lru_locks osc
5731         AFTER_INODES=$(num_inodes)
5732         echo "after inodes: $AFTER_INODES"
5733         local wait=0
5734         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5735                 sleep 2
5736                 AFTER_INODES=$(num_inodes)
5737                 wait=$((wait+2))
5738                 echo "wait $wait seconds inodes: $AFTER_INODES"
5739                 if [ $wait -gt 30 ]; then
5740                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5741                 fi
5742         done
5743         set_inode_slab_tunables "$SLAB_SETTINGS"
5744 }
5745 run_test 76 "confirm clients recycle inodes properly ===="
5746
5747
5748 export ORIG_CSUM=""
5749 set_checksums()
5750 {
5751         # Note: in sptlrpc modes which enable its own bulk checksum, the
5752         # original crc32_le bulk checksum will be automatically disabled,
5753         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5754         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5755         # In this case set_checksums() will not be no-op, because sptlrpc
5756         # bulk checksum will be enabled all through the test.
5757
5758         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5759         lctl set_param -n osc.*.checksums $1
5760         return 0
5761 }
5762
5763 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5764                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5765 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5766 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5767 set_checksum_type()
5768 {
5769         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5770         log "set checksum type to $1"
5771         return 0
5772 }
5773 F77_TMP=$TMP/f77-temp
5774 F77SZ=8
5775 setup_f77() {
5776         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5777                 error "error writing to $F77_TMP"
5778 }
5779
5780 test_77a() { # bug 10889
5781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5782         $GSS && skip "could not run with gss" && return
5783         [ ! -f $F77_TMP ] && setup_f77
5784         set_checksums 1
5785         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5786         set_checksums 0
5787         rm -f $DIR/$tfile
5788 }
5789 run_test 77a "normal checksum read/write operation"
5790
5791 test_77b() { # bug 10889
5792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5793         $GSS && skip "could not run with gss" && return
5794         [ ! -f $F77_TMP ] && setup_f77
5795         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5796         $LCTL set_param fail_loc=0x80000409
5797         set_checksums 1
5798
5799         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5800                 error "dd error: $?"
5801         $LCTL set_param fail_loc=0
5802
5803         for algo in $CKSUM_TYPES; do
5804                 cancel_lru_locks osc
5805                 set_checksum_type $algo
5806                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5807                 $LCTL set_param fail_loc=0x80000408
5808                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5809                 $LCTL set_param fail_loc=0
5810         done
5811         set_checksums 0
5812         set_checksum_type $ORIG_CSUM_TYPE
5813         rm -f $DIR/$tfile
5814 }
5815 run_test 77b "checksum error on client write, read"
5816
5817 test_77d() { # bug 10889
5818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5819         $GSS && skip "could not run with gss" && return
5820         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5821         $LCTL set_param fail_loc=0x80000409
5822         set_checksums 1
5823         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5824                 error "direct write: rc=$?"
5825         $LCTL set_param fail_loc=0
5826         set_checksums 0
5827
5828         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5829         $LCTL set_param fail_loc=0x80000408
5830         set_checksums 1
5831         cancel_lru_locks osc
5832         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5833                 error "direct read: rc=$?"
5834         $LCTL set_param fail_loc=0
5835         set_checksums 0
5836 }
5837 run_test 77d "checksum error on OST direct write, read"
5838
5839 test_77f() { # bug 10889
5840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5841         $GSS && skip "could not run with gss" && return
5842         set_checksums 1
5843         for algo in $CKSUM_TYPES; do
5844                 cancel_lru_locks osc
5845                 set_checksum_type $algo
5846                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5847                 $LCTL set_param fail_loc=0x409
5848                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5849                         error "direct write succeeded"
5850                 $LCTL set_param fail_loc=0
5851         done
5852         set_checksum_type $ORIG_CSUM_TYPE
5853         set_checksums 0
5854 }
5855 run_test 77f "repeat checksum error on write (expect error)"
5856
5857 test_77g() { # bug 10889
5858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5859         $GSS && skip "could not run with gss" && return
5860         remote_ost_nodsh && skip "remote OST with nodsh" && return
5861
5862         [ ! -f $F77_TMP ] && setup_f77
5863
5864         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5865         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5866         do_facet ost1 lctl set_param fail_loc=0x8000021a
5867         set_checksums 1
5868         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5869                 error "write error: rc=$?"
5870         do_facet ost1 lctl set_param fail_loc=0
5871         set_checksums 0
5872
5873         cancel_lru_locks osc
5874         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5875         do_facet ost1 lctl set_param fail_loc=0x8000021b
5876         set_checksums 1
5877         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5878         do_facet ost1 lctl set_param fail_loc=0
5879         set_checksums 0
5880 }
5881 run_test 77g "checksum error on OST write, read"
5882
5883 test_77i() { # bug 13805
5884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5885         $GSS && skip "could not run with gss" && return
5886         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5887         lctl set_param fail_loc=0x40b
5888         remount_client $MOUNT
5889         lctl set_param fail_loc=0
5890         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5891                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5892                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5893                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5894         done
5895         remount_client $MOUNT
5896 }
5897 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5898
5899 test_77j() { # bug 13805
5900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5901         $GSS && skip "could not run with gss" && return
5902         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5903         lctl set_param fail_loc=0x40c
5904         remount_client $MOUNT
5905         lctl set_param fail_loc=0
5906         sleep 2 # wait async osc connect to finish
5907         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5908                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5909                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5910                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5911         done
5912         remount_client $MOUNT
5913 }
5914 run_test 77j "client only supporting ADLER32"
5915
5916 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5917 rm -f $F77_TMP
5918 unset F77_TMP
5919
5920 test_78() { # bug 10901
5921         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5922         remote_ost || { skip_env "local OST" && return; }
5923
5924         NSEQ=5
5925         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5926         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5927         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5928         echo "MemTotal: $MEMTOTAL"
5929
5930         # reserve 256MB of memory for the kernel and other running processes,
5931         # and then take 1/2 of the remaining memory for the read/write buffers.
5932         if [ $MEMTOTAL -gt 512 ] ;then
5933                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5934         else
5935                 # for those poor memory-starved high-end clusters...
5936                 MEMTOTAL=$((MEMTOTAL / 2))
5937         fi
5938         echo "Mem to use for directio: $MEMTOTAL"
5939
5940         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5941         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5942         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5943         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5944                 head -n1)
5945         echo "Smallest OST: $SMALLESTOST"
5946         [[ $SMALLESTOST -lt 10240 ]] &&
5947                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5948
5949         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5950                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5951
5952         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5953         echo "File size: $F78SIZE"
5954         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5955         for i in $(seq 1 $NSEQ); do
5956                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5957                 echo directIO rdwr round $i of $NSEQ
5958                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5959         done
5960
5961         rm -f $DIR/$tfile
5962 }
5963 run_test 78 "handle large O_DIRECT writes correctly ============"
5964
5965 test_79() { # bug 12743
5966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5967         wait_delete_completed
5968
5969         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5970         BKFREE=$(calc_osc_kbytes kbytesfree)
5971         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5972
5973         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5974         DFTOTAL=`echo $STRING | cut -d, -f1`
5975         DFUSED=`echo $STRING  | cut -d, -f2`
5976         DFAVAIL=`echo $STRING | cut -d, -f3`
5977         DFFREE=$(($DFTOTAL - $DFUSED))
5978
5979         ALLOWANCE=$((64 * $OSTCOUNT))
5980
5981         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5982            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5983                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5984         fi
5985         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5986            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5987                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5988         fi
5989         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5990            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5991                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5992         fi
5993 }
5994 run_test 79 "df report consistency check ======================="
5995
5996 test_80() { # bug 10718
5997         remote_ost_nodsh && skip "remote OST with nodsh" && return
5998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5999         # relax strong synchronous semantics for slow backends like ZFS
6000         local soc="obdfilter.*.sync_on_lock_cancel"
6001         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6002         local hosts=
6003         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6004                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6005                           facet_active_host $host; done | sort -u)
6006                 do_nodes $hosts lctl set_param $soc=never
6007         fi
6008
6009         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6010         sync; sleep 1; sync
6011         local BEFORE=`date +%s`
6012         cancel_lru_locks osc
6013         local AFTER=`date +%s`
6014         local DIFF=$((AFTER-BEFORE))
6015         if [ $DIFF -gt 1 ] ; then
6016                 error "elapsed for 1M@1T = $DIFF"
6017         fi
6018
6019         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6020
6021         rm -f $DIR/$tfile
6022 }
6023 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6024
6025 test_81a() { # LU-456
6026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6027         remote_ost_nodsh && skip "remote OST with nodsh" && return
6028         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6029         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6030         do_facet ost1 lctl set_param fail_loc=0x80000228
6031
6032         # write should trigger a retry and success
6033         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6034         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6035         RC=$?
6036         if [ $RC -ne 0 ] ; then
6037                 error "write should success, but failed for $RC"
6038         fi
6039 }
6040 run_test 81a "OST should retry write when get -ENOSPC ==============="
6041
6042 test_81b() { # LU-456
6043         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6044         remote_ost_nodsh && skip "remote OST with nodsh" && return
6045         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6046         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6047         do_facet ost1 lctl set_param fail_loc=0x228
6048
6049         # write should retry several times and return -ENOSPC finally
6050         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6051         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6052         RC=$?
6053         ENOSPC=28
6054         if [ $RC -ne $ENOSPC ] ; then
6055                 error "dd should fail for -ENOSPC, but succeed."
6056         fi
6057 }
6058 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6059
6060 test_82() { # LU-1031
6061         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6062         local gid1=14091995
6063         local gid2=16022000
6064
6065         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6066         local MULTIPID1=$!
6067         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6068         local MULTIPID2=$!
6069         kill -USR1 $MULTIPID2
6070         sleep 2
6071         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6072                 error "First grouplock does not block second one"
6073         else
6074                 echo "Second grouplock blocks first one"
6075         fi
6076         kill -USR1 $MULTIPID1
6077         wait $MULTIPID1
6078         wait $MULTIPID2
6079 }
6080 run_test 82 "Basic grouplock test ==============================="
6081
6082 test_99a() {
6083         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6084                 return
6085         test_mkdir -p $DIR/d99cvsroot
6086         chown $RUNAS_ID $DIR/d99cvsroot
6087         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6088         cd $TMP
6089
6090         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6091         cd $oldPWD
6092 }
6093 run_test 99a "cvs init ========================================="
6094
6095 test_99b() {
6096         [ -z "$(which cvs 2>/dev/null)" ] &&
6097                 skip_env "could not find cvs" && return
6098         [ ! -d $DIR/d99cvsroot ] && test_99a
6099         cd /etc/init.d
6100         # some versions of cvs import exit(1) when asked to import links or
6101         # files they can't read.  ignore those files.
6102         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6103                         ! -perm +4 -printf '-I %f\n')
6104         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6105                 d99reposname vtag rtag
6106 }
6107 run_test 99b "cvs import ======================================="
6108
6109 test_99c() {
6110         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6111         [ ! -d $DIR/d99cvsroot ] && test_99b
6112         cd $DIR
6113         test_mkdir -p $DIR/d99reposname
6114         chown $RUNAS_ID $DIR/d99reposname
6115         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6116 }
6117 run_test 99c "cvs checkout ====================================="
6118
6119 test_99d() {
6120         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6121         [ ! -d $DIR/d99cvsroot ] && test_99c
6122         cd $DIR/d99reposname
6123         $RUNAS touch foo99
6124         $RUNAS cvs add -m 'addmsg' foo99
6125 }
6126 run_test 99d "cvs add =========================================="
6127
6128 test_99e() {
6129         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6130         [ ! -d $DIR/d99cvsroot ] && test_99c
6131         cd $DIR/d99reposname
6132         $RUNAS cvs update
6133 }
6134 run_test 99e "cvs update ======================================="
6135
6136 test_99f() {
6137         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6138         [ ! -d $DIR/d99cvsroot ] && test_99d
6139         cd $DIR/d99reposname
6140         $RUNAS cvs commit -m 'nomsg' foo99
6141     rm -fr $DIR/d99cvsroot
6142 }
6143 run_test 99f "cvs commit ======================================="
6144
6145 test_100() {
6146         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6147         [ "$NETTYPE" = tcp ] || \
6148                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6149                         return ; }
6150
6151         remote_ost_nodsh && skip "remote OST with nodsh" && return
6152         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6153         remote_servers || \
6154                 { skip "useless for local single node setup" && return; }
6155
6156         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6157                 [ "$PROT" != "tcp" ] && continue
6158                 RPORT=$(echo $REMOTE | cut -d: -f2)
6159                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6160
6161                 rc=0
6162                 LPORT=`echo $LOCAL | cut -d: -f2`
6163                 if [ $LPORT -ge 1024 ]; then
6164                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6165                         netstat -tna
6166                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6167                 fi
6168         done
6169         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6170 }
6171 run_test 100 "check local port using privileged port ==========="
6172
6173 function get_named_value()
6174 {
6175     local tag
6176
6177     tag=$1
6178     while read ;do
6179         line=$REPLY
6180         case $line in
6181         $tag*)
6182             echo $line | sed "s/^$tag[ ]*//"
6183             break
6184             ;;
6185         esac
6186     done
6187 }
6188
6189 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6190                    awk '/^max_cached_mb/ { print $2 }')
6191
6192 cleanup_101a() {
6193         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6194         trap 0
6195 }
6196
6197 test_101a() {
6198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6199         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6200         local s
6201         local discard
6202         local nreads=10000
6203         local cache_limit=32
6204
6205         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6206         trap cleanup_101a EXIT
6207         $LCTL set_param -n llite.*.read_ahead_stats 0
6208         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6209
6210         #
6211         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6212         #
6213         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6214         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6215
6216         discard=0
6217         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6218                 get_named_value 'read but discarded' | cut -d" " -f1); do
6219                         discard=$(($discard + $s))
6220         done
6221         cleanup_101a
6222
6223         if [[ $(($discard * 10)) -gt $nreads ]]; then
6224                 $LCTL get_param osc.*-osc*.rpc_stats
6225                 $LCTL get_param llite.*.read_ahead_stats
6226                 error "too many ($discard) discarded pages"
6227         fi
6228         rm -f $DIR/$tfile || true
6229 }
6230 run_test 101a "check read-ahead for random reads ================"
6231
6232 setup_test101bc() {
6233         test_mkdir -p $DIR/$tdir
6234         local STRIPE_SIZE=$1
6235         local FILE_LENGTH=$2
6236         STRIPE_OFFSET=0
6237
6238         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6239
6240         local list=$(comma_list $(osts_nodes))
6241         set_osd_param $list '' read_cache_enable 0
6242         set_osd_param $list '' writethrough_cache_enable 0
6243
6244         trap cleanup_test101bc EXIT
6245         # prepare the read-ahead file
6246         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6247
6248         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6249                                 count=$FILE_SIZE_MB 2> /dev/null
6250
6251 }
6252
6253 cleanup_test101bc() {
6254         trap 0
6255         rm -rf $DIR/$tdir
6256         rm -f $DIR/$tfile
6257
6258         local list=$(comma_list $(osts_nodes))
6259         set_osd_param $list '' read_cache_enable 1
6260         set_osd_param $list '' writethrough_cache_enable 1
6261 }
6262
6263 calc_total() {
6264         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6265 }
6266
6267 ra_check_101() {
6268         local READ_SIZE=$1
6269         local STRIPE_SIZE=$2
6270         local FILE_LENGTH=$3
6271         local RA_INC=1048576
6272         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6273         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6274                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6275         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6276                         get_named_value 'read but discarded' |
6277                         cut -d" " -f1 | calc_total)
6278         if [[ $DISCARD -gt $discard_limit ]]; then
6279                 $LCTL get_param llite.*.read_ahead_stats
6280                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6281         else
6282                 echo "Read-ahead success for size ${READ_SIZE}"
6283         fi
6284 }
6285
6286 test_101b() {
6287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6288         [[ $OSTCOUNT -lt 2 ]] &&
6289                 skip_env "skipping stride IO stride-ahead test" && return
6290         local STRIPE_SIZE=1048576
6291         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6292         if [ $SLOW == "yes" ]; then
6293                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6294         else
6295                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6296         fi
6297
6298         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6299
6300         # prepare the read-ahead file
6301         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6302         cancel_lru_locks osc
6303         for BIDX in 2 4 8 16 32 64 128 256
6304         do
6305                 local BSIZE=$((BIDX*4096))
6306                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6307                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6308                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6309                 $LCTL set_param -n llite.*.read_ahead_stats 0
6310                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6311                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6312                 cancel_lru_locks osc
6313                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6314         done
6315         cleanup_test101bc
6316         true
6317 }
6318 run_test 101b "check stride-io mode read-ahead ================="
6319
6320 test_101c() {
6321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6322         local STRIPE_SIZE=1048576
6323         local FILE_LENGTH=$((STRIPE_SIZE*100))
6324         local nreads=10000
6325         local osc_rpc_stats
6326
6327         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6328
6329         cancel_lru_locks osc
6330         $LCTL set_param osc.*.rpc_stats 0
6331         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6332         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6333                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6334                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6335                 local size
6336
6337                 if [ $lines -le 20 ]; then
6338                         continue
6339                 fi
6340                 for size in 1 2 4 8; do
6341                         local rpc=$(echo "$stats" |
6342                                     awk '($1 == "'$size':") {print $2; exit; }')
6343                         [ $rpc != 0 ] &&
6344                                 error "Small $((size*4))k read IO $rpc !"
6345                 done
6346                 echo "$osc_rpc_stats check passed!"
6347         done
6348         cleanup_test101bc
6349         true
6350 }
6351 run_test 101c "check stripe_size aligned read-ahead ================="
6352
6353 set_read_ahead() {
6354         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6355         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6356 }
6357
6358 test_101d() {
6359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6360         local file=$DIR/$tfile
6361         local sz_MB=${FILESIZE_101d:-500}
6362         local ra_MB=${READAHEAD_MB:-40}
6363
6364         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6365         [ $free_MB -lt $sz_MB ] &&
6366                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6367
6368         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6369         $SETSTRIPE -c -1 $file || error "setstripe failed"
6370
6371         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6372         echo Cancel LRU locks on lustre client to flush the client cache
6373         cancel_lru_locks osc
6374
6375         echo Disable read-ahead
6376         local old_READAHEAD=$(set_read_ahead 0)
6377
6378         echo Reading the test file $file with read-ahead disabled
6379         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6380
6381         echo Cancel LRU locks on lustre client to flush the client cache
6382         cancel_lru_locks osc
6383         echo Enable read-ahead with ${ra_MB}MB
6384         set_read_ahead $ra_MB
6385
6386         echo Reading the test file $file with read-ahead enabled
6387         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6388
6389         echo "read-ahead disabled time read $raOFF"
6390         echo "read-ahead enabled  time read $raON"
6391
6392         set_read_ahead $old_READAHEAD
6393         rm -f $file
6394         wait_delete_completed
6395
6396         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6397                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6398 }
6399 run_test 101d "file read with and without read-ahead enabled"
6400
6401 test_101e() {
6402         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6403         local file=$DIR/$tfile
6404         local size_KB=500  #KB
6405         local count=100
6406         local bsize=1024
6407
6408         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6409         local need_KB=$((count * size_KB))
6410         [[ $free_KB -le $need_KB ]] &&
6411                 skip_env "Need free space $need_KB, have $free_KB" && return
6412
6413         echo "Creating $count ${size_KB}K test files"
6414         for ((i = 0; i < $count; i++)); do
6415                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6416         done
6417
6418         echo "Cancel LRU locks on lustre client to flush the client cache"
6419         cancel_lru_locks osc
6420
6421         echo "Reset readahead stats"
6422         $LCTL set_param -n llite.*.read_ahead_stats 0
6423
6424         for ((i = 0; i < $count; i++)); do
6425                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6426         done
6427
6428         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6429                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6430
6431         for ((i = 0; i < $count; i++)); do
6432                 rm -rf $file.$i 2>/dev/null
6433         done
6434
6435         #10000 means 20% reads are missing in readahead
6436         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6437 }
6438 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6439
6440 cleanup_test101f() {
6441     trap 0
6442     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6443     rm -rf $DIR/$tfile 2>/dev/null
6444 }
6445
6446 test_101f() {
6447         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6448     local file=$DIR/$tfile
6449     local nreads=1000
6450
6451     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6452     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6453     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6454     trap cleanup_test101f EXIT
6455
6456     echo Cancel LRU locks on lustre client to flush the client cache
6457     cancel_lru_locks osc
6458
6459     echo Reset readahead stats
6460     $LCTL set_param -n llite.*.read_ahead_stats 0
6461     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6462     # readahead should read in 2M file on second read, so only miss
6463     # 2 pages.
6464     echo Random 4K reads on 2M file for 1000 times
6465     $READS -f $file -s 2097152 -b 4096 -n $nreads
6466
6467     echo checking missing pages
6468     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6469           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6470
6471     [ $miss -lt 3 ] || error "misses too much pages!"
6472     cleanup_test101f
6473 }
6474 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6475
6476 setup_test102() {
6477         test_mkdir -p $DIR/$tdir
6478         chown $RUNAS_ID $DIR/$tdir
6479         STRIPE_SIZE=65536
6480         STRIPE_OFFSET=1
6481         STRIPE_COUNT=$OSTCOUNT
6482         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6483
6484         trap cleanup_test102 EXIT
6485         cd $DIR
6486         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6487         cd $DIR/$tdir
6488         for num in 1 2 3 4; do
6489                 for count in $(seq 1 $STRIPE_COUNT); do
6490                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6491                                 local size=`expr $STRIPE_SIZE \* $num`
6492                                 local file=file"$num-$idx-$count"
6493                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6494                         done
6495                 done
6496         done
6497
6498         cd $DIR
6499         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6500 }
6501
6502 cleanup_test102() {
6503         trap 0
6504         rm -f $TMP/f102.tar
6505         rm -rf $DIR/d0.sanity/d102
6506 }
6507
6508 test_102a() {
6509         local testfile=$DIR/$tfile
6510
6511         touch $testfile
6512
6513         [ "$UID" != 0 ] && skip_env "must run as root" && return
6514         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6515                 skip_env "must have user_xattr" && return
6516
6517         [ -z "$(which setfattr 2>/dev/null)" ] &&
6518                 skip_env "could not find setfattr" && return
6519
6520         echo "set/get xattr..."
6521         setfattr -n trusted.name1 -v value1 $testfile ||
6522                 error "setfattr -n trusted.name1=value1 $testfile failed"
6523         getfattr -n trusted.name1 $testfile 2> /dev/null |
6524           grep "trusted.name1=.value1" ||
6525                 error "$testfile missing trusted.name1=value1"
6526
6527         setfattr -n user.author1 -v author1 $testfile ||
6528                 error "setfattr -n user.author1=author1 $testfile failed"
6529         getfattr -n user.author1 $testfile 2> /dev/null |
6530           grep "user.author1=.author1" ||
6531                 error "$testfile missing trusted.author1=author1"
6532
6533         echo "listxattr..."
6534         setfattr -n trusted.name2 -v value2 $testfile ||
6535                 error "$testfile unable to set trusted.name2"
6536         setfattr -n trusted.name3 -v value3 $testfile ||
6537                 error "$testfile unable to set trusted.name3"
6538         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6539             grep "trusted.name" | wc -l) -eq 3 ] ||
6540                 error "$testfile missing 3 trusted.name xattrs"
6541
6542         setfattr -n user.author2 -v author2 $testfile ||
6543                 error "$testfile unable to set user.author2"
6544         setfattr -n user.author3 -v author3 $testfile ||
6545                 error "$testfile unable to set user.author3"
6546         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6547             grep "user.author" | wc -l) -eq 3 ] ||
6548                 error "$testfile missing 3 user.author xattrs"
6549
6550         echo "remove xattr..."
6551         setfattr -x trusted.name1 $testfile ||
6552                 error "$testfile error deleting trusted.name1"
6553         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6554                 error "$testfile did not delete trusted.name1 xattr"
6555
6556         setfattr -x user.author1 $testfile ||
6557                 error "$testfile error deleting user.author1"
6558         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6559                 error "$testfile did not delete trusted.name1 xattr"
6560
6561         # b10667: setting lustre special xattr be silently discarded
6562         echo "set lustre special xattr ..."
6563         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6564                 error "$testfile allowed setting trusted.lov"
6565 }
6566 run_test 102a "user xattr test =================================="
6567
6568 test_102b() {
6569         [ -z "$(which setfattr 2>/dev/null)" ] &&
6570                 skip_env "could not find setfattr" && return
6571
6572         # b10930: get/set/list trusted.lov xattr
6573         echo "get/set/list trusted.lov xattr ..."
6574         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6575         local testfile=$DIR/$tfile
6576         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6577                 error "setstripe failed"
6578         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6579                 error "getstripe failed"
6580         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6581                 error "can't get trusted.lov from $testfile"
6582
6583         local testfile2=${testfile}2
6584         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6585                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6586
6587         $MCREATE $testfile2
6588         setfattr -n trusted.lov -v $value $testfile2
6589         local stripe_size=$($GETSTRIPE -S $testfile2)
6590         local stripe_count=$($GETSTRIPE -c $testfile2)
6591         [[ $stripe_size -eq 65536 ]] ||
6592                 error "stripe size $stripe_size != 65536"
6593         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6594                 error "stripe count $stripe_count != $STRIPECOUNT"
6595         rm -f $DIR/$tfile
6596 }
6597 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6598
6599 test_102c() {
6600         [ -z "$(which setfattr 2>/dev/null)" ] &&
6601                 skip_env "could not find setfattr" && return
6602
6603         # b10930: get/set/list lustre.lov xattr
6604         echo "get/set/list lustre.lov xattr ..."
6605         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6606         test_mkdir -p $DIR/$tdir
6607         chown $RUNAS_ID $DIR/$tdir
6608         local testfile=$DIR/$tdir/$tfile
6609         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6610                 error "setstripe failed"
6611         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6612                 error "getstripe failed"
6613         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6614         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6615
6616         local testfile2=${testfile}2
6617         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6618                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6619
6620         $RUNAS $MCREATE $testfile2
6621         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6622         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6623         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6624         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6625         [ $stripe_count -eq $STRIPECOUNT ] ||
6626                 error "stripe count $stripe_count != $STRIPECOUNT"
6627 }
6628 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6629
6630 compare_stripe_info1() {
6631         local stripe_index_all_zero=true
6632
6633         for num in 1 2 3 4; do
6634                 for count in $(seq 1 $STRIPE_COUNT); do
6635                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6636                                 local size=$((STRIPE_SIZE * num))
6637                                 local file=file"$num-$offset-$count"
6638                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6639                                 [[ $stripe_size -ne $size ]] &&
6640                                     error "$file: size $stripe_size != $size"
6641                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6642                                 # allow fewer stripes to be created, ORI-601
6643                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6644                                     error "$file: count $stripe_count != $count"
6645                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6646                                 [[ $stripe_index -ne 0 ]] &&
6647                                         stripe_index_all_zero=false
6648                         done
6649                 done
6650         done
6651         $stripe_index_all_zero &&
6652                 error "all files are being extracted starting from OST index 0"
6653         return 0
6654 }
6655
6656 find_lustre_tar() {
6657         [ -n "$(which tar 2>/dev/null)" ] &&
6658                 strings $(which tar) | grep -q "lustre" && echo tar
6659 }
6660
6661 test_102d() {
6662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6663         # b10930: tar test for trusted.lov xattr
6664         TAR=$(find_lustre_tar)
6665         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6666         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6667         setup_test102
6668         test_mkdir -p $DIR/d102d
6669         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6670         cd $DIR/d102d/$tdir
6671         compare_stripe_info1
6672 }
6673 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6674
6675 test_102f() {
6676         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6677         # b10930: tar test for trusted.lov xattr
6678         TAR=$(find_lustre_tar)
6679         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6680         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6681         setup_test102
6682         test_mkdir -p $DIR/d102f
6683         cd $DIR
6684         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6685         cd $DIR/d102f/$tdir
6686         compare_stripe_info1
6687 }
6688 run_test 102f "tar copy files, not keep osts ==========="
6689
6690 grow_xattr() {
6691         local xsize=${1:-1024}  # in bytes
6692         local file=$DIR/$tfile
6693
6694         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6695                 skip "must have user_xattr" && return 0
6696         [ -z "$(which setfattr 2>/dev/null)" ] &&
6697                 skip_env "could not find setfattr" && return 0
6698         [ -z "$(which getfattr 2>/dev/null)" ] &&
6699                 skip_env "could not find getfattr" && return 0
6700
6701         touch $file
6702
6703         local value="$(generate_string $xsize)"
6704
6705         local xbig=trusted.big
6706         log "save $xbig on $file"
6707         setfattr -n $xbig -v $value $file ||
6708                 error "saving $xbig on $file failed"
6709
6710         local orig=$(get_xattr_value $xbig $file)
6711         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6712
6713         local xsml=trusted.sml
6714         log "save $xsml on $file"
6715         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6716
6717         local new=$(get_xattr_value $xbig $file)
6718         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6719
6720         log "grow $xsml on $file"
6721         setfattr -n $xsml -v "$value" $file ||
6722                 error "growing $xsml on $file failed"
6723
6724         new=$(get_xattr_value $xbig $file)
6725         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6726         log "$xbig still valid after growing $xsml"
6727
6728         rm -f $file
6729 }
6730
6731 test_102h() { # bug 15777
6732         grow_xattr 1024
6733 }
6734 run_test 102h "grow xattr from inside inode to external block"
6735
6736 test_102ha() {
6737         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6738         grow_xattr $(max_xattr_size)
6739 }
6740 run_test 102ha "grow xattr from inside inode to external inode"
6741
6742 test_102i() { # bug 17038
6743         [ -z "$(which getfattr 2>/dev/null)" ] &&
6744                 skip "could not find getfattr" && return
6745         touch $DIR/$tfile
6746         ln -s $DIR/$tfile $DIR/${tfile}link
6747         getfattr -n trusted.lov $DIR/$tfile ||
6748                 error "lgetxattr on $DIR/$tfile failed"
6749         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6750                 grep -i "no such attr" ||
6751                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6752         rm -f $DIR/$tfile $DIR/${tfile}link
6753 }
6754 run_test 102i "lgetxattr test on symbolic link ============"
6755
6756 test_102j() {
6757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6758         TAR=$(find_lustre_tar)
6759         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6760         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6761         setup_test102 "$RUNAS"
6762         test_mkdir -p $DIR/d102j
6763         chown $RUNAS_ID $DIR/d102j
6764         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6765         cd $DIR/d102j/$tdir
6766         compare_stripe_info1 "$RUNAS"
6767 }
6768 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6769
6770 test_102k() {
6771         [ -z "$(which setfattr 2>/dev/null)" ] &&
6772                 skip "could not find setfattr" && return
6773         touch $DIR/$tfile
6774         # b22187 just check that does not crash for regular file.
6775         setfattr -n trusted.lov $DIR/$tfile
6776         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6777         local test_kdir=$DIR/d102k
6778         test_mkdir $test_kdir
6779         local default_size=`$GETSTRIPE -S $test_kdir`
6780         local default_count=`$GETSTRIPE -c $test_kdir`
6781         local default_offset=`$GETSTRIPE -i $test_kdir`
6782         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6783                 error 'dir setstripe failed'
6784         setfattr -n trusted.lov $test_kdir
6785         local stripe_size=`$GETSTRIPE -S $test_kdir`
6786         local stripe_count=`$GETSTRIPE -c $test_kdir`
6787         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6788         [ $stripe_size -eq $default_size ] ||
6789                 error "stripe size $stripe_size != $default_size"
6790         [ $stripe_count -eq $default_count ] ||
6791                 error "stripe count $stripe_count != $default_count"
6792         [ $stripe_offset -eq $default_offset ] ||
6793                 error "stripe offset $stripe_offset != $default_offset"
6794         rm -rf $DIR/$tfile $test_kdir
6795 }
6796 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6797
6798 test_102l() {
6799         [ -z "$(which getfattr 2>/dev/null)" ] &&
6800                 skip "could not find getfattr" && return
6801
6802         # LU-532 trusted. xattr is invisible to non-root
6803         local testfile=$DIR/$tfile
6804
6805         touch $testfile
6806
6807         echo "listxattr as user..."
6808         chown $RUNAS_ID $testfile
6809         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6810             grep -q "trusted" &&
6811                 error "$testfile trusted xattrs are user visible"
6812
6813         return 0;
6814 }
6815 run_test 102l "listxattr size test =================================="
6816
6817 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6818         local path=$DIR/$tfile
6819         touch $path
6820
6821         listxattr_size_check $path || error "listattr_size_check $path failed"
6822 }
6823 run_test 102m "Ensure listxattr fails on small bufffer ========"
6824
6825 cleanup_test102
6826
6827 getxattr() { # getxattr path name
6828         # Return the base64 encoding of the value of xattr name on path.
6829         local path=$1
6830         local name=$2
6831
6832         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6833         # file: $path
6834         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6835         #
6836         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6837
6838         getfattr --absolute-names --encoding=base64 --name=$name $path |
6839                 awk -F= -v name=$name '$1 == name {
6840                         print substr($0, index($0, "=") + 1);
6841         }'
6842 }
6843
6844 test_102n() { # LU-4101 mdt: protect internal xattrs
6845         local file0=$DIR/$tfile.0
6846         local file1=$DIR/$tfile.1
6847         local xattr0=$TMP/$tfile.0
6848         local xattr1=$TMP/$tfile.1
6849         local name
6850         local value
6851
6852         [ -z "$(which setfattr 2>/dev/null)" ] &&
6853                 skip "could not find setfattr" && return
6854
6855         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6856         then
6857                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6858                 return
6859         fi
6860
6861         rm -rf $file0 $file1 $xattr0 $xattr1
6862         touch $file0 $file1
6863
6864         # Get 'before' xattrs of $file1.
6865         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6866
6867         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6868                 # Try to copy xattr from $file0 to $file1.
6869                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6870
6871                 setfattr --name=trusted.$name --value="$value" $file1 ||
6872                         error "setxattr 'trusted.$name' failed"
6873
6874                 # Try to set a garbage xattr.
6875                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6876
6877                 setfattr --name=trusted.$name --value="$value" $file1 ||
6878                         error "setxattr 'trusted.$name' failed"
6879
6880                 # Try to remove the xattr from $file1. We don't care if this
6881                 # appears to succeed or fail, we just don't want there to be
6882                 # any changes or crashes.
6883                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6884         done
6885
6886         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6887         then
6888                 name="lfsck_ns"
6889                 # Try to copy xattr from $file0 to $file1.
6890                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6891
6892                 setfattr --name=trusted.$name --value="$value" $file1 ||
6893                         error "setxattr 'trusted.$name' failed"
6894
6895                 # Try to set a garbage xattr.
6896                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6897
6898                 setfattr --name=trusted.$name --value="$value" $file1 ||
6899                         error "setxattr 'trusted.$name' failed"
6900
6901                 # Try to remove the xattr from $file1. We don't care if this
6902                 # appears to succeed or fail, we just don't want there to be
6903                 # any changes or crashes.
6904                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6905         fi
6906
6907         # Get 'after' xattrs of file1.
6908         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6909
6910         if ! diff $xattr0 $xattr1; then
6911                 error "before and after xattrs of '$file1' differ"
6912         fi
6913
6914         rm -rf $file0 $file1 $xattr0 $xattr1
6915
6916         return 0
6917 }
6918 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6919
6920 test_102p() { # LU-4703 setxattr did not check ownership
6921         local testfile=$DIR/$tfile
6922
6923         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6924                 skip "MDS needs to be at least 2.5.56" && return
6925
6926         touch $testfile
6927
6928         echo "setfacl as user..."
6929         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6930         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6931
6932         echo "setfattr as user..."
6933         setfacl -m "u:$RUNAS_ID:---" $testfile
6934         $RUNAS setfattr -x system.posix_acl_access $testfile
6935         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6936 }
6937 run_test 102p "check setxattr(2) correctly fails without permission"
6938
6939 test_102q() {
6940         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
6941                 skip "MDS needs to be at least 2.6.92" && return
6942         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
6943 }
6944 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
6945
6946 test_102r() {
6947         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
6948                 skip "MDS needs to be at least 2.6.93" && return
6949         touch $DIR/$tfile || error "touch"
6950         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
6951         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
6952         rm $DIR/$tfile || error "rm"
6953
6954         #normal directory
6955         mkdir -p $DIR/$tdir || error "mkdir"
6956         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
6957         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
6958         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
6959                 error "$testfile error deleting user.author1"
6960         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
6961                 grep "user.$(basename $tdir)" &&
6962                 error "$tdir did not delete user.$(basename $tdir)"
6963         rmdir $DIR/$tdir || error "rmdir"
6964
6965         #striped directory
6966         test_mkdir -p $DIR/$tdir || error "make striped dir"
6967         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
6968         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
6969         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
6970                 error "$testfile error deleting user.author1"
6971         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
6972                 grep "user.$(basename $tdir)" &&
6973                 error "$tdir did not delete user.$(basename $tdir)"
6974         rmdir $DIR/$tdir || error "rm striped dir"
6975 }
6976 run_test 102r "set EAs with empty values"
6977
6978 run_acl_subtest()
6979 {
6980     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6981     return $?
6982 }
6983
6984 test_103a() {
6985         [ "$UID" != 0 ] && skip_env "must run as root" && return
6986         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6987                 skip "must have acl enabled" && return
6988         [ -z "$(which setfacl 2>/dev/null)" ] &&
6989                 skip_env "could not find setfacl" && return
6990         $GSS && skip "could not run under gss" && return
6991
6992         gpasswd -a daemon bin                           # LU-5641
6993         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
6994
6995         declare -a identity_old
6996
6997         for num in $(seq $MDSCOUNT); do
6998                 switch_identity $num true || identity_old[$num]=$?
6999         done
7000
7001         SAVE_UMASK=$(umask)
7002         umask 0022
7003         cd $DIR
7004
7005         echo "performing cp ..."
7006         run_acl_subtest cp || error "run_acl_subtest cp failed"
7007         echo "performing getfacl-noacl..."
7008         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7009         echo "performing misc..."
7010         run_acl_subtest misc || error  "misc test failed"
7011         echo "performing permissions..."
7012         run_acl_subtest permissions || error "permissions failed"
7013         echo "performing setfacl..."
7014         run_acl_subtest setfacl || error  "setfacl test failed"
7015
7016         # inheritance test got from HP
7017         echo "performing inheritance..."
7018         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7019         chmod +x make-tree || error "chmod +x failed"
7020         run_acl_subtest inheritance || error "inheritance test failed"
7021         rm -f make-tree
7022
7023         echo "LU-974 ignore umask when acl is enabled..."
7024         run_acl_subtest 974 || error "LU-974 umask test failed"
7025         if [ $MDSCOUNT -ge 2 ]; then
7026                 run_acl_subtest 974_remote ||
7027                         error "LU-974 umask test failed under remote dir"
7028         fi
7029
7030         echo "LU-2561 newly created file is same size as directory..."
7031         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7032                 run_acl_subtest 2561 || error "LU-2561 test failed"
7033         else
7034                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7035         fi
7036
7037         run_acl_subtest 4924 || error "LU-4924 test failed"
7038
7039         cd $SAVE_PWD
7040         umask $SAVE_UMASK
7041
7042         for num in $(seq $MDSCOUNT); do
7043                 if [ "${identity_old[$num]}" = 1 ]; then
7044                         switch_identity $num false || identity_old[$num]=$?
7045                 fi
7046         done
7047 }
7048 run_test 103a "acl test ========================================="
7049
7050 test_103b() {
7051         local noacl=false
7052         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7053         local mountopts=$MDS_MOUNT_OPTS
7054
7055         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7056                 noacl=true
7057         else
7058                 # stop the MDT
7059                 stop $SINGLEMDS || error "failed to stop MDT."
7060                 # remount the MDT
7061                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7062                         MDS_MOUNT_OPTS="-o noacl"
7063                 else
7064                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7065                 fi
7066                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7067                         error "failed to start MDT."
7068                 MDS_MOUNT_OPTS=$mountopts
7069         fi
7070
7071         touch $DIR/$tfile
7072         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7073
7074         if ! $noacl; then
7075                 # stop the MDT
7076                 stop $SINGLEMDS || error "failed to stop MDT."
7077                 # remount the MDT
7078                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7079                         error "failed to start MDT."
7080         fi
7081
7082         true
7083 }
7084 run_test 103b "MDS mount option 'noacl'"
7085
7086 test_103c() {
7087         mkdir -p $DIR/$tdir
7088         cp -rp $DIR/$tdir $DIR/$tdir.bak
7089
7090         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7091                 error "$DIR/$tdir shouldn't contain default ACL"
7092         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7093                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7094         true
7095 }
7096 run_test 103c "'cp -rp' won't set empty acl"
7097
7098 test_104a() {
7099         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7100         touch $DIR/$tfile
7101         lfs df || error "lfs df failed"
7102         lfs df -ih || error "lfs df -ih failed"
7103         lfs df -h $DIR || error "lfs df -h $DIR failed"
7104         lfs df -i $DIR || error "lfs df -i $DIR failed"
7105         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7106         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7107
7108         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7109         lctl --device %$OSC deactivate
7110         lfs df || error "lfs df with deactivated OSC failed"
7111         lctl --device %$OSC activate
7112         # wait the osc back to normal
7113         wait_osc_import_state client ost FULL
7114
7115         lfs df || error "lfs df with reactivated OSC failed"
7116         rm -f $DIR/$tfile
7117 }
7118 run_test 104a "lfs df [-ih] [path] test ========================="
7119
7120 test_104b() {
7121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7122         [ $RUNAS_ID -eq $UID ] &&
7123                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7124         chmod 666 /dev/obd
7125         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7126                         grep "Permission denied" | wc -l)))
7127         if [ $denied_cnt -ne 0 ]; then
7128                 error "lfs check servers test failed"
7129         fi
7130 }
7131 run_test 104b "$RUNAS lfs check servers test ===================="
7132
7133 test_105a() {
7134         # doesn't work on 2.4 kernels
7135         touch $DIR/$tfile
7136         if $(flock_is_enabled); then
7137                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7138         else
7139                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7140         fi
7141         rm -f $DIR/$tfile
7142 }
7143 run_test 105a "flock when mounted without -o flock test ========"
7144
7145 test_105b() {
7146         touch $DIR/$tfile
7147         if $(flock_is_enabled); then
7148                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7149         else
7150                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7151         fi
7152         rm -f $DIR/$tfile
7153 }
7154 run_test 105b "fcntl when mounted without -o flock test ========"
7155
7156 test_105c() {
7157         touch $DIR/$tfile
7158         if $(flock_is_enabled); then
7159                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7160         else
7161                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7162         fi
7163         rm -f $DIR/$tfile
7164 }
7165 run_test 105c "lockf when mounted without -o flock test ========"
7166
7167 test_105d() { # bug 15924
7168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7169         test_mkdir -p $DIR/$tdir
7170         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7171         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7172         $LCTL set_param fail_loc=0x80000315
7173         flocks_test 2 $DIR/$tdir
7174 }
7175 run_test 105d "flock race (should not freeze) ========"
7176
7177 test_105e() { # bug 22660 && 22040
7178         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7179         touch $DIR/$tfile
7180         flocks_test 3 $DIR/$tfile
7181 }
7182 run_test 105e "Two conflicting flocks from same process ======="
7183
7184 test_106() { #bug 10921
7185         test_mkdir -p $DIR/$tdir
7186         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7187         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7188 }
7189 run_test 106 "attempt exec of dir followed by chown of that dir"
7190
7191 test_107() {
7192         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7193         CDIR=`pwd`
7194         cd $DIR
7195
7196         local file=core
7197         rm -f $file
7198
7199         local save_pattern=$(sysctl -n kernel.core_pattern)
7200         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7201         sysctl -w kernel.core_pattern=$file
7202         sysctl -w kernel.core_uses_pid=0
7203
7204         ulimit -c unlimited
7205         sleep 60 &
7206         SLEEPPID=$!
7207
7208         sleep 1
7209
7210         kill -s 11 $SLEEPPID
7211         wait $SLEEPPID
7212         if [ -e $file ]; then
7213                 size=`stat -c%s $file`
7214                 [ $size -eq 0 ] && error "Fail to create core file $file"
7215         else
7216                 error "Fail to create core file $file"
7217         fi
7218         rm -f $file
7219         sysctl -w kernel.core_pattern=$save_pattern
7220         sysctl -w kernel.core_uses_pid=$save_uses_pid
7221         cd $CDIR
7222 }
7223 run_test 107 "Coredump on SIG"
7224
7225 test_110() {
7226         test_mkdir -p $DIR/$tdir
7227         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7228                 error "mkdir with 255 char failed"
7229         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7230                 error "mkdir with 256 char should fail, but did not"
7231         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7232                 error "create with 255 char failed"
7233         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7234                 error "create with 256 char should fail, but did not"
7235
7236         ls -l $DIR/$tdir
7237         rm -rf $DIR/$tdir
7238 }
7239 run_test 110 "filename length checking"
7240
7241 test_115() {
7242         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7243         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7244                 tail -1 | cut -c11-20)
7245         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7246         echo "Starting with $OSTIO_pre threads"
7247
7248         NUMTEST=20000
7249         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7250         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7251         echo "$NUMTEST creates/unlinks"
7252         test_mkdir -p $DIR/$tdir
7253         createmany -o $DIR/$tdir/$tfile $NUMTEST
7254         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7255
7256         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7257                 tail -1 | cut -c11-20)
7258
7259         # don't return an error
7260         [ $OSTIO_post == $OSTIO_pre ] && echo \
7261             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7262             echo "This may be fine, depending on what ran before this test" &&
7263             echo "and how fast this system is." && return
7264
7265         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7266 }
7267 run_test 115 "verify dynamic thread creation===================="
7268
7269 free_min_max () {
7270         wait_delete_completed
7271         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7272         echo OST kbytes available: ${AVAIL[@]}
7273         MAXI=0; MAXV=${AVAIL[0]}
7274         MINI=0; MINV=${AVAIL[0]}
7275         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7276                 #echo OST $i: ${AVAIL[i]}kb
7277                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7278                         MAXV=${AVAIL[i]}; MAXI=$i
7279                 fi
7280                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7281                         MINV=${AVAIL[i]}; MINI=$i
7282                 fi
7283         done
7284         echo Min free space: OST $MINI: $MINV
7285         echo Max free space: OST $MAXI: $MAXV
7286 }
7287
7288 test_116a() { # was previously test_116()
7289         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7290         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7291
7292         echo -n "Free space priority "
7293         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7294                 head -n1
7295         declare -a AVAIL
7296         free_min_max
7297
7298         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7299         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7300                 && return
7301         trap simple_cleanup_common EXIT
7302
7303
7304         # Check if we need to generate uneven OSTs
7305         test_mkdir -p $DIR/$tdir/OST${MINI}
7306         local FILL=$(($MINV / 4))
7307         local DIFF=$(($MAXV - $MINV))
7308         local DIFF2=$(($DIFF * 100 / $MINV))
7309
7310         local threshold=$(do_facet $SINGLEMDS \
7311                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7312         threshold=${threshold%%%}
7313         echo -n "Check for uneven OSTs: "
7314         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7315
7316         if [[ $DIFF2 -gt $threshold ]]; then
7317                 echo "ok"
7318                 echo "Don't need to fill OST$MINI"
7319         else
7320                 # generate uneven OSTs. Write 2% over the QOS threshold value
7321                 echo "no"
7322                 DIFF=$(($threshold - $DIFF2 + 2))
7323                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7324                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7325                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7326                         error "setstripe failed"
7327                 DIFF=$(($DIFF2 / 2048))
7328                 i=0
7329                 while [ $i -lt $DIFF ]; do
7330                         i=$(($i + 1))
7331                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7332                                 bs=2M count=1 2>/dev/null
7333                         echo -n .
7334                 done
7335                 echo .
7336                 sync
7337                 sleep_maxage
7338                 free_min_max
7339         fi
7340
7341         DIFF=$(($MAXV - $MINV))
7342         DIFF2=$(($DIFF * 100 / $MINV))
7343         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7344         if [[ $DIFF2 -gt $threshold ]]; then
7345                 echo "ok"
7346         else
7347                 echo "failed - QOS mode won't be used"
7348                 skip "QOS imbalance criteria not met"
7349                 simple_cleanup_common
7350                 return
7351         fi
7352
7353         MINI1=$MINI; MINV1=$MINV
7354         MAXI1=$MAXI; MAXV1=$MAXV
7355
7356         # now fill using QOS
7357         $SETSTRIPE -c 1 $DIR/$tdir
7358         FILL=$(($FILL / 200))
7359         if [ $FILL -gt 600 ]; then
7360                 FILL=600
7361         fi
7362         echo "writing $FILL files to QOS-assigned OSTs"
7363         i=0
7364         while [ $i -lt $FILL ]; do
7365                 i=$((i + 1))
7366                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7367                         count=1 2>/dev/null
7368                 echo -n .
7369         done
7370         echo "wrote $i 200k files"
7371         sync
7372         sleep_maxage
7373
7374         echo "Note: free space may not be updated, so measurements might be off"
7375         free_min_max
7376         DIFF2=$(($MAXV - $MINV))
7377         echo "free space delta: orig $DIFF final $DIFF2"
7378         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7379         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7380         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7381         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7382         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7383         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7384         [ $DIFF -gt 0 ] &&
7385                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7386
7387         # Figure out which files were written where
7388         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7389                   awk '/'$MINI1': / {print $2; exit}')
7390         echo $UUID
7391         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7392         echo "$MINC files created on smaller OST $MINI1"
7393         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7394                   awk '/'$MAXI1': / {print $2; exit}')
7395         echo $UUID
7396         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7397         echo "$MAXC files created on larger OST $MAXI1"
7398         FILL=$(($MAXC * 100 / $MINC - 100))
7399         [[ $MINC -gt 0 ]] &&
7400                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7401         [[ $MAXC -gt $MINC ]] ||
7402                 error_ignore LU-9 "stripe QOS didn't balance free space"
7403         simple_cleanup_common
7404 }
7405 run_test 116a "stripe QOS: free space balance ==================="
7406
7407 test_116b() { # LU-2093
7408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7409 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7410         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7411                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7412         [ -z "$old_rr" ] && skip "no QOS" && return 0
7413         do_facet $SINGLEMDS lctl set_param \
7414                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7415         mkdir -p $DIR/$tdir
7416         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7417         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7418         do_facet $SINGLEMDS lctl set_param fail_loc=0
7419         rm -rf $DIR/$tdir
7420         do_facet $SINGLEMDS lctl set_param \
7421                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7422 }
7423 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7424
7425 test_117() # bug 10891
7426 {
7427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7428         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7429         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7430         lctl set_param fail_loc=0x21e
7431         > $DIR/$tfile || error "truncate failed"
7432         lctl set_param fail_loc=0
7433         echo "Truncate succeeded."
7434         rm -f $DIR/$tfile
7435 }
7436 run_test 117 "verify osd extend =========="
7437
7438 NO_SLOW_RESENDCOUNT=4
7439 export OLD_RESENDCOUNT=""
7440 set_resend_count () {
7441         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7442         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7443         lctl set_param -n $PROC_RESENDCOUNT $1
7444         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7445 }
7446
7447 # for reduce test_118* time (b=14842)
7448 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7449
7450 # Reset async IO behavior after error case
7451 reset_async() {
7452         FILE=$DIR/reset_async
7453
7454         # Ensure all OSCs are cleared
7455         $SETSTRIPE -c -1 $FILE
7456         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7457         sync
7458         rm $FILE
7459 }
7460
7461 test_118a() #bug 11710
7462 {
7463         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7464         reset_async
7465
7466         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7467         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7468         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7469
7470         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7471                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7472                 return 1;
7473         fi
7474         rm -f $DIR/$tfile
7475 }
7476 run_test 118a "verify O_SYNC works =========="
7477
7478 test_118b()
7479 {
7480         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7481         remote_ost_nodsh && skip "remote OST with nodsh" && return
7482
7483         reset_async
7484
7485         #define OBD_FAIL_OST_ENOENT 0x217
7486         set_nodes_failloc "$(osts_nodes)" 0x217
7487         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7488         RC=$?
7489         set_nodes_failloc "$(osts_nodes)" 0
7490         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7491         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7492                     grep -c writeback)
7493
7494         if [[ $RC -eq 0 ]]; then
7495                 error "Must return error due to dropped pages, rc=$RC"
7496                 return 1;
7497         fi
7498
7499         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7500                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7501                 return 1;
7502         fi
7503
7504         echo "Dirty pages not leaked on ENOENT"
7505
7506         # Due to the above error the OSC will issue all RPCs syncronously
7507         # until a subsequent RPC completes successfully without error.
7508         $MULTIOP $DIR/$tfile Ow4096yc
7509         rm -f $DIR/$tfile
7510
7511         return 0
7512 }
7513 run_test 118b "Reclaim dirty pages on fatal error =========="
7514
7515 test_118c()
7516 {
7517         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7518
7519         # for 118c, restore the original resend count, LU-1940
7520         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7521                                 set_resend_count $OLD_RESENDCOUNT
7522         remote_ost_nodsh && skip "remote OST with nodsh" && return
7523
7524         reset_async
7525
7526         #define OBD_FAIL_OST_EROFS               0x216
7527         set_nodes_failloc "$(osts_nodes)" 0x216
7528
7529         # multiop should block due to fsync until pages are written
7530         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7531         MULTIPID=$!
7532         sleep 1
7533
7534         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7535                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7536         fi
7537
7538         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7539                     grep -c writeback)
7540         if [[ $WRITEBACK -eq 0 ]]; then
7541                 error "No page in writeback, writeback=$WRITEBACK"
7542         fi
7543
7544         set_nodes_failloc "$(osts_nodes)" 0
7545         wait $MULTIPID
7546         RC=$?
7547         if [[ $RC -ne 0 ]]; then
7548                 error "Multiop fsync failed, rc=$RC"
7549         fi
7550
7551         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7552         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7553                     grep -c writeback)
7554         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7555                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7556         fi
7557
7558         rm -f $DIR/$tfile
7559         echo "Dirty pages flushed via fsync on EROFS"
7560         return 0
7561 }
7562 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7563
7564 # continue to use small resend count to reduce test_118* time (b=14842)
7565 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7566
7567 test_118d()
7568 {
7569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7570         remote_ost_nodsh && skip "remote OST with nodsh" && return
7571
7572         reset_async
7573
7574         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7575         set_nodes_failloc "$(osts_nodes)" 0x214
7576         # multiop should block due to fsync until pages are written
7577         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7578         MULTIPID=$!
7579         sleep 1
7580
7581         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7582                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7583         fi
7584
7585         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7586                     grep -c writeback)
7587         if [[ $WRITEBACK -eq 0 ]]; then
7588                 error "No page in writeback, writeback=$WRITEBACK"
7589         fi
7590
7591         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7592         set_nodes_failloc "$(osts_nodes)" 0
7593
7594         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7595         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7596                     grep -c writeback)
7597         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7598                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7599         fi
7600
7601         rm -f $DIR/$tfile
7602         echo "Dirty pages gaurenteed flushed via fsync"
7603         return 0
7604 }
7605 run_test 118d "Fsync validation inject a delay of the bulk =========="
7606
7607 test_118f() {
7608         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7609         reset_async
7610
7611         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7612         lctl set_param fail_loc=0x8000040a
7613
7614         # Should simulate EINVAL error which is fatal
7615         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7616         RC=$?
7617         if [[ $RC -eq 0 ]]; then
7618                 error "Must return error due to dropped pages, rc=$RC"
7619         fi
7620
7621         lctl set_param fail_loc=0x0
7622
7623         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7624         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7625         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7626                     grep -c writeback)
7627         if [[ $LOCKED -ne 0 ]]; then
7628                 error "Locked pages remain in cache, locked=$LOCKED"
7629         fi
7630
7631         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7632                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7633         fi
7634
7635         rm -f $DIR/$tfile
7636         echo "No pages locked after fsync"
7637
7638         reset_async
7639         return 0
7640 }
7641 run_test 118f "Simulate unrecoverable OSC side error =========="
7642
7643 test_118g() {
7644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7645         reset_async
7646
7647         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7648         lctl set_param fail_loc=0x406
7649
7650         # simulate local -ENOMEM
7651         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7652         RC=$?
7653
7654         lctl set_param fail_loc=0
7655         if [[ $RC -eq 0 ]]; then
7656                 error "Must return error due to dropped pages, rc=$RC"
7657         fi
7658
7659         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7660         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7661         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7662                         grep -c writeback)
7663         if [[ $LOCKED -ne 0 ]]; then
7664                 error "Locked pages remain in cache, locked=$LOCKED"
7665         fi
7666
7667         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7668                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7669         fi
7670
7671         rm -f $DIR/$tfile
7672         echo "No pages locked after fsync"
7673
7674         reset_async
7675         return 0
7676 }
7677 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7678
7679 test_118h() {
7680         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7681         remote_ost_nodsh && skip "remote OST with nodsh" && return
7682
7683         reset_async
7684
7685         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7686         set_nodes_failloc "$(osts_nodes)" 0x20e
7687         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7688         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7689         RC=$?
7690
7691         set_nodes_failloc "$(osts_nodes)" 0
7692         if [[ $RC -eq 0 ]]; then
7693                 error "Must return error due to dropped pages, rc=$RC"
7694         fi
7695
7696         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7697         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7698         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7699                     grep -c writeback)
7700         if [[ $LOCKED -ne 0 ]]; then
7701                 error "Locked pages remain in cache, locked=$LOCKED"
7702         fi
7703
7704         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7705                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7706         fi
7707
7708         rm -f $DIR/$tfile
7709         echo "No pages locked after fsync"
7710
7711         return 0
7712 }
7713 run_test 118h "Verify timeout in handling recoverables errors  =========="
7714
7715 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7716
7717 test_118i() {
7718         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7719         remote_ost_nodsh && skip "remote OST with nodsh" && return
7720
7721         reset_async
7722
7723         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7724         set_nodes_failloc "$(osts_nodes)" 0x20e
7725
7726         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7727         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7728         PID=$!
7729         sleep 5
7730         set_nodes_failloc "$(osts_nodes)" 0
7731
7732         wait $PID
7733         RC=$?
7734         if [[ $RC -ne 0 ]]; then
7735                 error "got error, but should be not, rc=$RC"
7736         fi
7737
7738         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7739         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7740         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7741         if [[ $LOCKED -ne 0 ]]; then
7742                 error "Locked pages remain in cache, locked=$LOCKED"
7743         fi
7744
7745         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7746                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7747         fi
7748
7749         rm -f $DIR/$tfile
7750         echo "No pages locked after fsync"
7751
7752         return 0
7753 }
7754 run_test 118i "Fix error before timeout in recoverable error  =========="
7755
7756 [ "$SLOW" = "no" ] && set_resend_count 4
7757
7758 test_118j() {
7759         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7760         remote_ost_nodsh && skip "remote OST with nodsh" && return
7761
7762         reset_async
7763
7764         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7765         set_nodes_failloc "$(osts_nodes)" 0x220
7766
7767         # return -EIO from OST
7768         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7769         RC=$?
7770         set_nodes_failloc "$(osts_nodes)" 0x0
7771         if [[ $RC -eq 0 ]]; then
7772                 error "Must return error due to dropped pages, rc=$RC"
7773         fi
7774
7775         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7776         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7777         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7778         if [[ $LOCKED -ne 0 ]]; then
7779                 error "Locked pages remain in cache, locked=$LOCKED"
7780         fi
7781
7782         # in recoverable error on OST we want resend and stay until it finished
7783         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7784                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7785         fi
7786
7787         rm -f $DIR/$tfile
7788         echo "No pages locked after fsync"
7789
7790         return 0
7791 }
7792 run_test 118j "Simulate unrecoverable OST side error =========="
7793
7794 test_118k()
7795 {
7796         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7797         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7798
7799         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7800         set_nodes_failloc "$(osts_nodes)" 0x20e
7801         test_mkdir -p $DIR/$tdir
7802
7803         for ((i=0;i<10;i++)); do
7804                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7805                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7806                 SLEEPPID=$!
7807                 sleep 0.500s
7808                 kill $SLEEPPID
7809                 wait $SLEEPPID
7810         done
7811
7812         set_nodes_failloc "$(osts_nodes)" 0
7813         rm -rf $DIR/$tdir
7814 }
7815 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7816
7817 test_118l()
7818 {
7819         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7820         # LU-646
7821         test_mkdir -p $DIR/$tdir
7822         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7823         rm -rf $DIR/$tdir
7824 }
7825 run_test 118l "fsync dir ========="
7826
7827 test_118m() # LU-3066
7828 {
7829         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7830         test_mkdir -p $DIR/$tdir
7831         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7832         rm -rf $DIR/$tdir
7833 }
7834 run_test 118m "fdatasync dir ========="
7835
7836 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7837
7838 test_119a() # bug 11737
7839 {
7840         BSIZE=$((512 * 1024))
7841         directio write $DIR/$tfile 0 1 $BSIZE
7842         # We ask to read two blocks, which is more than a file size.
7843         # directio will indicate an error when requested and actual
7844         # sizes aren't equeal (a normal situation in this case) and
7845         # print actual read amount.
7846         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7847         if [ "$NOB" != "$BSIZE" ]; then
7848                 error "read $NOB bytes instead of $BSIZE"
7849         fi
7850         rm -f $DIR/$tfile
7851 }
7852 run_test 119a "Short directIO read must return actual read amount"
7853
7854 test_119b() # bug 11737
7855 {
7856         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7857
7858         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7859         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7860         sync
7861         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7862                 error "direct read failed"
7863         rm -f $DIR/$tfile
7864 }
7865 run_test 119b "Sparse directIO read must return actual read amount"
7866
7867 test_119c() # bug 13099
7868 {
7869         BSIZE=1048576
7870         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7871         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7872         rm -f $DIR/$tfile
7873 }
7874 run_test 119c "Testing for direct read hitting hole"
7875
7876 test_119d() # bug 15950
7877 {
7878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7879         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7880         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7881         BSIZE=1048576
7882         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7883         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7884         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7885         lctl set_param fail_loc=0x40d
7886         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7887         pid_dio=$!
7888         sleep 1
7889         cat $DIR/$tfile > /dev/null &
7890         lctl set_param fail_loc=0
7891         pid_reads=$!
7892         wait $pid_dio
7893         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7894         sleep 2
7895         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7896         error "the read rpcs have not completed in 2s"
7897         rm -f $DIR/$tfile
7898         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7899 }
7900 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7901
7902 test_120a() {
7903         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7904         test_mkdir -p $DIR/$tdir
7905         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7906                skip "no early lock cancel on server" && return 0
7907
7908         lru_resize_disable mdc
7909         lru_resize_disable osc
7910         cancel_lru_locks mdc
7911         # asynchronous object destroy at MDT could cause bl ast to client
7912         cancel_lru_locks osc
7913
7914         stat $DIR/$tdir > /dev/null
7915         can1=$(do_facet $SINGLEMDS \
7916                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7917                awk '/ldlm_cancel/ {print $2}')
7918         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7919                awk '/ldlm_bl_callback/ {print $2}')
7920         test_mkdir -c1 $DIR/$tdir/d1
7921         can2=$(do_facet $SINGLEMDS \
7922                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7923                awk '/ldlm_cancel/ {print $2}')
7924         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7925                awk '/ldlm_bl_callback/ {print $2}')
7926         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7927         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7928         lru_resize_enable mdc
7929         lru_resize_enable osc
7930 }
7931 run_test 120a "Early Lock Cancel: mkdir test"
7932
7933 test_120b() {
7934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7935         test_mkdir $DIR/$tdir
7936         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7937                skip "no early lock cancel on server" && return 0
7938         lru_resize_disable mdc
7939         lru_resize_disable osc
7940         cancel_lru_locks mdc
7941         stat $DIR/$tdir > /dev/null
7942         can1=$(do_facet $SINGLEMDS \
7943                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7944                awk '/ldlm_cancel/ {print $2}')
7945         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7946                awk '/ldlm_bl_callback/ {print $2}')
7947         touch $DIR/$tdir/f1
7948         can2=$(do_facet $SINGLEMDS \
7949                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7950                awk '/ldlm_cancel/ {print $2}')
7951         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7952                awk '/ldlm_bl_callback/ {print $2}')
7953         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7954         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7955         lru_resize_enable mdc
7956         lru_resize_enable osc
7957 }
7958 run_test 120b "Early Lock Cancel: create test"
7959
7960 test_120c() {
7961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7962         test_mkdir -c1 $DIR/$tdir
7963         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7964                skip "no early lock cancel on server" && return 0
7965         lru_resize_disable mdc
7966         lru_resize_disable osc
7967         test_mkdir -p -c1 $DIR/$tdir/d1
7968         test_mkdir -p -c1 $DIR/$tdir/d2
7969         touch $DIR/$tdir/d1/f1
7970         cancel_lru_locks mdc
7971         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7972         can1=$(do_facet $SINGLEMDS \
7973                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7974                awk '/ldlm_cancel/ {print $2}')
7975         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7976                awk '/ldlm_bl_callback/ {print $2}')
7977         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7978         can2=$(do_facet $SINGLEMDS \
7979                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7980                awk '/ldlm_cancel/ {print $2}')
7981         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7982                awk '/ldlm_bl_callback/ {print $2}')
7983         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7984         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7985         lru_resize_enable mdc
7986         lru_resize_enable osc
7987 }
7988 run_test 120c "Early Lock Cancel: link test"
7989
7990 test_120d() {
7991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7992         test_mkdir -p -c1 $DIR/$tdir
7993         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7994                skip "no early lock cancel on server" && return 0
7995         lru_resize_disable mdc
7996         lru_resize_disable osc
7997         touch $DIR/$tdir
7998         cancel_lru_locks mdc
7999         stat $DIR/$tdir > /dev/null
8000         can1=$(do_facet $SINGLEMDS \
8001                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8002                awk '/ldlm_cancel/ {print $2}')
8003         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8004                awk '/ldlm_bl_callback/ {print $2}')
8005         chmod a+x $DIR/$tdir
8006         can2=$(do_facet $SINGLEMDS \
8007                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8008                awk '/ldlm_cancel/ {print $2}')
8009         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8010                awk '/ldlm_bl_callback/ {print $2}')
8011         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8012         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8013         lru_resize_enable mdc
8014         lru_resize_enable osc
8015 }
8016 run_test 120d "Early Lock Cancel: setattr test"
8017
8018 test_120e() {
8019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8020         test_mkdir -p -c1 $DIR/$tdir
8021         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8022                skip "no early lock cancel on server" && return 0
8023         lru_resize_disable mdc
8024         lru_resize_disable osc
8025         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8026         cancel_lru_locks mdc
8027         cancel_lru_locks osc
8028         dd if=$DIR/$tdir/f1 of=/dev/null
8029         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8030         # XXX client can not do early lock cancel of OST lock
8031         # during unlink (LU-4206), so cancel osc lock now.
8032         cancel_lru_locks osc
8033         can1=$(do_facet $SINGLEMDS \
8034                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8035                awk '/ldlm_cancel/ {print $2}')
8036         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8037                awk '/ldlm_bl_callback/ {print $2}')
8038         unlink $DIR/$tdir/f1
8039         sleep 5
8040         can2=$(do_facet $SINGLEMDS \
8041                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8042                awk '/ldlm_cancel/ {print $2}')
8043         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8044                awk '/ldlm_bl_callback/ {print $2}')
8045         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8046         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8047         lru_resize_enable mdc
8048         lru_resize_enable osc
8049 }
8050 run_test 120e "Early Lock Cancel: unlink test"
8051
8052 test_120f() {
8053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8054         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8055                skip "no early lock cancel on server" && return 0
8056         test_mkdir -p -c1 $DIR/$tdir
8057         lru_resize_disable mdc
8058         lru_resize_disable osc
8059         test_mkdir -p -c1 $DIR/$tdir/d1
8060         test_mkdir -p -c1 $DIR/$tdir/d2
8061         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8062         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8063         cancel_lru_locks mdc
8064         cancel_lru_locks osc
8065         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8066         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8067         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8068         # XXX client can not do early lock cancel of OST lock
8069         # during rename (LU-4206), so cancel osc lock now.
8070         cancel_lru_locks osc
8071         can1=$(do_facet $SINGLEMDS \
8072                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8073                awk '/ldlm_cancel/ {print $2}')
8074         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8075                awk '/ldlm_bl_callback/ {print $2}')
8076         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8077         sleep 5
8078         can2=$(do_facet $SINGLEMDS \
8079                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8080                awk '/ldlm_cancel/ {print $2}')
8081         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8082                awk '/ldlm_bl_callback/ {print $2}')
8083         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8084         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8085         lru_resize_enable mdc
8086         lru_resize_enable osc
8087 }
8088 run_test 120f "Early Lock Cancel: rename test"
8089
8090 test_120g() {
8091         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8092         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8093                skip "no early lock cancel on server" && return 0
8094         lru_resize_disable mdc
8095         lru_resize_disable osc
8096         count=10000
8097         echo create $count files
8098         test_mkdir -p $DIR/$tdir
8099         cancel_lru_locks mdc
8100         cancel_lru_locks osc
8101         t0=`date +%s`
8102
8103         can0=$(do_facet $SINGLEMDS \
8104                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8105                awk '/ldlm_cancel/ {print $2}')
8106         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8107                awk '/ldlm_bl_callback/ {print $2}')
8108         createmany -o $DIR/$tdir/f $count
8109         sync
8110         can1=$(do_facet $SINGLEMDS \
8111                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8112                awk '/ldlm_cancel/ {print $2}')
8113         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8114                awk '/ldlm_bl_callback/ {print $2}')
8115         t1=$(date +%s)
8116         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8117         echo rm $count files
8118         rm -r $DIR/$tdir
8119         sync
8120         can2=$(do_facet $SINGLEMDS \
8121                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8122                awk '/ldlm_cancel/ {print $2}')
8123         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8124                awk '/ldlm_bl_callback/ {print $2}')
8125         t2=$(date +%s)
8126         echo total: $count removes in $((t2-t1))
8127         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8128         sleep 2
8129         # wait for commitment of removal
8130         lru_resize_enable mdc
8131         lru_resize_enable osc
8132 }
8133 run_test 120g "Early Lock Cancel: performance test"
8134
8135 test_121() { #bug #10589
8136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8137         rm -rf $DIR/$tfile
8138         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8139 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8140         lctl set_param fail_loc=0x310
8141         cancel_lru_locks osc > /dev/null
8142         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8143         lctl set_param fail_loc=0
8144         [[ $reads -eq $writes ]] ||
8145                 error "read $reads blocks, must be $writes blocks"
8146 }
8147 run_test 121 "read cancel race ========="
8148
8149 test_123a() { # was test 123, statahead(bug 11401)
8150         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8151         SLOWOK=0
8152         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8153             log "testing on UP system. Performance may be not as good as expected."
8154                         SLOWOK=1
8155         fi
8156
8157         rm -rf $DIR/$tdir
8158         test_mkdir -p $DIR/$tdir
8159         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8160         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8161         MULT=10
8162         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8163                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8164
8165                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8166                 lctl set_param -n llite.*.statahead_max 0
8167                 lctl get_param llite.*.statahead_max
8168                 cancel_lru_locks mdc
8169                 cancel_lru_locks osc
8170                 stime=`date +%s`
8171                 time ls -l $DIR/$tdir | wc -l
8172                 etime=`date +%s`
8173                 delta=$((etime - stime))
8174                 log "ls $i files without statahead: $delta sec"
8175                 lctl set_param llite.*.statahead_max=$max
8176
8177                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8178                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8179                 cancel_lru_locks mdc
8180                 cancel_lru_locks osc
8181                 stime=`date +%s`
8182                 time ls -l $DIR/$tdir | wc -l
8183                 etime=`date +%s`
8184                 delta_sa=$((etime - stime))
8185                 log "ls $i files with statahead: $delta_sa sec"
8186                 lctl get_param -n llite.*.statahead_stats
8187                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8188
8189                 [[ $swrong -lt $ewrong ]] &&
8190                         log "statahead was stopped, maybe too many locks held!"
8191                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8192
8193                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8194                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8195                     lctl set_param -n llite.*.statahead_max 0
8196                     lctl get_param llite.*.statahead_max
8197                     cancel_lru_locks mdc
8198                     cancel_lru_locks osc
8199                     stime=`date +%s`
8200                     time ls -l $DIR/$tdir | wc -l
8201                     etime=`date +%s`
8202                     delta=$((etime - stime))
8203                     log "ls $i files again without statahead: $delta sec"
8204                     lctl set_param llite.*.statahead_max=$max
8205                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8206                         if [  $SLOWOK -eq 0 ]; then
8207                                 error "ls $i files is slower with statahead!"
8208                         else
8209                                 log "ls $i files is slower with statahead!"
8210                         fi
8211                         break
8212                     fi
8213                 fi
8214
8215                 [ $delta -gt 20 ] && break
8216                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8217                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8218         done
8219         log "ls done"
8220
8221         stime=`date +%s`
8222         rm -r $DIR/$tdir
8223         sync
8224         etime=`date +%s`
8225         delta=$((etime - stime))
8226         log "rm -r $DIR/$tdir/: $delta seconds"
8227         log "rm done"
8228         lctl get_param -n llite.*.statahead_stats
8229 }
8230 run_test 123a "verify statahead work"
8231
8232 test_123b () { # statahead(bug 15027)
8233         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8234         test_mkdir -p $DIR/$tdir
8235         createmany -o $DIR/$tdir/$tfile-%d 1000
8236
8237         cancel_lru_locks mdc
8238         cancel_lru_locks osc
8239
8240 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8241         lctl set_param fail_loc=0x80000803
8242         ls -lR $DIR/$tdir > /dev/null
8243         log "ls done"
8244         lctl set_param fail_loc=0x0
8245         lctl get_param -n llite.*.statahead_stats
8246         rm -r $DIR/$tdir
8247         sync
8248
8249 }
8250 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8251
8252 test_124a() {
8253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8254         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8255                 skip "no lru resize on server" && return 0
8256         local NR=2000
8257         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8258
8259         log "create $NR files at $DIR/$tdir"
8260         createmany -o $DIR/$tdir/f $NR ||
8261                 error "failed to create $NR files in $DIR/$tdir"
8262
8263         cancel_lru_locks mdc
8264         ls -l $DIR/$tdir > /dev/null
8265
8266         local NSDIR=""
8267         local LRU_SIZE=0
8268         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8269                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8270                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8271                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8272                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8273                         log "NSDIR=$NSDIR"
8274                         log "NS=$(basename $NSDIR)"
8275                         break
8276                 fi
8277         done
8278
8279         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8280                 skip "Not enough cached locks created!"
8281                 return 0
8282         fi
8283         log "LRU=$LRU_SIZE"
8284
8285         local SLEEP=30
8286
8287         # We know that lru resize allows one client to hold $LIMIT locks
8288         # for 10h. After that locks begin to be killed by client.
8289         local MAX_HRS=10
8290         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8291         log "LIMIT=$LIMIT"
8292         if [ $LIMIT -lt $LRU_SIZE ]; then
8293             skip "Limit is too small $LIMIT"
8294             return 0
8295         fi
8296
8297         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8298         # killing locks. Some time was spent for creating locks. This means
8299         # that up to the moment of sleep finish we must have killed some of
8300         # them (10-100 locks). This depends on how fast ther were created.
8301         # Many of them were touched in almost the same moment and thus will
8302         # be killed in groups.
8303         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8304
8305         # Use $LRU_SIZE_B here to take into account real number of locks
8306         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8307         local LRU_SIZE_B=$LRU_SIZE
8308         log "LVF=$LVF"
8309         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8310         log "OLD_LVF=$OLD_LVF"
8311         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8312
8313         # Let's make sure that we really have some margin. Client checks
8314         # cached locks every 10 sec.
8315         SLEEP=$((SLEEP+20))
8316         log "Sleep ${SLEEP} sec"
8317         local SEC=0
8318         while ((SEC<$SLEEP)); do
8319                 echo -n "..."
8320                 sleep 5
8321                 SEC=$((SEC+5))
8322                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8323                 echo -n "$LRU_SIZE"
8324         done
8325         echo ""
8326         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8327         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8328
8329         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8330                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8331                 unlinkmany $DIR/$tdir/f $NR
8332                 return
8333         }
8334
8335         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8336         log "unlink $NR files at $DIR/$tdir"
8337         unlinkmany $DIR/$tdir/f $NR
8338 }
8339 run_test 124a "lru resize ======================================="
8340
8341 get_max_pool_limit()
8342 {
8343         local limit=$($LCTL get_param \
8344                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8345         local max=0
8346         for l in $limit; do
8347                 if [[ $l -gt $max ]]; then
8348                         max=$l
8349                 fi
8350         done
8351         echo $max
8352 }
8353
8354 test_124b() {
8355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8356         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8357                 skip "no lru resize on server" && return 0
8358
8359         LIMIT=$(get_max_pool_limit)
8360
8361         NR=$(($(default_lru_size)*20))
8362         if [[ $NR -gt $LIMIT ]]; then
8363                 log "Limit lock number by $LIMIT locks"
8364                 NR=$LIMIT
8365         fi
8366         lru_resize_disable mdc
8367         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8368                 error "failed to create $DIR/$tdir/disable_lru_resize"
8369
8370         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8371         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8372         cancel_lru_locks mdc
8373         stime=`date +%s`
8374         PID=""
8375         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8376         PID="$PID $!"
8377         sleep 2
8378         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8379         PID="$PID $!"
8380         sleep 2
8381         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8382         PID="$PID $!"
8383         wait $PID
8384         etime=`date +%s`
8385         nolruresize_delta=$((etime-stime))
8386         log "ls -la time: $nolruresize_delta seconds"
8387         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8388         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8389
8390         lru_resize_enable mdc
8391         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8392                 error "failed to create $DIR/$tdir/enable_lru_resize"
8393
8394         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8395         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8396         cancel_lru_locks mdc
8397         stime=`date +%s`
8398         PID=""
8399         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8400         PID="$PID $!"
8401         sleep 2
8402         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8403         PID="$PID $!"
8404         sleep 2
8405         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8406         PID="$PID $!"
8407         wait $PID
8408         etime=`date +%s`
8409         lruresize_delta=$((etime-stime))
8410         log "ls -la time: $lruresize_delta seconds"
8411         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8412
8413         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8414                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8415         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8416                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8417         else
8418                 log "lru resize performs the same with no lru resize"
8419         fi
8420         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8421 }
8422 run_test 124b "lru resize (performance test) ======================="
8423
8424 test_124c() {
8425         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8426         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8427                 skip "no lru resize on server" && return 0
8428
8429         # cache ununsed locks on client
8430         local nr=100
8431         cancel_lru_locks mdc
8432         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8433         createmany -o $DIR/$tdir/f $nr ||
8434                 error "failed to create $nr files in $DIR/$tdir"
8435         ls -l $DIR/$tdir > /dev/null
8436
8437         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8438         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8439         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8440         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8441         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8442
8443         # set lru_max_age to 1 sec
8444         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8445         echo "sleep $((recalc_p * 2)) seconds..."
8446         sleep $((recalc_p * 2))
8447
8448         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8449         # restore lru_max_age
8450         $LCTL set_param -n $nsdir.lru_max_age $max_age
8451         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8452         unlinkmany $DIR/$tdir/f $nr
8453 }
8454 run_test 124c "LRUR cancel very aged locks"
8455
8456 test_125() { # 13358
8457         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8458         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8459         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8460         test_mkdir -p $DIR/d125 || error "mkdir failed"
8461         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8462         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8463         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8464 }
8465 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8466
8467 test_126() { # bug 12829/13455
8468         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8469         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8470         $GSS && skip "must run as gss disabled" && return
8471
8472         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8473         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8474         rm -f $DIR/$tfile
8475         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8476 }
8477 run_test 126 "check that the fsgid provided by the client is taken into account"
8478
8479 test_127a() { # bug 15521
8480         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8481         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8482         $LCTL set_param osc.*.stats=0
8483         FSIZE=$((2048 * 1024))
8484         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8485         cancel_lru_locks osc
8486         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8487
8488         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8489         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8490                 echo "got $COUNT $NAME"
8491                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8492                 eval $NAME=$COUNT || error "Wrong proc format"
8493
8494                 case $NAME in
8495                         read_bytes|write_bytes)
8496                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8497                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8498                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8499                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8500                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8501                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8502                                 error "sumsquare is too small: $SUMSQ"
8503                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8504                                 error "sumsquare is too big: $SUMSQ"
8505                         ;;
8506                         *) ;;
8507                 esac
8508         done < $DIR/${tfile}.tmp
8509
8510         #check that we actually got some stats
8511         [ "$read_bytes" ] || error "Missing read_bytes stats"
8512         [ "$write_bytes" ] || error "Missing write_bytes stats"
8513         [ "$read_bytes" != 0 ] || error "no read done"
8514         [ "$write_bytes" != 0 ] || error "no write done"
8515 }
8516 run_test 127a "verify the client stats are sane"
8517
8518 test_127b() { # bug LU-333
8519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8520         $LCTL set_param llite.*.stats=0
8521         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8522         # perform 2 reads and writes so MAX is different from SUM.
8523         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8524         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8525         cancel_lru_locks osc
8526         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8527         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8528
8529         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8530         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8531                 echo "got $COUNT $NAME"
8532                 eval $NAME=$COUNT || error "Wrong proc format"
8533
8534         case $NAME in
8535                 read_bytes)
8536                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8537                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8538                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8539                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8540                         ;;
8541                 write_bytes)
8542                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8543                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8544                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8545                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8546                         ;;
8547                         *) ;;
8548                 esac
8549         done < $TMP/${tfile}.tmp
8550
8551         #check that we actually got some stats
8552         [ "$read_bytes" ] || error "Missing read_bytes stats"
8553         [ "$write_bytes" ] || error "Missing write_bytes stats"
8554         [ "$read_bytes" != 0 ] || error "no read done"
8555         [ "$write_bytes" != 0 ] || error "no write done"
8556 }
8557 run_test 127b "verify the llite client stats are sane"
8558
8559 test_128() { # bug 15212
8560         touch $DIR/$tfile
8561         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8562                 find $DIR/$tfile
8563                 find $DIR/$tfile
8564         EOF
8565
8566         result=$(grep error $TMP/$tfile.log)
8567         rm -f $DIR/$tfile
8568         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8569 }
8570 run_test 128 "interactive lfs for 2 consecutive find's"
8571
8572 set_dir_limits () {
8573         local mntdev
8574         local canondev
8575         local node
8576
8577         local LDPROC=/proc/fs/ldiskfs
8578         local facets=$(get_facets MDS)
8579
8580         for facet in ${facets//,/ }; do
8581                 canondev=$(ldiskfs_canon \
8582                            *.$(convert_facet2label $facet).mntdev $facet)
8583                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8584                                                 LDPROC=/sys/fs/ldiskfs
8585                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8586         done
8587 }
8588
8589 test_129() {
8590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8591         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8592                 skip "Only applicable to ldiskfs-based MDTs"
8593                 return
8594         fi
8595         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8596         ENOSPC=28
8597         EFBIG=27
8598
8599         rm -rf $DIR/$tdir
8600         test_mkdir -p $DIR/$tdir
8601
8602         # block size of mds1
8603         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8604         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8605         local MAX=$((MDSBLOCKSIZE * 3))
8606         set_dir_limits $MAX
8607         local I=$(stat -c%s "$DIR/$tdir")
8608         local J=0
8609         local STRIPE_COUNT=1
8610         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8611         MAX=$((MAX*STRIPE_COUNT))
8612         while [[ $I -le $MAX ]]; do
8613                 $MULTIOP $DIR/$tdir/$J Oc
8614                 rc=$?
8615                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8616                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8617                 #and EFBIG for previous versions
8618                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8619                         set_dir_limits 0
8620                         echo "return code $rc received as expected"
8621                         multiop $DIR/$tdir/$J Oc ||
8622                                 error_exit "multiop failed w/o dir size limit"
8623
8624                         I=$(stat -c%s "$DIR/$tdir")
8625
8626                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8627                                         $(version_code 2.4.51) ]
8628                         then
8629                                 [[ $I -eq $MAX ]] && return 0
8630                         else
8631                                 [[ $I -gt $MAX ]] && return 0
8632                         fi
8633                         error_exit "current dir size $I, previous limit $MAX"
8634                 elif [ $rc -ne 0 ]; then
8635                         set_dir_limits 0
8636                         error_exit "return code $rc received instead of expected " \
8637                                    "$EFBIG or $ENOSPC, files in dir $I"
8638                 fi
8639                 J=$((J+1))
8640                 I=$(stat -c%s "$DIR/$tdir")
8641         done
8642
8643         set_dir_limits 0
8644         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8645 }
8646 run_test 129 "test directory size limit ========================"
8647
8648 OLDIFS="$IFS"
8649 cleanup_130() {
8650         trap 0
8651         IFS="$OLDIFS"
8652 }
8653
8654 test_130a() {
8655         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8656         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8657                 return
8658
8659         trap cleanup_130 EXIT RETURN
8660
8661         local fm_file=$DIR/$tfile
8662         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8663         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8664                 error "dd failed for $fm_file"
8665
8666         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8667         filefrag -ves $fm_file
8668         RC=$?
8669         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8670                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8671         [ $RC != 0 ] && error "filefrag $fm_file failed"
8672
8673         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8674                       grep -v "ext:" | grep -v "found")
8675         lun=$($GETSTRIPE -i $fm_file)
8676
8677         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8678         IFS=$'\n'
8679         tot_len=0
8680         for line in $filefrag_op
8681         do
8682                 frag_lun=`echo $line | cut -d: -f5`
8683                 ext_len=`echo $line | cut -d: -f4`
8684                 if (( $frag_lun != $lun )); then
8685                         cleanup_130
8686                         error "FIEMAP on 1-stripe file($fm_file) failed"
8687                         return
8688                 fi
8689                 (( tot_len += ext_len ))
8690         done
8691
8692         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8693                 cleanup_130
8694                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8695                 return
8696         fi
8697
8698         cleanup_130
8699
8700         echo "FIEMAP on single striped file succeeded"
8701 }
8702 run_test 130a "FIEMAP (1-stripe file)"
8703
8704 test_130b() {
8705         [ "$OSTCOUNT" -lt "2" ] &&
8706                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8707
8708         [ "$OSTCOUNT" -ge "10" ] &&
8709                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8710
8711         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8712         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8713                 return
8714
8715         trap cleanup_130 EXIT RETURN
8716
8717         local fm_file=$DIR/$tfile
8718         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8719         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8720                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8721
8722         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8723                 error "dd failed on $fm_file"
8724
8725         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8726         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8727                       grep -v "ext:" | grep -v "found")
8728
8729         last_lun=$(echo $filefrag_op | cut -d: -f5)
8730
8731         IFS=$'\n'
8732         tot_len=0
8733         num_luns=1
8734         for line in $filefrag_op
8735         do
8736                 frag_lun=`echo $line | cut -d: -f5`
8737                 ext_len=`echo $line | cut -d: -f4`
8738                 if (( $frag_lun != $last_lun )); then
8739                         if (( tot_len != 1024 )); then
8740                                 cleanup_130
8741                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8742                                 return
8743                         else
8744                                 (( num_luns += 1 ))
8745                                 tot_len=0
8746                         fi
8747                 fi
8748                 (( tot_len += ext_len ))
8749                 last_lun=$frag_lun
8750         done
8751         if (( num_luns != 2 || tot_len != 1024 )); then
8752                 cleanup_130
8753                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8754                 return
8755         fi
8756
8757         cleanup_130
8758
8759         echo "FIEMAP on 2-stripe file succeeded"
8760 }
8761 run_test 130b "FIEMAP (2-stripe file)"
8762
8763 test_130c() {
8764         [ "$OSTCOUNT" -lt "2" ] &&
8765                 skip_env "skipping FIEMAP on 2-stripe file" && return
8766
8767         [ "$OSTCOUNT" -ge "10" ] &&
8768                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8769
8770         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8771         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8772                 return
8773
8774         trap cleanup_130 EXIT RETURN
8775
8776         local fm_file=$DIR/$tfile
8777         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8778         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8779                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8780
8781         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8782
8783         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8784         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8785
8786         last_lun=`echo $filefrag_op | cut -d: -f5`
8787
8788         IFS=$'\n'
8789         tot_len=0
8790         num_luns=1
8791         for line in $filefrag_op
8792         do
8793                 frag_lun=`echo $line | cut -d: -f5`
8794                 ext_len=`echo $line | cut -d: -f4`
8795                 if (( $frag_lun != $last_lun )); then
8796                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8797                         if (( logical != 512 )); then
8798                                 cleanup_130
8799                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8800                                 return
8801                         fi
8802                         if (( tot_len != 512 )); then
8803                                 cleanup_130
8804                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8805                                 return
8806                         else
8807                                 (( num_luns += 1 ))
8808                                 tot_len=0
8809                         fi
8810                 fi
8811                 (( tot_len += ext_len ))
8812                 last_lun=$frag_lun
8813         done
8814         if (( num_luns != 2 || tot_len != 512 )); then
8815                 cleanup_130
8816                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8817                 return
8818         fi
8819
8820         cleanup_130
8821
8822         echo "FIEMAP on 2-stripe file with hole succeeded"
8823 }
8824 run_test 130c "FIEMAP (2-stripe file with hole)"
8825
8826 test_130d() {
8827         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8828
8829         [ "$OSTCOUNT" -ge "10" ] &&
8830                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8831
8832         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8833         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8834
8835         trap cleanup_130 EXIT RETURN
8836
8837         local fm_file=$DIR/$tfile
8838         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8839         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8840                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8841
8842         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8843         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8844                 error "dd failed on $fm_file"
8845
8846         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8847         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8848                 grep -v "ext:" | grep -v "found"`
8849
8850         last_lun=`echo $filefrag_op | cut -d: -f5`
8851
8852         IFS=$'\n'
8853         tot_len=0
8854         num_luns=1
8855         for line in $filefrag_op
8856         do
8857                 frag_lun=`echo $line | cut -d: -f5`
8858                 ext_len=`echo $line | cut -d: -f4`
8859                 if (( $frag_lun != $last_lun )); then
8860                         if (( tot_len != 1024 )); then
8861                                 cleanup_130
8862                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8863                                 return
8864                         else
8865                                 (( num_luns += 1 ))
8866                                 tot_len=0
8867                         fi
8868                 fi
8869                 (( tot_len += ext_len ))
8870                 last_lun=$frag_lun
8871         done
8872         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8873                 cleanup_130
8874                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8875                 return
8876         fi
8877
8878         cleanup_130
8879
8880         echo "FIEMAP on N-stripe file succeeded"
8881 }
8882 run_test 130d "FIEMAP (N-stripe file)"
8883
8884 test_130e() {
8885         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8886
8887         [ "$OSTCOUNT" -ge "10" ] &&
8888                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8889
8890         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8891         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8892
8893         trap cleanup_130 EXIT RETURN
8894
8895         local fm_file=$DIR/$tfile
8896         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8897         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8898                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8899
8900         NUM_BLKS=512
8901         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8902         for ((i = 0; i < $NUM_BLKS; i++))
8903         do
8904                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8905         done
8906
8907         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8908         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8909
8910         last_lun=`echo $filefrag_op | cut -d: -f5`
8911
8912         IFS=$'\n'
8913         tot_len=0
8914         num_luns=1
8915         for line in $filefrag_op
8916         do
8917                 frag_lun=`echo $line | cut -d: -f5`
8918                 ext_len=`echo $line | cut -d: -f4`
8919                 if (( $frag_lun != $last_lun )); then
8920                         if (( tot_len != $EXPECTED_LEN )); then
8921                                 cleanup_130
8922                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8923                                 return
8924                         else
8925                                 (( num_luns += 1 ))
8926                                 tot_len=0
8927                         fi
8928                 fi
8929                 (( tot_len += ext_len ))
8930                 last_lun=$frag_lun
8931         done
8932         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8933                 cleanup_130
8934                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8935                 return
8936         fi
8937
8938         cleanup_130
8939
8940         echo "FIEMAP with continuation calls succeeded"
8941 }
8942 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8943
8944 # Test for writev/readv
8945 test_131a() {
8946         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8947         error "writev test failed"
8948         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8949         error "readv failed"
8950         rm -f $DIR/$tfile
8951 }
8952 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8953
8954 test_131b() {
8955         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8956         error "append writev test failed"
8957         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8958         error "append writev test failed"
8959         rm -f $DIR/$tfile
8960 }
8961 run_test 131b "test append writev"
8962
8963 test_131c() {
8964         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8965         error "NOT PASS"
8966 }
8967 run_test 131c "test read/write on file w/o objects"
8968
8969 test_131d() {
8970         rwv -f $DIR/$tfile -w -n 1 1572864
8971         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8972         if [ "$NOB" != 1572864 ]; then
8973                 error "Short read filed: read $NOB bytes instead of 1572864"
8974         fi
8975         rm -f $DIR/$tfile
8976 }
8977 run_test 131d "test short read"
8978
8979 test_131e() {
8980         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8981         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8982         error "read hitting hole failed"
8983         rm -f $DIR/$tfile
8984 }
8985 run_test 131e "test read hitting hole"
8986
8987 check_stats() {
8988         local res
8989         local count
8990         case $1 in
8991         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8992                  ;;
8993         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8994                  ;;
8995         *) error "Wrong argument $1" ;;
8996         esac
8997         echo $res
8998         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8999         # if the argument $3 is zero, it means any stat increment is ok.
9000         if [[ $3 -gt 0 ]]; then
9001                 count=$(echo $res | awk '{ print $2 }')
9002                 [[ $count -ne $3 ]] &&
9003                         error "The $2 counter on $1 is wrong - expected $3"
9004         fi
9005 }
9006
9007 test_133a() {
9008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9009         remote_ost_nodsh && skip "remote OST with nodsh" && return
9010         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9011
9012         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9013                 { skip "MDS doesn't support rename stats"; return; }
9014         local testdir=$DIR/${tdir}/stats_testdir
9015         mkdir -p $DIR/${tdir}
9016
9017         # clear stats.
9018         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9019         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9020
9021         # verify mdt stats first.
9022         mkdir ${testdir} || error "mkdir failed"
9023         check_stats $SINGLEMDS "mkdir" 1
9024         touch ${testdir}/${tfile} || "touch failed"
9025         check_stats $SINGLEMDS "open" 1
9026         check_stats $SINGLEMDS "close" 1
9027         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9028         check_stats $SINGLEMDS "mknod" 1
9029         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9030         check_stats $SINGLEMDS "unlink" 1
9031         rm -f ${testdir}/${tfile} || error "file remove failed"
9032         check_stats $SINGLEMDS "unlink" 2
9033
9034         # remove working dir and check mdt stats again.
9035         rmdir ${testdir} || error "rmdir failed"
9036         check_stats $SINGLEMDS "rmdir" 1
9037
9038         local testdir1=$DIR/${tdir}/stats_testdir1
9039         mkdir -p ${testdir}
9040         mkdir -p ${testdir1}
9041         touch ${testdir1}/test1
9042         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9043         check_stats $SINGLEMDS "crossdir_rename" 1
9044
9045         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9046         check_stats $SINGLEMDS "samedir_rename" 1
9047
9048         rm -rf $DIR/${tdir}
9049 }
9050 run_test 133a "Verifying MDT stats ========================================"
9051
9052 test_133b() {
9053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9054         remote_ost_nodsh && skip "remote OST with nodsh" && return
9055         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9056         local testdir=$DIR/${tdir}/stats_testdir
9057         mkdir -p ${testdir} || error "mkdir failed"
9058         touch ${testdir}/${tfile} || "touch failed"
9059         cancel_lru_locks mdc
9060
9061         # clear stats.
9062         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9063         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9064
9065         # extra mdt stats verification.
9066         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9067         check_stats $SINGLEMDS "setattr" 1
9068         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9069         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9070         then            # LU-1740
9071                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9072                 check_stats $SINGLEMDS "getattr" 1
9073         fi
9074         $LFS df || error "lfs failed"
9075         check_stats $SINGLEMDS "statfs" 1
9076
9077         rm -rf $DIR/${tdir}
9078 }
9079 run_test 133b "Verifying extra MDT stats =================================="
9080
9081 test_133c() {
9082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9083         remote_ost_nodsh && skip "remote OST with nodsh" && return
9084         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9085         local testdir=$DIR/${tdir}/stats_testdir
9086         test_mkdir -p ${testdir} || error "mkdir failed"
9087
9088         # verify obdfilter stats.
9089         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9090         sync
9091         cancel_lru_locks osc
9092         wait_delete_completed
9093
9094         # clear stats.
9095         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9096         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9097
9098         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9099         sync
9100         cancel_lru_locks osc
9101         check_stats ost "write" 1
9102
9103         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9104         check_stats ost "read" 1
9105
9106         > ${testdir}/${tfile} || error "truncate failed"
9107         check_stats ost "punch" 1
9108
9109         rm -f ${testdir}/${tfile} || error "file remove failed"
9110         wait_delete_completed
9111         check_stats ost "destroy" 1
9112
9113         rm -rf $DIR/${tdir}
9114 }
9115 run_test 133c "Verifying OST stats ========================================"
9116
9117 order_2() {
9118         local value=$1
9119         local orig=$value
9120         local order=1
9121
9122         while [ $value -ge 2 ]; do
9123                 order=$((order*2))
9124                 value=$((value/2))
9125         done
9126
9127         if [ $orig -gt $order ]; then
9128                 order=$((order*2))
9129         fi
9130         echo $order
9131 }
9132
9133 size_in_KMGT() {
9134     local value=$1
9135     local size=('K' 'M' 'G' 'T');
9136     local i=0
9137     local size_string=$value
9138
9139     while [ $value -ge 1024 ]; do
9140         if [ $i -gt 3 ]; then
9141             #T is the biggest unit we get here, if that is bigger,
9142             #just return XXXT
9143             size_string=${value}T
9144             break
9145         fi
9146         value=$((value >> 10))
9147         if [ $value -lt 1024 ]; then
9148             size_string=${value}${size[$i]}
9149             break
9150         fi
9151         i=$((i + 1))
9152     done
9153
9154     echo $size_string
9155 }
9156
9157 get_rename_size() {
9158     local size=$1
9159     local context=${2:-.}
9160     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9161                 grep -A1 $context |
9162                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9163     echo $sample
9164 }
9165
9166 test_133d() {
9167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9168         remote_ost_nodsh && skip "remote OST with nodsh" && return
9169         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9170         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9171         { skip "MDS doesn't support rename stats"; return; }
9172
9173         local testdir1=$DIR/${tdir}/stats_testdir1
9174         local testdir2=$DIR/${tdir}/stats_testdir2
9175
9176         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9177
9178         mkdir -p ${testdir1} || error "mkdir failed"
9179         mkdir -p ${testdir2} || error "mkdir failed"
9180
9181         createmany -o $testdir1/test 512 || error "createmany failed"
9182
9183         # check samedir rename size
9184         mv ${testdir1}/test0 ${testdir1}/test_0
9185
9186         local testdir1_size=$(ls -l $DIR/${tdir} |
9187                 awk '/stats_testdir1/ {print $5}')
9188         local testdir2_size=$(ls -l $DIR/${tdir} |
9189                 awk '/stats_testdir2/ {print $5}')
9190
9191         testdir1_size=$(order_2 $testdir1_size)
9192         testdir2_size=$(order_2 $testdir2_size)
9193
9194         testdir1_size=$(size_in_KMGT $testdir1_size)
9195         testdir2_size=$(size_in_KMGT $testdir2_size)
9196
9197         echo "source rename dir size: ${testdir1_size}"
9198         echo "target rename dir size: ${testdir2_size}"
9199
9200         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9201         eval $cmd || error "$cmd failed"
9202         local samedir=$($cmd | grep 'same_dir')
9203         local same_sample=$(get_rename_size $testdir1_size)
9204         [ -z "$samedir" ] && error "samedir_rename_size count error"
9205         [[ $same_sample -eq 1 ]] ||
9206                 error "samedir_rename_size error $same_sample"
9207         echo "Check same dir rename stats success"
9208
9209         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9210
9211         # check crossdir rename size
9212         mv ${testdir1}/test_0 ${testdir2}/test_0
9213
9214         testdir1_size=$(ls -l $DIR/${tdir} |
9215                 awk '/stats_testdir1/ {print $5}')
9216         testdir2_size=$(ls -l $DIR/${tdir} |
9217                 awk '/stats_testdir2/ {print $5}')
9218
9219         testdir1_size=$(order_2 $testdir1_size)
9220         testdir2_size=$(order_2 $testdir2_size)
9221
9222         testdir1_size=$(size_in_KMGT $testdir1_size)
9223         testdir2_size=$(size_in_KMGT $testdir2_size)
9224
9225         echo "source rename dir size: ${testdir1_size}"
9226         echo "target rename dir size: ${testdir2_size}"
9227
9228         eval $cmd || error "$cmd failed"
9229         local crossdir=$($cmd | grep 'crossdir')
9230         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9231         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9232         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9233         [[ $src_sample -eq 1 ]] ||
9234                 error "crossdir_rename_size error $src_sample"
9235         [[ $tgt_sample -eq 1 ]] ||
9236                 error "crossdir_rename_size error $tgt_sample"
9237         echo "Check cross dir rename stats success"
9238         rm -rf $DIR/${tdir}
9239 }
9240 run_test 133d "Verifying rename_stats ========================================"
9241
9242 test_133e() {
9243         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9244         remote_ost_nodsh && skip "remote OST with nodsh" && return
9245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9246         local testdir=$DIR/${tdir}/stats_testdir
9247         local ctr f0 f1 bs=32768 count=42 sum
9248
9249         mkdir -p ${testdir} || error "mkdir failed"
9250
9251         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9252
9253         for ctr in {write,read}_bytes; do
9254                 sync
9255                 cancel_lru_locks osc
9256
9257                 do_facet ost1 $LCTL set_param -n \
9258                         "obdfilter.*.exports.clear=clear"
9259
9260                 if [ $ctr = write_bytes ]; then
9261                         f0=/dev/zero
9262                         f1=${testdir}/${tfile}
9263                 else
9264                         f0=${testdir}/${tfile}
9265                         f1=/dev/null
9266                 fi
9267
9268                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9269                         error "dd failed"
9270                 sync
9271                 cancel_lru_locks osc
9272
9273                 sum=$(do_facet ost1 $LCTL get_param \
9274                         "obdfilter.*.exports.*.stats" |
9275                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9276                                 $1 == ctr { sum += $7 }
9277                                 END { printf("%0.0f", sum) }')
9278
9279                 if ((sum != bs * count)); then
9280                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9281                 fi
9282         done
9283
9284         rm -rf $DIR/${tdir}
9285 }
9286 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9287
9288 test_133f() {
9289         local proc_dirs
9290
9291         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9292 /sys/fs/lustre/ /sys/fs/lnet/"
9293         local dir
9294         for dir in $dirs; do
9295                 if [ -d $dir ]; then
9296                         proc_dirs="$proc_dirs $dir"
9297                 fi
9298         done
9299
9300         local facet
9301
9302         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9303         remote_ost_nodsh && skip "remote OST with nodsh" && return
9304         # First without trusting modes.
9305         find $proc_dirs -exec cat '{}' \; &> /dev/null
9306
9307         # Second verifying readability.
9308         find $proc_dirs \
9309                 -type f \
9310                 -exec cat '{}' \; &> /dev/null ||
9311                         error "proc file read failed"
9312
9313         for facet in $SINGLEMDS ost1; do
9314                 do_facet $facet find $proc_dirs \
9315                         ! -name req_history \
9316                         -exec cat '{}' \\\; &> /dev/null
9317
9318                 do_facet $facet find $proc_dirs \
9319                         ! -name req_history \
9320                         -type f \
9321                         -exec cat '{}' \\\; &> /dev/null ||
9322                                 error "proc file read failed"
9323         done
9324 }
9325 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9326
9327 test_133g() {
9328         local proc_dirs
9329
9330         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9331 /sys/fs/lustre/ /sys/fs/lnet/"
9332         local dir
9333         for dir in $dirs; do
9334                 if [ -d $dir ]; then
9335                         proc_dirs="$proc_dirs $dir"
9336                 fi
9337         done
9338
9339         local facet
9340
9341         # Second verifying readability.
9342         find $proc_dirs \
9343                 -type f \
9344                 -not -name force_lbug \
9345                 -not -name changelog_mask \
9346                 -exec badarea_io '{}' \; &> /dev/null ||
9347                 error "find $proc_dirs failed"
9348
9349         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9350                 skip "Too old lustre on MDS" && return
9351
9352         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9353                 skip "Too old lustre on ost1" && return
9354
9355         for facet in $SINGLEMDS ost1; do
9356                 do_facet $facet find $proc_dirs \
9357                         -type f \
9358                         -not -name force_lbug \
9359                         -not -name changelog_mask \
9360                         -exec badarea_io '{}' \\\; &> /dev/null ||
9361                 error "$facet find $proc_dirs failed"
9362
9363         done
9364
9365         # remount the FS in case writes/reads /proc break the FS
9366         cleanup || error "failed to unmount"
9367         setup || error "failed to setup"
9368         true
9369 }
9370 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9371
9372 test_140() { #bug-17379
9373         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9374         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9375         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9376         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9377
9378         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9379         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9380         local i=0
9381         while i=`expr $i + 1`; do
9382                 test_mkdir -p $i || error "Creating dir $i"
9383                 cd $i || error "Changing to $i"
9384                 ln -s ../stat stat || error "Creating stat symlink"
9385                 # Read the symlink until ELOOP present,
9386                 # not LBUGing the system is considered success,
9387                 # we didn't overrun the stack.
9388                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9389                 [ $ret -ne 0 ] && {
9390                         if [ $ret -eq 40 ]; then
9391                                 break  # -ELOOP
9392                         else
9393                                 error "Open stat symlink"
9394                                 return
9395                         fi
9396                 }
9397         done
9398         i=`expr $i - 1`
9399         echo "The symlink depth = $i"
9400         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9401                                         error "Invalid symlink depth"
9402
9403         # Test recursive symlink
9404         ln -s symlink_self symlink_self
9405         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9406         echo "open symlink_self returns $ret"
9407         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9408 }
9409 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9410
9411 test_150() {
9412         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9413         local TF="$TMP/$tfile"
9414
9415         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9416         cp $TF $DIR/$tfile
9417         cancel_lru_locks osc
9418         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9419         remount_client $MOUNT
9420         df -P $MOUNT
9421         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9422
9423         $TRUNCATE $TF 6000
9424         $TRUNCATE $DIR/$tfile 6000
9425         cancel_lru_locks osc
9426         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9427
9428         echo "12345" >>$TF
9429         echo "12345" >>$DIR/$tfile
9430         cancel_lru_locks osc
9431         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9432
9433         echo "12345" >>$TF
9434         echo "12345" >>$DIR/$tfile
9435         cancel_lru_locks osc
9436         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9437
9438         rm -f $TF
9439         true
9440 }
9441 run_test 150 "truncate/append tests"
9442
9443 #LU-2902 roc_hit was not able to read all values from lproc
9444 function roc_hit_init() {
9445         local list=$(comma_list $(osts_nodes))
9446         local dir=$DIR/$tdir-check
9447         local file=$dir/file
9448         local BEFORE
9449         local AFTER
9450         local idx
9451
9452         test_mkdir -p $dir
9453         #use setstripe to do a write to every ost
9454         for i in $(seq 0 $((OSTCOUNT-1))); do
9455                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9456                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9457                 idx=$(printf %04x $i)
9458                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9459                         awk '$1 == "cache_access" {sum += $7}
9460                                 END { printf("%0.0f", sum) }')
9461
9462                 cancel_lru_locks osc
9463                 cat $file >/dev/null
9464
9465                 AFTER=$(get_osd_param $list *OST*$idx stats |
9466                         awk '$1 == "cache_access" {sum += $7}
9467                                 END { printf("%0.0f", sum) }')
9468
9469                 echo BEFORE:$BEFORE AFTER:$AFTER
9470                 if ! let "AFTER - BEFORE == 4"; then
9471                         rm -rf $dir
9472                         error "roc_hit is not safe to use"
9473                 fi
9474                 rm $file
9475         done
9476
9477         rm -rf $dir
9478 }
9479
9480 function roc_hit() {
9481         local list=$(comma_list $(osts_nodes))
9482         echo $(get_osd_param $list '' stats |
9483                 awk '$1 == "cache_hit" {sum += $7}
9484                         END { printf("%0.0f", sum) }')
9485 }
9486
9487 function set_cache() {
9488         local on=1
9489
9490         if [ "$2" == "off" ]; then
9491                 on=0;
9492         fi
9493         local list=$(comma_list $(osts_nodes))
9494         set_osd_param $list '' $1_cache_enable $on
9495
9496         cancel_lru_locks osc
9497 }
9498
9499 test_151() {
9500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9501         remote_ost_nodsh && skip "remote OST with nodsh" && return
9502
9503         local CPAGES=3
9504         local list=$(comma_list $(osts_nodes))
9505
9506         # check whether obdfilter is cache capable at all
9507         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9508                 echo "not cache-capable obdfilter"
9509                 return 0
9510         fi
9511
9512         # check cache is enabled on all obdfilters
9513         if get_osd_param $list '' read_cache_enable | grep 0; then
9514                 echo "oss cache is disabled"
9515                 return 0
9516         fi
9517
9518         set_osd_param $list '' writethrough_cache_enable 1
9519
9520         # check write cache is enabled on all obdfilters
9521         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9522                 echo "oss write cache is NOT enabled"
9523                 return 0
9524         fi
9525
9526         roc_hit_init
9527
9528         #define OBD_FAIL_OBD_NO_LRU  0x609
9529         do_nodes $list $LCTL set_param fail_loc=0x609
9530
9531         # pages should be in the case right after write
9532         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9533                 error "dd failed"
9534
9535         local BEFORE=$(roc_hit)
9536         cancel_lru_locks osc
9537         cat $DIR/$tfile >/dev/null
9538         local AFTER=$(roc_hit)
9539
9540         do_nodes $list $LCTL set_param fail_loc=0
9541
9542         if ! let "AFTER - BEFORE == CPAGES"; then
9543                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9544         fi
9545
9546         # the following read invalidates the cache
9547         cancel_lru_locks osc
9548         set_osd_param $list '' read_cache_enable 0
9549         cat $DIR/$tfile >/dev/null
9550
9551         # now data shouldn't be found in the cache
9552         BEFORE=$(roc_hit)
9553         cancel_lru_locks osc
9554         cat $DIR/$tfile >/dev/null
9555         AFTER=$(roc_hit)
9556         if let "AFTER - BEFORE != 0"; then
9557                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9558         fi
9559
9560         set_osd_param $list '' read_cache_enable 1
9561         rm -f $DIR/$tfile
9562 }
9563 run_test 151 "test cache on oss and controls ==============================="
9564
9565 test_152() {
9566         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9567         local TF="$TMP/$tfile"
9568
9569         # simulate ENOMEM during write
9570 #define OBD_FAIL_OST_NOMEM      0x226
9571         lctl set_param fail_loc=0x80000226
9572         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9573         cp $TF $DIR/$tfile
9574         sync || error "sync failed"
9575         lctl set_param fail_loc=0
9576
9577         # discard client's cache
9578         cancel_lru_locks osc
9579
9580         # simulate ENOMEM during read
9581         lctl set_param fail_loc=0x80000226
9582         cmp $TF $DIR/$tfile || error "cmp failed"
9583         lctl set_param fail_loc=0
9584
9585         rm -f $TF
9586 }
9587 run_test 152 "test read/write with enomem ============================"
9588
9589 test_153() {
9590         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9591 }
9592 run_test 153 "test if fdatasync does not crash ======================="
9593
9594 dot_lustre_fid_permission_check() {
9595         local fid=$1
9596         local ffid=$MOUNT/.lustre/fid/$fid
9597         local test_dir=$2
9598
9599         echo "stat fid $fid"
9600         stat $ffid > /dev/null || error "stat $ffid failed."
9601         echo "touch fid $fid"
9602         touch $ffid || error "touch $ffid failed."
9603         echo "write to fid $fid"
9604         cat /etc/hosts > $ffid || error "write $ffid failed."
9605         echo "read fid $fid"
9606         diff /etc/hosts $ffid || error "read $ffid failed."
9607         echo "append write to fid $fid"
9608         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9609         echo "rename fid $fid"
9610         mv $ffid $test_dir/$tfile.1 &&
9611                 error "rename $ffid to $tfile.1 should fail."
9612         touch $test_dir/$tfile.1
9613         mv $test_dir/$tfile.1 $ffid &&
9614                 error "rename $tfile.1 to $ffid should fail."
9615         rm -f $test_dir/$tfile.1
9616         echo "truncate fid $fid"
9617         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9618         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9619                 echo "link fid $fid"
9620                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9621         fi
9622         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9623                 echo "setfacl fid $fid"
9624                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9625                 echo "getfacl fid $fid"
9626                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9627         fi
9628         echo "unlink fid $fid"
9629         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9630         echo "mknod fid $fid"
9631         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9632
9633         fid=[0xf00000400:0x1:0x0]
9634         ffid=$MOUNT/.lustre/fid/$fid
9635
9636         echo "stat non-exist fid $fid"
9637         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9638         echo "write to non-exist fid $fid"
9639         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9640         echo "link new fid $fid"
9641         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9642
9643         mkdir -p $test_dir/$tdir
9644         touch $test_dir/$tdir/$tfile
9645         fid=$($LFS path2fid $test_dir/$tdir)
9646         rc=$?
9647         [ $rc -ne 0 ] &&
9648                 error "error: could not get fid for $test_dir/$dir/$tfile."
9649
9650         ffid=$MOUNT/.lustre/fid/$fid
9651
9652         echo "ls $fid"
9653         ls $ffid > /dev/null || error "ls $ffid failed."
9654         echo "touch $fid/$tfile.1"
9655         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9656
9657         echo "touch $MOUNT/.lustre/fid/$tfile"
9658         touch $MOUNT/.lustre/fid/$tfile && \
9659                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9660
9661         echo "setxattr to $MOUNT/.lustre/fid"
9662         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9663
9664         echo "listxattr for $MOUNT/.lustre/fid"
9665         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9666
9667         echo "delxattr from $MOUNT/.lustre/fid"
9668         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9669
9670         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9671         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9672                 error "touch invalid fid should fail."
9673
9674         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9675         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9676                 error "touch non-normal fid should fail."
9677
9678         echo "rename $tdir to $MOUNT/.lustre/fid"
9679         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9680                 error "rename to $MOUNT/.lustre/fid should fail."
9681
9682         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9683         then            # LU-3547
9684                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9685                 local new_obf_mode=777
9686
9687                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9688                 chmod $new_obf_mode $DIR/.lustre/fid ||
9689                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9690
9691                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9692                 [ $obf_mode -eq $new_obf_mode ] ||
9693                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9694
9695                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9696                 chmod $old_obf_mode $DIR/.lustre/fid ||
9697                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9698         fi
9699
9700         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9701         fid=$($LFS path2fid $test_dir/$tfile-2)
9702
9703         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9704         then # LU-5424
9705                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9706                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9707                         error "create lov data thru .lustre failed"
9708         fi
9709         echo "cp /etc/passwd $test_dir/$tfile-2"
9710         cp /etc/passwd $test_dir/$tfile-2 ||
9711                 error "copy to $test_dir/$tfile-2 failed."
9712         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9713         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9714                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9715
9716         rm -rf $test_dir/tfile.lnk
9717         rm -rf $test_dir/$tfile-2
9718 }
9719
9720 test_154A() {
9721         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9722                 skip "Need MDS version at least 2.4.1" && return
9723
9724         touch $DIR/$tfile
9725         local FID=$($LFS path2fid $DIR/$tfile)
9726         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9727
9728         # check that we get the same pathname back
9729         local FOUND=$($LFS fid2path $MOUNT "$FID")
9730         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9731         [ "$FOUND" != "$DIR/$tfile" ] &&
9732                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9733
9734         rm -rf $DIR/$tfile
9735 }
9736 run_test 154A "lfs path2fid and fid2path basic checks"
9737
9738 test_154a() {
9739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9740         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9741                 { skip "Need MDS version at least 2.2.51"; return 0; }
9742         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9743
9744         cp /etc/hosts $DIR/$tfile
9745
9746         fid=$($LFS path2fid $DIR/$tfile)
9747         rc=$?
9748         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9749
9750         dot_lustre_fid_permission_check "$fid" $DIR ||
9751                 error "dot lustre permission check $fid failed"
9752
9753         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9754
9755         touch $MOUNT/.lustre/file &&
9756                 error "creation is not allowed under .lustre"
9757
9758         mkdir $MOUNT/.lustre/dir &&
9759                 error "mkdir is not allowed under .lustre"
9760
9761         rm -rf $DIR/$tfile
9762 }
9763 run_test 154a "Open-by-FID"
9764
9765 test_154b() {
9766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9767         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9768                 { skip "Need MDS version at least 2.2.51"; return 0; }
9769
9770         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9771
9772         local remote_dir=$DIR/$tdir/remote_dir
9773         local MDTIDX=1
9774         local rc=0
9775
9776         mkdir -p $DIR/$tdir
9777         $LFS mkdir -i $MDTIDX $remote_dir ||
9778                 error "create remote directory failed"
9779
9780         cp /etc/hosts $remote_dir/$tfile
9781
9782         fid=$($LFS path2fid $remote_dir/$tfile)
9783         rc=$?
9784         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9785
9786         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9787                 error "dot lustre permission check $fid failed"
9788         rm -rf $DIR/$tdir
9789 }
9790 run_test 154b "Open-by-FID for remote directory"
9791
9792 test_154c() {
9793         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9794                 skip "Need MDS version at least 2.4.1" && return
9795
9796         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9797         local FID1=$($LFS path2fid $DIR/$tfile.1)
9798         local FID2=$($LFS path2fid $DIR/$tfile.2)
9799         local FID3=$($LFS path2fid $DIR/$tfile.3)
9800
9801         local N=1
9802         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9803                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9804                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9805                 local want=FID$N
9806                 [ "$FID" = "${!want}" ] ||
9807                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9808                 N=$((N + 1))
9809         done
9810
9811         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
9812         do
9813                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9814                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9815                 N=$((N + 1))
9816         done
9817 }
9818 run_test 154c "lfs path2fid and fid2path multiple arguments"
9819
9820 test_154d() {
9821         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9822                 skip "Need MDS version at least 2.5.53" && return
9823
9824         if remote_mds; then
9825                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9826         else
9827                 nid="0@lo"
9828         fi
9829         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9830         local fd
9831         local cmd
9832
9833         rm -f $DIR/$tfile
9834         touch $DIR/$tfile
9835
9836         local fid=$($LFS path2fid $DIR/$tfile)
9837         # Open the file
9838         fd=$(free_fd)
9839         cmd="exec $fd<$DIR/$tfile"
9840         eval $cmd
9841         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9842         echo "$fid_list" | grep "$fid"
9843         rc=$?
9844
9845         cmd="exec $fd>/dev/null"
9846         eval $cmd
9847         if [ $rc -ne 0 ]; then
9848                 error "FID $fid not found in open files list $fid_list"
9849         fi
9850 }
9851 run_test 154d "Verify open file fid"
9852
9853 test_154e()
9854 {
9855         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9856                 skip "Need MDS version at least 2.6.50" && return
9857
9858         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9859                 error ".lustre returned by readdir"
9860         fi
9861 }
9862 run_test 154e ".lustre is not returned by readdir"
9863
9864 test_154f() {
9865         # create parent directory on a single MDT to avoid cross-MDT hardlinks
9866         test_mkdir -p -c1 $DIR/$tdir/d
9867         # test dirs inherit from its stripe
9868         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
9869         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
9870         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
9871         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
9872         touch $DIR/f
9873
9874         # get fid of parents
9875         local FID0=$($LFS path2fid $DIR/$tdir/d)
9876         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
9877         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
9878         local FID3=$($LFS path2fid $DIR)
9879
9880         # check that path2fid --parents returns expected <parent_fid>/name
9881         # 1) test for a directory (single parent)
9882         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
9883         [ "$parent" == "$FID0/foo1" ] ||
9884                 error "expected parent: $FID0/foo1, got: $parent"
9885
9886         # 2) test for a file with nlink > 1 (multiple parents)
9887         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
9888         echo "$parent" | grep -F "$FID1/$tfile" ||
9889                 error "$FID1/$tfile not returned in parent list"
9890         echo "$parent" | grep -F "$FID2/link" ||
9891                 error "$FID2/link not returned in parent list"
9892
9893         # 3) get parent by fid
9894         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
9895         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9896         echo "$parent" | grep -F "$FID1/$tfile" ||
9897                 error "$FID1/$tfile not returned in parent list (by fid)"
9898         echo "$parent" | grep -F "$FID2/link" ||
9899                 error "$FID2/link not returned in parent list (by fid)"
9900
9901         # 4) test for entry in root directory
9902         parent=$($LFS path2fid --parents $DIR/f)
9903         echo "$parent" | grep -F "$FID3/f" ||
9904                 error "$FID3/f not returned in parent list"
9905
9906         # 5) test it on root directory
9907         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
9908                 error "$MOUNT should not have parents"
9909
9910         # enable xattr caching and check that linkea is correctly updated
9911         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
9912         save_lustre_params client "llite.*.xattr_cache" > $save
9913         lctl set_param llite.*.xattr_cache 1
9914
9915         # 6.1) linkea update on rename
9916         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
9917
9918         # get parents by fid
9919         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9920         # foo1 should no longer be returned in parent list
9921         echo "$parent" | grep -F "$FID1" &&
9922                 error "$FID1 should no longer be in parent list"
9923         # the new path should appear
9924         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
9925                 error "$FID2/$tfile.moved is not in parent list"
9926
9927         # 6.2) linkea update on unlink
9928         rm -f $DIR/$tdir/d/foo2/link
9929         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9930         # foo2/link should no longer be returned in parent list
9931         echo "$parent" | grep -F "$FID2/link" &&
9932                 error "$FID2/link should no longer be in parent list"
9933         true
9934
9935         rm -f $DIR/f
9936         restore_lustre_params < $save
9937 }
9938 run_test 154f "get parent fids by reading link ea"
9939
9940 test_154g()
9941 {
9942         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
9943                 { skip "Need MDS version at least 2.6.92"; return 0; }
9944
9945         mkdir -p $DIR/$tdir
9946         llapi_fid_test -d $DIR/$tdir
9947 }
9948 run_test 154g "various llapi FID tests"
9949
9950 test_155_small_load() {
9951     local temp=$TMP/$tfile
9952     local file=$DIR/$tfile
9953
9954     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9955         error "dd of=$temp bs=6096 count=1 failed"
9956     cp $temp $file
9957     cancel_lru_locks osc
9958     cmp $temp $file || error "$temp $file differ"
9959
9960     $TRUNCATE $temp 6000
9961     $TRUNCATE $file 6000
9962     cmp $temp $file || error "$temp $file differ (truncate1)"
9963
9964     echo "12345" >>$temp
9965     echo "12345" >>$file
9966     cmp $temp $file || error "$temp $file differ (append1)"
9967
9968     echo "12345" >>$temp
9969     echo "12345" >>$file
9970     cmp $temp $file || error "$temp $file differ (append2)"
9971
9972     rm -f $temp $file
9973     true
9974 }
9975
9976 test_155_big_load() {
9977     remote_ost_nodsh && skip "remote OST with nodsh" && return
9978     local temp=$TMP/$tfile
9979     local file=$DIR/$tfile
9980
9981     free_min_max
9982     local cache_size=$(do_facet ost$((MAXI+1)) \
9983         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9984     local large_file_size=$((cache_size * 2))
9985
9986     echo "OSS cache size: $cache_size KB"
9987     echo "Large file size: $large_file_size KB"
9988
9989     [ $MAXV -le $large_file_size ] && \
9990         skip_env "max available OST size needs > $large_file_size KB" && \
9991         return 0
9992
9993     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9994
9995     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9996         error "dd of=$temp bs=$large_file_size count=1k failed"
9997     cp $temp $file
9998     ls -lh $temp $file
9999     cancel_lru_locks osc
10000     cmp $temp $file || error "$temp $file differ"
10001
10002     rm -f $temp $file
10003     true
10004 }
10005
10006 test_155a() {
10007         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10008         set_cache read on
10009         set_cache writethrough on
10010         test_155_small_load
10011 }
10012 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10013
10014 test_155b() {
10015         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10016         set_cache read on
10017         set_cache writethrough off
10018         test_155_small_load
10019 }
10020 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10021
10022 test_155c() {
10023         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10024         set_cache read off
10025         set_cache writethrough on
10026         test_155_small_load
10027 }
10028 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10029
10030 test_155d() {
10031         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10032         set_cache read off
10033         set_cache writethrough off
10034         test_155_small_load
10035 }
10036 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10037
10038 test_155e() {
10039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10040         set_cache read on
10041         set_cache writethrough on
10042         test_155_big_load
10043 }
10044 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10045
10046 test_155f() {
10047         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10048         set_cache read on
10049         set_cache writethrough off
10050         test_155_big_load
10051 }
10052 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10053
10054 test_155g() {
10055         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10056         set_cache read off
10057         set_cache writethrough on
10058         test_155_big_load
10059 }
10060 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10061
10062 test_155h() {
10063         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10064         set_cache read off
10065         set_cache writethrough off
10066         test_155_big_load
10067 }
10068 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10069
10070 test_156() {
10071         remote_ost_nodsh && skip "remote OST with nodsh" && return
10072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10073         local CPAGES=3
10074         local BEFORE
10075         local AFTER
10076         local file="$DIR/$tfile"
10077
10078         [ "$(facet_fstype ost1)" = "zfs" ] &&
10079                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
10080                 return
10081
10082         roc_hit_init
10083
10084     log "Turn on read and write cache"
10085     set_cache read on
10086     set_cache writethrough on
10087
10088     log "Write data and read it back."
10089     log "Read should be satisfied from the cache."
10090     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10091     BEFORE=`roc_hit`
10092     cancel_lru_locks osc
10093     cat $file >/dev/null
10094     AFTER=`roc_hit`
10095     if ! let "AFTER - BEFORE == CPAGES"; then
10096         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10097     else
10098         log "cache hits:: before: $BEFORE, after: $AFTER"
10099     fi
10100
10101     log "Read again; it should be satisfied from the cache."
10102     BEFORE=$AFTER
10103     cancel_lru_locks osc
10104     cat $file >/dev/null
10105     AFTER=`roc_hit`
10106     if ! let "AFTER - BEFORE == CPAGES"; then
10107         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10108     else
10109         log "cache hits:: before: $BEFORE, after: $AFTER"
10110     fi
10111
10112
10113     log "Turn off the read cache and turn on the write cache"
10114     set_cache read off
10115     set_cache writethrough on
10116
10117     log "Read again; it should be satisfied from the cache."
10118     BEFORE=`roc_hit`
10119     cancel_lru_locks osc
10120     cat $file >/dev/null
10121     AFTER=`roc_hit`
10122     if ! let "AFTER - BEFORE == CPAGES"; then
10123         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10124     else
10125         log "cache hits:: before: $BEFORE, after: $AFTER"
10126     fi
10127
10128     log "Read again; it should not be satisfied from the cache."
10129     BEFORE=$AFTER
10130     cancel_lru_locks osc
10131     cat $file >/dev/null
10132     AFTER=`roc_hit`
10133     if ! let "AFTER - BEFORE == 0"; then
10134         error "IN CACHE: before: $BEFORE, after: $AFTER"
10135     else
10136         log "cache hits:: before: $BEFORE, after: $AFTER"
10137     fi
10138
10139     log "Write data and read it back."
10140     log "Read should be satisfied from the cache."
10141     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10142     BEFORE=`roc_hit`
10143     cancel_lru_locks osc
10144     cat $file >/dev/null
10145     AFTER=`roc_hit`
10146     if ! let "AFTER - BEFORE == CPAGES"; then
10147         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10148     else
10149         log "cache hits:: before: $BEFORE, after: $AFTER"
10150     fi
10151
10152     log "Read again; it should not be satisfied from the cache."
10153     BEFORE=$AFTER
10154     cancel_lru_locks osc
10155     cat $file >/dev/null
10156     AFTER=`roc_hit`
10157     if ! let "AFTER - BEFORE == 0"; then
10158         error "IN CACHE: before: $BEFORE, after: $AFTER"
10159     else
10160         log "cache hits:: before: $BEFORE, after: $AFTER"
10161     fi
10162
10163
10164     log "Turn off read and write cache"
10165     set_cache read off
10166     set_cache writethrough off
10167
10168     log "Write data and read it back"
10169     log "It should not be satisfied from the cache."
10170     rm -f $file
10171     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10172     cancel_lru_locks osc
10173     BEFORE=`roc_hit`
10174     cat $file >/dev/null
10175     AFTER=`roc_hit`
10176         if ! let "AFTER - BEFORE == 0"; then
10177                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10178         else
10179                 log "cache hits:: before: $BEFORE, after: $AFTER"
10180         fi
10181
10182     log "Turn on the read cache and turn off the write cache"
10183     set_cache read on
10184     set_cache writethrough off
10185
10186     log "Write data and read it back"
10187     log "It should not be satisfied from the cache."
10188     rm -f $file
10189     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10190     BEFORE=`roc_hit`
10191     cancel_lru_locks osc
10192     cat $file >/dev/null
10193     AFTER=`roc_hit`
10194         if ! let "AFTER - BEFORE == 0"; then
10195                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10196         else
10197                 log "cache hits:: before: $BEFORE, after: $AFTER"
10198         fi
10199
10200     log "Read again; it should be satisfied from the cache."
10201     BEFORE=`roc_hit`
10202     cancel_lru_locks osc
10203     cat $file >/dev/null
10204     AFTER=`roc_hit`
10205     if ! let "AFTER - BEFORE == CPAGES"; then
10206         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10207     else
10208         log "cache hits:: before: $BEFORE, after: $AFTER"
10209     fi
10210
10211     rm -f $file
10212 }
10213 run_test 156 "Verification of tunables ============================"
10214
10215 #Changelogs
10216 err17935 () {
10217         if [[ $MDSCOUNT -gt 1 ]]; then
10218                 error_ignore bz17935 $*
10219         else
10220                 error $*
10221         fi
10222 }
10223
10224 changelog_chmask()
10225 {
10226         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10227
10228         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10229
10230         if [ $MASK -eq 1 ]; then
10231                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10232         else
10233                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10234         fi
10235 }
10236
10237 changelog_extract_field() {
10238         local mdt=$1
10239         local cltype=$2
10240         local file=$3
10241         local identifier=$4
10242
10243         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10244                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10245                 tail -1
10246 }
10247
10248 test_160a() {
10249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10250         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10251         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10252                 { skip "Need MDS version at least 2.2.0"; return; }
10253
10254         local CL_USERS="mdd.$MDT0.changelog_users"
10255         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10256         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10257         echo "Registered as changelog user $USER"
10258         $GET_CL_USERS | grep -q $USER ||
10259                 error "User $USER not found in changelog_users"
10260
10261         # change something
10262         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10263         touch $DIR/$tdir/pics/2008/zachy/timestamp
10264         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10265         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10266         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10267         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10268         rm $DIR/$tdir/pics/desktop.jpg
10269
10270         $LFS changelog $MDT0 | tail -5
10271
10272         echo "verifying changelog mask"
10273         changelog_chmask "MKDIR"
10274         changelog_chmask "CLOSE"
10275
10276         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10277         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10278
10279         changelog_chmask "MKDIR"
10280         changelog_chmask "CLOSE"
10281
10282         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10283         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10284
10285         $LFS changelog $MDT0
10286         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10287         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10288         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10289         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10290
10291         # verify contents
10292         echo "verifying target fid"
10293         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10294         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10295         [ "$fidc" == "$fidf" ] ||
10296                 err17935 "fid in changelog $fidc != file fid $fidf"
10297         echo "verifying parent fid"
10298         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10299         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10300         [ "$fidc" == "$fidf" ] ||
10301                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10302
10303         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10304         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10305         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10306         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10307         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10308                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10309
10310         MIN_REC=$($GET_CL_USERS |
10311                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10312         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10313         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10314         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10315                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10316
10317         # LU-3446 changelog index reset on MDT restart
10318         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10319         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10320         $LFS changelog_clear $MDT0 $USER 0
10321         stop $SINGLEMDS || error "Fail to stop MDT."
10322         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10323         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10324         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10325         [ $CUR_REC1 == $CUR_REC2 ] ||
10326                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10327
10328         echo "verifying user deregister"
10329         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10330         $GET_CL_USERS | grep -q $USER &&
10331                 error "User $USER still in changelog_users"
10332
10333         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10334         if [ $USERS -eq 0 ]; then
10335                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10336                 touch $DIR/$tdir/chloe
10337                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10338                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10339                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10340         else
10341                 echo "$USERS other changelog users; can't verify off"
10342         fi
10343 }
10344 run_test 160a "changelog sanity"
10345
10346 test_160b() { # LU-3587
10347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10348         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10349         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10350                 { skip "Need MDS version at least 2.2.0"; return; }
10351
10352         local CL_USERS="mdd.$MDT0.changelog_users"
10353         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10354         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10355         echo "Registered as changelog user $USER"
10356         $GET_CL_USERS | grep -q $USER ||
10357                 error "User $USER not found in changelog_users"
10358
10359         local LONGNAME1=$(str_repeat a 255)
10360         local LONGNAME2=$(str_repeat b 255)
10361
10362         cd $DIR
10363         echo "creating very long named file"
10364         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10365         echo "moving very long named file"
10366         mv $LONGNAME1 $LONGNAME2
10367
10368         $LFS changelog $MDT0 | grep RENME
10369
10370         echo "deregistering $USER"
10371         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10372
10373         rm -f $LONGNAME2
10374 }
10375 run_test 160b "Verify that very long rename doesn't crash in changelog"
10376
10377 test_160c() {
10378         local rc=0
10379         local server_version=$(lustre_version_code $SINGLEMDS)
10380
10381         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10382                 [[ $server_version -gt $(version_code 2.5.1) &&
10383                    $server_version -lt $(version_code 2.5.50) ]] ||
10384                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10385         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10386
10387         # Registration step
10388         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10389                 changelog_register -n)
10390
10391         rm -rf $DIR/$tdir
10392         mkdir -p $DIR/$tdir
10393         $MCREATE $DIR/$tdir/foo_160c
10394         changelog_chmask "TRUNC"
10395         $TRUNCATE $DIR/$tdir/foo_160c 200
10396         changelog_chmask "TRUNC"
10397         $TRUNCATE $DIR/$tdir/foo_160c 199
10398         $LFS changelog $MDT0
10399         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10400         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10401         $LFS changelog_clear $MDT0 $USER 0
10402
10403         # Deregistration step
10404         echo "deregistering $USER"
10405         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10406 }
10407 run_test 160c "verify that changelog log catch the truncate event"
10408
10409 test_161a() {
10410         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10411         test_mkdir -p -c1 $DIR/$tdir
10412         cp /etc/hosts $DIR/$tdir/$tfile
10413         test_mkdir -c1 $DIR/$tdir/foo1
10414         test_mkdir -c1 $DIR/$tdir/foo2
10415         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10416         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10417         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10418         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10419         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10420         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10421                 $LFS fid2path $DIR $FID
10422                 err17935 "bad link ea"
10423         fi
10424     # middle
10425     rm $DIR/$tdir/foo2/zachary
10426     # last
10427     rm $DIR/$tdir/foo2/thor
10428     # first
10429     rm $DIR/$tdir/$tfile
10430     # rename
10431     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10432     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10433         then
10434         $LFS fid2path $DIR $FID
10435         err17935 "bad link rename"
10436     fi
10437     rm $DIR/$tdir/foo2/maggie
10438
10439         # overflow the EA
10440         local longname=filename_avg_len_is_thirty_two_
10441         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10442                 error "failed to hardlink many files"
10443         links=$($LFS fid2path $DIR $FID | wc -l)
10444         echo -n "${links}/1000 links in link EA"
10445         [[ $links -gt 60 ]] ||
10446                 err17935 "expected at least 60 links in link EA"
10447         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10448                 error "failed to unlink many hardlinks"
10449 }
10450 run_test 161a "link ea sanity"
10451
10452 test_161b() {
10453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10454         [ $MDSCOUNT -lt 2 ] &&
10455                 skip "skipping remote directory test" && return
10456         local MDTIDX=1
10457         local remote_dir=$DIR/$tdir/remote_dir
10458
10459         mkdir -p $DIR/$tdir
10460         $LFS mkdir -i $MDTIDX $remote_dir ||
10461                 error "create remote directory failed"
10462
10463         cp /etc/hosts $remote_dir/$tfile
10464         mkdir -p $remote_dir/foo1
10465         mkdir -p $remote_dir/foo2
10466         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10467         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10468         ln $remote_dir/$tfile $remote_dir/foo1/luna
10469         ln $remote_dir/$tfile $remote_dir/foo2/thor
10470
10471         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10472                      tr -d ']')
10473         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10474                 $LFS fid2path $DIR $FID
10475                 err17935 "bad link ea"
10476         fi
10477         # middle
10478         rm $remote_dir/foo2/zachary
10479         # last
10480         rm $remote_dir/foo2/thor
10481         # first
10482         rm $remote_dir/$tfile
10483         # rename
10484         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10485         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10486         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10487                 $LFS fid2path $DIR $FID
10488                 err17935 "bad link rename"
10489         fi
10490         rm $remote_dir/foo2/maggie
10491
10492         # overflow the EA
10493         local longname=filename_avg_len_is_thirty_two_
10494         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10495                 error "failed to hardlink many files"
10496         links=$($LFS fid2path $DIR $FID | wc -l)
10497         echo -n "${links}/1000 links in link EA"
10498         [[ ${links} -gt 60 ]] ||
10499                 err17935 "expected at least 60 links in link EA"
10500         unlinkmany $remote_dir/foo2/$longname 1000 ||
10501         error "failed to unlink many hardlinks"
10502 }
10503 run_test 161b "link ea sanity under remote directory"
10504
10505 test_161c() {
10506         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10507         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10508         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10509                 skip "Need MDS version at least 2.1.5" && return
10510
10511         # define CLF_RENAME_LAST 0x0001
10512         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10513         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10514                 changelog_register -n)
10515         rm -rf $DIR/$tdir
10516         mkdir -p $DIR/$tdir
10517         touch $DIR/$tdir/foo_161c
10518         touch $DIR/$tdir/bar_161c
10519         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10520         $LFS changelog $MDT0 | grep RENME
10521         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10522                 cut -f5 -d' ')
10523         $LFS changelog_clear $MDT0 $USER 0
10524         if [ x$flags != "x0x1" ]; then
10525                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10526                         $USER
10527                 error "flag $flags is not 0x1"
10528         fi
10529         echo "rename overwrite a target having nlink = 1," \
10530                 "changelog record has flags of $flags"
10531
10532         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10533         touch $DIR/$tdir/foo_161c
10534         touch $DIR/$tdir/bar_161c
10535         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10536         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10537         $LFS changelog $MDT0 | grep RENME
10538         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10539         $LFS changelog_clear $MDT0 $USER 0
10540         if [ x$flags != "x0x0" ]; then
10541                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10542                         $USER
10543                 error "flag $flags is not 0x0"
10544         fi
10545         echo "rename overwrite a target having nlink > 1," \
10546                 "changelog record has flags of $flags"
10547
10548         # rename doesn't overwrite a target (changelog flag 0x0)
10549         touch $DIR/$tdir/foo_161c
10550         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10551         $LFS changelog $MDT0 | grep RENME
10552         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10553         $LFS changelog_clear $MDT0 $USER 0
10554         if [ x$flags != "x0x0" ]; then
10555                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10556                         $USER
10557                 error "flag $flags is not 0x0"
10558         fi
10559         echo "rename doesn't overwrite a target," \
10560                 "changelog record has flags of $flags"
10561
10562         # define CLF_UNLINK_LAST 0x0001
10563         # unlink a file having nlink = 1 (changelog flag 0x1)
10564         rm -f $DIR/$tdir/foo2_161c
10565         $LFS changelog $MDT0 | grep UNLNK
10566         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10567         $LFS changelog_clear $MDT0 $USER 0
10568         if [ x$flags != "x0x1" ]; then
10569                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10570                         $USER
10571                 error "flag $flags is not 0x1"
10572         fi
10573         echo "unlink a file having nlink = 1," \
10574                 "changelog record has flags of $flags"
10575
10576         # unlink a file having nlink > 1 (changelog flag 0x0)
10577         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10578         rm -f $DIR/$tdir/foobar_161c
10579         $LFS changelog $MDT0 | grep UNLNK
10580         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10581         $LFS changelog_clear $MDT0 $USER 0
10582         if [ x$flags != "x0x0" ]; then
10583                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10584                         $USER
10585                 error "flag $flags is not 0x0"
10586         fi
10587         echo "unlink a file having nlink > 1," \
10588                 "changelog record has flags of $flags"
10589         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10590 }
10591 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10592
10593 check_path() {
10594     local expected=$1
10595     shift
10596     local fid=$2
10597
10598     local path=$(${LFS} fid2path $*)
10599     # Remove the '//' indicating a remote directory
10600     path=$(echo $path | sed 's#//#/#g')
10601     RC=$?
10602
10603     if [ $RC -ne 0 ]; then
10604         err17935 "path looked up of $expected failed. Error $RC"
10605         return $RC
10606     elif [ "${path}" != "${expected}" ]; then
10607         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10608         return 2
10609     fi
10610     echo "fid $fid resolves to path $path (expected $expected)"
10611 }
10612
10613 test_162() {
10614         # Make changes to filesystem
10615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10616         test_mkdir -p -c1 $DIR/$tdir/d2
10617         touch $DIR/$tdir/d2/$tfile
10618         touch $DIR/$tdir/d2/x1
10619         touch $DIR/$tdir/d2/x2
10620         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10621         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10622         # regular file
10623         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10624         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10625                 error "check path $tdir/d2/$tfile failed"
10626
10627         # softlink
10628         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10629         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10630         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10631                 error "check path $tdir/d2/p/q/r/slink failed"
10632
10633         # softlink to wrong file
10634         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10635         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10636         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10637                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10638
10639         # hardlink
10640         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10641         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10642         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10643         # fid2path dir/fsname should both work
10644         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10645                 error "check path $tdir/d2/a/b/c/new_file failed"
10646         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10647                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10648
10649         # hardlink count: check that there are 2 links
10650         # Doesnt work with CMD yet: 17935
10651         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10652                 err17935 "expected 2 links"
10653
10654         # hardlink indexing: remove the first link
10655         rm $DIR/$tdir/d2/p/q/r/hlink
10656         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10657                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10658
10659         return 0
10660 }
10661 run_test 162 "path lookup sanity"
10662
10663 test_162b() {
10664         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10665         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10666
10667         mkdir $DIR/$tdir
10668         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10669                                 error "create striped dir failed"
10670
10671         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10672                                         tail -n 1 | awk '{print $2}')
10673         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10674
10675         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10676         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10677
10678         # regular file
10679         for ((i=0;i<5;i++)); do
10680                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10681                         error "get fid for f$i failed"
10682                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10683                         error "check path $tdir/striped_dir/f$i failed"
10684
10685                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10686                         error "get fid for d$i failed"
10687                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10688                         error "check path $tdir/striped_dir/d$i failed"
10689         done
10690
10691         return 0
10692 }
10693 run_test 162b "striped directory path lookup sanity"
10694
10695 # LU-4239: Verify fid2path works with paths 100 or more directories deep
10696 test_162c() {
10697         test_mkdir $DIR/$tdir.local
10698         test_mkdir $DIR/$tdir.remote
10699         local lpath=$tdir.local
10700         local rpath=$tdir.remote
10701
10702         for ((i = 0; i <= 101; i++)); do
10703                 lpath="$lpath/$i"
10704                 mkdir $DIR/$lpath
10705                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
10706                         error "get fid for local directory $DIR/$lpath failed"
10707                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
10708                         error "check path for local directory $DIR/$lpath failed"
10709
10710                 rpath="$rpath/$i"
10711                 test_mkdir $DIR/$rpath
10712                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
10713                         error "get fid for remote directory $DIR/$rpath failed"
10714                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
10715                         error "check path for remote directory $DIR/$rpath failed"
10716         done
10717
10718         return 0
10719 }
10720 run_test 162c "fid2path works with paths 100 or more directories deep"
10721
10722 test_169() {
10723         # do directio so as not to populate the page cache
10724         log "creating a 10 Mb file"
10725         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10726         log "starting reads"
10727         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10728         log "truncating the file"
10729         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10730         log "killing dd"
10731         kill %+ || true # reads might have finished
10732         echo "wait until dd is finished"
10733         wait
10734         log "removing the temporary file"
10735         rm -rf $DIR/$tfile || error "tmp file removal failed"
10736 }
10737 run_test 169 "parallel read and truncate should not deadlock"
10738
10739 test_170() {
10740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10741         $LCTL clear     # bug 18514
10742         $LCTL debug_daemon start $TMP/${tfile}_log_good
10743         touch $DIR/$tfile
10744         $LCTL debug_daemon stop
10745         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10746                error "sed failed to read log_good"
10747
10748         $LCTL debug_daemon start $TMP/${tfile}_log_good
10749         rm -rf $DIR/$tfile
10750         $LCTL debug_daemon stop
10751
10752         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10753                error "lctl df log_bad failed"
10754
10755         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10756         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10757
10758         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10759         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10760
10761         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10762                 error "bad_line good_line1 good_line2 are empty"
10763
10764         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10765         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10766         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10767
10768         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10769         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10770         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10771
10772         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10773                 error "bad_line_new good_line_new are empty"
10774
10775         local expected_good=$((good_line1 + good_line2*2))
10776
10777         rm -f $TMP/${tfile}*
10778         # LU-231, short malformed line may not be counted into bad lines
10779         if [ $bad_line -ne $bad_line_new ] &&
10780                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10781                 error "expected $bad_line bad lines, but got $bad_line_new"
10782                 return 1
10783         fi
10784
10785         if [ $expected_good -ne $good_line_new ]; then
10786                 error "expected $expected_good good lines, but got $good_line_new"
10787                 return 2
10788         fi
10789         true
10790 }
10791 run_test 170 "test lctl df to handle corrupted log ====================="
10792
10793 test_171() { # bug20592
10794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10795 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10796         $LCTL set_param fail_loc=0x50e
10797         $LCTL set_param fail_val=3000
10798         multiop_bg_pause $DIR/$tfile O_s || true
10799         local MULTIPID=$!
10800         kill -USR1 $MULTIPID
10801         # cause log dump
10802         sleep 3
10803         wait $MULTIPID
10804         if dmesg | grep "recursive fault"; then
10805                 error "caught a recursive fault"
10806         fi
10807         $LCTL set_param fail_loc=0
10808         true
10809 }
10810 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10811
10812 # it would be good to share it with obdfilter-survey/iokit-libecho code
10813 setup_obdecho_osc () {
10814         local rc=0
10815         local ost_nid=$1
10816         local obdfilter_name=$2
10817         echo "Creating new osc for $obdfilter_name on $ost_nid"
10818         # make sure we can find loopback nid
10819         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10820
10821         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10822                            ${obdfilter_name}_osc_UUID || rc=2; }
10823         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10824                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10825         return $rc
10826 }
10827
10828 cleanup_obdecho_osc () {
10829         local obdfilter_name=$1
10830         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10831         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10832         return 0
10833 }
10834
10835 obdecho_test() {
10836         local OBD=$1
10837         local node=$2
10838         local pages=${3:-64}
10839         local rc=0
10840         local id
10841
10842         local count=10
10843         local obd_size=$(get_obd_size $node $OBD)
10844         local page_size=$(get_page_size $node)
10845         if [[ -n "$obd_size" ]]; then
10846                 local new_count=$((obd_size / (pages * page_size / 1024)))
10847                 [[ $new_count -ge $count ]] || count=$new_count
10848         fi
10849
10850         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10851         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10852                            rc=2; }
10853         if [ $rc -eq 0 ]; then
10854             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10855             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10856         fi
10857         echo "New object id is $id"
10858         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10859                            rc=4; }
10860         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10861                            "test_brw $count w v $pages $id" || rc=4; }
10862         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10863                            rc=4; }
10864         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10865                                         "cleanup" || rc=5; }
10866         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10867                                         "detach" || rc=6; }
10868         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10869         return $rc
10870 }
10871
10872 test_180a() {
10873         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10874         remote_ost_nodsh && skip "remote OST with nodsh" && return
10875         local rc=0
10876         local rmmod_local=0
10877
10878         if ! module_loaded obdecho; then
10879             load_module obdecho/obdecho
10880             rmmod_local=1
10881         fi
10882
10883         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10884         local host=$(lctl get_param -n osc.$osc.import |
10885                              awk '/current_connection:/ {print $2}' )
10886         local target=$(lctl get_param -n osc.$osc.import |
10887                              awk '/target:/ {print $2}' )
10888         target=${target%_UUID}
10889
10890         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10891         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10892         [[ -n $target ]] && cleanup_obdecho_osc $target
10893         [ $rmmod_local -eq 1 ] && rmmod obdecho
10894         return $rc
10895 }
10896 run_test 180a "test obdecho on osc"
10897
10898 test_180b() {
10899         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10900         remote_ost_nodsh && skip "remote OST with nodsh" && return
10901         local rc=0
10902         local rmmod_remote=0
10903
10904         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10905                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10906                       "modprobe obdecho; }" && rmmod_remote=1
10907         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10908         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10909         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10910         return $rc
10911 }
10912 run_test 180b "test obdecho directly on obdfilter"
10913
10914 test_180c() { # LU-2598
10915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10916         remote_ost_nodsh && skip "remote OST with nodsh" && return
10917         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10918                 skip "Need MDS version at least 2.4.0" && return
10919
10920         local rc=0
10921         local rmmod_remote=false
10922         local pages=16384 # 64MB bulk I/O RPC size
10923         local target
10924
10925         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10926                 rmmod_remote=true || error "failed to load module obdecho"
10927
10928         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10929                 head -n1)
10930         if [ -n "$target" ]; then
10931                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10932         else
10933                 echo "there is no obdfilter target on ost1"
10934                 rc=2
10935         fi
10936         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10937         return $rc
10938 }
10939 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10940
10941 test_181() { # bug 22177
10942         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10943         # create enough files to index the directory
10944         createmany -o $DIR/$tdir/foobar 4000
10945         # print attributes for debug purpose
10946         lsattr -d .
10947         # open dir
10948         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10949         MULTIPID=$!
10950         # remove the files & current working dir
10951         unlinkmany $DIR/$tdir/foobar 4000
10952         rmdir $DIR/$tdir
10953         kill -USR1 $MULTIPID
10954         wait $MULTIPID
10955         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10956         return 0
10957 }
10958 run_test 181 "Test open-unlinked dir ========================"
10959
10960 test_182() {
10961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10962         # disable MDC RPC lock wouldn't crash client
10963         local fcount=1000
10964         local tcount=4
10965
10966         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10967 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10968         $LCTL set_param fail_loc=0x804
10969
10970         for (( i=0; i < $tcount; i++ )) ; do
10971                 mkdir $DIR/$tdir/$i
10972                 createmany -o $DIR/$tdir/$i/f- $fcount &
10973         done
10974         wait
10975
10976         for (( i=0; i < $tcount; i++ )) ; do
10977                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10978         done
10979         wait
10980
10981         rm -rf $DIR/$tdir
10982
10983         $LCTL set_param fail_loc=0
10984 }
10985 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10986
10987 test_183() { # LU-2275
10988         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10989         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10990                 skip "Need MDS version at least 2.3.56" && return
10991
10992         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10993         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10994         echo aaa > $DIR/$tdir/$tfile
10995
10996 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10997         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10998
10999         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11000         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11001
11002         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11003
11004         # Flush negative dentry cache
11005         touch $DIR/$tdir/$tfile
11006
11007         # We are not checking for any leaked references here, they'll
11008         # become evident next time we do cleanup with module unload.
11009         rm -rf $DIR/$tdir
11010 }
11011 run_test 183 "No crash or request leak in case of strange dispositions ========"
11012
11013 # test suite 184 is for LU-2016, LU-2017
11014 test_184a() {
11015         check_swap_layouts_support && return 0
11016
11017         dir0=$DIR/$tdir/$testnum
11018         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11019         ref1=/etc/passwd
11020         ref2=/etc/group
11021         file1=$dir0/f1
11022         file2=$dir0/f2
11023         $SETSTRIPE -c1 $file1
11024         cp $ref1 $file1
11025         $SETSTRIPE -c2 $file2
11026         cp $ref2 $file2
11027         gen1=$($GETSTRIPE -g $file1)
11028         gen2=$($GETSTRIPE -g $file2)
11029
11030         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11031         gen=$($GETSTRIPE -g $file1)
11032         [[ $gen1 != $gen ]] ||
11033                 "Layout generation on $file1 does not change"
11034         gen=$($GETSTRIPE -g $file2)
11035         [[ $gen2 != $gen ]] ||
11036                 "Layout generation on $file2 does not change"
11037
11038         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11039         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11040 }
11041 run_test 184a "Basic layout swap"
11042
11043 test_184b() {
11044         check_swap_layouts_support && return 0
11045
11046         dir0=$DIR/$tdir/$testnum
11047         mkdir -p $dir0 || error "creating dir $dir0"
11048         file1=$dir0/f1
11049         file2=$dir0/f2
11050         file3=$dir0/f3
11051         dir1=$dir0/d1
11052         dir2=$dir0/d2
11053         mkdir $dir1 $dir2
11054         $SETSTRIPE -c1 $file1
11055         $SETSTRIPE -c2 $file2
11056         $SETSTRIPE -c1 $file3
11057         chown $RUNAS_ID $file3
11058         gen1=$($GETSTRIPE -g $file1)
11059         gen2=$($GETSTRIPE -g $file2)
11060
11061         $LFS swap_layouts $dir1 $dir2 &&
11062                 error "swap of directories layouts should fail"
11063         $LFS swap_layouts $dir1 $file1 &&
11064                 error "swap of directory and file layouts should fail"
11065         $RUNAS $LFS swap_layouts $file1 $file2 &&
11066                 error "swap of file we cannot write should fail"
11067         $LFS swap_layouts $file1 $file3 &&
11068                 error "swap of file with different owner should fail"
11069         /bin/true # to clear error code
11070 }
11071 run_test 184b "Forbidden layout swap (will generate errors)"
11072
11073 test_184c() {
11074         check_swap_layouts_support && return 0
11075
11076         local dir0=$DIR/$tdir/$testnum
11077         mkdir -p $dir0 || error "creating dir $dir0"
11078
11079         local ref1=$dir0/ref1
11080         local ref2=$dir0/ref2
11081         local file1=$dir0/file1
11082         local file2=$dir0/file2
11083         # create a file large enough for the concurrent test
11084         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11085         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11086         echo "ref file size: ref1($(stat -c %s $ref1))," \
11087              "ref2($(stat -c %s $ref2))"
11088
11089         cp $ref2 $file2
11090         dd if=$ref1 of=$file1 bs=16k &
11091         local DD_PID=$!
11092
11093         # Make sure dd starts to copy file
11094         while [ ! -f $file1 ]; do sleep 0.1; done
11095
11096         $LFS swap_layouts $file1 $file2
11097         local rc=$?
11098         wait $DD_PID
11099         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11100         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11101
11102         # how many bytes copied before swapping layout
11103         local copied=$(stat -c %s $file2)
11104         local remaining=$(stat -c %s $ref1)
11105         remaining=$((remaining - copied))
11106         echo "Copied $copied bytes before swapping layout..."
11107
11108         cmp -n $copied $file1 $ref2 | grep differ &&
11109                 error "Content mismatch [0, $copied) of ref2 and file1"
11110         cmp -n $copied $file2 $ref1 ||
11111                 error "Content mismatch [0, $copied) of ref1 and file2"
11112         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11113                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11114
11115         # clean up
11116         rm -f $ref1 $ref2 $file1 $file2
11117 }
11118 run_test 184c "Concurrent write and layout swap"
11119
11120 test_184d() {
11121         check_swap_layouts_support && return 0
11122         [ -z "$(which getfattr 2>/dev/null)" ] &&
11123                 skip "no getfattr command" && return 0
11124
11125         local file1=$DIR/$tdir/$tfile-1
11126         local file2=$DIR/$tdir/$tfile-2
11127         local file3=$DIR/$tdir/$tfile-3
11128         local lovea1
11129         local lovea2
11130
11131         mkdir -p $DIR/$tdir
11132         touch $file1 || error "create $file1 failed"
11133         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11134                 error "create $file2 failed"
11135         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11136                 error "create $file3 failed"
11137         lovea1=$($LFS getstripe $file1 | sed 1d)
11138
11139         $LFS swap_layouts $file2 $file3 ||
11140                 error "swap $file2 $file3 layouts failed"
11141         $LFS swap_layouts $file1 $file2 ||
11142                 error "swap $file1 $file2 layouts failed"
11143
11144         lovea2=$($LFS getstripe $file2 | sed 1d)
11145         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11146
11147         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11148         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11149 }
11150 run_test 184d "allow stripeless layouts swap"
11151
11152 test_184e() {
11153         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11154                 { skip "Need MDS version at least 2.6.94"; return 0; }
11155         check_swap_layouts_support && return 0
11156         [ -z "$(which getfattr 2>/dev/null)" ] &&
11157                 skip "no getfattr command" && return 0
11158
11159         local file1=$DIR/$tdir/$tfile-1
11160         local file2=$DIR/$tdir/$tfile-2
11161         local file3=$DIR/$tdir/$tfile-3
11162         local lovea
11163
11164         mkdir -p $DIR/$tdir
11165         touch $file1 || error "create $file1 failed"
11166         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11167                 error "create $file2 failed"
11168         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11169                 error "create $file3 failed"
11170
11171         $LFS swap_layouts $file1 $file2 ||
11172                 error "swap $file1 $file2 layouts failed"
11173
11174         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11175         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11176
11177         echo 123 > $file1 || error "Should be able to write into $file1"
11178
11179         $LFS swap_layouts $file1 $file3 ||
11180                 error "swap $file1 $file3 layouts failed"
11181
11182         echo 123 > $file1 || error "Should be able to write into $file1"
11183
11184         rm -rf $file1 $file2 $file3
11185 }
11186 run_test 184e "Recreate layout after stripeless layout swaps"
11187
11188 test_185() { # LU-2441
11189         # LU-3553 - no volatile file support in old servers
11190         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11191                 { skip "Need MDS version at least 2.3.60"; return 0; }
11192
11193         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11194         touch $DIR/$tdir/spoo
11195         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11196         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11197                 error "cannot create/write a volatile file"
11198         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11199                 error "FID is still valid after close"
11200
11201         multiop_bg_pause $DIR/$tdir vVw4096_c
11202         local multi_pid=$!
11203
11204         local OLD_IFS=$IFS
11205         IFS=":"
11206         local fidv=($fid)
11207         IFS=$OLD_IFS
11208         # assume that the next FID for this client is sequential, since stdout
11209         # is unfortunately eaten by multiop_bg_pause
11210         local n=$((${fidv[1]} + 1))
11211         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11212         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11213                 error "FID is missing before close"
11214         kill -USR1 $multi_pid
11215         # 1 second delay, so if mtime change we will see it
11216         sleep 1
11217         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11218         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11219 }
11220 run_test 185 "Volatile file support"
11221
11222 test_187a() {
11223         local dir0=$DIR/$tdir/$testnum
11224         mkdir -p $dir0 || error "creating dir $dir0"
11225
11226         local file=$dir0/file1
11227         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11228         local dv1=$($LFS data_version $file)
11229         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11230         local dv2=$($LFS data_version $file)
11231         [[ $dv1 != $dv2 ]] ||
11232                 error "data version did not change on write $dv1 == $dv2"
11233
11234         # clean up
11235         rm -f $file1
11236 }
11237 run_test 187a "Test data version change"
11238
11239 test_187b() {
11240         local dir0=$DIR/$tdir/$testnum
11241         mkdir -p $dir0 || error "creating dir $dir0"
11242
11243         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11244         [[ ${DV[0]} != ${DV[1]} ]] ||
11245                 error "data version did not change on write"\
11246                       " ${DV[0]} == ${DV[1]}"
11247
11248         # clean up
11249         rm -f $file1
11250 }
11251 run_test 187b "Test data version change on volatile file"
11252
11253 test_200() {
11254         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11255         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11256
11257         local POOL=${POOL:-cea1}
11258         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11259         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11260         # Pool OST targets
11261         local first_ost=0
11262         local last_ost=$(($OSTCOUNT - 1))
11263         local ost_step=2
11264         local ost_list=$(seq $first_ost $ost_step $last_ost)
11265         local ost_range="$first_ost $last_ost $ost_step"
11266         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11267         local file_dir=$POOL_ROOT/file_tst
11268         local subdir=$test_path/subdir
11269
11270         local rc=0
11271         while : ; do
11272                 # former test_200a test_200b
11273                 pool_add $POOL                          || { rc=$? ; break; }
11274                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11275                 # former test_200c test_200d
11276                 mkdir -p $test_path
11277                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11278                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11279                 mkdir -p $subdir
11280                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11281                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11282                                                         || { rc=$? ; break; }
11283                 # former test_200e test_200f
11284                 local files=$((OSTCOUNT*3))
11285                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11286                                                         || { rc=$? ; break; }
11287                 pool_create_files $POOL $file_dir $files "$ost_list" \
11288                                                         || { rc=$? ; break; }
11289                 # former test_200g test_200h
11290                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11291                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11292
11293                 # former test_201a test_201b test_201c
11294                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11295
11296                 local f=$test_path/$tfile
11297                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11298                 pool_remove $POOL $f                    || { rc=$? ; break; }
11299                 break
11300         done
11301
11302         cleanup_pools
11303         return $rc
11304 }
11305 run_test 200 "OST pools"
11306
11307 # usage: default_attr <count | size | offset>
11308 default_attr() {
11309         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11310 }
11311
11312 # usage: check_default_stripe_attr
11313 check_default_stripe_attr() {
11314         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11315         case $1 in
11316         --stripe-count|--count)
11317                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11318         --stripe-size|--size)
11319                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11320         --stripe-index|--index)
11321                 EXPECTED=-1;;
11322         *)
11323                 error "unknown getstripe attr '$1'"
11324         esac
11325
11326         [ $ACTUAL != $EXPECTED ] &&
11327                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11328 }
11329
11330 test_204a() {
11331         test_mkdir -p $DIR/$tdir
11332         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11333
11334         check_default_stripe_attr --stripe-count
11335         check_default_stripe_attr --stripe-size
11336         check_default_stripe_attr --stripe-index
11337
11338         return 0
11339 }
11340 run_test 204a "Print default stripe attributes ================="
11341
11342 test_204b() {
11343         test_mkdir -p $DIR/$tdir
11344         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11345
11346         check_default_stripe_attr --stripe-size
11347         check_default_stripe_attr --stripe-index
11348
11349         return 0
11350 }
11351 run_test 204b "Print default stripe size and offset  ==========="
11352
11353 test_204c() {
11354         test_mkdir -p $DIR/$tdir
11355         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11356
11357         check_default_stripe_attr --stripe-count
11358         check_default_stripe_attr --stripe-index
11359
11360         return 0
11361 }
11362 run_test 204c "Print default stripe count and offset ==========="
11363
11364 test_204d() {
11365         test_mkdir -p $DIR/$tdir
11366         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11367
11368         check_default_stripe_attr --stripe-count
11369         check_default_stripe_attr --stripe-size
11370
11371         return 0
11372 }
11373 run_test 204d "Print default stripe count and size ============="
11374
11375 test_204e() {
11376         test_mkdir -p $DIR/$tdir
11377         $SETSTRIPE -d $DIR/$tdir
11378
11379         check_default_stripe_attr --stripe-count --raw
11380         check_default_stripe_attr --stripe-size --raw
11381         check_default_stripe_attr --stripe-index --raw
11382
11383         return 0
11384 }
11385 run_test 204e "Print raw stripe attributes ================="
11386
11387 test_204f() {
11388         test_mkdir -p $DIR/$tdir
11389         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11390
11391         check_default_stripe_attr --stripe-size --raw
11392         check_default_stripe_attr --stripe-index --raw
11393
11394         return 0
11395 }
11396 run_test 204f "Print raw stripe size and offset  ==========="
11397
11398 test_204g() {
11399         test_mkdir -p $DIR/$tdir
11400         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11401
11402         check_default_stripe_attr --stripe-count --raw
11403         check_default_stripe_attr --stripe-index --raw
11404
11405         return 0
11406 }
11407 run_test 204g "Print raw stripe count and offset ==========="
11408
11409 test_204h() {
11410         test_mkdir -p $DIR/$tdir
11411         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11412
11413         check_default_stripe_attr --stripe-count --raw
11414         check_default_stripe_attr --stripe-size --raw
11415
11416         return 0
11417 }
11418 run_test 204h "Print raw stripe count and size ============="
11419
11420 # Figure out which job scheduler is being used, if any,
11421 # or use a fake one
11422 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11423         JOBENV=SLURM_JOB_ID
11424 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11425         JOBENV=LSB_JOBID
11426 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11427         JOBENV=PBS_JOBID
11428 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11429         JOBENV=LOADL_STEP_ID
11430 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11431         JOBENV=JOB_ID
11432 else
11433         JOBENV=FAKE_JOBID
11434 fi
11435
11436 verify_jobstats() {
11437         local cmd=$1
11438         local target=$2
11439
11440         # clear old jobstats
11441         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11442         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11443
11444         # use a new JobID for this test, or we might see an old one
11445         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11446
11447         JOBVAL=${!JOBENV}
11448         log "Test: $cmd"
11449         log "Using JobID environment variable $JOBENV=$JOBVAL"
11450
11451         if [ $JOBENV = "FAKE_JOBID" ]; then
11452                 FAKE_JOBID=$JOBVAL $cmd
11453         else
11454                 $cmd
11455         fi
11456
11457         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11458                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11459                 do_facet $FACET lctl get_param mdt.*.job_stats |
11460                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11461         fi
11462         if [ "$target" = "ost" -o "$target" = "both" ]; then
11463                 FACET=ost1
11464                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11465                         grep $JOBVAL || error "No job stats found on OST $FACET"
11466         fi
11467 }
11468
11469 jobstats_set() {
11470         trap 0
11471         NEW_JOBENV=${1:-$OLD_JOBENV}
11472         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11473         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11474 }
11475
11476 test_205() { # Job stats
11477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11478         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11479         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11480                 skip "Server doesn't support jobstats" && return 0
11481         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11482
11483         local cmd
11484         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11485         if [ $OLD_JOBENV != $JOBENV ]; then
11486                 jobstats_set $JOBENV
11487                 trap jobstats_set EXIT
11488         fi
11489
11490         local user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11491                      changelog_register -n)
11492         echo "Registered as changelog user $user"
11493
11494         # mkdir
11495         cmd="mkdir $DIR/$tfile"
11496         verify_jobstats "$cmd" "mdt"
11497         # rmdir
11498         cmd="rm -fr $DIR/$tfile"
11499         verify_jobstats "$cmd" "mdt"
11500         # mknod
11501         cmd="mknod $DIR/$tfile c 1 3"
11502         verify_jobstats "$cmd" "mdt"
11503         # unlink
11504         cmd="rm -f $DIR/$tfile"
11505         verify_jobstats "$cmd" "mdt"
11506         # open & close
11507         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11508         verify_jobstats "$cmd" "mdt"
11509         # setattr
11510         cmd="touch $DIR/$tfile"
11511         verify_jobstats "$cmd" "both"
11512         # write
11513         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11514         verify_jobstats "$cmd" "ost"
11515         # read
11516         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11517         verify_jobstats "$cmd" "ost"
11518         # truncate
11519         cmd="$TRUNCATE $DIR/$tfile 0"
11520         verify_jobstats "$cmd" "both"
11521         # rename
11522         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11523         verify_jobstats "$cmd" "mdt"
11524
11525         # Ensure that jobid are present in changelog (if supported by MDS)
11526         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11527         then
11528                 $LFS changelog $MDT0 | tail -9
11529                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11530                 [ $jobids -eq 9 ] ||
11531                         error "Wrong changelog jobid count $jobids != 9"
11532
11533                 # LU-5862
11534                 JOBENV="disable"
11535                 jobstats_set $JOBENV
11536                 touch $DIR/$tfile
11537                 $LFS changelog $MDT0 | tail -1
11538                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11539                 [ $jobids -eq 0 ] ||
11540                         error "Unexpected jobids when jobid_var=$JOBENV"
11541         fi
11542
11543         # cleanup
11544         rm -f $DIR/jobstats_test_rename
11545
11546         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11547 }
11548 run_test 205 "Verify job stats"
11549
11550 # LU-1480, LU-1773 and LU-1657
11551 test_206() {
11552         mkdir -p $DIR/$tdir
11553         $SETSTRIPE -c -1 $DIR/$tdir
11554 #define OBD_FAIL_LOV_INIT 0x1403
11555         $LCTL set_param fail_loc=0xa0001403
11556         $LCTL set_param fail_val=1
11557         touch $DIR/$tdir/$tfile || true
11558 }
11559 run_test 206 "fail lov_init_raid0() doesn't lbug"
11560
11561 test_207a() {
11562         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11563         local fsz=`stat -c %s $DIR/$tfile`
11564         cancel_lru_locks mdc
11565
11566         # do not return layout in getattr intent
11567 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11568         $LCTL set_param fail_loc=0x170
11569         local sz=`stat -c %s $DIR/$tfile`
11570
11571         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11572
11573         rm -rf $DIR/$tfile
11574 }
11575 run_test 207a "can refresh layout at glimpse"
11576
11577 test_207b() {
11578         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11579         local cksum=`md5sum $DIR/$tfile`
11580         local fsz=`stat -c %s $DIR/$tfile`
11581         cancel_lru_locks mdc
11582         cancel_lru_locks osc
11583
11584         # do not return layout in getattr intent
11585 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11586         $LCTL set_param fail_loc=0x171
11587
11588         # it will refresh layout after the file is opened but before read issues
11589         echo checksum is "$cksum"
11590         echo "$cksum" |md5sum -c --quiet || error "file differs"
11591
11592         rm -rf $DIR/$tfile
11593 }
11594 run_test 207b "can refresh layout at open"
11595
11596 test_208() {
11597         # FIXME: in this test suite, only RD lease is used. This is okay
11598         # for now as only exclusive open is supported. After generic lease
11599         # is done, this test suite should be revised. - Jinshan
11600
11601         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11602                 { skip "Need MDS version at least 2.4.52"; return 0; }
11603         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11604
11605         echo "==== test 1: verify get lease work"
11606         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11607
11608         echo "==== test 2: verify lease can be broken by upcoming open"
11609         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11610         local PID=$!
11611         sleep 1
11612
11613         $MULTIOP $DIR/$tfile oO_RDONLY:c
11614         kill -USR1 $PID && wait $PID || error "break lease error"
11615
11616         echo "==== test 3: verify lease can't be granted if an open already exists"
11617         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11618         local PID=$!
11619         sleep 1
11620
11621         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11622         kill -USR1 $PID && wait $PID || error "open file error"
11623
11624         echo "==== test 4: lease can sustain over recovery"
11625         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11626         PID=$!
11627         sleep 1
11628
11629         fail mds1
11630
11631         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11632
11633         echo "==== test 5: lease broken can't be regained by replay"
11634         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11635         PID=$!
11636         sleep 1
11637
11638         # open file to break lease and then recovery
11639         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11640         fail mds1
11641
11642         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11643
11644         rm -f $DIR/$tfile
11645 }
11646 run_test 208 "Exclusive open"
11647
11648 test_209() {
11649         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11650                 skip_env "must have disp_stripe" && return
11651
11652         touch $DIR/$tfile
11653         sync; sleep 5; sync;
11654
11655         echo 3 > /proc/sys/vm/drop_caches
11656         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11657
11658         # open/close 500 times
11659         for i in $(seq 500); do
11660                 cat $DIR/$tfile
11661         done
11662
11663         echo 3 > /proc/sys/vm/drop_caches
11664         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11665
11666         echo "before: $req_before, after: $req_after"
11667         [ $((req_after - req_before)) -ge 300 ] &&
11668                 error "open/close requests are not freed"
11669         return 0
11670 }
11671 run_test 209 "read-only open/close requests should be freed promptly"
11672
11673 test_212() {
11674         size=`date +%s`
11675         size=$((size % 8192 + 1))
11676         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11677         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11678         rm -f $DIR/f212 $DIR/f212.xyz
11679 }
11680 run_test 212 "Sendfile test ============================================"
11681
11682 test_213() {
11683         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11684         cancel_lru_locks osc
11685         lctl set_param fail_loc=0x8000040f
11686         # generate a read lock
11687         cat $DIR/$tfile > /dev/null
11688         # write to the file, it will try to cancel the above read lock.
11689         cat /etc/hosts >> $DIR/$tfile
11690 }
11691 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11692
11693 test_214() { # for bug 20133
11694         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11695         for (( i=0; i < 340; i++ )) ; do
11696                 touch $DIR/$tdir/d214c/a$i
11697         done
11698
11699         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11700         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11701         ls $DIR/d214c || error "ls $DIR/d214c failed"
11702         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11703         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11704 }
11705 run_test 214 "hash-indexed directory test - bug 20133"
11706
11707 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11708 create_lnet_proc_files() {
11709         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11710         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11711
11712         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11713         rm -f "$TMP/lnet_$1.sys_tmp"
11714 }
11715
11716 # counterpart of create_lnet_proc_files
11717 remove_lnet_proc_files() {
11718         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11719 }
11720
11721 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11722 # 3rd arg as regexp for body
11723 check_lnet_proc_stats() {
11724         local l=$(cat "$TMP/lnet_$1" |wc -l)
11725         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11726
11727         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11728 }
11729
11730 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11731 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11732 # optional and can be regexp for 2nd line (lnet.routes case)
11733 check_lnet_proc_entry() {
11734         local blp=2          # blp stands for 'position of 1st line of body'
11735         [ -z "$5" ] || blp=3 # lnet.routes case
11736
11737         local l=$(cat "$TMP/lnet_$1" |wc -l)
11738         # subtracting one from $blp because the body can be empty
11739         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11740
11741         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11742                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11743
11744         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11745                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11746
11747         # bail out if any unexpected line happened
11748         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11749         [ "$?" != 0 ] || error "$2 misformatted"
11750 }
11751
11752 test_215() { # for bugs 18102, 21079, 21517
11753         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11754         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11755         local P='[1-9][0-9]*'           # positive numeric
11756         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11757         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11758         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11759         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11760
11761         local L1 # regexp for 1st line
11762         local L2 # regexp for 2nd line (optional)
11763         local BR # regexp for the rest (body)
11764
11765         # lnet.stats should look as 11 space-separated non-negative numerics
11766         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11767         create_lnet_proc_files "stats"
11768         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11769         remove_lnet_proc_files "stats"
11770
11771         # lnet.routes should look like this:
11772         # Routing disabled/enabled
11773         # net hops priority state router
11774         # where net is a string like tcp0, hops > 0, priority >= 0,
11775         # state is up/down,
11776         # router is a string like 192.168.1.1@tcp2
11777         L1="^Routing (disabled|enabled)$"
11778         L2="^net +hops +priority +state +router$"
11779         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11780         create_lnet_proc_files "routes"
11781         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11782         remove_lnet_proc_files "routes"
11783
11784         # lnet.routers should look like this:
11785         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11786         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11787         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11788         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11789         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11790         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11791         create_lnet_proc_files "routers"
11792         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11793         remove_lnet_proc_files "routers"
11794
11795         # lnet.peers should look like this:
11796         # nid refs state last max rtr min tx min queue
11797         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11798         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11799         # numeric (0 or >0 or <0), queue >= 0.
11800         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11801         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11802         create_lnet_proc_files "peers"
11803         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11804         remove_lnet_proc_files "peers"
11805
11806         # lnet.buffers  should look like this:
11807         # pages count credits min
11808         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11809         L1="^pages +count +credits +min$"
11810         BR="^ +$N +$N +$I +$I$"
11811         create_lnet_proc_files "buffers"
11812         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11813         remove_lnet_proc_files "buffers"
11814
11815         # lnet.nis should look like this:
11816         # nid status alive refs peer rtr max tx min
11817         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11818         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11819         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11820         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11821         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11822         create_lnet_proc_files "nis"
11823         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11824         remove_lnet_proc_files "nis"
11825
11826         # can we successfully write to lnet.stats?
11827         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11828         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11829 }
11830 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11831
11832 test_216() { # bug 20317
11833         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11834         remote_ost_nodsh && skip "remote OST with nodsh" && return
11835
11836         local node
11837         local facets=$(get_facets OST)
11838         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11839
11840         save_lustre_params client "osc.*.contention_seconds" > $p
11841         save_lustre_params $facets \
11842                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11843         save_lustre_params $facets \
11844                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11845         save_lustre_params $facets \
11846                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11847         clear_osc_stats
11848
11849         # agressive lockless i/o settings
11850         for node in $(osts_nodes); do
11851                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
11852         done
11853         lctl set_param -n osc.*.contention_seconds 60
11854
11855         $DIRECTIO write $DIR/$tfile 0 10 4096
11856         $CHECKSTAT -s 40960 $DIR/$tfile
11857
11858         # disable lockless i/o
11859         for node in $(osts_nodes); do
11860                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
11861         done
11862         lctl set_param -n osc.*.contention_seconds 0
11863         clear_osc_stats
11864
11865         dd if=/dev/zero of=$DIR/$tfile count=0
11866         $CHECKSTAT -s 0 $DIR/$tfile
11867
11868         restore_lustre_params <$p
11869         rm -f $p
11870         rm $DIR/$tfile
11871 }
11872 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11873
11874 test_217() { # bug 22430
11875         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11876         local node
11877         local nid
11878
11879         for node in $(nodes_list); do
11880                 nid=$(host_nids_address $node $NETTYPE)
11881                 if [[ $nid = *-* ]] ; then
11882                         echo "lctl ping $nid@$NETTYPE"
11883                         lctl ping $nid@$NETTYPE
11884                 else
11885                         echo "skipping $node (no hyphen detected)"
11886                 fi
11887         done
11888 }
11889 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11890
11891 test_218() {
11892        # do directio so as not to populate the page cache
11893        log "creating a 10 Mb file"
11894        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11895        log "starting reads"
11896        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11897        log "truncating the file"
11898        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11899        log "killing dd"
11900        kill %+ || true # reads might have finished
11901        echo "wait until dd is finished"
11902        wait
11903        log "removing the temporary file"
11904        rm -rf $DIR/$tfile || error "tmp file removal failed"
11905 }
11906 run_test 218 "parallel read and truncate should not deadlock ======================="
11907
11908 test_219() {
11909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11910         # write one partial page
11911         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11912         # set no grant so vvp_io_commit_write will do sync write
11913         $LCTL set_param fail_loc=0x411
11914         # write a full page at the end of file
11915         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11916
11917         $LCTL set_param fail_loc=0
11918         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11919         $LCTL set_param fail_loc=0x411
11920         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11921
11922         # LU-4201
11923         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11924         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11925 }
11926 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11927
11928 test_220() { #LU-325
11929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11930         remote_ost_nodsh && skip "remote OST with nodsh" && return
11931         local OSTIDX=0
11932
11933         test_mkdir -p $DIR/$tdir
11934         local OST=$($LFS osts | grep ${OSTIDX}": " | \
11935                 awk '{print $2}' | sed -e 's/_UUID$//')
11936
11937         # on the mdt's osc
11938         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11939         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11940                         osc.$mdtosc_proc1.prealloc_last_id)
11941         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11942                         osc.$mdtosc_proc1.prealloc_next_id)
11943
11944         $LFS df -i
11945
11946         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11947         #define OBD_FAIL_OST_ENOINO              0x229
11948         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11949         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11950         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11951
11952         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11953
11954         MDSOBJS=$((last_id - next_id))
11955         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11956
11957         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11958         echo "OST still has $count kbytes free"
11959
11960         echo "create $MDSOBJS files @next_id..."
11961         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11962
11963         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11964                         osc.$mdtosc_proc1.prealloc_last_id)
11965         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11966                         osc.$mdtosc_proc1.prealloc_next_id)
11967
11968         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11969         $LFS df -i
11970
11971         echo "cleanup..."
11972
11973         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11974         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11975
11976         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11977         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11978         echo "unlink $MDSOBJS files @$next_id..."
11979         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11980 }
11981 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11982
11983 test_221() {
11984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11985         dd if=`which date` of=$MOUNT/date oflag=sync
11986         chmod +x $MOUNT/date
11987
11988         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11989         $LCTL set_param fail_loc=0x80001401
11990
11991         $MOUNT/date > /dev/null
11992         rm -f $MOUNT/date
11993 }
11994 run_test 221 "make sure fault and truncate race to not cause OOM"
11995
11996 test_222a () {
11997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11998        rm -rf $DIR/$tdir
11999        test_mkdir -p $DIR/$tdir
12000        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12001        createmany -o $DIR/$tdir/$tfile 10
12002        cancel_lru_locks mdc
12003        cancel_lru_locks osc
12004        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12005        $LCTL set_param fail_loc=0x31a
12006        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12007        $LCTL set_param fail_loc=0
12008        rm -r $DIR/$tdir
12009 }
12010 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12011
12012 test_222b () {
12013         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12014        rm -rf $DIR/$tdir
12015        test_mkdir -p $DIR/$tdir
12016        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12017        createmany -o $DIR/$tdir/$tfile 10
12018        cancel_lru_locks mdc
12019        cancel_lru_locks osc
12020        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12021        $LCTL set_param fail_loc=0x31a
12022        rm -r $DIR/$tdir || "AGL for rmdir failed"
12023        $LCTL set_param fail_loc=0
12024 }
12025 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12026
12027 test_223 () {
12028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12029        rm -rf $DIR/$tdir
12030        test_mkdir -p $DIR/$tdir
12031        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12032        createmany -o $DIR/$tdir/$tfile 10
12033        cancel_lru_locks mdc
12034        cancel_lru_locks osc
12035        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12036        $LCTL set_param fail_loc=0x31b
12037        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12038        $LCTL set_param fail_loc=0
12039        rm -r $DIR/$tdir
12040 }
12041 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12042
12043 test_224a() { # LU-1039, MRP-303
12044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12045         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12046         $LCTL set_param fail_loc=0x508
12047         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12048         $LCTL set_param fail_loc=0
12049         df $DIR
12050 }
12051 run_test 224a "Don't panic on bulk IO failure"
12052
12053 test_224b() { # LU-1039, MRP-303
12054         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12055         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12056         cancel_lru_locks osc
12057         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12058         $LCTL set_param fail_loc=0x515
12059         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12060         $LCTL set_param fail_loc=0
12061         df $DIR
12062 }
12063 run_test 224b "Don't panic on bulk IO failure"
12064
12065 test_224c() { # LU-6441
12066         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12067         local pages_per_rpc=$($LCTL get_param \
12068                                 osc.*.max_pages_per_rpc)
12069         local at_max=$($LCTL get_param -n at_max)
12070         local timeout=$($LCTL get_param -n timeout)
12071         local test_at="$LCTL get_param -n at_max"
12072         local param_at="$FSNAME.sys.at_max"
12073         local test_timeout="$LCTL get_param -n timeout"
12074         local param_timeout="$FSNAME.sys.timeout"
12075
12076         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12077
12078         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12079                 error "conf_param at_max=0 failed"
12080         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12081                 error "conf_param timeout=5 failed"
12082
12083         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12084         $LCTL set_param fail_loc=0x520
12085         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12086         sync
12087         $LCTL set_param fail_loc=0
12088
12089         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12090                 error "conf_param at_max=$at_max failed"
12091         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12092                 $timeout || error "conf_param timeout=$timeout failed"
12093
12094         $LCTL set_param -n $pages_per_rpc
12095 }
12096 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12097
12098 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12099 test_225a () {
12100         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12101         if [ -z ${MDSSURVEY} ]; then
12102               skip_env "mds-survey not found" && return
12103         fi
12104
12105         [ $MDSCOUNT -ge 2 ] &&
12106                 skip "skipping now for more than one MDT" && return
12107
12108        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12109             { skip "Need MDS version at least 2.2.51"; return; }
12110
12111        local mds=$(facet_host $SINGLEMDS)
12112        local target=$(do_nodes $mds 'lctl dl' | \
12113                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12114
12115        local cmd1="file_count=1000 thrhi=4"
12116        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12117        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12118        local cmd="$cmd1 $cmd2 $cmd3"
12119
12120        rm -f ${TMP}/mds_survey*
12121        echo + $cmd
12122        eval $cmd || error "mds-survey with zero-stripe failed"
12123        cat ${TMP}/mds_survey*
12124        rm -f ${TMP}/mds_survey*
12125 }
12126 run_test 225a "Metadata survey sanity with zero-stripe"
12127
12128 test_225b () {
12129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12130
12131         if [ -z ${MDSSURVEY} ]; then
12132               skip_env "mds-survey not found" && return
12133         fi
12134         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12135             { skip "Need MDS version at least 2.2.51"; return; }
12136
12137         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12138               skip_env "Need to mount OST to test" && return
12139         fi
12140
12141         [ $MDSCOUNT -ge 2 ] &&
12142                 skip "skipping now for more than one MDT" && return
12143        local mds=$(facet_host $SINGLEMDS)
12144        local target=$(do_nodes $mds 'lctl dl' | \
12145                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12146
12147        local cmd1="file_count=1000 thrhi=4"
12148        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12149        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12150        local cmd="$cmd1 $cmd2 $cmd3"
12151
12152        rm -f ${TMP}/mds_survey*
12153        echo + $cmd
12154        eval $cmd || error "mds-survey with stripe_count failed"
12155        cat ${TMP}/mds_survey*
12156        rm -f ${TMP}/mds_survey*
12157 }
12158 run_test 225b "Metadata survey sanity with stripe_count = 1"
12159
12160 mcreate_path2fid () {
12161         local mode=$1
12162         local major=$2
12163         local minor=$3
12164         local name=$4
12165         local desc=$5
12166         local path=$DIR/$tdir/$name
12167         local fid
12168         local rc
12169         local fid_path
12170
12171         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12172                 error "cannot create $desc"
12173
12174         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12175         rc=$?
12176         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12177
12178         fid_path=$($LFS fid2path $MOUNT $fid)
12179         rc=$?
12180         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12181
12182         [ "$path" == "$fid_path" ] ||
12183                 error "fid2path returned $fid_path, expected $path"
12184
12185         echo "pass with $path and $fid"
12186 }
12187
12188 test_226a () {
12189         rm -rf $DIR/$tdir
12190         mkdir -p $DIR/$tdir
12191
12192         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12193         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12194         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12195         mcreate_path2fid 0040666 0 0 dir "directory"
12196         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12197         mcreate_path2fid 0100666 0 0 file "regular file"
12198         mcreate_path2fid 0120666 0 0 link "symbolic link"
12199         mcreate_path2fid 0140666 0 0 sock "socket"
12200 }
12201 run_test 226a "call path2fid and fid2path on files of all type"
12202
12203 test_226b () {
12204         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12205         rm -rf $DIR/$tdir
12206         local MDTIDX=1
12207
12208         mkdir -p $DIR/$tdir
12209         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12210                 error "create remote directory failed"
12211         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12212         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12213                                 "character special file (null)"
12214         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12215                                 "character special file (no device)"
12216         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12217         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12218                                 "block special file (loop)"
12219         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12220         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12221         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12222 }
12223 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12224
12225 # LU-1299 Executing or running ldd on a truncated executable does not
12226 # cause an out-of-memory condition.
12227 test_227() {
12228         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12229         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12230         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12231         chmod +x $MOUNT/date
12232
12233         $MOUNT/date > /dev/null
12234         ldd $MOUNT/date > /dev/null
12235         rm -f $MOUNT/date
12236 }
12237 run_test 227 "running truncated executable does not cause OOM"
12238
12239 # LU-1512 try to reuse idle OI blocks
12240 test_228a() {
12241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12242         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12243         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12244                 skip "non-ldiskfs backend" && return
12245
12246         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12247         local myDIR=$DIR/$tdir
12248
12249         mkdir -p $myDIR
12250         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12251         $LCTL set_param fail_loc=0x80001002
12252         createmany -o $myDIR/t- 10000
12253         $LCTL set_param fail_loc=0
12254         # The guard is current the largest FID holder
12255         touch $myDIR/guard
12256         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12257                     tr -d '[')
12258         local IDX=$(($SEQ % 64))
12259
12260         do_facet $SINGLEMDS sync
12261         # Make sure journal flushed.
12262         sleep 6
12263         local blk1=$(do_facet $SINGLEMDS \
12264                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12265                      grep Blockcount | awk '{print $4}')
12266
12267         # Remove old files, some OI blocks will become idle.
12268         unlinkmany $myDIR/t- 10000
12269         # Create new files, idle OI blocks should be reused.
12270         createmany -o $myDIR/t- 2000
12271         do_facet $SINGLEMDS sync
12272         # Make sure journal flushed.
12273         sleep 6
12274         local blk2=$(do_facet $SINGLEMDS \
12275                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12276                      grep Blockcount | awk '{print $4}')
12277
12278         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12279 }
12280 run_test 228a "try to reuse idle OI blocks"
12281
12282 test_228b() {
12283         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12284         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12285         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12286                 skip "non-ldiskfs backend" && return
12287
12288         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12289         local myDIR=$DIR/$tdir
12290
12291         mkdir -p $myDIR
12292         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12293         $LCTL set_param fail_loc=0x80001002
12294         createmany -o $myDIR/t- 10000
12295         $LCTL set_param fail_loc=0
12296         # The guard is current the largest FID holder
12297         touch $myDIR/guard
12298         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12299                     tr -d '[')
12300         local IDX=$(($SEQ % 64))
12301
12302         do_facet $SINGLEMDS sync
12303         # Make sure journal flushed.
12304         sleep 6
12305         local blk1=$(do_facet $SINGLEMDS \
12306                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12307                      grep Blockcount | awk '{print $4}')
12308
12309         # Remove old files, some OI blocks will become idle.
12310         unlinkmany $myDIR/t- 10000
12311
12312         # stop the MDT
12313         stop $SINGLEMDS || error "Fail to stop MDT."
12314         # remount the MDT
12315         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12316
12317         df $MOUNT || error "Fail to df."
12318         # Create new files, idle OI blocks should be reused.
12319         createmany -o $myDIR/t- 2000
12320         do_facet $SINGLEMDS sync
12321         # Make sure journal flushed.
12322         sleep 6
12323         local blk2=$(do_facet $SINGLEMDS \
12324                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12325                      grep Blockcount | awk '{print $4}')
12326
12327         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12328 }
12329 run_test 228b "idle OI blocks can be reused after MDT restart"
12330
12331 #LU-1881
12332 test_228c() {
12333         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12334         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12335         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12336                 skip "non-ldiskfs backend" && return
12337
12338         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12339         local myDIR=$DIR/$tdir
12340
12341         mkdir -p $myDIR
12342         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12343         $LCTL set_param fail_loc=0x80001002
12344         # 20000 files can guarantee there are index nodes in the OI file
12345         createmany -o $myDIR/t- 20000
12346         $LCTL set_param fail_loc=0
12347         # The guard is current the largest FID holder
12348         touch $myDIR/guard
12349         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12350                     tr -d '[')
12351         local IDX=$(($SEQ % 64))
12352
12353         do_facet $SINGLEMDS sync
12354         # Make sure journal flushed.
12355         sleep 6
12356         local blk1=$(do_facet $SINGLEMDS \
12357                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12358                      grep Blockcount | awk '{print $4}')
12359
12360         # Remove old files, some OI blocks will become idle.
12361         unlinkmany $myDIR/t- 20000
12362         rm -f $myDIR/guard
12363         # The OI file should become empty now
12364
12365         # Create new files, idle OI blocks should be reused.
12366         createmany -o $myDIR/t- 2000
12367         do_facet $SINGLEMDS sync
12368         # Make sure journal flushed.
12369         sleep 6
12370         local blk2=$(do_facet $SINGLEMDS \
12371                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12372                      grep Blockcount | awk '{print $4}')
12373
12374         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12375 }
12376 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12377
12378 test_229() { # LU-2482, LU-3448
12379         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12380                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12381                 return
12382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12383         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12384
12385         rm -f $DIR/$tfile
12386
12387         # Create a file with a released layout and stripe count 2.
12388         $MULTIOP $DIR/$tfile H2c ||
12389                 error "failed to create file with released layout"
12390
12391         $GETSTRIPE -v $DIR/$tfile
12392
12393         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12394         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12395
12396         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12397         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12398         stat $DIR/$tfile || error "failed to stat released file"
12399
12400         chown $RUNAS_ID $DIR/$tfile ||
12401                 error "chown $RUNAS_ID $DIR/$tfile failed"
12402
12403         chgrp $RUNAS_ID $DIR/$tfile ||
12404                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12405
12406         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12407         rm $DIR/$tfile || error "failed to remove released file"
12408 }
12409 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12410
12411 test_230a() {
12412         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12413         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12414         local MDTIDX=1
12415
12416         test_mkdir $DIR/$tdir
12417         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12418         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12419         [ $mdt_idx -ne 0 ] &&
12420                 error "create local directory on wrong MDT $mdt_idx"
12421
12422         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12423                         error "create remote directory failed"
12424         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12425         [ $mdt_idx -ne $MDTIDX ] &&
12426                 error "create remote directory on wrong MDT $mdt_idx"
12427
12428         createmany -o $DIR/$tdir/test_230/t- 10 ||
12429                 error "create files on remote directory failed"
12430         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12431         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12432         rm -r $DIR/$tdir || error "unlink remote directory failed"
12433 }
12434 run_test 230a "Create remote directory and files under the remote directory"
12435
12436 test_230b() {
12437         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12438         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12439         local MDTIDX=1
12440         local mdt_index
12441         local i
12442         local file
12443         local pid
12444         local stripe_count
12445         local migrate_dir=$DIR/$tdir/migrate_dir
12446         local other_dir=$DIR/$tdir/other_dir
12447
12448         test_mkdir $DIR/$tdir
12449         test_mkdir -i0 -c1 $migrate_dir
12450         test_mkdir -i0 -c1 $other_dir
12451         for ((i=0; i<10; i++)); do
12452                 mkdir -p $migrate_dir/dir_${i}
12453                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12454                         error "create files under remote dir failed $i"
12455         done
12456
12457         cp /etc/passwd $migrate_dir/$tfile
12458         cp /etc/passwd $other_dir/$tfile
12459         chattr +SAD $migrate_dir
12460         chattr +SAD $migrate_dir/$tfile
12461
12462         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12463         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12464         local old_dir_mode=$(stat -c%f $migrate_dir)
12465         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12466
12467         mkdir -p $migrate_dir/dir_default_stripe2
12468         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12469         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12470
12471         mkdir -p $other_dir
12472         ln $migrate_dir/$tfile $other_dir/luna
12473         ln $migrate_dir/$tfile $migrate_dir/sofia
12474         ln $other_dir/$tfile $migrate_dir/david
12475         ln -s $migrate_dir/$tfile $other_dir/zachary
12476         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12477         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12478
12479         $LFS mv -v -M $MDTIDX $migrate_dir ||
12480                 error "migrate remote dir error"
12481
12482         echo "migratate to MDT1, then checking.."
12483         for ((i = 0; i < 10; i++)); do
12484                 for file in $(find $migrate_dir/dir_${i}); do
12485                         mdt_index=$($LFS getstripe -M $file)
12486                         [ $mdt_index == $MDTIDX ] ||
12487                                 error "$file is not on MDT${MDTIDX}"
12488                 done
12489         done
12490
12491         # the multiple link file should still in MDT0
12492         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12493         [ $mdt_index == 0 ] ||
12494                 error "$file is not on MDT${MDTIDX}"
12495
12496         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12497         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12498                 error " expect $old_dir_flag get $new_dir_flag"
12499
12500         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12501         [ "$old_file_flag" = "$new_file_flag" ] ||
12502                 error " expect $old_file_flag get $new_file_flag"
12503
12504         local new_dir_mode=$(stat -c%f $migrate_dir)
12505         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12506                 error "expect mode $old_dir_mode get $new_dir_mode"
12507
12508         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12509         [ "$old_file_mode" = "$new_file_mode" ] ||
12510                 error "expect mode $old_file_mode get $new_file_mode"
12511
12512         diff /etc/passwd $migrate_dir/$tfile ||
12513                 error "$tfile different after migration"
12514
12515         diff /etc/passwd $other_dir/luna ||
12516                 error "luna different after migration"
12517
12518         diff /etc/passwd $migrate_dir/sofia ||
12519                 error "sofia different after migration"
12520
12521         diff /etc/passwd $migrate_dir/david ||
12522                 error "david different after migration"
12523
12524         diff /etc/passwd $other_dir/zachary ||
12525                 error "zachary different after migration"
12526
12527         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12528                 error "${tfile}_ln different after migration"
12529
12530         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12531                 error "${tfile}_ln_other different after migration"
12532
12533         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12534         [ $stripe_count = 2 ] ||
12535                 error "dir strpe_count $d != 2 after migration."
12536
12537         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12538         [ $stripe_count = 2 ] ||
12539                 error "file strpe_count $d != 2 after migration."
12540
12541         #migrate back to MDT0
12542         MDTIDX=0
12543         $LFS mv -v -M $MDTIDX $migrate_dir ||
12544                 error "migrate remote dir error"
12545
12546         echo "migrate back to MDT0, checking.."
12547         for file in $(find $migrate_dir); do
12548                 mdt_index=$($LFS getstripe -M $file)
12549                 [ $mdt_index == $MDTIDX ] ||
12550                         error "$file is not on MDT${MDTIDX}"
12551         done
12552
12553         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12554         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12555                 error " expect $old_dir_flag get $new_dir_flag"
12556
12557         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12558         [ "$old_file_flag" = "$new_file_flag" ] ||
12559                 error " expect $old_file_flag get $new_file_flag"
12560
12561         local new_dir_mode=$(stat -c%f $migrate_dir)
12562         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12563                 error "expect mode $old_dir_mode get $new_dir_mode"
12564
12565         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12566         [ "$old_file_mode" = "$new_file_mode" ] ||
12567                 error "expect mode $old_file_mode get $new_file_mode"
12568
12569         diff /etc/passwd ${migrate_dir}/$tfile ||
12570                 error "$tfile different after migration"
12571
12572         diff /etc/passwd ${other_dir}/luna ||
12573                 error "luna different after migration"
12574
12575         diff /etc/passwd ${migrate_dir}/sofia ||
12576                 error "sofia different after migration"
12577
12578         diff /etc/passwd ${other_dir}/zachary ||
12579                 error "zachary different after migration"
12580
12581         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12582                 error "${tfile}_ln different after migration"
12583
12584         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12585                 error "${tfile}_ln_other different after migration"
12586
12587         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12588         [ $stripe_count = 2 ] ||
12589                 error "dir strpe_count $d != 2 after migration."
12590
12591         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12592         [ $stripe_count = 2 ] ||
12593                 error "file strpe_count $d != 2 after migration."
12594
12595         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12596 }
12597 run_test 230b "migrate directory"
12598
12599 test_230c() {
12600         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12601         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12602         local MDTIDX=1
12603         local mdt_index
12604         local file
12605         local migrate_dir=$DIR/$tdir/migrate_dir
12606
12607         #If migrating directory fails in the middle, all entries of
12608         #the directory is still accessiable.
12609         test_mkdir $DIR/$tdir
12610         test_mkdir -i0 -c1 $migrate_dir
12611         stat $migrate_dir
12612         createmany -o $migrate_dir/f 10 ||
12613                 error "create files under ${migrate_dir} failed"
12614
12615         #failed after migrating 5 entries
12616         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12617         do_facet mds1 lctl set_param fail_loc=0x20001801
12618         do_facet mds1 lctl  set_param fail_val=5
12619         local t=$(ls $migrate_dir | wc -l)
12620         $LFS mv --mdt-index $MDTIDX $migrate_dir &&
12621                 error "migrate should fail after 5 entries"
12622         local u=$(ls $migrate_dir | wc -l)
12623         [ "$u" == "$t" ] || error "$u != $t during migration"
12624
12625         for file in $(find $migrate_dir); do
12626                 stat $file || error "stat $file failed"
12627         done
12628
12629         do_facet mds1 lctl set_param fail_loc=0
12630         do_facet mds1 lctl set_param fail_val=0
12631
12632         $LFS mv -M $MDTIDX $migrate_dir ||
12633                 error "migrate open files should failed with open files"
12634
12635         echo "Finish migration, then checking.."
12636         for file in $(find $migrate_dir); do
12637                 mdt_index=$($LFS getstripe -M $file)
12638                 [ $mdt_index == $MDTIDX ] ||
12639                         error "$file is not on MDT${MDTIDX}"
12640         done
12641
12642         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12643 }
12644 run_test 230c "check directory accessiblity if migration is failed"
12645
12646 test_230d() {
12647         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12648         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12649         local MDTIDX=1
12650         local mdt_index
12651         local migrate_dir=$DIR/$tdir/migrate_dir
12652         local i
12653         local j
12654
12655         test_mkdir $DIR/$tdir
12656         test_mkdir -i0 -c1 $migrate_dir
12657
12658         for ((i=0; i<100; i++)); do
12659                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
12660                 createmany -o $migrate_dir/dir_${i}/f 100 ||
12661                         error "create files under remote dir failed $i"
12662         done
12663
12664         $LFS mv -M $MDTIDX -v $migrate_dir || error "migrate remote dir error"
12665
12666         echo "Finish migration, then checking.."
12667         for file in $(find $migrate_dir); do
12668                 mdt_index=$($LFS getstripe -M $file)
12669                 [ $mdt_index == $MDTIDX ] ||
12670                         error "$file is not on MDT${MDTIDX}"
12671         done
12672
12673         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12674 }
12675 run_test 230d "check migrate big directory"
12676
12677 test_231a()
12678 {
12679         # For simplicity this test assumes that max_pages_per_rpc
12680         # is the same across all OSCs
12681         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12682         local bulk_size=$((max_pages * 4096))
12683
12684         mkdir -p $DIR/$tdir
12685
12686         # clear the OSC stats
12687         $LCTL set_param osc.*.stats=0 &>/dev/null
12688
12689         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12690         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12691                 oflag=direct &>/dev/null || error "dd failed"
12692
12693         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12694         if [ x$nrpcs != "x1" ]; then
12695                 error "found $nrpc ost_write RPCs, not 1 as expected"
12696         fi
12697
12698         # Drop the OSC cache, otherwise we will read from it
12699         cancel_lru_locks osc
12700
12701         # clear the OSC stats
12702         $LCTL set_param osc.*.stats=0 &>/dev/null
12703
12704         # Client reads $bulk_size.
12705         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12706                 iflag=direct &>/dev/null || error "dd failed"
12707
12708         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12709         if [ x$nrpcs != "x1" ]; then
12710                 error "found $nrpc ost_read RPCs, not 1 as expected"
12711         fi
12712 }
12713 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12714
12715 test_231b() {
12716         mkdir -p $DIR/$tdir
12717         local i
12718         for i in {0..1023}; do
12719                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12720                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12721                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12722         done
12723         sync
12724 }
12725 run_test 231b "must not assert on fully utilized OST request buffer"
12726
12727 test_232() {
12728         mkdir -p $DIR/$tdir
12729         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12730         $LCTL set_param fail_loc=0x31c
12731
12732         # ignore dd failure
12733         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12734
12735         $LCTL set_param fail_loc=0
12736         umount_client $MOUNT || error "umount failed"
12737         mount_client $MOUNT || error "mount failed"
12738 }
12739 run_test 232 "failed lock should not block umount"
12740
12741 test_233a() {
12742         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12743         { skip "Need MDS version at least 2.3.64"; return; }
12744
12745         local fid=$($LFS path2fid $MOUNT)
12746         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12747                 error "cannot access $MOUNT using its FID '$fid'"
12748 }
12749 run_test 233a "checking that OBF of the FS root succeeds"
12750
12751 test_233b() {
12752         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12753         { skip "Need MDS version at least 2.5.90"; return; }
12754
12755         local fid=$($LFS path2fid $MOUNT/.lustre)
12756         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12757                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12758
12759         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12760         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12761                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12762 }
12763 run_test 233b "checking that OBF of the FS .lustre succeeds"
12764
12765 test_234() {
12766         local p="$TMP/sanityN-$TESTNAME.parameters"
12767         save_lustre_params client "llite.*.xattr_cache" > $p
12768         lctl set_param llite.*.xattr_cache 1 ||
12769                 { skip "xattr cache is not supported"; return 0; }
12770
12771         mkdir -p $DIR/$tdir || error "mkdir failed"
12772         touch $DIR/$tdir/$tfile || error "touch failed"
12773         # OBD_FAIL_LLITE_XATTR_ENOMEM
12774         $LCTL set_param fail_loc=0x1405
12775         # output of the form: attr 2 4 44 3 fc13 x86_64
12776         V=($(IFS=".-" rpm -q attr))
12777         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
12778               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
12779                 # attr pre-2.4.44-7 had a bug with rc
12780                 # LU-3703 - SLES 11 and FC13 clients have older attr
12781                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12782                         error "getfattr should have failed with ENOMEM"
12783         else
12784                 skip "LU-3703: attr version $(getfattr --version) too old"
12785         fi
12786         $LCTL set_param fail_loc=0x0
12787         rm -rf $DIR/$tdir
12788
12789         restore_lustre_params < $p
12790         rm -f $p
12791 }
12792 run_test 234 "xattr cache should not crash on ENOMEM"
12793
12794 test_235() {
12795         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12796                 skip "Need MDS version at least 2.4.52" && return
12797         flock_deadlock $DIR/$tfile
12798         local RC=$?
12799         case $RC in
12800                 0)
12801                 ;;
12802                 124) error "process hangs on a deadlock"
12803                 ;;
12804                 *) error "error executing flock_deadlock $DIR/$tfile"
12805                 ;;
12806         esac
12807 }
12808 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12809
12810 #LU-2935
12811 test_236() {
12812         check_swap_layouts_support && return 0
12813         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12814
12815         local ref1=/etc/passwd
12816         local ref2=/etc/group
12817         local file1=$DIR/$tdir/f1
12818         local file2=$DIR/$tdir/f2
12819
12820         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12821         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12822         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12823         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12824         local fd=$(free_fd)
12825         local cmd="exec $fd<>$file2"
12826         eval $cmd
12827         rm $file2
12828         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12829                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12830         cmd="exec $fd>&-"
12831         eval $cmd
12832         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12833
12834         #cleanup
12835         rm -rf $DIR/$tdir
12836 }
12837 run_test 236 "Layout swap on open unlinked file"
12838
12839 # test to verify file handle related system calls
12840 # (name_to_handle_at/open_by_handle_at)
12841 # The new system calls are supported in glibc >= 2.14.
12842
12843 test_237() {
12844         echo "Test file_handle syscalls" > $DIR/$tfile ||
12845                 error "write failed"
12846         check_fhandle_syscalls $DIR/$tfile ||
12847                 error "check_fhandle_syscalls failed"
12848 }
12849 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12850
12851 # LU-4659 linkea consistency
12852 test_238() {
12853         local server_version=$(lustre_version_code $SINGLEMDS)
12854
12855         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12856                 [[ $server_version -gt $(version_code 2.5.1) &&
12857                    $server_version -lt $(version_code 2.5.50) ]] ||
12858                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12859
12860         touch $DIR/$tfile
12861         ln $DIR/$tfile $DIR/$tfile.lnk
12862         touch $DIR/$tfile.new
12863         mv $DIR/$tfile.new $DIR/$tfile
12864         local fid1=$($LFS path2fid $DIR/$tfile)
12865         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
12866         local path1=$($LFS fid2path $FSNAME "$fid1")
12867         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12868         local path2=$($LFS fid2path $FSNAME "$fid2")
12869         [ $tfile.lnk == $path2 ] ||
12870                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12871         rm -f $DIR/$tfile*
12872 }
12873 run_test 238 "Verify linkea consistency"
12874
12875 test_239() {
12876         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
12877                 skip "Need MDS version at least 2.5.60" && return
12878         local list=$(comma_list $(mdts_nodes))
12879
12880         mkdir -p $DIR/$tdir
12881         createmany -o $DIR/$tdir/f- 5000
12882         unlinkmany $DIR/$tdir/f- 5000
12883         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12884         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12885                         osc.*MDT*.sync_in_flight" | calc_sum)
12886         [ "$changes" -eq 0 ] || error "$changes not synced"
12887 }
12888 run_test 239 "osp_sync test"
12889
12890 test_240() {
12891         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12892
12893         mkdir -p $DIR/$tdir
12894
12895         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12896                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12897         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12898                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12899
12900         umount_client $MOUNT || error "umount failed"
12901         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12902         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12903         mount_client $MOUNT || error "failed to mount client"
12904
12905         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12906         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12907 }
12908 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12909
12910 test_241_bio() {
12911         for LOOP in $(seq $1); do
12912                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12913                 cancel_lru_locks osc
12914         done
12915 }
12916
12917 test_241_dio() {
12918         for LOOP in $(seq $1); do
12919                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12920                                                 iflag=direct 2>/dev/null
12921         done
12922 }
12923
12924 test_241() {
12925         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12926         ls -la $DIR/$tfile
12927         cancel_lru_locks osc
12928         test_241_bio 1000 &
12929         PID=$!
12930         test_241_dio 1000
12931         wait $PID
12932 }
12933 run_test 241 "bio vs dio"
12934
12935 test_241b() {
12936         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12937         ls -la $DIR/$tfile
12938         test_241_dio 1000 &
12939         PID=$!
12940         test_241_dio 1000
12941         wait $PID
12942 }
12943 run_test 241b "dio vs dio"
12944
12945 test_242() {
12946         mkdir -p $DIR/$tdir
12947         touch $DIR/$tdir/$tfile
12948
12949         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
12950         do_facet mds1 lctl set_param fail_loc=0x105
12951         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
12952
12953         do_facet mds1 lctl set_param fail_loc=0
12954         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
12955 }
12956 run_test 242 "mdt_readpage failure should not cause directory unreadable"
12957
12958 test_243()
12959 {
12960         test_mkdir -p $DIR/$tdir
12961         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
12962 }
12963 run_test 243 "various group lock tests"
12964
12965 test_244()
12966 {
12967         test_mkdir -p $DIR/$tdir
12968         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
12969         sendfile_grouplock $DIR/$tdir/$tfile || \
12970                 error "sendfile+grouplock failed"
12971         rm -rf $DIR/$tdir
12972 }
12973 run_test 244 "sendfile with group lock tests"
12974
12975 test_250() {
12976         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
12977          && skip "no 16TB file size limit on ZFS" && return
12978
12979         $SETSTRIPE -c 1 $DIR/$tfile
12980         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
12981         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
12982         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
12983         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
12984                 conv=notrunc,fsync && error "append succeeded"
12985         return 0
12986 }
12987 run_test 250 "Write above 16T limit"
12988
12989 test_251() {
12990         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
12991
12992         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
12993         #Skip once - writing the first stripe will succeed
12994         $LCTL set_param fail_loc=0xa0001407 fail_val=1
12995         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
12996                 error "short write happened"
12997
12998         $LCTL set_param fail_loc=0xa0001407 fail_val=1
12999         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
13000                 error "short read happened"
13001
13002         rm -f $DIR/$tfile
13003 }
13004 run_test 251 "Handling short read and write correctly"
13005
13006 cleanup_test_300() {
13007         trap 0
13008         umask $SAVE_UMASK
13009 }
13010 test_striped_dir() {
13011         local mdt_index=$1
13012         local stripe_count
13013         local stripe_index
13014
13015         mkdir -p $DIR/$tdir
13016
13017         SAVE_UMASK=$(umask)
13018         trap cleanup_test_300 RETURN EXIT
13019
13020         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13021                                                 $DIR/$tdir/striped_dir ||
13022                 error "set striped dir error"
13023
13024         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13025         [ "$mode" = "755" ] || error "expect 755 got $mode"
13026
13027         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13028         if [ "$stripe_count" != "2" ]; then
13029                 error "stripe_count is $stripe_count, expect 2"
13030         fi
13031
13032         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13033         if [ "$stripe_index" != "$mdt_index" ]; then
13034                 error "stripe_index is $stripe_index, expect $mdt_index"
13035         fi
13036
13037         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13038                 error "nlink error after create striped dir"
13039
13040         mkdir $DIR/$tdir/striped_dir/a
13041         mkdir $DIR/$tdir/striped_dir/b
13042
13043         stat $DIR/$tdir/striped_dir/a ||
13044                 error "create dir under striped dir failed"
13045         stat $DIR/$tdir/striped_dir/b ||
13046                 error "create dir under striped dir failed"
13047
13048         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13049                 error "nlink error after mkdir"
13050
13051         rmdir $DIR/$tdir/striped_dir/a
13052         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13053                 error "nlink error after rmdir"
13054
13055         rmdir $DIR/$tdir/striped_dir/b
13056         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13057                 error "nlink error after rmdir"
13058
13059         chattr +i $DIR/$tdir/striped_dir
13060         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13061                 error "immutable flags not working under striped dir!"
13062         chattr -i $DIR/$tdir/striped_dir
13063
13064         rmdir $DIR/$tdir/striped_dir ||
13065                 error "rmdir striped dir error"
13066
13067         cleanup_test_300
13068
13069         true
13070 }
13071
13072 test_300a() {
13073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13074         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13075
13076         test_striped_dir 0 || error "failed on striped dir on MDT0"
13077         test_striped_dir 1 || error "failed on striped dir on MDT0"
13078 }
13079 run_test 300a "basic striped dir sanity test"
13080
13081 test_300b() {
13082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13083         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13084         local i
13085         local mtime1
13086         local mtime2
13087         local mtime3
13088
13089         test_mkdir $DIR/$tdir || error "mkdir fail"
13090         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13091                 error "set striped dir error"
13092         for ((i=0; i<10; i++)); do
13093                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13094                 sleep 1
13095                 touch $DIR/$tdir/striped_dir/file_$i ||
13096                                         error "touch error $i"
13097                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13098                 [ $mtime1 -eq $mtime2 ] &&
13099                         error "mtime not change after create"
13100                 sleep 1
13101                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13102                                         error "unlink error $i"
13103                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13104                 [ $mtime2 -eq $mtime3 ] &&
13105                         error "mtime did not change after unlink"
13106         done
13107         true
13108 }
13109 run_test 300b "check ctime/mtime for striped dir"
13110
13111 test_300c() {
13112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13113         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13114         local file_count
13115
13116         mkdir -p $DIR/$tdir
13117         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13118                 error "set striped dir error"
13119
13120         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13121                 error "chown striped dir failed"
13122
13123         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13124                 error "create 5k files failed"
13125
13126         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13127
13128         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13129
13130         rm -rf $DIR/$tdir
13131 }
13132 run_test 300c "chown && check ls under striped directory"
13133
13134 test_300d() {
13135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13136         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13137         local stripe_count
13138         local file
13139
13140         mkdir -p $DIR/$tdir
13141         $SETSTRIPE -c 2 $DIR/$tdir
13142
13143         #local striped directory
13144         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13145                 error "set striped dir error"
13146         createmany -o $DIR/$tdir/striped_dir/f 10 ||
13147                 error "create 10 files failed"
13148
13149         #remote striped directory
13150         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
13151                 error "set striped dir error"
13152         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
13153                 error "create 10 files failed"
13154
13155         for file in $(find $DIR/$tdir); do
13156                 stripe_count=$($GETSTRIPE -c $file)
13157                 [ $stripe_count -eq 2 ] ||
13158                         error "wrong stripe $stripe_count for $file"
13159         done
13160
13161         rm -rf $DIR/$tdir
13162 }
13163 run_test 300d "check default stripe under striped directory"
13164
13165 test_300e() {
13166         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13167         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13168         local stripe_count
13169         local file
13170
13171         mkdir -p $DIR/$tdir
13172
13173         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13174                 error "set striped dir error"
13175
13176         touch $DIR/$tdir/striped_dir/a
13177         touch $DIR/$tdir/striped_dir/b
13178         touch $DIR/$tdir/striped_dir/c
13179
13180         mkdir $DIR/$tdir/striped_dir/dir_a
13181         mkdir $DIR/$tdir/striped_dir/dir_b
13182         mkdir $DIR/$tdir/striped_dir/dir_c
13183
13184         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
13185                 error "set striped dir under striped dir error"
13186
13187         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
13188                 error "set striped dir under striped dir error"
13189
13190         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
13191                 error "set striped dir under striped dir error"
13192
13193         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
13194                 error "rename file under striped dir should fail"
13195
13196         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
13197                 error "rename dir under striped dir should fail"
13198
13199         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
13200                 error "rename dir under different stripes should fail"
13201
13202         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
13203                 error "rename file under striped dir should succeed"
13204
13205         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
13206                 error "rename dir under striped dir should succeed"
13207
13208         rm -rf $DIR/$tdir
13209 }
13210 run_test 300e "check rename under striped directory"
13211
13212 test_300f() {
13213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13214         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13215         local stripe_count
13216         local file
13217
13218         rm -rf $DIR/$tdir
13219         mkdir -p $DIR/$tdir
13220
13221         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13222                 error "set striped dir error"
13223
13224         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
13225                 error "set striped dir error"
13226
13227         touch $DIR/$tdir/striped_dir/a
13228         mkdir $DIR/$tdir/striped_dir/dir_a
13229         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
13230                 error "create striped dir under striped dir fails"
13231
13232         touch $DIR/$tdir/striped_dir1/b
13233         mkdir $DIR/$tdir/striped_dir1/dir_b
13234         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
13235                 error "create striped dir under striped dir fails"
13236
13237         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
13238                 error "rename file under different striped dir should fail"
13239
13240         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
13241                 error "rename dir under different striped dir should fail"
13242
13243         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
13244                 error "rename striped dir under diff striped dir should fail"
13245
13246         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
13247                 error "rename file under diff striped dirs fails"
13248
13249         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
13250                 error "rename dir under diff striped dirs fails"
13251
13252         rm -rf $DIR/$tdir
13253 }
13254 run_test 300f "check rename cross striped directory"
13255
13256 test_300_check_default_striped_dir()
13257 {
13258         local dirname=$1
13259         local default_count=$2
13260         local default_index=$3
13261         local stripe_count
13262         local stripe_index
13263         local dir_stripe_index
13264         local dir
13265
13266         echo "checking $dirname $default_count $default_index"
13267         $LFS setdirstripe -D -c $default_count -i $default_index \
13268                                 -t all_char $DIR/$tdir/$dirname ||
13269                 error "set default stripe on striped dir error"
13270         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
13271         [ $stripe_count -eq $default_count ] ||
13272                 error "expect $default_count get $stripe_count for $dirname"
13273
13274         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
13275         [ $stripe_index -eq $default_index ] ||
13276                 error "expect $default_index get $stripe_index for $dirname"
13277
13278         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
13279                                                 error "create dirs failed"
13280
13281         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
13282         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
13283         for dir in $(find $DIR/$tdir/$dirname/*); do
13284                 stripe_count=$($LFS getdirstripe -c $dir)
13285                 [ $stripe_count -eq $default_count ] ||
13286                 error "stripe count $default_count != $stripe_count for $dir"
13287
13288                 stripe_index=$($LFS getdirstripe -i $dir)
13289                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
13290                         error "$stripe_index != $default_index for $dir"
13291
13292                 #check default stripe
13293                 stripe_count=$($LFS getdirstripe -D -c $dir)
13294                 [ $stripe_count -eq $default_count ] ||
13295                 error "default count $default_count != $stripe_count for $dir"
13296
13297                 stripe_index=$($LFS getdirstripe -D -i $dir)
13298                 [ $stripe_index -eq $default_index ] ||
13299                 error "default index $default_index != $stripe_index for $dir"
13300         done
13301         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
13302 }
13303
13304 test_300g() {
13305         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13306         local dir
13307         local stripe_count
13308         local stripe_index
13309
13310         mkdir $DIR/$tdir
13311         mkdir $DIR/$tdir/normal_dir
13312
13313         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
13314         test_300_check_default_striped_dir normal_dir 1 0
13315         test_300_check_default_striped_dir normal_dir 2 1
13316         test_300_check_default_striped_dir normal_dir 2 -1
13317
13318         #delete default stripe information
13319         echo "delete default stripeEA"
13320         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
13321                 error "set default stripe on striped dir error"
13322
13323         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
13324         for dir in $(find $DIR/$tdir/normal_dir/*); do
13325                 stripe_count=$($LFS getdirstripe -c $dir)
13326                 [ $stripe_count -eq 0 ] ||
13327                         error "expect 1 get $stripe_count for $dir"
13328                 stripe_index=$($LFS getdirstripe -i $dir)
13329                 [ $stripe_index -eq 0 ] ||
13330                         error "expect 0 get $stripe_index for $dir"
13331         done
13332 }
13333 run_test 300g "check default striped directory for normal directory"
13334
13335 test_300h() {
13336         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13337         local dir
13338         local stripe_count
13339
13340         mkdir $DIR/$tdir
13341         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
13342                                         $DIR/$tdir/striped_dir ||
13343                 error "set striped dir error"
13344
13345         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
13346         test_300_check_default_striped_dir striped_dir 1 0
13347         test_300_check_default_striped_dir striped_dir 2 1
13348         test_300_check_default_striped_dir striped_dir 2 -1
13349
13350         #delete default stripe information
13351         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
13352                 error "set default stripe on striped dir error"
13353
13354         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13355         for dir in $(find $DIR/$tdir/striped_dir/*); do
13356                 stripe_count=$($LFS getdirstripe -c $dir)
13357                 [ $stripe_count -eq 0 ] ||
13358                         error "expect 1 get $stripe_count for $dir"
13359         done
13360 }
13361 run_test 300h "check default striped directory for striped directory"
13362
13363 test_300i() {
13364         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13365         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13366         local stripe_count
13367         local file
13368
13369         mkdir $DIR/$tdir
13370
13371         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13372                 error "set striped dir error"
13373
13374         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13375                 error "create files under striped dir failed"
13376
13377         # unfortunately, we need to umount to clear dir layout cache for now
13378         # once we fully implement dir layout, we can drop this
13379         umount_client $MOUNT || error "umount failed"
13380         mount_client $MOUNT || error "mount failed"
13381
13382         #set the stripe to be unknown hash type
13383         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
13384         $LCTL set_param fail_loc=0x1901
13385         for ((i = 0; i < 10; i++)); do
13386                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
13387                         error "stat f-$i failed"
13388                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
13389         done
13390
13391         touch $DIR/$tdir/striped_dir/f0 &&
13392                 error "create under striped dir with unknown hash should fail"
13393
13394         $LCTL set_param fail_loc=0
13395
13396         umount_client $MOUNT || error "umount failed"
13397         mount_client $MOUNT || error "mount failed"
13398
13399         return 0
13400 }
13401 run_test 300i "client handle unknown hash type striped directory"
13402
13403 test_400a() { # LU-1606, was conf-sanity test_74
13404         local extra_flags=''
13405         local out=$TMP/$tfile
13406         local prefix=/usr/include/lustre
13407         local prog
13408
13409         if ! which $CC > /dev/null 2>&1; then
13410                 skip_env "$CC is not installed"
13411                 return 0
13412         fi
13413
13414         if ! [[ -d $prefix ]]; then
13415                 # Assume we're running in tree and fixup the include path.
13416                 extra_flags+=" -I$LUSTRE/../libcfs/include"
13417                 extra_flags+=" -I$LUSTRE/include"
13418                 extra_flags+=" -L$LUSTRE/utils"
13419         fi
13420
13421         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
13422                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
13423                         error "client api broken"
13424         done
13425 }
13426 run_test 400a "Lustre client api program can compile and link"
13427
13428 test_400b() { # LU-1606, LU-5011
13429         local header
13430         local out=$TMP/$tfile
13431         local prefix=/usr/include/lustre
13432
13433         # We use a hard coded prefix so that this test will not fail
13434         # when run in tree. There are headers in lustre/include/lustre/
13435         # that are not packaged (like lustre_idl.h) and have more
13436         # complicated include dependencies (like config.h and lnet/types.h).
13437         # Since this test about correct packaging we just skip them when
13438         # they don't exist (see below) rather than try to fixup cppflags.
13439
13440         if ! which $CC > /dev/null 2>&1; then
13441                 skip_env "$CC is not installed"
13442                 return 0
13443         fi
13444
13445         for header in $prefix/*.h; do
13446                 if ! [[ -f "$header" ]]; then
13447                         continue
13448                 fi
13449
13450                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
13451                         continue # liblustreapi.h is deprecated.
13452                 fi
13453
13454                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
13455                         error "cannot compile '$header'"
13456         done
13457 }
13458 run_test 400b "packaged headers can be compiled"
13459
13460 #
13461 # tests that do cleanup/setup should be run at the end
13462 #
13463
13464 test_900() {
13465         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13466         local ls
13467         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13468         $LCTL set_param fail_loc=0x903
13469
13470         cancel_lru_locks MGC
13471
13472         FAIL_ON_ERROR=true cleanup
13473         FAIL_ON_ERROR=true setup
13474 }
13475 run_test 900 "umount should not race with any mgc requeue thread"
13476
13477 complete $SECONDS
13478 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13479 check_and_cleanup_lustre
13480 if [ "$I_MOUNTED" != "yes" ]; then
13481         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13482 fi
13483 exit_status