Whamcloud - gitweb
LU-2610 tests: Reenable sanity/40 for ZFS
[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 27m 64b 68 71 77f 78 115 124b 230d"
62
63 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
64 # bug number for skipped test:        LU-1593 LU-2833 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     48a     180     184c"
66
67 FAIL_ON_ERROR=false
68
69 cleanup() {
70         echo -n "cln.."
71         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
72         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
73 }
74 setup() {
75         echo -n "mnt.."
76         load_modules
77         setupall || exit 10
78         echo "done"
79 }
80
81 check_kernel_version() {
82         WANT_VER=$1
83         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
84         case $GOT_VER in
85         patchless|patchless_client) return 0;;
86         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
87         esac
88         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
89         return 1
90 }
91
92 check_swap_layouts_support()
93 {
94         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
95                 { skip "Does not support layout lock."; return 0; }
96         return 1
97 }
98
99 if [ "$ONLY" == "cleanup" ]; then
100        sh llmountcleanup.sh
101        exit 0
102 fi
103
104 check_and_setup_lustre
105
106 DIR=${DIR:-$MOUNT}
107 assert_DIR
108
109 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
110         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
111 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
112 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
113 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
114 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
115 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
116 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
117
118 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
119 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
120 rm -rf $DIR/[Rdfs][0-9]*
121
122 # $RUNAS_ID may get set incorrectly somewhere else
123 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
124
125 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
126
127 build_test_filter
128
129 if [ "${ONLY}" = "MOUNT" ] ; then
130         echo "Lustre is up, please go on"
131         exit
132 fi
133
134 echo "preparing for tests involving mounts"
135 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
136 touch $EXT2_DEV
137 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
138 echo # add a newline after mke2fs.
139
140 umask 077
141
142 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
143 lctl set_param debug=-1 2> /dev/null || true
144 test_0a() {
145         touch $DIR/$tfile
146         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
147         rm $DIR/$tfile
148         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
149 }
150 run_test 0a "touch; rm ====================="
151
152 test_0b() {
153         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
154         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
155 }
156 run_test 0b "chmod 0755 $DIR ============================="
157
158 test_0c() {
159         $LCTL get_param mdc.*.import | grep "state: FULL" ||
160                 error "import not FULL"
161         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
162                 error "bad target"
163 }
164 run_test 0c "check import proc ============================="
165
166 test_1() {
167         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
168         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
169         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
170         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
171         rmdir $DIR/$tdir/d2
172         rmdir $DIR/$tdir
173         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
174 }
175 run_test 1 "mkdir; remkdir; rmdir =============================="
176
177 test_2() {
178         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
179         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
180         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
181         rm -r $DIR/$tdir
182         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
183 }
184 run_test 2 "mkdir; touch; rmdir; check file ===================="
185
186 test_3() {
187         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
189         touch $DIR/$tdir/$tfile
190         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
191         rm -r $DIR/$tdir
192         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
193 }
194 run_test 3 "mkdir; touch; rmdir; check dir ====================="
195
196 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
197 test_4() {
198         local MDTIDX=1
199
200         test_mkdir $DIR/$tdir ||
201                 error "Create remote directory failed"
202
203         touch $DIR/$tdir/$tfile ||
204                 error "Create file under remote directory failed"
205
206         rmdir $DIR/$tdir &&
207                 error "Expect error removing in-use dir $DIR/$tdir"
208
209         test -d $DIR/$tdir || error "Remote directory disappeared"
210
211         rm -rf $DIR/$tdir || error "remove remote dir error"
212 }
213 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
214
215 test_5() {
216         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
217         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
218         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
219         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
220         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
221 }
222 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
223
224 test_6a() {
225         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
226         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
227         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
228                 error "$tfile does not have perm 0666 or UID $UID"
229         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
230         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
231                 error "$tfile should be 0666 and owned by UID $UID"
232 }
233 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
234
235 test_6c() {
236         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
237         touch $DIR/$tfile
238         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
239         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
240                 error "$tfile should be owned by UID $RUNAS_ID"
241         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
242         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
243                 error "$tfile should be owned by UID $RUNAS_ID"
244 }
245 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
246
247 test_6e() {
248         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
249         touch $DIR/$tfile
250         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
251         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
252                 error "$tfile should be owned by GID $UID"
253         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
254         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
255                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
256 }
257 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
258
259 test_6g() {
260         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
261         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
262         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
263         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
264         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
265         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
266         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
267                 error "$tdir/d/subdir should be GID $RUNAS_GID"
268 }
269 run_test 6g "Is new dir in sgid dir inheriting group?"
270
271 test_6h() { # bug 7331
272         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
273         touch $DIR/$tfile || error "touch failed"
274         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
275         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
276                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
277         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
278                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
279 }
280 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
281
282 test_7a() {
283         test_mkdir $DIR/$tdir
284         $MCREATE $DIR/$tdir/$tfile
285         chmod 0666 $DIR/$tdir/$tfile
286         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
287                 error "$tdir/$tfile should be mode 0666"
288 }
289 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
290
291 test_7b() {
292         if [ ! -d $DIR/$tdir ]; then
293                 mkdir $DIR/$tdir
294         fi
295         $MCREATE $DIR/$tdir/$tfile
296         echo -n foo > $DIR/$tdir/$tfile
297         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
298         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
299 }
300 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
301
302 test_8() {
303         test_mkdir $DIR/$tdir
304         touch $DIR/$tdir/$tfile
305         chmod 0666 $DIR/$tdir/$tfile
306         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
307                 error "$tfile mode not 0666"
308 }
309 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
310
311 test_9() {
312         test_mkdir $DIR/$tdir
313         test_mkdir $DIR/$tdir/d2
314         test_mkdir $DIR/$tdir/d2/d3
315         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
316 }
317 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
318
319 test_10() {
320         test_mkdir $DIR/$tdir
321         test_mkdir $DIR/$tdir/d2
322         touch $DIR/$tdir/d2/$tfile
323         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
324                 error "$tdir/d2/$tfile not a file"
325 }
326 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
327
328 test_11() {
329         test_mkdir $DIR/$tdir
330         test_mkdir $DIR/$tdir/d2
331         chmod 0666 $DIR/$tdir/d2
332         chmod 0705 $DIR/$tdir/d2
333         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
334                 error "$tdir/d2 mode not 0705"
335 }
336 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
337
338 test_12() {
339         test_mkdir $DIR/$tdir
340         touch $DIR/$tdir/$tfile
341         chmod 0666 $DIR/$tdir/$tfile
342         chmod 0654 $DIR/$tdir/$tfile
343         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
344                 error "$tdir/d2 mode not 0654"
345 }
346 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
347
348 test_13() {
349         test_mkdir $DIR/$tdir
350         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
351         >  $DIR/$tdir/$tfile
352         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
353                 error "$tdir/$tfile size not 0 after truncate"
354 }
355 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
356
357 test_14() {
358         test_mkdir $DIR/$tdir
359         touch $DIR/$tdir/$tfile
360         rm $DIR/$tdir/$tfile
361         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
362 }
363 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
364
365 test_15() {
366         test_mkdir $DIR/$tdir
367         touch $DIR/$tdir/$tfile
368         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
369         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
370                 error "$tdir/${tfile_2} not a file after rename"
371 }
372 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
373
374 test_16() {
375         test_mkdir $DIR/$tdir
376         touch $DIR/$tdir/$tfile
377         rm -rf $DIR/$tdir/$tfile
378         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
379 }
380 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
381
382 test_17a() {
383         test_mkdir -p $DIR/$tdir
384         touch $DIR/$tdir/$tfile
385         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
386         ls -l $DIR/$tdir
387         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
388                 error "$tdir/l-exist not a symlink"
389         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
390                 error "$tdir/l-exist not referencing a file"
391         rm -f $DIR/$tdir/l-exist
392         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
393 }
394 run_test 17a "symlinks: create, remove (real) =================="
395
396 test_17b() {
397         test_mkdir -p $DIR/$tdir
398         ln -s no-such-file $DIR/$tdir/l-dangle
399         ls -l $DIR/$tdir
400         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
401                 error "$tdir/l-dangle not referencing no-such-file"
402         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
403                 error "$tdir/l-dangle not referencing non-existent file"
404         rm -f $DIR/$tdir/l-dangle
405         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
406 }
407 run_test 17b "symlinks: create, remove (dangling) =============="
408
409 test_17c() { # bug 3440 - don't save failed open RPC for replay
410         test_mkdir -p $DIR/$tdir
411         ln -s foo $DIR/$tdir/$tfile
412         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
413 }
414 run_test 17c "symlinks: open dangling (should return error) ===="
415
416 test_17d() {
417         test_mkdir -p $DIR/$tdir
418         ln -s foo $DIR/$tdir/$tfile
419         touch $DIR/$tdir/$tfile || error "creating to new symlink"
420 }
421 run_test 17d "symlinks: create dangling ========================"
422
423 test_17e() {
424         test_mkdir -p $DIR/$tdir
425         local foo=$DIR/$tdir/$tfile
426         ln -s $foo $foo || error "create symlink failed"
427         ls -l $foo || error "ls -l failed"
428         ls $foo && error "ls not failed" || true
429 }
430 run_test 17e "symlinks: create recursive symlink (should return error) ===="
431
432 test_17f() {
433         test_mkdir -p $DIR/$tdir
434         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
435         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
436         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
437         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
438         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
439         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
440         ls -l  $DIR/$tdir
441 }
442 run_test 17f "symlinks: long and very long symlink name ========================"
443
444 # str_repeat(S, N) generate a string that is string S repeated N times
445 str_repeat() {
446         local s=$1
447         local n=$2
448         local ret=''
449         while [ $((n -= 1)) -ge 0 ]; do
450                 ret=$ret$s
451         done
452         echo $ret
453 }
454
455 # Long symlinks and LU-2241
456 test_17g() {
457         test_mkdir -p $DIR/$tdir
458         local TESTS="59 60 61 4094 4095"
459
460         # Fix for inode size boundary in 2.1.4
461         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
462                 TESTS="4094 4095"
463
464         # Patch not applied to 2.2 or 2.3 branches
465         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
466         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
467                 TESTS="4094 4095"
468
469         # skip long symlink name for rhel6.5.
470         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
471         grep -q '6.5' /etc/redhat-release &>/dev/null &&
472                 TESTS="59 60 61 4062 4063"
473
474         for i in $TESTS; do
475                 local SYMNAME=$(str_repeat 'x' $i)
476                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
477                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
478         done
479 }
480 run_test 17g "symlinks: really long symlink name and inode boundaries"
481
482 test_17h() { #bug 17378
483         remote_mds_nodsh && skip "remote MDS with nodsh" && return
484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
485         local mdt_idx
486         test_mkdir -p $DIR/$tdir
487         if [[ $MDSCOUNT -gt 1 ]]; then
488                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
489         else
490                 mdt_idx=0
491         fi
492         $SETSTRIPE -c -1 $DIR/$tdir
493 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
494         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
495         touch $DIR/$tdir/$tfile || true
496 }
497 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
498
499 test_17i() { #bug 20018
500         remote_mds_nodsh && skip "remote MDS with nodsh" && return
501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
502         test_mkdir -c1 $DIR/$tdir
503         local foo=$DIR/$tdir/$tfile
504         local mdt_idx
505         if [[ $MDSCOUNT -gt 1 ]]; then
506                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
507         else
508                 mdt_idx=0
509         fi
510         ln -s $foo $foo || error "create symlink failed"
511 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
512         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
513         ls -l $foo && error "error not detected"
514         return 0
515 }
516 run_test 17i "don't panic on short symlink"
517
518 test_17k() { #bug 22301
519         [[ -z "$(which rsync 2>/dev/null)" ]] &&
520                 skip "no rsync command" && return 0
521         rsync --help | grep -q xattr ||
522                 skip_env "$(rsync --version | head -n1) does not support xattrs"
523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
524         test_mkdir -p $DIR/$tdir
525         test_mkdir -p $DIR/$tdir.new
526         touch $DIR/$tdir/$tfile
527         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
528         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
529                 error "rsync failed with xattrs enabled"
530 }
531 run_test 17k "symlinks: rsync with xattrs enabled ========================="
532
533 test_17l() { # LU-279
534         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
535                 skip "no getfattr command" && return 0
536         mkdir -p $DIR/$tdir
537         touch $DIR/$tdir/$tfile
538         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
539         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
540                 # -h to not follow symlinks. -m '' to list all the xattrs.
541                 # grep to remove first line: '# file: $path'.
542                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
543                 do
544                         lgetxattr_size_check $path $xattr ||
545                                 error "lgetxattr_size_check $path $xattr failed"
546                 done
547         done
548 }
549 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
550
551 # LU-1540
552 test_17m() {
553         local short_sym="0123456789"
554         local WDIR=$DIR/${tdir}m
555         local mds_index
556         local devname
557         local cmd
558         local i
559         local rc=0
560
561         remote_mds_nodsh && skip "remote MDS with nodsh" && return
562         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
563         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
564                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
565
566         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
567                 skip "only for ldiskfs MDT" && return 0
568
569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
570
571         mkdir -p $WDIR
572         long_sym=$short_sym
573         # create a long symlink file
574         for ((i = 0; i < 4; ++i)); do
575                 long_sym=${long_sym}${long_sym}
576         done
577
578         echo "create 512 short and long symlink files under $WDIR"
579         for ((i = 0; i < 256; ++i)); do
580                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
581                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
582         done
583
584         echo "erase them"
585         rm -f $WDIR/*
586         sync
587         wait_delete_completed
588
589         echo "recreate the 512 symlink files with a shorter string"
590         for ((i = 0; i < 512; ++i)); do
591                 # rewrite the symlink file with a shorter string
592                 ln -sf ${long_sym} $WDIR/long-$i
593                 ln -sf ${short_sym} $WDIR/short-$i
594         done
595
596         mds_index=$($LFS getstripe -M $WDIR)
597         mds_index=$((mds_index+1))
598         devname=$(mdsdevname $mds_index)
599         cmd="$E2FSCK -fnvd $devname"
600
601         echo "stop and checking mds${mds_index}: $cmd"
602         # e2fsck should not return error
603         stop mds${mds_index}
604         do_facet mds${mds_index} $cmd || rc=$?
605
606         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
607         df $MOUNT > /dev/null 2>&1
608         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
609                 "short/long symlink MDT: rc=$rc"
610         return $rc
611 }
612 run_test 17m "run e2fsck against MDT which contains short/long symlink"
613
614 check_fs_consistency_17n() {
615         local mdt_index
616         local devname
617         local cmd
618         local rc=0
619
620         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
621         # so it only check MDT1/MDT2 instead of all of MDTs.
622         for mdt_index in $(seq 1 2); do
623                 devname=$(mdsdevname $mdt_index)
624                 cmd="$E2FSCK -fnvd $devname"
625
626                 echo "stop and checking mds${mdt_index}: $cmd"
627                 # e2fsck should not return error
628                 stop mds${mdt_index}
629                 do_facet mds${mdt_index} $cmd || rc=$?
630
631                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
632                         error "mount mds${mdt_index} failed"
633                 df $MOUNT > /dev/null 2>&1
634                 [ $rc -ne 0 ] && break
635         done
636         return $rc
637 }
638
639 test_17n() {
640         local i
641
642         remote_mds_nodsh && skip "remote MDS with nodsh" && return
643         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
644         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
645                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
646
647         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
648                 skip "only for ldiskfs MDT" && return 0
649
650         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
651
652         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
653
654         mkdir $DIR/$tdir
655         for ((i=0; i<10; i++)); do
656                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
657                         error "create remote dir error $i"
658                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
659                         error "create files under remote dir failed $i"
660         done
661
662         check_fs_consistency_17n ||
663                 error "e2fsck report error after create files under remote dir"
664
665         for ((i=0;i<10;i++)); do
666                 rm -rf $DIR/$tdir/remote_dir_${i} ||
667                         error "destroy remote dir error $i"
668         done
669
670         check_fs_consistency_17n ||
671                 error "e2fsck report error after unlink files under remote dir"
672
673         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
674                 skip "lustre < 2.4.50 does not support migrate mv " && return
675
676         for ((i=0; i<10; i++)); do
677                 mkdir -p $DIR/$tdir/remote_dir_${i}
678                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
679                         error "create files under remote dir failed $i"
680                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
681                         error "migrate remote dir error $i"
682         done
683         check_fs_consistency_17n || error "e2fsck report error after migration"
684
685         for ((i=0;i<10;i++)); do
686                 rm -rf $DIR/$tdir/remote_dir_${i} ||
687                         error "destroy remote dir error $i"
688         done
689
690         check_fs_consistency_17n || error "e2fsck report error after unlink"
691 }
692 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
693
694 test_17o() {
695         remote_mds_nodsh && skip "remote MDS with nodsh" && return
696         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
697                 skip "Need MDS version at least 2.3.64" && return
698
699         local WDIR=$DIR/${tdir}o
700         local mdt_index
701         local mdtdevname
702         local rc=0
703
704         mkdir -p $WDIR
705         mdt_index=$($LFS getstripe -M $WDIR)
706         mdt_index=$((mdt_index+1))
707         mdtdevname=$(mdsdevname $mdt_index)
708
709         touch $WDIR/$tfile
710         stop mds${mdt_index}
711         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS ||
712                 error "mount mds${mdt_index} failed"
713
714         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
715         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
716         ls -l $WDIR/$tfile && rc=1
717         do_facet mds${mdt_index} lctl set_param fail_loc=0
718         [[ $rc -ne 0 ]] && error "stat file should fail"
719         true
720 }
721 run_test 17o "stat file with incompat LMA feature"
722
723 test_18() {
724         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
725         ls $DIR || error "Failed to ls $DIR: $?"
726 }
727 run_test 18 "touch .../f ; ls ... =============================="
728
729 test_19a() {
730         touch $DIR/$tfile
731         ls -l $DIR
732         rm $DIR/$tfile
733         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
734 }
735 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
736
737 test_19b() {
738         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
739 }
740 run_test 19b "ls -l .../f19 (should return error) =============="
741
742 test_19c() {
743         [ $RUNAS_ID -eq $UID ] &&
744                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
745         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
746 }
747 run_test 19c "$RUNAS touch .../f19 (should return error) =="
748
749 test_19d() {
750         cat $DIR/f19 && error || true
751 }
752 run_test 19d "cat .../f19 (should return error) =============="
753
754 test_20() {
755         touch $DIR/$tfile
756         rm $DIR/$tfile
757         log "1 done"
758         touch $DIR/$tfile
759         rm $DIR/$tfile
760         log "2 done"
761         touch $DIR/$tfile
762         rm $DIR/$tfile
763         log "3 done"
764         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
765 }
766 run_test 20 "touch .../f ; ls -l ... ==========================="
767
768 test_21() {
769         test_mkdir -p $DIR/$tdir
770         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
771         ln -s dangle $DIR/$tdir/link
772         echo foo >> $DIR/$tdir/link
773         cat $DIR/$tdir/dangle
774         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
775         $CHECKSTAT -f -t file $DIR/$tdir/link ||
776                 error "$tdir/link not linked to a file"
777 }
778 run_test 21 "write to dangling link ============================"
779
780 test_22() {
781         WDIR=$DIR/$tdir
782         test_mkdir -p $DIR/$tdir
783         chown $RUNAS_ID:$RUNAS_GID $WDIR
784         (cd $WDIR || error "cd $WDIR failed";
785         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
786         $RUNAS tar xf -)
787         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
788         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
789         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
790 }
791 run_test 22 "unpack tar archive as non-root user ==============="
792
793 # was test_23
794 test_23a() {
795         test_mkdir -p $DIR/$tdir
796         local file=$DIR/$tdir/$tfile
797
798         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
799         openfile -f O_CREAT:O_EXCL $file &&
800                 error "$file recreate succeeded" || true
801 }
802 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
803
804 test_23b() { # bug 18988
805         test_mkdir -p $DIR/$tdir
806         local file=$DIR/$tdir/$tfile
807
808         rm -f $file
809         echo foo > $file || error "write filed"
810         echo bar >> $file || error "append filed"
811         $CHECKSTAT -s 8 $file || error "wrong size"
812         rm $file
813 }
814 run_test 23b "O_APPEND check =========================="
815
816 # rename sanity
817 test_24a() {
818         echo '-- same directory rename'
819         test_mkdir $DIR/$tdir
820         touch $DIR/$tdir/$tfile.1
821         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
822         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
823 }
824 run_test 24a "rename file to non-existent target"
825
826 test_24b() {
827         test_mkdir $DIR/$tdir
828         touch $DIR/$tdir/$tfile.{1,2}
829         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
830         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
831         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
832 }
833 run_test 24b "rename file to existing target"
834
835 test_24c() {
836         test_mkdir $DIR/$tdir
837         test_mkdir $DIR/$tdir/d$testnum.1
838         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
839         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
840         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
841 }
842 run_test 24c "rename directory to non-existent target"
843
844 test_24d() {
845         test_mkdir -c1 $DIR/$tdir
846         test_mkdir -c1 $DIR/$tdir/d$testnum.1
847         test_mkdir -c1 $DIR/$tdir/d$testnum.2
848         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
849         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
850         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
851 }
852 run_test 24d "rename directory to existing target"
853
854 test_24e() {
855         echo '-- cross directory renames --'
856         test_mkdir $DIR/R5a
857         test_mkdir $DIR/R5b
858         touch $DIR/R5a/f
859         mv $DIR/R5a/f $DIR/R5b/g
860         $CHECKSTAT -a $DIR/R5a/f || error
861         $CHECKSTAT -t file $DIR/R5b/g || error
862 }
863 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
864
865 test_24f() {
866         test_mkdir $DIR/R6a
867         test_mkdir $DIR/R6b
868         touch $DIR/R6a/f $DIR/R6b/g
869         mv $DIR/R6a/f $DIR/R6b/g
870         $CHECKSTAT -a $DIR/R6a/f || error
871         $CHECKSTAT -t file $DIR/R6b/g || error
872 }
873 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
874
875 test_24g() {
876         test_mkdir $DIR/R7a
877         test_mkdir $DIR/R7b
878         test_mkdir $DIR/R7a/d
879         mv $DIR/R7a/d $DIR/R7b/e
880         $CHECKSTAT -a $DIR/R7a/d || error
881         $CHECKSTAT -t dir $DIR/R7b/e || error
882 }
883 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
884
885 test_24h() {
886         test_mkdir -c1 $DIR/R8a
887         test_mkdir -c1 $DIR/R8b
888         test_mkdir -c1 $DIR/R8a/d
889         test_mkdir -c1 $DIR/R8b/e
890         mrename $DIR/R8a/d $DIR/R8b/e
891         $CHECKSTAT -a $DIR/R8a/d || error
892         $CHECKSTAT -t dir $DIR/R8b/e || error
893 }
894 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
895
896 test_24i() {
897         echo "-- rename error cases"
898         test_mkdir $DIR/R9
899         test_mkdir $DIR/R9/a
900         touch $DIR/R9/f
901         mrename $DIR/R9/f $DIR/R9/a
902         $CHECKSTAT -t file $DIR/R9/f || error
903         $CHECKSTAT -t dir  $DIR/R9/a || error
904         $CHECKSTAT -a $DIR/R9/a/f || error
905 }
906 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
907
908 test_24j() {
909         test_mkdir $DIR/R10
910         mrename $DIR/R10/f $DIR/R10/g
911         $CHECKSTAT -t dir $DIR/R10 || error
912         $CHECKSTAT -a $DIR/R10/f || error
913         $CHECKSTAT -a $DIR/R10/g || error
914 }
915 run_test 24j "source does not exist ============================"
916
917 test_24k() {
918         test_mkdir $DIR/R11a
919         test_mkdir $DIR/R11a/d
920         touch $DIR/R11a/f
921         mv $DIR/R11a/f $DIR/R11a/d
922         $CHECKSTAT -a $DIR/R11a/f || error
923         $CHECKSTAT -t file $DIR/R11a/d/f || error
924 }
925 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
926
927 # bug 2429 - rename foo foo foo creates invalid file
928 test_24l() {
929         f="$DIR/f24l"
930         $MULTIOP $f OcNs || error
931 }
932 run_test 24l "Renaming a file to itself ========================"
933
934 test_24m() {
935         f="$DIR/f24m"
936         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
937         # on ext3 this does not remove either the source or target files
938         # though the "expected" operation would be to remove the source
939         $CHECKSTAT -t file ${f} || error "${f} missing"
940         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
941 }
942 run_test 24m "Renaming a file to a hard link to itself ========="
943
944 test_24n() {
945     f="$DIR/f24n"
946     # this stats the old file after it was renamed, so it should fail
947     touch ${f}
948     $CHECKSTAT ${f}
949     mv ${f} ${f}.rename
950     $CHECKSTAT ${f}.rename
951     $CHECKSTAT -a ${f}
952 }
953 run_test 24n "Statting the old file after renaming (Posix rename 2)"
954
955 test_24o() {
956         check_kernel_version 37 || return 0
957         test_mkdir -p $DIR/d24o
958         rename_many -s random -v -n 10 $DIR/d24o
959 }
960 run_test 24o "rename of files during htree split ==============="
961
962 test_24p() {
963         test_mkdir $DIR/R12a
964         test_mkdir $DIR/R12b
965         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
966         mrename $DIR/R12a $DIR/R12b
967         $CHECKSTAT -a $DIR/R12a || error
968         $CHECKSTAT -t dir $DIR/R12b || error
969         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
970         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
971 }
972 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
973
974 cleanup_multiop_pause() {
975         trap 0
976         kill -USR1 $MULTIPID
977 }
978
979 test_24q() {
980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
981         test_mkdir $DIR/R13a
982         test_mkdir $DIR/R13b
983         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
984         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
985         MULTIPID=$!
986
987         trap cleanup_multiop_pause EXIT
988         mrename $DIR/R13a $DIR/R13b
989         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
990         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
991         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
992         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
993         cleanup_multiop_pause
994         wait $MULTIPID || error "multiop close failed"
995 }
996 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
997
998 test_24r() { #bug 3789
999         test_mkdir $DIR/R14a
1000         test_mkdir $DIR/R14a/b
1001         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1002         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1003         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1004 }
1005 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1006
1007 test_24s() {
1008         test_mkdir $DIR/R15a
1009         test_mkdir $DIR/R15a/b
1010         test_mkdir $DIR/R15a/b/c
1011         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1012         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1013         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1014 }
1015 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1016 test_24t() {
1017         test_mkdir $DIR/R16a
1018         test_mkdir $DIR/R16a/b
1019         test_mkdir $DIR/R16a/b/c
1020         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1021         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1022         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1023 }
1024 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1025
1026 test_24u() { # bug12192
1027         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1028         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1029 }
1030 run_test 24u "create stripe file"
1031
1032 page_size() {
1033         getconf PAGE_SIZE
1034 }
1035
1036 simple_cleanup_common() {
1037         trap 0
1038         rm -rf $DIR/$tdir
1039         wait_delete_completed
1040 }
1041
1042 max_pages_per_rpc() {
1043         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1044 }
1045
1046 test_24v() {
1047         local NRFILES=100000
1048         local FREE_INODES=$(mdt_free_inodes 0)
1049         [[ $FREE_INODES -lt $NRFILES ]] &&
1050                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1051                 return
1052
1053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1054         trap simple_cleanup_common EXIT
1055
1056         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1057         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1058
1059         mkdir -p $DIR/$tdir
1060         createmany -m $DIR/$tdir/$tfile $NRFILES
1061
1062         cancel_lru_locks mdc
1063         lctl set_param mdc.*.stats clear
1064
1065         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1066
1067         # LU-5 large readdir
1068         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1069         #               8 bytes for name(filename is mostly 5 in this test) +
1070         #               8 bytes for luda_type
1071         # take into account of overhead in lu_dirpage header and end mark in
1072         # each page, plus one in RPC_NUM calculation.
1073         DIRENT_SIZE=48
1074         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1075         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1076         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1077                                 awk '/^mds_readpage/ {print $2}')
1078         [[ $mds_readpage -gt $RPC_NUM ]] &&
1079                 error "large readdir doesn't take effect"
1080
1081         simple_cleanup_common
1082 }
1083 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1084
1085 test_24w() { # bug21506
1086         SZ1=234852
1087         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1088         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1089         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1090         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1091         [[ "$SZ1" -eq "$SZ2" ]] ||
1092                 error "Error reading at the end of the file $tfile"
1093 }
1094 run_test 24w "Reading a file larger than 4Gb"
1095
1096 test_24x() {
1097         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1099         local MDTIDX=1
1100         local remote_dir=$DIR/$tdir/remote_dir
1101
1102         mkdir -p $DIR/$tdir
1103         $LFS mkdir -i $MDTIDX $remote_dir ||
1104                 error "create remote directory failed"
1105
1106         mkdir -p $DIR/$tdir/src_dir
1107         touch $DIR/$tdir/src_file
1108         mkdir -p $remote_dir/tgt_dir
1109         touch $remote_dir/tgt_file
1110
1111         mrename $remote_dir $DIR/ &&
1112                 error "rename dir cross MDT works!"
1113
1114         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1115                 error "rename dir cross MDT works!"
1116
1117         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1118                 error "rename file cross MDT works!"
1119
1120         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1121                 error "ln file cross MDT should not work!"
1122
1123         rm -rf $DIR/$tdir || error "Can not delete directories"
1124 }
1125 run_test 24x "cross rename/link should be failed"
1126
1127 test_24y() {
1128         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1130         local MDTIDX=1
1131         local remote_dir=$DIR/$tdir/remote_dir
1132
1133         mkdir -p $DIR/$tdir
1134         $LFS mkdir -i $MDTIDX $remote_dir ||
1135                    error "create remote directory failed"
1136
1137         mkdir -p $remote_dir/src_dir
1138         touch $remote_dir/src_file
1139         mkdir -p $remote_dir/tgt_dir
1140         touch $remote_dir/tgt_file
1141
1142         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1143                 error "rename subdir in the same remote dir failed!"
1144
1145         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1146                 error "rename files in the same remote dir failed!"
1147
1148         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1149                 error "link files in the same remote dir failed!"
1150
1151         rm -rf $DIR/$tdir || error "Can not delete directories"
1152 }
1153 run_test 24y "rename/link on the same dir should succeed"
1154
1155 test_24z() {
1156         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1158         local MDTIDX=1
1159         local remote_src=$DIR/$tdir/remote_dir
1160         local remote_tgt=$DIR/$tdir/remote_tgt
1161
1162         mkdir -p $DIR/$tdir
1163         $LFS mkdir -i $MDTIDX $remote_src ||
1164                    error "create remote directory failed"
1165
1166         $LFS mkdir -i $MDTIDX $remote_tgt ||
1167                    error "create remote directory failed"
1168
1169         mrename $remote_src $remote_tgt &&
1170                 error "rename remote dirs should not work!"
1171
1172         # If target dir does not exists, it should succeed
1173         rm -rf $remote_tgt
1174         mrename $remote_src $remote_tgt ||
1175                 error "rename remote dirs(tgt dir does not exists) failed!"
1176
1177         rm -rf $DIR/$tdir || error "Can not delete directories"
1178 }
1179 run_test 24z "rename one remote dir to another remote dir should fail"
1180
1181 test_24A() { # LU-3182
1182         local NFILES=5000
1183
1184         rm -rf $DIR/$tdir
1185         mkdir -p $DIR/$tdir
1186         createmany -m $DIR/$tdir/$tfile $NFILES
1187         local t=$(ls $DIR/$tdir | wc -l)
1188         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1189         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1190         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1191                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1192         fi
1193
1194         rm -rf $DIR/$tdir || error "Can not delete directories"
1195 }
1196 run_test 24A "readdir() returns correct number of entries."
1197
1198 test_24B() { # LU-4805
1199         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1200         local count
1201
1202         mkdir $DIR/$tdir
1203         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1204                 error "create striped dir failed"
1205
1206         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1207         [ $count -eq 2 ] || error "Expected 2, got $count"
1208
1209         touch $DIR/$tdir/striped_dir/a
1210
1211         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1212         [ $count -eq 3 ] || error "Expected 3, got $count"
1213
1214         touch $DIR/$tdir/striped_dir/.f
1215
1216         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1217         [ $count -eq 4 ] || error "Expected 4, got $count"
1218
1219         rm -rf $DIR/$tdir || error "Can not delete directories"
1220 }
1221 run_test 24B "readdir for striped dir return correct number of entries"
1222
1223 test_24C() {
1224         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1225
1226         mkdir $DIR/$tdir
1227         mkdir $DIR/$tdir/d0
1228         mkdir $DIR/$tdir/d1
1229
1230         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1231                 error "create striped dir failed"
1232
1233         cd $DIR/$tdir/d0/striped_dir
1234
1235         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1236         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1237         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1238
1239         [ "$d0_ino" = "$parent_ino" ] ||
1240                 error ".. wrong, expect $d0_ino, get $parent_ino"
1241
1242         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1243                 error "mv striped dir failed"
1244
1245         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1246
1247         [ "$d1_ino" = "$parent_ino" ] ||
1248                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1249 }
1250 run_test 24C "check .. in striped dir"
1251
1252 test_25a() {
1253         echo '== symlink sanity ============================================='
1254
1255         test_mkdir $DIR/d25
1256         ln -s d25 $DIR/s25
1257         touch $DIR/s25/foo || error
1258 }
1259 run_test 25a "create file in symlinked directory ==============="
1260
1261 test_25b() {
1262         [ ! -d $DIR/d25 ] && test_25a
1263         $CHECKSTAT -t file $DIR/s25/foo || error
1264 }
1265 run_test 25b "lookup file in symlinked directory ==============="
1266
1267 test_26a() {
1268         test_mkdir $DIR/d26
1269         test_mkdir $DIR/d26/d26-2
1270         ln -s d26/d26-2 $DIR/s26
1271         touch $DIR/s26/foo || error
1272 }
1273 run_test 26a "multiple component symlink ======================="
1274
1275 test_26b() {
1276         test_mkdir -p $DIR/d26b/d26-2
1277         ln -s d26b/d26-2/foo $DIR/s26-2
1278         touch $DIR/s26-2 || error
1279 }
1280 run_test 26b "multiple component symlink at end of lookup ======"
1281
1282 test_26c() {
1283         test_mkdir $DIR/d26.2
1284         touch $DIR/d26.2/foo
1285         ln -s d26.2 $DIR/s26.2-1
1286         ln -s s26.2-1 $DIR/s26.2-2
1287         ln -s s26.2-2 $DIR/s26.2-3
1288         chmod 0666 $DIR/s26.2-3/foo
1289 }
1290 run_test 26c "chain of symlinks ================================"
1291
1292 # recursive symlinks (bug 439)
1293 test_26d() {
1294         ln -s d26-3/foo $DIR/d26-3
1295 }
1296 run_test 26d "create multiple component recursive symlink ======"
1297
1298 test_26e() {
1299         [ ! -h $DIR/d26-3 ] && test_26d
1300         rm $DIR/d26-3
1301 }
1302 run_test 26e "unlink multiple component recursive symlink ======"
1303
1304 # recursive symlinks (bug 7022)
1305 test_26f() {
1306         test_mkdir -p $DIR/$tdir
1307         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1308         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1309         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1310         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1311         cd $tfile                || error "cd $tfile failed"
1312         ln -s .. dotdot          || error "ln dotdot failed"
1313         ln -s dotdot/lndir lndir || error "ln lndir failed"
1314         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1315         output=`ls $tfile/$tfile/lndir/bar1`
1316         [ "$output" = bar1 ] && error "unexpected output"
1317         rm -r $tfile             || error "rm $tfile failed"
1318         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1319 }
1320 run_test 26f "rm -r of a directory which has recursive symlink ="
1321
1322 test_27a() {
1323         echo '== stripe sanity =============================================='
1324         test_mkdir -p $DIR/d27 || error "mkdir failed"
1325         $GETSTRIPE $DIR/d27
1326         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1327         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1328         log "== test_27a: write to one stripe file ========================="
1329         cp /etc/hosts $DIR/d27/f0 || error
1330 }
1331 run_test 27a "one stripe file =================================="
1332
1333 test_27b() {
1334         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1335         test_mkdir -p $DIR/d27
1336         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1337         $GETSTRIPE -c $DIR/d27/f01
1338         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1339                 error "two-stripe file doesn't have two stripes"
1340
1341         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1342 }
1343 run_test 27b "create and write to two stripe file"
1344
1345 test_27d() {
1346         test_mkdir -p $DIR/d27
1347         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1348         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1349         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1350 }
1351 run_test 27d "create file with default settings ================"
1352
1353 test_27e() {
1354         test_mkdir -p $DIR/d27
1355         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1356         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1357         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1358 }
1359 run_test 27e "setstripe existing file (should return error) ======"
1360
1361 test_27f() {
1362         test_mkdir -p $DIR/d27
1363         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1364         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1365         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1366 }
1367 run_test 27f "setstripe with bad stripe size (should return error)"
1368
1369 test_27g() {
1370         test_mkdir -p $DIR/d27
1371         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1372         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1373                 error "$DIR/d27/fnone has object"
1374 }
1375 run_test 27g "$GETSTRIPE with no objects"
1376
1377 test_27i() {
1378         touch $DIR/d27/fsome || error "touch failed"
1379         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1380 }
1381 run_test 27i "$GETSTRIPE with some objects"
1382
1383 test_27j() {
1384         test_mkdir -p $DIR/d27
1385         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1386 }
1387 run_test 27j "setstripe with bad stripe offset (should return error)"
1388
1389 test_27k() { # bug 2844
1390         test_mkdir -p $DIR/d27
1391         FILE=$DIR/d27/f27k
1392         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1393         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1394         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1395         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1396         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1397         dd if=/dev/zero of=$FILE bs=4k count=1
1398         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1399         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1400 }
1401 run_test 27k "limit i_blksize for broken user apps ============="
1402
1403 test_27l() {
1404         test_mkdir -p $DIR/d27
1405         mcreate $DIR/f27l || error "creating file"
1406         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1407                 error "setstripe should have failed" || true
1408 }
1409 run_test 27l "check setstripe permissions (should return error)"
1410
1411 test_27m() {
1412         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1413                 return
1414         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1415                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1416                 return
1417         fi
1418         trap simple_cleanup_common EXIT
1419         test_mkdir -p $DIR/$tdir
1420         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1421         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1422                 error "dd should fill OST0"
1423         i=2
1424         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1425                 i=$((i + 1))
1426                 [ $i -gt 256 ] && break
1427         done
1428         i=$((i + 1))
1429         touch $DIR/$tdir/f27m_$i
1430         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1431                 error "OST0 was full but new created file still use it"
1432         i=$((i + 1))
1433         touch $DIR/$tdir/f27m_$i
1434         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1435                 error "OST0 was full but new created file still use it"
1436         simple_cleanup_common
1437 }
1438 run_test 27m "create file while OST0 was full =================="
1439
1440 sleep_maxage() {
1441         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1442         sleep $DELAY
1443 }
1444
1445 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1446 # if the OST isn't full anymore.
1447 reset_enospc() {
1448         local OSTIDX=${1:-""}
1449
1450         local list=$(comma_list $(osts_nodes))
1451         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1452
1453         do_nodes $list lctl set_param fail_loc=0
1454         sync    # initiate all OST_DESTROYs from MDS to OST
1455         sleep_maxage
1456 }
1457
1458 exhaust_precreations() {
1459         local OSTIDX=$1
1460         local FAILLOC=$2
1461         local FAILIDX=${3:-$OSTIDX}
1462
1463         test_mkdir -p $DIR/$tdir
1464         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1465         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1466
1467         local OST=$(ostname_from_index $OSTIDX)
1468         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1469                           sed -e 's/_UUID$//;s/^.*-//')
1470
1471         # on the mdt's osc
1472         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1473         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1474                         osc.$mdtosc_proc1.prealloc_last_id)
1475         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1476                         osc.$mdtosc_proc1.prealloc_next_id)
1477
1478         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1479         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1480
1481         test_mkdir -p $DIR/$tdir/${OST}
1482         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1483 #define OBD_FAIL_OST_ENOSPC              0x215
1484         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1485         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1486         echo "Creating to objid $last_id on ost $OST..."
1487         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1488         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1489         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1490         sleep_maxage
1491 }
1492
1493 exhaust_all_precreations() {
1494         local i
1495         for (( i=0; i < OSTCOUNT; i++ )) ; do
1496                 exhaust_precreations $i $1 -1
1497         done
1498 }
1499
1500 test_27n() {
1501         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1502         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1503         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1504         remote_ost_nodsh && skip "remote OST with nodsh" && return
1505
1506         reset_enospc
1507         rm -f $DIR/$tdir/$tfile
1508         exhaust_precreations 0 0x80000215
1509         $SETSTRIPE -c -1 $DIR/$tdir
1510         touch $DIR/$tdir/$tfile || error
1511         $GETSTRIPE $DIR/$tdir/$tfile
1512         reset_enospc
1513 }
1514 run_test 27n "create file with some full OSTs =================="
1515
1516 test_27o() {
1517         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1520         remote_ost_nodsh && skip "remote OST with nodsh" && return
1521
1522         reset_enospc
1523         rm -f $DIR/$tdir/$tfile
1524         exhaust_all_precreations 0x215
1525
1526         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1527
1528         reset_enospc
1529         rm -rf $DIR/$tdir/*
1530 }
1531 run_test 27o "create file with all full OSTs (should error) ===="
1532
1533 test_27p() {
1534         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1536         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1537         remote_ost_nodsh && skip "remote OST with nodsh" && return
1538
1539         reset_enospc
1540         rm -f $DIR/$tdir/$tfile
1541         test_mkdir -p $DIR/$tdir
1542
1543         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1544         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1545         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1546
1547         exhaust_precreations 0 0x80000215
1548         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1549         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1550         $GETSTRIPE $DIR/$tdir/$tfile
1551
1552         reset_enospc
1553 }
1554 run_test 27p "append to a truncated file with some full OSTs ==="
1555
1556 test_27q() {
1557         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1559         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1560         remote_ost_nodsh && skip "remote OST with nodsh" && return
1561
1562         reset_enospc
1563         rm -f $DIR/$tdir/$tfile
1564
1565         test_mkdir -p $DIR/$tdir
1566         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1567         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1568         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1569
1570         exhaust_all_precreations 0x215
1571
1572         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1573         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1574
1575         reset_enospc
1576 }
1577 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1578
1579 test_27r() {
1580         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1581         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1582         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1583         remote_ost_nodsh && skip "remote OST with nodsh" && return
1584
1585         reset_enospc
1586         rm -f $DIR/$tdir/$tfile
1587         exhaust_precreations 0 0x80000215
1588
1589         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1590
1591         reset_enospc
1592 }
1593 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1594
1595 test_27s() { # bug 10725
1596         test_mkdir -p $DIR/$tdir
1597         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1598         local stripe_count=0
1599         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1600         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1601                 error "stripe width >= 2^32 succeeded" || true
1602
1603 }
1604 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1605
1606 test_27t() { # bug 10864
1607         WDIR=$(pwd)
1608         WLFS=$(which lfs)
1609         cd $DIR
1610         touch $tfile
1611         $WLFS getstripe $tfile
1612         cd $WDIR
1613 }
1614 run_test 27t "check that utils parse path correctly"
1615
1616 test_27u() { # bug 4900
1617         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1618         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1619         local index
1620         local list=$(comma_list $(mdts_nodes))
1621
1622 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1623         do_nodes $list $LCTL set_param fail_loc=0x139
1624         test_mkdir -p $DIR/$tdir
1625         rm -rf $DIR/$tdir/*
1626         createmany -o $DIR/$tdir/t- 1000
1627         do_nodes $list $LCTL set_param fail_loc=0
1628
1629         TLOG=$DIR/$tfile.getstripe
1630         $GETSTRIPE $DIR/$tdir > $TLOG
1631         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1632         unlinkmany $DIR/$tdir/t- 1000
1633         [[ $OBJS -gt 0 ]] &&
1634                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1635 }
1636 run_test 27u "skip object creation on OSC w/o objects =========="
1637
1638 test_27v() { # bug 4900
1639         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1641         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1642         remote_ost_nodsh && skip "remote OST with nodsh" && return
1643
1644         exhaust_all_precreations 0x215
1645         reset_enospc
1646
1647         test_mkdir -p $DIR/$tdir
1648         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1649
1650         touch $DIR/$tdir/$tfile
1651         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1652         # all except ost1
1653         for (( i=1; i < OSTCOUNT; i++ )); do
1654                 do_facet ost$i lctl set_param fail_loc=0x705
1655         done
1656         local START=`date +%s`
1657         createmany -o $DIR/$tdir/$tfile 32
1658
1659         local FINISH=`date +%s`
1660         local TIMEOUT=`lctl get_param -n timeout`
1661         local PROCESS=$((FINISH - START))
1662         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1663                error "$FINISH - $START >= $TIMEOUT / 2"
1664         sleep $((TIMEOUT / 2 - PROCESS))
1665         reset_enospc
1666 }
1667 run_test 27v "skip object creation on slow OST ================="
1668
1669 test_27w() { # bug 10997
1670         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1671         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1672         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1673                 error "stripe size $size != 65536" || true
1674         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1675                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1676 }
1677 run_test 27w "check $SETSTRIPE -S option"
1678
1679 test_27wa() {
1680         [[ $OSTCOUNT -lt 2 ]] &&
1681                 skip_env "skipping multiple stripe count/offset test" && return
1682
1683         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1684         for i in $(seq 1 $OSTCOUNT); do
1685                 offset=$((i - 1))
1686                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1687                         error "setstripe -c $i -i $offset failed"
1688                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1689                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1690                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1691                 [ $index -ne $offset ] &&
1692                         error "stripe offset $index != $offset" || true
1693         done
1694 }
1695 run_test 27wa "check $SETSTRIPE -c -i options"
1696
1697 test_27x() {
1698         remote_ost_nodsh && skip "remote OST with nodsh" && return
1699         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1700         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1701         OFFSET=$(($OSTCOUNT - 1))
1702         OSTIDX=0
1703         local OST=$(ostname_from_index $OSTIDX)
1704
1705         test_mkdir -p $DIR/$tdir
1706         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1707         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1708         sleep_maxage
1709         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1710         for i in `seq 0 $OFFSET`; do
1711                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1712                 error "OST0 was degraded but new created file still use it"
1713         done
1714         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1715 }
1716 run_test 27x "create files while OST0 is degraded"
1717
1718 test_27y() {
1719         [[ $OSTCOUNT -lt 2 ]] &&
1720                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1721         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1722         remote_ost_nodsh && skip "remote OST with nodsh" && return
1723         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1724
1725         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1726         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1727             osc.$mdtosc.prealloc_last_id)
1728         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1729             osc.$mdtosc.prealloc_next_id)
1730         local fcount=$((last_id - next_id))
1731         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1732         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1733
1734         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1735                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1736         local OST_DEACTIVE_IDX=-1
1737         local OSC
1738         local OSTIDX
1739         local OST
1740
1741         for OSC in $MDS_OSCS; do
1742                 OST=$(osc_to_ost $OSC)
1743                 OSTIDX=$(index_from_ostuuid $OST)
1744                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1745                         OST_DEACTIVE_IDX=$OSTIDX
1746                 fi
1747                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1748                         echo $OSC "is Deactivated:"
1749                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1750                 fi
1751         done
1752
1753         OSTIDX=$(index_from_ostuuid $OST)
1754         mkdir -p $DIR/$tdir
1755         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1756
1757         for OSC in $MDS_OSCS; do
1758                 OST=$(osc_to_ost $OSC)
1759                 OSTIDX=$(index_from_ostuuid $OST)
1760                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1761                         echo $OST "is degraded:"
1762                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1763                                                 obdfilter.$OST.degraded=1
1764                 fi
1765         done
1766
1767         sleep_maxage
1768         createmany -o $DIR/$tdir/$tfile $fcount
1769
1770         for OSC in $MDS_OSCS; do
1771                 OST=$(osc_to_ost $OSC)
1772                 OSTIDX=$(index_from_ostuuid $OST)
1773                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1774                         echo $OST "is recovered from degraded:"
1775                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1776                                                 obdfilter.$OST.degraded=0
1777                 else
1778                         do_facet $SINGLEMDS lctl --device %$OSC activate
1779                 fi
1780         done
1781
1782         # all osp devices get activated, hence -1 stripe count restored
1783         local stripecnt=0
1784
1785         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1786         # devices get activated.
1787         sleep_maxage
1788         $SETSTRIPE -c -1 $DIR/$tfile
1789         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1790         rm -f $DIR/$tfile
1791         [ $stripecnt -ne $OSTCOUNT ] &&
1792                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1793         return 0
1794 }
1795 run_test 27y "create files while OST0 is degraded and the rest inactive"
1796
1797 check_seq_oid()
1798 {
1799         log "check file $1"
1800
1801         lmm_count=$($GETSTRIPE -c $1)
1802         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1803         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1804
1805         local old_ifs="$IFS"
1806         IFS=$'[:]'
1807         fid=($($LFS path2fid $1))
1808         IFS="$old_ifs"
1809
1810         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1811         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1812
1813         # compare lmm_seq and lu_fid->f_seq
1814         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1815         # compare lmm_object_id and lu_fid->oid
1816         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1817
1818         # check the trusted.fid attribute of the OST objects of the file
1819         local have_obdidx=false
1820         local stripe_nr=0
1821         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1822                 # skip lines up to and including "obdidx"
1823                 [ -z "$obdidx" ] && break
1824                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1825                 $have_obdidx || continue
1826
1827                 local ost=$((obdidx + 1))
1828                 local dev=$(ostdevname $ost)
1829                 local oid_hex
1830
1831                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1832
1833                 seq=$(echo $seq | sed -e "s/^0x//g")
1834                 if [ $seq == 0 ]; then
1835                         oid_hex=$(echo $oid)
1836                 else
1837                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1838                 fi
1839                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1840
1841                 local ff
1842                 #
1843                 # Don't unmount/remount the OSTs if we don't need to do that.
1844                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1845                 # update too, until that use mount/ll_decode_filter_fid/mount.
1846                 # Re-enable when debugfs will understand new filter_fid.
1847                 #
1848                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1849                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1850                                 $dev 2>/dev/null" | grep "parent=")
1851                 else
1852                         stop ost$ost
1853                         mount_fstype ost$ost
1854                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1855                                 $(facet_mntpt ost$ost)/$obj_file)
1856                         unmount_fstype ost$ost
1857                         start ost$ost $dev $OST_MOUNT_OPTS
1858                 fi
1859
1860                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1861
1862                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1863
1864                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1865                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1866                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1867                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1868                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1869                 local ff_pstripe
1870                 if echo $ff_parent | grep -q 'stripe='; then
1871                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1872                 else
1873                         #
1874                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1875                         # into f_ver in this case.  See the comment on
1876                         # ff_parent.
1877                         #
1878                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1879                                 sed -e 's/\]//')
1880                 fi
1881
1882                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1883                 [ $ff_pseq = $lmm_seq ] ||
1884                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1885                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1886                 [ $ff_poid = $lmm_oid ] ||
1887                         error "FF parent OID $ff_poid != $lmm_oid"
1888                 (($ff_pstripe == $stripe_nr)) ||
1889                         error "FF stripe $ff_pstripe != $stripe_nr"
1890
1891                 stripe_nr=$((stripe_nr + 1))
1892         done
1893 }
1894
1895 test_27z() {
1896         remote_ost_nodsh && skip "remote OST with nodsh" && return
1897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1898         test_mkdir -p $DIR/$tdir
1899
1900         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1901                 { error "setstripe -c -1 failed"; return 1; }
1902         # We need to send a write to every object to get parent FID info set.
1903         # This _should_ also work for setattr, but does not currently.
1904         # touch $DIR/$tdir/$tfile-1 ||
1905         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1906                 { error "dd $tfile-1 failed"; return 2; }
1907         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1908                 { error "setstripe -c -1 failed"; return 3; }
1909         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1910                 { error "dd $tfile-2 failed"; return 4; }
1911
1912         # make sure write RPCs have been sent to OSTs
1913         sync; sleep 5; sync
1914
1915         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1916         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1917 }
1918 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1919
1920 test_27A() { # b=19102
1921         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1922         local restore_size=$($GETSTRIPE -S $MOUNT)
1923         local restore_count=$($GETSTRIPE -c $MOUNT)
1924         local restore_offset=$($GETSTRIPE -i $MOUNT)
1925         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1926         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1927                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1928         local default_size=$($GETSTRIPE -S $MOUNT)
1929         local default_offset=$($GETSTRIPE -i $MOUNT)
1930         local dsize=$((1024 * 1024))
1931         [ $default_size -eq $dsize ] ||
1932                 error "stripe size $default_size != $dsize"
1933         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1934         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1935 }
1936 run_test 27A "check filesystem-wide default LOV EA values"
1937
1938 test_27B() { # LU-2523
1939         test_mkdir -p $DIR/$tdir
1940         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1941         touch $DIR/$tdir/f0
1942         # open f1 with O_LOV_DELAY_CREATE
1943         # rename f0 onto f1
1944         # call setstripe ioctl on open file descriptor for f1
1945         # close
1946         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1947                 $DIR/$tdir/f0
1948
1949         rm -f $DIR/$tdir/f1
1950         # open f1 with O_LOV_DELAY_CREATE
1951         # unlink f1
1952         # call setstripe ioctl on open file descriptor for f1
1953         # close
1954         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1955
1956         # Allow multiop to fail in imitation of NFS's busted semantics.
1957         true
1958 }
1959 run_test 27B "call setstripe on open unlinked file/rename victim"
1960
1961 test_27C() { #LU-2871
1962         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1963
1964         declare -a ost_idx
1965         local index
1966         local found
1967         local i
1968         local j
1969
1970         test_mkdir -p $DIR/$tdir
1971         cd $DIR/$tdir
1972         for i in $(seq 0 $((OSTCOUNT - 1))); do
1973                 # set stripe across all OSTs starting from OST$i
1974                 $SETSTRIPE -i $i -c -1 $tfile$i
1975                 # get striping information
1976                 ost_idx=($($GETSTRIPE $tfile$i |
1977                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1978                 echo ${ost_idx[@]}
1979
1980                 # check the layout
1981                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1982                         error "${#ost_idx[@]} != $OSTCOUNT"
1983
1984                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1985                         found=0
1986                         for j in $(echo ${ost_idx[@]}); do
1987                                 if [ $index -eq $j ]; then
1988                                         found=1
1989                                         break
1990                                 fi
1991                         done
1992                         [ $found = 1 ] ||
1993                                 error "Can not find $index in ${ost_idx[@]}"
1994                 done
1995         done
1996 }
1997 run_test 27C "check full striping across all OSTs"
1998
1999 test_27D() {
2000         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2001         local POOL=${POOL:-testpool}
2002         local first_ost=0
2003         local last_ost=$(($OSTCOUNT - 1))
2004         local ost_step=1
2005         local ost_list=$(seq $first_ost $ost_step $last_ost)
2006         local ost_range="$first_ost $last_ost $ost_step"
2007
2008         mkdir -p $DIR/$tdir
2009         pool_add $POOL || error "pool_add failed"
2010         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2011         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2012                 error "llapi_layout_test failed"
2013         cleanup_pools || error "cleanup_pools failed"
2014 }
2015 run_test 27D "validate llapi_layout API"
2016
2017 # createtest also checks that device nodes are created and
2018 # then visible correctly (#2091)
2019 test_28() { # bug 2091
2020         test_mkdir $DIR/d28
2021         $CREATETEST $DIR/d28/ct || error
2022 }
2023 run_test 28 "create/mknod/mkdir with bad file types ============"
2024
2025 test_29() {
2026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2027         cancel_lru_locks mdc
2028         test_mkdir $DIR/d29
2029         touch $DIR/d29/foo
2030         log 'first d29'
2031         ls -l $DIR/d29
2032
2033         declare -i LOCKCOUNTORIG=0
2034         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2035                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2036         done
2037         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2038
2039         declare -i LOCKUNUSEDCOUNTORIG=0
2040         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2041                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2042         done
2043
2044         log 'second d29'
2045         ls -l $DIR/d29
2046         log 'done'
2047
2048         declare -i LOCKCOUNTCURRENT=0
2049         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2050                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2051         done
2052
2053         declare -i LOCKUNUSEDCOUNTCURRENT=0
2054         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2055                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2056         done
2057
2058         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2059                 $LCTL set_param -n ldlm.dump_namespaces ""
2060                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2061                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2062                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2063                 return 2
2064         fi
2065         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2066                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2067                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2068                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2069                 return 3
2070         fi
2071 }
2072 run_test 29 "IT_GETATTR regression  ============================"
2073
2074 test_30a() { # was test_30
2075         cp $(which ls) $DIR || cp /bin/ls $DIR
2076         $DIR/ls / || error
2077         rm $DIR/ls
2078 }
2079 run_test 30a "execute binary from Lustre (execve) =============="
2080
2081 test_30b() {
2082         cp `which ls` $DIR || cp /bin/ls $DIR
2083         chmod go+rx $DIR/ls
2084         $RUNAS $DIR/ls / || error
2085         rm $DIR/ls
2086 }
2087 run_test 30b "execute binary from Lustre as non-root ==========="
2088
2089 test_30c() { # b=22376
2090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2091         cp `which ls` $DIR || cp /bin/ls $DIR
2092         chmod a-rw $DIR/ls
2093         cancel_lru_locks mdc
2094         cancel_lru_locks osc
2095         $RUNAS $DIR/ls / || error
2096         rm -f $DIR/ls
2097 }
2098 run_test 30c "execute binary from Lustre without read perms ===="
2099
2100 test_31a() {
2101         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2102         $CHECKSTAT -a $DIR/f31 || error
2103 }
2104 run_test 31a "open-unlink file =================================="
2105
2106 test_31b() {
2107         touch $DIR/f31 || error
2108         ln $DIR/f31 $DIR/f31b || error
2109         $MULTIOP $DIR/f31b Ouc || error
2110         $CHECKSTAT -t file $DIR/f31 || error
2111 }
2112 run_test 31b "unlink file with multiple links while open ======="
2113
2114 test_31c() {
2115         touch $DIR/f31 || error
2116         ln $DIR/f31 $DIR/f31c || error
2117         multiop_bg_pause $DIR/f31 O_uc || return 1
2118         MULTIPID=$!
2119         $MULTIOP $DIR/f31c Ouc
2120         kill -USR1 $MULTIPID
2121         wait $MULTIPID
2122 }
2123 run_test 31c "open-unlink file with multiple links ============="
2124
2125 test_31d() {
2126         opendirunlink $DIR/d31d $DIR/d31d || error
2127         $CHECKSTAT -a $DIR/d31d || error
2128 }
2129 run_test 31d "remove of open directory ========================="
2130
2131 test_31e() { # bug 2904
2132         check_kernel_version 34 || return 0
2133         openfilleddirunlink $DIR/d31e || error
2134 }
2135 run_test 31e "remove of open non-empty directory ==============="
2136
2137 test_31f() { # bug 4554
2138         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2139         set -vx
2140         test_mkdir $DIR/d31f
2141         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2142         cp /etc/hosts $DIR/d31f
2143         ls -l $DIR/d31f
2144         $GETSTRIPE $DIR/d31f/hosts
2145         multiop_bg_pause $DIR/d31f D_c || return 1
2146         MULTIPID=$!
2147
2148         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2149         test_mkdir $DIR/d31f
2150         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2151         cp /etc/hosts $DIR/d31f
2152         ls -l $DIR/d31f
2153         $GETSTRIPE $DIR/d31f/hosts
2154         multiop_bg_pause $DIR/d31f D_c || return 1
2155         MULTIPID2=$!
2156
2157         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2158         wait $MULTIPID || error "first opendir $MULTIPID failed"
2159
2160         sleep 6
2161
2162         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2163         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2164         set +vx
2165 }
2166 run_test 31f "remove of open directory with open-unlink file ==="
2167
2168 test_31g() {
2169         echo "-- cross directory link --"
2170         test_mkdir -c1 $DIR/${tdir}ga
2171         test_mkdir -c1 $DIR/${tdir}gb
2172         touch $DIR/${tdir}ga/f
2173         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2174         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2175         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2176         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2177         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2178 }
2179 run_test 31g "cross directory link==============="
2180
2181 test_31h() {
2182         echo "-- cross directory link --"
2183         test_mkdir -c1 $DIR/${tdir}
2184         test_mkdir -c1 $DIR/${tdir}/dir
2185         touch $DIR/${tdir}/f
2186         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2187         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2188         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2189         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2190         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2191 }
2192 run_test 31h "cross directory link under child==============="
2193
2194 test_31i() {
2195         echo "-- cross directory link --"
2196         test_mkdir -c1 $DIR/$tdir
2197         test_mkdir -c1 $DIR/$tdir/dir
2198         touch $DIR/$tdir/dir/f
2199         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2200         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2201         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2202         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2203         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2204 }
2205 run_test 31i "cross directory link under parent==============="
2206
2207 test_31j() {
2208         test_mkdir -c1 -p $DIR/$tdir
2209         test_mkdir -c1 -p $DIR/$tdir/dir1
2210         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2211         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2212         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2213         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2214         return 0
2215 }
2216 run_test 31j "link for directory==============="
2217
2218 test_31k() {
2219         test_mkdir -c1 -p $DIR/$tdir
2220         touch $DIR/$tdir/s
2221         touch $DIR/$tdir/exist
2222         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2223         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2224         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2225         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2226         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2227         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2228         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2229         return 0
2230 }
2231 run_test 31k "link to file: the same, non-existing, dir==============="
2232
2233 test_31m() {
2234         mkdir $DIR/d31m
2235         touch $DIR/d31m/s
2236         mkdir $DIR/d31m2
2237         touch $DIR/d31m2/exist
2238         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2239         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2240         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2241         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2242         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2243         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2244         return 0
2245 }
2246 run_test 31m "link to file: the same, non-existing, dir==============="
2247
2248 test_31n() {
2249         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2250         nlink=$(stat --format=%h $DIR/$tfile)
2251         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2252         local fd=$(free_fd)
2253         local cmd="exec $fd<$DIR/$tfile"
2254         eval $cmd
2255         cmd="exec $fd<&-"
2256         trap "eval $cmd" EXIT
2257         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2258         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2259         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2260         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2261         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2262         eval $cmd
2263 }
2264 run_test 31n "check link count of unlinked file"
2265
2266 link_one() {
2267         local TEMPNAME=$(mktemp $1_XXXXXX)
2268         mlink $TEMPNAME $1 2> /dev/null &&
2269                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2270         munlink $TEMPNAME
2271 }
2272
2273 test_31o() { # LU-2901
2274         mkdir -p $DIR/$tdir
2275         for LOOP in $(seq 100); do
2276                 rm -f $DIR/$tdir/$tfile*
2277                 for THREAD in $(seq 8); do
2278                         link_one $DIR/$tdir/$tfile.$LOOP &
2279                 done
2280                 wait
2281                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2282                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2283                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2284                         break || true
2285         done
2286 }
2287 run_test 31o "duplicate hard links with same filename"
2288
2289 test_31p() {
2290         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2291
2292         mkdir $DIR/$tdir
2293         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2294         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2295
2296         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2297                 error "open unlink test1 failed"
2298         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2299                 error "open unlink test2 failed"
2300
2301         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2302                 error "test1 still exists"
2303         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2304                 error "test2 still exists"
2305 }
2306 run_test 31p "remove of open striped directory"
2307
2308 cleanup_test32_mount() {
2309         trap 0
2310         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2311 }
2312
2313 test_32a() {
2314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2315         echo "== more mountpoints and symlinks ================="
2316         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2317         trap cleanup_test32_mount EXIT
2318         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2319         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2320         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2321         cleanup_test32_mount
2322 }
2323 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2324
2325 test_32b() {
2326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2327         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2328         trap cleanup_test32_mount EXIT
2329         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2330         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2331         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2332         cleanup_test32_mount
2333 }
2334 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2335
2336 test_32c() {
2337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2338         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2339         trap cleanup_test32_mount EXIT
2340         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2341         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2342         test_mkdir -p $DIR/$tdir/d2/test_dir
2343         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2344         cleanup_test32_mount
2345 }
2346 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2347
2348 test_32d() {
2349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
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         test_mkdir -p $DIR/$tdir/d2/test_dir
2355         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2356         cleanup_test32_mount
2357 }
2358 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2359
2360 test_32e() {
2361         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2362         test_mkdir -p $DIR/d32e/tmp
2363         TMP_DIR=$DIR/d32e/tmp
2364         ln -s $DIR/d32e $TMP_DIR/symlink11
2365         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2366         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2367         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2368 }
2369 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2370
2371 test_32f() {
2372         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2373         test_mkdir -p $DIR/d32f/tmp
2374         TMP_DIR=$DIR/d32f/tmp
2375         ln -s $DIR/d32f $TMP_DIR/symlink11
2376         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2377         ls $DIR/d32f/tmp/symlink11  || error
2378         ls $DIR/d32f/symlink01 || error
2379 }
2380 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2381
2382 test_32g() {
2383         TMP_DIR=$DIR/$tdir/tmp
2384         test_mkdir -p $DIR/$tdir/tmp
2385         test_mkdir $DIR/${tdir}2
2386         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2387         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2388         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2389         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2390         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2391         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2392 }
2393 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2394
2395 test_32h() {
2396         rm -fr $DIR/$tdir $DIR/${tdir}2
2397         TMP_DIR=$DIR/$tdir/tmp
2398         test_mkdir -p $DIR/$tdir/tmp
2399         test_mkdir $DIR/${tdir}2
2400         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2401         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2402         ls $TMP_DIR/symlink12 || error
2403         ls $DIR/$tdir/symlink02  || error
2404 }
2405 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2406
2407 test_32i() {
2408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2409         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2410         trap cleanup_test32_mount EXIT
2411         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2412         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2413         touch $DIR/$tdir/test_file
2414         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2415         cleanup_test32_mount
2416 }
2417 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2418
2419 test_32j() {
2420         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2421         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2422         trap cleanup_test32_mount EXIT
2423         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2424         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2425         touch $DIR/$tdir/test_file
2426         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2427         cleanup_test32_mount
2428 }
2429 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2430
2431 test_32k() {
2432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2433         rm -fr $DIR/$tdir
2434         trap cleanup_test32_mount EXIT
2435         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2436         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2437         test_mkdir -p $DIR/$tdir/d2
2438         touch $DIR/$tdir/d2/test_file || error
2439         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2440         cleanup_test32_mount
2441 }
2442 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2443
2444 test_32l() {
2445         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2446         rm -fr $DIR/$tdir
2447         trap cleanup_test32_mount EXIT
2448         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2449         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2450         test_mkdir -p $DIR/$tdir/d2
2451         touch $DIR/$tdir/d2/test_file
2452         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2453         cleanup_test32_mount
2454 }
2455 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2456
2457 test_32m() {
2458         rm -fr $DIR/d32m
2459         test_mkdir -p $DIR/d32m/tmp
2460         TMP_DIR=$DIR/d32m/tmp
2461         ln -s $DIR $TMP_DIR/symlink11
2462         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2463         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2464         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2465 }
2466 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2467
2468 test_32n() {
2469         rm -fr $DIR/d32n
2470         test_mkdir -p $DIR/d32n/tmp
2471         TMP_DIR=$DIR/d32n/tmp
2472         ln -s $DIR $TMP_DIR/symlink11
2473         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2474         ls -l $DIR/d32n/tmp/symlink11  || error
2475         ls -l $DIR/d32n/symlink01 || error
2476 }
2477 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2478
2479 test_32o() {
2480         touch $DIR/$tfile
2481         test_mkdir -p $DIR/d32o/tmp
2482         TMP_DIR=$DIR/d32o/tmp
2483         ln -s $DIR/$tfile $TMP_DIR/symlink12
2484         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2485         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2486         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2487         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2488         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2489 }
2490 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2491
2492 test_32p() {
2493     log 32p_1
2494         rm -fr $DIR/d32p
2495     log 32p_2
2496         rm -f $DIR/$tfile
2497     log 32p_3
2498         touch $DIR/$tfile
2499     log 32p_4
2500         test_mkdir -p $DIR/d32p/tmp
2501     log 32p_5
2502         TMP_DIR=$DIR/d32p/tmp
2503     log 32p_6
2504         ln -s $DIR/$tfile $TMP_DIR/symlink12
2505     log 32p_7
2506         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2507     log 32p_8
2508         cat $DIR/d32p/tmp/symlink12 || error
2509     log 32p_9
2510         cat $DIR/d32p/symlink02 || error
2511     log 32p_10
2512 }
2513 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2514
2515 cleanup_testdir_mount() {
2516         trap 0
2517         $UMOUNT -d $DIR/$tdir
2518 }
2519
2520 test_32q() {
2521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2522         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2523         trap cleanup_testdir_mount EXIT
2524         test_mkdir -p $DIR/$tdir
2525         touch $DIR/$tdir/under_the_mount
2526         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2527         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2528         cleanup_testdir_mount
2529 }
2530 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2531
2532 test_32r() {
2533         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2534         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2535         trap cleanup_testdir_mount EXIT
2536         test_mkdir -p $DIR/$tdir
2537         touch $DIR/$tdir/under_the_mount
2538         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2539         ls $DIR/$tdir | grep -q under_the_mount && error || true
2540         cleanup_testdir_mount
2541 }
2542 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2543
2544 test_33aa() {
2545         rm -f $DIR/$tfile
2546         touch $DIR/$tfile
2547         chmod 444 $DIR/$tfile
2548         chown $RUNAS_ID $DIR/$tfile
2549         log 33_1
2550         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2551         log 33_2
2552 }
2553 run_test 33aa "write file with mode 444 (should return error) ===="
2554
2555 test_33a() {
2556         rm -fr $DIR/d33
2557         test_mkdir -p $DIR/d33
2558         chown $RUNAS_ID $DIR/d33
2559         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2560         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2561                 error "open RDWR" || true
2562 }
2563 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2564
2565 test_33b() {
2566         rm -fr $DIR/d33
2567         test_mkdir -p $DIR/d33
2568         chown $RUNAS_ID $DIR/d33
2569         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33
2570 }
2571 run_test 33b "test open file with malformed flags (No panic)"
2572
2573 test_33c() {
2574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2575         local ostnum
2576         local ostname
2577         local write_bytes
2578         local all_zeros
2579
2580         remote_ost_nodsh && skip "remote OST with nodsh" && return
2581         all_zeros=:
2582         rm -fr $DIR/d33
2583         test_mkdir -p $DIR/d33
2584         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2585
2586         sync
2587         for ostnum in $(seq $OSTCOUNT); do
2588                 # test-framework's OST numbering is one-based, while Lustre's
2589                 # is zero-based
2590                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2591                 # Parsing llobdstat's output sucks; we could grep the /proc
2592                 # path, but that's likely to not be as portable as using the
2593                 # llobdstat utility.  So we parse lctl output instead.
2594                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2595                         obdfilter/$ostname/stats |
2596                         awk '/^write_bytes/ {print $7}' )
2597                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2598                 if (( ${write_bytes:-0} > 0 ))
2599                 then
2600                         all_zeros=false
2601                         break;
2602                 fi
2603         done
2604
2605         $all_zeros || return 0
2606
2607         # Write four bytes
2608         echo foo > $DIR/d33/bar
2609         # Really write them
2610         sync
2611
2612         # Total up write_bytes after writing.  We'd better find non-zeros.
2613         for ostnum in $(seq $OSTCOUNT); do
2614                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2615                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2616                         obdfilter/$ostname/stats |
2617                         awk '/^write_bytes/ {print $7}' )
2618                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2619                 if (( ${write_bytes:-0} > 0 ))
2620                 then
2621                         all_zeros=false
2622                         break;
2623                 fi
2624         done
2625
2626         if $all_zeros
2627         then
2628                 for ostnum in $(seq $OSTCOUNT); do
2629                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2630                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2631                         do_facet ost$ostnum lctl get_param -n \
2632                                 obdfilter/$ostname/stats
2633                 done
2634                 error "OST not keeping write_bytes stats (b22312)"
2635         fi
2636 }
2637 run_test 33c "test llobdstat and write_bytes"
2638
2639 test_33d() {
2640         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2641         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2642         local MDTIDX=1
2643         local remote_dir=$DIR/$tdir/remote_dir
2644
2645         mkdir -p $DIR/$tdir
2646         $LFS mkdir -i $MDTIDX $remote_dir ||
2647                 error "create remote directory failed"
2648
2649         touch $remote_dir/$tfile
2650         chmod 444 $remote_dir/$tfile
2651         chown $RUNAS_ID $remote_dir/$tfile
2652
2653         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2654
2655         chown $RUNAS_ID $remote_dir
2656         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2657                                         error "create" || true
2658         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2659                                     error "open RDWR" || true
2660         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2661                                     error "create" || true
2662 }
2663 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2664
2665 test_33e() {
2666         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2667
2668         mkdir $DIR/$tdir
2669
2670         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2671         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2672         mkdir $DIR/$tdir/local_dir
2673
2674         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2675         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2676         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2677
2678         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2679                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2680
2681         rmdir $DIR/$tdir/* || error "rmdir failed"
2682
2683         umask 777
2684         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2685         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2686         mkdir $DIR/$tdir/local_dir
2687
2688         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2689         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2690         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2691
2692         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2693                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2694
2695         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2696
2697         umask 000
2698         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2699         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2700         mkdir $DIR/$tdir/local_dir
2701
2702         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2703         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2704         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2705
2706         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2707                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2708 }
2709 run_test 33e "mkdir and striped directory should have same mode"
2710
2711 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2712 test_34a() {
2713         rm -f $DIR/f34
2714         $MCREATE $DIR/f34 || error
2715         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2716         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2717         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2718         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2719 }
2720 run_test 34a "truncate file that has not been opened ==========="
2721
2722 test_34b() {
2723         [ ! -f $DIR/f34 ] && test_34a
2724         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2725         $OPENFILE -f O_RDONLY $DIR/f34
2726         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2727         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2728 }
2729 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2730
2731 test_34c() {
2732         [ ! -f $DIR/f34 ] && test_34a
2733         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2734         $OPENFILE -f O_RDWR $DIR/f34
2735         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2736         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2737 }
2738 run_test 34c "O_RDWR opening file-with-size works =============="
2739
2740 test_34d() {
2741         [ ! -f $DIR/f34 ] && test_34a
2742         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2743         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2744         rm $DIR/f34
2745 }
2746 run_test 34d "write to sparse file ============================="
2747
2748 test_34e() {
2749         rm -f $DIR/f34e
2750         $MCREATE $DIR/f34e || error
2751         $TRUNCATE $DIR/f34e 1000 || error
2752         $CHECKSTAT -s 1000 $DIR/f34e || error
2753         $OPENFILE -f O_RDWR $DIR/f34e
2754         $CHECKSTAT -s 1000 $DIR/f34e || error
2755 }
2756 run_test 34e "create objects, some with size and some without =="
2757
2758 test_34f() { # bug 6242, 6243
2759         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2760         SIZE34F=48000
2761         rm -f $DIR/f34f
2762         $MCREATE $DIR/f34f || error
2763         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2764         dd if=$DIR/f34f of=$TMP/f34f
2765         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2766         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2767         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2768         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2769         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2770 }
2771 run_test 34f "read from a file with no objects until EOF ======="
2772
2773 test_34g() {
2774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2775         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2776         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2777         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2778         cancel_lru_locks osc
2779         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2780                 error "wrong size after lock cancel"
2781
2782         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2783         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2784                 error "expanding truncate failed"
2785         cancel_lru_locks osc
2786         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2787                 error "wrong expanded size after lock cancel"
2788 }
2789 run_test 34g "truncate long file ==============================="
2790
2791 test_34h() {
2792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2793         local gid=10
2794         local sz=1000
2795
2796         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2797         sync # Flush the cache so that multiop below does not block on cache
2798              # flush when getting the group lock
2799         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2800         MULTIPID=$!
2801
2802         # Since just timed wait is not good enough, let's do a sync write
2803         # that way we are sure enough time for a roundtrip + processing
2804         # passed + 2 seconds of extra margin.
2805         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2806         rm $DIR/${tfile}-1
2807         sleep 2
2808
2809         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2810                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2811                 kill -9 $MULTIPID
2812         fi
2813         wait $MULTIPID
2814         local nsz=`stat -c %s $DIR/$tfile`
2815         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2816 }
2817 run_test 34h "ftruncate file under grouplock should not block"
2818
2819 test_35a() {
2820         cp /bin/sh $DIR/f35a
2821         chmod 444 $DIR/f35a
2822         chown $RUNAS_ID $DIR/f35a
2823         $RUNAS $DIR/f35a && error || true
2824         rm $DIR/f35a
2825 }
2826 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2827
2828 test_36a() {
2829         rm -f $DIR/f36
2830         utime $DIR/f36 || error
2831 }
2832 run_test 36a "MDS utime check (mknod, utime) ==================="
2833
2834 test_36b() {
2835         echo "" > $DIR/f36
2836         utime $DIR/f36 || error
2837 }
2838 run_test 36b "OST utime check (open, utime) ===================="
2839
2840 test_36c() {
2841         rm -f $DIR/d36/f36
2842         test_mkdir $DIR/d36
2843         chown $RUNAS_ID $DIR/d36
2844         $RUNAS utime $DIR/d36/f36 || error
2845 }
2846 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2847
2848 test_36d() {
2849         [ ! -d $DIR/d36 ] && test_36c
2850         echo "" > $DIR/d36/f36
2851         $RUNAS utime $DIR/d36/f36 || error
2852 }
2853 run_test 36d "non-root OST utime check (open, utime) ==========="
2854
2855 test_36e() {
2856         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2857         test_mkdir -p $DIR/$tdir
2858         touch $DIR/$tdir/$tfile
2859         $RUNAS utime $DIR/$tdir/$tfile && \
2860                 error "utime worked, expected failure" || true
2861 }
2862 run_test 36e "utime on non-owned file (should return error) ===="
2863
2864 subr_36fh() {
2865         local fl="$1"
2866         local LANG_SAVE=$LANG
2867         local LC_LANG_SAVE=$LC_LANG
2868         export LANG=C LC_LANG=C # for date language
2869
2870         DATESTR="Dec 20  2000"
2871         test_mkdir -p $DIR/$tdir
2872         lctl set_param fail_loc=$fl
2873         date; date +%s
2874         cp /etc/hosts $DIR/$tdir/$tfile
2875         sync & # write RPC generated with "current" inode timestamp, but delayed
2876         sleep 1
2877         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2878         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2879         cancel_lru_locks osc
2880         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2881         date; date +%s
2882         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2883                 echo "BEFORE: $LS_BEFORE" && \
2884                 echo "AFTER : $LS_AFTER" && \
2885                 echo "WANT  : $DATESTR" && \
2886                 error "$DIR/$tdir/$tfile timestamps changed" || true
2887
2888         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2889 }
2890
2891 test_36f() {
2892         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2893         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2894         subr_36fh "0x80000214"
2895 }
2896 run_test 36f "utime on file racing with OST BRW write =========="
2897
2898 test_36g() {
2899         remote_ost_nodsh && skip "remote OST with nodsh" && return
2900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2901         local fmd_max_age
2902         local fmd_before
2903         local fmd_after
2904
2905         test_mkdir -p $DIR/$tdir
2906         fmd_max_age=$(do_facet ost1 \
2907                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2908                 head -n 1")
2909
2910         fmd_before=$(do_facet ost1 \
2911                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2912         touch $DIR/$tdir/$tfile
2913         sleep $((fmd_max_age + 12))
2914         fmd_after=$(do_facet ost1 \
2915                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2916
2917         echo "fmd_before: $fmd_before"
2918         echo "fmd_after: $fmd_after"
2919         [[ $fmd_after -gt $fmd_before ]] &&
2920                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2921                 error "fmd didn't expire after ping" || true
2922 }
2923 run_test 36g "filter mod data cache expiry ====================="
2924
2925 test_36h() {
2926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2927         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2928         subr_36fh "0x80000227"
2929 }
2930 run_test 36h "utime on file racing with OST BRW write =========="
2931
2932 test_36i() {
2933         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2934
2935         mkdir $DIR/$tdir
2936         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2937
2938         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
2939         local new_mtime=$((mtime + 200))
2940
2941         #change Modify time of striped dir
2942         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
2943                         error "change mtime failed"
2944
2945         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
2946
2947         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
2948 }
2949 run_test 36i "change mtime on striped directory"
2950
2951 # test_37 - duplicate with tests 32q 32r
2952
2953 test_38() {
2954         local file=$DIR/$tfile
2955         touch $file
2956         openfile -f O_DIRECTORY $file
2957         local RC=$?
2958         local ENOTDIR=20
2959         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2960         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2961 }
2962 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2963
2964 test_39() {
2965         touch $DIR/$tfile
2966         touch $DIR/${tfile}2
2967 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2968 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2969 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2970         sleep 2
2971         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2972         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2973                 echo "mtime"
2974                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2975                 echo "atime"
2976                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2977                 echo "ctime"
2978                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2979                 error "O_TRUNC didn't change timestamps"
2980         fi
2981 }
2982 run_test 39 "mtime changed on create ==========================="
2983
2984 test_39b() {
2985         test_mkdir -p -c1 $DIR/$tdir
2986         cp -p /etc/passwd $DIR/$tdir/fopen
2987         cp -p /etc/passwd $DIR/$tdir/flink
2988         cp -p /etc/passwd $DIR/$tdir/funlink
2989         cp -p /etc/passwd $DIR/$tdir/frename
2990         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2991
2992         sleep 1
2993         echo "aaaaaa" >> $DIR/$tdir/fopen
2994         echo "aaaaaa" >> $DIR/$tdir/flink
2995         echo "aaaaaa" >> $DIR/$tdir/funlink
2996         echo "aaaaaa" >> $DIR/$tdir/frename
2997
2998         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2999         local link_new=`stat -c %Y $DIR/$tdir/flink`
3000         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3001         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3002
3003         cat $DIR/$tdir/fopen > /dev/null
3004         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3005         rm -f $DIR/$tdir/funlink2
3006         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3007
3008         for (( i=0; i < 2; i++ )) ; do
3009                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3010                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3011                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3012                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3013
3014                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3015                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3016                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3017                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3018
3019                 cancel_lru_locks osc
3020                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3021         done
3022 }
3023 run_test 39b "mtime change on open, link, unlink, rename  ======"
3024
3025 # this should be set to past
3026 TEST_39_MTIME=`date -d "1 year ago" +%s`
3027
3028 # bug 11063
3029 test_39c() {
3030         touch $DIR1/$tfile
3031         sleep 2
3032         local mtime0=`stat -c %Y $DIR1/$tfile`
3033
3034         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3035         local mtime1=`stat -c %Y $DIR1/$tfile`
3036         [ "$mtime1" = $TEST_39_MTIME ] || \
3037                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3038
3039         local d1=`date +%s`
3040         echo hello >> $DIR1/$tfile
3041         local d2=`date +%s`
3042         local mtime2=`stat -c %Y $DIR1/$tfile`
3043         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3044                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3045
3046         mv $DIR1/$tfile $DIR1/$tfile-1
3047
3048         for (( i=0; i < 2; i++ )) ; do
3049                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3050                 [ "$mtime2" = "$mtime3" ] || \
3051                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3052
3053                 cancel_lru_locks osc
3054                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3055         done
3056 }
3057 run_test 39c "mtime change on rename ==========================="
3058
3059 # bug 21114
3060 test_39d() {
3061         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3062         touch $DIR1/$tfile
3063
3064         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3065
3066         for (( i=0; i < 2; i++ )) ; do
3067                 local mtime=`stat -c %Y $DIR1/$tfile`
3068                 [ $mtime = $TEST_39_MTIME ] || \
3069                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3070
3071                 cancel_lru_locks osc
3072                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3073         done
3074 }
3075 run_test 39d "create, utime, stat =============================="
3076
3077 # bug 21114
3078 test_39e() {
3079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3080         touch $DIR1/$tfile
3081         local mtime1=`stat -c %Y $DIR1/$tfile`
3082
3083         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3084
3085         for (( i=0; i < 2; i++ )) ; do
3086                 local mtime2=`stat -c %Y $DIR1/$tfile`
3087                 [ $mtime2 = $TEST_39_MTIME ] || \
3088                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3089
3090                 cancel_lru_locks osc
3091                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3092         done
3093 }
3094 run_test 39e "create, stat, utime, stat ========================"
3095
3096 # bug 21114
3097 test_39f() {
3098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3099         touch $DIR1/$tfile
3100         mtime1=`stat -c %Y $DIR1/$tfile`
3101
3102         sleep 2
3103         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3104
3105         for (( i=0; i < 2; i++ )) ; do
3106                 local mtime2=`stat -c %Y $DIR1/$tfile`
3107                 [ $mtime2 = $TEST_39_MTIME ] || \
3108                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3109
3110                 cancel_lru_locks osc
3111                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3112         done
3113 }
3114 run_test 39f "create, stat, sleep, utime, stat ================="
3115
3116 # bug 11063
3117 test_39g() {
3118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3119         echo hello >> $DIR1/$tfile
3120         local mtime1=`stat -c %Y $DIR1/$tfile`
3121
3122         sleep 2
3123         chmod o+r $DIR1/$tfile
3124
3125         for (( i=0; i < 2; i++ )) ; do
3126                 local mtime2=`stat -c %Y $DIR1/$tfile`
3127                 [ "$mtime1" = "$mtime2" ] || \
3128                         error "lost mtime: $mtime2, should be $mtime1"
3129
3130                 cancel_lru_locks osc
3131                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3132         done
3133 }
3134 run_test 39g "write, chmod, stat ==============================="
3135
3136 # bug 11063
3137 test_39h() {
3138         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3139         touch $DIR1/$tfile
3140         sleep 1
3141
3142         local d1=`date`
3143         echo hello >> $DIR1/$tfile
3144         local mtime1=`stat -c %Y $DIR1/$tfile`
3145
3146         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3147         local d2=`date`
3148         if [ "$d1" != "$d2" ]; then
3149                 echo "write and touch not within one second"
3150         else
3151                 for (( i=0; i < 2; i++ )) ; do
3152                         local mtime2=`stat -c %Y $DIR1/$tfile`
3153                         [ "$mtime2" = $TEST_39_MTIME ] || \
3154                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3155
3156                         cancel_lru_locks osc
3157                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3158                 done
3159         fi
3160 }
3161 run_test 39h "write, utime within one second, stat ============="
3162
3163 test_39i() {
3164         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3165         touch $DIR1/$tfile
3166         sleep 1
3167
3168         echo hello >> $DIR1/$tfile
3169         local mtime1=`stat -c %Y $DIR1/$tfile`
3170
3171         mv $DIR1/$tfile $DIR1/$tfile-1
3172
3173         for (( i=0; i < 2; i++ )) ; do
3174                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3175
3176                 [ "$mtime1" = "$mtime2" ] || \
3177                         error "lost mtime: $mtime2, should be $mtime1"
3178
3179                 cancel_lru_locks osc
3180                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3181         done
3182 }
3183 run_test 39i "write, rename, stat =============================="
3184
3185 test_39j() {
3186         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3187         start_full_debug_logging
3188         touch $DIR1/$tfile
3189         sleep 1
3190
3191         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3192         lctl set_param fail_loc=0x80000412
3193         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3194                 error "multiop failed"
3195         local multipid=$!
3196         local mtime1=`stat -c %Y $DIR1/$tfile`
3197
3198         mv $DIR1/$tfile $DIR1/$tfile-1
3199
3200         kill -USR1 $multipid
3201         wait $multipid || error "multiop close failed"
3202
3203         for (( i=0; i < 2; i++ )) ; do
3204                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3205                 [ "$mtime1" = "$mtime2" ] ||
3206                         error "mtime is lost on close: $mtime2, " \
3207                               "should be $mtime1"
3208
3209                 cancel_lru_locks osc
3210                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3211         done
3212         lctl set_param fail_loc=0
3213         stop_full_debug_logging
3214 }
3215 run_test 39j "write, rename, close, stat ======================="
3216
3217 test_39k() {
3218         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3219         touch $DIR1/$tfile
3220         sleep 1
3221
3222         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3223         local multipid=$!
3224         local mtime1=`stat -c %Y $DIR1/$tfile`
3225
3226         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3227
3228         kill -USR1 $multipid
3229         wait $multipid || error "multiop close failed"
3230
3231         for (( i=0; i < 2; i++ )) ; do
3232                 local mtime2=`stat -c %Y $DIR1/$tfile`
3233
3234                 [ "$mtime2" = $TEST_39_MTIME ] || \
3235                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3236
3237                 cancel_lru_locks osc
3238                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3239         done
3240 }
3241 run_test 39k "write, utime, close, stat ========================"
3242
3243 # this should be set to future
3244 TEST_39_ATIME=`date -d "1 year" +%s`
3245
3246 test_39l() {
3247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3248         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3249         local atime_diff=$(do_facet $SINGLEMDS \
3250                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3251         rm -rf $DIR/$tdir
3252         mkdir -p $DIR/$tdir
3253
3254         # test setting directory atime to future
3255         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3256         local atime=$(stat -c %X $DIR/$tdir)
3257         [ "$atime" = $TEST_39_ATIME ] || \
3258                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3259
3260         # test setting directory atime from future to now
3261         local d1=$(date +%s)
3262         ls $DIR/$tdir
3263         local d2=$(date +%s)
3264
3265         cancel_lru_locks mdc
3266         atime=$(stat -c %X $DIR/$tdir)
3267         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3268                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3269
3270         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3271         sleep 3
3272
3273         # test setting directory atime when now > dir atime + atime_diff
3274         d1=$(date +%s)
3275         ls $DIR/$tdir
3276         d2=$(date +%s)
3277         cancel_lru_locks mdc
3278         atime=$(stat -c %X $DIR/$tdir)
3279         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3280                 error "atime is not updated  : $atime, should be $d2"
3281
3282         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3283         sleep 3
3284
3285         # test not setting directory atime when now < dir atime + atime_diff
3286         ls $DIR/$tdir
3287         cancel_lru_locks mdc
3288         atime=$(stat -c %X $DIR/$tdir)
3289         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3290                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3291
3292         do_facet $SINGLEMDS \
3293                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3294 }
3295 run_test 39l "directory atime update ==========================="
3296
3297 test_39m() {
3298         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3299         touch $DIR1/$tfile
3300         sleep 2
3301         local far_past_mtime=$(date -d "May 29 1953" +%s)
3302         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3303
3304         touch -m -d @$far_past_mtime $DIR1/$tfile
3305         touch -a -d @$far_past_atime $DIR1/$tfile
3306
3307         for (( i=0; i < 2; i++ )) ; do
3308                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3309                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3310                         error "atime or mtime set incorrectly"
3311
3312                 cancel_lru_locks osc
3313                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3314         done
3315 }
3316 run_test 39m "test atime and mtime before 1970"
3317
3318 test_39n() { # LU-3832
3319         local atime_diff=$(do_facet $SINGLEMDS \
3320                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3321         local atime0
3322         local atime1
3323         local atime2
3324
3325         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3326
3327         rm -rf $DIR/$tfile
3328         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3329         atime0=$(stat -c %X $DIR/$tfile)
3330
3331         sleep 5
3332         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3333         atime1=$(stat -c %X $DIR/$tfile)
3334
3335         sleep 5
3336         cancel_lru_locks mdc
3337         cancel_lru_locks osc
3338         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3339         atime2=$(stat -c %X $DIR/$tfile)
3340
3341         do_facet $SINGLEMDS \
3342                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3343
3344         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3345         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3346 }
3347 run_test 39n "check that O_NOATIME is honored"
3348
3349 test_39o() {
3350         TESTDIR=$DIR/$tdir/$tfile
3351         [ -e $TESTDIR ] && rm -rf $TESTDIR
3352         test_mkdir -p $TESTDIR
3353         cd $TESTDIR
3354         links1=2
3355         ls
3356         mkdir a b
3357         ls
3358         links2=$(stat -c %h .)
3359         [ $(($links1 + 2)) != $links2 ] &&
3360                 error "wrong links count $(($links1 + 2)) != $links2"
3361         rmdir b
3362         links3=$(stat -c %h .)
3363         [ $(($links1 + 1)) != $links3 ] &&
3364                 error "wrong links count $links1 != $links3"
3365         return 0
3366 }
3367 run_test 39o "directory cached attributes updated after create ========"
3368
3369 test_39p() {
3370         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3371         local MDTIDX=1
3372         TESTDIR=$DIR/$tdir/$tfile
3373         [ -e $TESTDIR ] && rm -rf $TESTDIR
3374         mkdir -p $TESTDIR
3375         cd $TESTDIR
3376         links1=2
3377         ls
3378         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3379         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3380         ls
3381         links2=$(stat -c %h .)
3382         [ $(($links1 + 2)) != $links2 ] &&
3383                 error "wrong links count $(($links1 + 2)) != $links2"
3384         rmdir remote_dir2
3385         links3=$(stat -c %h .)
3386         [ $(($links1 + 1)) != $links3 ] &&
3387                 error "wrong links count $links1 != $links3"
3388         return 0
3389 }
3390 run_test 39p "remote directory cached attributes updated after create ========"
3391
3392
3393 test_40() {
3394         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3395         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3396                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3397         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3398                 error "$tfile is not 4096 bytes in size"
3399 }
3400 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3401
3402 test_41() {
3403         # bug 1553
3404         small_write $DIR/f41 18
3405 }
3406 run_test 41 "test small file write + fstat ====================="
3407
3408 count_ost_writes() {
3409         lctl get_param -n osc.*.stats |
3410                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3411                         END { printf("%0.0f", writes) }'
3412 }
3413
3414 # decent default
3415 WRITEBACK_SAVE=500
3416 DIRTY_RATIO_SAVE=40
3417 MAX_DIRTY_RATIO=50
3418 BG_DIRTY_RATIO_SAVE=10
3419 MAX_BG_DIRTY_RATIO=25
3420
3421 start_writeback() {
3422         trap 0
3423         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3424         # dirty_ratio, dirty_background_ratio
3425         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3426                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3427                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3428                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3429         else
3430                 # if file not here, we are a 2.4 kernel
3431                 kill -CONT `pidof kupdated`
3432         fi
3433 }
3434
3435 stop_writeback() {
3436         # setup the trap first, so someone cannot exit the test at the
3437         # exact wrong time and mess up a machine
3438         trap start_writeback EXIT
3439         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3440         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3441                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3442                 sysctl -w vm.dirty_writeback_centisecs=0
3443                 sysctl -w vm.dirty_writeback_centisecs=0
3444                 # save and increase /proc/sys/vm/dirty_ratio
3445                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3446                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3447                 # save and increase /proc/sys/vm/dirty_background_ratio
3448                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3449                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3450         else
3451                 # if file not here, we are a 2.4 kernel
3452                 kill -STOP `pidof kupdated`
3453         fi
3454 }
3455
3456 # ensure that all stripes have some grant before we test client-side cache
3457 setup_test42() {
3458         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3459                 dd if=/dev/zero of=$i bs=4k count=1
3460                 rm $i
3461         done
3462 }
3463
3464 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3465 # file truncation, and file removal.
3466 test_42a() {
3467         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3468         setup_test42
3469         cancel_lru_locks osc
3470         stop_writeback
3471         sync; sleep 1; sync # just to be safe
3472         BEFOREWRITES=`count_ost_writes`
3473         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3474         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3475         AFTERWRITES=`count_ost_writes`
3476         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3477                 error "$BEFOREWRITES < $AFTERWRITES"
3478         start_writeback
3479 }
3480 run_test 42a "ensure that we don't flush on close =============="
3481
3482 test_42b() {
3483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3484         setup_test42
3485         cancel_lru_locks osc
3486         stop_writeback
3487         sync
3488         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3489         BEFOREWRITES=$(count_ost_writes)
3490         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3491         AFTERWRITES=$(count_ost_writes)
3492         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3493                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3494         fi
3495         BEFOREWRITES=$(count_ost_writes)
3496         sync || error "sync: $?"
3497         AFTERWRITES=$(count_ost_writes)
3498         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3499                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3500         fi
3501         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3502         start_writeback
3503         return 0
3504 }
3505 run_test 42b "test destroy of file with cached dirty data ======"
3506
3507 # if these tests just want to test the effect of truncation,
3508 # they have to be very careful.  consider:
3509 # - the first open gets a {0,EOF}PR lock
3510 # - the first write conflicts and gets a {0, count-1}PW
3511 # - the rest of the writes are under {count,EOF}PW
3512 # - the open for truncate tries to match a {0,EOF}PR
3513 #   for the filesize and cancels the PWs.
3514 # any number of fixes (don't get {0,EOF} on open, match
3515 # composite locks, do smarter file size management) fix
3516 # this, but for now we want these tests to verify that
3517 # the cancellation with truncate intent works, so we
3518 # start the file with a full-file pw lock to match against
3519 # until the truncate.
3520 trunc_test() {
3521         test=$1
3522         file=$DIR/$test
3523         offset=$2
3524         cancel_lru_locks osc
3525         stop_writeback
3526         # prime the file with 0,EOF PW to match
3527         touch $file
3528         $TRUNCATE $file 0
3529         sync; sync
3530         # now the real test..
3531         dd if=/dev/zero of=$file bs=1024 count=100
3532         BEFOREWRITES=`count_ost_writes`
3533         $TRUNCATE $file $offset
3534         cancel_lru_locks osc
3535         AFTERWRITES=`count_ost_writes`
3536         start_writeback
3537 }
3538
3539 test_42c() {
3540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3541         trunc_test 42c 1024
3542         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3543             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3544         rm $file
3545 }
3546 run_test 42c "test partial truncate of file with cached dirty data"
3547
3548 test_42d() {
3549         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3550         trunc_test 42d 0
3551         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3552             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3553         rm $file
3554 }
3555 run_test 42d "test complete truncate of file with cached dirty data"
3556
3557 test_42e() { # bug22074
3558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3559         local TDIR=$DIR/${tdir}e
3560         local pagesz=$(page_size)
3561         local pages=16 # hardcoded 16 pages, don't change it.
3562         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3563         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3564         local max_dirty_mb
3565         local warmup_files
3566
3567         test_mkdir -p $DIR/${tdir}e
3568         $SETSTRIPE -c 1 $TDIR
3569         createmany -o $TDIR/f $files
3570
3571         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3572
3573         # we assume that with $OSTCOUNT files, at least one of them will
3574         # be allocated on OST0.
3575         warmup_files=$((OSTCOUNT * max_dirty_mb))
3576         createmany -o $TDIR/w $warmup_files
3577
3578         # write a large amount of data into one file and sync, to get good
3579         # avail_grant number from OST.
3580         for ((i=0; i<$warmup_files; i++)); do
3581                 idx=$($GETSTRIPE -i $TDIR/w$i)
3582                 [ $idx -ne 0 ] && continue
3583                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3584                 break
3585         done
3586         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3587         sync
3588         $LCTL get_param $proc_osc0/cur_dirty_bytes
3589         $LCTL get_param $proc_osc0/cur_grant_bytes
3590
3591         # create as much dirty pages as we can while not to trigger the actual
3592         # RPCs directly. but depends on the env, VFS may trigger flush during this
3593         # period, hopefully we are good.
3594         for ((i=0; i<$warmup_files; i++)); do
3595                 idx=$($GETSTRIPE -i $TDIR/w$i)
3596                 [ $idx -ne 0 ] && continue
3597                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3598         done
3599         $LCTL get_param $proc_osc0/cur_dirty_bytes
3600         $LCTL get_param $proc_osc0/cur_grant_bytes
3601
3602         # perform the real test
3603         $LCTL set_param $proc_osc0/rpc_stats 0
3604         for ((;i<$files; i++)); do
3605                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3606                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3607         done
3608         sync
3609         $LCTL get_param $proc_osc0/rpc_stats
3610
3611         local percent=0
3612         local have_ppr=false
3613         $LCTL get_param $proc_osc0/rpc_stats |
3614                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3615                         # skip lines until we are at the RPC histogram data
3616                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3617                         $have_ppr || continue
3618
3619                         # we only want the percent stat for < 16 pages
3620                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3621
3622                         percent=$((percent + WPCT))
3623                         if [[ $percent -gt 15 ]]; then
3624                                 error "less than 16-pages write RPCs" \
3625                                       "$percent% > 15%"
3626                                 break
3627                         fi
3628                 done
3629         rm -rf $TDIR
3630 }
3631 run_test 42e "verify sub-RPC writes are not done synchronously"
3632
3633 test_43() {
3634         test_mkdir -p $DIR/$tdir
3635         cp -p /bin/ls $DIR/$tdir/$tfile
3636         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3637         pid=$!
3638         # give multiop a chance to open
3639         sleep 1
3640
3641         $DIR/$tdir/$tfile && error || true
3642         kill -USR1 $pid
3643 }
3644 run_test 43 "execution of file opened for write should return -ETXTBSY"
3645
3646 test_43a() {
3647         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3648         test_mkdir -p $DIR/$tdir
3649         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3650                         cp -p multiop $DIR/$tdir/multiop
3651         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3652                         return 1
3653         MULTIOP_PID=$!
3654         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3655         kill -USR1 $MULTIOP_PID || return 2
3656         wait $MULTIOP_PID || return 3
3657         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3658 }
3659 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3660
3661 test_43b() {
3662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3663         test_mkdir -p $DIR/$tdir
3664         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3665                         cp -p multiop $DIR/$tdir/multiop
3666         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3667                         return 1
3668         MULTIOP_PID=$!
3669         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3670         kill -USR1 $MULTIOP_PID || return 2
3671         wait $MULTIOP_PID || return 3
3672         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3673 }
3674 run_test 43b "truncate of file being executed should return -ETXTBSY"
3675
3676 test_43c() {
3677         local testdir="$DIR/$tdir"
3678         test_mkdir -p $DIR/$tdir
3679         cp $SHELL $testdir/
3680         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3681                 ( cd $testdir && md5sum -c)
3682 }
3683 run_test 43c "md5sum of copy into lustre========================"
3684
3685 test_44() {
3686         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3687         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3688         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3689 }
3690 run_test 44 "zero length read from a sparse stripe ============="
3691
3692 test_44a() {
3693         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3694                 awk '{ print $2 }')
3695         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3696         [[ $nstripe -gt $OSTCOUNT ]] &&
3697             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3698             return
3699         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3700                 awk '{ print $2 }')
3701         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3702                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3703                         awk '{ print $2 }')
3704         fi
3705
3706         OFFSETS="0 $((stride/2)) $((stride-1))"
3707         for offset in $OFFSETS; do
3708                 for i in $(seq 0 $((nstripe-1))); do
3709                         local GLOBALOFFSETS=""
3710                         # size in Bytes
3711                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3712                         local myfn=$DIR/d44a-$size
3713                         echo "--------writing $myfn at $size"
3714                         ll_sparseness_write $myfn $size ||
3715                                 error "ll_sparseness_write"
3716                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3717                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3718                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3719
3720                         for j in $(seq 0 $((nstripe-1))); do
3721                                 # size in Bytes
3722                                 size=$((((j + $nstripe )*$stride + $offset)))
3723                                 ll_sparseness_write $myfn $size ||
3724                                         error "ll_sparseness_write"
3725                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3726                         done
3727                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3728                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3729                         rm -f $myfn
3730                 done
3731         done
3732 }
3733 run_test 44a "test sparse pwrite ==============================="
3734
3735 dirty_osc_total() {
3736         tot=0
3737         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3738                 tot=$(($tot + $d))
3739         done
3740         echo $tot
3741 }
3742 do_dirty_record() {
3743         before=`dirty_osc_total`
3744         echo executing "\"$*\""
3745         eval $*
3746         after=`dirty_osc_total`
3747         echo before $before, after $after
3748 }
3749 test_45() {
3750         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3751         f="$DIR/f45"
3752         # Obtain grants from OST if it supports it
3753         echo blah > ${f}_grant
3754         stop_writeback
3755         sync
3756         do_dirty_record "echo blah > $f"
3757         [[ $before -eq $after ]] && error "write wasn't cached"
3758         do_dirty_record "> $f"
3759         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3760         do_dirty_record "echo blah > $f"
3761         [[ $before -eq $after ]] && error "write wasn't cached"
3762         do_dirty_record "sync"
3763         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3764         do_dirty_record "echo blah > $f"
3765         [[ $before -eq $after ]] && error "write wasn't cached"
3766         do_dirty_record "cancel_lru_locks osc"
3767         [[ $before -gt $after ]] ||
3768                 error "lock cancellation didn't lower dirty count"
3769         start_writeback
3770 }
3771 run_test 45 "osc io page accounting ============================"
3772
3773 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3774 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3775 # objects offset and an assert hit when an rpc was built with 1023's mapped
3776 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3777 test_46() {
3778         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3779         f="$DIR/f46"
3780         stop_writeback
3781         sync
3782         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3783         sync
3784         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3785         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3786         sync
3787         start_writeback
3788 }
3789 run_test 46 "dirtying a previously written page ================"
3790
3791 # test_47 is removed "Device nodes check" is moved to test_28
3792
3793 test_48a() { # bug 2399
3794         check_kernel_version 34 || return 0
3795         test_mkdir -p $DIR/$tdir
3796         cd $DIR/$tdir
3797         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3798         test_mkdir $DIR/$tdir || error "recreate directory failed"
3799         touch foo || error "'touch foo' failed after recreating cwd"
3800         test_mkdir $DIR/$tdir/bar ||
3801                      error "'mkdir foo' failed after recreating cwd"
3802         if check_kernel_version 44; then
3803                 touch .foo || error "'touch .foo' failed after recreating cwd"
3804                 test_mkdir $DIR/$tdir/.bar ||
3805                               error "'mkdir .foo' failed after recreating cwd"
3806         fi
3807         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3808         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3809         cd . || error "'cd .' failed after recreating cwd"
3810         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3811         rmdir . && error "'rmdir .' worked after recreating cwd"
3812         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3813         cd .. || error "'cd ..' failed after recreating cwd"
3814 }
3815 run_test 48a "Access renamed working dir (should return errors)="
3816
3817 test_48b() { # bug 2399
3818         check_kernel_version 34 || return 0
3819         rm -rf $DIR/$tdir
3820         test_mkdir -p $DIR/$tdir
3821         cd $DIR/$tdir
3822         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3823         touch foo && error "'touch foo' worked after removing cwd"
3824         test_mkdir $DIR/$tdir/foo &&
3825                      error "'mkdir foo' worked after removing cwd"
3826         if check_kernel_version 44; then
3827                 touch .foo && error "'touch .foo' worked after removing cwd"
3828                 test_mkdir $DIR/$tdir/.foo &&
3829                               error "'mkdir .foo' worked after removing cwd"
3830         fi
3831         ls . > /dev/null && error "'ls .' worked after removing cwd"
3832         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3833         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3834         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3835         rmdir . && error "'rmdir .' worked after removing cwd"
3836         ln -s . foo && error "'ln -s .' worked after removing cwd"
3837         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3838 }
3839 run_test 48b "Access removed working dir (should return errors)="
3840
3841 test_48c() { # bug 2350
3842         check_kernel_version 36 || return 0
3843         #lctl set_param debug=-1
3844         #set -vx
3845         rm -rf $DIR/$tdir
3846         test_mkdir -p $DIR/$tdir/dir
3847         cd $DIR/$tdir/dir
3848         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3849         $TRACE touch foo && error "touch foo worked after removing cwd"
3850         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3851         if check_kernel_version 44; then
3852                 touch .foo && error "touch .foo worked after removing cwd"
3853                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3854         fi
3855         $TRACE ls . && error "'ls .' worked after removing cwd"
3856         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3857         is_patchless || ( $TRACE cd . &&
3858                         error "'cd .' worked after removing cwd" )
3859         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3860         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3861         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3862         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3863 }
3864 run_test 48c "Access removed working subdir (should return errors)"
3865
3866 test_48d() { # bug 2350
3867         check_kernel_version 36 || return 0
3868         #lctl set_param debug=-1
3869         #set -vx
3870         rm -rf $DIR/$tdir
3871         test_mkdir -p $DIR/$tdir/dir
3872         cd $DIR/$tdir/dir
3873         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3874         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3875         $TRACE touch foo && error "'touch foo' worked after removing parent"
3876         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3877         if check_kernel_version 44; then
3878                 touch .foo && error "'touch .foo' worked after removing parent"
3879                 test_mkdir .foo &&
3880                               error "mkdir .foo worked after removing parent"
3881         fi
3882         $TRACE ls . && error "'ls .' worked after removing parent"
3883         $TRACE ls .. && error "'ls ..' worked after removing parent"
3884         is_patchless || ( $TRACE cd . &&
3885                         error "'cd .' worked after recreate parent" )
3886         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3887         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3888         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3889         is_patchless || ( $TRACE cd .. &&
3890                         error "'cd ..' worked after removing parent" || true )
3891 }
3892 run_test 48d "Access removed parent subdir (should return errors)"
3893
3894 test_48e() { # bug 4134
3895         check_kernel_version 41 || return 0
3896         #lctl set_param debug=-1
3897         #set -vx
3898         rm -rf $DIR/$tdir
3899         test_mkdir -p $DIR/$tdir/dir
3900         cd $DIR/$tdir/dir
3901         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3902         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3903         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3904         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3905         # On a buggy kernel addition of "touch foo" after cd .. will
3906         # produce kernel oops in lookup_hash_it
3907         touch ../foo && error "'cd ..' worked after recreate parent"
3908         cd $DIR
3909         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3910 }
3911 run_test 48e "Access to recreated parent subdir (should return errors)"
3912
3913 test_49() { # LU-1030
3914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3915         # get ost1 size - lustre-OST0000
3916         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3917                 awk '{ print $4 }')
3918         # write 800M at maximum
3919         [[ $ost1_size -lt 2 ]] && ost1_size=2
3920         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3921
3922         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3923         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3924         local dd_pid=$!
3925
3926         # change max_pages_per_rpc while writing the file
3927         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3928         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3929         # loop until dd process exits
3930         while ps ax -opid | grep -wq $dd_pid; do
3931                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3932                 sleep $((RANDOM % 5 + 1))
3933         done
3934         # restore original max_pages_per_rpc
3935         $LCTL set_param $osc1_mppc=$orig_mppc
3936         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3937 }
3938 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3939
3940 test_50() {
3941         # bug 1485
3942         test_mkdir $DIR/$tdir
3943         cd $DIR/$tdir
3944         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3945 }
3946 run_test 50 "special situations: /proc symlinks  ==============="
3947
3948 test_51a() {    # was test_51
3949         # bug 1516 - create an empty entry right after ".." then split dir
3950         test_mkdir -c1 $DIR/$tdir
3951         touch $DIR/$tdir/foo
3952         $MCREATE $DIR/$tdir/bar
3953         rm $DIR/$tdir/foo
3954         createmany -m $DIR/$tdir/longfile 201
3955         FNUM=202
3956         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3957                 $MCREATE $DIR/$tdir/longfile$FNUM
3958                 FNUM=$(($FNUM + 1))
3959                 echo -n "+"
3960         done
3961         echo
3962         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3963 }
3964 run_test 51a "special situations: split htree with empty entry =="
3965
3966 export NUMTEST=70000
3967 test_51b() {
3968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3969         local BASE=$DIR/d${base}.${TESTSUITE}
3970
3971         # cleanup the directory
3972         rm -fr $BASE
3973
3974         test_mkdir -p -c1 $BASE
3975
3976         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3977         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3978         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3979                 return
3980
3981         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3982                 echo "reduced count to $NUMTEST due to inodes"
3983
3984         # need to check free space for the directories as well
3985         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3986         numfree=$((blkfree / 4))
3987         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3988                 echo "reduced count to $NUMTEST due to blocks"
3989
3990         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3991                 echo "failed" > $BASE/fnum
3992 }
3993 run_test 51b "exceed 64k subdirectory nlink limit"
3994
3995 test_51ba() { # LU-993
3996         local BASE=$DIR/d${base}.${TESTSUITE}
3997         # unlink all but 100 subdirectories, then check it still works
3998         local LEFT=100
3999         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4000
4001         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4002         local DELETE=$((NUMTEST - LEFT))
4003
4004         # continue on to run this test even if 51b didn't finish,
4005         # just to delete the many subdirectories created.
4006         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4007
4008         # for ldiskfs the nlink count should be 1, but this is OSD specific
4009         # and so this is listed for informational purposes only
4010         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4011         unlinkmany -d $BASE/d $DELETE
4012         RC=$?
4013
4014         if [ $RC -ne 0 ]; then
4015                 if [ "$NUMPREV" == "failed" ]; then
4016                         skip "previous setup failed"
4017                         return 0
4018                 else
4019                         error "unlink of first $DELETE subdirs failed"
4020                         return $RC
4021                 fi
4022         fi
4023
4024         echo "nlink between: $(stat -c %h $BASE)"
4025         # trim the first line of ls output
4026         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4027         [ $FOUND -ne $LEFT ] &&
4028                 error "can't find subdirs: found only $FOUND/$LEFT"
4029
4030         unlinkmany -d $BASE/d $DELETE $LEFT ||
4031                 error "unlink of second $LEFT subdirs failed"
4032         # regardless of whether the backing filesystem tracks nlink accurately
4033         # or not, the nlink count shouldn't be more than "." and ".." here
4034         local AFTER=$(stat -c %h $BASE)
4035         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4036                 echo "nlink after: $AFTER"
4037 }
4038 run_test 51ba "verify nlink for many subdirectory cleanup"
4039
4040 test_51d() {
4041         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4042         [[ $OSTCOUNT -lt 3 ]] &&
4043                 skip_env "skipping test with few OSTs" && return
4044         test_mkdir -p $DIR/$tdir
4045         createmany -o $DIR/$tdir/t- 1000
4046         $GETSTRIPE $DIR/$tdir > $TMP/files
4047         for N in $(seq 0 $((OSTCOUNT - 1))); do
4048                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4049                         END { printf("%0.0f", objs) }' $TMP/files)
4050                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4051                         '($1 == '$N') { objs += 1 } \
4052                         END { printf("%0.0f", objs) }')
4053                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4054         done
4055         unlinkmany $DIR/$tdir/t- 1000
4056
4057         NLAST=0
4058         for N in $(seq 1 $((OSTCOUNT - 1))); do
4059                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4060                         error "OST $N has less objects vs OST $NLAST" \
4061                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4062                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4063                         error "OST $N has less objects vs OST $NLAST" \
4064                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4065
4066                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4067                         error "OST $N has less #0 objects vs OST $NLAST" \
4068                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4069                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4070                         error "OST $N has less #0 objects vs OST $NLAST" \
4071                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4072                 NLAST=$N
4073         done
4074 }
4075 run_test 51d "check object distribution ===================="
4076
4077 test_51e() {
4078         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4079                 skip "Only applicable to ldiskfs-based MDTs"
4080                 return
4081         fi
4082
4083         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4084         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4085
4086         touch $DIR/$tdir/d0/foo
4087         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4088                 error "file exceed 65000 nlink limit!"
4089         unlinkmany $DIR/$tdir/d0/f- 65001
4090         return 0
4091 }
4092 run_test 51e "check file nlink limit"
4093
4094 test_52a() {
4095         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4096         test_mkdir -p $DIR/$tdir
4097         touch $DIR/$tdir/foo
4098         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4099         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4100         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4101         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4102         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4103                                         error "link worked"
4104         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4105         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4106         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4107                                                      error "lsattr"
4108         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4109         cp -r $DIR/$tdir /tmp/
4110         rm -fr $DIR/$tdir || error "cleanup rm failed"
4111 }
4112 run_test 52a "append-only flag test (should return errors) ====="
4113
4114 test_52b() {
4115         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4116         test_mkdir -p $DIR/$tdir
4117         touch $DIR/$tdir/foo
4118         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4119         cat test > $DIR/$tdir/foo && error "cat test worked"
4120         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4121         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4122         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4123                                         error "link worked"
4124         echo foo >> $DIR/$tdir/foo && error "echo worked"
4125         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4126         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4127         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4128         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4129                                                         error "lsattr"
4130         chattr -i $DIR/$tdir/foo || error "chattr failed"
4131
4132         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4133 }
4134 run_test 52b "immutable flag test (should return errors) ======="
4135
4136 test_53() {
4137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4138         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4139         remote_ost_nodsh && skip "remote OST with nodsh" && return
4140
4141         local param
4142         local param_seq
4143         local ostname
4144         local mds_last
4145         local mds_last_seq
4146         local ost_last
4147         local ost_last_seq
4148         local ost_last_id
4149         local ostnum
4150         local node
4151         local found=false
4152         local support_last_seq=true
4153
4154         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4155                 support_last_seq=false
4156
4157         # only test MDT0000
4158         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4159         local value
4160         for value in $(do_facet $SINGLEMDS \
4161                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4162                 param=$(echo ${value[0]} | cut -d "=" -f1)
4163                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4164
4165                 if $support_last_seq; then
4166                         param_seq=$(echo $param |
4167                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4168                         mds_last_seq=$(do_facet $SINGLEMDS \
4169                                        $LCTL get_param -n $param_seq)
4170                 fi
4171                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4172
4173                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4174                 node=$(facet_active_host ost$((ostnum+1)))
4175                 param="obdfilter.$ostname.last_id"
4176                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4177                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4178                         ost_last_id=$ost_last
4179
4180                         if $support_last_seq; then
4181                                 ost_last_id=$(echo $ost_last |
4182                                               awk -F':' '{print $2}' |
4183                                               sed -e "s/^0x//g")
4184                                 ost_last_seq=$(echo $ost_last |
4185                                                awk -F':' '{print $1}')
4186                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4187                         fi
4188
4189                         if [[ $ost_last_id != $mds_last ]]; then
4190                                 error "$ost_last_id != $mds_last"
4191                         else
4192                                 found=true
4193                                 break
4194                         fi
4195                 done
4196         done
4197         $found || error "can not match last_seq/last_id for $mdtosc"
4198         return 0
4199 }
4200 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4201
4202 test_54a() {
4203         $SOCKETSERVER $DIR/socket ||
4204                 error "$SOCKETSERVER $DIR/socket failed: $?"
4205         $SOCKETCLIENT $DIR/socket ||
4206                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4207         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4208 }
4209 run_test 54a "unix domain socket test =========================="
4210
4211 test_54b() {
4212         f="$DIR/f54b"
4213         mknod $f c 1 3
4214         chmod 0666 $f
4215         dd if=/dev/zero of=$f bs=$(page_size) count=1
4216 }
4217 run_test 54b "char device works in lustre ======================"
4218
4219 find_loop_dev() {
4220         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4221         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4222         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4223
4224         for i in $(seq 3 7); do
4225                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4226                 LOOPDEV=$LOOPBASE$i
4227                 LOOPNUM=$i
4228                 break
4229         done
4230 }
4231
4232 cleanup_54c() {
4233         loopdev="$DIR/loop54c"
4234
4235         trap 0
4236         $UMOUNT -d $DIR/$tdir || rc=$?
4237         losetup -d $loopdev || true
4238         losetup -d $LOOPDEV || true
4239         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4240         return $rc
4241 }
4242
4243 test_54c() {
4244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4245         loopdev="$DIR/loop54c"
4246
4247         find_loop_dev
4248         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4249         trap cleanup_54c EXIT
4250         mknod $loopdev b 7 $LOOPNUM
4251         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4252         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4253         losetup $loopdev $DIR/$tfile ||
4254                 error "can't set up $loopdev for $DIR/$tfile"
4255         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4256         test_mkdir -p $DIR/$tdir
4257         mount -t ext2 $loopdev $DIR/$tdir ||
4258                 error "error mounting $loopdev on $DIR/$tdir"
4259         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4260                 error "dd write"
4261         df $DIR/$tdir
4262         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4263                 error "dd read"
4264         cleanup_54c
4265 }
4266 run_test 54c "block device works in lustre ====================="
4267
4268 test_54d() {
4269         f="$DIR/f54d"
4270         string="aaaaaa"
4271         mknod $f p
4272         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4273 }
4274 run_test 54d "fifo device works in lustre ======================"
4275
4276 test_54e() {
4277         check_kernel_version 46 || return 0
4278         f="$DIR/f54e"
4279         string="aaaaaa"
4280         cp -aL /dev/console $f
4281         echo $string > $f || error "echo $string to $f failed"
4282 }
4283 run_test 54e "console/tty device works in lustre ======================"
4284
4285 #The test_55 used to be iopen test and it was removed by bz#24037.
4286 #run_test 55 "check iopen_connect_dentry() ======================"
4287
4288 test_56a() {    # was test_56
4289         rm -rf $DIR/$tdir
4290         $SETSTRIPE -d $DIR
4291         test_mkdir -p $DIR/$tdir/dir
4292         NUMFILES=3
4293         NUMFILESx2=$(($NUMFILES * 2))
4294         for i in $(seq 1 $NUMFILES); do
4295                 touch $DIR/$tdir/file$i
4296                 touch $DIR/$tdir/dir/file$i
4297         done
4298
4299         # test lfs getstripe with --recursive
4300         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4301         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4302                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4303         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4304         [[ $FILENUM -eq $NUMFILES ]] ||
4305                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4306         echo "$GETSTRIPE --recursive passed."
4307
4308         # test lfs getstripe with file instead of dir
4309         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4310         [[ $FILENUM -eq 1 ]] ||
4311                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4312         echo "$GETSTRIPE file1 passed."
4313
4314         #test lfs getstripe with --verbose
4315         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4316                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4317                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4318         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4319                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4320         echo "$GETSTRIPE --verbose passed."
4321
4322         #test lfs getstripe with --obd
4323         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4324                 grep -q "unknown obduuid" ||
4325                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4326
4327         [[ $OSTCOUNT -lt 2 ]] &&
4328                 skip_env "skipping other $GETSTRIPE --obd test" && return
4329
4330         OSTIDX=1
4331         OBDUUID=$(ostuuid_from_index $OSTIDX)
4332         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4333         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4334         [[ $FOUND -eq $FILENUM ]] ||
4335                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4336         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4337                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4338                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4339                 error "$GETSTRIPE --obd: should not show file on other obd"
4340         echo "$GETSTRIPE --obd passed"
4341 }
4342 run_test 56a "check $GETSTRIPE"
4343
4344 NUMFILES=3
4345 NUMDIRS=3
4346 setup_56() {
4347         local LOCAL_NUMFILES="$1"
4348         local LOCAL_NUMDIRS="$2"
4349         local MKDIR_PARAMS="$3"
4350         local DIR_STRIPE_PARAMS="$4"
4351
4352         if [ ! -d "$TDIR" ] ; then
4353                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4354                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4355                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4356                         touch $TDIR/file$i
4357                 done
4358                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4359                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4360                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4361                                 touch $TDIR/dir$i/file$j
4362                         done
4363                 done
4364         fi
4365 }
4366
4367 setup_56_special() {
4368         LOCAL_NUMFILES=$1
4369         LOCAL_NUMDIRS=$2
4370         setup_56 $1 $2
4371         if [ ! -e "$TDIR/loop1b" ] ; then
4372                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4373                         mknod $TDIR/loop${i}b b 7 $i
4374                         mknod $TDIR/null${i}c c 1 3
4375                         ln -s $TDIR/file1 $TDIR/link${i}l
4376                 done
4377                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4378                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4379                         mknod $TDIR/dir$i/null${i}c c 1 3
4380                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4381                 done
4382         fi
4383 }
4384
4385 test_56g() {
4386         $SETSTRIPE -d $DIR
4387
4388         TDIR=$DIR/${tdir}g
4389         setup_56 $NUMFILES $NUMDIRS
4390
4391         EXPECTED=$(($NUMDIRS + 2))
4392         # test lfs find with -name
4393         for i in $(seq 1 $NUMFILES) ; do
4394                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4395                 [ $NUMS -eq $EXPECTED ] ||
4396                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4397                               "found $NUMS, expected $EXPECTED"
4398         done
4399 }
4400 run_test 56g "check lfs find -name ============================="
4401
4402 test_56h() {
4403         $SETSTRIPE -d $DIR
4404
4405         TDIR=$DIR/${tdir}g
4406         setup_56 $NUMFILES $NUMDIRS
4407
4408         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4409         # test lfs find with ! -name
4410         for i in $(seq 1 $NUMFILES) ; do
4411                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4412                 [ $NUMS -eq $EXPECTED ] ||
4413                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4414                               "found $NUMS, expected $EXPECTED"
4415         done
4416 }
4417 run_test 56h "check lfs find ! -name ============================="
4418
4419 test_56i() {
4420        tdir=${tdir}i
4421        test_mkdir -p $DIR/$tdir
4422        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4423        CMD="$LFIND -ost $UUID $DIR/$tdir"
4424        OUT=$($CMD)
4425        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4426 }
4427 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4428
4429 test_56j() {
4430         TDIR=$DIR/${tdir}g
4431         setup_56_special $NUMFILES $NUMDIRS
4432
4433         EXPECTED=$((NUMDIRS + 1))
4434         CMD="$LFIND -type d $TDIR"
4435         NUMS=$($CMD | wc -l)
4436         [ $NUMS -eq $EXPECTED ] ||
4437                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4438 }
4439 run_test 56j "check lfs find -type d ============================="
4440
4441 test_56k() {
4442         TDIR=$DIR/${tdir}g
4443         setup_56_special $NUMFILES $NUMDIRS
4444
4445         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4446         CMD="$LFIND -type f $TDIR"
4447         NUMS=$($CMD | wc -l)
4448         [ $NUMS -eq $EXPECTED ] ||
4449                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4450 }
4451 run_test 56k "check lfs find -type f ============================="
4452
4453 test_56l() {
4454         TDIR=$DIR/${tdir}g
4455         setup_56_special $NUMFILES $NUMDIRS
4456
4457         EXPECTED=$((NUMDIRS + NUMFILES))
4458         CMD="$LFIND -type b $TDIR"
4459         NUMS=$($CMD | wc -l)
4460         [ $NUMS -eq $EXPECTED ] ||
4461                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4462 }
4463 run_test 56l "check lfs find -type b ============================="
4464
4465 test_56m() {
4466         TDIR=$DIR/${tdir}g
4467         setup_56_special $NUMFILES $NUMDIRS
4468
4469         EXPECTED=$((NUMDIRS + NUMFILES))
4470         CMD="$LFIND -type c $TDIR"
4471         NUMS=$($CMD | wc -l)
4472         [ $NUMS -eq $EXPECTED ] ||
4473                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4474 }
4475 run_test 56m "check lfs find -type c ============================="
4476
4477 test_56n() {
4478         TDIR=$DIR/${tdir}g
4479         setup_56_special $NUMFILES $NUMDIRS
4480
4481         EXPECTED=$((NUMDIRS + NUMFILES))
4482         CMD="$LFIND -type l $TDIR"
4483         NUMS=$($CMD | wc -l)
4484         [ $NUMS -eq $EXPECTED ] ||
4485                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4486 }
4487 run_test 56n "check lfs find -type l ============================="
4488
4489 test_56o() {
4490         TDIR=$DIR/${tdir}o
4491         setup_56 $NUMFILES $NUMDIRS
4492         utime $TDIR/file1 > /dev/null || error "utime (1)"
4493         utime $TDIR/file2 > /dev/null || error "utime (2)"
4494         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4495         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4496         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4497         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4498
4499         EXPECTED=4
4500         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4501         [ $NUMS -eq $EXPECTED ] || \
4502                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4503
4504         EXPECTED=12
4505         CMD="$LFIND -mtime 0 $TDIR"
4506         NUMS=$($CMD | wc -l)
4507         [ $NUMS -eq $EXPECTED ] ||
4508                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4509 }
4510 run_test 56o "check lfs find -mtime for old files =========================="
4511
4512 test_56p() {
4513         [ $RUNAS_ID -eq $UID ] &&
4514                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4515
4516         TDIR=$DIR/${tdir}p
4517         setup_56 $NUMFILES $NUMDIRS
4518
4519         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4520         EXPECTED=$NUMFILES
4521         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4522         NUMS=$($CMD | wc -l)
4523         [ $NUMS -eq $EXPECTED ] || \
4524                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4525
4526         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4527         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4528         NUMS=$($CMD | wc -l)
4529         [ $NUMS -eq $EXPECTED ] || \
4530                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4531 }
4532 run_test 56p "check lfs find -uid and ! -uid ==============================="
4533
4534 test_56q() {
4535         [ $RUNAS_ID -eq $UID ] &&
4536                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4537
4538         TDIR=$DIR/${tdir}q
4539         setup_56 $NUMFILES $NUMDIRS
4540
4541         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4542
4543         EXPECTED=$NUMFILES
4544         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4545         NUMS=$($CMD | wc -l)
4546         [ $NUMS -eq $EXPECTED ] ||
4547                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4548
4549         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4550         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4551         NUMS=$($CMD | wc -l)
4552         [ $NUMS -eq $EXPECTED ] ||
4553                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4554 }
4555 run_test 56q "check lfs find -gid and ! -gid ==============================="
4556
4557 test_56r() {
4558         TDIR=$DIR/${tdir}r
4559         setup_56 $NUMFILES $NUMDIRS
4560
4561         EXPECTED=12
4562         CMD="$LFIND -size 0 -type f $TDIR"
4563         NUMS=$($CMD | wc -l)
4564         [ $NUMS -eq $EXPECTED ] ||
4565                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4566         EXPECTED=0
4567         CMD="$LFIND ! -size 0 -type f $TDIR"
4568         NUMS=$($CMD | wc -l)
4569         [ $NUMS -eq $EXPECTED ] ||
4570                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4571         echo "test" > $TDIR/$tfile
4572         echo "test2" > $TDIR/$tfile.2 && sync
4573         EXPECTED=1
4574         CMD="$LFIND -size 5 -type f $TDIR"
4575         NUMS=$($CMD | wc -l)
4576         [ $NUMS -eq $EXPECTED ] ||
4577                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4578         EXPECTED=1
4579         CMD="$LFIND -size +5 -type f $TDIR"
4580         NUMS=$($CMD | wc -l)
4581         [ $NUMS -eq $EXPECTED ] ||
4582                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4583         EXPECTED=2
4584         CMD="$LFIND -size +0 -type f $TDIR"
4585         NUMS=$($CMD | wc -l)
4586         [ $NUMS -eq $EXPECTED ] ||
4587                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4588         EXPECTED=2
4589         CMD="$LFIND ! -size -5 -type f $TDIR"
4590         NUMS=$($CMD | wc -l)
4591         [ $NUMS -eq $EXPECTED ] ||
4592                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4593         EXPECTED=12
4594         CMD="$LFIND -size -5 -type f $TDIR"
4595         NUMS=$($CMD | wc -l)
4596         [ $NUMS -eq $EXPECTED ] ||
4597                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4598 }
4599 run_test 56r "check lfs find -size works =========================="
4600
4601 test_56s() { # LU-611
4602         TDIR=$DIR/${tdir}s
4603         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4604
4605         if [[ $OSTCOUNT -gt 1 ]]; then
4606                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4607                 ONESTRIPE=4
4608                 EXTRA=4
4609         else
4610                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4611                 EXTRA=0
4612         fi
4613
4614         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4615         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4616         NUMS=$($CMD | wc -l)
4617         [ $NUMS -eq $EXPECTED ] || {
4618                 $GETSTRIPE -R $TDIR
4619                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4620         }
4621
4622         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4623         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4624         NUMS=$($CMD | wc -l)
4625         [ $NUMS -eq $EXPECTED ] || {
4626                 $GETSTRIPE -R $TDIR
4627                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4628         }
4629
4630         EXPECTED=$ONESTRIPE
4631         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4632         NUMS=$($CMD | wc -l)
4633         [ $NUMS -eq $EXPECTED ] || {
4634                 $GETSTRIPE -R $TDIR
4635                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4636         }
4637
4638         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4639         NUMS=$($CMD | wc -l)
4640         [ $NUMS -eq $EXPECTED ] || {
4641                 $GETSTRIPE -R $TDIR
4642                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4643         }
4644
4645         EXPECTED=0
4646         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4647         NUMS=$($CMD | wc -l)
4648         [ $NUMS -eq $EXPECTED ] || {
4649                 $GETSTRIPE -R $TDIR
4650                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4651         }
4652 }
4653 run_test 56s "check lfs find -stripe-count works"
4654
4655 test_56t() { # LU-611
4656         TDIR=$DIR/${tdir}t
4657         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4658
4659         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4660
4661         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4662         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4663         NUMS=$($CMD | wc -l)
4664         [ $NUMS -eq $EXPECTED ] ||
4665                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4666
4667         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4668         NUMS=$($CMD | wc -l)
4669         [ $NUMS -eq $EXPECTED ] ||
4670                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4671
4672         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4673         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4674         NUMS=$($CMD | wc -l)
4675         [ $NUMS -eq $EXPECTED ] ||
4676                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4677
4678         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4679         NUMS=$($CMD | wc -l)
4680         [ $NUMS -eq $EXPECTED ] ||
4681                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4682
4683         EXPECTED=4
4684         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4685         NUMS=$($CMD | wc -l)
4686         [ $NUMS -eq $EXPECTED ] ||
4687                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4688
4689         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4690         NUMS=$($CMD | wc -l)
4691         [ $NUMS -eq $EXPECTED ] ||
4692                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4693
4694         EXPECTED=0
4695         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4696         NUMS=$($CMD | wc -l)
4697         [ $NUMS -eq $EXPECTED ] ||
4698                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4699 }
4700 run_test 56t "check lfs find -stripe-size works"
4701
4702 test_56u() { # LU-611
4703         TDIR=$DIR/${tdir}u
4704         setup_56 $NUMFILES $NUMDIRS "-i 0"
4705
4706         if [[ $OSTCOUNT -gt 1 ]]; then
4707                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4708                 ONESTRIPE=4
4709         else
4710                 ONESTRIPE=0
4711         fi
4712
4713         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4714         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4715         NUMS=$($CMD | wc -l)
4716         [ $NUMS -eq $EXPECTED ] ||
4717                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4718
4719         EXPECTED=$ONESTRIPE
4720         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4721         NUMS=$($CMD | wc -l)
4722         [ $NUMS -eq $EXPECTED ] ||
4723                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4724
4725         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4726         NUMS=$($CMD | wc -l)
4727         [ $NUMS -eq $EXPECTED ] ||
4728                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4729
4730         EXPECTED=0
4731         # This should produce an error and not return any files
4732         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4733         NUMS=$($CMD 2>/dev/null | wc -l)
4734         [ $NUMS -eq $EXPECTED ] ||
4735                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4736
4737         if [[ $OSTCOUNT -gt 1 ]]; then
4738                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4739                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4740                 NUMS=$($CMD | wc -l)
4741                 [ $NUMS -eq $EXPECTED ] ||
4742                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4743         fi
4744 }
4745 run_test 56u "check lfs find -stripe-index works"
4746
4747 test_56v() {
4748     local MDT_IDX=0
4749
4750     TDIR=$DIR/${tdir}v
4751     rm -rf $TDIR
4752     setup_56 $NUMFILES $NUMDIRS
4753
4754     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4755     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4756
4757     for file in $($LFIND -mdt $UUID $TDIR); do
4758         file_mdt_idx=$($GETSTRIPE -M $file)
4759         [ $file_mdt_idx -eq $MDT_IDX ] ||
4760             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4761     done
4762 }
4763 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4764
4765 # Get and check the actual stripe count of one file.
4766 # Usage: check_stripe_count <file> <expected_stripe_count>
4767 check_stripe_count() {
4768     local file=$1
4769     local expected=$2
4770     local actual
4771
4772     [[ -z "$file" || -z "$expected" ]] &&
4773         error "check_stripe_count: invalid argument!"
4774
4775     local cmd="$GETSTRIPE -c $file"
4776     actual=$($cmd) || error "$cmd failed"
4777     actual=${actual%% *}
4778
4779     if [[ $actual -ne $expected ]]; then
4780         [[ $expected -eq -1 ]] ||
4781             error "$cmd wrong: found $actual, expected $expected"
4782         [[ $actual -eq $OSTCOUNT ]] ||
4783             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4784     fi
4785 }
4786
4787 test_56w() {
4788         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4789         TDIR=$DIR/${tdir}w
4790
4791     rm -rf $TDIR || error "remove $TDIR failed"
4792     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4793
4794     local stripe_size
4795     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4796         error "$GETSTRIPE -S -d $TDIR failed"
4797     stripe_size=${stripe_size%% *}
4798
4799     local file_size=$((stripe_size * OSTCOUNT))
4800     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4801     local required_space=$((file_num * file_size))
4802     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4803     [[ $free_space -le $((required_space / 1024)) ]] &&
4804         skip_env "need at least $required_space bytes free space," \
4805                  "have $free_space kbytes" && return
4806
4807     local dd_bs=65536
4808     local dd_count=$((file_size / dd_bs))
4809
4810     # write data into the files
4811     local i
4812     local j
4813     local file
4814     for i in $(seq 1 $NUMFILES); do
4815         file=$TDIR/file$i
4816         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4817             error "write data into $file failed"
4818     done
4819     for i in $(seq 1 $NUMDIRS); do
4820         for j in $(seq 1 $NUMFILES); do
4821             file=$TDIR/dir$i/file$j
4822             yes | dd bs=$dd_bs count=$dd_count of=$file \
4823                 >/dev/null 2>&1 ||
4824                 error "write data into $file failed"
4825         done
4826     done
4827
4828     local expected=-1
4829     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4830
4831     # lfs_migrate file
4832     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4833     echo "$cmd"
4834     eval $cmd || error "$cmd failed"
4835
4836     check_stripe_count $TDIR/file1 $expected
4837
4838     # lfs_migrate dir
4839     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4840     echo "$cmd"
4841     eval $cmd || error "$cmd failed"
4842
4843     for j in $(seq 1 $NUMFILES); do
4844         check_stripe_count $TDIR/dir1/file$j $expected
4845     done
4846
4847     # lfs_migrate works with lfs find
4848     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4849          $LFS_MIGRATE -y -c $expected"
4850     echo "$cmd"
4851     eval $cmd || error "$cmd failed"
4852
4853     for i in $(seq 2 $NUMFILES); do
4854         check_stripe_count $TDIR/file$i $expected
4855     done
4856     for i in $(seq 2 $NUMDIRS); do
4857         for j in $(seq 1 $NUMFILES); do
4858             check_stripe_count $TDIR/dir$i/file$j $expected
4859         done
4860     done
4861 }
4862 run_test 56w "check lfs_migrate -c stripe_count works"
4863
4864 test_56x() {
4865         check_swap_layouts_support && return 0
4866         [[ $OSTCOUNT -lt 2 ]] &&
4867                 skip_env "need 2 OST, skipping test" && return
4868
4869         local dir0=$DIR/$tdir/$testnum
4870         mkdir -p $dir0 || error "creating dir $dir0"
4871
4872         local ref1=/etc/passwd
4873         local file1=$dir0/file1
4874
4875         $SETSTRIPE -c 2 $file1
4876         cp $ref1 $file1
4877         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4878         stripe=$($GETSTRIPE -c $file1)
4879         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4880         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4881
4882         # clean up
4883         rm -f $file1
4884 }
4885 run_test 56x "lfs migration support"
4886
4887 test_56y() {
4888         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4889                 skip "No HSM support on MDS of $(get_lustre_version)," \
4890                          "need 2.4.53 at least" && return
4891         local res=""
4892
4893         local dir0=$DIR/$tdir/$testnum
4894         mkdir -p $dir0 || error "creating dir $dir0"
4895         local f1=$dir0/file1
4896         local f2=$dir0/file2
4897
4898         touch $f1 || error "creating std file $f1"
4899         $MULTIOP $f2 H2c || error "creating released file $f2"
4900
4901         # a directory can be raid0, so ask only for files
4902         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4903         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4904
4905         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4906         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4907
4908         # only files can be released, so no need to force file search
4909         res=$($LFIND $dir0 -L released)
4910         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4911
4912         res=$($LFIND $dir0 \! -L released)
4913         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4914
4915 }
4916 run_test 56y "lfs find -L raid0|released"
4917
4918 test_56z() { # LU-4824
4919         # This checks to make sure 'lfs find' continues after errors
4920         # There are two classes of errors that should be caught:
4921         # - If multiple paths are provided, all should be searched even if one
4922         #   errors out
4923         # - If errors are encountered during the search, it should not terminate
4924         #   early
4925         local i
4926         test_mkdir $DIR/$tdir
4927         for i in d{0..9}; do
4928                 test_mkdir $DIR/$tdir/$i
4929         done
4930         touch $DIR/$tdir/d{0..9}/$tfile
4931         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4932                 error "$LFS find did not return an error"
4933         # Make a directory unsearchable. This should NOT be the last entry in
4934         # directory order.  Arbitrarily pick the 6th entry
4935         chmod 700 $(lfs find $DIR/$tdir -type d | sed '6!d')
4936         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4937         # The user should be able to see 10 directories and 9 files
4938         [ $count == 19 ] || error "$LFS find did not continue after error"
4939 }
4940 run_test 56z "lfs find should continue after an error"
4941
4942 test_57a() {
4943         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4944         # note test will not do anything if MDS is not local
4945         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4946                 skip "Only applicable to ldiskfs-based MDTs"
4947                 return
4948         fi
4949
4950         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4951         local MNTDEV="osd*.*MDT*.mntdev"
4952         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4953         [ -z "$DEV" ] && error "can't access $MNTDEV"
4954         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4955                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4956                         error "can't access $DEV"
4957                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4958                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4959                 rm $TMP/t57a.dump
4960         done
4961 }
4962 run_test 57a "verify MDS filesystem created with large inodes =="
4963
4964 test_57b() {
4965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4966         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4967                 skip "Only applicable to ldiskfs-based MDTs"
4968                 return
4969         fi
4970
4971         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4972         local dir=$DIR/d57b
4973
4974         local FILECOUNT=100
4975         local FILE1=$dir/f1
4976         local FILEN=$dir/f$FILECOUNT
4977
4978         rm -rf $dir || error "removing $dir"
4979         test_mkdir -p $dir || error "creating $dir"
4980         local num=$(get_mds_dir $dir)
4981         local mymds=mds$num
4982
4983         echo "mcreating $FILECOUNT files"
4984         createmany -m $dir/f 1 $FILECOUNT || \
4985                 error "creating files in $dir"
4986
4987         # verify that files do not have EAs yet
4988         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4989         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4990
4991         sync
4992         sleep 1
4993         df $dir  #make sure we get new statfs data
4994         local MDSFREE=$(do_facet $mymds \
4995                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4996         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4997         echo "opening files to create objects/EAs"
4998         local FILE
4999         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5000                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5001         done
5002
5003         # verify that files have EAs now
5004         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5005         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5006
5007         sleep 1  #make sure we get new statfs data
5008         df $dir
5009         local MDSFREE2=$(do_facet $mymds \
5010                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
5011         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5012         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5013                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5014                         error "MDC before $MDCFREE != after $MDCFREE2"
5015                 else
5016                         echo "MDC before $MDCFREE != after $MDCFREE2"
5017                         echo "unable to confirm if MDS has large inodes"
5018                 fi
5019         fi
5020         rm -rf $dir
5021 }
5022 run_test 57b "default LOV EAs are stored inside large inodes ==="
5023
5024 test_58() {
5025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5026         [ -z "$(which wiretest 2>/dev/null)" ] &&
5027                         skip_env "could not find wiretest" && return
5028         wiretest
5029 }
5030 run_test 58 "verify cross-platform wire constants =============="
5031
5032 test_59() {
5033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5034         echo "touch 130 files"
5035         createmany -o $DIR/f59- 130
5036         echo "rm 130 files"
5037         unlinkmany $DIR/f59- 130
5038         sync
5039         # wait for commitment of removal
5040         wait_delete_completed
5041 }
5042 run_test 59 "verify cancellation of llog records async ========="
5043
5044 TEST60_HEAD="test_60 run $RANDOM"
5045 test_60a() {
5046         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5047         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5048         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5049                 skip_env "missing subtest run-llog.sh" && return
5050         log "$TEST60_HEAD - from kernel mode"
5051         do_facet mgs sh run-llog.sh
5052 }
5053 run_test 60a "llog sanity tests run from kernel module =========="
5054
5055 test_60b() { # bug 6411
5056         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5057         dmesg > $DIR/$tfile
5058         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5059                                  /llog.test/ {
5060                                          if (marker)
5061                                                  from_marker++
5062                                          from_begin++
5063                                  }
5064                                  END {
5065                                          if (marker)
5066                                                  print from_marker
5067                                          else
5068                                                  print from_begin
5069                                  }"`
5070         [[ $LLOG_COUNT -gt 50 ]] &&
5071                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5072 }
5073 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5074
5075 test_60c() {
5076         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5077         echo "create 5000 files"
5078         createmany -o $DIR/f60c- 5000
5079 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5080         lctl set_param fail_loc=0x80000137
5081         unlinkmany $DIR/f60c- 5000
5082         lctl set_param fail_loc=0
5083 }
5084 run_test 60c "unlink file when mds full"
5085
5086 test_60d() {
5087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5088         SAVEPRINTK=$(lctl get_param -n printk)
5089
5090         # verify "lctl mark" is even working"
5091         MESSAGE="test message ID $RANDOM $$"
5092         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5093         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5094
5095         lctl set_param printk=0 || error "set lnet.printk failed"
5096         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5097         MESSAGE="new test message ID $RANDOM $$"
5098         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5099         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5100         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5101
5102         lctl set_param -n printk="$SAVEPRINTK"
5103 }
5104 run_test 60d "test printk console message masking"
5105
5106 test_61() {
5107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5108         f="$DIR/f61"
5109         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5110         cancel_lru_locks osc
5111         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5112         sync
5113 }
5114 run_test 61 "mmap() writes don't make sync hang ================"
5115
5116 # bug 2330 - insufficient obd_match error checking causes LBUG
5117 test_62() {
5118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5119         f="$DIR/f62"
5120         echo foo > $f
5121         cancel_lru_locks osc
5122         lctl set_param fail_loc=0x405
5123         cat $f && error "cat succeeded, expect -EIO"
5124         lctl set_param fail_loc=0
5125 }
5126 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5127 # match every page all of the time.
5128 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5129
5130 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5131 # Though this test is irrelevant anymore, it helped to reveal some
5132 # other grant bugs (LU-4482), let's keep it.
5133 test_63a() {   # was test_63
5134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5135         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5136         for i in `seq 10` ; do
5137                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5138                 sleep 5
5139                 kill $!
5140                 sleep 1
5141         done
5142
5143         rm -f $DIR/f63 || true
5144 }
5145 run_test 63a "Verify oig_wait interruption does not crash ======="
5146
5147 # bug 2248 - async write errors didn't return to application on sync
5148 # bug 3677 - async write errors left page locked
5149 test_63b() {
5150         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5151         debugsave
5152         lctl set_param debug=-1
5153
5154         # ensure we have a grant to do async writes
5155         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5156         rm $DIR/$tfile
5157
5158         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5159         lctl set_param fail_loc=0x80000406
5160         $MULTIOP $DIR/$tfile Owy && \
5161                 error "sync didn't return ENOMEM"
5162         sync; sleep 2; sync     # do a real sync this time to flush page
5163         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5164                 error "locked page left in cache after async error" || true
5165         debugrestore
5166 }
5167 run_test 63b "async write errors should be returned to fsync ==="
5168
5169 test_64a () {
5170         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5171         df $DIR
5172         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5173 }
5174 run_test 64a "verify filter grant calculations (in kernel) ====="
5175
5176 test_64b () {
5177         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5178         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5179 }
5180 run_test 64b "check out-of-space detection on client ==========="
5181
5182 test_64c() {
5183         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5184 }
5185 run_test 64c "verify grant shrink ========================------"
5186
5187 # bug 1414 - set/get directories' stripe info
5188 test_65a() {
5189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5190         test_mkdir -p $DIR/$tdir
5191         touch $DIR/$tdir/f1
5192         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5193 }
5194 run_test 65a "directory with no stripe info ===================="
5195
5196 test_65b() {
5197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5198         test_mkdir -p $DIR/$tdir
5199         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5200                                                 error "setstripe"
5201         touch $DIR/$tdir/f2
5202         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5203 }
5204 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5205
5206 test_65c() {
5207         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5208         if [[ $OSTCOUNT -gt 1 ]]; then
5209                 test_mkdir -p $DIR/$tdir
5210                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5211                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5212                 touch $DIR/$tdir/f3
5213                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5214         fi
5215 }
5216 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5217
5218 test_65d() {
5219         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5220         test_mkdir -p $DIR/$tdir
5221         if [[ $STRIPECOUNT -le 0 ]]; then
5222                 sc=1
5223         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5224 #LOV_MAX_STRIPE_COUNT is 2000
5225                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5226         else
5227                 sc=$(($STRIPECOUNT - 1))
5228         fi
5229         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5230         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5231         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5232                 error "lverify failed"
5233 }
5234 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5235
5236 test_65e() {
5237         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5238         test_mkdir -p $DIR/$tdir
5239
5240         $SETSTRIPE $DIR/$tdir || error "setstripe"
5241         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5242                                         error "no stripe info failed"
5243         touch $DIR/$tdir/f6
5244         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5245 }
5246 run_test 65e "directory setstripe defaults ======================="
5247
5248 test_65f() {
5249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5250         test_mkdir -p $DIR/${tdir}f
5251         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5252 }
5253 run_test 65f "dir setstripe permission (should return error) ==="
5254
5255 test_65g() {
5256         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5257         test_mkdir -p $DIR/$tdir
5258         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5259                                                         error "setstripe"
5260         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5261         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5262                 error "delete default stripe failed"
5263 }
5264 run_test 65g "directory setstripe -d ==========================="
5265
5266 test_65h() {
5267         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5268         test_mkdir -p $DIR/$tdir
5269         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5270                                                         error "setstripe"
5271         test_mkdir -p $DIR/$tdir/dd1
5272         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5273                 error "stripe info inherit failed"
5274 }
5275 run_test 65h "directory stripe info inherit ===================="
5276
5277 test_65i() { # bug6367
5278         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5279         $SETSTRIPE -S 65536 -c -1 $MOUNT
5280 }
5281 run_test 65i "set non-default striping on root directory (bug 6367)="
5282
5283 test_65ia() { # bug12836
5284         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5285         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5286 }
5287 run_test 65ia "getstripe on -1 default directory striping"
5288
5289 test_65ib() { # bug12836
5290         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5291         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5292 }
5293 run_test 65ib "getstripe -v on -1 default directory striping"
5294
5295 test_65ic() { # bug12836
5296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5297         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5298 }
5299 run_test 65ic "new find on -1 default directory striping"
5300
5301 test_65j() { # bug6367
5302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5303         sync; sleep 1
5304         # if we aren't already remounting for each test, do so for this test
5305         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5306                 cleanup || error "failed to unmount"
5307                 setup
5308         fi
5309         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5310 }
5311 run_test 65j "set default striping on root directory (bug 6367)="
5312
5313 test_65k() { # bug11679
5314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5315         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5316         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5317
5318     echo "Check OST status: "
5319     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5320               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5321
5322     for OSC in $MDS_OSCS; do
5323         echo $OSC "is activate"
5324         do_facet $SINGLEMDS lctl --device %$OSC activate
5325     done
5326
5327     mkdir -p $DIR/$tdir
5328     for INACTIVE_OSC in $MDS_OSCS; do
5329         echo "Deactivate: " $INACTIVE_OSC
5330         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5331         for STRIPE_OSC in $MDS_OSCS; do
5332             OST=`osc_to_ost $STRIPE_OSC`
5333             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5334                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5335
5336             [ -f $DIR/$tdir/$IDX ] && continue
5337             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5338             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5339             RC=$?
5340             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5341         done
5342         rm -f $DIR/$tdir/*
5343         echo $INACTIVE_OSC "is Activate."
5344         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5345     done
5346 }
5347 run_test 65k "validate manual striping works properly with deactivated OSCs"
5348
5349 test_65l() { # bug 12836
5350         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5351         test_mkdir -p $DIR/$tdir/test_dir
5352         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5353         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5354 }
5355 run_test 65l "lfs find on -1 stripe dir ========================"
5356
5357 # bug 2543 - update blocks count on client
5358 test_66() {
5359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5360         COUNT=${COUNT:-8}
5361         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5362         sync; sync_all_data; sync; sync_all_data
5363         cancel_lru_locks osc
5364         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5365         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5366 }
5367 run_test 66 "update inode blocks count on client ==============="
5368
5369 LLOOP=
5370 LLITELOOPLOAD=
5371 cleanup_68() {
5372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5373         trap 0
5374         if [ ! -z "$LLOOP" ]; then
5375                 if swapon -s | grep -q $LLOOP; then
5376                         swapoff $LLOOP || error "swapoff failed"
5377                 fi
5378
5379                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5380                 rm -f $LLOOP
5381                 unset LLOOP
5382         fi
5383         if [ ! -z "$LLITELOOPLOAD" ]; then
5384                 rmmod llite_lloop
5385                 unset LLITELOOPLOAD
5386         fi
5387         rm -f $DIR/f68*
5388 }
5389
5390 meminfo() {
5391         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5392 }
5393
5394 swap_used() {
5395         swapon -s | awk '($1 == "'$1'") { print $4 }'
5396 }
5397
5398 # test case for lloop driver, basic function
5399 test_68a() {
5400         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5401         [ "$UID" != 0 ] && skip_env "must run as root" && return
5402         llite_lloop_enabled || \
5403                 { skip_env "llite_lloop module disabled" && return; }
5404
5405         trap cleanup_68 EXIT
5406
5407         if ! module_loaded llite_lloop; then
5408                 if load_module llite/llite_lloop; then
5409                         LLITELOOPLOAD=yes
5410                 else
5411                         skip_env "can't find module llite_lloop"
5412                         return
5413                 fi
5414         fi
5415
5416         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5417         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5418         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5419
5420         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5421         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5422
5423         cleanup_68
5424 }
5425 run_test 68a "lloop driver - basic test ========================"
5426
5427 # excercise swapping to lustre by adding a high priority swapfile entry
5428 # and then consuming memory until it is used.
5429 test_68b() {  # was test_68
5430         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5431         [ "$UID" != 0 ] && skip_env "must run as root" && return
5432         lctl get_param -n devices | grep -q obdfilter && \
5433                 skip "local OST" && return
5434
5435         grep -q llite_lloop /proc/modules
5436         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5437
5438         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5439                 skip "can't reliably test swap with TCP" && return
5440
5441         MEMTOTAL=`meminfo MemTotal`
5442         NR_BLOCKS=$((MEMTOTAL>>8))
5443         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5444
5445         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5446         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5447         mkswap $DIR/f68b
5448
5449         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5450
5451         trap cleanup_68 EXIT
5452
5453         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5454
5455         echo "before: `swapon -s | grep $LLOOP`"
5456         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5457         echo "after: `swapon -s | grep $LLOOP`"
5458         SWAPUSED=`swap_used $LLOOP`
5459
5460         cleanup_68
5461
5462         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5463 }
5464 run_test 68b "support swapping to Lustre ========================"
5465
5466 # bug5265, obdfilter oa2dentry return -ENOENT
5467 # #define OBD_FAIL_OST_ENOENT 0x217
5468 test_69() {
5469         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5470         remote_ost_nodsh && skip "remote OST with nodsh" && return
5471
5472         f="$DIR/$tfile"
5473         $SETSTRIPE -c 1 -i 0 $f
5474
5475         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5476
5477         do_facet ost1 lctl set_param fail_loc=0x217
5478         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5479         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5480
5481         do_facet ost1 lctl set_param fail_loc=0
5482         $DIRECTIO write $f 0 2 || error "write error"
5483
5484         cancel_lru_locks osc
5485         $DIRECTIO read $f 0 1 || error "read error"
5486
5487         do_facet ost1 lctl set_param fail_loc=0x217
5488         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5489
5490         do_facet ost1 lctl set_param fail_loc=0
5491         rm -f $f
5492 }
5493 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5494
5495 test_71() {
5496     test_mkdir -p $DIR/$tdir
5497     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5498 }
5499 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5500
5501 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5502         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5503         [ "$RUNAS_ID" = "$UID" ] &&
5504                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5505
5506         # Check that testing environment is properly set up. Skip if not
5507         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5508                 skip_env "User $RUNAS_ID does not exist - skipping"
5509                 return 0
5510         }
5511         touch $DIR/$tfile
5512         chmod 777 $DIR/$tfile
5513         chmod ug+s $DIR/$tfile
5514         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5515                 error "$RUNAS dd $DIR/$tfile failed"
5516         # See if we are still setuid/sgid
5517         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5518                 error "S/gid is not dropped on write"
5519         # Now test that MDS is updated too
5520         cancel_lru_locks mdc
5521         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5522                 error "S/gid is not dropped on MDS"
5523         rm -f $DIR/$tfile
5524 }
5525 run_test 72a "Test that remove suid works properly (bug5695) ===="
5526
5527 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5528         local perm
5529
5530         [ "$RUNAS_ID" = "$UID" ] && \
5531                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5532         [ "$RUNAS_ID" -eq 0 ] && \
5533                 skip_env "RUNAS_ID = 0 -- skipping" && return
5534
5535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5536         # Check that testing environment is properly set up. Skip if not
5537         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5538                 skip_env "User $RUNAS_ID does not exist - skipping"
5539                 return 0
5540         }
5541         touch $DIR/${tfile}-f{g,u}
5542         test_mkdir $DIR/${tfile}-dg
5543         test_mkdir $DIR/${tfile}-du
5544         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5545         chmod g+s $DIR/${tfile}-{f,d}g
5546         chmod u+s $DIR/${tfile}-{f,d}u
5547         for perm in 777 2777 4777; do
5548                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5549                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5550                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5551                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5552         done
5553         true
5554 }
5555 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5556
5557 # bug 3462 - multiple simultaneous MDC requests
5558 test_73() {
5559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5560         test_mkdir $DIR/d73-1
5561         test_mkdir $DIR/d73-2
5562         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5563         pid1=$!
5564
5565         lctl set_param fail_loc=0x80000129
5566         $MULTIOP $DIR/d73-1/f73-2 Oc &
5567         sleep 1
5568         lctl set_param fail_loc=0
5569
5570         $MULTIOP $DIR/d73-2/f73-3 Oc &
5571         pid3=$!
5572
5573         kill -USR1 $pid1
5574         wait $pid1 || return 1
5575
5576         sleep 25
5577
5578         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5579         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5580         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5581
5582         rm -rf $DIR/d73-*
5583 }
5584 run_test 73 "multiple MDC requests (should not deadlock)"
5585
5586 test_74a() { # bug 6149, 6184
5587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5588         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5589         #
5590         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5591         # will spin in a tight reconnection loop
5592         touch $DIR/f74a
5593         $LCTL set_param fail_loc=0x8000030e
5594         # get any lock that won't be difficult - lookup works.
5595         ls $DIR/f74a
5596         $LCTL set_param fail_loc=0
5597         rm -f $DIR/f74a
5598         true
5599 }
5600 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5601
5602 test_74b() { # bug 13310
5603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5604         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5605         #
5606         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5607         # will spin in a tight reconnection loop
5608         $LCTL set_param fail_loc=0x8000030e
5609         # get a "difficult" lock
5610         touch $DIR/f74b
5611         $LCTL set_param fail_loc=0
5612         rm -f $DIR/f74b
5613         true
5614 }
5615 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5616
5617 test_74c() {
5618         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5619         #define OBD_FAIL_LDLM_NEW_LOCK
5620         $LCTL set_param fail_loc=0x319
5621         touch $DIR/$tfile && error "touch successful"
5622         $LCTL set_param fail_loc=0
5623         true
5624 }
5625 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5626
5627 num_inodes() {
5628         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5629 }
5630
5631 get_inode_slab_tunables() {
5632         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5633 }
5634
5635 set_inode_slab_tunables() {
5636         echo "lustre_inode_cache $1" > /proc/slabinfo
5637 }
5638
5639 test_76() { # Now for bug 20433, added originally in bug 1443
5640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5641         local SLAB_SETTINGS=`get_inode_slab_tunables`
5642         local CPUS=`getconf _NPROCESSORS_ONLN`
5643         # we cannot set limit below 1 which means 1 inode in each
5644         # per-cpu cache is still allowed
5645         set_inode_slab_tunables "1 1 0"
5646         cancel_lru_locks osc
5647         BEFORE_INODES=$(num_inodes)
5648         echo "before inodes: $BEFORE_INODES"
5649         local COUNT=1000
5650         [ "$SLOW" = "no" ] && COUNT=100
5651         for i in $(seq $COUNT); do
5652                 touch $DIR/$tfile
5653                 rm -f $DIR/$tfile
5654         done
5655         cancel_lru_locks osc
5656         AFTER_INODES=$(num_inodes)
5657         echo "after inodes: $AFTER_INODES"
5658         local wait=0
5659         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5660                 sleep 2
5661                 AFTER_INODES=$(num_inodes)
5662                 wait=$((wait+2))
5663                 echo "wait $wait seconds inodes: $AFTER_INODES"
5664                 if [ $wait -gt 30 ]; then
5665                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5666                 fi
5667         done
5668         set_inode_slab_tunables "$SLAB_SETTINGS"
5669 }
5670 run_test 76 "confirm clients recycle inodes properly ===="
5671
5672
5673 export ORIG_CSUM=""
5674 set_checksums()
5675 {
5676         # Note: in sptlrpc modes which enable its own bulk checksum, the
5677         # original crc32_le bulk checksum will be automatically disabled,
5678         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5679         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5680         # In this case set_checksums() will not be no-op, because sptlrpc
5681         # bulk checksum will be enabled all through the test.
5682
5683         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5684         lctl set_param -n osc.*.checksums $1
5685         return 0
5686 }
5687
5688 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5689                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5690 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5691 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5692 set_checksum_type()
5693 {
5694         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5695         log "set checksum type to $1"
5696         return 0
5697 }
5698 F77_TMP=$TMP/f77-temp
5699 F77SZ=8
5700 setup_f77() {
5701         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5702                 error "error writing to $F77_TMP"
5703 }
5704
5705 test_77a() { # bug 10889
5706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5707         $GSS && skip "could not run with gss" && return
5708         [ ! -f $F77_TMP ] && setup_f77
5709         set_checksums 1
5710         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5711         set_checksums 0
5712         rm -f $DIR/$tfile
5713 }
5714 run_test 77a "normal checksum read/write operation"
5715
5716 test_77b() { # bug 10889
5717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5718         $GSS && skip "could not run with gss" && return
5719         [ ! -f $F77_TMP ] && setup_f77
5720         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5721         $LCTL set_param fail_loc=0x80000409
5722         set_checksums 1
5723
5724         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5725                 error "dd error: $?"
5726         $LCTL set_param fail_loc=0
5727
5728         for algo in $CKSUM_TYPES; do
5729                 cancel_lru_locks osc
5730                 set_checksum_type $algo
5731                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5732                 $LCTL set_param fail_loc=0x80000408
5733                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5734                 $LCTL set_param fail_loc=0
5735         done
5736         set_checksums 0
5737         set_checksum_type $ORIG_CSUM_TYPE
5738         rm -f $DIR/$tfile
5739 }
5740 run_test 77b "checksum error on client write, read"
5741
5742 test_77d() { # bug 10889
5743         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5744         $GSS && skip "could not run with gss" && return
5745         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5746         $LCTL set_param fail_loc=0x80000409
5747         set_checksums 1
5748         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5749                 error "direct write: rc=$?"
5750         $LCTL set_param fail_loc=0
5751         set_checksums 0
5752
5753         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5754         $LCTL set_param fail_loc=0x80000408
5755         set_checksums 1
5756         cancel_lru_locks osc
5757         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5758                 error "direct read: rc=$?"
5759         $LCTL set_param fail_loc=0
5760         set_checksums 0
5761 }
5762 run_test 77d "checksum error on OST direct write, read"
5763
5764 test_77f() { # bug 10889
5765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5766         $GSS && skip "could not run with gss" && return
5767         set_checksums 1
5768         for algo in $CKSUM_TYPES; do
5769                 cancel_lru_locks osc
5770                 set_checksum_type $algo
5771                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5772                 $LCTL set_param fail_loc=0x409
5773                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5774                         error "direct write succeeded"
5775                 $LCTL set_param fail_loc=0
5776         done
5777         set_checksum_type $ORIG_CSUM_TYPE
5778         set_checksums 0
5779 }
5780 run_test 77f "repeat checksum error on write (expect error)"
5781
5782 test_77g() { # bug 10889
5783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5784         $GSS && skip "could not run with gss" && return
5785         remote_ost_nodsh && skip "remote OST with nodsh" && return
5786
5787         [ ! -f $F77_TMP ] && setup_f77
5788
5789         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5790         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5791         do_facet ost1 lctl set_param fail_loc=0x8000021a
5792         set_checksums 1
5793         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5794                 error "write error: rc=$?"
5795         do_facet ost1 lctl set_param fail_loc=0
5796         set_checksums 0
5797
5798         cancel_lru_locks osc
5799         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5800         do_facet ost1 lctl set_param fail_loc=0x8000021b
5801         set_checksums 1
5802         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5803         do_facet ost1 lctl set_param fail_loc=0
5804         set_checksums 0
5805 }
5806 run_test 77g "checksum error on OST write, read"
5807
5808 test_77i() { # bug 13805
5809         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5810         $GSS && skip "could not run with gss" && return
5811         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5812         lctl set_param fail_loc=0x40b
5813         remount_client $MOUNT
5814         lctl set_param fail_loc=0
5815         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5816                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5817                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5818                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5819         done
5820         remount_client $MOUNT
5821 }
5822 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5823
5824 test_77j() { # bug 13805
5825         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5826         $GSS && skip "could not run with gss" && return
5827         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5828         lctl set_param fail_loc=0x40c
5829         remount_client $MOUNT
5830         lctl set_param fail_loc=0
5831         sleep 2 # wait async osc connect to finish
5832         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5833                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5834                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5835                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5836         done
5837         remount_client $MOUNT
5838 }
5839 run_test 77j "client only supporting ADLER32"
5840
5841 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5842 rm -f $F77_TMP
5843 unset F77_TMP
5844
5845 test_78() { # bug 10901
5846         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5847         remote_ost || { skip_env "local OST" && return; }
5848
5849         NSEQ=5
5850         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5851         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5852         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5853         echo "MemTotal: $MEMTOTAL"
5854
5855         # reserve 256MB of memory for the kernel and other running processes,
5856         # and then take 1/2 of the remaining memory for the read/write buffers.
5857         if [ $MEMTOTAL -gt 512 ] ;then
5858                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5859         else
5860                 # for those poor memory-starved high-end clusters...
5861                 MEMTOTAL=$((MEMTOTAL / 2))
5862         fi
5863         echo "Mem to use for directio: $MEMTOTAL"
5864
5865         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5866         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5867         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5868         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5869                 head -n1)
5870         echo "Smallest OST: $SMALLESTOST"
5871         [[ $SMALLESTOST -lt 10240 ]] &&
5872                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5873
5874         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5875                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5876
5877         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5878         echo "File size: $F78SIZE"
5879         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5880         for i in $(seq 1 $NSEQ); do
5881                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5882                 echo directIO rdwr round $i of $NSEQ
5883                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5884         done
5885
5886         rm -f $DIR/$tfile
5887 }
5888 run_test 78 "handle large O_DIRECT writes correctly ============"
5889
5890 test_79() { # bug 12743
5891         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5892         wait_delete_completed
5893
5894         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5895         BKFREE=$(calc_osc_kbytes kbytesfree)
5896         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5897
5898         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5899         DFTOTAL=`echo $STRING | cut -d, -f1`
5900         DFUSED=`echo $STRING  | cut -d, -f2`
5901         DFAVAIL=`echo $STRING | cut -d, -f3`
5902         DFFREE=$(($DFTOTAL - $DFUSED))
5903
5904         ALLOWANCE=$((64 * $OSTCOUNT))
5905
5906         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5907            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5908                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5909         fi
5910         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5911            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5912                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5913         fi
5914         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5915            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5916                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5917         fi
5918 }
5919 run_test 79 "df report consistency check ======================="
5920
5921 test_80() { # bug 10718
5922         remote_ost_nodsh && skip "remote OST with nodsh" && return
5923         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5924         # relax strong synchronous semantics for slow backends like ZFS
5925         local soc="obdfilter.*.sync_on_lock_cancel"
5926         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5927         local hosts=
5928         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5929                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5930                           facet_active_host $host; done | sort -u)
5931                 do_nodes $hosts lctl set_param $soc=never
5932         fi
5933
5934         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5935         sync; sleep 1; sync
5936         local BEFORE=`date +%s`
5937         cancel_lru_locks osc
5938         local AFTER=`date +%s`
5939         local DIFF=$((AFTER-BEFORE))
5940         if [ $DIFF -gt 1 ] ; then
5941                 error "elapsed for 1M@1T = $DIFF"
5942         fi
5943
5944         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5945
5946         rm -f $DIR/$tfile
5947 }
5948 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5949
5950 test_81a() { # LU-456
5951         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5952         remote_ost_nodsh && skip "remote OST with nodsh" && return
5953         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5954         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5955         do_facet ost1 lctl set_param fail_loc=0x80000228
5956
5957         # write should trigger a retry and success
5958         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5959         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5960         RC=$?
5961         if [ $RC -ne 0 ] ; then
5962                 error "write should success, but failed for $RC"
5963         fi
5964 }
5965 run_test 81a "OST should retry write when get -ENOSPC ==============="
5966
5967 test_81b() { # LU-456
5968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5969         remote_ost_nodsh && skip "remote OST with nodsh" && return
5970         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5971         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5972         do_facet ost1 lctl set_param fail_loc=0x228
5973
5974         # write should retry several times and return -ENOSPC finally
5975         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5976         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5977         RC=$?
5978         ENOSPC=28
5979         if [ $RC -ne $ENOSPC ] ; then
5980                 error "dd should fail for -ENOSPC, but succeed."
5981         fi
5982 }
5983 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5984
5985 test_82() { # LU-1031
5986         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5987         local gid1=14091995
5988         local gid2=16022000
5989
5990         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5991         local MULTIPID1=$!
5992         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5993         local MULTIPID2=$!
5994         kill -USR1 $MULTIPID2
5995         sleep 2
5996         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5997                 error "First grouplock does not block second one"
5998         else
5999                 echo "Second grouplock blocks first one"
6000         fi
6001         kill -USR1 $MULTIPID1
6002         wait $MULTIPID1
6003         wait $MULTIPID2
6004 }
6005 run_test 82 "Basic grouplock test ==============================="
6006
6007 test_99a() {
6008         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6009                 return
6010         test_mkdir -p $DIR/d99cvsroot
6011         chown $RUNAS_ID $DIR/d99cvsroot
6012         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6013         cd $TMP
6014
6015         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6016         cd $oldPWD
6017 }
6018 run_test 99a "cvs init ========================================="
6019
6020 test_99b() {
6021         [ -z "$(which cvs 2>/dev/null)" ] &&
6022                 skip_env "could not find cvs" && return
6023         [ ! -d $DIR/d99cvsroot ] && test_99a
6024         cd /etc/init.d
6025         # some versions of cvs import exit(1) when asked to import links or
6026         # files they can't read.  ignore those files.
6027         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6028                         ! -perm +4 -printf '-I %f\n')
6029         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6030                 d99reposname vtag rtag
6031 }
6032 run_test 99b "cvs import ======================================="
6033
6034 test_99c() {
6035         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6036         [ ! -d $DIR/d99cvsroot ] && test_99b
6037         cd $DIR
6038         test_mkdir -p $DIR/d99reposname
6039         chown $RUNAS_ID $DIR/d99reposname
6040         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6041 }
6042 run_test 99c "cvs checkout ====================================="
6043
6044 test_99d() {
6045         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6046         [ ! -d $DIR/d99cvsroot ] && test_99c
6047         cd $DIR/d99reposname
6048         $RUNAS touch foo99
6049         $RUNAS cvs add -m 'addmsg' foo99
6050 }
6051 run_test 99d "cvs add =========================================="
6052
6053 test_99e() {
6054         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6055         [ ! -d $DIR/d99cvsroot ] && test_99c
6056         cd $DIR/d99reposname
6057         $RUNAS cvs update
6058 }
6059 run_test 99e "cvs update ======================================="
6060
6061 test_99f() {
6062         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6063         [ ! -d $DIR/d99cvsroot ] && test_99d
6064         cd $DIR/d99reposname
6065         $RUNAS cvs commit -m 'nomsg' foo99
6066     rm -fr $DIR/d99cvsroot
6067 }
6068 run_test 99f "cvs commit ======================================="
6069
6070 test_100() {
6071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6072         [ "$NETTYPE" = tcp ] || \
6073                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6074                         return ; }
6075
6076         remote_ost_nodsh && skip "remote OST with nodsh" && return
6077         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6078         remote_servers || \
6079                 { skip "useless for local single node setup" && return; }
6080
6081         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6082                 [ "$PROT" != "tcp" ] && continue
6083                 RPORT=$(echo $REMOTE | cut -d: -f2)
6084                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6085
6086                 rc=0
6087                 LPORT=`echo $LOCAL | cut -d: -f2`
6088                 if [ $LPORT -ge 1024 ]; then
6089                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6090                         netstat -tna
6091                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6092                 fi
6093         done
6094         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6095 }
6096 run_test 100 "check local port using privileged port ==========="
6097
6098 function get_named_value()
6099 {
6100     local tag
6101
6102     tag=$1
6103     while read ;do
6104         line=$REPLY
6105         case $line in
6106         $tag*)
6107             echo $line | sed "s/^$tag[ ]*//"
6108             break
6109             ;;
6110         esac
6111     done
6112 }
6113
6114 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6115                    awk '/^max_cached_mb/ { print $2 }')
6116
6117 cleanup_101a() {
6118         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6119         trap 0
6120 }
6121
6122 test_101a() {
6123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6124         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6125         local s
6126         local discard
6127         local nreads=10000
6128         local cache_limit=32
6129
6130         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6131         trap cleanup_101a EXIT
6132         $LCTL set_param -n llite.*.read_ahead_stats 0
6133         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6134
6135         #
6136         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6137         #
6138         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6139         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6140
6141         discard=0
6142         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6143                 get_named_value 'read but discarded' | cut -d" " -f1); do
6144                         discard=$(($discard + $s))
6145         done
6146         cleanup_101a
6147
6148         if [[ $(($discard * 10)) -gt $nreads ]]; then
6149                 $LCTL get_param osc.*-osc*.rpc_stats
6150                 $LCTL get_param llite.*.read_ahead_stats
6151                 error "too many ($discard) discarded pages"
6152         fi
6153         rm -f $DIR/$tfile || true
6154 }
6155 run_test 101a "check read-ahead for random reads ================"
6156
6157 setup_test101bc() {
6158         test_mkdir -p $DIR/$tdir
6159         local STRIPE_SIZE=$1
6160         local FILE_LENGTH=$2
6161         STRIPE_OFFSET=0
6162
6163         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6164
6165         local list=$(comma_list $(osts_nodes))
6166         set_osd_param $list '' read_cache_enable 0
6167         set_osd_param $list '' writethrough_cache_enable 0
6168
6169         trap cleanup_test101bc EXIT
6170         # prepare the read-ahead file
6171         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6172
6173         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6174                                 count=$FILE_SIZE_MB 2> /dev/null
6175
6176 }
6177
6178 cleanup_test101bc() {
6179         trap 0
6180         rm -rf $DIR/$tdir
6181         rm -f $DIR/$tfile
6182
6183         local list=$(comma_list $(osts_nodes))
6184         set_osd_param $list '' read_cache_enable 1
6185         set_osd_param $list '' writethrough_cache_enable 1
6186 }
6187
6188 calc_total() {
6189         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6190 }
6191
6192 ra_check_101() {
6193         local READ_SIZE=$1
6194         local STRIPE_SIZE=$2
6195         local FILE_LENGTH=$3
6196         local RA_INC=1048576
6197         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6198         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6199                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6200         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6201                         get_named_value 'read but discarded' |
6202                         cut -d" " -f1 | calc_total)
6203         if [[ $DISCARD -gt $discard_limit ]]; then
6204                 $LCTL get_param llite.*.read_ahead_stats
6205                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6206         else
6207                 echo "Read-ahead success for size ${READ_SIZE}"
6208         fi
6209 }
6210
6211 test_101b() {
6212         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6213         [[ $OSTCOUNT -lt 2 ]] &&
6214                 skip_env "skipping stride IO stride-ahead test" && return
6215         local STRIPE_SIZE=1048576
6216         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6217         if [ $SLOW == "yes" ]; then
6218                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6219         else
6220                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6221         fi
6222
6223         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6224
6225         # prepare the read-ahead file
6226         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6227         cancel_lru_locks osc
6228         for BIDX in 2 4 8 16 32 64 128 256
6229         do
6230                 local BSIZE=$((BIDX*4096))
6231                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6232                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6233                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6234                 $LCTL set_param -n llite.*.read_ahead_stats 0
6235                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6236                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6237                 cancel_lru_locks osc
6238                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6239         done
6240         cleanup_test101bc
6241         true
6242 }
6243 run_test 101b "check stride-io mode read-ahead ================="
6244
6245 test_101c() {
6246         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6247         local STRIPE_SIZE=1048576
6248         local FILE_LENGTH=$((STRIPE_SIZE*100))
6249         local nreads=10000
6250         local osc_rpc_stats
6251
6252         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6253
6254         cancel_lru_locks osc
6255         $LCTL set_param osc.*.rpc_stats 0
6256         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6257         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6258                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6259                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6260                 local size
6261
6262                 if [ $lines -le 20 ]; then
6263                         continue
6264                 fi
6265                 for size in 1 2 4 8; do
6266                         local rpc=$(echo "$stats" |
6267                                     awk '($1 == "'$size':") {print $2; exit; }')
6268                         [ $rpc != 0 ] &&
6269                                 error "Small $((size*4))k read IO $rpc !"
6270                 done
6271                 echo "$osc_rpc_stats check passed!"
6272         done
6273         cleanup_test101bc
6274         true
6275 }
6276 run_test 101c "check stripe_size aligned read-ahead ================="
6277
6278 set_read_ahead() {
6279         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6280         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6281 }
6282
6283 test_101d() {
6284         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6285         local file=$DIR/$tfile
6286         local sz_MB=${FILESIZE_101d:-500}
6287         local ra_MB=${READAHEAD_MB:-40}
6288
6289         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6290         [ $free_MB -lt $sz_MB ] &&
6291                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6292
6293         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6294         $SETSTRIPE -c -1 $file || error "setstripe failed"
6295
6296         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6297         echo Cancel LRU locks on lustre client to flush the client cache
6298         cancel_lru_locks osc
6299
6300         echo Disable read-ahead
6301         local old_READAHEAD=$(set_read_ahead 0)
6302
6303         echo Reading the test file $file with read-ahead disabled
6304         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6305
6306         echo Cancel LRU locks on lustre client to flush the client cache
6307         cancel_lru_locks osc
6308         echo Enable read-ahead with ${ra_MB}MB
6309         set_read_ahead $ra_MB
6310
6311         echo Reading the test file $file with read-ahead enabled
6312         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6313
6314         echo "read-ahead disabled time read $raOFF"
6315         echo "read-ahead enabled  time read $raON"
6316
6317         set_read_ahead $old_READAHEAD
6318         rm -f $file
6319         wait_delete_completed
6320
6321         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6322                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6323 }
6324 run_test 101d "file read with and without read-ahead enabled"
6325
6326 test_101e() {
6327         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6328         local file=$DIR/$tfile
6329         local size_KB=500  #KB
6330         local count=100
6331         local bsize=1024
6332
6333         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6334         local need_KB=$((count * size_KB))
6335         [[ $free_KB -le $need_KB ]] &&
6336                 skip_env "Need free space $need_KB, have $free_KB" && return
6337
6338         echo "Creating $count ${size_KB}K test files"
6339         for ((i = 0; i < $count; i++)); do
6340                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6341         done
6342
6343         echo "Cancel LRU locks on lustre client to flush the client cache"
6344         cancel_lru_locks osc
6345
6346         echo "Reset readahead stats"
6347         $LCTL set_param -n llite.*.read_ahead_stats 0
6348
6349         for ((i = 0; i < $count; i++)); do
6350                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6351         done
6352
6353         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6354                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6355
6356         for ((i = 0; i < $count; i++)); do
6357                 rm -rf $file.$i 2>/dev/null
6358         done
6359
6360         #10000 means 20% reads are missing in readahead
6361         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6362 }
6363 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6364
6365 cleanup_test101f() {
6366     trap 0
6367     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6368     rm -rf $DIR/$tfile 2>/dev/null
6369 }
6370
6371 test_101f() {
6372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6373     local file=$DIR/$tfile
6374     local nreads=1000
6375
6376     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6377     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6378     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6379     trap cleanup_test101f EXIT
6380
6381     echo Cancel LRU locks on lustre client to flush the client cache
6382     cancel_lru_locks osc
6383
6384     echo Reset readahead stats
6385     $LCTL set_param -n llite.*.read_ahead_stats 0
6386     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6387     # readahead should read in 2M file on second read, so only miss
6388     # 2 pages.
6389     echo Random 4K reads on 2M file for 1000 times
6390     $READS -f $file -s 2097152 -b 4096 -n $nreads
6391
6392     echo checking missing pages
6393     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6394           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6395
6396     [ $miss -lt 3 ] || error "misses too much pages!"
6397     cleanup_test101f
6398 }
6399 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6400
6401 setup_test102() {
6402         test_mkdir -p $DIR/$tdir
6403         chown $RUNAS_ID $DIR/$tdir
6404         STRIPE_SIZE=65536
6405         STRIPE_OFFSET=1
6406         STRIPE_COUNT=$OSTCOUNT
6407         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6408
6409         trap cleanup_test102 EXIT
6410         cd $DIR
6411         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6412         cd $DIR/$tdir
6413         for num in 1 2 3 4; do
6414                 for count in $(seq 1 $STRIPE_COUNT); do
6415                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6416                                 local size=`expr $STRIPE_SIZE \* $num`
6417                                 local file=file"$num-$idx-$count"
6418                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6419                         done
6420                 done
6421         done
6422
6423         cd $DIR
6424         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6425 }
6426
6427 cleanup_test102() {
6428         trap 0
6429         rm -f $TMP/f102.tar
6430         rm -rf $DIR/d0.sanity/d102
6431 }
6432
6433 test_102a() {
6434         local testfile=$DIR/$tfile
6435
6436         touch $testfile
6437
6438         [ "$UID" != 0 ] && skip_env "must run as root" && return
6439         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6440                 skip_env "must have user_xattr" && return
6441
6442         [ -z "$(which setfattr 2>/dev/null)" ] &&
6443                 skip_env "could not find setfattr" && return
6444
6445         echo "set/get xattr..."
6446         setfattr -n trusted.name1 -v value1 $testfile ||
6447                 error "setfattr -n trusted.name1=value1 $testfile failed"
6448         getfattr -n trusted.name1 $testfile 2> /dev/null |
6449           grep "trusted.name1=.value1" ||
6450                 error "$testfile missing trusted.name1=value1"
6451
6452         setfattr -n user.author1 -v author1 $testfile ||
6453                 error "setfattr -n user.author1=author1 $testfile failed"
6454         getfattr -n user.author1 $testfile 2> /dev/null |
6455           grep "user.author1=.author1" ||
6456                 error "$testfile missing trusted.author1=author1"
6457
6458         echo "listxattr..."
6459         setfattr -n trusted.name2 -v value2 $testfile ||
6460                 error "$testfile unable to set trusted.name2"
6461         setfattr -n trusted.name3 -v value3 $testfile ||
6462                 error "$testfile unable to set trusted.name3"
6463         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6464             grep "trusted.name" | wc -l) -eq 3 ] ||
6465                 error "$testfile missing 3 trusted.name xattrs"
6466
6467         setfattr -n user.author2 -v author2 $testfile ||
6468                 error "$testfile unable to set user.author2"
6469         setfattr -n user.author3 -v author3 $testfile ||
6470                 error "$testfile unable to set user.author3"
6471         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6472             grep "user.author" | wc -l) -eq 3 ] ||
6473                 error "$testfile missing 3 user.author xattrs"
6474
6475         echo "remove xattr..."
6476         setfattr -x trusted.name1 $testfile ||
6477                 error "$testfile error deleting trusted.name1"
6478         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6479                 error "$testfile did not delete trusted.name1 xattr"
6480
6481         setfattr -x user.author1 $testfile ||
6482                 error "$testfile error deleting user.author1"
6483         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6484                 error "$testfile did not delete trusted.name1 xattr"
6485
6486         # b10667: setting lustre special xattr be silently discarded
6487         echo "set lustre special xattr ..."
6488         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6489                 error "$testfile allowed setting trusted.lov"
6490 }
6491 run_test 102a "user xattr test =================================="
6492
6493 test_102b() {
6494         [ -z "$(which setfattr 2>/dev/null)" ] &&
6495                 skip_env "could not find setfattr" && return
6496
6497         # b10930: get/set/list trusted.lov xattr
6498         echo "get/set/list trusted.lov xattr ..."
6499         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6500         local testfile=$DIR/$tfile
6501         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6502                 error "setstripe failed"
6503         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6504                 error "getstripe failed"
6505         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6506                 error "can't get trusted.lov from $testfile"
6507
6508         local testfile2=${testfile}2
6509         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6510                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6511
6512         $MCREATE $testfile2
6513         setfattr -n trusted.lov -v $value $testfile2
6514         local stripe_size=$($GETSTRIPE -S $testfile2)
6515         local stripe_count=$($GETSTRIPE -c $testfile2)
6516         [[ $stripe_size -eq 65536 ]] ||
6517                 error "stripe size $stripe_size != 65536"
6518         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6519                 error "stripe count $stripe_count != $STRIPECOUNT"
6520         rm -f $DIR/$tfile
6521 }
6522 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6523
6524 test_102c() {
6525         [ -z "$(which setfattr 2>/dev/null)" ] &&
6526                 skip_env "could not find setfattr" && return
6527
6528         # b10930: get/set/list lustre.lov xattr
6529         echo "get/set/list lustre.lov xattr ..."
6530         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6531         test_mkdir -p $DIR/$tdir
6532         chown $RUNAS_ID $DIR/$tdir
6533         local testfile=$DIR/$tdir/$tfile
6534         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6535                 error "setstripe failed"
6536         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6537                 error "getstripe failed"
6538         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6539         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6540
6541         local testfile2=${testfile}2
6542         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6543                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6544
6545         $RUNAS $MCREATE $testfile2
6546         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6547         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6548         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6549         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6550         [ $stripe_count -eq $STRIPECOUNT ] ||
6551                 error "stripe count $stripe_count != $STRIPECOUNT"
6552 }
6553 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6554
6555 compare_stripe_info1() {
6556         local stripe_index_all_zero=true
6557
6558         for num in 1 2 3 4; do
6559                 for count in $(seq 1 $STRIPE_COUNT); do
6560                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6561                                 local size=$((STRIPE_SIZE * num))
6562                                 local file=file"$num-$offset-$count"
6563                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6564                                 [[ $stripe_size -ne $size ]] &&
6565                                     error "$file: size $stripe_size != $size"
6566                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6567                                 # allow fewer stripes to be created, ORI-601
6568                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6569                                     error "$file: count $stripe_count != $count"
6570                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6571                                 [[ $stripe_index -ne 0 ]] &&
6572                                         stripe_index_all_zero=false
6573                         done
6574                 done
6575         done
6576         $stripe_index_all_zero &&
6577                 error "all files are being extracted starting from OST index 0"
6578         return 0
6579 }
6580
6581 find_lustre_tar() {
6582         [ -n "$(which tar 2>/dev/null)" ] &&
6583                 strings $(which tar) | grep -q "lustre" && echo tar
6584 }
6585
6586 test_102d() {
6587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6588         # b10930: tar test for trusted.lov xattr
6589         TAR=$(find_lustre_tar)
6590         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6591         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6592         setup_test102
6593         test_mkdir -p $DIR/d102d
6594         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6595         cd $DIR/d102d/$tdir
6596         compare_stripe_info1
6597 }
6598 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6599
6600 test_102f() {
6601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6602         # b10930: tar test for trusted.lov xattr
6603         TAR=$(find_lustre_tar)
6604         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6605         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6606         setup_test102
6607         test_mkdir -p $DIR/d102f
6608         cd $DIR
6609         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6610         cd $DIR/d102f/$tdir
6611         compare_stripe_info1
6612 }
6613 run_test 102f "tar copy files, not keep osts ==========="
6614
6615 grow_xattr() {
6616         local xsize=${1:-1024}  # in bytes
6617         local file=$DIR/$tfile
6618
6619         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6620                 skip "must have user_xattr" && return 0
6621         [ -z "$(which setfattr 2>/dev/null)" ] &&
6622                 skip_env "could not find setfattr" && return 0
6623         [ -z "$(which getfattr 2>/dev/null)" ] &&
6624                 skip_env "could not find getfattr" && return 0
6625
6626         touch $file
6627
6628         local value="$(generate_string $xsize)"
6629
6630         local xbig=trusted.big
6631         log "save $xbig on $file"
6632         setfattr -n $xbig -v $value $file ||
6633                 error "saving $xbig on $file failed"
6634
6635         local orig=$(get_xattr_value $xbig $file)
6636         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6637
6638         local xsml=trusted.sml
6639         log "save $xsml on $file"
6640         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6641
6642         local new=$(get_xattr_value $xbig $file)
6643         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6644
6645         log "grow $xsml on $file"
6646         setfattr -n $xsml -v "$value" $file ||
6647                 error "growing $xsml on $file failed"
6648
6649         new=$(get_xattr_value $xbig $file)
6650         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6651         log "$xbig still valid after growing $xsml"
6652
6653         rm -f $file
6654 }
6655
6656 test_102h() { # bug 15777
6657         grow_xattr 1024
6658 }
6659 run_test 102h "grow xattr from inside inode to external block"
6660
6661 test_102ha() {
6662         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6663         grow_xattr $(max_xattr_size)
6664 }
6665 run_test 102ha "grow xattr from inside inode to external inode"
6666
6667 test_102i() { # bug 17038
6668         [ -z "$(which getfattr 2>/dev/null)" ] &&
6669                 skip "could not find getfattr" && return
6670         touch $DIR/$tfile
6671         ln -s $DIR/$tfile $DIR/${tfile}link
6672         getfattr -n trusted.lov $DIR/$tfile ||
6673                 error "lgetxattr on $DIR/$tfile failed"
6674         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6675                 grep -i "no such attr" ||
6676                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6677         rm -f $DIR/$tfile $DIR/${tfile}link
6678 }
6679 run_test 102i "lgetxattr test on symbolic link ============"
6680
6681 test_102j() {
6682         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6683         TAR=$(find_lustre_tar)
6684         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6685         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6686         setup_test102 "$RUNAS"
6687         test_mkdir -p $DIR/d102j
6688         chown $RUNAS_ID $DIR/d102j
6689         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6690         cd $DIR/d102j/$tdir
6691         compare_stripe_info1 "$RUNAS"
6692 }
6693 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6694
6695 test_102k() {
6696         [ -z "$(which setfattr 2>/dev/null)" ] &&
6697                 skip "could not find setfattr" && return
6698         touch $DIR/$tfile
6699         # b22187 just check that does not crash for regular file.
6700         setfattr -n trusted.lov $DIR/$tfile
6701         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6702         local test_kdir=$DIR/d102k
6703         test_mkdir $test_kdir
6704         local default_size=`$GETSTRIPE -S $test_kdir`
6705         local default_count=`$GETSTRIPE -c $test_kdir`
6706         local default_offset=`$GETSTRIPE -i $test_kdir`
6707         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6708                 error 'dir setstripe failed'
6709         setfattr -n trusted.lov $test_kdir
6710         local stripe_size=`$GETSTRIPE -S $test_kdir`
6711         local stripe_count=`$GETSTRIPE -c $test_kdir`
6712         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6713         [ $stripe_size -eq $default_size ] ||
6714                 error "stripe size $stripe_size != $default_size"
6715         [ $stripe_count -eq $default_count ] ||
6716                 error "stripe count $stripe_count != $default_count"
6717         [ $stripe_offset -eq $default_offset ] ||
6718                 error "stripe offset $stripe_offset != $default_offset"
6719         rm -rf $DIR/$tfile $test_kdir
6720 }
6721 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6722
6723 test_102l() {
6724         [ -z "$(which getfattr 2>/dev/null)" ] &&
6725                 skip "could not find getfattr" && return
6726
6727         # LU-532 trusted. xattr is invisible to non-root
6728         local testfile=$DIR/$tfile
6729
6730         touch $testfile
6731
6732         echo "listxattr as user..."
6733         chown $RUNAS_ID $testfile
6734         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6735             grep -q "trusted" &&
6736                 error "$testfile trusted xattrs are user visible"
6737
6738         return 0;
6739 }
6740 run_test 102l "listxattr size test =================================="
6741
6742 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6743         local path=$DIR/$tfile
6744         touch $path
6745
6746         listxattr_size_check $path || error "listattr_size_check $path failed"
6747 }
6748 run_test 102m "Ensure listxattr fails on small bufffer ========"
6749
6750 cleanup_test102
6751
6752 getxattr() { # getxattr path name
6753         # Return the base64 encoding of the value of xattr name on path.
6754         local path=$1
6755         local name=$2
6756
6757         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6758         # file: $path
6759         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6760         #
6761         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6762
6763         getfattr --absolute-names --encoding=base64 --name=$name $path |
6764                 awk -F= -v name=$name '$1 == name {
6765                         print substr($0, index($0, "=") + 1);
6766         }'
6767 }
6768
6769 test_102n() { # LU-4101 mdt: protect internal xattrs
6770         local file0=$DIR/$tfile.0
6771         local file1=$DIR/$tfile.1
6772         local xattr0=$TMP/$tfile.0
6773         local xattr1=$TMP/$tfile.1
6774         local name
6775         local value
6776
6777         [ -z "$(which setfattr 2>/dev/null)" ] &&
6778                 skip "could not find setfattr" && return
6779
6780         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6781         then
6782                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6783                 return
6784         fi
6785
6786         rm -rf $file0 $file1 $xattr0 $xattr1
6787         touch $file0 $file1
6788
6789         # Get 'before' xattrs of $file1.
6790         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6791
6792         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6793                 # Try to copy xattr from $file0 to $file1.
6794                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6795
6796                 setfattr --name=trusted.$name --value="$value" $file1 ||
6797                         error "setxattr 'trusted.$name' failed"
6798
6799                 # Try to set a garbage xattr.
6800                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6801
6802                 setfattr --name=trusted.$name --value="$value" $file1 ||
6803                         error "setxattr 'trusted.$name' failed"
6804
6805                 # Try to remove the xattr from $file1. We don't care if this
6806                 # appears to succeed or fail, we just don't want there to be
6807                 # any changes or crashes.
6808                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6809         done
6810
6811         # Get 'after' xattrs of file1.
6812         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6813
6814         if ! diff $xattr0 $xattr1; then
6815                 error "before and after xattrs of '$file1' differ"
6816         fi
6817
6818         rm -rf $file0 $file1 $xattr0 $xattr1
6819
6820         return 0
6821 }
6822 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6823
6824 test_102p() { # LU-4703 setxattr did not check ownership
6825         local testfile=$DIR/$tfile
6826
6827         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6828                 skip "MDS needs to be at least 2.5.56" && return
6829
6830         touch $testfile
6831
6832         echo "setfacl as user..."
6833         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6834         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6835
6836         echo "setfattr as user..."
6837         setfacl -m "u:$RUNAS_ID:---" $testfile
6838         $RUNAS setfattr -x system.posix_acl_access $testfile
6839         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6840 }
6841 run_test 102p "check setxattr(2) correctly fails without permission"
6842
6843 run_acl_subtest()
6844 {
6845     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6846     return $?
6847 }
6848
6849 test_103a() {
6850         [ "$UID" != 0 ] && skip_env "must run as root" && return
6851         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6852                 skip "must have acl enabled" && return
6853         [ -z "$(which setfacl 2>/dev/null)" ] &&
6854                 skip_env "could not find setfacl" && return
6855         $GSS && skip "could not run under gss" && return
6856
6857         declare -a identity_old
6858
6859         for num in $(seq $MDSCOUNT); do
6860                 switch_identity $num true || identity_old[$num]=$?
6861         done
6862
6863         SAVE_UMASK=$(umask)
6864         umask 0022
6865         cd $DIR
6866
6867         echo "performing cp ..."
6868         run_acl_subtest cp || error "run_acl_subtest cp failed"
6869         echo "performing getfacl-noacl..."
6870         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6871         echo "performing misc..."
6872         run_acl_subtest misc || error  "misc test failed"
6873         echo "performing permissions..."
6874         run_acl_subtest permissions || error "permissions failed"
6875         echo "performing setfacl..."
6876         run_acl_subtest setfacl || error  "setfacl test failed"
6877
6878         # inheritance test got from HP
6879         echo "performing inheritance..."
6880         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6881         chmod +x make-tree || error "chmod +x failed"
6882         run_acl_subtest inheritance || error "inheritance test failed"
6883         rm -f make-tree
6884
6885         echo "LU-974 ignore umask when acl is enabled..."
6886         run_acl_subtest 974 || error "LU-974 umask test failed"
6887         if [ $MDSCOUNT -ge 2 ]; then
6888                 run_acl_subtest 974_remote ||
6889                         error "LU-974 umask test failed under remote dir"
6890         fi
6891
6892         echo "LU-2561 newly created file is same size as directory..."
6893         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6894                 run_acl_subtest 2561 || error "LU-2561 test failed"
6895         else
6896                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6897         fi
6898
6899         run_acl_subtest 4924 || error "LU-4924 test failed"
6900
6901         cd $SAVE_PWD
6902         umask $SAVE_UMASK
6903
6904         for num in $(seq $MDSCOUNT); do
6905                 if [ "${identity_old[$num]}" = 1 ]; then
6906                         switch_identity $num false || identity_old[$num]=$?
6907                 fi
6908         done
6909 }
6910 run_test 103a "acl test ========================================="
6911
6912 test_103b() {
6913         local noacl=false
6914         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
6915         local mountopts=$MDS_MOUNT_OPTS
6916
6917         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
6918                 noacl=true
6919         else
6920                 # stop the MDT
6921                 stop $SINGLEMDS || error "failed to stop MDT."
6922                 # remount the MDT
6923                 if [ -z "$MDS_MOUNT_OPTS" ]; then
6924                         MDS_MOUNT_OPTS="-o noacl"
6925                 else
6926                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
6927                 fi
6928                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6929                         error "failed to start MDT."
6930                 MDS_MOUNT_OPTS=$mountopts
6931         fi
6932
6933         touch $DIR/$tfile
6934         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
6935
6936         if ! $noacl; then
6937                 # stop the MDT
6938                 stop $SINGLEMDS || error "failed to stop MDT."
6939                 # remount the MDT
6940                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6941                         error "failed to start MDT."
6942         fi
6943
6944         true
6945 }
6946 run_test 103b "MDS mount option 'noacl'"
6947
6948 test_103c() {
6949         mkdir -p $DIR/$tdir
6950         cp -rp $DIR/$tdir $DIR/$tdir.bak
6951
6952         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
6953                 error "$DIR/$tdir shouldn't contain default ACL"
6954         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
6955                 error "$DIR/$tdir.bak shouldn't contain default ACL"
6956         true
6957 }
6958 run_test 103c "'cp -rp' won't set empty acl"
6959
6960 test_104a() {
6961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6962         touch $DIR/$tfile
6963         lfs df || error "lfs df failed"
6964         lfs df -ih || error "lfs df -ih failed"
6965         lfs df -h $DIR || error "lfs df -h $DIR failed"
6966         lfs df -i $DIR || error "lfs df -i $DIR failed"
6967         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6968         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6969
6970         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6971         lctl --device %$OSC deactivate
6972         lfs df || error "lfs df with deactivated OSC failed"
6973         lctl --device %$OSC activate
6974         # wait the osc back to normal
6975         wait_osc_import_state client ost FULL
6976
6977         lfs df || error "lfs df with reactivated OSC failed"
6978         rm -f $DIR/$tfile
6979 }
6980 run_test 104a "lfs df [-ih] [path] test ========================="
6981
6982 test_104b() {
6983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6984         [ $RUNAS_ID -eq $UID ] &&
6985                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6986         chmod 666 /dev/obd
6987         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6988                         grep "Permission denied" | wc -l)))
6989         if [ $denied_cnt -ne 0 ]; then
6990                 error "lfs check servers test failed"
6991         fi
6992 }
6993 run_test 104b "$RUNAS lfs check servers test ===================="
6994
6995 test_105a() {
6996         # doesn't work on 2.4 kernels
6997         touch $DIR/$tfile
6998         if $(flock_is_enabled); then
6999                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7000         else
7001                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7002         fi
7003         rm -f $DIR/$tfile
7004 }
7005 run_test 105a "flock when mounted without -o flock test ========"
7006
7007 test_105b() {
7008         touch $DIR/$tfile
7009         if $(flock_is_enabled); then
7010                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7011         else
7012                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7013         fi
7014         rm -f $DIR/$tfile
7015 }
7016 run_test 105b "fcntl when mounted without -o flock test ========"
7017
7018 test_105c() {
7019         touch $DIR/$tfile
7020         if $(flock_is_enabled); then
7021                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7022         else
7023                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7024         fi
7025         rm -f $DIR/$tfile
7026 }
7027 run_test 105c "lockf when mounted without -o flock test ========"
7028
7029 test_105d() { # bug 15924
7030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7031         test_mkdir -p $DIR/$tdir
7032         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7033         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7034         $LCTL set_param fail_loc=0x80000315
7035         flocks_test 2 $DIR/$tdir
7036 }
7037 run_test 105d "flock race (should not freeze) ========"
7038
7039 test_105e() { # bug 22660 && 22040
7040         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7041         touch $DIR/$tfile
7042         flocks_test 3 $DIR/$tfile
7043 }
7044 run_test 105e "Two conflicting flocks from same process ======="
7045
7046 test_106() { #bug 10921
7047         test_mkdir -p $DIR/$tdir
7048         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7049         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7050 }
7051 run_test 106 "attempt exec of dir followed by chown of that dir"
7052
7053 test_107() {
7054         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7055         CDIR=`pwd`
7056         cd $DIR
7057
7058         local file=core
7059         rm -f $file
7060
7061         local save_pattern=$(sysctl -n kernel.core_pattern)
7062         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7063         sysctl -w kernel.core_pattern=$file
7064         sysctl -w kernel.core_uses_pid=0
7065
7066         ulimit -c unlimited
7067         sleep 60 &
7068         SLEEPPID=$!
7069
7070         sleep 1
7071
7072         kill -s 11 $SLEEPPID
7073         wait $SLEEPPID
7074         if [ -e $file ]; then
7075                 size=`stat -c%s $file`
7076                 [ $size -eq 0 ] && error "Fail to create core file $file"
7077         else
7078                 error "Fail to create core file $file"
7079         fi
7080         rm -f $file
7081         sysctl -w kernel.core_pattern=$save_pattern
7082         sysctl -w kernel.core_uses_pid=$save_uses_pid
7083         cd $CDIR
7084 }
7085 run_test 107 "Coredump on SIG"
7086
7087 test_110() {
7088         test_mkdir -p $DIR/$tdir
7089         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7090                 error "mkdir with 255 char failed"
7091         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7092                 error "mkdir with 256 char should fail, but did not"
7093         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7094                 error "create with 255 char failed"
7095         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7096                 error "create with 256 char should fail, but did not"
7097
7098         ls -l $DIR/$tdir
7099         rm -rf $DIR/$tdir
7100 }
7101 run_test 110 "filename length checking"
7102
7103 test_115() {
7104         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7105         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7106                 tail -1 | cut -c11-20)
7107         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7108         echo "Starting with $OSTIO_pre threads"
7109
7110         NUMTEST=20000
7111         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7112         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7113         echo "$NUMTEST creates/unlinks"
7114         test_mkdir -p $DIR/$tdir
7115         createmany -o $DIR/$tdir/$tfile $NUMTEST
7116         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7117
7118         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7119                 tail -1 | cut -c11-20)
7120
7121         # don't return an error
7122         [ $OSTIO_post == $OSTIO_pre ] && echo \
7123             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7124             echo "This may be fine, depending on what ran before this test" &&
7125             echo "and how fast this system is." && return
7126
7127         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7128 }
7129 run_test 115 "verify dynamic thread creation===================="
7130
7131 free_min_max () {
7132         wait_delete_completed
7133         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7134         echo OST kbytes available: ${AVAIL[@]}
7135         MAXI=0; MAXV=${AVAIL[0]}
7136         MINI=0; MINV=${AVAIL[0]}
7137         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7138                 #echo OST $i: ${AVAIL[i]}kb
7139                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7140                         MAXV=${AVAIL[i]}; MAXI=$i
7141                 fi
7142                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7143                         MINV=${AVAIL[i]}; MINI=$i
7144                 fi
7145         done
7146         echo Min free space: OST $MINI: $MINV
7147         echo Max free space: OST $MAXI: $MAXV
7148 }
7149
7150 test_116a() { # was previously test_116()
7151         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7152         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7153
7154         echo -n "Free space priority "
7155         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7156                 head -n1
7157         declare -a AVAIL
7158         free_min_max
7159
7160         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7161         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7162                 && return
7163         trap simple_cleanup_common EXIT
7164
7165
7166         # Check if we need to generate uneven OSTs
7167         test_mkdir -p $DIR/$tdir/OST${MINI}
7168         local FILL=$(($MINV / 4))
7169         local DIFF=$(($MAXV - $MINV))
7170         local DIFF2=$(($DIFF * 100 / $MINV))
7171
7172         local threshold=$(do_facet $SINGLEMDS \
7173                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7174         threshold=${threshold%%%}
7175         echo -n "Check for uneven OSTs: "
7176         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7177
7178         if [[ $DIFF2 -gt $threshold ]]; then
7179                 echo "ok"
7180                 echo "Don't need to fill OST$MINI"
7181         else
7182                 # generate uneven OSTs. Write 2% over the QOS threshold value
7183                 echo "no"
7184                 DIFF=$(($threshold - $DIFF2 + 2))
7185                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7186                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7187                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7188                         error "setstripe failed"
7189                 DIFF=$(($DIFF2 / 2048))
7190                 i=0
7191                 while [ $i -lt $DIFF ]; do
7192                         i=$(($i + 1))
7193                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7194                                 bs=2M count=1 2>/dev/null
7195                         echo -n .
7196                 done
7197                 echo .
7198                 sync
7199                 sleep_maxage
7200                 free_min_max
7201         fi
7202
7203         DIFF=$(($MAXV - $MINV))
7204         DIFF2=$(($DIFF * 100 / $MINV))
7205         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7206         if [[ $DIFF2 -gt $threshold ]]; then
7207                 echo "ok"
7208         else
7209                 echo "failed - QOS mode won't be used"
7210                 skip "QOS imbalance criteria not met"
7211                 simple_cleanup_common
7212                 return
7213         fi
7214
7215         MINI1=$MINI; MINV1=$MINV
7216         MAXI1=$MAXI; MAXV1=$MAXV
7217
7218         # now fill using QOS
7219         $SETSTRIPE -c 1 $DIR/$tdir
7220         FILL=$(($FILL / 200))
7221         if [ $FILL -gt 600 ]; then
7222                 FILL=600
7223         fi
7224         echo "writing $FILL files to QOS-assigned OSTs"
7225         i=0
7226         while [ $i -lt $FILL ]; do
7227                 i=$((i + 1))
7228                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7229                         count=1 2>/dev/null
7230                 echo -n .
7231         done
7232         echo "wrote $i 200k files"
7233         sync
7234         sleep_maxage
7235
7236         echo "Note: free space may not be updated, so measurements might be off"
7237         free_min_max
7238         DIFF2=$(($MAXV - $MINV))
7239         echo "free space delta: orig $DIFF final $DIFF2"
7240         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7241         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7242         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7243         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7244         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7245         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7246         [ $DIFF -gt 0 ] &&
7247                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7248
7249         # Figure out which files were written where
7250         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7251                   awk '/'$MINI1': / {print $2; exit}')
7252         echo $UUID
7253         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7254         echo "$MINC files created on smaller OST $MINI1"
7255         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7256                   awk '/'$MAXI1': / {print $2; exit}')
7257         echo $UUID
7258         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7259         echo "$MAXC files created on larger OST $MAXI1"
7260         FILL=$(($MAXC * 100 / $MINC - 100))
7261         [[ $MINC -gt 0 ]] &&
7262                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7263         [[ $MAXC -gt $MINC ]] ||
7264                 error_ignore LU-9 "stripe QOS didn't balance free space"
7265         simple_cleanup_common
7266 }
7267 run_test 116a "stripe QOS: free space balance ==================="
7268
7269 test_116b() { # LU-2093
7270         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7271         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7272                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7273 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7274         local old_rr
7275         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7276                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7277         do_facet $SINGLEMDS lctl set_param \
7278                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7279         mkdir -p $DIR/$tdir
7280         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7281         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7282         do_facet $SINGLEMDS lctl set_param fail_loc=0
7283         rm -rf $DIR/$tdir
7284         do_facet $SINGLEMDS lctl set_param \
7285                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7286 }
7287 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7288
7289 test_117() # bug 10891
7290 {
7291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7292         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7293         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7294         lctl set_param fail_loc=0x21e
7295         > $DIR/$tfile || error "truncate failed"
7296         lctl set_param fail_loc=0
7297         echo "Truncate succeeded."
7298         rm -f $DIR/$tfile
7299 }
7300 run_test 117 "verify osd extend =========="
7301
7302 NO_SLOW_RESENDCOUNT=4
7303 export OLD_RESENDCOUNT=""
7304 set_resend_count () {
7305         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7306         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7307         lctl set_param -n $PROC_RESENDCOUNT $1
7308         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7309 }
7310
7311 # for reduce test_118* time (b=14842)
7312 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7313
7314 # Reset async IO behavior after error case
7315 reset_async() {
7316         FILE=$DIR/reset_async
7317
7318         # Ensure all OSCs are cleared
7319         $SETSTRIPE -c -1 $FILE
7320         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7321         sync
7322         rm $FILE
7323 }
7324
7325 test_118a() #bug 11710
7326 {
7327         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7328         reset_async
7329
7330         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7331         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7332         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7333
7334         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7335                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7336                 return 1;
7337         fi
7338         rm -f $DIR/$tfile
7339 }
7340 run_test 118a "verify O_SYNC works =========="
7341
7342 test_118b()
7343 {
7344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7345         remote_ost_nodsh && skip "remote OST with nodsh" && return
7346
7347         reset_async
7348
7349         #define OBD_FAIL_OST_ENOENT 0x217
7350         set_nodes_failloc "$(osts_nodes)" 0x217
7351         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7352         RC=$?
7353         set_nodes_failloc "$(osts_nodes)" 0
7354         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7355         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7356                     grep -c writeback)
7357
7358         if [[ $RC -eq 0 ]]; then
7359                 error "Must return error due to dropped pages, rc=$RC"
7360                 return 1;
7361         fi
7362
7363         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7364                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7365                 return 1;
7366         fi
7367
7368         echo "Dirty pages not leaked on ENOENT"
7369
7370         # Due to the above error the OSC will issue all RPCs syncronously
7371         # until a subsequent RPC completes successfully without error.
7372         $MULTIOP $DIR/$tfile Ow4096yc
7373         rm -f $DIR/$tfile
7374
7375         return 0
7376 }
7377 run_test 118b "Reclaim dirty pages on fatal error =========="
7378
7379 test_118c()
7380 {
7381         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7382
7383         # for 118c, restore the original resend count, LU-1940
7384         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7385                                 set_resend_count $OLD_RESENDCOUNT
7386         remote_ost_nodsh && skip "remote OST with nodsh" && return
7387
7388         reset_async
7389
7390         #define OBD_FAIL_OST_EROFS               0x216
7391         set_nodes_failloc "$(osts_nodes)" 0x216
7392
7393         # multiop should block due to fsync until pages are written
7394         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7395         MULTIPID=$!
7396         sleep 1
7397
7398         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7399                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7400         fi
7401
7402         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7403                     grep -c writeback)
7404         if [[ $WRITEBACK -eq 0 ]]; then
7405                 error "No page in writeback, writeback=$WRITEBACK"
7406         fi
7407
7408         set_nodes_failloc "$(osts_nodes)" 0
7409         wait $MULTIPID
7410         RC=$?
7411         if [[ $RC -ne 0 ]]; then
7412                 error "Multiop fsync failed, rc=$RC"
7413         fi
7414
7415         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7416         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7417                     grep -c writeback)
7418         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7419                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7420         fi
7421
7422         rm -f $DIR/$tfile
7423         echo "Dirty pages flushed via fsync on EROFS"
7424         return 0
7425 }
7426 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7427
7428 # continue to use small resend count to reduce test_118* time (b=14842)
7429 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7430
7431 test_118d()
7432 {
7433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7434         remote_ost_nodsh && skip "remote OST with nodsh" && return
7435
7436         reset_async
7437
7438         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7439         set_nodes_failloc "$(osts_nodes)" 0x214
7440         # multiop should block due to fsync until pages are written
7441         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7442         MULTIPID=$!
7443         sleep 1
7444
7445         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7446                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7447         fi
7448
7449         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7450                     grep -c writeback)
7451         if [[ $WRITEBACK -eq 0 ]]; then
7452                 error "No page in writeback, writeback=$WRITEBACK"
7453         fi
7454
7455         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7456         set_nodes_failloc "$(osts_nodes)" 0
7457
7458         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7459         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7460                     grep -c writeback)
7461         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7462                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7463         fi
7464
7465         rm -f $DIR/$tfile
7466         echo "Dirty pages gaurenteed flushed via fsync"
7467         return 0
7468 }
7469 run_test 118d "Fsync validation inject a delay of the bulk =========="
7470
7471 test_118f() {
7472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7473         reset_async
7474
7475         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7476         lctl set_param fail_loc=0x8000040a
7477
7478         # Should simulate EINVAL error which is fatal
7479         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7480         RC=$?
7481         if [[ $RC -eq 0 ]]; then
7482                 error "Must return error due to dropped pages, rc=$RC"
7483         fi
7484
7485         lctl set_param fail_loc=0x0
7486
7487         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7488         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7489         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7490                     grep -c writeback)
7491         if [[ $LOCKED -ne 0 ]]; then
7492                 error "Locked pages remain in cache, locked=$LOCKED"
7493         fi
7494
7495         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7496                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7497         fi
7498
7499         rm -f $DIR/$tfile
7500         echo "No pages locked after fsync"
7501
7502         reset_async
7503         return 0
7504 }
7505 run_test 118f "Simulate unrecoverable OSC side error =========="
7506
7507 test_118g() {
7508         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7509         reset_async
7510
7511         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7512         lctl set_param fail_loc=0x406
7513
7514         # simulate local -ENOMEM
7515         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7516         RC=$?
7517
7518         lctl set_param fail_loc=0
7519         if [[ $RC -eq 0 ]]; then
7520                 error "Must return error due to dropped pages, rc=$RC"
7521         fi
7522
7523         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7524         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7525         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7526                         grep -c writeback)
7527         if [[ $LOCKED -ne 0 ]]; then
7528                 error "Locked pages remain in cache, locked=$LOCKED"
7529         fi
7530
7531         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7532                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7533         fi
7534
7535         rm -f $DIR/$tfile
7536         echo "No pages locked after fsync"
7537
7538         reset_async
7539         return 0
7540 }
7541 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7542
7543 test_118h() {
7544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7545         remote_ost_nodsh && skip "remote OST with nodsh" && return
7546
7547         reset_async
7548
7549         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7550         set_nodes_failloc "$(osts_nodes)" 0x20e
7551         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7552         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7553         RC=$?
7554
7555         set_nodes_failloc "$(osts_nodes)" 0
7556         if [[ $RC -eq 0 ]]; then
7557                 error "Must return error due to dropped pages, rc=$RC"
7558         fi
7559
7560         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7561         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7562         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7563                     grep -c writeback)
7564         if [[ $LOCKED -ne 0 ]]; then
7565                 error "Locked pages remain in cache, locked=$LOCKED"
7566         fi
7567
7568         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7569                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7570         fi
7571
7572         rm -f $DIR/$tfile
7573         echo "No pages locked after fsync"
7574
7575         return 0
7576 }
7577 run_test 118h "Verify timeout in handling recoverables errors  =========="
7578
7579 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7580
7581 test_118i() {
7582         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7583         remote_ost_nodsh && skip "remote OST with nodsh" && return
7584
7585         reset_async
7586
7587         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7588         set_nodes_failloc "$(osts_nodes)" 0x20e
7589
7590         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7591         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7592         PID=$!
7593         sleep 5
7594         set_nodes_failloc "$(osts_nodes)" 0
7595
7596         wait $PID
7597         RC=$?
7598         if [[ $RC -ne 0 ]]; then
7599                 error "got error, but should be not, rc=$RC"
7600         fi
7601
7602         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7603         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7604         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7605         if [[ $LOCKED -ne 0 ]]; then
7606                 error "Locked pages remain in cache, locked=$LOCKED"
7607         fi
7608
7609         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7610                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7611         fi
7612
7613         rm -f $DIR/$tfile
7614         echo "No pages locked after fsync"
7615
7616         return 0
7617 }
7618 run_test 118i "Fix error before timeout in recoverable error  =========="
7619
7620 [ "$SLOW" = "no" ] && set_resend_count 4
7621
7622 test_118j() {
7623         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7624         remote_ost_nodsh && skip "remote OST with nodsh" && return
7625
7626         reset_async
7627
7628         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7629         set_nodes_failloc "$(osts_nodes)" 0x220
7630
7631         # return -EIO from OST
7632         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7633         RC=$?
7634         set_nodes_failloc "$(osts_nodes)" 0x0
7635         if [[ $RC -eq 0 ]]; then
7636                 error "Must return error due to dropped pages, rc=$RC"
7637         fi
7638
7639         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7640         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7641         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7642         if [[ $LOCKED -ne 0 ]]; then
7643                 error "Locked pages remain in cache, locked=$LOCKED"
7644         fi
7645
7646         # in recoverable error on OST we want resend and stay until it finished
7647         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7648                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7649         fi
7650
7651         rm -f $DIR/$tfile
7652         echo "No pages locked after fsync"
7653
7654         return 0
7655 }
7656 run_test 118j "Simulate unrecoverable OST side error =========="
7657
7658 test_118k()
7659 {
7660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7661         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7662
7663         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7664         set_nodes_failloc "$(osts_nodes)" 0x20e
7665         test_mkdir -p $DIR/$tdir
7666
7667         for ((i=0;i<10;i++)); do
7668                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7669                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7670                 SLEEPPID=$!
7671                 sleep 0.500s
7672                 kill $SLEEPPID
7673                 wait $SLEEPPID
7674         done
7675
7676         set_nodes_failloc "$(osts_nodes)" 0
7677         rm -rf $DIR/$tdir
7678 }
7679 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7680
7681 test_118l()
7682 {
7683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7684         # LU-646
7685         test_mkdir -p $DIR/$tdir
7686         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7687         rm -rf $DIR/$tdir
7688 }
7689 run_test 118l "fsync dir ========="
7690
7691 test_118m() # LU-3066
7692 {
7693         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7694         test_mkdir -p $DIR/$tdir
7695         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7696         rm -rf $DIR/$tdir
7697 }
7698 run_test 118m "fdatasync dir ========="
7699
7700 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7701
7702 test_119a() # bug 11737
7703 {
7704         BSIZE=$((512 * 1024))
7705         directio write $DIR/$tfile 0 1 $BSIZE
7706         # We ask to read two blocks, which is more than a file size.
7707         # directio will indicate an error when requested and actual
7708         # sizes aren't equeal (a normal situation in this case) and
7709         # print actual read amount.
7710         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7711         if [ "$NOB" != "$BSIZE" ]; then
7712                 error "read $NOB bytes instead of $BSIZE"
7713         fi
7714         rm -f $DIR/$tfile
7715 }
7716 run_test 119a "Short directIO read must return actual read amount"
7717
7718 test_119b() # bug 11737
7719 {
7720         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7721
7722         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7723         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7724         sync
7725         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7726                 error "direct read failed"
7727         rm -f $DIR/$tfile
7728 }
7729 run_test 119b "Sparse directIO read must return actual read amount"
7730
7731 test_119c() # bug 13099
7732 {
7733         BSIZE=1048576
7734         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7735         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7736         rm -f $DIR/$tfile
7737 }
7738 run_test 119c "Testing for direct read hitting hole"
7739
7740 test_119d() # bug 15950
7741 {
7742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7743         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7744         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7745         BSIZE=1048576
7746         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7747         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7748         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7749         lctl set_param fail_loc=0x40d
7750         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7751         pid_dio=$!
7752         sleep 1
7753         cat $DIR/$tfile > /dev/null &
7754         lctl set_param fail_loc=0
7755         pid_reads=$!
7756         wait $pid_dio
7757         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7758         sleep 2
7759         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7760         error "the read rpcs have not completed in 2s"
7761         rm -f $DIR/$tfile
7762         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7763 }
7764 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7765
7766 test_120a() {
7767         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7768         test_mkdir -p $DIR/$tdir
7769         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7770                skip "no early lock cancel on server" && return 0
7771
7772         lru_resize_disable mdc
7773         lru_resize_disable osc
7774         cancel_lru_locks mdc
7775         # asynchronous object destroy at MDT could cause bl ast to client
7776         cancel_lru_locks osc
7777
7778         stat $DIR/$tdir > /dev/null
7779         can1=$(do_facet $SINGLEMDS \
7780                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7781                awk '/ldlm_cancel/ {print $2}')
7782         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7783                awk '/ldlm_bl_callback/ {print $2}')
7784         test_mkdir -c1 $DIR/$tdir/d1
7785         can2=$(do_facet $SINGLEMDS \
7786                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7787                awk '/ldlm_cancel/ {print $2}')
7788         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7789                awk '/ldlm_bl_callback/ {print $2}')
7790         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7791         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7792         lru_resize_enable mdc
7793         lru_resize_enable osc
7794 }
7795 run_test 120a "Early Lock Cancel: mkdir test"
7796
7797 test_120b() {
7798         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7799         test_mkdir $DIR/$tdir
7800         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7801                skip "no early lock cancel on server" && return 0
7802         lru_resize_disable mdc
7803         lru_resize_disable osc
7804         cancel_lru_locks mdc
7805         stat $DIR/$tdir > /dev/null
7806         can1=$(do_facet $SINGLEMDS \
7807                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7808                awk '/ldlm_cancel/ {print $2}')
7809         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7810                awk '/ldlm_bl_callback/ {print $2}')
7811         touch $DIR/$tdir/f1
7812         can2=$(do_facet $SINGLEMDS \
7813                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7814                awk '/ldlm_cancel/ {print $2}')
7815         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7816                awk '/ldlm_bl_callback/ {print $2}')
7817         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7818         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7819         lru_resize_enable mdc
7820         lru_resize_enable osc
7821 }
7822 run_test 120b "Early Lock Cancel: create test"
7823
7824 test_120c() {
7825         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7826         test_mkdir -c1 $DIR/$tdir
7827         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7828                skip "no early lock cancel on server" && return 0
7829         lru_resize_disable mdc
7830         lru_resize_disable osc
7831         test_mkdir -p -c1 $DIR/$tdir/d1
7832         test_mkdir -p -c1 $DIR/$tdir/d2
7833         touch $DIR/$tdir/d1/f1
7834         cancel_lru_locks mdc
7835         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7836         can1=$(do_facet $SINGLEMDS \
7837                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7838                awk '/ldlm_cancel/ {print $2}')
7839         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7840                awk '/ldlm_bl_callback/ {print $2}')
7841         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7842         can2=$(do_facet $SINGLEMDS \
7843                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7844                awk '/ldlm_cancel/ {print $2}')
7845         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7846                awk '/ldlm_bl_callback/ {print $2}')
7847         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7848         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7849         lru_resize_enable mdc
7850         lru_resize_enable osc
7851 }
7852 run_test 120c "Early Lock Cancel: link test"
7853
7854 test_120d() {
7855         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7856         test_mkdir -p -c1 $DIR/$tdir
7857         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7858                skip "no early lock cancel on server" && return 0
7859         lru_resize_disable mdc
7860         lru_resize_disable osc
7861         touch $DIR/$tdir
7862         cancel_lru_locks mdc
7863         stat $DIR/$tdir > /dev/null
7864         can1=$(do_facet $SINGLEMDS \
7865                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7866                awk '/ldlm_cancel/ {print $2}')
7867         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7868                awk '/ldlm_bl_callback/ {print $2}')
7869         chmod a+x $DIR/$tdir
7870         can2=$(do_facet $SINGLEMDS \
7871                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7872                awk '/ldlm_cancel/ {print $2}')
7873         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7874                awk '/ldlm_bl_callback/ {print $2}')
7875         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7876         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7877         lru_resize_enable mdc
7878         lru_resize_enable osc
7879 }
7880 run_test 120d "Early Lock Cancel: setattr test"
7881
7882 test_120e() {
7883         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7884         test_mkdir -p -c1 $DIR/$tdir
7885         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7886                skip "no early lock cancel on server" && return 0
7887         lru_resize_disable mdc
7888         lru_resize_disable osc
7889         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7890         cancel_lru_locks mdc
7891         cancel_lru_locks osc
7892         dd if=$DIR/$tdir/f1 of=/dev/null
7893         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7894         # XXX client can not do early lock cancel of OST lock
7895         # during unlink (LU-4206), so cancel osc lock now.
7896         cancel_lru_locks osc
7897         can1=$(do_facet $SINGLEMDS \
7898                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7899                awk '/ldlm_cancel/ {print $2}')
7900         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7901                awk '/ldlm_bl_callback/ {print $2}')
7902         unlink $DIR/$tdir/f1
7903         sleep 5
7904         can2=$(do_facet $SINGLEMDS \
7905                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7906                awk '/ldlm_cancel/ {print $2}')
7907         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7908                awk '/ldlm_bl_callback/ {print $2}')
7909         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7910         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7911         lru_resize_enable mdc
7912         lru_resize_enable osc
7913 }
7914 run_test 120e "Early Lock Cancel: unlink test"
7915
7916 test_120f() {
7917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7918         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7919                skip "no early lock cancel on server" && return 0
7920         test_mkdir -p -c1 $DIR/$tdir
7921         lru_resize_disable mdc
7922         lru_resize_disable osc
7923         test_mkdir -p -c1 $DIR/$tdir/d1
7924         test_mkdir -p -c1 $DIR/$tdir/d2
7925         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7926         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7927         cancel_lru_locks mdc
7928         cancel_lru_locks osc
7929         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7930         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7931         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7932         # XXX client can not do early lock cancel of OST lock
7933         # during rename (LU-4206), so cancel osc lock now.
7934         cancel_lru_locks osc
7935         can1=$(do_facet $SINGLEMDS \
7936                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7937                awk '/ldlm_cancel/ {print $2}')
7938         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7939                awk '/ldlm_bl_callback/ {print $2}')
7940         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7941         sleep 5
7942         can2=$(do_facet $SINGLEMDS \
7943                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7944                awk '/ldlm_cancel/ {print $2}')
7945         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7946                awk '/ldlm_bl_callback/ {print $2}')
7947         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7948         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7949         lru_resize_enable mdc
7950         lru_resize_enable osc
7951 }
7952 run_test 120f "Early Lock Cancel: rename test"
7953
7954 test_120g() {
7955         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7956         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7957                skip "no early lock cancel on server" && return 0
7958         lru_resize_disable mdc
7959         lru_resize_disable osc
7960         count=10000
7961         echo create $count files
7962         test_mkdir -p $DIR/$tdir
7963         cancel_lru_locks mdc
7964         cancel_lru_locks osc
7965         t0=`date +%s`
7966
7967         can0=$(do_facet $SINGLEMDS \
7968                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7969                awk '/ldlm_cancel/ {print $2}')
7970         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7971                awk '/ldlm_bl_callback/ {print $2}')
7972         createmany -o $DIR/$tdir/f $count
7973         sync
7974         can1=$(do_facet $SINGLEMDS \
7975                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7976                awk '/ldlm_cancel/ {print $2}')
7977         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7978                awk '/ldlm_bl_callback/ {print $2}')
7979         t1=$(date +%s)
7980         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7981         echo rm $count files
7982         rm -r $DIR/$tdir
7983         sync
7984         can2=$(do_facet $SINGLEMDS \
7985                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7986                awk '/ldlm_cancel/ {print $2}')
7987         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7988                awk '/ldlm_bl_callback/ {print $2}')
7989         t2=$(date +%s)
7990         echo total: $count removes in $((t2-t1))
7991         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7992         sleep 2
7993         # wait for commitment of removal
7994         lru_resize_enable mdc
7995         lru_resize_enable osc
7996 }
7997 run_test 120g "Early Lock Cancel: performance test"
7998
7999 test_121() { #bug #10589
8000         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8001         rm -rf $DIR/$tfile
8002         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8003 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8004         lctl set_param fail_loc=0x310
8005         cancel_lru_locks osc > /dev/null
8006         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8007         lctl set_param fail_loc=0
8008         [[ $reads -eq $writes ]] ||
8009                 error "read $reads blocks, must be $writes blocks"
8010 }
8011 run_test 121 "read cancel race ========="
8012
8013 test_123a() { # was test 123, statahead(bug 11401)
8014         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8015         SLOWOK=0
8016         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8017             log "testing on UP system. Performance may be not as good as expected."
8018                         SLOWOK=1
8019         fi
8020
8021         rm -rf $DIR/$tdir
8022         test_mkdir -p $DIR/$tdir
8023         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8024         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8025         MULT=10
8026         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8027                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8028
8029                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8030                 lctl set_param -n llite.*.statahead_max 0
8031                 lctl get_param llite.*.statahead_max
8032                 cancel_lru_locks mdc
8033                 cancel_lru_locks osc
8034                 stime=`date +%s`
8035                 time ls -l $DIR/$tdir | wc -l
8036                 etime=`date +%s`
8037                 delta=$((etime - stime))
8038                 log "ls $i files without statahead: $delta sec"
8039                 lctl set_param llite.*.statahead_max=$max
8040
8041                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8042                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8043                 cancel_lru_locks mdc
8044                 cancel_lru_locks osc
8045                 stime=`date +%s`
8046                 time ls -l $DIR/$tdir | wc -l
8047                 etime=`date +%s`
8048                 delta_sa=$((etime - stime))
8049                 log "ls $i files with statahead: $delta_sa sec"
8050                 lctl get_param -n llite.*.statahead_stats
8051                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8052
8053                 [[ $swrong -lt $ewrong ]] &&
8054                         log "statahead was stopped, maybe too many locks held!"
8055                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8056
8057                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8058                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8059                     lctl set_param -n llite.*.statahead_max 0
8060                     lctl get_param llite.*.statahead_max
8061                     cancel_lru_locks mdc
8062                     cancel_lru_locks osc
8063                     stime=`date +%s`
8064                     time ls -l $DIR/$tdir | wc -l
8065                     etime=`date +%s`
8066                     delta=$((etime - stime))
8067                     log "ls $i files again without statahead: $delta sec"
8068                     lctl set_param llite.*.statahead_max=$max
8069                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8070                         if [  $SLOWOK -eq 0 ]; then
8071                                 error "ls $i files is slower with statahead!"
8072                         else
8073                                 log "ls $i files is slower with statahead!"
8074                         fi
8075                         break
8076                     fi
8077                 fi
8078
8079                 [ $delta -gt 20 ] && break
8080                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8081                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8082         done
8083         log "ls done"
8084
8085         stime=`date +%s`
8086         rm -r $DIR/$tdir
8087         sync
8088         etime=`date +%s`
8089         delta=$((etime - stime))
8090         log "rm -r $DIR/$tdir/: $delta seconds"
8091         log "rm done"
8092         lctl get_param -n llite.*.statahead_stats
8093 }
8094 run_test 123a "verify statahead work"
8095
8096 test_123b () { # statahead(bug 15027)
8097         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8098         test_mkdir -p $DIR/$tdir
8099         createmany -o $DIR/$tdir/$tfile-%d 1000
8100
8101         cancel_lru_locks mdc
8102         cancel_lru_locks osc
8103
8104 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8105         lctl set_param fail_loc=0x80000803
8106         ls -lR $DIR/$tdir > /dev/null
8107         log "ls done"
8108         lctl set_param fail_loc=0x0
8109         lctl get_param -n llite.*.statahead_stats
8110         rm -r $DIR/$tdir
8111         sync
8112
8113 }
8114 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8115
8116 test_124a() {
8117         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8118         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8119                 skip "no lru resize on server" && return 0
8120         local NR=2000
8121         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8122
8123         log "create $NR files at $DIR/$tdir"
8124         createmany -o $DIR/$tdir/f $NR ||
8125                 error "failed to create $NR files in $DIR/$tdir"
8126
8127         cancel_lru_locks mdc
8128         ls -l $DIR/$tdir > /dev/null
8129
8130         local NSDIR=""
8131         local LRU_SIZE=0
8132         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8133                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8134                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8135                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8136                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8137                         log "NSDIR=$NSDIR"
8138                         log "NS=$(basename $NSDIR)"
8139                         break
8140                 fi
8141         done
8142
8143         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8144                 skip "Not enough cached locks created!"
8145                 return 0
8146         fi
8147         log "LRU=$LRU_SIZE"
8148
8149         local SLEEP=30
8150
8151         # We know that lru resize allows one client to hold $LIMIT locks
8152         # for 10h. After that locks begin to be killed by client.
8153         local MAX_HRS=10
8154         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8155         log "LIMIT=$LIMIT"
8156
8157         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8158         # killing locks. Some time was spent for creating locks. This means
8159         # that up to the moment of sleep finish we must have killed some of
8160         # them (10-100 locks). This depends on how fast ther were created.
8161         # Many of them were touched in almost the same moment and thus will
8162         # be killed in groups.
8163         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8164
8165         # Use $LRU_SIZE_B here to take into account real number of locks
8166         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8167         local LRU_SIZE_B=$LRU_SIZE
8168         log "LVF=$LVF"
8169         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8170         log "OLD_LVF=$OLD_LVF"
8171         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8172
8173         # Let's make sure that we really have some margin. Client checks
8174         # cached locks every 10 sec.
8175         SLEEP=$((SLEEP+20))
8176         log "Sleep ${SLEEP} sec"
8177         local SEC=0
8178         while ((SEC<$SLEEP)); do
8179                 echo -n "..."
8180                 sleep 5
8181                 SEC=$((SEC+5))
8182                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8183                 echo -n "$LRU_SIZE"
8184         done
8185         echo ""
8186         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8187         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8188
8189         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8190                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8191                 unlinkmany $DIR/$tdir/f $NR
8192                 return
8193         }
8194
8195         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8196         log "unlink $NR files at $DIR/$tdir"
8197         unlinkmany $DIR/$tdir/f $NR
8198 }
8199 run_test 124a "lru resize ======================================="
8200
8201 get_max_pool_limit()
8202 {
8203         local limit=$($LCTL get_param \
8204                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8205         local max=0
8206         for l in $limit; do
8207                 if [[ $l -gt $max ]]; then
8208                         max=$l
8209                 fi
8210         done
8211         echo $max
8212 }
8213
8214 test_124b() {
8215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8216         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8217                 skip "no lru resize on server" && return 0
8218
8219         LIMIT=$(get_max_pool_limit)
8220
8221         NR=$(($(default_lru_size)*20))
8222         if [[ $NR -gt $LIMIT ]]; then
8223                 log "Limit lock number by $LIMIT locks"
8224                 NR=$LIMIT
8225         fi
8226         lru_resize_disable mdc
8227         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8228                 error "failed to create $DIR/$tdir/disable_lru_resize"
8229
8230         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8231         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8232         cancel_lru_locks mdc
8233         stime=`date +%s`
8234         PID=""
8235         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8236         PID="$PID $!"
8237         sleep 2
8238         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8239         PID="$PID $!"
8240         sleep 2
8241         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8242         PID="$PID $!"
8243         wait $PID
8244         etime=`date +%s`
8245         nolruresize_delta=$((etime-stime))
8246         log "ls -la time: $nolruresize_delta seconds"
8247         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8248         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8249
8250         lru_resize_enable mdc
8251         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8252                 error "failed to create $DIR/$tdir/enable_lru_resize"
8253
8254         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8255         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8256         cancel_lru_locks mdc
8257         stime=`date +%s`
8258         PID=""
8259         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8260         PID="$PID $!"
8261         sleep 2
8262         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8263         PID="$PID $!"
8264         sleep 2
8265         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8266         PID="$PID $!"
8267         wait $PID
8268         etime=`date +%s`
8269         lruresize_delta=$((etime-stime))
8270         log "ls -la time: $lruresize_delta seconds"
8271         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8272
8273         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8274                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8275         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8276                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8277         else
8278                 log "lru resize performs the same with no lru resize"
8279         fi
8280         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8281 }
8282 run_test 124b "lru resize (performance test) ======================="
8283
8284 test_125() { # 13358
8285         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8286         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8287         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8288         test_mkdir -p $DIR/d125 || error "mkdir failed"
8289         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8290         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8291         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8292 }
8293 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8294
8295 test_126() { # bug 12829/13455
8296         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8297         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8298         $GSS && skip "must run as gss disabled" && return
8299
8300         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8301         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8302         rm -f $DIR/$tfile
8303         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8304 }
8305 run_test 126 "check that the fsgid provided by the client is taken into account"
8306
8307 test_127a() { # bug 15521
8308         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8309         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8310         $LCTL set_param osc.*.stats=0
8311         FSIZE=$((2048 * 1024))
8312         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8313         cancel_lru_locks osc
8314         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8315
8316         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8317         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8318                 echo "got $COUNT $NAME"
8319                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8320                 eval $NAME=$COUNT || error "Wrong proc format"
8321
8322                 case $NAME in
8323                         read_bytes|write_bytes)
8324                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8325                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8326                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8327                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8328                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8329                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8330                                 error "sumsquare is too small: $SUMSQ"
8331                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8332                                 error "sumsquare is too big: $SUMSQ"
8333                         ;;
8334                         *) ;;
8335                 esac
8336         done < $DIR/${tfile}.tmp
8337
8338         #check that we actually got some stats
8339         [ "$read_bytes" ] || error "Missing read_bytes stats"
8340         [ "$write_bytes" ] || error "Missing write_bytes stats"
8341         [ "$read_bytes" != 0 ] || error "no read done"
8342         [ "$write_bytes" != 0 ] || error "no write done"
8343 }
8344 run_test 127a "verify the client stats are sane"
8345
8346 test_127b() { # bug LU-333
8347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8348         $LCTL set_param llite.*.stats=0
8349         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8350         # perform 2 reads and writes so MAX is different from SUM.
8351         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8352         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8353         cancel_lru_locks osc
8354         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8355         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8356
8357         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8358         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8359                 echo "got $COUNT $NAME"
8360                 eval $NAME=$COUNT || error "Wrong proc format"
8361
8362         case $NAME in
8363                 read_bytes)
8364                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8365                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8366                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8367                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8368                         ;;
8369                 write_bytes)
8370                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8371                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8372                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8373                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8374                         ;;
8375                         *) ;;
8376                 esac
8377         done < $TMP/${tfile}.tmp
8378
8379         #check that we actually got some stats
8380         [ "$read_bytes" ] || error "Missing read_bytes stats"
8381         [ "$write_bytes" ] || error "Missing write_bytes stats"
8382         [ "$read_bytes" != 0 ] || error "no read done"
8383         [ "$write_bytes" != 0 ] || error "no write done"
8384 }
8385 run_test 127b "verify the llite client stats are sane"
8386
8387 test_128() { # bug 15212
8388         touch $DIR/$tfile
8389         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8390                 find $DIR/$tfile
8391                 find $DIR/$tfile
8392         EOF
8393
8394         result=$(grep error $TMP/$tfile.log)
8395         rm -f $DIR/$tfile
8396         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8397 }
8398 run_test 128 "interactive lfs for 2 consecutive find's"
8399
8400 set_dir_limits () {
8401         local mntdev
8402         local canondev
8403         local node
8404
8405         local LDPROC=/proc/fs/ldiskfs
8406         local facets=$(get_facets MDS)
8407
8408         for facet in ${facets//,/ }; do
8409                 canondev=$(ldiskfs_canon \
8410                            *.$(convert_facet2label $facet).mntdev $facet)
8411                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8412                                                 LDPROC=/sys/fs/ldiskfs
8413                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8414         done
8415 }
8416
8417 test_129() {
8418         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8419         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8420                 skip "Only applicable to ldiskfs-based MDTs"
8421                 return
8422         fi
8423         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8424         ENOSPC=28
8425         EFBIG=27
8426
8427         rm -rf $DIR/$tdir
8428         test_mkdir -p $DIR/$tdir
8429
8430         # block size of mds1
8431         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8432         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8433         local MAX=$((MDSBLOCKSIZE * 3))
8434         set_dir_limits $MAX
8435         local I=$(stat -c%s "$DIR/$tdir")
8436         local J=0
8437         local STRIPE_COUNT=1
8438         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8439         MAX=$((MAX*STRIPE_COUNT))
8440         while [[ $I -le $MAX ]]; do
8441                 $MULTIOP $DIR/$tdir/$J Oc
8442                 rc=$?
8443                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8444                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8445                 #and EFBIG for previous versions
8446                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8447                         set_dir_limits 0
8448                         echo "return code $rc received as expected"
8449                         multiop $DIR/$tdir/$J Oc ||
8450                                 error_exit "multiop failed w/o dir size limit"
8451
8452                         I=$(stat -c%s "$DIR/$tdir")
8453
8454                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8455                                         $(version_code 2.4.51) ]
8456                         then
8457                                 [[ $I -eq $MAX ]] && return 0
8458                         else
8459                                 [[ $I -gt $MAX ]] && return 0
8460                         fi
8461                         error_exit "current dir size $I, previous limit $MAX"
8462                 elif [ $rc -ne 0 ]; then
8463                         set_dir_limits 0
8464                         error_exit "return code $rc received instead of expected " \
8465                                    "$EFBIG or $ENOSPC, files in dir $I"
8466                 fi
8467                 J=$((J+1))
8468                 I=$(stat -c%s "$DIR/$tdir")
8469         done
8470
8471         set_dir_limits 0
8472         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8473 }
8474 run_test 129 "test directory size limit ========================"
8475
8476 OLDIFS="$IFS"
8477 cleanup_130() {
8478         trap 0
8479         IFS="$OLDIFS"
8480 }
8481
8482 test_130a() {
8483         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8484         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8485                 return
8486
8487         trap cleanup_130 EXIT RETURN
8488
8489         local fm_file=$DIR/$tfile
8490         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8491         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8492                 error "dd failed for $fm_file"
8493
8494         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8495         filefrag -ves $fm_file
8496         RC=$?
8497         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8498                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8499         [ $RC != 0 ] && error "filefrag $fm_file failed"
8500
8501         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8502                       grep -v "ext:" | grep -v "found")
8503         lun=$($GETSTRIPE -i $fm_file)
8504
8505         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8506         IFS=$'\n'
8507         tot_len=0
8508         for line in $filefrag_op
8509         do
8510                 frag_lun=`echo $line | cut -d: -f5`
8511                 ext_len=`echo $line | cut -d: -f4`
8512                 if (( $frag_lun != $lun )); then
8513                         cleanup_130
8514                         error "FIEMAP on 1-stripe file($fm_file) failed"
8515                         return
8516                 fi
8517                 (( tot_len += ext_len ))
8518         done
8519
8520         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8521                 cleanup_130
8522                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8523                 return
8524         fi
8525
8526         cleanup_130
8527
8528         echo "FIEMAP on single striped file succeeded"
8529 }
8530 run_test 130a "FIEMAP (1-stripe file)"
8531
8532 test_130b() {
8533         [ "$OSTCOUNT" -lt "2" ] &&
8534                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8535
8536         [ "$OSTCOUNT" -ge "10" ] &&
8537                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8538
8539         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8540         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8541                 return
8542
8543         trap cleanup_130 EXIT RETURN
8544
8545         local fm_file=$DIR/$tfile
8546         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8547         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8548                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8549
8550         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8551                 error "dd failed on $fm_file"
8552
8553         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8554         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8555                       grep -v "ext:" | grep -v "found")
8556
8557         last_lun=$(echo $filefrag_op | cut -d: -f5)
8558
8559         IFS=$'\n'
8560         tot_len=0
8561         num_luns=1
8562         for line in $filefrag_op
8563         do
8564                 frag_lun=`echo $line | cut -d: -f5`
8565                 ext_len=`echo $line | cut -d: -f4`
8566                 if (( $frag_lun != $last_lun )); then
8567                         if (( tot_len != 1024 )); then
8568                                 cleanup_130
8569                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8570                                 return
8571                         else
8572                                 (( num_luns += 1 ))
8573                                 tot_len=0
8574                         fi
8575                 fi
8576                 (( tot_len += ext_len ))
8577                 last_lun=$frag_lun
8578         done
8579         if (( num_luns != 2 || tot_len != 1024 )); then
8580                 cleanup_130
8581                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8582                 return
8583         fi
8584
8585         cleanup_130
8586
8587         echo "FIEMAP on 2-stripe file succeeded"
8588 }
8589 run_test 130b "FIEMAP (2-stripe file)"
8590
8591 test_130c() {
8592         [ "$OSTCOUNT" -lt "2" ] &&
8593                 skip_env "skipping FIEMAP on 2-stripe file" && return
8594
8595         [ "$OSTCOUNT" -ge "10" ] &&
8596                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8597
8598         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8599         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8600                 return
8601
8602         trap cleanup_130 EXIT RETURN
8603
8604         local fm_file=$DIR/$tfile
8605         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8606         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8607                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8608
8609         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8610
8611         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8612         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8613
8614         last_lun=`echo $filefrag_op | cut -d: -f5`
8615
8616         IFS=$'\n'
8617         tot_len=0
8618         num_luns=1
8619         for line in $filefrag_op
8620         do
8621                 frag_lun=`echo $line | cut -d: -f5`
8622                 ext_len=`echo $line | cut -d: -f4`
8623                 if (( $frag_lun != $last_lun )); then
8624                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8625                         if (( logical != 512 )); then
8626                                 cleanup_130
8627                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8628                                 return
8629                         fi
8630                         if (( tot_len != 512 )); then
8631                                 cleanup_130
8632                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8633                                 return
8634                         else
8635                                 (( num_luns += 1 ))
8636                                 tot_len=0
8637                         fi
8638                 fi
8639                 (( tot_len += ext_len ))
8640                 last_lun=$frag_lun
8641         done
8642         if (( num_luns != 2 || tot_len != 512 )); then
8643                 cleanup_130
8644                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8645                 return
8646         fi
8647
8648         cleanup_130
8649
8650         echo "FIEMAP on 2-stripe file with hole succeeded"
8651 }
8652 run_test 130c "FIEMAP (2-stripe file with hole)"
8653
8654 test_130d() {
8655         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8656
8657         [ "$OSTCOUNT" -ge "10" ] &&
8658                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8659
8660         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8661         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8662
8663         trap cleanup_130 EXIT RETURN
8664
8665         local fm_file=$DIR/$tfile
8666         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8667         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8668                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8669
8670         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8671         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8672                 error "dd failed on $fm_file"
8673
8674         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8675         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8676                 grep -v "ext:" | grep -v "found"`
8677
8678         last_lun=`echo $filefrag_op | cut -d: -f5`
8679
8680         IFS=$'\n'
8681         tot_len=0
8682         num_luns=1
8683         for line in $filefrag_op
8684         do
8685                 frag_lun=`echo $line | cut -d: -f5`
8686                 ext_len=`echo $line | cut -d: -f4`
8687                 if (( $frag_lun != $last_lun )); then
8688                         if (( tot_len != 1024 )); then
8689                                 cleanup_130
8690                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8691                                 return
8692                         else
8693                                 (( num_luns += 1 ))
8694                                 tot_len=0
8695                         fi
8696                 fi
8697                 (( tot_len += ext_len ))
8698                 last_lun=$frag_lun
8699         done
8700         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8701                 cleanup_130
8702                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8703                 return
8704         fi
8705
8706         cleanup_130
8707
8708         echo "FIEMAP on N-stripe file succeeded"
8709 }
8710 run_test 130d "FIEMAP (N-stripe file)"
8711
8712 test_130e() {
8713         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8714
8715         [ "$OSTCOUNT" -ge "10" ] &&
8716                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8717
8718         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8719         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8720
8721         trap cleanup_130 EXIT RETURN
8722
8723         local fm_file=$DIR/$tfile
8724         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8725         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8726                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8727
8728         NUM_BLKS=512
8729         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8730         for ((i = 0; i < $NUM_BLKS; i++))
8731         do
8732                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8733         done
8734
8735         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8736         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8737
8738         last_lun=`echo $filefrag_op | cut -d: -f5`
8739
8740         IFS=$'\n'
8741         tot_len=0
8742         num_luns=1
8743         for line in $filefrag_op
8744         do
8745                 frag_lun=`echo $line | cut -d: -f5`
8746                 ext_len=`echo $line | cut -d: -f4`
8747                 if (( $frag_lun != $last_lun )); then
8748                         if (( tot_len != $EXPECTED_LEN )); then
8749                                 cleanup_130
8750                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8751                                 return
8752                         else
8753                                 (( num_luns += 1 ))
8754                                 tot_len=0
8755                         fi
8756                 fi
8757                 (( tot_len += ext_len ))
8758                 last_lun=$frag_lun
8759         done
8760         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8761                 cleanup_130
8762                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8763                 return
8764         fi
8765
8766         cleanup_130
8767
8768         echo "FIEMAP with continuation calls succeeded"
8769 }
8770 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8771
8772 # Test for writev/readv
8773 test_131a() {
8774         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8775         error "writev test failed"
8776         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8777         error "readv failed"
8778         rm -f $DIR/$tfile
8779 }
8780 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8781
8782 test_131b() {
8783         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8784         error "append writev test failed"
8785         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8786         error "append writev test failed"
8787         rm -f $DIR/$tfile
8788 }
8789 run_test 131b "test append writev"
8790
8791 test_131c() {
8792         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8793         error "NOT PASS"
8794 }
8795 run_test 131c "test read/write on file w/o objects"
8796
8797 test_131d() {
8798         rwv -f $DIR/$tfile -w -n 1 1572864
8799         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8800         if [ "$NOB" != 1572864 ]; then
8801                 error "Short read filed: read $NOB bytes instead of 1572864"
8802         fi
8803         rm -f $DIR/$tfile
8804 }
8805 run_test 131d "test short read"
8806
8807 test_131e() {
8808         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8809         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8810         error "read hitting hole failed"
8811         rm -f $DIR/$tfile
8812 }
8813 run_test 131e "test read hitting hole"
8814
8815 get_ost_param() {
8816         local token=$1
8817         local gl_sum=0
8818         for node in $(osts_nodes); do
8819                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8820                 [ x$gl = x"" ] && gl=0
8821                 gl_sum=$((gl_sum + gl))
8822         done
8823         echo $gl_sum
8824 }
8825
8826 som_mode_switch() {
8827         local som=$1
8828         local gl1=$2
8829         local gl2=$3
8830
8831         if [ x$som = x"enabled" ]; then
8832                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8833                 MOUNT_OPTS=`echo $MOUNT_OPTS |
8834                     sed 's/som_preview,\|,som_preview\|som_preview//g'`
8835                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8836         else
8837                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8838                 MOUNT_OPTS="${MOUNT_OPTS:+$MOUNT_OPTS,}som_preview"
8839                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8840         fi
8841
8842         # do remount to make new mount-conf parameters actual
8843         echo remounting...
8844         sync
8845         stopall
8846         setupall
8847 }
8848
8849 test_132() { #1028, SOM
8850         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8851         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8852         local num=$(get_mds_dir $DIR)
8853         local mymds=mds${num}
8854         local MOUNT_OPTS_SAVE=$MOUNT_OPTS
8855
8856         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8857         cancel_lru_locks osc
8858
8859         som1=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8860
8861         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8862         stat $DIR/$tfile >/dev/null
8863         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8864         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8865         rm $DIR/$tfile
8866         som_mode_switch $som1 $gl1 $gl2
8867
8868         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8869         cancel_lru_locks osc
8870
8871         som2=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8872         if [ $som1 == $som2 ]; then
8873             error "som is still "$som2
8874             if [ x$som2 = x"enabled" ]; then
8875                 som2="disabled"
8876             else
8877                 som2="enabled"
8878             fi
8879         fi
8880
8881         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8882         stat $DIR/$tfile >/dev/null
8883         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8884         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8885         som_mode_switch $som2 $gl1 $gl2
8886         MOUNT_OPTS=$MOUNT_OPTS_SAVE
8887 }
8888 run_test 132 "som avoids glimpse rpc"
8889
8890 check_stats() {
8891         local res
8892         local count
8893         case $1 in
8894         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8895                  ;;
8896         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8897                  ;;
8898         *) error "Wrong argument $1" ;;
8899         esac
8900         echo $res
8901         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8902         # if the argument $3 is zero, it means any stat increment is ok.
8903         if [[ $3 -gt 0 ]]; then
8904                 count=$(echo $res | awk '{ print $2 }')
8905                 [[ $count -ne $3 ]] &&
8906                         error "The $2 counter on $1 is wrong - expected $3"
8907         fi
8908 }
8909
8910 test_133a() {
8911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8912         remote_ost_nodsh && skip "remote OST with nodsh" && return
8913         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8914
8915         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8916                 { skip "MDS doesn't support rename stats"; return; }
8917         local testdir=$DIR/${tdir}/stats_testdir
8918         mkdir -p $DIR/${tdir}
8919
8920         # clear stats.
8921         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8922         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8923
8924         # verify mdt stats first.
8925         mkdir ${testdir} || error "mkdir failed"
8926         check_stats $SINGLEMDS "mkdir" 1
8927         touch ${testdir}/${tfile} || "touch failed"
8928         check_stats $SINGLEMDS "open" 1
8929         check_stats $SINGLEMDS "close" 1
8930         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8931         check_stats $SINGLEMDS "mknod" 1
8932         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8933         check_stats $SINGLEMDS "unlink" 1
8934         rm -f ${testdir}/${tfile} || error "file remove failed"
8935         check_stats $SINGLEMDS "unlink" 2
8936
8937         # remove working dir and check mdt stats again.
8938         rmdir ${testdir} || error "rmdir failed"
8939         check_stats $SINGLEMDS "rmdir" 1
8940
8941         local testdir1=$DIR/${tdir}/stats_testdir1
8942         mkdir -p ${testdir}
8943         mkdir -p ${testdir1}
8944         touch ${testdir1}/test1
8945         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8946         check_stats $SINGLEMDS "crossdir_rename" 1
8947
8948         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8949         check_stats $SINGLEMDS "samedir_rename" 1
8950
8951         rm -rf $DIR/${tdir}
8952 }
8953 run_test 133a "Verifying MDT stats ========================================"
8954
8955 test_133b() {
8956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8957         remote_ost_nodsh && skip "remote OST with nodsh" && return
8958         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8959         local testdir=$DIR/${tdir}/stats_testdir
8960         mkdir -p ${testdir} || error "mkdir failed"
8961         touch ${testdir}/${tfile} || "touch failed"
8962         cancel_lru_locks mdc
8963
8964         # clear stats.
8965         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8966         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8967
8968         # extra mdt stats verification.
8969         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8970         check_stats $SINGLEMDS "setattr" 1
8971         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8972         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8973         then            # LU-1740
8974                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8975                 check_stats $SINGLEMDS "getattr" 1
8976         fi
8977         $LFS df || error "lfs failed"
8978         check_stats $SINGLEMDS "statfs" 1
8979
8980         rm -rf $DIR/${tdir}
8981 }
8982 run_test 133b "Verifying extra MDT stats =================================="
8983
8984 test_133c() {
8985         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8986         remote_ost_nodsh && skip "remote OST with nodsh" && return
8987         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8988         local testdir=$DIR/${tdir}/stats_testdir
8989         test_mkdir -p ${testdir} || error "mkdir failed"
8990
8991         # verify obdfilter stats.
8992         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8993         sync
8994         cancel_lru_locks osc
8995         wait_delete_completed
8996
8997         # clear stats.
8998         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8999         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9000
9001         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9002         sync
9003         cancel_lru_locks osc
9004         check_stats ost "write" 1
9005
9006         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9007         check_stats ost "read" 1
9008
9009         > ${testdir}/${tfile} || error "truncate failed"
9010         check_stats ost "punch" 1
9011
9012         rm -f ${testdir}/${tfile} || error "file remove failed"
9013         wait_delete_completed
9014         check_stats ost "destroy" 1
9015
9016         rm -rf $DIR/${tdir}
9017 }
9018 run_test 133c "Verifying OST stats ========================================"
9019
9020 order_2() {
9021         local value=$1
9022         local orig=$value
9023         local order=1
9024
9025         while [ $value -ge 2 ]; do
9026                 order=$((order*2))
9027                 value=$((value/2))
9028         done
9029
9030         if [ $orig -gt $order ]; then
9031                 order=$((order*2))
9032         fi
9033         echo $order
9034 }
9035
9036 size_in_KMGT() {
9037     local value=$1
9038     local size=('K' 'M' 'G' 'T');
9039     local i=0
9040     local size_string=$value
9041
9042     while [ $value -ge 1024 ]; do
9043         if [ $i -gt 3 ]; then
9044             #T is the biggest unit we get here, if that is bigger,
9045             #just return XXXT
9046             size_string=${value}T
9047             break
9048         fi
9049         value=$((value >> 10))
9050         if [ $value -lt 1024 ]; then
9051             size_string=${value}${size[$i]}
9052             break
9053         fi
9054         i=$((i + 1))
9055     done
9056
9057     echo $size_string
9058 }
9059
9060 get_rename_size() {
9061     local size=$1
9062     local context=${2:-.}
9063     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9064                 grep -A1 $context |
9065                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9066     echo $sample
9067 }
9068
9069 test_133d() {
9070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9071         remote_ost_nodsh && skip "remote OST with nodsh" && return
9072         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9073         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9074         { skip "MDS doesn't support rename stats"; return; }
9075
9076         local testdir1=$DIR/${tdir}/stats_testdir1
9077         local testdir2=$DIR/${tdir}/stats_testdir2
9078
9079         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9080
9081         mkdir -p ${testdir1} || error "mkdir failed"
9082         mkdir -p ${testdir2} || error "mkdir failed"
9083
9084         createmany -o $testdir1/test 512 || error "createmany failed"
9085
9086         # check samedir rename size
9087         mv ${testdir1}/test0 ${testdir1}/test_0
9088
9089         local testdir1_size=$(ls -l $DIR/${tdir} |
9090                 awk '/stats_testdir1/ {print $5}')
9091         local testdir2_size=$(ls -l $DIR/${tdir} |
9092                 awk '/stats_testdir2/ {print $5}')
9093
9094         testdir1_size=$(order_2 $testdir1_size)
9095         testdir2_size=$(order_2 $testdir2_size)
9096
9097         testdir1_size=$(size_in_KMGT $testdir1_size)
9098         testdir2_size=$(size_in_KMGT $testdir2_size)
9099
9100         echo "source rename dir size: ${testdir1_size}"
9101         echo "target rename dir size: ${testdir2_size}"
9102
9103         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9104         eval $cmd || error "$cmd failed"
9105         local samedir=$($cmd | grep 'same_dir')
9106         local same_sample=$(get_rename_size $testdir1_size)
9107         [ -z "$samedir" ] && error "samedir_rename_size count error"
9108         [[ $same_sample -eq 1 ]] ||
9109                 error "samedir_rename_size error $same_sample"
9110         echo "Check same dir rename stats success"
9111
9112         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9113
9114         # check crossdir rename size
9115         mv ${testdir1}/test_0 ${testdir2}/test_0
9116
9117         testdir1_size=$(ls -l $DIR/${tdir} |
9118                 awk '/stats_testdir1/ {print $5}')
9119         testdir2_size=$(ls -l $DIR/${tdir} |
9120                 awk '/stats_testdir2/ {print $5}')
9121
9122         testdir1_size=$(order_2 $testdir1_size)
9123         testdir2_size=$(order_2 $testdir2_size)
9124
9125         testdir1_size=$(size_in_KMGT $testdir1_size)
9126         testdir2_size=$(size_in_KMGT $testdir2_size)
9127
9128         echo "source rename dir size: ${testdir1_size}"
9129         echo "target rename dir size: ${testdir2_size}"
9130
9131         eval $cmd || error "$cmd failed"
9132         local crossdir=$($cmd | grep 'crossdir')
9133         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9134         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9135         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9136         [[ $src_sample -eq 1 ]] ||
9137                 error "crossdir_rename_size error $src_sample"
9138         [[ $tgt_sample -eq 1 ]] ||
9139                 error "crossdir_rename_size error $tgt_sample"
9140         echo "Check cross dir rename stats success"
9141         rm -rf $DIR/${tdir}
9142 }
9143 run_test 133d "Verifying rename_stats ========================================"
9144
9145 test_133e() {
9146         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9147         remote_ost_nodsh && skip "remote OST with nodsh" && return
9148         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9149         local testdir=$DIR/${tdir}/stats_testdir
9150         local ctr f0 f1 bs=32768 count=42 sum
9151
9152         mkdir -p ${testdir} || error "mkdir failed"
9153
9154         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9155
9156         for ctr in {write,read}_bytes; do
9157                 sync
9158                 cancel_lru_locks osc
9159
9160                 do_facet ost1 $LCTL set_param -n \
9161                         "obdfilter.*.exports.clear=clear"
9162
9163                 if [ $ctr = write_bytes ]; then
9164                         f0=/dev/zero
9165                         f1=${testdir}/${tfile}
9166                 else
9167                         f0=${testdir}/${tfile}
9168                         f1=/dev/null
9169                 fi
9170
9171                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9172                         error "dd failed"
9173                 sync
9174                 cancel_lru_locks osc
9175
9176                 sum=$(do_facet ost1 $LCTL get_param \
9177                         "obdfilter.*.exports.*.stats" |
9178                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9179                                 $1 == ctr { sum += $7 }
9180                                 END { printf("%0.0f", sum) }')
9181
9182                 if ((sum != bs * count)); then
9183                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9184                 fi
9185         done
9186
9187         rm -rf $DIR/${tdir}
9188 }
9189 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9190
9191 test_133f() {
9192         local proc_dirs
9193
9194         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9195 /sys/fs/lustre/ /sys/fs/lnet/"
9196         local dir
9197         for dir in $dirs; do
9198                 if [ -d $dir ]; then
9199                         proc_dirs="$proc_dirs $dir"
9200                 fi
9201         done
9202
9203         local facet
9204
9205         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9206         remote_ost_nodsh && skip "remote OST with nodsh" && return
9207         # First without trusting modes.
9208         find $proc_dirs -exec cat '{}' \; &> /dev/null
9209
9210         # Second verifying readability.
9211         find $proc_dirs \
9212                 -type f \
9213                 -exec cat '{}' \; &> /dev/null ||
9214                         error "proc file read failed"
9215
9216         for facet in $SINGLEMDS ost1; do
9217                 do_facet $facet find $proc_dirs \
9218                         ! -name req_history \
9219                         -exec cat '{}' \\\; &> /dev/null
9220
9221                 do_facet $facet find $proc_dirs \
9222                         ! -name req_history \
9223                         -type f \
9224                         -exec cat '{}' \\\; &> /dev/null ||
9225                                 error "proc file read failed"
9226         done
9227 }
9228 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9229
9230 test_133g() {
9231         local proc_dirs
9232
9233         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9234 /sys/fs/lustre/ /sys/fs/lnet/"
9235         local dir
9236         for dir in $dirs; do
9237                 if [ -d $dir ]; then
9238                         proc_dirs="$proc_dirs $dir"
9239                 fi
9240         done
9241
9242         local facet
9243
9244         # Second verifying readability.
9245         find $proc_dirs \
9246                 -type f \
9247                 -not -name force_lbug \
9248                 -not -name changelog_mask \
9249                 -exec badarea_io '{}' \; &> /dev/null ||
9250                 error "find $proc_dirs failed"
9251
9252         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9253                 skip "Too old lustre on MDS"
9254
9255         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9256                 skip "Too old lustre on ost1"
9257
9258         for facet in $SINGLEMDS ost1; do
9259                 do_facet $facet find $proc_dirs \
9260                         -type f \
9261                         -not -name force_lbug \
9262                         -not -name changelog_mask \
9263                         -exec badarea_io '{}' \\\; &> /dev/null ||
9264                 error "$facet find $proc_dirs failed"
9265
9266         done
9267
9268         # remount the FS in case writes/reads /proc break the FS
9269         cleanup || error "failed to unmount"
9270         setup || error "failed to setup"
9271         true
9272 }
9273 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9274
9275 test_140() { #bug-17379
9276         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9277         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9278         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9279         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9280
9281         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9282         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9283         local i=0
9284         while i=`expr $i + 1`; do
9285                 test_mkdir -p $i || error "Creating dir $i"
9286                 cd $i || error "Changing to $i"
9287                 ln -s ../stat stat || error "Creating stat symlink"
9288                 # Read the symlink until ELOOP present,
9289                 # not LBUGing the system is considered success,
9290                 # we didn't overrun the stack.
9291                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9292                 [ $ret -ne 0 ] && {
9293                         if [ $ret -eq 40 ]; then
9294                                 break  # -ELOOP
9295                         else
9296                                 error "Open stat symlink"
9297                                 return
9298                         fi
9299                 }
9300         done
9301         i=`expr $i - 1`
9302         echo "The symlink depth = $i"
9303         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9304                                         error "Invalid symlink depth"
9305
9306         # Test recursive symlink
9307         ln -s symlink_self symlink_self
9308         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9309         echo "open symlink_self returns $ret"
9310         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9311 }
9312 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9313
9314 test_150() {
9315         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9316         local TF="$TMP/$tfile"
9317
9318         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9319         cp $TF $DIR/$tfile
9320         cancel_lru_locks osc
9321         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9322         remount_client $MOUNT
9323         df -P $MOUNT
9324         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9325
9326         $TRUNCATE $TF 6000
9327         $TRUNCATE $DIR/$tfile 6000
9328         cancel_lru_locks osc
9329         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9330
9331         echo "12345" >>$TF
9332         echo "12345" >>$DIR/$tfile
9333         cancel_lru_locks osc
9334         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9335
9336         echo "12345" >>$TF
9337         echo "12345" >>$DIR/$tfile
9338         cancel_lru_locks osc
9339         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9340
9341         rm -f $TF
9342         true
9343 }
9344 run_test 150 "truncate/append tests"
9345
9346 #LU-2902 roc_hit was not able to read all values from lproc
9347 function roc_hit_init() {
9348         local list=$(comma_list $(osts_nodes))
9349         local dir=$DIR/$tdir-check
9350         local file=$dir/file
9351         local BEFORE
9352         local AFTER
9353         local idx
9354
9355         test_mkdir -p $dir
9356         #use setstripe to do a write to every ost
9357         for i in $(seq 0 $((OSTCOUNT-1))); do
9358                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9359                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9360                 idx=$(printf %04x $i)
9361                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9362                         awk '$1 == "cache_access" {sum += $7}
9363                                 END { printf("%0.0f", sum) }')
9364
9365                 cancel_lru_locks osc
9366                 cat $file >/dev/null
9367
9368                 AFTER=$(get_osd_param $list *OST*$idx stats |
9369                         awk '$1 == "cache_access" {sum += $7}
9370                                 END { printf("%0.0f", sum) }')
9371
9372                 echo BEFORE:$BEFORE AFTER:$AFTER
9373                 if ! let "AFTER - BEFORE == 4"; then
9374                         rm -rf $dir
9375                         error "roc_hit is not safe to use"
9376                 fi
9377                 rm $file
9378         done
9379
9380         rm -rf $dir
9381 }
9382
9383 function roc_hit() {
9384         local list=$(comma_list $(osts_nodes))
9385         echo $(get_osd_param $list '' stats |
9386                 awk '$1 == "cache_hit" {sum += $7}
9387                         END { printf("%0.0f", sum) }')
9388 }
9389
9390 function set_cache() {
9391         local on=1
9392
9393         if [ "$2" == "off" ]; then
9394                 on=0;
9395         fi
9396         local list=$(comma_list $(osts_nodes))
9397         set_osd_param $list '' $1_cache_enable $on
9398
9399         cancel_lru_locks osc
9400 }
9401
9402 test_151() {
9403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9404         remote_ost_nodsh && skip "remote OST with nodsh" && return
9405
9406         local CPAGES=3
9407         local list=$(comma_list $(osts_nodes))
9408
9409         # check whether obdfilter is cache capable at all
9410         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9411                 echo "not cache-capable obdfilter"
9412                 return 0
9413         fi
9414
9415         # check cache is enabled on all obdfilters
9416         if get_osd_param $list '' read_cache_enable | grep 0; then
9417                 echo "oss cache is disabled"
9418                 return 0
9419         fi
9420
9421         set_osd_param $list '' writethrough_cache_enable 1
9422
9423         # check write cache is enabled on all obdfilters
9424         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9425                 echo "oss write cache is NOT enabled"
9426                 return 0
9427         fi
9428
9429         roc_hit_init
9430
9431         #define OBD_FAIL_OBD_NO_LRU  0x609
9432         do_nodes $list $LCTL set_param fail_loc=0x609
9433
9434         # pages should be in the case right after write
9435         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9436                 error "dd failed"
9437
9438         local BEFORE=$(roc_hit)
9439         cancel_lru_locks osc
9440         cat $DIR/$tfile >/dev/null
9441         local AFTER=$(roc_hit)
9442
9443         do_nodes $list $LCTL set_param fail_loc=0
9444
9445         if ! let "AFTER - BEFORE == CPAGES"; then
9446                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9447         fi
9448
9449         # the following read invalidates the cache
9450         cancel_lru_locks osc
9451         set_osd_param $list '' read_cache_enable 0
9452         cat $DIR/$tfile >/dev/null
9453
9454         # now data shouldn't be found in the cache
9455         BEFORE=$(roc_hit)
9456         cancel_lru_locks osc
9457         cat $DIR/$tfile >/dev/null
9458         AFTER=$(roc_hit)
9459         if let "AFTER - BEFORE != 0"; then
9460                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9461         fi
9462
9463         set_osd_param $list '' read_cache_enable 1
9464         rm -f $DIR/$tfile
9465 }
9466 run_test 151 "test cache on oss and controls ==============================="
9467
9468 test_152() {
9469         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9470         local TF="$TMP/$tfile"
9471
9472         # simulate ENOMEM during write
9473 #define OBD_FAIL_OST_NOMEM      0x226
9474         lctl set_param fail_loc=0x80000226
9475         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9476         cp $TF $DIR/$tfile
9477         sync || error "sync failed"
9478         lctl set_param fail_loc=0
9479
9480         # discard client's cache
9481         cancel_lru_locks osc
9482
9483         # simulate ENOMEM during read
9484         lctl set_param fail_loc=0x80000226
9485         cmp $TF $DIR/$tfile || error "cmp failed"
9486         lctl set_param fail_loc=0
9487
9488         rm -f $TF
9489 }
9490 run_test 152 "test read/write with enomem ============================"
9491
9492 test_153() {
9493         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9494 }
9495 run_test 153 "test if fdatasync does not crash ======================="
9496
9497 dot_lustre_fid_permission_check() {
9498         local fid=$1
9499         local ffid=$MOUNT/.lustre/fid/$fid
9500         local test_dir=$2
9501
9502         echo "stat fid $fid"
9503         stat $ffid > /dev/null || error "stat $ffid failed."
9504         echo "touch fid $fid"
9505         touch $ffid || error "touch $ffid failed."
9506         echo "write to fid $fid"
9507         cat /etc/hosts > $ffid || error "write $ffid failed."
9508         echo "read fid $fid"
9509         diff /etc/hosts $ffid || error "read $ffid failed."
9510         echo "append write to fid $fid"
9511         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9512         echo "rename fid $fid"
9513         mv $ffid $test_dir/$tfile.1 &&
9514                 error "rename $ffid to $tfile.1 should fail."
9515         touch $test_dir/$tfile.1
9516         mv $test_dir/$tfile.1 $ffid &&
9517                 error "rename $tfile.1 to $ffid should fail."
9518         rm -f $test_dir/$tfile.1
9519         echo "truncate fid $fid"
9520         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9521         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9522                 echo "link fid $fid"
9523                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9524         fi
9525         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9526                 echo "setfacl fid $fid"
9527                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9528                 echo "getfacl fid $fid"
9529                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9530         fi
9531         echo "unlink fid $fid"
9532         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9533         echo "mknod fid $fid"
9534         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9535
9536         fid=[0xf00000400:0x1:0x0]
9537         ffid=$MOUNT/.lustre/fid/$fid
9538
9539         echo "stat non-exist fid $fid"
9540         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9541         echo "write to non-exist fid $fid"
9542         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9543         echo "link new fid $fid"
9544         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9545
9546         mkdir -p $test_dir/$tdir
9547         touch $test_dir/$tdir/$tfile
9548         fid=$($LFS path2fid $test_dir/$tdir)
9549         rc=$?
9550         [ $rc -ne 0 ] &&
9551                 error "error: could not get fid for $test_dir/$dir/$tfile."
9552
9553         ffid=$MOUNT/.lustre/fid/$fid
9554
9555         echo "ls $fid"
9556         ls $ffid > /dev/null || error "ls $ffid failed."
9557         echo "touch $fid/$tfile.1"
9558         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9559
9560         echo "touch $MOUNT/.lustre/fid/$tfile"
9561         touch $MOUNT/.lustre/fid/$tfile && \
9562                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9563
9564         echo "setxattr to $MOUNT/.lustre/fid"
9565         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9566
9567         echo "listxattr for $MOUNT/.lustre/fid"
9568         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9569
9570         echo "delxattr from $MOUNT/.lustre/fid"
9571         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9572
9573         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9574         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9575                 error "touch invalid fid should fail."
9576
9577         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9578         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9579                 error "touch non-normal fid should fail."
9580
9581         echo "rename $tdir to $MOUNT/.lustre/fid"
9582         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9583                 error "rename to $MOUNT/.lustre/fid should fail."
9584
9585         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9586         then            # LU-3547
9587                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9588                 local new_obf_mode=777
9589
9590                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9591                 chmod $new_obf_mode $DIR/.lustre/fid ||
9592                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9593
9594                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9595                 [ $obf_mode -eq $new_obf_mode ] ||
9596                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9597
9598                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9599                 chmod $old_obf_mode $DIR/.lustre/fid ||
9600                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9601         fi
9602
9603         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9604         fid=$($LFS path2fid $test_dir/$tfile-2)
9605
9606         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9607         then # LU-5424
9608                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9609                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9610                         error "create lov data thru .lustre failed"
9611         fi
9612         echo "cp /etc/passwd $test_dir/$tfile-2"
9613         cp /etc/passwd $test_dir/$tfile-2 ||
9614                 error "copy to $test_dir/$tfile-2 failed."
9615         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9616         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9617                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9618
9619         rm -rf $test_dir/tfile.lnk
9620         rm -rf $test_dir/$tfile-2
9621 }
9622
9623 test_154A() {
9624         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9625                 skip "Need MDS version at least 2.4.1" && return
9626
9627         touch $DIR/$tfile
9628         local FID=$($LFS path2fid $DIR/$tfile)
9629         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9630
9631         # check that we get the same pathname back
9632         local FOUND=$($LFS fid2path $MOUNT $FID)
9633         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9634         [ "$FOUND" != "$DIR/$tfile" ] &&
9635                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9636
9637         rm -rf $DIR/$tfile
9638 }
9639 run_test 154A "lfs path2fid and fid2path basic checks"
9640
9641 test_154a() {
9642         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9643         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9644                 { skip "Need MDS version at least 2.2.51"; return 0; }
9645         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9646
9647         cp /etc/hosts $DIR/$tfile
9648
9649         fid=$($LFS path2fid $DIR/$tfile)
9650         rc=$?
9651         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9652
9653         dot_lustre_fid_permission_check "$fid" $DIR ||
9654                 error "dot lustre permission check $fid failed"
9655
9656         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9657
9658         touch $MOUNT/.lustre/file &&
9659                 error "creation is not allowed under .lustre"
9660
9661         mkdir $MOUNT/.lustre/dir &&
9662                 error "mkdir is not allowed under .lustre"
9663
9664         rm -rf $DIR/$tfile
9665 }
9666 run_test 154a "Open-by-FID"
9667
9668 test_154b() {
9669         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9670         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9671                 { skip "Need MDS version at least 2.2.51"; return 0; }
9672
9673         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9674
9675         local remote_dir=$DIR/$tdir/remote_dir
9676         local MDTIDX=1
9677         local rc=0
9678
9679         mkdir -p $DIR/$tdir
9680         $LFS mkdir -i $MDTIDX $remote_dir ||
9681                 error "create remote directory failed"
9682
9683         cp /etc/hosts $remote_dir/$tfile
9684
9685         fid=$($LFS path2fid $remote_dir/$tfile)
9686         rc=$?
9687         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9688
9689         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9690                 error "dot lustre permission check $fid failed"
9691         rm -rf $DIR/$tdir
9692 }
9693 run_test 154b "Open-by-FID for remote directory"
9694
9695 test_154c() {
9696         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9697                 skip "Need MDS version at least 2.4.1" && return
9698
9699         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9700         local FID1=$($LFS path2fid $DIR/$tfile.1)
9701         local FID2=$($LFS path2fid $DIR/$tfile.2)
9702         local FID3=$($LFS path2fid $DIR/$tfile.3)
9703
9704         local N=1
9705         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9706                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9707                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9708                 local want=FID$N
9709                 [ "$FID" = "${!want}" ] ||
9710                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9711                 N=$((N + 1))
9712         done
9713
9714         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9715                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9716                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9717                 N=$((N + 1))
9718         done
9719 }
9720 run_test 154c "lfs path2fid and fid2path multiple arguments"
9721
9722 test_154d() {
9723         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9724                 skip "Need MDS version at least 2.5.53" && return
9725
9726         if remote_mds; then
9727                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9728         else
9729                 nid="0@lo"
9730         fi
9731         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9732         local fd
9733         local cmd
9734
9735         rm -f $DIR/$tfile
9736         touch $DIR/$tfile
9737
9738         fid=$($LFS path2fid $DIR/$tfile)
9739         # Open the file
9740         fd=$(free_fd)
9741         cmd="exec $fd<$DIR/$tfile"
9742         eval $cmd
9743         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9744         echo $fid_list | grep $fid
9745         rc=$?
9746
9747         cmd="exec $fd>/dev/null"
9748         eval $cmd
9749         if [ $rc -ne 0 ]; then
9750                 error "FID $fid not found in open files list $fid_list"
9751         fi
9752 }
9753 run_test 154d "Verify open file fid"
9754
9755 test_154e()
9756 {
9757         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9758                 skip "Need MDS version at least 2.6.50" && return
9759
9760         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9761                 error ".lustre returned by readdir"
9762         fi
9763 }
9764 run_test 154e ".lustre is not returned by readdir"
9765
9766 test_155_small_load() {
9767     local temp=$TMP/$tfile
9768     local file=$DIR/$tfile
9769
9770     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9771         error "dd of=$temp bs=6096 count=1 failed"
9772     cp $temp $file
9773     cancel_lru_locks osc
9774     cmp $temp $file || error "$temp $file differ"
9775
9776     $TRUNCATE $temp 6000
9777     $TRUNCATE $file 6000
9778     cmp $temp $file || error "$temp $file differ (truncate1)"
9779
9780     echo "12345" >>$temp
9781     echo "12345" >>$file
9782     cmp $temp $file || error "$temp $file differ (append1)"
9783
9784     echo "12345" >>$temp
9785     echo "12345" >>$file
9786     cmp $temp $file || error "$temp $file differ (append2)"
9787
9788     rm -f $temp $file
9789     true
9790 }
9791
9792 test_155_big_load() {
9793     remote_ost_nodsh && skip "remote OST with nodsh" && return
9794     local temp=$TMP/$tfile
9795     local file=$DIR/$tfile
9796
9797     free_min_max
9798     local cache_size=$(do_facet ost$((MAXI+1)) \
9799         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9800     local large_file_size=$((cache_size * 2))
9801
9802     echo "OSS cache size: $cache_size KB"
9803     echo "Large file size: $large_file_size KB"
9804
9805     [ $MAXV -le $large_file_size ] && \
9806         skip_env "max available OST size needs > $large_file_size KB" && \
9807         return 0
9808
9809     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9810
9811     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9812         error "dd of=$temp bs=$large_file_size count=1k failed"
9813     cp $temp $file
9814     ls -lh $temp $file
9815     cancel_lru_locks osc
9816     cmp $temp $file || error "$temp $file differ"
9817
9818     rm -f $temp $file
9819     true
9820 }
9821
9822 test_155a() {
9823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9824         set_cache read on
9825         set_cache writethrough on
9826         test_155_small_load
9827 }
9828 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9829
9830 test_155b() {
9831         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9832         set_cache read on
9833         set_cache writethrough off
9834         test_155_small_load
9835 }
9836 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9837
9838 test_155c() {
9839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9840         set_cache read off
9841         set_cache writethrough on
9842         test_155_small_load
9843 }
9844 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9845
9846 test_155d() {
9847         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9848         set_cache read off
9849         set_cache writethrough off
9850         test_155_small_load
9851 }
9852 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9853
9854 test_155e() {
9855         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9856         set_cache read on
9857         set_cache writethrough on
9858         test_155_big_load
9859 }
9860 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9861
9862 test_155f() {
9863         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9864         set_cache read on
9865         set_cache writethrough off
9866         test_155_big_load
9867 }
9868 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9869
9870 test_155g() {
9871         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9872         set_cache read off
9873         set_cache writethrough on
9874         test_155_big_load
9875 }
9876 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9877
9878 test_155h() {
9879         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9880         set_cache read off
9881         set_cache writethrough off
9882         test_155_big_load
9883 }
9884 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9885
9886 test_156() {
9887         remote_ost_nodsh && skip "remote OST with nodsh" && return
9888         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9889         local CPAGES=3
9890         local BEFORE
9891         local AFTER
9892         local file="$DIR/$tfile"
9893
9894         [ "$(facet_fstype ost1)" = "zfs" ] &&
9895                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9896                 return
9897
9898         roc_hit_init
9899
9900     log "Turn on read and write cache"
9901     set_cache read on
9902     set_cache writethrough on
9903
9904     log "Write data and read it back."
9905     log "Read should be satisfied from the cache."
9906     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9907     BEFORE=`roc_hit`
9908     cancel_lru_locks osc
9909     cat $file >/dev/null
9910     AFTER=`roc_hit`
9911     if ! let "AFTER - BEFORE == CPAGES"; then
9912         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9913     else
9914         log "cache hits:: before: $BEFORE, after: $AFTER"
9915     fi
9916
9917     log "Read again; it should be satisfied from the cache."
9918     BEFORE=$AFTER
9919     cancel_lru_locks osc
9920     cat $file >/dev/null
9921     AFTER=`roc_hit`
9922     if ! let "AFTER - BEFORE == CPAGES"; then
9923         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9924     else
9925         log "cache hits:: before: $BEFORE, after: $AFTER"
9926     fi
9927
9928
9929     log "Turn off the read cache and turn on the write cache"
9930     set_cache read off
9931     set_cache writethrough on
9932
9933     log "Read again; it should be satisfied from the cache."
9934     BEFORE=`roc_hit`
9935     cancel_lru_locks osc
9936     cat $file >/dev/null
9937     AFTER=`roc_hit`
9938     if ! let "AFTER - BEFORE == CPAGES"; then
9939         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9940     else
9941         log "cache hits:: before: $BEFORE, after: $AFTER"
9942     fi
9943
9944     log "Read again; it should not be satisfied from the cache."
9945     BEFORE=$AFTER
9946     cancel_lru_locks osc
9947     cat $file >/dev/null
9948     AFTER=`roc_hit`
9949     if ! let "AFTER - BEFORE == 0"; then
9950         error "IN CACHE: before: $BEFORE, after: $AFTER"
9951     else
9952         log "cache hits:: before: $BEFORE, after: $AFTER"
9953     fi
9954
9955     log "Write data and read it back."
9956     log "Read should be satisfied from the cache."
9957     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9958     BEFORE=`roc_hit`
9959     cancel_lru_locks osc
9960     cat $file >/dev/null
9961     AFTER=`roc_hit`
9962     if ! let "AFTER - BEFORE == CPAGES"; then
9963         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9964     else
9965         log "cache hits:: before: $BEFORE, after: $AFTER"
9966     fi
9967
9968     log "Read again; it should not be satisfied from the cache."
9969     BEFORE=$AFTER
9970     cancel_lru_locks osc
9971     cat $file >/dev/null
9972     AFTER=`roc_hit`
9973     if ! let "AFTER - BEFORE == 0"; then
9974         error "IN CACHE: before: $BEFORE, after: $AFTER"
9975     else
9976         log "cache hits:: before: $BEFORE, after: $AFTER"
9977     fi
9978
9979
9980     log "Turn off read and write cache"
9981     set_cache read off
9982     set_cache writethrough off
9983
9984     log "Write data and read it back"
9985     log "It should not be satisfied from the cache."
9986     rm -f $file
9987     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9988     cancel_lru_locks osc
9989     BEFORE=`roc_hit`
9990     cat $file >/dev/null
9991     AFTER=`roc_hit`
9992         if ! let "AFTER - BEFORE == 0"; then
9993                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9994         else
9995                 log "cache hits:: before: $BEFORE, after: $AFTER"
9996         fi
9997
9998     log "Turn on the read cache and turn off the write cache"
9999     set_cache read on
10000     set_cache writethrough off
10001
10002     log "Write data and read it back"
10003     log "It should not be satisfied from the cache."
10004     rm -f $file
10005     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10006     BEFORE=`roc_hit`
10007     cancel_lru_locks osc
10008     cat $file >/dev/null
10009     AFTER=`roc_hit`
10010         if ! let "AFTER - BEFORE == 0"; then
10011                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10012         else
10013                 log "cache hits:: before: $BEFORE, after: $AFTER"
10014         fi
10015
10016     log "Read again; it should be satisfied from the cache."
10017     BEFORE=`roc_hit`
10018     cancel_lru_locks osc
10019     cat $file >/dev/null
10020     AFTER=`roc_hit`
10021     if ! let "AFTER - BEFORE == CPAGES"; then
10022         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10023     else
10024         log "cache hits:: before: $BEFORE, after: $AFTER"
10025     fi
10026
10027     rm -f $file
10028 }
10029 run_test 156 "Verification of tunables ============================"
10030
10031 #Changelogs
10032 err17935 () {
10033         if [[ $MDSCOUNT -gt 1 ]]; then
10034                 error_ignore bz17935 $*
10035         else
10036                 error $*
10037         fi
10038 }
10039
10040 changelog_chmask()
10041 {
10042         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10043
10044         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10045
10046         if [ $MASK -eq 1 ]; then
10047                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10048         else
10049                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10050         fi
10051 }
10052
10053 changelog_extract_field() {
10054         local mdt=$1
10055         local cltype=$2
10056         local file=$3
10057         local identifier=$4
10058
10059         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10060                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10061                 tail -1
10062 }
10063
10064 test_160a() {
10065         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10066         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10067         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10068                 { skip "Need MDS version at least 2.2.0"; return; }
10069
10070         local CL_USERS="mdd.$MDT0.changelog_users"
10071         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10072         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10073         echo "Registered as changelog user $USER"
10074         $GET_CL_USERS | grep -q $USER ||
10075                 error "User $USER not found in changelog_users"
10076
10077         # change something
10078         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10079         touch $DIR/$tdir/pics/2008/zachy/timestamp
10080         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10081         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10082         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10083         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10084         rm $DIR/$tdir/pics/desktop.jpg
10085
10086         $LFS changelog $MDT0 | tail -5
10087
10088         echo "verifying changelog mask"
10089         changelog_chmask "MKDIR"
10090         changelog_chmask "CLOSE"
10091
10092         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10093         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10094
10095         changelog_chmask "MKDIR"
10096         changelog_chmask "CLOSE"
10097
10098         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10099         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10100
10101         $LFS changelog $MDT0
10102         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10103         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10104         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10105         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10106
10107         # verify contents
10108         echo "verifying target fid"
10109         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10110         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10111         [ "$fidc" == "$fidf" ] ||
10112                 err17935 "fid in changelog $fidc != file fid $fidf"
10113         echo "verifying parent fid"
10114         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10115         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10116         [ "$fidc" == "$fidf" ] ||
10117                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10118
10119         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10120         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10121         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10122         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10123         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10124                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10125
10126         MIN_REC=$($GET_CL_USERS |
10127                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10128         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10129         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10130         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10131                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10132
10133         # LU-3446 changelog index reset on MDT restart
10134         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10135         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10136         $LFS changelog_clear $MDT0 $USER 0
10137         stop $SINGLEMDS || error "Fail to stop MDT."
10138         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10139         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10140         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10141         [ $CUR_REC1 == $CUR_REC2 ] ||
10142                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10143
10144         echo "verifying user deregister"
10145         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10146         $GET_CL_USERS | grep -q $USER &&
10147                 error "User $USER still in changelog_users"
10148
10149         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10150         if [ $USERS -eq 0 ]; then
10151                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10152                 touch $DIR/$tdir/chloe
10153                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10154                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10155                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10156         else
10157                 echo "$USERS other changelog users; can't verify off"
10158         fi
10159 }
10160 run_test 160a "changelog sanity"
10161
10162 test_160b() { # LU-3587
10163         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10164         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10165         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10166                 { skip "Need MDS version at least 2.2.0"; return; }
10167
10168         local CL_USERS="mdd.$MDT0.changelog_users"
10169         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10170         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10171         echo "Registered as changelog user $USER"
10172         $GET_CL_USERS | grep -q $USER ||
10173                 error "User $USER not found in changelog_users"
10174
10175         local LONGNAME1=$(str_repeat a 255)
10176         local LONGNAME2=$(str_repeat b 255)
10177
10178         cd $DIR
10179         echo "creating very long named file"
10180         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10181         echo "moving very long named file"
10182         mv $LONGNAME1 $LONGNAME2
10183
10184         $LFS changelog $MDT0 | grep RENME
10185
10186         echo "deregistering $USER"
10187         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10188
10189         rm -f $LONGNAME2
10190 }
10191 run_test 160b "Verify that very long rename doesn't crash in changelog"
10192
10193 test_160c() {
10194         local rc=0
10195         local server_version=$(lustre_version_code $SINGLEMDS)
10196
10197         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10198                 [[ $server_version -gt $(version_code 2.5.1) &&
10199                    $server_version -lt $(version_code 2.5.50) ]] ||
10200                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10202
10203         # Registration step
10204         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10205                 changelog_register -n)
10206
10207         rm -rf $DIR/$tdir
10208         mkdir -p $DIR/$tdir
10209         $MCREATE $DIR/$tdir/foo_160c
10210         changelog_chmask "TRUNC"
10211         $TRUNCATE $DIR/$tdir/foo_160c 200
10212         changelog_chmask "TRUNC"
10213         $TRUNCATE $DIR/$tdir/foo_160c 199
10214         $LFS changelog $MDT0
10215         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10216         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10217         $LFS changelog_clear $MDT0 $USER 0
10218
10219         # Deregistration step
10220         echo "deregistering $USER"
10221         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10222 }
10223 run_test 160c "verify that changelog log catch the truncate event"
10224
10225 test_161a() {
10226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10227         test_mkdir -p -c1 $DIR/$tdir
10228         cp /etc/hosts $DIR/$tdir/$tfile
10229         test_mkdir -c1 $DIR/$tdir/foo1
10230         test_mkdir -c1 $DIR/$tdir/foo2
10231         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10232         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10233         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10234         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10235         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10236         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10237                 $LFS fid2path $DIR $FID
10238                 err17935 "bad link ea"
10239         fi
10240     # middle
10241     rm $DIR/$tdir/foo2/zachary
10242     # last
10243     rm $DIR/$tdir/foo2/thor
10244     # first
10245     rm $DIR/$tdir/$tfile
10246     # rename
10247     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10248     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10249         then
10250         $LFS fid2path $DIR $FID
10251         err17935 "bad link rename"
10252     fi
10253     rm $DIR/$tdir/foo2/maggie
10254
10255         # overflow the EA
10256         local longname=filename_avg_len_is_thirty_two_
10257         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10258                 error "failed to hardlink many files"
10259         links=$($LFS fid2path $DIR $FID | wc -l)
10260         echo -n "${links}/1000 links in link EA"
10261         [[ $links -gt 60 ]] ||
10262                 err17935 "expected at least 60 links in link EA"
10263         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10264                 error "failed to unlink many hardlinks"
10265 }
10266 run_test 161a "link ea sanity"
10267
10268 test_161b() {
10269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10270         [ $MDSCOUNT -lt 2 ] &&
10271                 skip "skipping remote directory test" && return
10272         local MDTIDX=1
10273         local remote_dir=$DIR/$tdir/remote_dir
10274
10275         mkdir -p $DIR/$tdir
10276         $LFS mkdir -i $MDTIDX $remote_dir ||
10277                 error "create remote directory failed"
10278
10279         cp /etc/hosts $remote_dir/$tfile
10280         mkdir -p $remote_dir/foo1
10281         mkdir -p $remote_dir/foo2
10282         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10283         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10284         ln $remote_dir/$tfile $remote_dir/foo1/luna
10285         ln $remote_dir/$tfile $remote_dir/foo2/thor
10286
10287         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10288                      tr -d ']')
10289         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10290                 $LFS fid2path $DIR $FID
10291                 err17935 "bad link ea"
10292         fi
10293         # middle
10294         rm $remote_dir/foo2/zachary
10295         # last
10296         rm $remote_dir/foo2/thor
10297         # first
10298         rm $remote_dir/$tfile
10299         # rename
10300         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10301         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10302         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10303                 $LFS fid2path $DIR $FID
10304                 err17935 "bad link rename"
10305         fi
10306         rm $remote_dir/foo2/maggie
10307
10308         # overflow the EA
10309         local longname=filename_avg_len_is_thirty_two_
10310         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10311                 error "failed to hardlink many files"
10312         links=$($LFS fid2path $DIR $FID | wc -l)
10313         echo -n "${links}/1000 links in link EA"
10314         [[ ${links} -gt 60 ]] ||
10315                 err17935 "expected at least 60 links in link EA"
10316         unlinkmany $remote_dir/foo2/$longname 1000 ||
10317         error "failed to unlink many hardlinks"
10318 }
10319 run_test 161b "link ea sanity under remote directory"
10320
10321 test_161c() {
10322         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10324         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10325                 skip "Need MDS version at least 2.1.5" && return
10326
10327         # define CLF_RENAME_LAST 0x0001
10328         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10329         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10330                 changelog_register -n)
10331         rm -rf $DIR/$tdir
10332         mkdir -p $DIR/$tdir
10333         touch $DIR/$tdir/foo_161c
10334         touch $DIR/$tdir/bar_161c
10335         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10336         $LFS changelog $MDT0 | grep RENME
10337         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10338                 cut -f5 -d' ')
10339         $LFS changelog_clear $MDT0 $USER 0
10340         if [ x$flags != "x0x1" ]; then
10341                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10342                         $USER
10343                 error "flag $flags is not 0x1"
10344         fi
10345         echo "rename overwrite a target having nlink = 1," \
10346                 "changelog record has flags of $flags"
10347
10348         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10349         touch $DIR/$tdir/foo_161c
10350         touch $DIR/$tdir/bar_161c
10351         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10352         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10353         $LFS changelog $MDT0 | grep RENME
10354         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10355         $LFS changelog_clear $MDT0 $USER 0
10356         if [ x$flags != "x0x0" ]; then
10357                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10358                         $USER
10359                 error "flag $flags is not 0x0"
10360         fi
10361         echo "rename overwrite a target having nlink > 1," \
10362                 "changelog record has flags of $flags"
10363
10364         # rename doesn't overwrite a target (changelog flag 0x0)
10365         touch $DIR/$tdir/foo_161c
10366         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10367         $LFS changelog $MDT0 | grep RENME
10368         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10369         $LFS changelog_clear $MDT0 $USER 0
10370         if [ x$flags != "x0x0" ]; then
10371                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10372                         $USER
10373                 error "flag $flags is not 0x0"
10374         fi
10375         echo "rename doesn't overwrite a target," \
10376                 "changelog record has flags of $flags"
10377
10378         # define CLF_UNLINK_LAST 0x0001
10379         # unlink a file having nlink = 1 (changelog flag 0x1)
10380         rm -f $DIR/$tdir/foo2_161c
10381         $LFS changelog $MDT0 | grep UNLNK
10382         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10383         $LFS changelog_clear $MDT0 $USER 0
10384         if [ x$flags != "x0x1" ]; then
10385                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10386                         $USER
10387                 error "flag $flags is not 0x1"
10388         fi
10389         echo "unlink a file having nlink = 1," \
10390                 "changelog record has flags of $flags"
10391
10392         # unlink a file having nlink > 1 (changelog flag 0x0)
10393         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10394         rm -f $DIR/$tdir/foobar_161c
10395         $LFS changelog $MDT0 | grep UNLNK
10396         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10397         $LFS changelog_clear $MDT0 $USER 0
10398         if [ x$flags != "x0x0" ]; then
10399                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10400                         $USER
10401                 error "flag $flags is not 0x0"
10402         fi
10403         echo "unlink a file having nlink > 1," \
10404                 "changelog record has flags of $flags"
10405         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10406 }
10407 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10408
10409 check_path() {
10410     local expected=$1
10411     shift
10412     local fid=$2
10413
10414     local path=$(${LFS} fid2path $*)
10415     RC=$?
10416
10417     if [ $RC -ne 0 ]; then
10418         err17935 "path looked up of $expected failed. Error $RC"
10419         return $RC
10420     elif [ "${path}" != "${expected}" ]; then
10421         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10422         return 2
10423     fi
10424     echo "fid $fid resolves to path $path (expected $expected)"
10425 }
10426
10427 test_162() {
10428         # Make changes to filesystem
10429         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10430         test_mkdir -p -c1 $DIR/$tdir/d2
10431         touch $DIR/$tdir/d2/$tfile
10432         touch $DIR/$tdir/d2/x1
10433         touch $DIR/$tdir/d2/x2
10434         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10435         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10436         # regular file
10437         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10438         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10439                 error "check path $tdir/d2/$tfile failed"
10440
10441         # softlink
10442         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10443         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10444         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10445                 error "check path $tdir/d2/p/q/r/slink failed"
10446
10447         # softlink to wrong file
10448         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10449         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10450         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10451                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10452
10453         # hardlink
10454         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10455         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10456         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10457         # fid2path dir/fsname should both work
10458         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10459                 error "check path $tdir/d2/a/b/c/new_file failed"
10460         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10461                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10462
10463         # hardlink count: check that there are 2 links
10464         # Doesnt work with CMD yet: 17935
10465         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10466                 err17935 "expected 2 links"
10467
10468         # hardlink indexing: remove the first link
10469         rm $DIR/$tdir/d2/p/q/r/hlink
10470         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10471                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10472
10473         return 0
10474 }
10475 run_test 162 "path lookup sanity"
10476
10477 test_162b() {
10478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10479         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10480
10481         mkdir $DIR/$tdir
10482         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10483                                 error "create striped dir failed"
10484
10485         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10486                                         tail -n 1 | awk '{print $2}')
10487         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10488
10489         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10490         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10491
10492         # regular file
10493         for ((i=0;i<5;i++)); do
10494                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10495                         error "get fid for f$i failed"
10496                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10497                         error "check path $tdir/striped_dir/f$i failed"
10498
10499                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10500                         error "get fid for d$i failed"
10501                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10502                         error "check path $tdir/striped_dir/d$i failed"
10503         done
10504
10505         return 0
10506 }
10507 run_test 162b "striped directory path lookup sanity"
10508
10509 test_169() {
10510         # do directio so as not to populate the page cache
10511         log "creating a 10 Mb file"
10512         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10513         log "starting reads"
10514         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10515         log "truncating the file"
10516         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10517         log "killing dd"
10518         kill %+ || true # reads might have finished
10519         echo "wait until dd is finished"
10520         wait
10521         log "removing the temporary file"
10522         rm -rf $DIR/$tfile || error "tmp file removal failed"
10523 }
10524 run_test 169 "parallel read and truncate should not deadlock"
10525
10526 test_170() {
10527         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10528         $LCTL clear     # bug 18514
10529         $LCTL debug_daemon start $TMP/${tfile}_log_good
10530         touch $DIR/$tfile
10531         $LCTL debug_daemon stop
10532         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10533                error "sed failed to read log_good"
10534
10535         $LCTL debug_daemon start $TMP/${tfile}_log_good
10536         rm -rf $DIR/$tfile
10537         $LCTL debug_daemon stop
10538
10539         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10540                error "lctl df log_bad failed"
10541
10542         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10543         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10544
10545         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10546         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10547
10548         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10549                 error "bad_line good_line1 good_line2 are empty"
10550
10551         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10552         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10553         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10554
10555         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10556         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10557         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10558
10559         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10560                 error "bad_line_new good_line_new are empty"
10561
10562         local expected_good=$((good_line1 + good_line2*2))
10563
10564         rm -f $TMP/${tfile}*
10565         # LU-231, short malformed line may not be counted into bad lines
10566         if [ $bad_line -ne $bad_line_new ] &&
10567                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10568                 error "expected $bad_line bad lines, but got $bad_line_new"
10569                 return 1
10570         fi
10571
10572         if [ $expected_good -ne $good_line_new ]; then
10573                 error "expected $expected_good good lines, but got $good_line_new"
10574                 return 2
10575         fi
10576         true
10577 }
10578 run_test 170 "test lctl df to handle corrupted log ====================="
10579
10580 test_171() { # bug20592
10581         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10582 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10583         $LCTL set_param fail_loc=0x50e
10584         $LCTL set_param fail_val=3000
10585         multiop_bg_pause $DIR/$tfile O_s || true
10586         local MULTIPID=$!
10587         kill -USR1 $MULTIPID
10588         # cause log dump
10589         sleep 3
10590         wait $MULTIPID
10591         if dmesg | grep "recursive fault"; then
10592                 error "caught a recursive fault"
10593         fi
10594         $LCTL set_param fail_loc=0
10595         true
10596 }
10597 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10598
10599 # it would be good to share it with obdfilter-survey/iokit-libecho code
10600 setup_obdecho_osc () {
10601         local rc=0
10602         local ost_nid=$1
10603         local obdfilter_name=$2
10604         echo "Creating new osc for $obdfilter_name on $ost_nid"
10605         # make sure we can find loopback nid
10606         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10607
10608         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10609                            ${obdfilter_name}_osc_UUID || rc=2; }
10610         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10611                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10612         return $rc
10613 }
10614
10615 cleanup_obdecho_osc () {
10616         local obdfilter_name=$1
10617         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10618         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10619         return 0
10620 }
10621
10622 obdecho_test() {
10623         local OBD=$1
10624         local node=$2
10625         local pages=${3:-64}
10626         local rc=0
10627         local id
10628
10629         local count=10
10630         local obd_size=$(get_obd_size $node $OBD)
10631         local page_size=$(get_page_size $node)
10632         if [[ -n "$obd_size" ]]; then
10633                 local new_count=$((obd_size / (pages * page_size / 1024)))
10634                 [[ $new_count -ge $count ]] || count=$new_count
10635         fi
10636
10637         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10638         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10639                            rc=2; }
10640         if [ $rc -eq 0 ]; then
10641             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10642             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10643         fi
10644         echo "New object id is $id"
10645         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10646                            rc=4; }
10647         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10648                            "test_brw $count w v $pages $id" || rc=4; }
10649         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10650                            rc=4; }
10651         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10652                                         "cleanup" || rc=5; }
10653         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10654                                         "detach" || rc=6; }
10655         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10656         return $rc
10657 }
10658
10659 test_180a() {
10660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10661         remote_ost_nodsh && skip "remote OST with nodsh" && return
10662         local rc=0
10663         local rmmod_local=0
10664
10665         if ! module_loaded obdecho; then
10666             load_module obdecho/obdecho
10667             rmmod_local=1
10668         fi
10669
10670         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10671         local host=$(lctl get_param -n osc.$osc.import |
10672                              awk '/current_connection:/ {print $2}' )
10673         local target=$(lctl get_param -n osc.$osc.import |
10674                              awk '/target:/ {print $2}' )
10675         target=${target%_UUID}
10676
10677         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10678         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10679         [[ -n $target ]] && cleanup_obdecho_osc $target
10680         [ $rmmod_local -eq 1 ] && rmmod obdecho
10681         return $rc
10682 }
10683 run_test 180a "test obdecho on osc"
10684
10685 test_180b() {
10686         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10687         remote_ost_nodsh && skip "remote OST with nodsh" && return
10688         local rc=0
10689         local rmmod_remote=0
10690
10691         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10692                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10693                       "modprobe obdecho; }" && rmmod_remote=1
10694         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10695         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10696         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10697         return $rc
10698 }
10699 run_test 180b "test obdecho directly on obdfilter"
10700
10701 test_180c() { # LU-2598
10702         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10703         remote_ost_nodsh && skip "remote OST with nodsh" && return
10704         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10705                 skip "Need MDS version at least 2.4.0" && return
10706
10707         local rc=0
10708         local rmmod_remote=false
10709         local pages=16384 # 64MB bulk I/O RPC size
10710         local target
10711
10712         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10713                 rmmod_remote=true || error "failed to load module obdecho"
10714
10715         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10716                 head -n1)
10717         if [ -n "$target" ]; then
10718                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10719         else
10720                 echo "there is no obdfilter target on ost1"
10721                 rc=2
10722         fi
10723         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10724         return $rc
10725 }
10726 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10727
10728 test_181() { # bug 22177
10729         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10730         # create enough files to index the directory
10731         createmany -o $DIR/$tdir/foobar 4000
10732         # print attributes for debug purpose
10733         lsattr -d .
10734         # open dir
10735         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10736         MULTIPID=$!
10737         # remove the files & current working dir
10738         unlinkmany $DIR/$tdir/foobar 4000
10739         rmdir $DIR/$tdir
10740         kill -USR1 $MULTIPID
10741         wait $MULTIPID
10742         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10743         return 0
10744 }
10745 run_test 181 "Test open-unlinked dir ========================"
10746
10747 test_182() {
10748         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10749         # disable MDC RPC lock wouldn't crash client
10750         local fcount=1000
10751         local tcount=4
10752
10753         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10754 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10755         $LCTL set_param fail_loc=0x804
10756
10757         for (( i=0; i < $tcount; i++ )) ; do
10758                 mkdir $DIR/$tdir/$i
10759                 createmany -o $DIR/$tdir/$i/f- $fcount &
10760         done
10761         wait
10762
10763         for (( i=0; i < $tcount; i++ )) ; do
10764                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10765         done
10766         wait
10767
10768         rm -rf $DIR/$tdir
10769
10770         $LCTL set_param fail_loc=0
10771 }
10772 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10773
10774 test_183() { # LU-2275
10775         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10776         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10777                 skip "Need MDS version at least 2.3.56" && return
10778
10779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10780         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10781         echo aaa > $DIR/$tdir/$tfile
10782
10783 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10784         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10785
10786         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10787         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10788
10789         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10790
10791         # Flush negative dentry cache
10792         touch $DIR/$tdir/$tfile
10793
10794         # We are not checking for any leaked references here, they'll
10795         # become evident next time we do cleanup with module unload.
10796         rm -rf $DIR/$tdir
10797 }
10798 run_test 183 "No crash or request leak in case of strange dispositions ========"
10799
10800 # test suite 184 is for LU-2016, LU-2017
10801 test_184a() {
10802         check_swap_layouts_support && return 0
10803
10804         dir0=$DIR/$tdir/$testnum
10805         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10806         ref1=/etc/passwd
10807         ref2=/etc/group
10808         file1=$dir0/f1
10809         file2=$dir0/f2
10810         $SETSTRIPE -c1 $file1
10811         cp $ref1 $file1
10812         $SETSTRIPE -c2 $file2
10813         cp $ref2 $file2
10814         gen1=$($GETSTRIPE -g $file1)
10815         gen2=$($GETSTRIPE -g $file2)
10816
10817         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10818         gen=$($GETSTRIPE -g $file1)
10819         [[ $gen1 != $gen ]] ||
10820                 "Layout generation on $file1 does not change"
10821         gen=$($GETSTRIPE -g $file2)
10822         [[ $gen2 != $gen ]] ||
10823                 "Layout generation on $file2 does not change"
10824
10825         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10826         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10827 }
10828 run_test 184a "Basic layout swap"
10829
10830 test_184b() {
10831         check_swap_layouts_support && return 0
10832
10833         dir0=$DIR/$tdir/$testnum
10834         mkdir -p $dir0 || error "creating dir $dir0"
10835         file1=$dir0/f1
10836         file2=$dir0/f2
10837         file3=$dir0/f3
10838         dir1=$dir0/d1
10839         dir2=$dir0/d2
10840         mkdir $dir1 $dir2
10841         $SETSTRIPE -c1 $file1
10842         $SETSTRIPE -c2 $file2
10843         $SETSTRIPE -c1 $file3
10844         chown $RUNAS_ID $file3
10845         gen1=$($GETSTRIPE -g $file1)
10846         gen2=$($GETSTRIPE -g $file2)
10847
10848         $LFS swap_layouts $dir1 $dir2 &&
10849                 error "swap of directories layouts should fail"
10850         $LFS swap_layouts $dir1 $file1 &&
10851                 error "swap of directory and file layouts should fail"
10852         $RUNAS $LFS swap_layouts $file1 $file2 &&
10853                 error "swap of file we cannot write should fail"
10854         $LFS swap_layouts $file1 $file3 &&
10855                 error "swap of file with different owner should fail"
10856         /bin/true # to clear error code
10857 }
10858 run_test 184b "Forbidden layout swap (will generate errors)"
10859
10860 test_184c() {
10861         check_swap_layouts_support && return 0
10862
10863         local dir0=$DIR/$tdir/$testnum
10864         mkdir -p $dir0 || error "creating dir $dir0"
10865
10866         local ref1=$dir0/ref1
10867         local ref2=$dir0/ref2
10868         local file1=$dir0/file1
10869         local file2=$dir0/file2
10870         # create a file large enough for the concurent test
10871         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10872         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10873         echo "ref file size: ref1($(stat -c %s $ref1))," \
10874              "ref2($(stat -c %s $ref2))"
10875
10876         cp $ref2 $file2
10877         dd if=$ref1 of=$file1 bs=16k &
10878         local DD_PID=$!
10879
10880         # Make sure dd starts to copy file
10881         while [ ! -f $file1 ]; do sleep 0.1; done
10882
10883         $LFS swap_layouts $file1 $file2
10884         local rc=$?
10885         wait $DD_PID
10886         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10887         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10888
10889         # how many bytes copied before swapping layout
10890         local copied=$(stat -c %s $file2)
10891         local remaining=$(stat -c %s $ref1)
10892         remaining=$((remaining - copied))
10893         echo "Copied $copied bytes before swapping layout..."
10894
10895         cmp -n $copied $file1 $ref2 | grep differ &&
10896                 error "Content mismatch [0, $copied) of ref2 and file1"
10897         cmp -n $copied $file2 $ref1 ||
10898                 error "Content mismatch [0, $copied) of ref1 and file2"
10899         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10900                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10901
10902         # clean up
10903         rm -f $ref1 $ref2 $file1 $file2
10904 }
10905 run_test 184c "Concurrent write and layout swap"
10906
10907 test_184d() {
10908         check_swap_layouts_support && return 0
10909         [ -z "$(which getfattr 2>/dev/null)" ] &&
10910                 skip "no getfattr command" && return 0
10911
10912         local file1=$DIR/$tdir/$tfile-1
10913         local file2=$DIR/$tdir/$tfile-2
10914         local file3=$DIR/$tdir/$tfile-3
10915         local lovea1
10916         local lovea2
10917
10918         mkdir -p $DIR/$tdir
10919         touch $file1 || error "create $file1 failed"
10920         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10921                 error "create $file2 failed"
10922         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10923                 error "create $file3 failed"
10924         lovea1=$($LFS getstripe $file1 | sed 1d)
10925
10926         $LFS swap_layouts $file2 $file3 ||
10927                 error "swap $file2 $file3 layouts failed"
10928         $LFS swap_layouts $file1 $file2 ||
10929                 error "swap $file1 $file2 layouts failed"
10930
10931         lovea2=$($LFS getstripe $file2 | sed 1d)
10932         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10933
10934         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10935         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10936 }
10937 run_test 184d "allow stripeless layouts swap"
10938
10939
10940 test_185() { # LU-2441
10941         # LU-3553 - no volatile file support in old servers
10942         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10943                 { skip "Need MDS version at least 2.3.60"; return 0; }
10944
10945         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10946         touch $DIR/$tdir/spoo
10947         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10948         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10949                 error "cannot create/write a volatile file"
10950         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10951                 error "FID is still valid after close"
10952
10953         multiop_bg_pause $DIR/$tdir vVw4096_c
10954         local multi_pid=$!
10955
10956         local OLD_IFS=$IFS
10957         IFS=":"
10958         local fidv=($fid)
10959         IFS=$OLD_IFS
10960         # assume that the next FID for this client is sequential, since stdout
10961         # is unfortunately eaten by multiop_bg_pause
10962         local n=$((${fidv[1]} + 1))
10963         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10964         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10965                 error "FID is missing before close"
10966         kill -USR1 $multi_pid
10967         # 1 second delay, so if mtime change we will see it
10968         sleep 1
10969         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10970         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10971 }
10972 run_test 185 "Volatile file support"
10973
10974 test_187a() {
10975         local dir0=$DIR/$tdir/$testnum
10976         mkdir -p $dir0 || error "creating dir $dir0"
10977
10978         local file=$dir0/file1
10979         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10980         local dv1=$($LFS data_version $file)
10981         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10982         local dv2=$($LFS data_version $file)
10983         [[ $dv1 != $dv2 ]] ||
10984                 error "data version did not change on write $dv1 == $dv2"
10985
10986         # clean up
10987         rm -f $file1
10988 }
10989 run_test 187a "Test data version change"
10990
10991 test_187b() {
10992         local dir0=$DIR/$tdir/$testnum
10993         mkdir -p $dir0 || error "creating dir $dir0"
10994
10995         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10996         [[ ${DV[0]} != ${DV[1]} ]] ||
10997                 error "data version did not change on write"\
10998                       " ${DV[0]} == ${DV[1]}"
10999
11000         # clean up
11001         rm -f $file1
11002 }
11003 run_test 187b "Test data version change on volatile file"
11004
11005 test_200() {
11006         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11007         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11008
11009         local POOL=${POOL:-cea1}
11010         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11011         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11012         # Pool OST targets
11013         local first_ost=0
11014         local last_ost=$(($OSTCOUNT - 1))
11015         local ost_step=2
11016         local ost_list=$(seq $first_ost $ost_step $last_ost)
11017         local ost_range="$first_ost $last_ost $ost_step"
11018         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11019         local file_dir=$POOL_ROOT/file_tst
11020
11021         local rc=0
11022         while : ; do
11023                 # former test_200a test_200b
11024                 pool_add $POOL                          || { rc=$? ; break; }
11025                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11026                 # former test_200c test_200d
11027                 mkdir -p $test_path
11028                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11029                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11030                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11031                                                         || { rc=$? ; break; }
11032                 # former test_200e test_200f
11033                 local files=$((OSTCOUNT*3))
11034                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11035                                                         || { rc=$? ; break; }
11036                 pool_create_files $POOL $file_dir $files "$ost_list" \
11037                                                         || { rc=$? ; break; }
11038                 # former test_200g test_200h
11039                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11040                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11041
11042                 # former test_201a test_201b test_201c
11043                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11044
11045                 local f=$test_path/$tfile
11046                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11047                 pool_remove $POOL $f                    || { rc=$? ; break; }
11048                 break
11049         done
11050
11051         cleanup_pools
11052         return $rc
11053 }
11054 run_test 200 "OST pools"
11055
11056 # usage: default_attr <count | size | offset>
11057 default_attr() {
11058         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11059 }
11060
11061 # usage: check_default_stripe_attr
11062 check_default_stripe_attr() {
11063         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11064         case $1 in
11065         --stripe-count|--count)
11066                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11067         --stripe-size|--size)
11068                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11069         --stripe-index|--index)
11070                 EXPECTED=-1;;
11071         *)
11072                 error "unknown getstripe attr '$1'"
11073         esac
11074
11075         [ $ACTUAL != $EXPECTED ] &&
11076                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11077 }
11078
11079 test_204a() {
11080         test_mkdir -p $DIR/$tdir
11081         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11082
11083         check_default_stripe_attr --stripe-count
11084         check_default_stripe_attr --stripe-size
11085         check_default_stripe_attr --stripe-index
11086
11087         return 0
11088 }
11089 run_test 204a "Print default stripe attributes ================="
11090
11091 test_204b() {
11092         test_mkdir -p $DIR/$tdir
11093         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11094
11095         check_default_stripe_attr --stripe-size
11096         check_default_stripe_attr --stripe-index
11097
11098         return 0
11099 }
11100 run_test 204b "Print default stripe size and offset  ==========="
11101
11102 test_204c() {
11103         test_mkdir -p $DIR/$tdir
11104         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11105
11106         check_default_stripe_attr --stripe-count
11107         check_default_stripe_attr --stripe-index
11108
11109         return 0
11110 }
11111 run_test 204c "Print default stripe count and offset ==========="
11112
11113 test_204d() {
11114         test_mkdir -p $DIR/$tdir
11115         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11116
11117         check_default_stripe_attr --stripe-count
11118         check_default_stripe_attr --stripe-size
11119
11120         return 0
11121 }
11122 run_test 204d "Print default stripe count and size ============="
11123
11124 test_204e() {
11125         test_mkdir -p $DIR/$tdir
11126         $SETSTRIPE -d $DIR/$tdir
11127
11128         check_default_stripe_attr --stripe-count --raw
11129         check_default_stripe_attr --stripe-size --raw
11130         check_default_stripe_attr --stripe-index --raw
11131
11132         return 0
11133 }
11134 run_test 204e "Print raw stripe attributes ================="
11135
11136 test_204f() {
11137         test_mkdir -p $DIR/$tdir
11138         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11139
11140         check_default_stripe_attr --stripe-size --raw
11141         check_default_stripe_attr --stripe-index --raw
11142
11143         return 0
11144 }
11145 run_test 204f "Print raw stripe size and offset  ==========="
11146
11147 test_204g() {
11148         test_mkdir -p $DIR/$tdir
11149         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11150
11151         check_default_stripe_attr --stripe-count --raw
11152         check_default_stripe_attr --stripe-index --raw
11153
11154         return 0
11155 }
11156 run_test 204g "Print raw stripe count and offset ==========="
11157
11158 test_204h() {
11159         test_mkdir -p $DIR/$tdir
11160         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11161
11162         check_default_stripe_attr --stripe-count --raw
11163         check_default_stripe_attr --stripe-size --raw
11164
11165         return 0
11166 }
11167 run_test 204h "Print raw stripe count and size ============="
11168
11169 # Figure out which job scheduler is being used, if any,
11170 # or use a fake one
11171 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11172         JOBENV=SLURM_JOB_ID
11173 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11174         JOBENV=LSB_JOBID
11175 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11176         JOBENV=PBS_JOBID
11177 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11178         JOBENV=LOADL_STEP_ID
11179 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11180         JOBENV=JOB_ID
11181 else
11182         JOBENV=FAKE_JOBID
11183 fi
11184
11185 verify_jobstats() {
11186         local cmd=$1
11187         local target=$2
11188
11189         # clear old jobstats
11190         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11191         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11192
11193         # use a new JobID for this test, or we might see an old one
11194         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11195
11196         JOBVAL=${!JOBENV}
11197         log "Test: $cmd"
11198         log "Using JobID environment variable $JOBENV=$JOBVAL"
11199
11200         if [ $JOBENV = "FAKE_JOBID" ]; then
11201                 FAKE_JOBID=$JOBVAL $cmd
11202         else
11203                 $cmd
11204         fi
11205
11206         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11207                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11208                 do_facet $FACET lctl get_param mdt.*.job_stats |
11209                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11210         fi
11211         if [ "$target" = "ost" -o "$target" = "both" ]; then
11212                 FACET=ost1
11213                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11214                         grep $JOBVAL || error "No job stats found on OST $FACET"
11215         fi
11216 }
11217
11218 jobstats_set() {
11219         trap 0
11220         NEW_JOBENV=${1:-$OLD_JOBENV}
11221         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11222         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11223 }
11224
11225 test_205() { # Job stats
11226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11227         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11228         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11229                 skip "Server doesn't support jobstats" && return 0
11230         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11231
11232         local cmd
11233         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11234         if [ $OLD_JOBENV != $JOBENV ]; then
11235                 jobstats_set $JOBENV
11236                 trap jobstats_set EXIT
11237         fi
11238
11239         # mkdir
11240         cmd="mkdir $DIR/$tfile"
11241         verify_jobstats "$cmd" "mdt"
11242         # rmdir
11243         cmd="rm -fr $DIR/$tfile"
11244         verify_jobstats "$cmd" "mdt"
11245         # mknod
11246         cmd="mknod $DIR/$tfile c 1 3"
11247         verify_jobstats "$cmd" "mdt"
11248         # unlink
11249         cmd="rm -f $DIR/$tfile"
11250         verify_jobstats "$cmd" "mdt"
11251         # open & close
11252         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11253         verify_jobstats "$cmd" "mdt"
11254         # setattr
11255         cmd="touch $DIR/$tfile"
11256         verify_jobstats "$cmd" "both"
11257         # write
11258         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11259         verify_jobstats "$cmd" "ost"
11260         # read
11261         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11262         verify_jobstats "$cmd" "ost"
11263         # truncate
11264         cmd="$TRUNCATE $DIR/$tfile 0"
11265         verify_jobstats "$cmd" "both"
11266         # rename
11267         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11268         verify_jobstats "$cmd" "mdt"
11269
11270         # cleanup
11271         rm -f $DIR/jobstats_test_rename
11272
11273         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11274 }
11275 run_test 205 "Verify job stats"
11276
11277 # LU-1480, LU-1773 and LU-1657
11278 test_206() {
11279         mkdir -p $DIR/$tdir
11280         $SETSTRIPE -c -1 $DIR/$tdir
11281 #define OBD_FAIL_LOV_INIT 0x1403
11282         $LCTL set_param fail_loc=0xa0001403
11283         $LCTL set_param fail_val=1
11284         touch $DIR/$tdir/$tfile || true
11285 }
11286 run_test 206 "fail lov_init_raid0() doesn't lbug"
11287
11288 test_207a() {
11289         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11290         local fsz=`stat -c %s $DIR/$tfile`
11291         cancel_lru_locks mdc
11292
11293         # do not return layout in getattr intent
11294 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11295         $LCTL set_param fail_loc=0x170
11296         local sz=`stat -c %s $DIR/$tfile`
11297
11298         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11299
11300         rm -rf $DIR/$tfile
11301 }
11302 run_test 207a "can refresh layout at glimpse"
11303
11304 test_207b() {
11305         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11306         local cksum=`md5sum $DIR/$tfile`
11307         local fsz=`stat -c %s $DIR/$tfile`
11308         cancel_lru_locks mdc
11309         cancel_lru_locks osc
11310
11311         # do not return layout in getattr intent
11312 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11313         $LCTL set_param fail_loc=0x171
11314
11315         # it will refresh layout after the file is opened but before read issues
11316         echo checksum is "$cksum"
11317         echo "$cksum" |md5sum -c --quiet || error "file differs"
11318
11319         rm -rf $DIR/$tfile
11320 }
11321 run_test 207b "can refresh layout at open"
11322
11323 test_208() {
11324         # FIXME: in this test suite, only RD lease is used. This is okay
11325         # for now as only exclusive open is supported. After generic lease
11326         # is done, this test suite should be revised. - Jinshan
11327
11328         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11329                 { skip "Need MDS version at least 2.4.52"; return 0; }
11330         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11331
11332         echo "==== test 1: verify get lease work"
11333         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11334
11335         echo "==== test 2: verify lease can be broken by upcoming open"
11336         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11337         local PID=$!
11338         sleep 1
11339
11340         $MULTIOP $DIR/$tfile oO_RDONLY:c
11341         kill -USR1 $PID && wait $PID || error "break lease error"
11342
11343         echo "==== test 3: verify lease can't be granted if an open already exists"
11344         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11345         local PID=$!
11346         sleep 1
11347
11348         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11349         kill -USR1 $PID && wait $PID || error "open file error"
11350
11351         echo "==== test 4: lease can sustain over recovery"
11352         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11353         PID=$!
11354         sleep 1
11355
11356         fail mds1
11357
11358         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11359
11360         echo "==== test 5: lease broken can't be regained by replay"
11361         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11362         PID=$!
11363         sleep 1
11364
11365         # open file to break lease and then recovery
11366         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11367         fail mds1
11368
11369         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11370
11371         rm -f $DIR/$tfile
11372 }
11373 run_test 208 "Exclusive open"
11374
11375 test_209() {
11376         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11377                 skip_env "must have disp_stripe" && return
11378
11379         touch $DIR/$tfile
11380         sync; sleep 5; sync;
11381
11382         echo 3 > /proc/sys/vm/drop_caches
11383         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11384
11385         # open/close 500 times
11386         for i in $(seq 500); do
11387                 cat $DIR/$tfile
11388         done
11389
11390         echo 3 > /proc/sys/vm/drop_caches
11391         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11392
11393         echo "before: $req_before, after: $req_after"
11394         [ $((req_after - req_before)) -ge 300 ] &&
11395                 error "open/close requests are not freed"
11396         return 0
11397 }
11398 run_test 209 "read-only open/close requests should be freed promptly"
11399
11400 test_212() {
11401         size=`date +%s`
11402         size=$((size % 8192 + 1))
11403         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11404         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11405         rm -f $DIR/f212 $DIR/f212.xyz
11406 }
11407 run_test 212 "Sendfile test ============================================"
11408
11409 test_213() {
11410         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11411         cancel_lru_locks osc
11412         lctl set_param fail_loc=0x8000040f
11413         # generate a read lock
11414         cat $DIR/$tfile > /dev/null
11415         # write to the file, it will try to cancel the above read lock.
11416         cat /etc/hosts >> $DIR/$tfile
11417 }
11418 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11419
11420 test_214() { # for bug 20133
11421         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11422         for (( i=0; i < 340; i++ )) ; do
11423                 touch $DIR/$tdir/d214c/a$i
11424         done
11425
11426         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11427         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11428         ls $DIR/d214c || error "ls $DIR/d214c failed"
11429         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11430         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11431 }
11432 run_test 214 "hash-indexed directory test - bug 20133"
11433
11434 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11435 create_lnet_proc_files() {
11436         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11437         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11438
11439         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11440         rm -f "$TMP/lnet_$1.sys_tmp"
11441 }
11442
11443 # counterpart of create_lnet_proc_files
11444 remove_lnet_proc_files() {
11445         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11446 }
11447
11448 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11449 # 3rd arg as regexp for body
11450 check_lnet_proc_stats() {
11451         local l=$(cat "$TMP/lnet_$1" |wc -l)
11452         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11453
11454         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11455 }
11456
11457 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11458 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11459 # optional and can be regexp for 2nd line (lnet.routes case)
11460 check_lnet_proc_entry() {
11461         local blp=2          # blp stands for 'position of 1st line of body'
11462         [ -z "$5" ] || blp=3 # lnet.routes case
11463
11464         local l=$(cat "$TMP/lnet_$1" |wc -l)
11465         # subtracting one from $blp because the body can be empty
11466         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11467
11468         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11469                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11470
11471         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11472                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11473
11474         # bail out if any unexpected line happened
11475         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11476         [ "$?" != 0 ] || error "$2 misformatted"
11477 }
11478
11479 test_215() { # for bugs 18102, 21079, 21517
11480         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11481         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11482         local P='[1-9][0-9]*'           # positive numeric
11483         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11484         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11485         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11486         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11487
11488         local L1 # regexp for 1st line
11489         local L2 # regexp for 2nd line (optional)
11490         local BR # regexp for the rest (body)
11491
11492         # lnet.stats should look as 11 space-separated non-negative numerics
11493         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11494         create_lnet_proc_files "stats"
11495         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11496         remove_lnet_proc_files "stats"
11497
11498         # lnet.routes should look like this:
11499         # Routing disabled/enabled
11500         # net hops priority state router
11501         # where net is a string like tcp0, hops > 0, priority >= 0,
11502         # state is up/down,
11503         # router is a string like 192.168.1.1@tcp2
11504         L1="^Routing (disabled|enabled)$"
11505         L2="^net +hops +priority +state +router$"
11506         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11507         create_lnet_proc_files "routes"
11508         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11509         remove_lnet_proc_files "routes"
11510
11511         # lnet.routers should look like this:
11512         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11513         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11514         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11515         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11516         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11517         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11518         create_lnet_proc_files "routers"
11519         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11520         remove_lnet_proc_files "routers"
11521
11522         # lnet.peers should look like this:
11523         # nid refs state last max rtr min tx min queue
11524         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11525         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11526         # numeric (0 or >0 or <0), queue >= 0.
11527         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11528         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11529         create_lnet_proc_files "peers"
11530         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11531         remove_lnet_proc_files "peers"
11532
11533         # lnet.buffers  should look like this:
11534         # pages count credits min
11535         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11536         L1="^pages +count +credits +min$"
11537         BR="^ +$N +$N +$I +$I$"
11538         create_lnet_proc_files "buffers"
11539         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11540         remove_lnet_proc_files "buffers"
11541
11542         # lnet.nis should look like this:
11543         # nid status alive refs peer rtr max tx min
11544         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11545         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11546         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11547         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11548         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11549         create_lnet_proc_files "nis"
11550         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11551         remove_lnet_proc_files "nis"
11552
11553         # can we successfully write to lnet.stats?
11554         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11555         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11556 }
11557 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11558
11559 test_216() { # bug 20317
11560         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11561         remote_ost_nodsh && skip "remote OST with nodsh" && return
11562
11563         local node
11564         local facets=$(get_facets OST)
11565         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11566
11567         save_lustre_params client "osc.*.contention_seconds" > $p
11568         save_lustre_params $facets \
11569                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11570         save_lustre_params $facets \
11571                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11572         save_lustre_params $facets \
11573                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11574         clear_osc_stats
11575
11576         # agressive lockless i/o settings
11577         for node in $(osts_nodes); do
11578                 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'
11579         done
11580         lctl set_param -n osc.*.contention_seconds 60
11581
11582         $DIRECTIO write $DIR/$tfile 0 10 4096
11583         $CHECKSTAT -s 40960 $DIR/$tfile
11584
11585         # disable lockless i/o
11586         for node in $(osts_nodes); do
11587                 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'
11588         done
11589         lctl set_param -n osc.*.contention_seconds 0
11590         clear_osc_stats
11591
11592         dd if=/dev/zero of=$DIR/$tfile count=0
11593         $CHECKSTAT -s 0 $DIR/$tfile
11594
11595         restore_lustre_params <$p
11596         rm -f $p
11597         rm $DIR/$tfile
11598 }
11599 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11600
11601 test_217() { # bug 22430
11602         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11603         local node
11604         local nid
11605
11606         for node in $(nodes_list); do
11607                 nid=$(host_nids_address $node $NETTYPE)
11608                 if [[ $nid = *-* ]] ; then
11609                         echo "lctl ping $nid@$NETTYPE"
11610                         lctl ping $nid@$NETTYPE
11611                 else
11612                         echo "skipping $node (no hyphen detected)"
11613                 fi
11614         done
11615 }
11616 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11617
11618 test_218() {
11619        # do directio so as not to populate the page cache
11620        log "creating a 10 Mb file"
11621        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11622        log "starting reads"
11623        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11624        log "truncating the file"
11625        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11626        log "killing dd"
11627        kill %+ || true # reads might have finished
11628        echo "wait until dd is finished"
11629        wait
11630        log "removing the temporary file"
11631        rm -rf $DIR/$tfile || error "tmp file removal failed"
11632 }
11633 run_test 218 "parallel read and truncate should not deadlock ======================="
11634
11635 test_219() {
11636         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11637         # write one partial page
11638         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11639         # set no grant so vvp_io_commit_write will do sync write
11640         $LCTL set_param fail_loc=0x411
11641         # write a full page at the end of file
11642         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11643
11644         $LCTL set_param fail_loc=0
11645         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11646         $LCTL set_param fail_loc=0x411
11647         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11648
11649         # LU-4201
11650         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11651         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11652 }
11653 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11654
11655 test_220() { #LU-325
11656         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11657         remote_ost_nodsh && skip "remote OST with nodsh" && return
11658         local OSTIDX=0
11659
11660         test_mkdir -p $DIR/$tdir
11661         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11662                 awk '{print $2}' | sed -e 's/_UUID$//')
11663
11664         # on the mdt's osc
11665         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11666         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11667                         osc.$mdtosc_proc1.prealloc_last_id)
11668         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11669                         osc.$mdtosc_proc1.prealloc_next_id)
11670
11671         $LFS df -i
11672
11673         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11674         #define OBD_FAIL_OST_ENOINO              0x229
11675         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11676         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11677         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11678
11679         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11680
11681         MDSOBJS=$((last_id - next_id))
11682         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11683
11684         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11685         echo "OST still has $count kbytes free"
11686
11687         echo "create $MDSOBJS files @next_id..."
11688         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11689
11690         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11691                         osc.$mdtosc_proc1.prealloc_last_id)
11692         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11693                         osc.$mdtosc_proc1.prealloc_next_id)
11694
11695         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11696         $LFS df -i
11697
11698         echo "cleanup..."
11699
11700         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11701         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11702
11703         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11704         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11705         echo "unlink $MDSOBJS files @$next_id..."
11706         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11707 }
11708 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11709
11710 test_221() {
11711         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11712         dd if=`which date` of=$MOUNT/date oflag=sync
11713         chmod +x $MOUNT/date
11714
11715         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11716         $LCTL set_param fail_loc=0x80001401
11717
11718         $MOUNT/date > /dev/null
11719         rm -f $MOUNT/date
11720 }
11721 run_test 221 "make sure fault and truncate race to not cause OOM"
11722
11723 test_222a () {
11724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11725        rm -rf $DIR/$tdir
11726        test_mkdir -p $DIR/$tdir
11727        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11728        createmany -o $DIR/$tdir/$tfile 10
11729        cancel_lru_locks mdc
11730        cancel_lru_locks osc
11731        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11732        $LCTL set_param fail_loc=0x31a
11733        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11734        $LCTL set_param fail_loc=0
11735        rm -r $DIR/$tdir
11736 }
11737 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11738
11739 test_222b () {
11740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11741        rm -rf $DIR/$tdir
11742        test_mkdir -p $DIR/$tdir
11743        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11744        createmany -o $DIR/$tdir/$tfile 10
11745        cancel_lru_locks mdc
11746        cancel_lru_locks osc
11747        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11748        $LCTL set_param fail_loc=0x31a
11749        rm -r $DIR/$tdir || "AGL for rmdir failed"
11750        $LCTL set_param fail_loc=0
11751 }
11752 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11753
11754 test_223 () {
11755         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11756        rm -rf $DIR/$tdir
11757        test_mkdir -p $DIR/$tdir
11758        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11759        createmany -o $DIR/$tdir/$tfile 10
11760        cancel_lru_locks mdc
11761        cancel_lru_locks osc
11762        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11763        $LCTL set_param fail_loc=0x31b
11764        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11765        $LCTL set_param fail_loc=0
11766        rm -r $DIR/$tdir
11767 }
11768 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11769
11770 test_224a() { # LU-1039, MRP-303
11771         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11772         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11773         $LCTL set_param fail_loc=0x508
11774         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11775         $LCTL set_param fail_loc=0
11776         df $DIR
11777 }
11778 run_test 224a "Don't panic on bulk IO failure"
11779
11780 test_224b() { # LU-1039, MRP-303
11781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11782         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11783         cancel_lru_locks osc
11784         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11785         $LCTL set_param fail_loc=0x515
11786         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11787         $LCTL set_param fail_loc=0
11788         df $DIR
11789 }
11790 run_test 224b "Don't panic on bulk IO failure"
11791
11792 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11793 test_225a () {
11794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11795         if [ -z ${MDSSURVEY} ]; then
11796               skip_env "mds-survey not found" && return
11797         fi
11798
11799         [ $MDSCOUNT -ge 2 ] &&
11800                 skip "skipping now for more than one MDT" && return
11801
11802        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11803             { skip "Need MDS version at least 2.2.51"; return; }
11804
11805        local mds=$(facet_host $SINGLEMDS)
11806        local target=$(do_nodes $mds 'lctl dl' | \
11807                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11808
11809        local cmd1="file_count=1000 thrhi=4"
11810        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11811        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11812        local cmd="$cmd1 $cmd2 $cmd3"
11813
11814        rm -f ${TMP}/mds_survey*
11815        echo + $cmd
11816        eval $cmd || error "mds-survey with zero-stripe failed"
11817        cat ${TMP}/mds_survey*
11818        rm -f ${TMP}/mds_survey*
11819 }
11820 run_test 225a "Metadata survey sanity with zero-stripe"
11821
11822 test_225b () {
11823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11824
11825         if [ -z ${MDSSURVEY} ]; then
11826               skip_env "mds-survey not found" && return
11827         fi
11828         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11829             { skip "Need MDS version at least 2.2.51"; return; }
11830
11831         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11832               skip_env "Need to mount OST to test" && return
11833         fi
11834
11835         [ $MDSCOUNT -ge 2 ] &&
11836                 skip "skipping now for more than one MDT" && return
11837        local mds=$(facet_host $SINGLEMDS)
11838        local target=$(do_nodes $mds 'lctl dl' | \
11839                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11840
11841        local cmd1="file_count=1000 thrhi=4"
11842        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11843        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11844        local cmd="$cmd1 $cmd2 $cmd3"
11845
11846        rm -f ${TMP}/mds_survey*
11847        echo + $cmd
11848        eval $cmd || error "mds-survey with stripe_count failed"
11849        cat ${TMP}/mds_survey*
11850        rm -f ${TMP}/mds_survey*
11851 }
11852 run_test 225b "Metadata survey sanity with stripe_count = 1"
11853
11854 mcreate_path2fid () {
11855         local mode=$1
11856         local major=$2
11857         local minor=$3
11858         local name=$4
11859         local desc=$5
11860         local path=$DIR/$tdir/$name
11861         local fid
11862         local rc
11863         local fid_path
11864
11865         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11866                 error "cannot create $desc"
11867
11868         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11869         rc=$?
11870         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11871
11872         fid_path=$($LFS fid2path $MOUNT $fid)
11873         rc=$?
11874         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11875
11876         [ "$path" == "$fid_path" ] ||
11877                 error "fid2path returned $fid_path, expected $path"
11878
11879         echo "pass with $path and $fid"
11880 }
11881
11882 test_226a () {
11883         rm -rf $DIR/$tdir
11884         mkdir -p $DIR/$tdir
11885
11886         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11887         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11888         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11889         mcreate_path2fid 0040666 0 0 dir "directory"
11890         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11891         mcreate_path2fid 0100666 0 0 file "regular file"
11892         mcreate_path2fid 0120666 0 0 link "symbolic link"
11893         mcreate_path2fid 0140666 0 0 sock "socket"
11894 }
11895 run_test 226a "call path2fid and fid2path on files of all type"
11896
11897 test_226b () {
11898         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11899         rm -rf $DIR/$tdir
11900         local MDTIDX=1
11901
11902         mkdir -p $DIR/$tdir
11903         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11904                 error "create remote directory failed"
11905         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11906         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11907                                 "character special file (null)"
11908         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11909                                 "character special file (no device)"
11910         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11911         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11912                                 "block special file (loop)"
11913         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11914         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11915         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11916 }
11917 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11918
11919 # LU-1299 Executing or running ldd on a truncated executable does not
11920 # cause an out-of-memory condition.
11921 test_227() {
11922         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11923         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
11924         dd if=$(which date) of=$MOUNT/date bs=1k count=1
11925         chmod +x $MOUNT/date
11926
11927         $MOUNT/date > /dev/null
11928         ldd $MOUNT/date > /dev/null
11929         rm -f $MOUNT/date
11930 }
11931 run_test 227 "running truncated executable does not cause OOM"
11932
11933 # LU-1512 try to reuse idle OI blocks
11934 test_228a() {
11935         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11936         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11937         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11938                 skip "non-ldiskfs backend" && return
11939
11940         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11941         local myDIR=$DIR/$tdir
11942
11943         mkdir -p $myDIR
11944         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11945         $LCTL set_param fail_loc=0x80001002
11946         createmany -o $myDIR/t- 10000
11947         $LCTL set_param fail_loc=0
11948         # The guard is current the largest FID holder
11949         touch $myDIR/guard
11950         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11951                     tr -d '[')
11952         local IDX=$(($SEQ % 64))
11953
11954         do_facet $SINGLEMDS sync
11955         # Make sure journal flushed.
11956         sleep 6
11957         local blk1=$(do_facet $SINGLEMDS \
11958                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11959                      grep Blockcount | awk '{print $4}')
11960
11961         # Remove old files, some OI blocks will become idle.
11962         unlinkmany $myDIR/t- 10000
11963         # Create new files, idle OI blocks should be reused.
11964         createmany -o $myDIR/t- 2000
11965         do_facet $SINGLEMDS sync
11966         # Make sure journal flushed.
11967         sleep 6
11968         local blk2=$(do_facet $SINGLEMDS \
11969                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11970                      grep Blockcount | awk '{print $4}')
11971
11972         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11973 }
11974 run_test 228a "try to reuse idle OI blocks"
11975
11976 test_228b() {
11977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11978         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11979         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11980                 skip "non-ldiskfs backend" && return
11981
11982         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11983         local myDIR=$DIR/$tdir
11984
11985         mkdir -p $myDIR
11986         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11987         $LCTL set_param fail_loc=0x80001002
11988         createmany -o $myDIR/t- 10000
11989         $LCTL set_param fail_loc=0
11990         # The guard is current the largest FID holder
11991         touch $myDIR/guard
11992         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11993                     tr -d '[')
11994         local IDX=$(($SEQ % 64))
11995
11996         do_facet $SINGLEMDS sync
11997         # Make sure journal flushed.
11998         sleep 6
11999         local blk1=$(do_facet $SINGLEMDS \
12000                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12001                      grep Blockcount | awk '{print $4}')
12002
12003         # Remove old files, some OI blocks will become idle.
12004         unlinkmany $myDIR/t- 10000
12005
12006         # stop the MDT
12007         stop $SINGLEMDS || error "Fail to stop MDT."
12008         # remount the MDT
12009         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12010
12011         df $MOUNT || error "Fail to df."
12012         # Create new files, idle OI blocks should be reused.
12013         createmany -o $myDIR/t- 2000
12014         do_facet $SINGLEMDS sync
12015         # Make sure journal flushed.
12016         sleep 6
12017         local blk2=$(do_facet $SINGLEMDS \
12018                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12019                      grep Blockcount | awk '{print $4}')
12020
12021         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12022 }
12023 run_test 228b "idle OI blocks can be reused after MDT restart"
12024
12025 #LU-1881
12026 test_228c() {
12027         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12028         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12029         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12030                 skip "non-ldiskfs backend" && return
12031
12032         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12033         local myDIR=$DIR/$tdir
12034
12035         mkdir -p $myDIR
12036         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12037         $LCTL set_param fail_loc=0x80001002
12038         # 20000 files can guarantee there are index nodes in the OI file
12039         createmany -o $myDIR/t- 20000
12040         $LCTL set_param fail_loc=0
12041         # The guard is current the largest FID holder
12042         touch $myDIR/guard
12043         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12044                     tr -d '[')
12045         local IDX=$(($SEQ % 64))
12046
12047         do_facet $SINGLEMDS sync
12048         # Make sure journal flushed.
12049         sleep 6
12050         local blk1=$(do_facet $SINGLEMDS \
12051                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12052                      grep Blockcount | awk '{print $4}')
12053
12054         # Remove old files, some OI blocks will become idle.
12055         unlinkmany $myDIR/t- 20000
12056         rm -f $myDIR/guard
12057         # The OI file should become empty now
12058
12059         # Create new files, idle OI blocks should be reused.
12060         createmany -o $myDIR/t- 2000
12061         do_facet $SINGLEMDS sync
12062         # Make sure journal flushed.
12063         sleep 6
12064         local blk2=$(do_facet $SINGLEMDS \
12065                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12066                      grep Blockcount | awk '{print $4}')
12067
12068         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12069 }
12070 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12071
12072 test_229() { # LU-2482, LU-3448
12073         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12074                 skip "No HSM support on MDS of $(get_lustre_version)," \
12075                          "need 2.4.53 at least" && return
12076         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12077         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12078
12079         rm -f $DIR/$tfile
12080
12081         # Create a file with a released layout and stripe count 2.
12082         $MULTIOP $DIR/$tfile H2c ||
12083                 error "failed to create file with released layout"
12084
12085         $GETSTRIPE -v $DIR/$tfile
12086
12087         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12088         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12089
12090         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12091         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12092         stat $DIR/$tfile || error "failed to stat released file"
12093
12094         chown $RUNAS_ID $DIR/$tfile ||
12095                 error "chown $RUNAS_ID $DIR/$tfile failed"
12096
12097         chgrp $RUNAS_ID $DIR/$tfile ||
12098                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12099
12100         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12101         rm $DIR/$tfile || error "failed to remove released file"
12102 }
12103 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12104
12105 test_230a() {
12106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12107         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12108         local MDTIDX=1
12109
12110         mkdir -p $DIR/$tdir/test_230_local
12111         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12112         [ $mdt_idx -ne 0 ] &&
12113                 error "create local directory on wrong MDT $mdt_idx"
12114
12115         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12116                         error "create remote directory failed"
12117         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12118         [ $mdt_idx -ne $MDTIDX ] &&
12119                 error "create remote directory on wrong MDT $mdt_idx"
12120
12121         createmany -o $DIR/$tdir/test_230/t- 10 ||
12122                 error "create files on remote directory failed"
12123         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12124         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12125         rm -r $DIR/$tdir || error "unlink remote directory failed"
12126 }
12127 run_test 230a "Create remote directory and files under the remote directory"
12128
12129 test_230b() {
12130         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12131         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12132         local MDTIDX=1
12133         local mdt_index
12134         local i
12135         local file
12136         local pid
12137         local stripe_count
12138         local migrate_dir=$DIR/$tdir/migrate_dir
12139         local other_dir=$DIR/$tdir/other_dir
12140
12141         mkdir -p $migrate_dir
12142         mkdir -p $other_dir
12143         for ((i=0; i<10; i++)); do
12144                 mkdir -p $migrate_dir/dir_${i}
12145                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12146                         error "create files under remote dir failed $i"
12147         done
12148
12149         cp /etc/passwd $migrate_dir/$tfile
12150         cp /etc/passwd $other_dir/$tfile
12151         chattr +SAD $migrate_dir
12152         chattr +SAD $migrate_dir/$tfile
12153
12154         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12155         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12156         local old_dir_mode=$(stat -c%f $migrate_dir)
12157         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12158
12159         mkdir -p $migrate_dir/dir_default_stripe2
12160         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12161         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12162
12163         mkdir -p $other_dir
12164         ln $migrate_dir/$tfile $other_dir/luna
12165         ln $migrate_dir/$tfile $migrate_dir/sofia
12166         ln $other_dir/$tfile $migrate_dir/david
12167         ln -s $migrate_dir/$tfile $other_dir/zachary
12168         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12169         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12170
12171         $LFS mv -v -M $MDTIDX $migrate_dir ||
12172                         error "migrate remote dir error"
12173
12174         echo "migratate to MDT1, then checking.."
12175         for ((i=0; i<10; i++)); do
12176                 for file in $(find $migrate_dir/dir_${i}); do
12177                         mdt_index=$($LFS getstripe -M $file)
12178                         [ $mdt_index == $MDTIDX ] ||
12179                                 error "$file is not on MDT${MDTIDX}"
12180                 done
12181         done
12182
12183         # the multiple link file should still in MDT0
12184         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12185         [ $mdt_index == 0 ] ||
12186                 error "$file is not on MDT${MDTIDX}"
12187
12188         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12189         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12190                 error " expect $old_dir_flag get $new_dir_flag"
12191
12192         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12193         [ "$old_file_flag" = "$new_file_flag" ] ||
12194                 error " expect $old_file_flag get $new_file_flag"
12195
12196         local new_dir_mode=$(stat -c%f $migrate_dir)
12197         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12198                 error "expect mode $old_dir_mode get $new_dir_mode"
12199
12200         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12201         [ "$old_file_mode" = "$new_file_mode" ] ||
12202                 error "expect mode $old_file_mode get $new_file_mode"
12203
12204         diff /etc/passwd $migrate_dir/$tfile ||
12205                 error "$tfile different after migration"
12206
12207         diff /etc/passwd $other_dir/luna ||
12208                 error "luna different after migration"
12209
12210         diff /etc/passwd $migrate_dir/sofia ||
12211                 error "sofia different after migration"
12212
12213         diff /etc/passwd $migrate_dir/david ||
12214                 error "david different after migration"
12215
12216         diff /etc/passwd $other_dir/zachary ||
12217                 error "zachary different after migration"
12218
12219         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12220                 error "${tfile}_ln different after migration"
12221
12222         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12223                 error "${tfile}_ln_other different after migration"
12224
12225         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12226         [ $stripe_count = 2 ] ||
12227                         error "dir strpe_count $d != 2 after migration."
12228
12229         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12230         [ $stripe_count = 2 ] ||
12231                         error "file strpe_count $d != 2 after migration."
12232
12233         #migrate back to MDT0
12234         MDTIDX=0
12235         $LFS mv -v -M $MDTIDX $migrate_dir ||
12236                         error "migrate remote dir error"
12237
12238         echo "migrate back to MDT0, checking.."
12239         for file in $(find $migrate_dir); do
12240                 mdt_index=$($LFS getstripe -M $file)
12241                 [ $mdt_index == $MDTIDX ] ||
12242                         error "$file is not on MDT${MDTIDX}"
12243         done
12244
12245         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12246         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12247                 error " expect $old_dir_flag get $new_dir_flag"
12248
12249         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12250         [ "$old_file_flag" = "$new_file_flag" ] ||
12251                 error " expect $old_file_flag get $new_file_flag"
12252
12253         local new_dir_mode=$(stat -c%f $migrate_dir)
12254         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12255                 error "expect mode $old_dir_mode get $new_dir_mode"
12256
12257         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12258         [ "$old_file_mode" = "$new_file_mode" ] ||
12259                 error "expect mode $old_file_mode get $new_file_mode"
12260
12261         diff /etc/passwd ${migrate_dir}/$tfile ||
12262                 error "$tfile different after migration"
12263
12264         diff /etc/passwd ${other_dir}/luna ||
12265                 error "luna different after migration"
12266
12267         diff /etc/passwd ${migrate_dir}/sofia ||
12268                 error "sofia different after migration"
12269
12270         diff /etc/passwd ${other_dir}/zachary ||
12271                 error "zachary different after migration"
12272
12273         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12274                 error "${tfile}_ln different after migration"
12275
12276         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12277                 error "${tfile}_ln_other different after migration"
12278
12279         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12280         [ $stripe_count = 2 ] ||
12281                 error "dir strpe_count $d != 2 after migration."
12282
12283         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12284         [ $stripe_count = 2 ] ||
12285                 error "file strpe_count $d != 2 after migration."
12286
12287         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12288 }
12289 run_test 230b "migrate directory"
12290
12291 test_230c() {
12292         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12293         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12294         local MDTIDX=1
12295         local mdt_index
12296         local file
12297
12298         #If migrating directory fails in the middle, all entries of
12299         #the directory is still accessiable.
12300         mkdir -p $DIR/$tdir
12301         stat $DIR/$tdir
12302         createmany -o $DIR/$tdir/f 10 ||
12303                 error "create files under ${tdir} failed"
12304
12305         #failed after migrating 5 entries
12306         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12307         do_facet mds1 lctl set_param fail_loc=0x20001801
12308         do_facet mds1 lctl  set_param fail_val=5
12309         local t=`ls $DIR/$tdir | wc -l`
12310         $LFS mv -M $MDTIDX $DIR/$tdir &&
12311                 error "migrate should failed after 5 entries"
12312         local u=`ls $DIR/$tdir | wc -l`
12313         [ "$u" == "$t" ] || error "$u != $t during migration"
12314
12315         for file in $(find $DIR/$tdir); do
12316                 stat $file || error "stat $file failed"
12317         done
12318
12319         do_facet mds1 lctl set_param fail_loc=0
12320         do_facet mds1 lctl set_param fail_val=0
12321
12322         $LFS mv -M $MDTIDX $DIR/$tdir ||
12323                 error "migrate open files should failed with open files"
12324
12325         echo "Finish migration, then checking.."
12326         for file in $(find $DIR/$tdir); do
12327                 mdt_index=$($LFS getstripe -M $file)
12328                 [ $mdt_index == $MDTIDX ] ||
12329                         error "$file is not on MDT${MDTIDX}"
12330         done
12331
12332         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12333 }
12334 run_test 230c "check directory accessiblity if migration is failed"
12335
12336 test_230d() {
12337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12338         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12339         local MDTIDX=1
12340         local mdt_index
12341         local i
12342         local j
12343
12344         mkdir -p $DIR/$tdir
12345
12346         for ((i=0; i<100; i++)); do
12347                 mkdir -p $DIR/$tdir/dir_${i}
12348                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12349                         error "create files under remote dir failed $i"
12350         done
12351
12352         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12353
12354         echo "Finish migration, then checking.."
12355         for file in $(find $DIR/$tdir); do
12356                 mdt_index=$($LFS getstripe -M $file)
12357                 [ $mdt_index == $MDTIDX ] ||
12358                         error "$file is not on MDT${MDTIDX}"
12359         done
12360
12361         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12362 }
12363 run_test 230d "check migrate big directory"
12364
12365 test_231a()
12366 {
12367         # For simplicity this test assumes that max_pages_per_rpc
12368         # is the same across all OSCs
12369         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12370         local bulk_size=$((max_pages * 4096))
12371
12372         mkdir -p $DIR/$tdir
12373
12374         # clear the OSC stats
12375         $LCTL set_param osc.*.stats=0 &>/dev/null
12376
12377         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12378         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12379                 oflag=direct &>/dev/null || error "dd failed"
12380
12381         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12382         if [ x$nrpcs != "x1" ]; then
12383                 error "found $nrpc ost_write RPCs, not 1 as expected"
12384         fi
12385
12386         # Drop the OSC cache, otherwise we will read from it
12387         cancel_lru_locks osc
12388
12389         # clear the OSC stats
12390         $LCTL set_param osc.*.stats=0 &>/dev/null
12391
12392         # Client reads $bulk_size.
12393         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12394                 iflag=direct &>/dev/null || error "dd failed"
12395
12396         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12397         if [ x$nrpcs != "x1" ]; then
12398                 error "found $nrpc ost_read RPCs, not 1 as expected"
12399         fi
12400 }
12401 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12402
12403 test_231b() {
12404         mkdir -p $DIR/$tdir
12405         local i
12406         for i in {0..1023}; do
12407                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12408                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12409                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12410         done
12411         sync
12412 }
12413 run_test 231b "must not assert on fully utilized OST request buffer"
12414
12415 test_232() {
12416         mkdir -p $DIR/$tdir
12417         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12418         $LCTL set_param fail_loc=0x31c
12419
12420         # ignore dd failure
12421         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12422
12423         $LCTL set_param fail_loc=0
12424         umount_client $MOUNT || error "umount failed"
12425         mount_client $MOUNT || error "mount failed"
12426 }
12427 run_test 232 "failed lock should not block umount"
12428
12429 test_233a() {
12430         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12431         { skip "Need MDS version at least 2.3.64"; return; }
12432
12433         local fid=$($LFS path2fid $MOUNT)
12434         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12435                 error "cannot access $MOUNT using its FID '$fid'"
12436 }
12437 run_test 233a "checking that OBF of the FS root succeeds"
12438
12439 test_233b() {
12440         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12441         { skip "Need MDS version at least 2.5.90"; return; }
12442
12443         local fid=$($LFS path2fid $MOUNT/.lustre)
12444         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12445                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12446
12447         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12448         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12449                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12450 }
12451 run_test 233b "checking that OBF of the FS .lustre succeeds"
12452
12453 test_234() {
12454         local p="$TMP/sanityN-$TESTNAME.parameters"
12455         save_lustre_params client "llite.*.xattr_cache" > $p
12456         lctl set_param llite.*.xattr_cache 1 ||
12457                 { skip "xattr cache is not supported"; return 0; }
12458
12459         mkdir -p $DIR/$tdir || error "mkdir failed"
12460         touch $DIR/$tdir/$tfile || error "touch failed"
12461         # OBD_FAIL_LLITE_XATTR_ENOMEM
12462         $LCTL set_param fail_loc=0x1405
12463         # output of the form: attr 2 4 44 3 fc13 x86_64
12464         V=($(IFS=".-" rpm -q attr))
12465         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
12466               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
12467                 # attr pre-2.4.44-7 had a bug with rc
12468                 # LU-3703 - SLES 11 and FC13 clients have older attr
12469                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12470                         error "getfattr should have failed with ENOMEM"
12471         else
12472                 skip "LU-3703: attr version $(getfattr --version) too old"
12473         fi
12474         $LCTL set_param fail_loc=0x0
12475         rm -rf $DIR/$tdir
12476
12477         restore_lustre_params < $p
12478         rm -f $p
12479 }
12480 run_test 234 "xattr cache should not crash on ENOMEM"
12481
12482 test_235() {
12483         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12484                 skip "Need MDS version at least 2.4.52" && return
12485         flock_deadlock $DIR/$tfile
12486         local RC=$?
12487         case $RC in
12488                 0)
12489                 ;;
12490                 124) error "process hangs on a deadlock"
12491                 ;;
12492                 *) error "error executing flock_deadlock $DIR/$tfile"
12493                 ;;
12494         esac
12495 }
12496 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12497
12498 #LU-2935
12499 test_236() {
12500         check_swap_layouts_support && return 0
12501         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12502
12503         local ref1=/etc/passwd
12504         local ref2=/etc/group
12505         local file1=$DIR/$tdir/f1
12506         local file2=$DIR/$tdir/f2
12507
12508         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12509         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12510         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12511         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12512         local fd=$(free_fd)
12513         local cmd="exec $fd<>$file2"
12514         eval $cmd
12515         rm $file2
12516         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12517                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12518         cmd="exec $fd>&-"
12519         eval $cmd
12520         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12521
12522         #cleanup
12523         rm -rf $DIR/$tdir
12524 }
12525 run_test 236 "Layout swap on open unlinked file"
12526
12527 # test to verify file handle related system calls
12528 # (name_to_handle_at/open_by_handle_at)
12529 # The new system calls are supported in glibc >= 2.14.
12530
12531 test_237() {
12532         echo "Test file_handle syscalls" > $DIR/$tfile ||
12533                 error "write failed"
12534         check_fhandle_syscalls $DIR/$tfile ||
12535                 error "check_fhandle_syscalls failed"
12536 }
12537 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12538
12539 # LU-4659 linkea consistency
12540 test_238() {
12541         local server_version=$(lustre_version_code $SINGLEMDS)
12542
12543         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12544                 [[ $server_version -gt $(version_code 2.5.1) &&
12545                    $server_version -lt $(version_code 2.5.50) ]] ||
12546                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12547
12548         touch $DIR/$tfile
12549         ln $DIR/$tfile $DIR/$tfile.lnk
12550         touch $DIR/$tfile.new
12551         mv $DIR/$tfile.new $DIR/$tfile
12552         local fid1=$(lfs path2fid $DIR/$tfile)
12553         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12554         local path1=$(lfs fid2path $FSNAME $fid1)
12555         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12556         local path2=$(lfs fid2path $FSNAME $fid2)
12557         [ $tfile.lnk == $path2 ] ||
12558                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12559         rm -f $DIR/$tfile*
12560 }
12561 run_test 238 "Verify linkea consistency"
12562
12563 test_239() {
12564         local list=$(comma_list $(mdts_nodes))
12565
12566         mkdir -p $DIR/$tdir
12567         createmany -o $DIR/$tdir/f- 5000
12568         unlinkmany $DIR/$tdir/f- 5000
12569         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12570         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12571                         osc.*MDT*.sync_in_flight" | calc_sum)
12572         [ "$changes" -eq 0 ] || error "$changes not synced"
12573 }
12574 run_test 239 "osp_sync test"
12575
12576 test_240() {
12577         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12578
12579         mkdir -p $DIR/$tdir
12580
12581         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12582                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12583         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12584                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12585
12586         umount_client $MOUNT || error "umount failed"
12587         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12588         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12589         mount_client $MOUNT || error "failed to mount client"
12590
12591         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12592         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12593 }
12594 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12595
12596 test_241_bio() {
12597         for LOOP in $(seq $1); do
12598                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12599                 cancel_lru_locks osc
12600         done
12601 }
12602
12603 test_241_dio() {
12604         for LOOP in $(seq $1); do
12605                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12606                                                 iflag=direct 2>/dev/null
12607         done
12608 }
12609
12610 test_241() {
12611         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12612         ls -la $DIR/$tfile
12613         cancel_lru_locks osc
12614         test_241_bio 1000 &
12615         PID=$!
12616         test_241_dio 1000
12617         wait $PID
12618 }
12619 run_test 241 "bio vs dio"
12620
12621 cleanup_test_300() {
12622         trap 0
12623         umask $SAVE_UMASK
12624 }
12625 test_striped_dir() {
12626         local mdt_index=$1
12627         local stripe_count
12628         local stripe_index
12629
12630         mkdir -p $DIR/$tdir
12631
12632         SAVE_UMASK=$(umask)
12633         trap cleanup_test_300 RETURN EXIT
12634
12635         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
12636                                                 $DIR/$tdir/striped_dir ||
12637                 error "set striped dir error"
12638
12639         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
12640         [ "$mode" = "755" ] || error "expect 755 got $mode"
12641
12642         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12643         if [ "$stripe_count" != "2" ]; then
12644                 error "stripe_count is $stripe_count, expect 2"
12645         fi
12646
12647         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12648         if [ "$stripe_index" != "$mdt_index" ]; then
12649                 error "stripe_index is $stripe_index, expect $mdt_index"
12650         fi
12651
12652         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12653                 error "nlink error after create striped dir"
12654
12655         mkdir $DIR/$tdir/striped_dir/a
12656         mkdir $DIR/$tdir/striped_dir/b
12657
12658         stat $DIR/$tdir/striped_dir/a ||
12659                 error "create dir under striped dir failed"
12660         stat $DIR/$tdir/striped_dir/b ||
12661                 error "create dir under striped dir failed"
12662
12663         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12664                 error "nlink error after mkdir"
12665
12666         rmdir $DIR/$tdir/striped_dir/a
12667         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12668                 error "nlink error after rmdir"
12669
12670         rmdir $DIR/$tdir/striped_dir/b
12671         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12672                 error "nlink error after rmdir"
12673
12674         rmdir $DIR/$tdir/striped_dir ||
12675                 error "rmdir striped dir error"
12676
12677         cleanup_test_300
12678
12679         true
12680 }
12681
12682 test_300a() {
12683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12684         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12685
12686         test_striped_dir 0 || error "failed on striped dir on MDT0"
12687         test_striped_dir 1 || error "failed on striped dir on MDT0"
12688 }
12689 run_test 300a "basic striped dir sanity test"
12690
12691 test_300b() {
12692         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12693         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12694         local i
12695         local mtime1
12696         local mtime2
12697         local mtime3
12698
12699         test_mkdir $DIR/$tdir || error "mkdir fail"
12700         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12701                 error "set striped dir error"
12702         for ((i=0; i<10; i++)); do
12703                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12704                 sleep 1
12705                 touch $DIR/$tdir/striped_dir/file_$i ||
12706                                         error "touch error $i"
12707                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12708                 [ $mtime1 -eq $mtime2 ] &&
12709                         error "mtime not change after create"
12710                 sleep 1
12711                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12712                                         error "unlink error $i"
12713                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12714                 [ $mtime2 -eq $mtime3 ] &&
12715                         error "mtime did not change after unlink"
12716         done
12717         true
12718 }
12719 run_test 300b "check ctime/mtime for striped dir"
12720
12721 test_300c() {
12722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12723         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12724         local file_count
12725
12726         mkdir -p $DIR/$tdir
12727         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12728                 error "set striped dir error"
12729
12730         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12731                 error "chown striped dir failed"
12732
12733         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12734                 error "create 5k files failed"
12735
12736         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12737
12738         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12739
12740         rm -rf $DIR/$tdir
12741 }
12742 run_test 300c "chown && check ls under striped directory"
12743
12744 test_300d() {
12745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12746         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12747         local stripe_count
12748         local file
12749
12750         mkdir -p $DIR/$tdir
12751         $SETSTRIPE -c 2 $DIR/$tdir
12752
12753         #local striped directory
12754         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12755                 error "set striped dir error"
12756         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12757                 error "create 10 files failed"
12758
12759         #remote striped directory
12760         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12761                 error "set striped dir error"
12762         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12763                 error "create 10 files failed"
12764
12765         for file in $(find $DIR/$tdir); do
12766                 stripe_count=$($GETSTRIPE -c $file)
12767                 [ $stripe_count -eq 2 ] ||
12768                         error "wrong stripe $stripe_count for $file"
12769         done
12770
12771         rm -rf $DIR/$tdir
12772 }
12773 run_test 300d "check default stripe under striped directory"
12774
12775 test_300e() {
12776         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12777         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12778         local stripe_count
12779         local file
12780
12781         mkdir -p $DIR/$tdir
12782
12783         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12784                 error "set striped dir error"
12785
12786         touch $DIR/$tdir/striped_dir/a
12787         touch $DIR/$tdir/striped_dir/b
12788         touch $DIR/$tdir/striped_dir/c
12789
12790         mkdir $DIR/$tdir/striped_dir/dir_a
12791         mkdir $DIR/$tdir/striped_dir/dir_b
12792         mkdir $DIR/$tdir/striped_dir/dir_c
12793
12794         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12795                 error "set striped dir under striped dir error"
12796
12797         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12798                 error "set striped dir under striped dir error"
12799
12800         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12801                 error "set striped dir under striped dir error"
12802
12803         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12804                 error "rename file under striped dir should fail"
12805
12806         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12807                 error "rename dir under striped dir should fail"
12808
12809         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12810                 error "rename dir under different stripes should fail"
12811
12812         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12813                 error "rename file under striped dir should succeed"
12814
12815         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12816                 error "rename dir under striped dir should succeed"
12817
12818         rm -rf $DIR/$tdir
12819 }
12820 run_test 300e "check rename under striped directory"
12821
12822 test_300f() {
12823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12824         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12825         local stripe_count
12826         local file
12827
12828         rm -rf $DIR/$tdir
12829         mkdir -p $DIR/$tdir
12830
12831         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12832                 error "set striped dir error"
12833
12834         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12835                 error "set striped dir error"
12836
12837         touch $DIR/$tdir/striped_dir/a
12838         mkdir $DIR/$tdir/striped_dir/dir_a
12839         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12840                 error "create striped dir under striped dir fails"
12841
12842         touch $DIR/$tdir/striped_dir1/b
12843         mkdir $DIR/$tdir/striped_dir1/dir_b
12844         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12845                 error "create striped dir under striped dir fails"
12846
12847         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12848                 error "rename file under different striped dir should fail"
12849
12850         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12851                 error "rename dir under different striped dir should fail"
12852
12853         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12854                 error "rename striped dir under diff striped dir should fail"
12855
12856         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12857                 error "rename file under diff striped dirs fails"
12858
12859         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12860                 error "rename dir under diff striped dirs fails"
12861
12862         rm -rf $DIR/$tdir
12863 }
12864 run_test 300f "check rename cross striped directory"
12865
12866 test_300g() {
12867         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12868         local stripe_count
12869         local dir
12870
12871         mkdir $DIR/$tdir
12872         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
12873                                         $DIR/$tdir/striped_dir ||
12874                 error "set striped dir error"
12875
12876         $LFS setdirstripe -D -c $MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12877                 error "set default stripe on striped dir error"
12878
12879         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/striped_dir)
12880         [ $stripe_count -eq $MDSCOUNT ] ||
12881                 error "default stripe wrong expect $MDSCOUNT get $stripe_count"
12882
12883         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12884
12885         for dir in $(find $DIR/$tdir/striped_dir/*); do
12886                 stripe_count=$($LFS getdirstripe -c $dir)
12887                 [ $stripe_count -eq $MDSCOUNT ] ||
12888                         error "expect $MDSCOUNT get $stripe_count for $dir"
12889         done
12890
12891         rmdir $DIR/$tdir/striped_dir/* || error "rmdir1 failed"
12892         #change default stripe count to 2
12893         $LFS setdirstripe -D -c 2 -t all_char $DIR/$tdir/striped_dir ||
12894                 error "set default stripe on striped dir error"
12895
12896         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12897
12898         rmdir $DIR/$tdir/striped_dir/* || error "rmdir2 failed"
12899
12900         #change default stripe count to 1
12901         $LFS setdirstripe -D -c 1 -t all_char $DIR/$tdir/striped_dir ||
12902                 error "set default stripe on striped dir error"
12903
12904         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12905         for dir in $(find $DIR/$tdir/striped_dir/*); do
12906                 stripe_count=$($LFS getdirstripe -c $dir)
12907                 [ $stripe_count -eq 1 ] ||
12908                         error "expect 1 get $stripe_count for $dir"
12909         done
12910         rmdir $DIR/$tdir/striped_dir/* || error "rmdir3 failed"
12911 }
12912 run_test 300g "check default striped directory for striped directory"
12913
12914 test_300h() {
12915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12916         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12917         local stripe_count
12918         local file
12919
12920         mkdir $DIR/$tdir
12921
12922         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12923                 error "set striped dir error"
12924
12925         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
12926                 error "create files under striped dir failed"
12927
12928         # unfortunately, we need to umount to clear dir layout cache for now
12929         # once we fully implement dir layout, we can drop this
12930         umount_client $MOUNT || error "umount failed"
12931         mount_client $MOUNT || error "mount failed"
12932
12933         #set the stripe to be unknown hash type
12934         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
12935         $LCTL set_param fail_loc=0x1901
12936         for ((i = 0; i < 10; i++)); do
12937                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
12938                         error "stat f-$i failed"
12939                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
12940         done
12941
12942         touch $DIR/$tdir/striped_dir/f0 &&
12943                 error "create under striped dir with unknown hash should fail"
12944
12945         $LCTL set_param fail_loc=0
12946
12947         umount_client $MOUNT || error "umount failed"
12948         mount_client $MOUNT || error "mount failed"
12949
12950         return 0
12951 }
12952 run_test 300h "client handle unknown hash type striped directory"
12953
12954 test_400a() { # LU-1606, was conf-sanity test_74
12955         local extra_flags=''
12956         local out=$TMP/$tfile
12957         local prefix=/usr/include/lustre
12958         local prog
12959
12960         if ! which $CC > /dev/null 2>&1; then
12961                 skip_env "$CC is not installed"
12962                 return 0
12963         fi
12964
12965         if ! [[ -d $prefix ]]; then
12966                 # Assume we're running in tree and fixup the include path.
12967                 extra_flags+=" -I$LUSTRE/../libcfs/include"
12968                 extra_flags+=" -I$LUSTRE/include"
12969                 extra_flags+=" -L$LUSTRE/utils"
12970         fi
12971
12972         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
12973                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
12974                         error "client api broken"
12975         done
12976 }
12977 run_test 400a "Lustre client api program can compile and link"
12978
12979 test_400b() { # LU-1606, LU-5011
12980         local header
12981         local out=$TMP/$tfile
12982         local prefix=/usr/include/lustre
12983
12984         # We use a hard coded prefix so that this test will not fail
12985         # when run in tree. There are headers in lustre/include/lustre/
12986         # that are not packaged (like lustre_idl.h) and have more
12987         # complicated include dependencies (like config.h and lnet/types.h).
12988         # Since this test about correct packaging we just skip them when
12989         # they don't exist (see below) rather than try to fixup cppflags.
12990
12991         if ! which $CC > /dev/null 2>&1; then
12992                 skip_env "$CC is not installed"
12993                 return 0
12994         fi
12995
12996         for header in $prefix/*.h; do
12997                 if ! [[ -f "$header" ]]; then
12998                         continue
12999                 fi
13000
13001                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
13002                         continue # liblustreapi.h is deprecated.
13003                 fi
13004
13005                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
13006                         error "cannot compile '$header'"
13007         done
13008 }
13009 run_test 400b "packaged headers can be compiled"
13010
13011 #
13012 # tests that do cleanup/setup should be run at the end
13013 #
13014
13015 test_900() {
13016         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13017         local ls
13018         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13019         $LCTL set_param fail_loc=0x903
13020
13021         cancel_lru_locks MGC
13022
13023         FAIL_ON_ERROR=true cleanup
13024         FAIL_ON_ERROR=true setup
13025 }
13026 run_test 900 "umount should not race with any mgc requeue thread"
13027
13028 complete $SECONDS
13029 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13030 check_and_cleanup_lustre
13031 if [ "$I_MOUNTED" != "yes" ]; then
13032         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13033 fi
13034 exit_status