Whamcloud - gitweb
LU-2182 llapi: implementation of new llapi_layout API
[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-2610 LU-2833 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     40      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         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
562         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
563                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
564
565         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
566                 skip "only for ldiskfs MDT" && return 0
567
568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
569
570         mkdir -p $WDIR
571         long_sym=$short_sym
572         # create a long symlink file
573         for ((i = 0; i < 4; ++i)); do
574                 long_sym=${long_sym}${long_sym}
575         done
576
577         echo "create 512 short and long symlink files under $WDIR"
578         for ((i = 0; i < 256; ++i)); do
579                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
580                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
581         done
582
583         echo "erase them"
584         rm -f $WDIR/*
585         sync
586         wait_delete_completed
587
588         echo "recreate the 512 symlink files with a shorter string"
589         for ((i = 0; i < 512; ++i)); do
590                 # rewrite the symlink file with a shorter string
591                 ln -sf ${long_sym} $WDIR/long-$i
592                 ln -sf ${short_sym} $WDIR/short-$i
593         done
594
595         mds_index=$($LFS getstripe -M $WDIR)
596         mds_index=$((mds_index+1))
597         devname=$(mdsdevname $mds_index)
598         cmd="$E2FSCK -fnvd $devname"
599
600         echo "stop and checking mds${mds_index}: $cmd"
601         # e2fsck should not return error
602         stop mds${mds_index}
603         do_facet mds${mds_index} $cmd || rc=$?
604
605         start mds${mds_index} $devname $MDS_MOUNT_OPTS
606         df $MOUNT > /dev/null 2>&1
607         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
608                 "short/long symlink MDT: rc=$rc"
609         return $rc
610 }
611 run_test 17m "run e2fsck against MDT which contains short/long symlink"
612
613 check_fs_consistency_17n() {
614         local mdt_index
615         local devname
616         local cmd
617         local rc=0
618
619         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
620         # so it only check MDT1/MDT2 instead of all of MDTs.
621         for mdt_index in $(seq 1 2); do
622                 devname=$(mdsdevname $mdt_index)
623                 cmd="$E2FSCK -fnvd $devname"
624
625                 echo "stop and checking mds${mdt_index}: $cmd"
626                 # e2fsck should not return error
627                 stop mds${mdt_index}
628                 do_facet mds${mdt_index} $cmd || rc=$?
629
630                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
631                 df $MOUNT > /dev/null 2>&1
632                 [ $rc -ne 0 ] && break
633         done
634         return $rc
635 }
636
637 test_17n() {
638         local i
639
640         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
641         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
642                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
643
644         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
645                 skip "only for ldiskfs MDT" && return 0
646
647         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
648
649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
650
651         mkdir $DIR/$tdir
652         for ((i=0; i<10; i++)); do
653                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
654                         error "create remote dir error $i"
655                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
656                         error "create files under remote dir failed $i"
657         done
658
659         check_fs_consistency_17n ||
660                 error "e2fsck report error after create files under remote dir"
661
662         for ((i=0;i<10;i++)); do
663                 rm -rf $DIR/$tdir/remote_dir_${i} ||
664                         error "destroy remote dir error $i"
665         done
666
667         check_fs_consistency_17n ||
668                 error "e2fsck report error after unlink files under remote dir"
669
670         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
671                 skip "lustre < 2.4.50 does not support migrate mv " && return
672
673         for ((i=0; i<10; i++)); do
674                 mkdir -p $DIR/$tdir/remote_dir_${i}
675                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
676                         error "create files under remote dir failed $i"
677                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
678                         error "migrate remote dir error $i"
679         done
680         check_fs_consistency_17n || error "e2fsck report error after migration"
681
682         for ((i=0;i<10;i++)); do
683                 rm -rf $DIR/$tdir/remote_dir_${i} ||
684                         error "destroy remote dir error $i"
685         done
686
687         check_fs_consistency_17n || error "e2fsck report error after unlink"
688 }
689 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
690
691 test_17o() {
692         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
693                 skip "Need MDS version at least 2.3.64" && return
694
695         local WDIR=$DIR/${tdir}o
696         local mdt_index
697         local mdtdevname
698         local rc=0
699
700         mkdir -p $WDIR
701         mdt_index=$($LFS getstripe -M $WDIR)
702         mdt_index=$((mdt_index+1))
703         mdtdevname=$(mdsdevname $mdt_index)
704
705         touch $WDIR/$tfile
706         stop mds${mdt_index}
707         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
708
709         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
710         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
711         ls -l $WDIR/$tfile && rc=1
712         do_facet mds${mdt_index} lctl set_param fail_loc=0
713         [[ $rc -ne 0 ]] && error "stat file should fail"
714         true
715 }
716 run_test 17o "stat file with incompat LMA feature"
717
718 test_18() {
719         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
720         ls $DIR || error "Failed to ls $DIR: $?"
721 }
722 run_test 18 "touch .../f ; ls ... =============================="
723
724 test_19a() {
725         touch $DIR/$tfile
726         ls -l $DIR
727         rm $DIR/$tfile
728         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
729 }
730 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
731
732 test_19b() {
733         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
734 }
735 run_test 19b "ls -l .../f19 (should return error) =============="
736
737 test_19c() {
738         [ $RUNAS_ID -eq $UID ] &&
739                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
740         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
741 }
742 run_test 19c "$RUNAS touch .../f19 (should return error) =="
743
744 test_19d() {
745         cat $DIR/f19 && error || true
746 }
747 run_test 19d "cat .../f19 (should return error) =============="
748
749 test_20() {
750         touch $DIR/$tfile
751         rm $DIR/$tfile
752         log "1 done"
753         touch $DIR/$tfile
754         rm $DIR/$tfile
755         log "2 done"
756         touch $DIR/$tfile
757         rm $DIR/$tfile
758         log "3 done"
759         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
760 }
761 run_test 20 "touch .../f ; ls -l ... ==========================="
762
763 test_21() {
764         test_mkdir -p $DIR/$tdir
765         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
766         ln -s dangle $DIR/$tdir/link
767         echo foo >> $DIR/$tdir/link
768         cat $DIR/$tdir/dangle
769         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
770         $CHECKSTAT -f -t file $DIR/$tdir/link ||
771                 error "$tdir/link not linked to a file"
772 }
773 run_test 21 "write to dangling link ============================"
774
775 test_22() {
776         WDIR=$DIR/$tdir
777         test_mkdir -p $DIR/$tdir
778         chown $RUNAS_ID:$RUNAS_GID $WDIR
779         (cd $WDIR || error "cd $WDIR failed";
780         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
781         $RUNAS tar xf -)
782         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
783         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
784         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
785 }
786 run_test 22 "unpack tar archive as non-root user ==============="
787
788 # was test_23
789 test_23a() {
790         test_mkdir -p $DIR/$tdir
791         local file=$DIR/$tdir/$tfile
792
793         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
794         openfile -f O_CREAT:O_EXCL $file &&
795                 error "$file recreate succeeded" || true
796 }
797 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
798
799 test_23b() { # bug 18988
800         test_mkdir -p $DIR/$tdir
801         local file=$DIR/$tdir/$tfile
802
803         rm -f $file
804         echo foo > $file || error "write filed"
805         echo bar >> $file || error "append filed"
806         $CHECKSTAT -s 8 $file || error "wrong size"
807         rm $file
808 }
809 run_test 23b "O_APPEND check =========================="
810
811 # rename sanity
812 test_24a() {
813         echo '-- same directory rename'
814         test_mkdir $DIR/$tdir
815         touch $DIR/$tdir/$tfile.1
816         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
817         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
818 }
819 run_test 24a "rename file to non-existent target"
820
821 test_24b() {
822         test_mkdir $DIR/$tdir
823         touch $DIR/$tdir/$tfile.{1,2}
824         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
825         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
826         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
827 }
828 run_test 24b "rename file to existing target"
829
830 test_24c() {
831         test_mkdir $DIR/$tdir
832         test_mkdir $DIR/$tdir/d$testnum.1
833         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
834         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
835         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
836 }
837 run_test 24c "rename directory to non-existent target"
838
839 test_24d() {
840         test_mkdir -c1 $DIR/$tdir
841         test_mkdir -c1 $DIR/$tdir/d$testnum.1
842         test_mkdir -c1 $DIR/$tdir/d$testnum.2
843         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
844         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
845         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
846 }
847 run_test 24d "rename directory to existing target"
848
849 test_24e() {
850         echo '-- cross directory renames --'
851         test_mkdir $DIR/R5a
852         test_mkdir $DIR/R5b
853         touch $DIR/R5a/f
854         mv $DIR/R5a/f $DIR/R5b/g
855         $CHECKSTAT -a $DIR/R5a/f || error
856         $CHECKSTAT -t file $DIR/R5b/g || error
857 }
858 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
859
860 test_24f() {
861         test_mkdir $DIR/R6a
862         test_mkdir $DIR/R6b
863         touch $DIR/R6a/f $DIR/R6b/g
864         mv $DIR/R6a/f $DIR/R6b/g
865         $CHECKSTAT -a $DIR/R6a/f || error
866         $CHECKSTAT -t file $DIR/R6b/g || error
867 }
868 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
869
870 test_24g() {
871         test_mkdir $DIR/R7a
872         test_mkdir $DIR/R7b
873         test_mkdir $DIR/R7a/d
874         mv $DIR/R7a/d $DIR/R7b/e
875         $CHECKSTAT -a $DIR/R7a/d || error
876         $CHECKSTAT -t dir $DIR/R7b/e || error
877 }
878 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
879
880 test_24h() {
881         test_mkdir -c1 $DIR/R8a
882         test_mkdir -c1 $DIR/R8b
883         test_mkdir -c1 $DIR/R8a/d
884         test_mkdir -c1 $DIR/R8b/e
885         mrename $DIR/R8a/d $DIR/R8b/e
886         $CHECKSTAT -a $DIR/R8a/d || error
887         $CHECKSTAT -t dir $DIR/R8b/e || error
888 }
889 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
890
891 test_24i() {
892         echo "-- rename error cases"
893         test_mkdir $DIR/R9
894         test_mkdir $DIR/R9/a
895         touch $DIR/R9/f
896         mrename $DIR/R9/f $DIR/R9/a
897         $CHECKSTAT -t file $DIR/R9/f || error
898         $CHECKSTAT -t dir  $DIR/R9/a || error
899         $CHECKSTAT -a $DIR/R9/a/f || error
900 }
901 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
902
903 test_24j() {
904         test_mkdir $DIR/R10
905         mrename $DIR/R10/f $DIR/R10/g
906         $CHECKSTAT -t dir $DIR/R10 || error
907         $CHECKSTAT -a $DIR/R10/f || error
908         $CHECKSTAT -a $DIR/R10/g || error
909 }
910 run_test 24j "source does not exist ============================"
911
912 test_24k() {
913         test_mkdir $DIR/R11a
914         test_mkdir $DIR/R11a/d
915         touch $DIR/R11a/f
916         mv $DIR/R11a/f $DIR/R11a/d
917         $CHECKSTAT -a $DIR/R11a/f || error
918         $CHECKSTAT -t file $DIR/R11a/d/f || error
919 }
920 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
921
922 # bug 2429 - rename foo foo foo creates invalid file
923 test_24l() {
924         f="$DIR/f24l"
925         $MULTIOP $f OcNs || error
926 }
927 run_test 24l "Renaming a file to itself ========================"
928
929 test_24m() {
930         f="$DIR/f24m"
931         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
932         # on ext3 this does not remove either the source or target files
933         # though the "expected" operation would be to remove the source
934         $CHECKSTAT -t file ${f} || error "${f} missing"
935         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
936 }
937 run_test 24m "Renaming a file to a hard link to itself ========="
938
939 test_24n() {
940     f="$DIR/f24n"
941     # this stats the old file after it was renamed, so it should fail
942     touch ${f}
943     $CHECKSTAT ${f}
944     mv ${f} ${f}.rename
945     $CHECKSTAT ${f}.rename
946     $CHECKSTAT -a ${f}
947 }
948 run_test 24n "Statting the old file after renaming (Posix rename 2)"
949
950 test_24o() {
951         check_kernel_version 37 || return 0
952         test_mkdir -p $DIR/d24o
953         rename_many -s random -v -n 10 $DIR/d24o
954 }
955 run_test 24o "rename of files during htree split ==============="
956
957 test_24p() {
958         test_mkdir $DIR/R12a
959         test_mkdir $DIR/R12b
960         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
961         mrename $DIR/R12a $DIR/R12b
962         $CHECKSTAT -a $DIR/R12a || error
963         $CHECKSTAT -t dir $DIR/R12b || error
964         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
965         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
966 }
967 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
968
969 cleanup_multiop_pause() {
970         trap 0
971         kill -USR1 $MULTIPID
972 }
973
974 test_24q() {
975         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
976         test_mkdir $DIR/R13a
977         test_mkdir $DIR/R13b
978         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
979         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
980         MULTIPID=$!
981
982         trap cleanup_multiop_pause EXIT
983         mrename $DIR/R13a $DIR/R13b
984         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
985         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
986         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
987         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
988         cleanup_multiop_pause
989         wait $MULTIPID || error "multiop close failed"
990 }
991 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
992
993 test_24r() { #bug 3789
994         test_mkdir $DIR/R14a
995         test_mkdir $DIR/R14a/b
996         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
997         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
998         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
999 }
1000 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1001
1002 test_24s() {
1003         test_mkdir $DIR/R15a
1004         test_mkdir $DIR/R15a/b
1005         test_mkdir $DIR/R15a/b/c
1006         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1007         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1008         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1009 }
1010 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1011 test_24t() {
1012         test_mkdir $DIR/R16a
1013         test_mkdir $DIR/R16a/b
1014         test_mkdir $DIR/R16a/b/c
1015         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1016         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1017         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1018 }
1019 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1020
1021 test_24u() { # bug12192
1022         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1023         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1024 }
1025 run_test 24u "create stripe file"
1026
1027 page_size() {
1028         getconf PAGE_SIZE
1029 }
1030
1031 simple_cleanup_common() {
1032         trap 0
1033         rm -rf $DIR/$tdir
1034         wait_delete_completed
1035 }
1036
1037 max_pages_per_rpc() {
1038         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1039 }
1040
1041 test_24v() {
1042         local NRFILES=100000
1043         local FREE_INODES=$(mdt_free_inodes 0)
1044         [[ $FREE_INODES -lt $NRFILES ]] &&
1045                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1046                 return
1047
1048         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1049         trap simple_cleanup_common EXIT
1050
1051         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1052         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1053
1054         mkdir -p $DIR/$tdir
1055         createmany -m $DIR/$tdir/$tfile $NRFILES
1056
1057         cancel_lru_locks mdc
1058         lctl set_param mdc.*.stats clear
1059
1060         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1061
1062         # LU-5 large readdir
1063         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1064         #               8 bytes for name(filename is mostly 5 in this test) +
1065         #               8 bytes for luda_type
1066         # take into account of overhead in lu_dirpage header and end mark in
1067         # each page, plus one in RPC_NUM calculation.
1068         DIRENT_SIZE=48
1069         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1070         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1071         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1072                                 awk '/^mds_readpage/ {print $2}')
1073         [[ $mds_readpage -gt $RPC_NUM ]] &&
1074                 error "large readdir doesn't take effect"
1075
1076         simple_cleanup_common
1077 }
1078 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1079
1080 test_24w() { # bug21506
1081         SZ1=234852
1082         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1083         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1084         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1085         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1086         [[ "$SZ1" -eq "$SZ2" ]] ||
1087                 error "Error reading at the end of the file $tfile"
1088 }
1089 run_test 24w "Reading a file larger than 4Gb"
1090
1091 test_24x() {
1092         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1093         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1094         local MDTIDX=1
1095         local remote_dir=$DIR/$tdir/remote_dir
1096
1097         mkdir -p $DIR/$tdir
1098         $LFS mkdir -i $MDTIDX $remote_dir ||
1099                 error "create remote directory failed"
1100
1101         mkdir -p $DIR/$tdir/src_dir
1102         touch $DIR/$tdir/src_file
1103         mkdir -p $remote_dir/tgt_dir
1104         touch $remote_dir/tgt_file
1105
1106         mrename $remote_dir $DIR/ &&
1107                 error "rename dir cross MDT works!"
1108
1109         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1110                 error "rename dir cross MDT works!"
1111
1112         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1113                 error "rename file cross MDT works!"
1114
1115         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1116                 error "ln file cross MDT should not work!"
1117
1118         rm -rf $DIR/$tdir || error "Can not delete directories"
1119 }
1120 run_test 24x "cross rename/link should be failed"
1121
1122 test_24y() {
1123         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1125         local MDTIDX=1
1126         local remote_dir=$DIR/$tdir/remote_dir
1127
1128         mkdir -p $DIR/$tdir
1129         $LFS mkdir -i $MDTIDX $remote_dir ||
1130                    error "create remote directory failed"
1131
1132         mkdir -p $remote_dir/src_dir
1133         touch $remote_dir/src_file
1134         mkdir -p $remote_dir/tgt_dir
1135         touch $remote_dir/tgt_file
1136
1137         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1138                 error "rename subdir in the same remote dir failed!"
1139
1140         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1141                 error "rename files in the same remote dir failed!"
1142
1143         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1144                 error "link files in the same remote dir failed!"
1145
1146         rm -rf $DIR/$tdir || error "Can not delete directories"
1147 }
1148 run_test 24y "rename/link on the same dir should succeed"
1149
1150 test_24z() {
1151         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1153         local MDTIDX=1
1154         local remote_src=$DIR/$tdir/remote_dir
1155         local remote_tgt=$DIR/$tdir/remote_tgt
1156
1157         mkdir -p $DIR/$tdir
1158         $LFS mkdir -i $MDTIDX $remote_src ||
1159                    error "create remote directory failed"
1160
1161         $LFS mkdir -i $MDTIDX $remote_tgt ||
1162                    error "create remote directory failed"
1163
1164         mrename $remote_src $remote_tgt &&
1165                 error "rename remote dirs should not work!"
1166
1167         # If target dir does not exists, it should succeed
1168         rm -rf $remote_tgt
1169         mrename $remote_src $remote_tgt ||
1170                 error "rename remote dirs(tgt dir does not exists) failed!"
1171
1172         rm -rf $DIR/$tdir || error "Can not delete directories"
1173 }
1174 run_test 24z "rename one remote dir to another remote dir should fail"
1175
1176 test_24A() { # LU-3182
1177         local NFILES=5000
1178
1179         rm -rf $DIR/$tdir
1180         mkdir -p $DIR/$tdir
1181         createmany -m $DIR/$tdir/$tfile $NFILES
1182         local t=$(ls $DIR/$tdir | wc -l)
1183         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1184         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1185         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1186                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1187         fi
1188
1189         rm -rf $DIR/$tdir || error "Can not delete directories"
1190 }
1191 run_test 24A "readdir() returns correct number of entries."
1192
1193 test_24B() { # LU-4805
1194         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1195         local count
1196
1197         mkdir $DIR/$tdir
1198         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1199                 error "create striped dir failed"
1200
1201         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1202         [ $count -eq 2 ] || error "Expected 2, got $count"
1203
1204         touch $DIR/$tdir/striped_dir/a
1205
1206         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1207         [ $count -eq 3 ] || error "Expected 3, got $count"
1208
1209         touch $DIR/$tdir/striped_dir/.f
1210
1211         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1212         [ $count -eq 4 ] || error "Expected 4, got $count"
1213
1214         rm -rf $DIR/$tdir || error "Can not delete directories"
1215 }
1216 run_test 24B "readdir for striped dir return correct number of entries"
1217
1218 test_24C() {
1219         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1220
1221         mkdir $DIR/$tdir
1222         mkdir $DIR/$tdir/d0
1223         mkdir $DIR/$tdir/d1
1224
1225         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1226                 error "create striped dir failed"
1227
1228         cd $DIR/$tdir/d0/striped_dir
1229
1230         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1231         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1232         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1233
1234         [ "$d0_ino" = "$parent_ino" ] ||
1235                 error ".. wrong, expect $d0_ino, get $parent_ino"
1236
1237         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1238                 error "mv striped dir failed"
1239
1240         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1241
1242         [ "$d1_ino" = "$parent_ino" ] ||
1243                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1244 }
1245 run_test 24C "check .. in striped dir"
1246
1247 test_25a() {
1248         echo '== symlink sanity ============================================='
1249
1250         test_mkdir $DIR/d25
1251         ln -s d25 $DIR/s25
1252         touch $DIR/s25/foo || error
1253 }
1254 run_test 25a "create file in symlinked directory ==============="
1255
1256 test_25b() {
1257         [ ! -d $DIR/d25 ] && test_25a
1258         $CHECKSTAT -t file $DIR/s25/foo || error
1259 }
1260 run_test 25b "lookup file in symlinked directory ==============="
1261
1262 test_26a() {
1263         test_mkdir $DIR/d26
1264         test_mkdir $DIR/d26/d26-2
1265         ln -s d26/d26-2 $DIR/s26
1266         touch $DIR/s26/foo || error
1267 }
1268 run_test 26a "multiple component symlink ======================="
1269
1270 test_26b() {
1271         test_mkdir -p $DIR/d26b/d26-2
1272         ln -s d26b/d26-2/foo $DIR/s26-2
1273         touch $DIR/s26-2 || error
1274 }
1275 run_test 26b "multiple component symlink at end of lookup ======"
1276
1277 test_26c() {
1278         test_mkdir $DIR/d26.2
1279         touch $DIR/d26.2/foo
1280         ln -s d26.2 $DIR/s26.2-1
1281         ln -s s26.2-1 $DIR/s26.2-2
1282         ln -s s26.2-2 $DIR/s26.2-3
1283         chmod 0666 $DIR/s26.2-3/foo
1284 }
1285 run_test 26c "chain of symlinks ================================"
1286
1287 # recursive symlinks (bug 439)
1288 test_26d() {
1289         ln -s d26-3/foo $DIR/d26-3
1290 }
1291 run_test 26d "create multiple component recursive symlink ======"
1292
1293 test_26e() {
1294         [ ! -h $DIR/d26-3 ] && test_26d
1295         rm $DIR/d26-3
1296 }
1297 run_test 26e "unlink multiple component recursive symlink ======"
1298
1299 # recursive symlinks (bug 7022)
1300 test_26f() {
1301         test_mkdir -p $DIR/$tdir
1302         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1303         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1304         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1305         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1306         cd $tfile                || error "cd $tfile failed"
1307         ln -s .. dotdot          || error "ln dotdot failed"
1308         ln -s dotdot/lndir lndir || error "ln lndir failed"
1309         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1310         output=`ls $tfile/$tfile/lndir/bar1`
1311         [ "$output" = bar1 ] && error "unexpected output"
1312         rm -r $tfile             || error "rm $tfile failed"
1313         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1314 }
1315 run_test 26f "rm -r of a directory which has recursive symlink ="
1316
1317 test_27a() {
1318         echo '== stripe sanity =============================================='
1319         test_mkdir -p $DIR/d27 || error "mkdir failed"
1320         $GETSTRIPE $DIR/d27
1321         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1322         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1323         log "== test_27a: write to one stripe file ========================="
1324         cp /etc/hosts $DIR/d27/f0 || error
1325 }
1326 run_test 27a "one stripe file =================================="
1327
1328 test_27b() {
1329         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1330         test_mkdir -p $DIR/d27
1331         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1332         $GETSTRIPE -c $DIR/d27/f01
1333         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1334                 error "two-stripe file doesn't have two stripes"
1335
1336         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1337 }
1338 run_test 27b "create and write to two stripe file"
1339
1340 test_27d() {
1341         test_mkdir -p $DIR/d27
1342         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1343         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1344         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1345 }
1346 run_test 27d "create file with default settings ================"
1347
1348 test_27e() {
1349         test_mkdir -p $DIR/d27
1350         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1351         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1352         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1353 }
1354 run_test 27e "setstripe existing file (should return error) ======"
1355
1356 test_27f() {
1357         test_mkdir -p $DIR/d27
1358         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1359         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1360         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1361 }
1362 run_test 27f "setstripe with bad stripe size (should return error)"
1363
1364 test_27g() {
1365         test_mkdir -p $DIR/d27
1366         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1367         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1368                 error "$DIR/d27/fnone has object"
1369 }
1370 run_test 27g "$GETSTRIPE with no objects"
1371
1372 test_27i() {
1373         touch $DIR/d27/fsome || error "touch failed"
1374         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1375 }
1376 run_test 27i "$GETSTRIPE with some objects"
1377
1378 test_27j() {
1379         test_mkdir -p $DIR/d27
1380         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1381 }
1382 run_test 27j "setstripe with bad stripe offset (should return error)"
1383
1384 test_27k() { # bug 2844
1385         test_mkdir -p $DIR/d27
1386         FILE=$DIR/d27/f27k
1387         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1388         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1389         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1390         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1391         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1392         dd if=/dev/zero of=$FILE bs=4k count=1
1393         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1394         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1395 }
1396 run_test 27k "limit i_blksize for broken user apps ============="
1397
1398 test_27l() {
1399         test_mkdir -p $DIR/d27
1400         mcreate $DIR/f27l || error "creating file"
1401         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1402                 error "setstripe should have failed" || true
1403 }
1404 run_test 27l "check setstripe permissions (should return error)"
1405
1406 test_27m() {
1407         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1408                 return
1409         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1410                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1411                 return
1412         fi
1413         trap simple_cleanup_common EXIT
1414         test_mkdir -p $DIR/$tdir
1415         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1416         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1417                 error "dd should fill OST0"
1418         i=2
1419         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1420                 i=$((i + 1))
1421                 [ $i -gt 256 ] && break
1422         done
1423         i=$((i + 1))
1424         touch $DIR/$tdir/f27m_$i
1425         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1426                 error "OST0 was full but new created file still use it"
1427         i=$((i + 1))
1428         touch $DIR/$tdir/f27m_$i
1429         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1430                 error "OST0 was full but new created file still use it"
1431         simple_cleanup_common
1432 }
1433 run_test 27m "create file while OST0 was full =================="
1434
1435 sleep_maxage() {
1436         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1437         sleep $DELAY
1438 }
1439
1440 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1441 # if the OST isn't full anymore.
1442 reset_enospc() {
1443         local OSTIDX=${1:-""}
1444
1445         local list=$(comma_list $(osts_nodes))
1446         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1447
1448         do_nodes $list lctl set_param fail_loc=0
1449         sync    # initiate all OST_DESTROYs from MDS to OST
1450         sleep_maxage
1451 }
1452
1453 exhaust_precreations() {
1454         local OSTIDX=$1
1455         local FAILLOC=$2
1456         local FAILIDX=${3:-$OSTIDX}
1457
1458         test_mkdir -p $DIR/$tdir
1459         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1460         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1461
1462         local OST=$(ostname_from_index $OSTIDX)
1463         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1464                           sed -e 's/_UUID$//;s/^.*-//')
1465
1466         # on the mdt's osc
1467         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1468         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1469                         osc.$mdtosc_proc1.prealloc_last_id)
1470         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1471                         osc.$mdtosc_proc1.prealloc_next_id)
1472
1473         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1474         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1475
1476         test_mkdir -p $DIR/$tdir/${OST}
1477         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1478 #define OBD_FAIL_OST_ENOSPC              0x215
1479         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1480         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1481         echo "Creating to objid $last_id on ost $OST..."
1482         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1483         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1484         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1485         sleep_maxage
1486 }
1487
1488 exhaust_all_precreations() {
1489         local i
1490         for (( i=0; i < OSTCOUNT; i++ )) ; do
1491                 exhaust_precreations $i $1 -1
1492         done
1493 }
1494
1495 test_27n() {
1496         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1498         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1499         remote_ost_nodsh && skip "remote OST with nodsh" && return
1500
1501         reset_enospc
1502         rm -f $DIR/$tdir/$tfile
1503         exhaust_precreations 0 0x80000215
1504         $SETSTRIPE -c -1 $DIR/$tdir
1505         touch $DIR/$tdir/$tfile || error
1506         $GETSTRIPE $DIR/$tdir/$tfile
1507         reset_enospc
1508 }
1509 run_test 27n "create file with some full OSTs =================="
1510
1511 test_27o() {
1512         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1513         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1514         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1515         remote_ost_nodsh && skip "remote OST with nodsh" && return
1516
1517         reset_enospc
1518         rm -f $DIR/$tdir/$tfile
1519         exhaust_all_precreations 0x215
1520
1521         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1522
1523         reset_enospc
1524         rm -rf $DIR/$tdir/*
1525 }
1526 run_test 27o "create file with all full OSTs (should error) ===="
1527
1528 test_27p() {
1529         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1531         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1532         remote_ost_nodsh && skip "remote OST with nodsh" && return
1533
1534         reset_enospc
1535         rm -f $DIR/$tdir/$tfile
1536         test_mkdir -p $DIR/$tdir
1537
1538         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1539         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1540         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1541
1542         exhaust_precreations 0 0x80000215
1543         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1544         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1545         $GETSTRIPE $DIR/$tdir/$tfile
1546
1547         reset_enospc
1548 }
1549 run_test 27p "append to a truncated file with some full OSTs ==="
1550
1551 test_27q() {
1552         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1554         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1555         remote_ost_nodsh && skip "remote OST with nodsh" && return
1556
1557         reset_enospc
1558         rm -f $DIR/$tdir/$tfile
1559
1560         test_mkdir -p $DIR/$tdir
1561         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1562         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1563         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1564
1565         exhaust_all_precreations 0x215
1566
1567         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1568         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1569
1570         reset_enospc
1571 }
1572 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1573
1574 test_27r() {
1575         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1576         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1577         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1578         remote_ost_nodsh && skip "remote OST with nodsh" && return
1579
1580         reset_enospc
1581         rm -f $DIR/$tdir/$tfile
1582         exhaust_precreations 0 0x80000215
1583
1584         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1585
1586         reset_enospc
1587 }
1588 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1589
1590 test_27s() { # bug 10725
1591         test_mkdir -p $DIR/$tdir
1592         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1593         local stripe_count=0
1594         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1595         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1596                 error "stripe width >= 2^32 succeeded" || true
1597
1598 }
1599 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1600
1601 test_27t() { # bug 10864
1602         WDIR=$(pwd)
1603         WLFS=$(which lfs)
1604         cd $DIR
1605         touch $tfile
1606         $WLFS getstripe $tfile
1607         cd $WDIR
1608 }
1609 run_test 27t "check that utils parse path correctly"
1610
1611 test_27u() { # bug 4900
1612         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1613         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1614         local index
1615         local list=$(comma_list $(mdts_nodes))
1616
1617 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1618         do_nodes $list $LCTL set_param fail_loc=0x139
1619         test_mkdir -p $DIR/$tdir
1620         rm -rf $DIR/$tdir/*
1621         createmany -o $DIR/$tdir/t- 1000
1622         do_nodes $list $LCTL set_param fail_loc=0
1623
1624         TLOG=$DIR/$tfile.getstripe
1625         $GETSTRIPE $DIR/$tdir > $TLOG
1626         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1627         unlinkmany $DIR/$tdir/t- 1000
1628         [[ $OBJS -gt 0 ]] &&
1629                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1630 }
1631 run_test 27u "skip object creation on OSC w/o objects =========="
1632
1633 test_27v() { # bug 4900
1634         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1635         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1636         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1637         remote_ost_nodsh && skip "remote OST with nodsh" && return
1638
1639         exhaust_all_precreations 0x215
1640         reset_enospc
1641
1642         test_mkdir -p $DIR/$tdir
1643         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1644
1645         touch $DIR/$tdir/$tfile
1646         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1647         # all except ost1
1648         for (( i=1; i < OSTCOUNT; i++ )); do
1649                 do_facet ost$i lctl set_param fail_loc=0x705
1650         done
1651         local START=`date +%s`
1652         createmany -o $DIR/$tdir/$tfile 32
1653
1654         local FINISH=`date +%s`
1655         local TIMEOUT=`lctl get_param -n timeout`
1656         local PROCESS=$((FINISH - START))
1657         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1658                error "$FINISH - $START >= $TIMEOUT / 2"
1659         sleep $((TIMEOUT / 2 - PROCESS))
1660         reset_enospc
1661 }
1662 run_test 27v "skip object creation on slow OST ================="
1663
1664 test_27w() { # bug 10997
1665         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1666         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1667         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1668                 error "stripe size $size != 65536" || true
1669         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1670                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1671 }
1672 run_test 27w "check $SETSTRIPE -S option"
1673
1674 test_27wa() {
1675         [[ $OSTCOUNT -lt 2 ]] &&
1676                 skip_env "skipping multiple stripe count/offset test" && return
1677
1678         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1679         for i in $(seq 1 $OSTCOUNT); do
1680                 offset=$((i - 1))
1681                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1682                         error "setstripe -c $i -i $offset failed"
1683                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1684                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1685                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1686                 [ $index -ne $offset ] &&
1687                         error "stripe offset $index != $offset" || true
1688         done
1689 }
1690 run_test 27wa "check $SETSTRIPE -c -i options"
1691
1692 test_27x() {
1693         remote_ost_nodsh && skip "remote OST with nodsh" && return
1694         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1696         OFFSET=$(($OSTCOUNT - 1))
1697         OSTIDX=0
1698         local OST=$(ostname_from_index $OSTIDX)
1699
1700         test_mkdir -p $DIR/$tdir
1701         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1702         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1703         sleep_maxage
1704         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1705         for i in `seq 0 $OFFSET`; do
1706                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1707                 error "OST0 was degraded but new created file still use it"
1708         done
1709         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1710 }
1711 run_test 27x "create files while OST0 is degraded"
1712
1713 test_27y() {
1714         [[ $OSTCOUNT -lt 2 ]] &&
1715                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1716         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1717         remote_ost_nodsh && skip "remote OST with nodsh" && return
1718         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1719
1720         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1721         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1722             osc.$mdtosc.prealloc_last_id)
1723         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1724             osc.$mdtosc.prealloc_next_id)
1725         local fcount=$((last_id - next_id))
1726         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1727         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1728
1729         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1730                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1731         local OST_DEACTIVE_IDX=-1
1732         local OSC
1733         local OSTIDX
1734         local OST
1735
1736         for OSC in $MDS_OSCS; do
1737                 OST=$(osc_to_ost $OSC)
1738                 OSTIDX=$(index_from_ostuuid $OST)
1739                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1740                         OST_DEACTIVE_IDX=$OSTIDX
1741                 fi
1742                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1743                         echo $OSC "is Deactivated:"
1744                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1745                 fi
1746         done
1747
1748         OSTIDX=$(index_from_ostuuid $OST)
1749         mkdir -p $DIR/$tdir
1750         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1751
1752         for OSC in $MDS_OSCS; do
1753                 OST=$(osc_to_ost $OSC)
1754                 OSTIDX=$(index_from_ostuuid $OST)
1755                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1756                         echo $OST "is degraded:"
1757                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1758                                                 obdfilter.$OST.degraded=1
1759                 fi
1760         done
1761
1762         sleep_maxage
1763         createmany -o $DIR/$tdir/$tfile $fcount
1764
1765         for OSC in $MDS_OSCS; do
1766                 OST=$(osc_to_ost $OSC)
1767                 OSTIDX=$(index_from_ostuuid $OST)
1768                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1769                         echo $OST "is recovered from degraded:"
1770                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1771                                                 obdfilter.$OST.degraded=0
1772                 else
1773                         do_facet $SINGLEMDS lctl --device %$OSC activate
1774                 fi
1775         done
1776
1777         # all osp devices get activated, hence -1 stripe count restored
1778         local stripecnt=0
1779
1780         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1781         # devices get activated.
1782         sleep_maxage
1783         $SETSTRIPE -c -1 $DIR/$tfile
1784         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1785         rm -f $DIR/$tfile
1786         [ $stripecnt -ne $OSTCOUNT ] &&
1787                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1788         return 0
1789 }
1790 run_test 27y "create files while OST0 is degraded and the rest inactive"
1791
1792 check_seq_oid()
1793 {
1794         log "check file $1"
1795
1796         lmm_count=$($GETSTRIPE -c $1)
1797         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1798         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1799
1800         local old_ifs="$IFS"
1801         IFS=$'[:]'
1802         fid=($($LFS path2fid $1))
1803         IFS="$old_ifs"
1804
1805         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1806         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1807
1808         # compare lmm_seq and lu_fid->f_seq
1809         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1810         # compare lmm_object_id and lu_fid->oid
1811         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1812
1813         # check the trusted.fid attribute of the OST objects of the file
1814         local have_obdidx=false
1815         local stripe_nr=0
1816         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1817                 # skip lines up to and including "obdidx"
1818                 [ -z "$obdidx" ] && break
1819                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1820                 $have_obdidx || continue
1821
1822                 local ost=$((obdidx + 1))
1823                 local dev=$(ostdevname $ost)
1824                 local oid_hex
1825
1826                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1827
1828                 seq=$(echo $seq | sed -e "s/^0x//g")
1829                 if [ $seq == 0 ]; then
1830                         oid_hex=$(echo $oid)
1831                 else
1832                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1833                 fi
1834                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1835
1836                 local ff
1837                 #
1838                 # Don't unmount/remount the OSTs if we don't need to do that.
1839                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1840                 # update too, until that use mount/ll_decode_filter_fid/mount.
1841                 # Re-enable when debugfs will understand new filter_fid.
1842                 #
1843                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1844                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1845                                 $dev 2>/dev/null" | grep "parent=")
1846                 else
1847                         stop ost$ost
1848                         mount_fstype ost$ost
1849                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1850                                 $(facet_mntpt ost$ost)/$obj_file)
1851                         unmount_fstype ost$ost
1852                         start ost$ost $dev $OST_MOUNT_OPTS
1853                 fi
1854
1855                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1856
1857                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1858
1859                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1860                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1861                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1862                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1863                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1864                 local ff_pstripe
1865                 if echo $ff_parent | grep -q 'stripe='; then
1866                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1867                 else
1868                         #
1869                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1870                         # into f_ver in this case.  See the comment on
1871                         # ff_parent.
1872                         #
1873                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1874                                 sed -e 's/\]//')
1875                 fi
1876
1877                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1878                 [ $ff_pseq = $lmm_seq ] ||
1879                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1880                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1881                 [ $ff_poid = $lmm_oid ] ||
1882                         error "FF parent OID $ff_poid != $lmm_oid"
1883                 (($ff_pstripe == $stripe_nr)) ||
1884                         error "FF stripe $ff_pstripe != $stripe_nr"
1885
1886                 stripe_nr=$((stripe_nr + 1))
1887         done
1888 }
1889
1890 test_27z() {
1891         remote_ost_nodsh && skip "remote OST with nodsh" && return
1892         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1893         test_mkdir -p $DIR/$tdir
1894
1895         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1896                 { error "setstripe -c -1 failed"; return 1; }
1897         # We need to send a write to every object to get parent FID info set.
1898         # This _should_ also work for setattr, but does not currently.
1899         # touch $DIR/$tdir/$tfile-1 ||
1900         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1901                 { error "dd $tfile-1 failed"; return 2; }
1902         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1903                 { error "setstripe -c -1 failed"; return 3; }
1904         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1905                 { error "dd $tfile-2 failed"; return 4; }
1906
1907         # make sure write RPCs have been sent to OSTs
1908         sync; sleep 5; sync
1909
1910         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1911         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1912 }
1913 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1914
1915 test_27A() { # b=19102
1916         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1917         local restore_size=$($GETSTRIPE -S $MOUNT)
1918         local restore_count=$($GETSTRIPE -c $MOUNT)
1919         local restore_offset=$($GETSTRIPE -i $MOUNT)
1920         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1921         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1922                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1923         local default_size=$($GETSTRIPE -S $MOUNT)
1924         local default_offset=$($GETSTRIPE -i $MOUNT)
1925         local dsize=$((1024 * 1024))
1926         [ $default_size -eq $dsize ] ||
1927                 error "stripe size $default_size != $dsize"
1928         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1929         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1930 }
1931 run_test 27A "check filesystem-wide default LOV EA values"
1932
1933 test_27B() { # LU-2523
1934         test_mkdir -p $DIR/$tdir
1935         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1936         touch $DIR/$tdir/f0
1937         # open f1 with O_LOV_DELAY_CREATE
1938         # rename f0 onto f1
1939         # call setstripe ioctl on open file descriptor for f1
1940         # close
1941         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1942                 $DIR/$tdir/f0
1943
1944         rm -f $DIR/$tdir/f1
1945         # open f1 with O_LOV_DELAY_CREATE
1946         # unlink f1
1947         # call setstripe ioctl on open file descriptor for f1
1948         # close
1949         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1950
1951         # Allow multiop to fail in imitation of NFS's busted semantics.
1952         true
1953 }
1954 run_test 27B "call setstripe on open unlinked file/rename victim"
1955
1956 test_27C() { #LU-2871
1957         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1958
1959         declare -a ost_idx
1960         local index
1961         local found
1962         local i
1963         local j
1964
1965         test_mkdir -p $DIR/$tdir
1966         cd $DIR/$tdir
1967         for i in $(seq 0 $((OSTCOUNT - 1))); do
1968                 # set stripe across all OSTs starting from OST$i
1969                 $SETSTRIPE -i $i -c -1 $tfile$i
1970                 # get striping information
1971                 ost_idx=($($GETSTRIPE $tfile$i |
1972                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1973                 echo ${ost_idx[@]}
1974
1975                 # check the layout
1976                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1977                         error "${#ost_idx[@]} != $OSTCOUNT"
1978
1979                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1980                         found=0
1981                         for j in $(echo ${ost_idx[@]}); do
1982                                 if [ $index -eq $j ]; then
1983                                         found=1
1984                                         break
1985                                 fi
1986                         done
1987                         [ $found = 1 ] ||
1988                                 error "Can not find $index in ${ost_idx[@]}"
1989                 done
1990         done
1991 }
1992 run_test 27C "check full striping across all OSTs"
1993
1994 test_27D() {
1995         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1996         local POOL=${POOL:-testpool}
1997         local first_ost=0
1998         local last_ost=$(($OSTCOUNT - 1))
1999         local ost_step=1
2000         local ost_list=$(seq $first_ost $ost_step $last_ost)
2001         local ost_range="$first_ost $last_ost $ost_step"
2002
2003         mkdir -p $DIR/$tdir
2004         pool_add $POOL || error "pool_add failed"
2005         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2006         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2007                 error "llapi_layout_test failed"
2008         cleanup_pools || error "cleanup_pools failed"
2009 }
2010 run_test 27D "validate llapi_layout API"
2011
2012 # createtest also checks that device nodes are created and
2013 # then visible correctly (#2091)
2014 test_28() { # bug 2091
2015         test_mkdir $DIR/d28
2016         $CREATETEST $DIR/d28/ct || error
2017 }
2018 run_test 28 "create/mknod/mkdir with bad file types ============"
2019
2020 test_29() {
2021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2022         cancel_lru_locks mdc
2023         test_mkdir $DIR/d29
2024         touch $DIR/d29/foo
2025         log 'first d29'
2026         ls -l $DIR/d29
2027
2028         declare -i LOCKCOUNTORIG=0
2029         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2030                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2031         done
2032         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2033
2034         declare -i LOCKUNUSEDCOUNTORIG=0
2035         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2036                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2037         done
2038
2039         log 'second d29'
2040         ls -l $DIR/d29
2041         log 'done'
2042
2043         declare -i LOCKCOUNTCURRENT=0
2044         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2045                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2046         done
2047
2048         declare -i LOCKUNUSEDCOUNTCURRENT=0
2049         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2050                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2051         done
2052
2053         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2054                 $LCTL set_param -n ldlm.dump_namespaces ""
2055                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2056                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2057                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2058                 return 2
2059         fi
2060         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2061                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2062                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2063                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2064                 return 3
2065         fi
2066 }
2067 run_test 29 "IT_GETATTR regression  ============================"
2068
2069 test_30a() { # was test_30
2070         cp $(which ls) $DIR || cp /bin/ls $DIR
2071         $DIR/ls / || error
2072         rm $DIR/ls
2073 }
2074 run_test 30a "execute binary from Lustre (execve) =============="
2075
2076 test_30b() {
2077         cp `which ls` $DIR || cp /bin/ls $DIR
2078         chmod go+rx $DIR/ls
2079         $RUNAS $DIR/ls / || error
2080         rm $DIR/ls
2081 }
2082 run_test 30b "execute binary from Lustre as non-root ==========="
2083
2084 test_30c() { # b=22376
2085         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2086         cp `which ls` $DIR || cp /bin/ls $DIR
2087         chmod a-rw $DIR/ls
2088         cancel_lru_locks mdc
2089         cancel_lru_locks osc
2090         $RUNAS $DIR/ls / || error
2091         rm -f $DIR/ls
2092 }
2093 run_test 30c "execute binary from Lustre without read perms ===="
2094
2095 test_31a() {
2096         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2097         $CHECKSTAT -a $DIR/f31 || error
2098 }
2099 run_test 31a "open-unlink file =================================="
2100
2101 test_31b() {
2102         touch $DIR/f31 || error
2103         ln $DIR/f31 $DIR/f31b || error
2104         $MULTIOP $DIR/f31b Ouc || error
2105         $CHECKSTAT -t file $DIR/f31 || error
2106 }
2107 run_test 31b "unlink file with multiple links while open ======="
2108
2109 test_31c() {
2110         touch $DIR/f31 || error
2111         ln $DIR/f31 $DIR/f31c || error
2112         multiop_bg_pause $DIR/f31 O_uc || return 1
2113         MULTIPID=$!
2114         $MULTIOP $DIR/f31c Ouc
2115         kill -USR1 $MULTIPID
2116         wait $MULTIPID
2117 }
2118 run_test 31c "open-unlink file with multiple links ============="
2119
2120 test_31d() {
2121         opendirunlink $DIR/d31d $DIR/d31d || error
2122         $CHECKSTAT -a $DIR/d31d || error
2123 }
2124 run_test 31d "remove of open directory ========================="
2125
2126 test_31e() { # bug 2904
2127         check_kernel_version 34 || return 0
2128         openfilleddirunlink $DIR/d31e || error
2129 }
2130 run_test 31e "remove of open non-empty directory ==============="
2131
2132 test_31f() { # bug 4554
2133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2134         set -vx
2135         test_mkdir $DIR/d31f
2136         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2137         cp /etc/hosts $DIR/d31f
2138         ls -l $DIR/d31f
2139         $GETSTRIPE $DIR/d31f/hosts
2140         multiop_bg_pause $DIR/d31f D_c || return 1
2141         MULTIPID=$!
2142
2143         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2144         test_mkdir $DIR/d31f
2145         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2146         cp /etc/hosts $DIR/d31f
2147         ls -l $DIR/d31f
2148         $GETSTRIPE $DIR/d31f/hosts
2149         multiop_bg_pause $DIR/d31f D_c || return 1
2150         MULTIPID2=$!
2151
2152         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2153         wait $MULTIPID || error "first opendir $MULTIPID failed"
2154
2155         sleep 6
2156
2157         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2158         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2159         set +vx
2160 }
2161 run_test 31f "remove of open directory with open-unlink file ==="
2162
2163 test_31g() {
2164         echo "-- cross directory link --"
2165         test_mkdir -c1 $DIR/${tdir}ga
2166         test_mkdir -c1 $DIR/${tdir}gb
2167         touch $DIR/${tdir}ga/f
2168         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2169         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2170         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2171         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2172         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2173 }
2174 run_test 31g "cross directory link==============="
2175
2176 test_31h() {
2177         echo "-- cross directory link --"
2178         test_mkdir -c1 $DIR/${tdir}
2179         test_mkdir -c1 $DIR/${tdir}/dir
2180         touch $DIR/${tdir}/f
2181         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2182         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2183         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2184         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2185         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2186 }
2187 run_test 31h "cross directory link under child==============="
2188
2189 test_31i() {
2190         echo "-- cross directory link --"
2191         test_mkdir -c1 $DIR/$tdir
2192         test_mkdir -c1 $DIR/$tdir/dir
2193         touch $DIR/$tdir/dir/f
2194         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2195         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2196         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2197         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2198         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2199 }
2200 run_test 31i "cross directory link under parent==============="
2201
2202 test_31j() {
2203         test_mkdir -c1 -p $DIR/$tdir
2204         test_mkdir -c1 -p $DIR/$tdir/dir1
2205         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2206         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2207         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2208         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2209         return 0
2210 }
2211 run_test 31j "link for directory==============="
2212
2213 test_31k() {
2214         test_mkdir -c1 -p $DIR/$tdir
2215         touch $DIR/$tdir/s
2216         touch $DIR/$tdir/exist
2217         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2218         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2219         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2220         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2221         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2222         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2223         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2224         return 0
2225 }
2226 run_test 31k "link to file: the same, non-existing, dir==============="
2227
2228 test_31m() {
2229         mkdir $DIR/d31m
2230         touch $DIR/d31m/s
2231         mkdir $DIR/d31m2
2232         touch $DIR/d31m2/exist
2233         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2234         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2235         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2236         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2237         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2238         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2239         return 0
2240 }
2241 run_test 31m "link to file: the same, non-existing, dir==============="
2242
2243 test_31n() {
2244         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2245         nlink=$(stat --format=%h $DIR/$tfile)
2246         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2247         local fd=$(free_fd)
2248         local cmd="exec $fd<$DIR/$tfile"
2249         eval $cmd
2250         cmd="exec $fd<&-"
2251         trap "eval $cmd" EXIT
2252         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2253         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2254         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2255         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2256         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2257         eval $cmd
2258 }
2259 run_test 31n "check link count of unlinked file"
2260
2261 link_one() {
2262         local TEMPNAME=$(mktemp $1_XXXXXX)
2263         mlink $TEMPNAME $1 2> /dev/null &&
2264                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2265         munlink $TEMPNAME
2266 }
2267
2268 test_31o() { # LU-2901
2269         mkdir -p $DIR/$tdir
2270         for LOOP in $(seq 100); do
2271                 rm -f $DIR/$tdir/$tfile*
2272                 for THREAD in $(seq 8); do
2273                         link_one $DIR/$tdir/$tfile.$LOOP &
2274                 done
2275                 wait
2276                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2277                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2278                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2279                         break || true
2280         done
2281 }
2282 run_test 31o "duplicate hard links with same filename"
2283
2284 test_31p() {
2285         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2286
2287         mkdir $DIR/$tdir
2288         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2289         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2290
2291         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2292                 error "open unlink test1 failed"
2293         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2294                 error "open unlink test2 failed"
2295
2296         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2297                 error "test1 still exists"
2298         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2299                 error "test2 still exists"
2300 }
2301 run_test 31p "remove of open striped directory"
2302
2303 cleanup_test32_mount() {
2304         trap 0
2305         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2306 }
2307
2308 test_32a() {
2309         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2310         echo "== more mountpoints and symlinks ================="
2311         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2312         trap cleanup_test32_mount EXIT
2313         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2314         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2315         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2316         cleanup_test32_mount
2317 }
2318 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2319
2320 test_32b() {
2321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2322         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2323         trap cleanup_test32_mount EXIT
2324         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2325         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2326         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2327         cleanup_test32_mount
2328 }
2329 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2330
2331 test_32c() {
2332         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2333         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2334         trap cleanup_test32_mount EXIT
2335         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2336         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2337         test_mkdir -p $DIR/$tdir/d2/test_dir
2338         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2339         cleanup_test32_mount
2340 }
2341 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2342
2343 test_32d() {
2344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2345         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2346         trap cleanup_test32_mount EXIT
2347         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2348         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2349         test_mkdir -p $DIR/$tdir/d2/test_dir
2350         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2351         cleanup_test32_mount
2352 }
2353 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2354
2355 test_32e() {
2356         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2357         test_mkdir -p $DIR/d32e/tmp
2358         TMP_DIR=$DIR/d32e/tmp
2359         ln -s $DIR/d32e $TMP_DIR/symlink11
2360         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2361         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2362         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2363 }
2364 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2365
2366 test_32f() {
2367         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2368         test_mkdir -p $DIR/d32f/tmp
2369         TMP_DIR=$DIR/d32f/tmp
2370         ln -s $DIR/d32f $TMP_DIR/symlink11
2371         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2372         ls $DIR/d32f/tmp/symlink11  || error
2373         ls $DIR/d32f/symlink01 || error
2374 }
2375 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2376
2377 test_32g() {
2378         TMP_DIR=$DIR/$tdir/tmp
2379         test_mkdir -p $DIR/$tdir/tmp
2380         test_mkdir $DIR/${tdir}2
2381         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2382         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2383         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2384         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2385         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2386         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2387 }
2388 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2389
2390 test_32h() {
2391         rm -fr $DIR/$tdir $DIR/${tdir}2
2392         TMP_DIR=$DIR/$tdir/tmp
2393         test_mkdir -p $DIR/$tdir/tmp
2394         test_mkdir $DIR/${tdir}2
2395         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2396         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2397         ls $TMP_DIR/symlink12 || error
2398         ls $DIR/$tdir/symlink02  || error
2399 }
2400 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2401
2402 test_32i() {
2403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2404         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2405         trap cleanup_test32_mount EXIT
2406         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2407         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2408         touch $DIR/$tdir/test_file
2409         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2410         cleanup_test32_mount
2411 }
2412 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2413
2414 test_32j() {
2415         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2416         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2417         trap cleanup_test32_mount EXIT
2418         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2419         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2420         touch $DIR/$tdir/test_file
2421         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2422         cleanup_test32_mount
2423 }
2424 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2425
2426 test_32k() {
2427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2428         rm -fr $DIR/$tdir
2429         trap cleanup_test32_mount EXIT
2430         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2431         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2432         test_mkdir -p $DIR/$tdir/d2
2433         touch $DIR/$tdir/d2/test_file || error
2434         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2435         cleanup_test32_mount
2436 }
2437 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2438
2439 test_32l() {
2440         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2441         rm -fr $DIR/$tdir
2442         trap cleanup_test32_mount EXIT
2443         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2444         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2445         test_mkdir -p $DIR/$tdir/d2
2446         touch $DIR/$tdir/d2/test_file
2447         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2448         cleanup_test32_mount
2449 }
2450 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2451
2452 test_32m() {
2453         rm -fr $DIR/d32m
2454         test_mkdir -p $DIR/d32m/tmp
2455         TMP_DIR=$DIR/d32m/tmp
2456         ln -s $DIR $TMP_DIR/symlink11
2457         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2458         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2459         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2460 }
2461 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2462
2463 test_32n() {
2464         rm -fr $DIR/d32n
2465         test_mkdir -p $DIR/d32n/tmp
2466         TMP_DIR=$DIR/d32n/tmp
2467         ln -s $DIR $TMP_DIR/symlink11
2468         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2469         ls -l $DIR/d32n/tmp/symlink11  || error
2470         ls -l $DIR/d32n/symlink01 || error
2471 }
2472 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2473
2474 test_32o() {
2475         touch $DIR/$tfile
2476         test_mkdir -p $DIR/d32o/tmp
2477         TMP_DIR=$DIR/d32o/tmp
2478         ln -s $DIR/$tfile $TMP_DIR/symlink12
2479         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2480         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2481         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2482         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2483         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2484 }
2485 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2486
2487 test_32p() {
2488     log 32p_1
2489         rm -fr $DIR/d32p
2490     log 32p_2
2491         rm -f $DIR/$tfile
2492     log 32p_3
2493         touch $DIR/$tfile
2494     log 32p_4
2495         test_mkdir -p $DIR/d32p/tmp
2496     log 32p_5
2497         TMP_DIR=$DIR/d32p/tmp
2498     log 32p_6
2499         ln -s $DIR/$tfile $TMP_DIR/symlink12
2500     log 32p_7
2501         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2502     log 32p_8
2503         cat $DIR/d32p/tmp/symlink12 || error
2504     log 32p_9
2505         cat $DIR/d32p/symlink02 || error
2506     log 32p_10
2507 }
2508 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2509
2510 cleanup_testdir_mount() {
2511         trap 0
2512         $UMOUNT -d $DIR/$tdir
2513 }
2514
2515 test_32q() {
2516         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2517         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2518         trap cleanup_testdir_mount EXIT
2519         test_mkdir -p $DIR/$tdir
2520         touch $DIR/$tdir/under_the_mount
2521         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2522         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2523         cleanup_testdir_mount
2524 }
2525 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2526
2527 test_32r() {
2528         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2529         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2530         trap cleanup_testdir_mount EXIT
2531         test_mkdir -p $DIR/$tdir
2532         touch $DIR/$tdir/under_the_mount
2533         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2534         ls $DIR/$tdir | grep -q under_the_mount && error || true
2535         cleanup_testdir_mount
2536 }
2537 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2538
2539 test_33aa() {
2540         rm -f $DIR/$tfile
2541         touch $DIR/$tfile
2542         chmod 444 $DIR/$tfile
2543         chown $RUNAS_ID $DIR/$tfile
2544         log 33_1
2545         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2546         log 33_2
2547 }
2548 run_test 33aa "write file with mode 444 (should return error) ===="
2549
2550 test_33a() {
2551         rm -fr $DIR/d33
2552         test_mkdir -p $DIR/d33
2553         chown $RUNAS_ID $DIR/d33
2554         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2555         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2556                 error "open RDWR" || true
2557 }
2558 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2559
2560 test_33b() {
2561         rm -fr $DIR/d33
2562         test_mkdir -p $DIR/d33
2563         chown $RUNAS_ID $DIR/d33
2564         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33
2565 }
2566 run_test 33b "test open file with malformed flags (No panic)"
2567
2568 test_33c() {
2569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2570         local ostnum
2571         local ostname
2572         local write_bytes
2573         local all_zeros
2574
2575         remote_ost_nodsh && skip "remote OST with nodsh" && return
2576         all_zeros=:
2577         rm -fr $DIR/d33
2578         test_mkdir -p $DIR/d33
2579         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2580
2581         sync
2582         for ostnum in $(seq $OSTCOUNT); do
2583                 # test-framework's OST numbering is one-based, while Lustre's
2584                 # is zero-based
2585                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2586                 # Parsing llobdstat's output sucks; we could grep the /proc
2587                 # path, but that's likely to not be as portable as using the
2588                 # llobdstat utility.  So we parse lctl output instead.
2589                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2590                         obdfilter/$ostname/stats |
2591                         awk '/^write_bytes/ {print $7}' )
2592                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2593                 if (( ${write_bytes:-0} > 0 ))
2594                 then
2595                         all_zeros=false
2596                         break;
2597                 fi
2598         done
2599
2600         $all_zeros || return 0
2601
2602         # Write four bytes
2603         echo foo > $DIR/d33/bar
2604         # Really write them
2605         sync
2606
2607         # Total up write_bytes after writing.  We'd better find non-zeros.
2608         for ostnum in $(seq $OSTCOUNT); do
2609                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2610                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2611                         obdfilter/$ostname/stats |
2612                         awk '/^write_bytes/ {print $7}' )
2613                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2614                 if (( ${write_bytes:-0} > 0 ))
2615                 then
2616                         all_zeros=false
2617                         break;
2618                 fi
2619         done
2620
2621         if $all_zeros
2622         then
2623                 for ostnum in $(seq $OSTCOUNT); do
2624                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2625                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2626                         do_facet ost$ostnum lctl get_param -n \
2627                                 obdfilter/$ostname/stats
2628                 done
2629                 error "OST not keeping write_bytes stats (b22312)"
2630         fi
2631 }
2632 run_test 33c "test llobdstat and write_bytes"
2633
2634 test_33d() {
2635         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2636         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2637         local MDTIDX=1
2638         local remote_dir=$DIR/$tdir/remote_dir
2639
2640         mkdir -p $DIR/$tdir
2641         $LFS mkdir -i $MDTIDX $remote_dir ||
2642                 error "create remote directory failed"
2643
2644         touch $remote_dir/$tfile
2645         chmod 444 $remote_dir/$tfile
2646         chown $RUNAS_ID $remote_dir/$tfile
2647
2648         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2649
2650         chown $RUNAS_ID $remote_dir
2651         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2652                                         error "create" || true
2653         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2654                                     error "open RDWR" || true
2655         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2656                                     error "create" || true
2657 }
2658 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2659
2660 test_33e() {
2661         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2662
2663         mkdir $DIR/$tdir
2664
2665         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2666         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2667         mkdir $DIR/$tdir/local_dir
2668
2669         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2670         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2671         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2672
2673         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2674                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2675
2676         rmdir $DIR/$tdir/* || error "rmdir failed"
2677
2678         umask 777
2679         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2680         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2681         mkdir $DIR/$tdir/local_dir
2682
2683         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2684         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2685         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2686
2687         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2688                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2689
2690         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2691
2692         umask 000
2693         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2694         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2695         mkdir $DIR/$tdir/local_dir
2696
2697         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2698         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2699         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2700
2701         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2702                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2703 }
2704 run_test 33e "mkdir and striped directory should have same mode"
2705
2706 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2707 test_34a() {
2708         rm -f $DIR/f34
2709         $MCREATE $DIR/f34 || error
2710         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2711         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2712         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2713         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2714 }
2715 run_test 34a "truncate file that has not been opened ==========="
2716
2717 test_34b() {
2718         [ ! -f $DIR/f34 ] && test_34a
2719         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2720         $OPENFILE -f O_RDONLY $DIR/f34
2721         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2722         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2723 }
2724 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2725
2726 test_34c() {
2727         [ ! -f $DIR/f34 ] && test_34a
2728         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2729         $OPENFILE -f O_RDWR $DIR/f34
2730         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2731         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2732 }
2733 run_test 34c "O_RDWR opening file-with-size works =============="
2734
2735 test_34d() {
2736         [ ! -f $DIR/f34 ] && test_34a
2737         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2738         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2739         rm $DIR/f34
2740 }
2741 run_test 34d "write to sparse file ============================="
2742
2743 test_34e() {
2744         rm -f $DIR/f34e
2745         $MCREATE $DIR/f34e || error
2746         $TRUNCATE $DIR/f34e 1000 || error
2747         $CHECKSTAT -s 1000 $DIR/f34e || error
2748         $OPENFILE -f O_RDWR $DIR/f34e
2749         $CHECKSTAT -s 1000 $DIR/f34e || error
2750 }
2751 run_test 34e "create objects, some with size and some without =="
2752
2753 test_34f() { # bug 6242, 6243
2754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2755         SIZE34F=48000
2756         rm -f $DIR/f34f
2757         $MCREATE $DIR/f34f || error
2758         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2759         dd if=$DIR/f34f of=$TMP/f34f
2760         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2761         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2762         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2763         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2764         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2765 }
2766 run_test 34f "read from a file with no objects until EOF ======="
2767
2768 test_34g() {
2769         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2770         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2771         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2772         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2773         cancel_lru_locks osc
2774         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2775                 error "wrong size after lock cancel"
2776
2777         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2778         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2779                 error "expanding truncate failed"
2780         cancel_lru_locks osc
2781         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2782                 error "wrong expanded size after lock cancel"
2783 }
2784 run_test 34g "truncate long file ==============================="
2785
2786 test_34h() {
2787         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2788         local gid=10
2789         local sz=1000
2790
2791         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2792         sync # Flush the cache so that multiop below does not block on cache
2793              # flush when getting the group lock
2794         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2795         MULTIPID=$!
2796
2797         # Since just timed wait is not good enough, let's do a sync write
2798         # that way we are sure enough time for a roundtrip + processing
2799         # passed + 2 seconds of extra margin.
2800         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2801         rm $DIR/${tfile}-1
2802         sleep 2
2803
2804         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2805                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2806                 kill -9 $MULTIPID
2807         fi
2808         wait $MULTIPID
2809         local nsz=`stat -c %s $DIR/$tfile`
2810         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2811 }
2812 run_test 34h "ftruncate file under grouplock should not block"
2813
2814 test_35a() {
2815         cp /bin/sh $DIR/f35a
2816         chmod 444 $DIR/f35a
2817         chown $RUNAS_ID $DIR/f35a
2818         $RUNAS $DIR/f35a && error || true
2819         rm $DIR/f35a
2820 }
2821 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2822
2823 test_36a() {
2824         rm -f $DIR/f36
2825         utime $DIR/f36 || error
2826 }
2827 run_test 36a "MDS utime check (mknod, utime) ==================="
2828
2829 test_36b() {
2830         echo "" > $DIR/f36
2831         utime $DIR/f36 || error
2832 }
2833 run_test 36b "OST utime check (open, utime) ===================="
2834
2835 test_36c() {
2836         rm -f $DIR/d36/f36
2837         test_mkdir $DIR/d36
2838         chown $RUNAS_ID $DIR/d36
2839         $RUNAS utime $DIR/d36/f36 || error
2840 }
2841 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2842
2843 test_36d() {
2844         [ ! -d $DIR/d36 ] && test_36c
2845         echo "" > $DIR/d36/f36
2846         $RUNAS utime $DIR/d36/f36 || error
2847 }
2848 run_test 36d "non-root OST utime check (open, utime) ==========="
2849
2850 test_36e() {
2851         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2852         test_mkdir -p $DIR/$tdir
2853         touch $DIR/$tdir/$tfile
2854         $RUNAS utime $DIR/$tdir/$tfile && \
2855                 error "utime worked, expected failure" || true
2856 }
2857 run_test 36e "utime on non-owned file (should return error) ===="
2858
2859 subr_36fh() {
2860         local fl="$1"
2861         local LANG_SAVE=$LANG
2862         local LC_LANG_SAVE=$LC_LANG
2863         export LANG=C LC_LANG=C # for date language
2864
2865         DATESTR="Dec 20  2000"
2866         test_mkdir -p $DIR/$tdir
2867         lctl set_param fail_loc=$fl
2868         date; date +%s
2869         cp /etc/hosts $DIR/$tdir/$tfile
2870         sync & # write RPC generated with "current" inode timestamp, but delayed
2871         sleep 1
2872         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2873         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2874         cancel_lru_locks osc
2875         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2876         date; date +%s
2877         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2878                 echo "BEFORE: $LS_BEFORE" && \
2879                 echo "AFTER : $LS_AFTER" && \
2880                 echo "WANT  : $DATESTR" && \
2881                 error "$DIR/$tdir/$tfile timestamps changed" || true
2882
2883         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2884 }
2885
2886 test_36f() {
2887         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2888         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2889         subr_36fh "0x80000214"
2890 }
2891 run_test 36f "utime on file racing with OST BRW write =========="
2892
2893 test_36g() {
2894         remote_ost_nodsh && skip "remote OST with nodsh" && return
2895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2896         local fmd_max_age
2897         local fmd_before
2898         local fmd_after
2899
2900         test_mkdir -p $DIR/$tdir
2901         fmd_max_age=$(do_facet ost1 \
2902                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2903                 head -n 1")
2904
2905         fmd_before=$(do_facet ost1 \
2906                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2907         touch $DIR/$tdir/$tfile
2908         sleep $((fmd_max_age + 12))
2909         fmd_after=$(do_facet ost1 \
2910                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2911
2912         echo "fmd_before: $fmd_before"
2913         echo "fmd_after: $fmd_after"
2914         [[ $fmd_after -gt $fmd_before ]] &&
2915                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2916                 error "fmd didn't expire after ping" || true
2917 }
2918 run_test 36g "filter mod data cache expiry ====================="
2919
2920 test_36h() {
2921         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2922         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2923         subr_36fh "0x80000227"
2924 }
2925 run_test 36h "utime on file racing with OST BRW write =========="
2926
2927 test_36i() {
2928         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2929
2930         mkdir $DIR/$tdir
2931         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2932
2933         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
2934         local new_mtime=$((mtime + 200))
2935
2936         #change Modify time of striped dir
2937         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
2938                         error "change mtime failed"
2939
2940         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
2941
2942         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
2943 }
2944 run_test 36i "change mtime on striped directory"
2945
2946 # test_37 - duplicate with tests 32q 32r
2947
2948 test_38() {
2949         local file=$DIR/$tfile
2950         touch $file
2951         openfile -f O_DIRECTORY $file
2952         local RC=$?
2953         local ENOTDIR=20
2954         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2955         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2956 }
2957 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2958
2959 test_39() {
2960         touch $DIR/$tfile
2961         touch $DIR/${tfile}2
2962 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2963 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2964 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2965         sleep 2
2966         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2967         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2968                 echo "mtime"
2969                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2970                 echo "atime"
2971                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2972                 echo "ctime"
2973                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2974                 error "O_TRUNC didn't change timestamps"
2975         fi
2976 }
2977 run_test 39 "mtime changed on create ==========================="
2978
2979 test_39b() {
2980         test_mkdir -p -c1 $DIR/$tdir
2981         cp -p /etc/passwd $DIR/$tdir/fopen
2982         cp -p /etc/passwd $DIR/$tdir/flink
2983         cp -p /etc/passwd $DIR/$tdir/funlink
2984         cp -p /etc/passwd $DIR/$tdir/frename
2985         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2986
2987         sleep 1
2988         echo "aaaaaa" >> $DIR/$tdir/fopen
2989         echo "aaaaaa" >> $DIR/$tdir/flink
2990         echo "aaaaaa" >> $DIR/$tdir/funlink
2991         echo "aaaaaa" >> $DIR/$tdir/frename
2992
2993         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2994         local link_new=`stat -c %Y $DIR/$tdir/flink`
2995         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2996         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2997
2998         cat $DIR/$tdir/fopen > /dev/null
2999         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3000         rm -f $DIR/$tdir/funlink2
3001         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3002
3003         for (( i=0; i < 2; i++ )) ; do
3004                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3005                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3006                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3007                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3008
3009                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3010                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3011                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3012                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3013
3014                 cancel_lru_locks osc
3015                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3016         done
3017 }
3018 run_test 39b "mtime change on open, link, unlink, rename  ======"
3019
3020 # this should be set to past
3021 TEST_39_MTIME=`date -d "1 year ago" +%s`
3022
3023 # bug 11063
3024 test_39c() {
3025         touch $DIR1/$tfile
3026         sleep 2
3027         local mtime0=`stat -c %Y $DIR1/$tfile`
3028
3029         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3030         local mtime1=`stat -c %Y $DIR1/$tfile`
3031         [ "$mtime1" = $TEST_39_MTIME ] || \
3032                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3033
3034         local d1=`date +%s`
3035         echo hello >> $DIR1/$tfile
3036         local d2=`date +%s`
3037         local mtime2=`stat -c %Y $DIR1/$tfile`
3038         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3039                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3040
3041         mv $DIR1/$tfile $DIR1/$tfile-1
3042
3043         for (( i=0; i < 2; i++ )) ; do
3044                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3045                 [ "$mtime2" = "$mtime3" ] || \
3046                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3047
3048                 cancel_lru_locks osc
3049                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3050         done
3051 }
3052 run_test 39c "mtime change on rename ==========================="
3053
3054 # bug 21114
3055 test_39d() {
3056         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3057         touch $DIR1/$tfile
3058
3059         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3060
3061         for (( i=0; i < 2; i++ )) ; do
3062                 local mtime=`stat -c %Y $DIR1/$tfile`
3063                 [ $mtime = $TEST_39_MTIME ] || \
3064                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3065
3066                 cancel_lru_locks osc
3067                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3068         done
3069 }
3070 run_test 39d "create, utime, stat =============================="
3071
3072 # bug 21114
3073 test_39e() {
3074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3075         touch $DIR1/$tfile
3076         local mtime1=`stat -c %Y $DIR1/$tfile`
3077
3078         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3079
3080         for (( i=0; i < 2; i++ )) ; do
3081                 local mtime2=`stat -c %Y $DIR1/$tfile`
3082                 [ $mtime2 = $TEST_39_MTIME ] || \
3083                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3084
3085                 cancel_lru_locks osc
3086                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3087         done
3088 }
3089 run_test 39e "create, stat, utime, stat ========================"
3090
3091 # bug 21114
3092 test_39f() {
3093         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3094         touch $DIR1/$tfile
3095         mtime1=`stat -c %Y $DIR1/$tfile`
3096
3097         sleep 2
3098         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3099
3100         for (( i=0; i < 2; i++ )) ; do
3101                 local mtime2=`stat -c %Y $DIR1/$tfile`
3102                 [ $mtime2 = $TEST_39_MTIME ] || \
3103                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3104
3105                 cancel_lru_locks osc
3106                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3107         done
3108 }
3109 run_test 39f "create, stat, sleep, utime, stat ================="
3110
3111 # bug 11063
3112 test_39g() {
3113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3114         echo hello >> $DIR1/$tfile
3115         local mtime1=`stat -c %Y $DIR1/$tfile`
3116
3117         sleep 2
3118         chmod o+r $DIR1/$tfile
3119
3120         for (( i=0; i < 2; i++ )) ; do
3121                 local mtime2=`stat -c %Y $DIR1/$tfile`
3122                 [ "$mtime1" = "$mtime2" ] || \
3123                         error "lost mtime: $mtime2, should be $mtime1"
3124
3125                 cancel_lru_locks osc
3126                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3127         done
3128 }
3129 run_test 39g "write, chmod, stat ==============================="
3130
3131 # bug 11063
3132 test_39h() {
3133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3134         touch $DIR1/$tfile
3135         sleep 1
3136
3137         local d1=`date`
3138         echo hello >> $DIR1/$tfile
3139         local mtime1=`stat -c %Y $DIR1/$tfile`
3140
3141         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3142         local d2=`date`
3143         if [ "$d1" != "$d2" ]; then
3144                 echo "write and touch not within one second"
3145         else
3146                 for (( i=0; i < 2; i++ )) ; do
3147                         local mtime2=`stat -c %Y $DIR1/$tfile`
3148                         [ "$mtime2" = $TEST_39_MTIME ] || \
3149                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3150
3151                         cancel_lru_locks osc
3152                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3153                 done
3154         fi
3155 }
3156 run_test 39h "write, utime within one second, stat ============="
3157
3158 test_39i() {
3159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3160         touch $DIR1/$tfile
3161         sleep 1
3162
3163         echo hello >> $DIR1/$tfile
3164         local mtime1=`stat -c %Y $DIR1/$tfile`
3165
3166         mv $DIR1/$tfile $DIR1/$tfile-1
3167
3168         for (( i=0; i < 2; i++ )) ; do
3169                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3170
3171                 [ "$mtime1" = "$mtime2" ] || \
3172                         error "lost mtime: $mtime2, should be $mtime1"
3173
3174                 cancel_lru_locks osc
3175                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3176         done
3177 }
3178 run_test 39i "write, rename, stat =============================="
3179
3180 test_39j() {
3181         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3182         start_full_debug_logging
3183         touch $DIR1/$tfile
3184         sleep 1
3185
3186         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3187         lctl set_param fail_loc=0x80000412
3188         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3189                 error "multiop failed"
3190         local multipid=$!
3191         local mtime1=`stat -c %Y $DIR1/$tfile`
3192
3193         mv $DIR1/$tfile $DIR1/$tfile-1
3194
3195         kill -USR1 $multipid
3196         wait $multipid || error "multiop close failed"
3197
3198         for (( i=0; i < 2; i++ )) ; do
3199                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3200                 [ "$mtime1" = "$mtime2" ] ||
3201                         error "mtime is lost on close: $mtime2, " \
3202                               "should be $mtime1"
3203
3204                 cancel_lru_locks osc
3205                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3206         done
3207         lctl set_param fail_loc=0
3208         stop_full_debug_logging
3209 }
3210 run_test 39j "write, rename, close, stat ======================="
3211
3212 test_39k() {
3213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3214         touch $DIR1/$tfile
3215         sleep 1
3216
3217         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3218         local multipid=$!
3219         local mtime1=`stat -c %Y $DIR1/$tfile`
3220
3221         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3222
3223         kill -USR1 $multipid
3224         wait $multipid || error "multiop close failed"
3225
3226         for (( i=0; i < 2; i++ )) ; do
3227                 local mtime2=`stat -c %Y $DIR1/$tfile`
3228
3229                 [ "$mtime2" = $TEST_39_MTIME ] || \
3230                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3231
3232                 cancel_lru_locks osc
3233                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3234         done
3235 }
3236 run_test 39k "write, utime, close, stat ========================"
3237
3238 # this should be set to future
3239 TEST_39_ATIME=`date -d "1 year" +%s`
3240
3241 test_39l() {
3242         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3243         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3244         local atime_diff=$(do_facet $SINGLEMDS \
3245                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3246         rm -rf $DIR/$tdir
3247         mkdir -p $DIR/$tdir
3248
3249         # test setting directory atime to future
3250         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3251         local atime=$(stat -c %X $DIR/$tdir)
3252         [ "$atime" = $TEST_39_ATIME ] || \
3253                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3254
3255         # test setting directory atime from future to now
3256         local d1=$(date +%s)
3257         ls $DIR/$tdir
3258         local d2=$(date +%s)
3259
3260         cancel_lru_locks mdc
3261         atime=$(stat -c %X $DIR/$tdir)
3262         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3263                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3264
3265         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3266         sleep 3
3267
3268         # test setting directory atime when now > dir atime + atime_diff
3269         d1=$(date +%s)
3270         ls $DIR/$tdir
3271         d2=$(date +%s)
3272         cancel_lru_locks mdc
3273         atime=$(stat -c %X $DIR/$tdir)
3274         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3275                 error "atime is not updated  : $atime, should be $d2"
3276
3277         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3278         sleep 3
3279
3280         # test not setting directory atime when now < dir atime + atime_diff
3281         ls $DIR/$tdir
3282         cancel_lru_locks mdc
3283         atime=$(stat -c %X $DIR/$tdir)
3284         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3285                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3286
3287         do_facet $SINGLEMDS \
3288                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3289 }
3290 run_test 39l "directory atime update ==========================="
3291
3292 test_39m() {
3293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3294         touch $DIR1/$tfile
3295         sleep 2
3296         local far_past_mtime=$(date -d "May 29 1953" +%s)
3297         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3298
3299         touch -m -d @$far_past_mtime $DIR1/$tfile
3300         touch -a -d @$far_past_atime $DIR1/$tfile
3301
3302         for (( i=0; i < 2; i++ )) ; do
3303                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3304                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3305                         error "atime or mtime set incorrectly"
3306
3307                 cancel_lru_locks osc
3308                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3309         done
3310 }
3311 run_test 39m "test atime and mtime before 1970"
3312
3313 test_39n() { # LU-3832
3314         local atime_diff=$(do_facet $SINGLEMDS \
3315                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3316         local atime0
3317         local atime1
3318         local atime2
3319
3320         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3321
3322         rm -rf $DIR/$tfile
3323         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3324         atime0=$(stat -c %X $DIR/$tfile)
3325
3326         sleep 5
3327         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3328         atime1=$(stat -c %X $DIR/$tfile)
3329
3330         sleep 5
3331         cancel_lru_locks mdc
3332         cancel_lru_locks osc
3333         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3334         atime2=$(stat -c %X $DIR/$tfile)
3335
3336         do_facet $SINGLEMDS \
3337                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3338
3339         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3340         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3341 }
3342 run_test 39n "check that O_NOATIME is honored"
3343
3344 test_39o() {
3345         TESTDIR=$DIR/$tdir/$tfile
3346         [ -e $TESTDIR ] && rm -rf $TESTDIR
3347         test_mkdir -p $TESTDIR
3348         cd $TESTDIR
3349         links1=2
3350         ls
3351         mkdir a b
3352         ls
3353         links2=$(stat -c %h .)
3354         [ $(($links1 + 2)) != $links2 ] &&
3355                 error "wrong links count $(($links1 + 2)) != $links2"
3356         rmdir b
3357         links3=$(stat -c %h .)
3358         [ $(($links1 + 1)) != $links3 ] &&
3359                 error "wrong links count $links1 != $links3"
3360         return 0
3361 }
3362 run_test 39o "directory cached attributes updated after create ========"
3363
3364 test_39p() {
3365         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3366         local MDTIDX=1
3367         TESTDIR=$DIR/$tdir/$tfile
3368         [ -e $TESTDIR ] && rm -rf $TESTDIR
3369         mkdir -p $TESTDIR
3370         cd $TESTDIR
3371         links1=2
3372         ls
3373         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3374         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3375         ls
3376         links2=$(stat -c %h .)
3377         [ $(($links1 + 2)) != $links2 ] &&
3378                 error "wrong links count $(($links1 + 2)) != $links2"
3379         rmdir remote_dir2
3380         links3=$(stat -c %h .)
3381         [ $(($links1 + 1)) != $links3 ] &&
3382                 error "wrong links count $links1 != $links3"
3383         return 0
3384 }
3385 run_test 39p "remote directory cached attributes updated after create ========"
3386
3387
3388 test_40() {
3389         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3390         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3391                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3392         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3393                 error "$tfile is not 4096 bytes in size"
3394 }
3395 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3396
3397 test_41() {
3398         # bug 1553
3399         small_write $DIR/f41 18
3400 }
3401 run_test 41 "test small file write + fstat ====================="
3402
3403 count_ost_writes() {
3404         lctl get_param -n osc.*.stats |
3405                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3406                         END { printf("%0.0f", writes) }'
3407 }
3408
3409 # decent default
3410 WRITEBACK_SAVE=500
3411 DIRTY_RATIO_SAVE=40
3412 MAX_DIRTY_RATIO=50
3413 BG_DIRTY_RATIO_SAVE=10
3414 MAX_BG_DIRTY_RATIO=25
3415
3416 start_writeback() {
3417         trap 0
3418         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3419         # dirty_ratio, dirty_background_ratio
3420         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3421                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3422                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3423                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3424         else
3425                 # if file not here, we are a 2.4 kernel
3426                 kill -CONT `pidof kupdated`
3427         fi
3428 }
3429
3430 stop_writeback() {
3431         # setup the trap first, so someone cannot exit the test at the
3432         # exact wrong time and mess up a machine
3433         trap start_writeback EXIT
3434         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3435         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3436                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3437                 sysctl -w vm.dirty_writeback_centisecs=0
3438                 sysctl -w vm.dirty_writeback_centisecs=0
3439                 # save and increase /proc/sys/vm/dirty_ratio
3440                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3441                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3442                 # save and increase /proc/sys/vm/dirty_background_ratio
3443                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3444                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3445         else
3446                 # if file not here, we are a 2.4 kernel
3447                 kill -STOP `pidof kupdated`
3448         fi
3449 }
3450
3451 # ensure that all stripes have some grant before we test client-side cache
3452 setup_test42() {
3453         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3454                 dd if=/dev/zero of=$i bs=4k count=1
3455                 rm $i
3456         done
3457 }
3458
3459 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3460 # file truncation, and file removal.
3461 test_42a() {
3462         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3463         setup_test42
3464         cancel_lru_locks osc
3465         stop_writeback
3466         sync; sleep 1; sync # just to be safe
3467         BEFOREWRITES=`count_ost_writes`
3468         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3469         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3470         AFTERWRITES=`count_ost_writes`
3471         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3472                 error "$BEFOREWRITES < $AFTERWRITES"
3473         start_writeback
3474 }
3475 run_test 42a "ensure that we don't flush on close =============="
3476
3477 test_42b() {
3478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3479         setup_test42
3480         cancel_lru_locks osc
3481         stop_writeback
3482         sync
3483         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3484         BEFOREWRITES=$(count_ost_writes)
3485         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3486         AFTERWRITES=$(count_ost_writes)
3487         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3488                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3489         fi
3490         BEFOREWRITES=$(count_ost_writes)
3491         sync || error "sync: $?"
3492         AFTERWRITES=$(count_ost_writes)
3493         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3494                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3495         fi
3496         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3497         start_writeback
3498         return 0
3499 }
3500 run_test 42b "test destroy of file with cached dirty data ======"
3501
3502 # if these tests just want to test the effect of truncation,
3503 # they have to be very careful.  consider:
3504 # - the first open gets a {0,EOF}PR lock
3505 # - the first write conflicts and gets a {0, count-1}PW
3506 # - the rest of the writes are under {count,EOF}PW
3507 # - the open for truncate tries to match a {0,EOF}PR
3508 #   for the filesize and cancels the PWs.
3509 # any number of fixes (don't get {0,EOF} on open, match
3510 # composite locks, do smarter file size management) fix
3511 # this, but for now we want these tests to verify that
3512 # the cancellation with truncate intent works, so we
3513 # start the file with a full-file pw lock to match against
3514 # until the truncate.
3515 trunc_test() {
3516         test=$1
3517         file=$DIR/$test
3518         offset=$2
3519         cancel_lru_locks osc
3520         stop_writeback
3521         # prime the file with 0,EOF PW to match
3522         touch $file
3523         $TRUNCATE $file 0
3524         sync; sync
3525         # now the real test..
3526         dd if=/dev/zero of=$file bs=1024 count=100
3527         BEFOREWRITES=`count_ost_writes`
3528         $TRUNCATE $file $offset
3529         cancel_lru_locks osc
3530         AFTERWRITES=`count_ost_writes`
3531         start_writeback
3532 }
3533
3534 test_42c() {
3535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3536         trunc_test 42c 1024
3537         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3538             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3539         rm $file
3540 }
3541 run_test 42c "test partial truncate of file with cached dirty data"
3542
3543 test_42d() {
3544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3545         trunc_test 42d 0
3546         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3547             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3548         rm $file
3549 }
3550 run_test 42d "test complete truncate of file with cached dirty data"
3551
3552 test_42e() { # bug22074
3553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3554         local TDIR=$DIR/${tdir}e
3555         local pagesz=$(page_size)
3556         local pages=16 # hardcoded 16 pages, don't change it.
3557         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3558         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3559         local max_dirty_mb
3560         local warmup_files
3561
3562         test_mkdir -p $DIR/${tdir}e
3563         $SETSTRIPE -c 1 $TDIR
3564         createmany -o $TDIR/f $files
3565
3566         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3567
3568         # we assume that with $OSTCOUNT files, at least one of them will
3569         # be allocated on OST0.
3570         warmup_files=$((OSTCOUNT * max_dirty_mb))
3571         createmany -o $TDIR/w $warmup_files
3572
3573         # write a large amount of data into one file and sync, to get good
3574         # avail_grant number from OST.
3575         for ((i=0; i<$warmup_files; i++)); do
3576                 idx=$($GETSTRIPE -i $TDIR/w$i)
3577                 [ $idx -ne 0 ] && continue
3578                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3579                 break
3580         done
3581         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3582         sync
3583         $LCTL get_param $proc_osc0/cur_dirty_bytes
3584         $LCTL get_param $proc_osc0/cur_grant_bytes
3585
3586         # create as much dirty pages as we can while not to trigger the actual
3587         # RPCs directly. but depends on the env, VFS may trigger flush during this
3588         # period, hopefully we are good.
3589         for ((i=0; i<$warmup_files; i++)); do
3590                 idx=$($GETSTRIPE -i $TDIR/w$i)
3591                 [ $idx -ne 0 ] && continue
3592                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3593         done
3594         $LCTL get_param $proc_osc0/cur_dirty_bytes
3595         $LCTL get_param $proc_osc0/cur_grant_bytes
3596
3597         # perform the real test
3598         $LCTL set_param $proc_osc0/rpc_stats 0
3599         for ((;i<$files; i++)); do
3600                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3601                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3602         done
3603         sync
3604         $LCTL get_param $proc_osc0/rpc_stats
3605
3606         local percent=0
3607         local have_ppr=false
3608         $LCTL get_param $proc_osc0/rpc_stats |
3609                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3610                         # skip lines until we are at the RPC histogram data
3611                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3612                         $have_ppr || continue
3613
3614                         # we only want the percent stat for < 16 pages
3615                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3616
3617                         percent=$((percent + WPCT))
3618                         if [[ $percent -gt 15 ]]; then
3619                                 error "less than 16-pages write RPCs" \
3620                                       "$percent% > 15%"
3621                                 break
3622                         fi
3623                 done
3624         rm -rf $TDIR
3625 }
3626 run_test 42e "verify sub-RPC writes are not done synchronously"
3627
3628 test_43() {
3629         test_mkdir -p $DIR/$tdir
3630         cp -p /bin/ls $DIR/$tdir/$tfile
3631         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3632         pid=$!
3633         # give multiop a chance to open
3634         sleep 1
3635
3636         $DIR/$tdir/$tfile && error || true
3637         kill -USR1 $pid
3638 }
3639 run_test 43 "execution of file opened for write should return -ETXTBSY"
3640
3641 test_43a() {
3642         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3643         test_mkdir -p $DIR/$tdir
3644         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3645                         cp -p multiop $DIR/$tdir/multiop
3646         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3647                         return 1
3648         MULTIOP_PID=$!
3649         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3650         kill -USR1 $MULTIOP_PID || return 2
3651         wait $MULTIOP_PID || return 3
3652         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3653 }
3654 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3655
3656 test_43b() {
3657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3658         test_mkdir -p $DIR/$tdir
3659         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3660                         cp -p multiop $DIR/$tdir/multiop
3661         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3662                         return 1
3663         MULTIOP_PID=$!
3664         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3665         kill -USR1 $MULTIOP_PID || return 2
3666         wait $MULTIOP_PID || return 3
3667         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3668 }
3669 run_test 43b "truncate of file being executed should return -ETXTBSY"
3670
3671 test_43c() {
3672         local testdir="$DIR/$tdir"
3673         test_mkdir -p $DIR/$tdir
3674         cp $SHELL $testdir/
3675         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3676                 ( cd $testdir && md5sum -c)
3677 }
3678 run_test 43c "md5sum of copy into lustre========================"
3679
3680 test_44() {
3681         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3682         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3683         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3684 }
3685 run_test 44 "zero length read from a sparse stripe ============="
3686
3687 test_44a() {
3688         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3689                 awk '{ print $2 }')
3690         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3691         [[ $nstripe -gt $OSTCOUNT ]] &&
3692             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3693             return
3694         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3695                 awk '{ print $2 }')
3696         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3697                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3698                         awk '{ print $2 }')
3699         fi
3700
3701         OFFSETS="0 $((stride/2)) $((stride-1))"
3702         for offset in $OFFSETS; do
3703                 for i in $(seq 0 $((nstripe-1))); do
3704                         local GLOBALOFFSETS=""
3705                         # size in Bytes
3706                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3707                         local myfn=$DIR/d44a-$size
3708                         echo "--------writing $myfn at $size"
3709                         ll_sparseness_write $myfn $size ||
3710                                 error "ll_sparseness_write"
3711                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3712                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3713                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3714
3715                         for j in $(seq 0 $((nstripe-1))); do
3716                                 # size in Bytes
3717                                 size=$((((j + $nstripe )*$stride + $offset)))
3718                                 ll_sparseness_write $myfn $size ||
3719                                         error "ll_sparseness_write"
3720                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3721                         done
3722                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3723                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3724                         rm -f $myfn
3725                 done
3726         done
3727 }
3728 run_test 44a "test sparse pwrite ==============================="
3729
3730 dirty_osc_total() {
3731         tot=0
3732         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3733                 tot=$(($tot + $d))
3734         done
3735         echo $tot
3736 }
3737 do_dirty_record() {
3738         before=`dirty_osc_total`
3739         echo executing "\"$*\""
3740         eval $*
3741         after=`dirty_osc_total`
3742         echo before $before, after $after
3743 }
3744 test_45() {
3745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3746         f="$DIR/f45"
3747         # Obtain grants from OST if it supports it
3748         echo blah > ${f}_grant
3749         stop_writeback
3750         sync
3751         do_dirty_record "echo blah > $f"
3752         [[ $before -eq $after ]] && error "write wasn't cached"
3753         do_dirty_record "> $f"
3754         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3755         do_dirty_record "echo blah > $f"
3756         [[ $before -eq $after ]] && error "write wasn't cached"
3757         do_dirty_record "sync"
3758         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3759         do_dirty_record "echo blah > $f"
3760         [[ $before -eq $after ]] && error "write wasn't cached"
3761         do_dirty_record "cancel_lru_locks osc"
3762         [[ $before -gt $after ]] ||
3763                 error "lock cancellation didn't lower dirty count"
3764         start_writeback
3765 }
3766 run_test 45 "osc io page accounting ============================"
3767
3768 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3769 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3770 # objects offset and an assert hit when an rpc was built with 1023's mapped
3771 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3772 test_46() {
3773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3774         f="$DIR/f46"
3775         stop_writeback
3776         sync
3777         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3778         sync
3779         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3780         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3781         sync
3782         start_writeback
3783 }
3784 run_test 46 "dirtying a previously written page ================"
3785
3786 # test_47 is removed "Device nodes check" is moved to test_28
3787
3788 test_48a() { # bug 2399
3789         check_kernel_version 34 || return 0
3790         test_mkdir -p $DIR/$tdir
3791         cd $DIR/$tdir
3792         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3793         test_mkdir $DIR/$tdir || error "recreate directory failed"
3794         touch foo || error "'touch foo' failed after recreating cwd"
3795         test_mkdir $DIR/$tdir/bar ||
3796                      error "'mkdir foo' failed after recreating cwd"
3797         if check_kernel_version 44; then
3798                 touch .foo || error "'touch .foo' failed after recreating cwd"
3799                 test_mkdir $DIR/$tdir/.bar ||
3800                               error "'mkdir .foo' failed after recreating cwd"
3801         fi
3802         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3803         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3804         cd . || error "'cd .' failed after recreating cwd"
3805         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3806         rmdir . && error "'rmdir .' worked after recreating cwd"
3807         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3808         cd .. || error "'cd ..' failed after recreating cwd"
3809 }
3810 run_test 48a "Access renamed working dir (should return errors)="
3811
3812 test_48b() { # bug 2399
3813         check_kernel_version 34 || return 0
3814         rm -rf $DIR/$tdir
3815         test_mkdir -p $DIR/$tdir
3816         cd $DIR/$tdir
3817         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3818         touch foo && error "'touch foo' worked after removing cwd"
3819         test_mkdir $DIR/$tdir/foo &&
3820                      error "'mkdir foo' worked after removing cwd"
3821         if check_kernel_version 44; then
3822                 touch .foo && error "'touch .foo' worked after removing cwd"
3823                 test_mkdir $DIR/$tdir/.foo &&
3824                               error "'mkdir .foo' worked after removing cwd"
3825         fi
3826         ls . > /dev/null && error "'ls .' worked after removing cwd"
3827         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3828         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3829         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3830         rmdir . && error "'rmdir .' worked after removing cwd"
3831         ln -s . foo && error "'ln -s .' worked after removing cwd"
3832         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3833 }
3834 run_test 48b "Access removed working dir (should return errors)="
3835
3836 test_48c() { # bug 2350
3837         check_kernel_version 36 || return 0
3838         #lctl set_param debug=-1
3839         #set -vx
3840         rm -rf $DIR/$tdir
3841         test_mkdir -p $DIR/$tdir/dir
3842         cd $DIR/$tdir/dir
3843         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3844         $TRACE touch foo && error "touch foo worked after removing cwd"
3845         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3846         if check_kernel_version 44; then
3847                 touch .foo && error "touch .foo worked after removing cwd"
3848                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3849         fi
3850         $TRACE ls . && error "'ls .' worked after removing cwd"
3851         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3852         is_patchless || ( $TRACE cd . &&
3853                         error "'cd .' worked after removing cwd" )
3854         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3855         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3856         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3857         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3858 }
3859 run_test 48c "Access removed working subdir (should return errors)"
3860
3861 test_48d() { # bug 2350
3862         check_kernel_version 36 || return 0
3863         #lctl set_param debug=-1
3864         #set -vx
3865         rm -rf $DIR/$tdir
3866         test_mkdir -p $DIR/$tdir/dir
3867         cd $DIR/$tdir/dir
3868         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3869         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3870         $TRACE touch foo && error "'touch foo' worked after removing parent"
3871         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3872         if check_kernel_version 44; then
3873                 touch .foo && error "'touch .foo' worked after removing parent"
3874                 test_mkdir .foo &&
3875                               error "mkdir .foo worked after removing parent"
3876         fi
3877         $TRACE ls . && error "'ls .' worked after removing parent"
3878         $TRACE ls .. && error "'ls ..' worked after removing parent"
3879         is_patchless || ( $TRACE cd . &&
3880                         error "'cd .' worked after recreate parent" )
3881         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3882         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3883         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3884         is_patchless || ( $TRACE cd .. &&
3885                         error "'cd ..' worked after removing parent" || true )
3886 }
3887 run_test 48d "Access removed parent subdir (should return errors)"
3888
3889 test_48e() { # bug 4134
3890         check_kernel_version 41 || return 0
3891         #lctl set_param debug=-1
3892         #set -vx
3893         rm -rf $DIR/$tdir
3894         test_mkdir -p $DIR/$tdir/dir
3895         cd $DIR/$tdir/dir
3896         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3897         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3898         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3899         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3900         # On a buggy kernel addition of "touch foo" after cd .. will
3901         # produce kernel oops in lookup_hash_it
3902         touch ../foo && error "'cd ..' worked after recreate parent"
3903         cd $DIR
3904         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3905 }
3906 run_test 48e "Access to recreated parent subdir (should return errors)"
3907
3908 test_49() { # LU-1030
3909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3910         # get ost1 size - lustre-OST0000
3911         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3912                 awk '{ print $4 }')
3913         # write 800M at maximum
3914         [[ $ost1_size -lt 2 ]] && ost1_size=2
3915         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3916
3917         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3918         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3919         local dd_pid=$!
3920
3921         # change max_pages_per_rpc while writing the file
3922         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3923         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3924         # loop until dd process exits
3925         while ps ax -opid | grep -wq $dd_pid; do
3926                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3927                 sleep $((RANDOM % 5 + 1))
3928         done
3929         # restore original max_pages_per_rpc
3930         $LCTL set_param $osc1_mppc=$orig_mppc
3931         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3932 }
3933 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3934
3935 test_50() {
3936         # bug 1485
3937         test_mkdir $DIR/$tdir
3938         cd $DIR/$tdir
3939         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3940 }
3941 run_test 50 "special situations: /proc symlinks  ==============="
3942
3943 test_51a() {    # was test_51
3944         # bug 1516 - create an empty entry right after ".." then split dir
3945         test_mkdir -c1 $DIR/$tdir
3946         touch $DIR/$tdir/foo
3947         $MCREATE $DIR/$tdir/bar
3948         rm $DIR/$tdir/foo
3949         createmany -m $DIR/$tdir/longfile 201
3950         FNUM=202
3951         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3952                 $MCREATE $DIR/$tdir/longfile$FNUM
3953                 FNUM=$(($FNUM + 1))
3954                 echo -n "+"
3955         done
3956         echo
3957         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3958 }
3959 run_test 51a "special situations: split htree with empty entry =="
3960
3961 export NUMTEST=70000
3962 test_51b() {
3963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3964         local BASE=$DIR/d${base}.${TESTSUITE}
3965
3966         # cleanup the directory
3967         rm -fr $BASE
3968
3969         test_mkdir -p -c1 $BASE
3970
3971         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3972         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3973         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3974                 return
3975
3976         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3977                 echo "reduced count to $NUMTEST due to inodes"
3978
3979         # need to check free space for the directories as well
3980         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3981         numfree=$((blkfree / 4))
3982         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3983                 echo "reduced count to $NUMTEST due to blocks"
3984
3985         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3986                 echo "failed" > $BASE/fnum
3987 }
3988 run_test 51b "exceed 64k subdirectory nlink limit"
3989
3990 test_51ba() { # LU-993
3991         local BASE=$DIR/d${base}.${TESTSUITE}
3992         # unlink all but 100 subdirectories, then check it still works
3993         local LEFT=100
3994         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3995
3996         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3997         local DELETE=$((NUMTEST - LEFT))
3998
3999         # continue on to run this test even if 51b didn't finish,
4000         # just to delete the many subdirectories created.
4001         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4002
4003         # for ldiskfs the nlink count should be 1, but this is OSD specific
4004         # and so this is listed for informational purposes only
4005         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4006         unlinkmany -d $BASE/d $DELETE
4007         RC=$?
4008
4009         if [ $RC -ne 0 ]; then
4010                 if [ "$NUMPREV" == "failed" ]; then
4011                         skip "previous setup failed"
4012                         return 0
4013                 else
4014                         error "unlink of first $DELETE subdirs failed"
4015                         return $RC
4016                 fi
4017         fi
4018
4019         echo "nlink between: $(stat -c %h $BASE)"
4020         # trim the first line of ls output
4021         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4022         [ $FOUND -ne $LEFT ] &&
4023                 error "can't find subdirs: found only $FOUND/$LEFT"
4024
4025         unlinkmany -d $BASE/d $DELETE $LEFT ||
4026                 error "unlink of second $LEFT subdirs failed"
4027         # regardless of whether the backing filesystem tracks nlink accurately
4028         # or not, the nlink count shouldn't be more than "." and ".." here
4029         local AFTER=$(stat -c %h $BASE)
4030         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4031                 echo "nlink after: $AFTER"
4032 }
4033 run_test 51ba "verify nlink for many subdirectory cleanup"
4034
4035 test_51d() {
4036         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4037         [[ $OSTCOUNT -lt 3 ]] &&
4038                 skip_env "skipping test with few OSTs" && return
4039         test_mkdir -p $DIR/$tdir
4040         createmany -o $DIR/$tdir/t- 1000
4041         $GETSTRIPE $DIR/$tdir > $TMP/files
4042         for N in $(seq 0 $((OSTCOUNT - 1))); do
4043                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4044                         END { printf("%0.0f", objs) }' $TMP/files)
4045                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4046                         '($1 == '$N') { objs += 1 } \
4047                         END { printf("%0.0f", objs) }')
4048                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4049         done
4050         unlinkmany $DIR/$tdir/t- 1000
4051
4052         NLAST=0
4053         for N in $(seq 1 $((OSTCOUNT - 1))); do
4054                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4055                         error "OST $N has less objects vs OST $NLAST" \
4056                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4057                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4058                         error "OST $N has less objects vs OST $NLAST" \
4059                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4060
4061                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4062                         error "OST $N has less #0 objects vs OST $NLAST" \
4063                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4064                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4065                         error "OST $N has less #0 objects vs OST $NLAST" \
4066                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4067                 NLAST=$N
4068         done
4069 }
4070 run_test 51d "check object distribution ===================="
4071
4072 test_51e() {
4073         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4074                 skip "Only applicable to ldiskfs-based MDTs"
4075                 return
4076         fi
4077
4078         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4079         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4080
4081         touch $DIR/$tdir/d0/foo
4082         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4083                 error "file exceed 65000 nlink limit!"
4084         unlinkmany $DIR/$tdir/d0/f- 65001
4085         return 0
4086 }
4087 run_test 51e "check file nlink limit"
4088
4089 test_52a() {
4090         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4091         test_mkdir -p $DIR/$tdir
4092         touch $DIR/$tdir/foo
4093         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4094         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4095         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4096         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4097         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4098                                         error "link worked"
4099         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4100         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4101         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4102                                                      error "lsattr"
4103         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4104         cp -r $DIR/$tdir /tmp/
4105         rm -fr $DIR/$tdir || error "cleanup rm failed"
4106 }
4107 run_test 52a "append-only flag test (should return errors) ====="
4108
4109 test_52b() {
4110         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4111         test_mkdir -p $DIR/$tdir
4112         touch $DIR/$tdir/foo
4113         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4114         cat test > $DIR/$tdir/foo && error "cat test worked"
4115         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4116         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4117         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4118                                         error "link worked"
4119         echo foo >> $DIR/$tdir/foo && error "echo worked"
4120         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4121         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4122         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4123         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4124                                                         error "lsattr"
4125         chattr -i $DIR/$tdir/foo || error "chattr failed"
4126
4127         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4128 }
4129 run_test 52b "immutable flag test (should return errors) ======="
4130
4131 test_53() {
4132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4133         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4134         remote_ost_nodsh && skip "remote OST with nodsh" && return
4135
4136         local param
4137         local param_seq
4138         local ostname
4139         local mds_last
4140         local mds_last_seq
4141         local ost_last
4142         local ost_last_seq
4143         local ost_last_id
4144         local ostnum
4145         local node
4146         local found=false
4147         local support_last_seq=true
4148
4149         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4150                 support_last_seq=false
4151
4152         # only test MDT0000
4153         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4154         local value
4155         for value in $(do_facet $SINGLEMDS \
4156                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4157                 param=$(echo ${value[0]} | cut -d "=" -f1)
4158                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4159
4160                 if $support_last_seq; then
4161                         param_seq=$(echo $param |
4162                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4163                         mds_last_seq=$(do_facet $SINGLEMDS \
4164                                        $LCTL get_param -n $param_seq)
4165                 fi
4166                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4167
4168                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4169                 node=$(facet_active_host ost$((ostnum+1)))
4170                 param="obdfilter.$ostname.last_id"
4171                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4172                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4173                         ost_last_id=$ost_last
4174
4175                         if $support_last_seq; then
4176                                 ost_last_id=$(echo $ost_last |
4177                                               awk -F':' '{print $2}' |
4178                                               sed -e "s/^0x//g")
4179                                 ost_last_seq=$(echo $ost_last |
4180                                                awk -F':' '{print $1}')
4181                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4182                         fi
4183
4184                         if [[ $ost_last_id != $mds_last ]]; then
4185                                 error "$ost_last_id != $mds_last"
4186                         else
4187                                 found=true
4188                                 break
4189                         fi
4190                 done
4191         done
4192         $found || error "can not match last_seq/last_id for $mdtosc"
4193         return 0
4194 }
4195 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4196
4197 test_54a() {
4198         $SOCKETSERVER $DIR/socket ||
4199                 error "$SOCKETSERVER $DIR/socket failed: $?"
4200         $SOCKETCLIENT $DIR/socket ||
4201                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4202         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4203 }
4204 run_test 54a "unix domain socket test =========================="
4205
4206 test_54b() {
4207         f="$DIR/f54b"
4208         mknod $f c 1 3
4209         chmod 0666 $f
4210         dd if=/dev/zero of=$f bs=$(page_size) count=1
4211 }
4212 run_test 54b "char device works in lustre ======================"
4213
4214 find_loop_dev() {
4215         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4216         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4217         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4218
4219         for i in $(seq 3 7); do
4220                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4221                 LOOPDEV=$LOOPBASE$i
4222                 LOOPNUM=$i
4223                 break
4224         done
4225 }
4226
4227 cleanup_54c() {
4228         loopdev="$DIR/loop54c"
4229
4230         trap 0
4231         $UMOUNT -d $DIR/$tdir || rc=$?
4232         losetup -d $loopdev || true
4233         losetup -d $LOOPDEV || true
4234         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4235         return $rc
4236 }
4237
4238 test_54c() {
4239         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4240         loopdev="$DIR/loop54c"
4241
4242         find_loop_dev
4243         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4244         trap cleanup_54c EXIT
4245         mknod $loopdev b 7 $LOOPNUM
4246         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4247         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4248         losetup $loopdev $DIR/$tfile ||
4249                 error "can't set up $loopdev for $DIR/$tfile"
4250         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4251         test_mkdir -p $DIR/$tdir
4252         mount -t ext2 $loopdev $DIR/$tdir ||
4253                 error "error mounting $loopdev on $DIR/$tdir"
4254         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4255                 error "dd write"
4256         df $DIR/$tdir
4257         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4258                 error "dd read"
4259         cleanup_54c
4260 }
4261 run_test 54c "block device works in lustre ====================="
4262
4263 test_54d() {
4264         f="$DIR/f54d"
4265         string="aaaaaa"
4266         mknod $f p
4267         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4268 }
4269 run_test 54d "fifo device works in lustre ======================"
4270
4271 test_54e() {
4272         check_kernel_version 46 || return 0
4273         f="$DIR/f54e"
4274         string="aaaaaa"
4275         cp -aL /dev/console $f
4276         echo $string > $f || error "echo $string to $f failed"
4277 }
4278 run_test 54e "console/tty device works in lustre ======================"
4279
4280 #The test_55 used to be iopen test and it was removed by bz#24037.
4281 #run_test 55 "check iopen_connect_dentry() ======================"
4282
4283 test_56a() {    # was test_56
4284         rm -rf $DIR/$tdir
4285         $SETSTRIPE -d $DIR
4286         test_mkdir -p $DIR/$tdir/dir
4287         NUMFILES=3
4288         NUMFILESx2=$(($NUMFILES * 2))
4289         for i in $(seq 1 $NUMFILES); do
4290                 touch $DIR/$tdir/file$i
4291                 touch $DIR/$tdir/dir/file$i
4292         done
4293
4294         # test lfs getstripe with --recursive
4295         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4296         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4297                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4298         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4299         [[ $FILENUM -eq $NUMFILES ]] ||
4300                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4301         echo "$GETSTRIPE --recursive passed."
4302
4303         # test lfs getstripe with file instead of dir
4304         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4305         [[ $FILENUM -eq 1 ]] ||
4306                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4307         echo "$GETSTRIPE file1 passed."
4308
4309         #test lfs getstripe with --verbose
4310         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4311                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4312                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4313         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4314                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4315         echo "$GETSTRIPE --verbose passed."
4316
4317         #test lfs getstripe with --obd
4318         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4319                 grep -q "unknown obduuid" ||
4320                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4321
4322         [[ $OSTCOUNT -lt 2 ]] &&
4323                 skip_env "skipping other $GETSTRIPE --obd test" && return
4324
4325         OSTIDX=1
4326         OBDUUID=$(ostuuid_from_index $OSTIDX)
4327         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4328         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4329         [[ $FOUND -eq $FILENUM ]] ||
4330                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4331         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4332                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4333                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4334                 error "$GETSTRIPE --obd: should not show file on other obd"
4335         echo "$GETSTRIPE --obd passed"
4336 }
4337 run_test 56a "check $GETSTRIPE"
4338
4339 NUMFILES=3
4340 NUMDIRS=3
4341 setup_56() {
4342         local LOCAL_NUMFILES="$1"
4343         local LOCAL_NUMDIRS="$2"
4344         local MKDIR_PARAMS="$3"
4345         local DIR_STRIPE_PARAMS="$4"
4346
4347         if [ ! -d "$TDIR" ] ; then
4348                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4349                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4350                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4351                         touch $TDIR/file$i
4352                 done
4353                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4354                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4355                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4356                                 touch $TDIR/dir$i/file$j
4357                         done
4358                 done
4359         fi
4360 }
4361
4362 setup_56_special() {
4363         LOCAL_NUMFILES=$1
4364         LOCAL_NUMDIRS=$2
4365         setup_56 $1 $2
4366         if [ ! -e "$TDIR/loop1b" ] ; then
4367                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4368                         mknod $TDIR/loop${i}b b 7 $i
4369                         mknod $TDIR/null${i}c c 1 3
4370                         ln -s $TDIR/file1 $TDIR/link${i}l
4371                 done
4372                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4373                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4374                         mknod $TDIR/dir$i/null${i}c c 1 3
4375                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4376                 done
4377         fi
4378 }
4379
4380 test_56g() {
4381         $SETSTRIPE -d $DIR
4382
4383         TDIR=$DIR/${tdir}g
4384         setup_56 $NUMFILES $NUMDIRS
4385
4386         EXPECTED=$(($NUMDIRS + 2))
4387         # test lfs find with -name
4388         for i in $(seq 1 $NUMFILES) ; do
4389                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4390                 [ $NUMS -eq $EXPECTED ] ||
4391                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4392                               "found $NUMS, expected $EXPECTED"
4393         done
4394 }
4395 run_test 56g "check lfs find -name ============================="
4396
4397 test_56h() {
4398         $SETSTRIPE -d $DIR
4399
4400         TDIR=$DIR/${tdir}g
4401         setup_56 $NUMFILES $NUMDIRS
4402
4403         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4404         # test lfs find with ! -name
4405         for i in $(seq 1 $NUMFILES) ; do
4406                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4407                 [ $NUMS -eq $EXPECTED ] ||
4408                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4409                               "found $NUMS, expected $EXPECTED"
4410         done
4411 }
4412 run_test 56h "check lfs find ! -name ============================="
4413
4414 test_56i() {
4415        tdir=${tdir}i
4416        test_mkdir -p $DIR/$tdir
4417        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4418        CMD="$LFIND -ost $UUID $DIR/$tdir"
4419        OUT=$($CMD)
4420        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4421 }
4422 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4423
4424 test_56j() {
4425         TDIR=$DIR/${tdir}g
4426         setup_56_special $NUMFILES $NUMDIRS
4427
4428         EXPECTED=$((NUMDIRS + 1))
4429         CMD="$LFIND -type d $TDIR"
4430         NUMS=$($CMD | wc -l)
4431         [ $NUMS -eq $EXPECTED ] ||
4432                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4433 }
4434 run_test 56j "check lfs find -type d ============================="
4435
4436 test_56k() {
4437         TDIR=$DIR/${tdir}g
4438         setup_56_special $NUMFILES $NUMDIRS
4439
4440         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4441         CMD="$LFIND -type f $TDIR"
4442         NUMS=$($CMD | wc -l)
4443         [ $NUMS -eq $EXPECTED ] ||
4444                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4445 }
4446 run_test 56k "check lfs find -type f ============================="
4447
4448 test_56l() {
4449         TDIR=$DIR/${tdir}g
4450         setup_56_special $NUMFILES $NUMDIRS
4451
4452         EXPECTED=$((NUMDIRS + NUMFILES))
4453         CMD="$LFIND -type b $TDIR"
4454         NUMS=$($CMD | wc -l)
4455         [ $NUMS -eq $EXPECTED ] ||
4456                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4457 }
4458 run_test 56l "check lfs find -type b ============================="
4459
4460 test_56m() {
4461         TDIR=$DIR/${tdir}g
4462         setup_56_special $NUMFILES $NUMDIRS
4463
4464         EXPECTED=$((NUMDIRS + NUMFILES))
4465         CMD="$LFIND -type c $TDIR"
4466         NUMS=$($CMD | wc -l)
4467         [ $NUMS -eq $EXPECTED ] ||
4468                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4469 }
4470 run_test 56m "check lfs find -type c ============================="
4471
4472 test_56n() {
4473         TDIR=$DIR/${tdir}g
4474         setup_56_special $NUMFILES $NUMDIRS
4475
4476         EXPECTED=$((NUMDIRS + NUMFILES))
4477         CMD="$LFIND -type l $TDIR"
4478         NUMS=$($CMD | wc -l)
4479         [ $NUMS -eq $EXPECTED ] ||
4480                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4481 }
4482 run_test 56n "check lfs find -type l ============================="
4483
4484 test_56o() {
4485         TDIR=$DIR/${tdir}o
4486         setup_56 $NUMFILES $NUMDIRS
4487         utime $TDIR/file1 > /dev/null || error "utime (1)"
4488         utime $TDIR/file2 > /dev/null || error "utime (2)"
4489         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4490         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4491         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4492         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4493
4494         EXPECTED=4
4495         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4496         [ $NUMS -eq $EXPECTED ] || \
4497                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4498
4499         EXPECTED=12
4500         CMD="$LFIND -mtime 0 $TDIR"
4501         NUMS=$($CMD | wc -l)
4502         [ $NUMS -eq $EXPECTED ] ||
4503                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4504 }
4505 run_test 56o "check lfs find -mtime for old files =========================="
4506
4507 test_56p() {
4508         [ $RUNAS_ID -eq $UID ] &&
4509                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4510
4511         TDIR=$DIR/${tdir}p
4512         setup_56 $NUMFILES $NUMDIRS
4513
4514         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4515         EXPECTED=$NUMFILES
4516         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4517         NUMS=$($CMD | wc -l)
4518         [ $NUMS -eq $EXPECTED ] || \
4519                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4520
4521         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4522         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4523         NUMS=$($CMD | wc -l)
4524         [ $NUMS -eq $EXPECTED ] || \
4525                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4526 }
4527 run_test 56p "check lfs find -uid and ! -uid ==============================="
4528
4529 test_56q() {
4530         [ $RUNAS_ID -eq $UID ] &&
4531                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4532
4533         TDIR=$DIR/${tdir}q
4534         setup_56 $NUMFILES $NUMDIRS
4535
4536         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4537
4538         EXPECTED=$NUMFILES
4539         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4540         NUMS=$($CMD | wc -l)
4541         [ $NUMS -eq $EXPECTED ] ||
4542                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4543
4544         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4545         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4546         NUMS=$($CMD | wc -l)
4547         [ $NUMS -eq $EXPECTED ] ||
4548                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4549 }
4550 run_test 56q "check lfs find -gid and ! -gid ==============================="
4551
4552 test_56r() {
4553         TDIR=$DIR/${tdir}r
4554         setup_56 $NUMFILES $NUMDIRS
4555
4556         EXPECTED=12
4557         CMD="$LFIND -size 0 -type f $TDIR"
4558         NUMS=$($CMD | wc -l)
4559         [ $NUMS -eq $EXPECTED ] ||
4560                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4561         EXPECTED=0
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         echo "test" > $TDIR/$tfile
4567         echo "test2" > $TDIR/$tfile.2 && sync
4568         EXPECTED=1
4569         CMD="$LFIND -size 5 -type f $TDIR"
4570         NUMS=$($CMD | wc -l)
4571         [ $NUMS -eq $EXPECTED ] ||
4572                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
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=2
4579         CMD="$LFIND -size +0 -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 -5 -type f $TDIR"
4585         NUMS=$($CMD | wc -l)
4586         [ $NUMS -eq $EXPECTED ] ||
4587                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4588         EXPECTED=12
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 }
4594 run_test 56r "check lfs find -size works =========================="
4595
4596 test_56s() { # LU-611
4597         TDIR=$DIR/${tdir}s
4598         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4599
4600         if [[ $OSTCOUNT -gt 1 ]]; then
4601                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4602                 ONESTRIPE=4
4603                 EXTRA=4
4604         else
4605                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4606                 EXTRA=0
4607         fi
4608
4609         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4610         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4611         NUMS=$($CMD | wc -l)
4612         [ $NUMS -eq $EXPECTED ] || {
4613                 $GETSTRIPE -R $TDIR
4614                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4615         }
4616
4617         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4618         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4619         NUMS=$($CMD | wc -l)
4620         [ $NUMS -eq $EXPECTED ] || {
4621                 $GETSTRIPE -R $TDIR
4622                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4623         }
4624
4625         EXPECTED=$ONESTRIPE
4626         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4627         NUMS=$($CMD | wc -l)
4628         [ $NUMS -eq $EXPECTED ] || {
4629                 $GETSTRIPE -R $TDIR
4630                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4631         }
4632
4633         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4634         NUMS=$($CMD | wc -l)
4635         [ $NUMS -eq $EXPECTED ] || {
4636                 $GETSTRIPE -R $TDIR
4637                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4638         }
4639
4640         EXPECTED=0
4641         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4642         NUMS=$($CMD | wc -l)
4643         [ $NUMS -eq $EXPECTED ] || {
4644                 $GETSTRIPE -R $TDIR
4645                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4646         }
4647 }
4648 run_test 56s "check lfs find -stripe-count works"
4649
4650 test_56t() { # LU-611
4651         TDIR=$DIR/${tdir}t
4652         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4653
4654         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4655
4656         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4657         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4658         NUMS=$($CMD | wc -l)
4659         [ $NUMS -eq $EXPECTED ] ||
4660                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4661
4662         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4663         NUMS=$($CMD | wc -l)
4664         [ $NUMS -eq $EXPECTED ] ||
4665                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4666
4667         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4668         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4669         NUMS=$($CMD | wc -l)
4670         [ $NUMS -eq $EXPECTED ] ||
4671                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4672
4673         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4674         NUMS=$($CMD | wc -l)
4675         [ $NUMS -eq $EXPECTED ] ||
4676                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4677
4678         EXPECTED=4
4679         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4680         NUMS=$($CMD | wc -l)
4681         [ $NUMS -eq $EXPECTED ] ||
4682                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4683
4684         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4685         NUMS=$($CMD | wc -l)
4686         [ $NUMS -eq $EXPECTED ] ||
4687                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4688
4689         EXPECTED=0
4690         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4691         NUMS=$($CMD | wc -l)
4692         [ $NUMS -eq $EXPECTED ] ||
4693                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4694 }
4695 run_test 56t "check lfs find -stripe-size works"
4696
4697 test_56u() { # LU-611
4698         TDIR=$DIR/${tdir}u
4699         setup_56 $NUMFILES $NUMDIRS "-i 0"
4700
4701         if [[ $OSTCOUNT -gt 1 ]]; then
4702                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4703                 ONESTRIPE=4
4704         else
4705                 ONESTRIPE=0
4706         fi
4707
4708         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4709         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4710         NUMS=$($CMD | wc -l)
4711         [ $NUMS -eq $EXPECTED ] ||
4712                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4713
4714         EXPECTED=$ONESTRIPE
4715         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4716         NUMS=$($CMD | wc -l)
4717         [ $NUMS -eq $EXPECTED ] ||
4718                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4719
4720         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4721         NUMS=$($CMD | wc -l)
4722         [ $NUMS -eq $EXPECTED ] ||
4723                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4724
4725         EXPECTED=0
4726         # This should produce an error and not return any files
4727         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4728         NUMS=$($CMD 2>/dev/null | wc -l)
4729         [ $NUMS -eq $EXPECTED ] ||
4730                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4731
4732         if [[ $OSTCOUNT -gt 1 ]]; then
4733                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4734                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4735                 NUMS=$($CMD | wc -l)
4736                 [ $NUMS -eq $EXPECTED ] ||
4737                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4738         fi
4739 }
4740 run_test 56u "check lfs find -stripe-index works"
4741
4742 test_56v() {
4743     local MDT_IDX=0
4744
4745     TDIR=$DIR/${tdir}v
4746     rm -rf $TDIR
4747     setup_56 $NUMFILES $NUMDIRS
4748
4749     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4750     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4751
4752     for file in $($LFIND -mdt $UUID $TDIR); do
4753         file_mdt_idx=$($GETSTRIPE -M $file)
4754         [ $file_mdt_idx -eq $MDT_IDX ] ||
4755             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4756     done
4757 }
4758 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4759
4760 # Get and check the actual stripe count of one file.
4761 # Usage: check_stripe_count <file> <expected_stripe_count>
4762 check_stripe_count() {
4763     local file=$1
4764     local expected=$2
4765     local actual
4766
4767     [[ -z "$file" || -z "$expected" ]] &&
4768         error "check_stripe_count: invalid argument!"
4769
4770     local cmd="$GETSTRIPE -c $file"
4771     actual=$($cmd) || error "$cmd failed"
4772     actual=${actual%% *}
4773
4774     if [[ $actual -ne $expected ]]; then
4775         [[ $expected -eq -1 ]] ||
4776             error "$cmd wrong: found $actual, expected $expected"
4777         [[ $actual -eq $OSTCOUNT ]] ||
4778             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4779     fi
4780 }
4781
4782 test_56w() {
4783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4784         TDIR=$DIR/${tdir}w
4785
4786     rm -rf $TDIR || error "remove $TDIR failed"
4787     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4788
4789     local stripe_size
4790     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4791         error "$GETSTRIPE -S -d $TDIR failed"
4792     stripe_size=${stripe_size%% *}
4793
4794     local file_size=$((stripe_size * OSTCOUNT))
4795     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4796     local required_space=$((file_num * file_size))
4797     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4798     [[ $free_space -le $((required_space / 1024)) ]] &&
4799         skip_env "need at least $required_space bytes free space," \
4800                  "have $free_space kbytes" && return
4801
4802     local dd_bs=65536
4803     local dd_count=$((file_size / dd_bs))
4804
4805     # write data into the files
4806     local i
4807     local j
4808     local file
4809     for i in $(seq 1 $NUMFILES); do
4810         file=$TDIR/file$i
4811         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4812             error "write data into $file failed"
4813     done
4814     for i in $(seq 1 $NUMDIRS); do
4815         for j in $(seq 1 $NUMFILES); do
4816             file=$TDIR/dir$i/file$j
4817             yes | dd bs=$dd_bs count=$dd_count of=$file \
4818                 >/dev/null 2>&1 ||
4819                 error "write data into $file failed"
4820         done
4821     done
4822
4823     local expected=-1
4824     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4825
4826     # lfs_migrate file
4827     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4828     echo "$cmd"
4829     eval $cmd || error "$cmd failed"
4830
4831     check_stripe_count $TDIR/file1 $expected
4832
4833     # lfs_migrate dir
4834     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4835     echo "$cmd"
4836     eval $cmd || error "$cmd failed"
4837
4838     for j in $(seq 1 $NUMFILES); do
4839         check_stripe_count $TDIR/dir1/file$j $expected
4840     done
4841
4842     # lfs_migrate works with lfs find
4843     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4844          $LFS_MIGRATE -y -c $expected"
4845     echo "$cmd"
4846     eval $cmd || error "$cmd failed"
4847
4848     for i in $(seq 2 $NUMFILES); do
4849         check_stripe_count $TDIR/file$i $expected
4850     done
4851     for i in $(seq 2 $NUMDIRS); do
4852         for j in $(seq 1 $NUMFILES); do
4853             check_stripe_count $TDIR/dir$i/file$j $expected
4854         done
4855     done
4856 }
4857 run_test 56w "check lfs_migrate -c stripe_count works"
4858
4859 test_56x() {
4860         check_swap_layouts_support && return 0
4861         [[ $OSTCOUNT -lt 2 ]] &&
4862                 skip_env "need 2 OST, skipping test" && return
4863
4864         local dir0=$DIR/$tdir/$testnum
4865         mkdir -p $dir0 || error "creating dir $dir0"
4866
4867         local ref1=/etc/passwd
4868         local file1=$dir0/file1
4869
4870         $SETSTRIPE -c 2 $file1
4871         cp $ref1 $file1
4872         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4873         stripe=$($GETSTRIPE -c $file1)
4874         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4875         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4876
4877         # clean up
4878         rm -f $file1
4879 }
4880 run_test 56x "lfs migration support"
4881
4882 test_56y() {
4883         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4884                 skip "No HSM support on MDS of $(get_lustre_version)," \
4885                          "need 2.4.53 at least" && return
4886         local res=""
4887
4888         local dir0=$DIR/$tdir/$testnum
4889         mkdir -p $dir0 || error "creating dir $dir0"
4890         local f1=$dir0/file1
4891         local f2=$dir0/file2
4892
4893         touch $f1 || error "creating std file $f1"
4894         $MULTIOP $f2 H2c || error "creating released file $f2"
4895
4896         # a directory can be raid0, so ask only for files
4897         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4898         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4899
4900         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4901         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4902
4903         # only files can be released, so no need to force file search
4904         res=$($LFIND $dir0 -L released)
4905         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4906
4907         res=$($LFIND $dir0 \! -L released)
4908         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4909
4910 }
4911 run_test 56y "lfs find -L raid0|released"
4912
4913 test_56z() { # LU-4824
4914         # This checks to make sure 'lfs find' continues after errors
4915         # There are two classes of errors that should be caught:
4916         # - If multiple paths are provided, all should be searched even if one
4917         #   errors out
4918         # - If errors are encountered during the search, it should not terminate
4919         #   early
4920         local i
4921         test_mkdir $DIR/$tdir
4922         for i in d{0..9}; do
4923                 test_mkdir $DIR/$tdir/$i
4924         done
4925         touch $DIR/$tdir/d{0..9}/$tfile
4926         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4927                 error "$LFS find did not return an error"
4928         # Make a directory unsearchable. This should NOT be the last entry in
4929         # directory order.  Arbitrarily pick the 6th entry
4930         chmod 700 $(lfs find $DIR/$tdir -type d | sed '6!d')
4931         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4932         # The user should be able to see 10 directories and 9 files
4933         [ $count == 19 ] || error "$LFS find did not continue after error"
4934 }
4935 run_test 56z "lfs find should continue after an error"
4936
4937 test_57a() {
4938         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4939         # note test will not do anything if MDS is not local
4940         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4941                 skip "Only applicable to ldiskfs-based MDTs"
4942                 return
4943         fi
4944
4945         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4946         local MNTDEV="osd*.*MDT*.mntdev"
4947         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4948         [ -z "$DEV" ] && error "can't access $MNTDEV"
4949         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4950                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4951                         error "can't access $DEV"
4952                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4953                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4954                 rm $TMP/t57a.dump
4955         done
4956 }
4957 run_test 57a "verify MDS filesystem created with large inodes =="
4958
4959 test_57b() {
4960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4961         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4962                 skip "Only applicable to ldiskfs-based MDTs"
4963                 return
4964         fi
4965
4966         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4967         local dir=$DIR/d57b
4968
4969         local FILECOUNT=100
4970         local FILE1=$dir/f1
4971         local FILEN=$dir/f$FILECOUNT
4972
4973         rm -rf $dir || error "removing $dir"
4974         test_mkdir -p $dir || error "creating $dir"
4975         local num=$(get_mds_dir $dir)
4976         local mymds=mds$num
4977
4978         echo "mcreating $FILECOUNT files"
4979         createmany -m $dir/f 1 $FILECOUNT || \
4980                 error "creating files in $dir"
4981
4982         # verify that files do not have EAs yet
4983         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4984         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4985
4986         sync
4987         sleep 1
4988         df $dir  #make sure we get new statfs data
4989         local MDSFREE=$(do_facet $mymds \
4990                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4991         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4992         echo "opening files to create objects/EAs"
4993         local FILE
4994         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4995                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4996         done
4997
4998         # verify that files have EAs now
4999         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5000         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5001
5002         sleep 1  #make sure we get new statfs data
5003         df $dir
5004         local MDSFREE2=$(do_facet $mymds \
5005                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
5006         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5007         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5008                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5009                         error "MDC before $MDCFREE != after $MDCFREE2"
5010                 else
5011                         echo "MDC before $MDCFREE != after $MDCFREE2"
5012                         echo "unable to confirm if MDS has large inodes"
5013                 fi
5014         fi
5015         rm -rf $dir
5016 }
5017 run_test 57b "default LOV EAs are stored inside large inodes ==="
5018
5019 test_58() {
5020         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5021         [ -z "$(which wiretest 2>/dev/null)" ] &&
5022                         skip_env "could not find wiretest" && return
5023         wiretest
5024 }
5025 run_test 58 "verify cross-platform wire constants =============="
5026
5027 test_59() {
5028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5029         echo "touch 130 files"
5030         createmany -o $DIR/f59- 130
5031         echo "rm 130 files"
5032         unlinkmany $DIR/f59- 130
5033         sync
5034         # wait for commitment of removal
5035         wait_delete_completed
5036 }
5037 run_test 59 "verify cancellation of llog records async ========="
5038
5039 TEST60_HEAD="test_60 run $RANDOM"
5040 test_60a() {
5041         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5042         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5043         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5044                 skip_env "missing subtest run-llog.sh" && return
5045         log "$TEST60_HEAD - from kernel mode"
5046         do_facet mgs sh run-llog.sh
5047 }
5048 run_test 60a "llog sanity tests run from kernel module =========="
5049
5050 test_60b() { # bug 6411
5051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5052         dmesg > $DIR/$tfile
5053         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5054                                  /llog.test/ {
5055                                          if (marker)
5056                                                  from_marker++
5057                                          from_begin++
5058                                  }
5059                                  END {
5060                                          if (marker)
5061                                                  print from_marker
5062                                          else
5063                                                  print from_begin
5064                                  }"`
5065         [[ $LLOG_COUNT -gt 50 ]] &&
5066                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5067 }
5068 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5069
5070 test_60c() {
5071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5072         echo "create 5000 files"
5073         createmany -o $DIR/f60c- 5000
5074 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5075         lctl set_param fail_loc=0x80000137
5076         unlinkmany $DIR/f60c- 5000
5077         lctl set_param fail_loc=0
5078 }
5079 run_test 60c "unlink file when mds full"
5080
5081 test_60d() {
5082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5083         SAVEPRINTK=$(lctl get_param -n printk)
5084
5085         # verify "lctl mark" is even working"
5086         MESSAGE="test message ID $RANDOM $$"
5087         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5088         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5089
5090         lctl set_param printk=0 || error "set lnet.printk failed"
5091         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5092         MESSAGE="new test message ID $RANDOM $$"
5093         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5094         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5095         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5096
5097         lctl set_param -n printk="$SAVEPRINTK"
5098 }
5099 run_test 60d "test printk console message masking"
5100
5101 test_61() {
5102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5103         f="$DIR/f61"
5104         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5105         cancel_lru_locks osc
5106         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5107         sync
5108 }
5109 run_test 61 "mmap() writes don't make sync hang ================"
5110
5111 # bug 2330 - insufficient obd_match error checking causes LBUG
5112 test_62() {
5113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5114         f="$DIR/f62"
5115         echo foo > $f
5116         cancel_lru_locks osc
5117         lctl set_param fail_loc=0x405
5118         cat $f && error "cat succeeded, expect -EIO"
5119         lctl set_param fail_loc=0
5120 }
5121 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5122 # match every page all of the time.
5123 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5124
5125 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5126 # Though this test is irrelevant anymore, it helped to reveal some
5127 # other grant bugs (LU-4482), let's keep it.
5128 test_63a() {   # was test_63
5129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5130         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5131         for i in `seq 10` ; do
5132                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5133                 sleep 5
5134                 kill $!
5135                 sleep 1
5136         done
5137
5138         rm -f $DIR/f63 || true
5139 }
5140 run_test 63a "Verify oig_wait interruption does not crash ======="
5141
5142 # bug 2248 - async write errors didn't return to application on sync
5143 # bug 3677 - async write errors left page locked
5144 test_63b() {
5145         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5146         debugsave
5147         lctl set_param debug=-1
5148
5149         # ensure we have a grant to do async writes
5150         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5151         rm $DIR/$tfile
5152
5153         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5154         lctl set_param fail_loc=0x80000406
5155         $MULTIOP $DIR/$tfile Owy && \
5156                 error "sync didn't return ENOMEM"
5157         sync; sleep 2; sync     # do a real sync this time to flush page
5158         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5159                 error "locked page left in cache after async error" || true
5160         debugrestore
5161 }
5162 run_test 63b "async write errors should be returned to fsync ==="
5163
5164 test_64a () {
5165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5166         df $DIR
5167         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5168 }
5169 run_test 64a "verify filter grant calculations (in kernel) ====="
5170
5171 test_64b () {
5172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5173         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5174 }
5175 run_test 64b "check out-of-space detection on client ==========="
5176
5177 test_64c() {
5178         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5179 }
5180 run_test 64c "verify grant shrink ========================------"
5181
5182 # bug 1414 - set/get directories' stripe info
5183 test_65a() {
5184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5185         test_mkdir -p $DIR/$tdir
5186         touch $DIR/$tdir/f1
5187         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5188 }
5189 run_test 65a "directory with no stripe info ===================="
5190
5191 test_65b() {
5192         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5193         test_mkdir -p $DIR/$tdir
5194         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5195                                                 error "setstripe"
5196         touch $DIR/$tdir/f2
5197         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5198 }
5199 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5200
5201 test_65c() {
5202         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5203         if [[ $OSTCOUNT -gt 1 ]]; then
5204                 test_mkdir -p $DIR/$tdir
5205                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5206                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5207                 touch $DIR/$tdir/f3
5208                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5209         fi
5210 }
5211 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5212
5213 test_65d() {
5214         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5215         test_mkdir -p $DIR/$tdir
5216         if [[ $STRIPECOUNT -le 0 ]]; then
5217                 sc=1
5218         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5219 #LOV_MAX_STRIPE_COUNT is 2000
5220                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5221         else
5222                 sc=$(($STRIPECOUNT - 1))
5223         fi
5224         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5225         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5226         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5227                 error "lverify failed"
5228 }
5229 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5230
5231 test_65e() {
5232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5233         test_mkdir -p $DIR/$tdir
5234
5235         $SETSTRIPE $DIR/$tdir || error "setstripe"
5236         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5237                                         error "no stripe info failed"
5238         touch $DIR/$tdir/f6
5239         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5240 }
5241 run_test 65e "directory setstripe defaults ======================="
5242
5243 test_65f() {
5244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5245         test_mkdir -p $DIR/${tdir}f
5246         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5247 }
5248 run_test 65f "dir setstripe permission (should return error) ==="
5249
5250 test_65g() {
5251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5252         test_mkdir -p $DIR/$tdir
5253         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5254                                                         error "setstripe"
5255         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5256         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5257                 error "delete default stripe failed"
5258 }
5259 run_test 65g "directory setstripe -d ==========================="
5260
5261 test_65h() {
5262         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5263         test_mkdir -p $DIR/$tdir
5264         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5265                                                         error "setstripe"
5266         test_mkdir -p $DIR/$tdir/dd1
5267         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5268                 error "stripe info inherit failed"
5269 }
5270 run_test 65h "directory stripe info inherit ===================="
5271
5272 test_65i() { # bug6367
5273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5274         $SETSTRIPE -S 65536 -c -1 $MOUNT
5275 }
5276 run_test 65i "set non-default striping on root directory (bug 6367)="
5277
5278 test_65ia() { # bug12836
5279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5280         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5281 }
5282 run_test 65ia "getstripe on -1 default directory striping"
5283
5284 test_65ib() { # bug12836
5285         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5286         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5287 }
5288 run_test 65ib "getstripe -v on -1 default directory striping"
5289
5290 test_65ic() { # bug12836
5291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5292         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5293 }
5294 run_test 65ic "new find on -1 default directory striping"
5295
5296 test_65j() { # bug6367
5297         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5298         sync; sleep 1
5299         # if we aren't already remounting for each test, do so for this test
5300         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5301                 cleanup || error "failed to unmount"
5302                 setup
5303         fi
5304         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5305 }
5306 run_test 65j "set default striping on root directory (bug 6367)="
5307
5308 test_65k() { # bug11679
5309         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5310         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5311         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5312
5313     echo "Check OST status: "
5314     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5315               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5316
5317     for OSC in $MDS_OSCS; do
5318         echo $OSC "is activate"
5319         do_facet $SINGLEMDS lctl --device %$OSC activate
5320     done
5321
5322     mkdir -p $DIR/$tdir
5323     for INACTIVE_OSC in $MDS_OSCS; do
5324         echo "Deactivate: " $INACTIVE_OSC
5325         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5326         for STRIPE_OSC in $MDS_OSCS; do
5327             OST=`osc_to_ost $STRIPE_OSC`
5328             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5329                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5330
5331             [ -f $DIR/$tdir/$IDX ] && continue
5332             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5333             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5334             RC=$?
5335             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5336         done
5337         rm -f $DIR/$tdir/*
5338         echo $INACTIVE_OSC "is Activate."
5339         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5340     done
5341 }
5342 run_test 65k "validate manual striping works properly with deactivated OSCs"
5343
5344 test_65l() { # bug 12836
5345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5346         test_mkdir -p $DIR/$tdir/test_dir
5347         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5348         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5349 }
5350 run_test 65l "lfs find on -1 stripe dir ========================"
5351
5352 # bug 2543 - update blocks count on client
5353 test_66() {
5354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5355         COUNT=${COUNT:-8}
5356         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5357         sync; sync_all_data; sync; sync_all_data
5358         cancel_lru_locks osc
5359         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5360         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5361 }
5362 run_test 66 "update inode blocks count on client ==============="
5363
5364 LLOOP=
5365 LLITELOOPLOAD=
5366 cleanup_68() {
5367         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5368         trap 0
5369         if [ ! -z "$LLOOP" ]; then
5370                 if swapon -s | grep -q $LLOOP; then
5371                         swapoff $LLOOP || error "swapoff failed"
5372                 fi
5373
5374                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5375                 rm -f $LLOOP
5376                 unset LLOOP
5377         fi
5378         if [ ! -z "$LLITELOOPLOAD" ]; then
5379                 rmmod llite_lloop
5380                 unset LLITELOOPLOAD
5381         fi
5382         rm -f $DIR/f68*
5383 }
5384
5385 meminfo() {
5386         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5387 }
5388
5389 swap_used() {
5390         swapon -s | awk '($1 == "'$1'") { print $4 }'
5391 }
5392
5393 # test case for lloop driver, basic function
5394 test_68a() {
5395         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5396         [ "$UID" != 0 ] && skip_env "must run as root" && return
5397         llite_lloop_enabled || \
5398                 { skip_env "llite_lloop module disabled" && return; }
5399
5400         trap cleanup_68 EXIT
5401
5402         if ! module_loaded llite_lloop; then
5403                 if load_module llite/llite_lloop; then
5404                         LLITELOOPLOAD=yes
5405                 else
5406                         skip_env "can't find module llite_lloop"
5407                         return
5408                 fi
5409         fi
5410
5411         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5412         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5413         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5414
5415         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5416         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5417
5418         cleanup_68
5419 }
5420 run_test 68a "lloop driver - basic test ========================"
5421
5422 # excercise swapping to lustre by adding a high priority swapfile entry
5423 # and then consuming memory until it is used.
5424 test_68b() {  # was test_68
5425         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5426         [ "$UID" != 0 ] && skip_env "must run as root" && return
5427         lctl get_param -n devices | grep -q obdfilter && \
5428                 skip "local OST" && return
5429
5430         grep -q llite_lloop /proc/modules
5431         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5432
5433         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5434                 skip "can't reliably test swap with TCP" && return
5435
5436         MEMTOTAL=`meminfo MemTotal`
5437         NR_BLOCKS=$((MEMTOTAL>>8))
5438         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5439
5440         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5441         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5442         mkswap $DIR/f68b
5443
5444         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5445
5446         trap cleanup_68 EXIT
5447
5448         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5449
5450         echo "before: `swapon -s | grep $LLOOP`"
5451         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5452         echo "after: `swapon -s | grep $LLOOP`"
5453         SWAPUSED=`swap_used $LLOOP`
5454
5455         cleanup_68
5456
5457         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5458 }
5459 run_test 68b "support swapping to Lustre ========================"
5460
5461 # bug5265, obdfilter oa2dentry return -ENOENT
5462 # #define OBD_FAIL_OST_ENOENT 0x217
5463 test_69() {
5464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5465         remote_ost_nodsh && skip "remote OST with nodsh" && return
5466
5467         f="$DIR/$tfile"
5468         $SETSTRIPE -c 1 -i 0 $f
5469
5470         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5471
5472         do_facet ost1 lctl set_param fail_loc=0x217
5473         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5474         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5475
5476         do_facet ost1 lctl set_param fail_loc=0
5477         $DIRECTIO write $f 0 2 || error "write error"
5478
5479         cancel_lru_locks osc
5480         $DIRECTIO read $f 0 1 || error "read error"
5481
5482         do_facet ost1 lctl set_param fail_loc=0x217
5483         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5484
5485         do_facet ost1 lctl set_param fail_loc=0
5486         rm -f $f
5487 }
5488 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5489
5490 test_71() {
5491     test_mkdir -p $DIR/$tdir
5492     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5493 }
5494 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5495
5496 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5498         [ "$RUNAS_ID" = "$UID" ] &&
5499                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5500
5501         # Check that testing environment is properly set up. Skip if not
5502         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5503                 skip_env "User $RUNAS_ID does not exist - skipping"
5504                 return 0
5505         }
5506         touch $DIR/$tfile
5507         chmod 777 $DIR/$tfile
5508         chmod ug+s $DIR/$tfile
5509         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5510                 error "$RUNAS dd $DIR/$tfile failed"
5511         # See if we are still setuid/sgid
5512         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5513                 error "S/gid is not dropped on write"
5514         # Now test that MDS is updated too
5515         cancel_lru_locks mdc
5516         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5517                 error "S/gid is not dropped on MDS"
5518         rm -f $DIR/$tfile
5519 }
5520 run_test 72a "Test that remove suid works properly (bug5695) ===="
5521
5522 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5523         local perm
5524
5525         [ "$RUNAS_ID" = "$UID" ] && \
5526                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5527         [ "$RUNAS_ID" -eq 0 ] && \
5528                 skip_env "RUNAS_ID = 0 -- skipping" && return
5529
5530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5531         # Check that testing environment is properly set up. Skip if not
5532         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5533                 skip_env "User $RUNAS_ID does not exist - skipping"
5534                 return 0
5535         }
5536         touch $DIR/${tfile}-f{g,u}
5537         test_mkdir $DIR/${tfile}-dg
5538         test_mkdir $DIR/${tfile}-du
5539         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5540         chmod g+s $DIR/${tfile}-{f,d}g
5541         chmod u+s $DIR/${tfile}-{f,d}u
5542         for perm in 777 2777 4777; do
5543                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5544                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5545                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5546                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5547         done
5548         true
5549 }
5550 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5551
5552 # bug 3462 - multiple simultaneous MDC requests
5553 test_73() {
5554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5555         test_mkdir $DIR/d73-1
5556         test_mkdir $DIR/d73-2
5557         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5558         pid1=$!
5559
5560         lctl set_param fail_loc=0x80000129
5561         $MULTIOP $DIR/d73-1/f73-2 Oc &
5562         sleep 1
5563         lctl set_param fail_loc=0
5564
5565         $MULTIOP $DIR/d73-2/f73-3 Oc &
5566         pid3=$!
5567
5568         kill -USR1 $pid1
5569         wait $pid1 || return 1
5570
5571         sleep 25
5572
5573         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5574         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5575         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5576
5577         rm -rf $DIR/d73-*
5578 }
5579 run_test 73 "multiple MDC requests (should not deadlock)"
5580
5581 test_74a() { # bug 6149, 6184
5582         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5583         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5584         #
5585         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5586         # will spin in a tight reconnection loop
5587         touch $DIR/f74a
5588         $LCTL set_param fail_loc=0x8000030e
5589         # get any lock that won't be difficult - lookup works.
5590         ls $DIR/f74a
5591         $LCTL set_param fail_loc=0
5592         rm -f $DIR/f74a
5593         true
5594 }
5595 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5596
5597 test_74b() { # bug 13310
5598         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5599         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5600         #
5601         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5602         # will spin in a tight reconnection loop
5603         $LCTL set_param fail_loc=0x8000030e
5604         # get a "difficult" lock
5605         touch $DIR/f74b
5606         $LCTL set_param fail_loc=0
5607         rm -f $DIR/f74b
5608         true
5609 }
5610 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5611
5612 test_74c() {
5613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5614         #define OBD_FAIL_LDLM_NEW_LOCK
5615         $LCTL set_param fail_loc=0x319
5616         touch $DIR/$tfile && error "touch successful"
5617         $LCTL set_param fail_loc=0
5618         true
5619 }
5620 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5621
5622 num_inodes() {
5623         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5624 }
5625
5626 get_inode_slab_tunables() {
5627         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5628 }
5629
5630 set_inode_slab_tunables() {
5631         echo "lustre_inode_cache $1" > /proc/slabinfo
5632 }
5633
5634 test_76() { # Now for bug 20433, added originally in bug 1443
5635         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5636         local SLAB_SETTINGS=`get_inode_slab_tunables`
5637         local CPUS=`getconf _NPROCESSORS_ONLN`
5638         # we cannot set limit below 1 which means 1 inode in each
5639         # per-cpu cache is still allowed
5640         set_inode_slab_tunables "1 1 0"
5641         cancel_lru_locks osc
5642         BEFORE_INODES=$(num_inodes)
5643         echo "before inodes: $BEFORE_INODES"
5644         local COUNT=1000
5645         [ "$SLOW" = "no" ] && COUNT=100
5646         for i in $(seq $COUNT); do
5647                 touch $DIR/$tfile
5648                 rm -f $DIR/$tfile
5649         done
5650         cancel_lru_locks osc
5651         AFTER_INODES=$(num_inodes)
5652         echo "after inodes: $AFTER_INODES"
5653         local wait=0
5654         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5655                 sleep 2
5656                 AFTER_INODES=$(num_inodes)
5657                 wait=$((wait+2))
5658                 echo "wait $wait seconds inodes: $AFTER_INODES"
5659                 if [ $wait -gt 30 ]; then
5660                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5661                 fi
5662         done
5663         set_inode_slab_tunables "$SLAB_SETTINGS"
5664 }
5665 run_test 76 "confirm clients recycle inodes properly ===="
5666
5667
5668 export ORIG_CSUM=""
5669 set_checksums()
5670 {
5671         # Note: in sptlrpc modes which enable its own bulk checksum, the
5672         # original crc32_le bulk checksum will be automatically disabled,
5673         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5674         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5675         # In this case set_checksums() will not be no-op, because sptlrpc
5676         # bulk checksum will be enabled all through the test.
5677
5678         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5679         lctl set_param -n osc.*.checksums $1
5680         return 0
5681 }
5682
5683 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5684                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5685 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5686 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5687 set_checksum_type()
5688 {
5689         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5690         log "set checksum type to $1"
5691         return 0
5692 }
5693 F77_TMP=$TMP/f77-temp
5694 F77SZ=8
5695 setup_f77() {
5696         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5697                 error "error writing to $F77_TMP"
5698 }
5699
5700 test_77a() { # bug 10889
5701         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5702         $GSS && skip "could not run with gss" && return
5703         [ ! -f $F77_TMP ] && setup_f77
5704         set_checksums 1
5705         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5706         set_checksums 0
5707         rm -f $DIR/$tfile
5708 }
5709 run_test 77a "normal checksum read/write operation"
5710
5711 test_77b() { # bug 10889
5712         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5713         $GSS && skip "could not run with gss" && return
5714         [ ! -f $F77_TMP ] && setup_f77
5715         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5716         $LCTL set_param fail_loc=0x80000409
5717         set_checksums 1
5718
5719         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5720                 error "dd error: $?"
5721         $LCTL set_param fail_loc=0
5722
5723         for algo in $CKSUM_TYPES; do
5724                 cancel_lru_locks osc
5725                 set_checksum_type $algo
5726                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5727                 $LCTL set_param fail_loc=0x80000408
5728                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5729                 $LCTL set_param fail_loc=0
5730         done
5731         set_checksums 0
5732         set_checksum_type $ORIG_CSUM_TYPE
5733         rm -f $DIR/$tfile
5734 }
5735 run_test 77b "checksum error on client write, read"
5736
5737 test_77d() { # bug 10889
5738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5739         $GSS && skip "could not run with gss" && return
5740         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5741         $LCTL set_param fail_loc=0x80000409
5742         set_checksums 1
5743         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5744                 error "direct write: rc=$?"
5745         $LCTL set_param fail_loc=0
5746         set_checksums 0
5747
5748         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5749         $LCTL set_param fail_loc=0x80000408
5750         set_checksums 1
5751         cancel_lru_locks osc
5752         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5753                 error "direct read: rc=$?"
5754         $LCTL set_param fail_loc=0
5755         set_checksums 0
5756 }
5757 run_test 77d "checksum error on OST direct write, read"
5758
5759 test_77f() { # bug 10889
5760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5761         $GSS && skip "could not run with gss" && return
5762         set_checksums 1
5763         for algo in $CKSUM_TYPES; do
5764                 cancel_lru_locks osc
5765                 set_checksum_type $algo
5766                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5767                 $LCTL set_param fail_loc=0x409
5768                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5769                         error "direct write succeeded"
5770                 $LCTL set_param fail_loc=0
5771         done
5772         set_checksum_type $ORIG_CSUM_TYPE
5773         set_checksums 0
5774 }
5775 run_test 77f "repeat checksum error on write (expect error)"
5776
5777 test_77g() { # bug 10889
5778         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5779         $GSS && skip "could not run with gss" && return
5780         remote_ost_nodsh && skip "remote OST with nodsh" && return
5781
5782         [ ! -f $F77_TMP ] && setup_f77
5783
5784         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5785         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5786         do_facet ost1 lctl set_param fail_loc=0x8000021a
5787         set_checksums 1
5788         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5789                 error "write error: rc=$?"
5790         do_facet ost1 lctl set_param fail_loc=0
5791         set_checksums 0
5792
5793         cancel_lru_locks osc
5794         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5795         do_facet ost1 lctl set_param fail_loc=0x8000021b
5796         set_checksums 1
5797         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5798         do_facet ost1 lctl set_param fail_loc=0
5799         set_checksums 0
5800 }
5801 run_test 77g "checksum error on OST write, read"
5802
5803 test_77i() { # bug 13805
5804         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5805         $GSS && skip "could not run with gss" && return
5806         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5807         lctl set_param fail_loc=0x40b
5808         remount_client $MOUNT
5809         lctl set_param fail_loc=0
5810         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5811                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5812                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5813                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5814         done
5815         remount_client $MOUNT
5816 }
5817 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5818
5819 test_77j() { # bug 13805
5820         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5821         $GSS && skip "could not run with gss" && return
5822         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5823         lctl set_param fail_loc=0x40c
5824         remount_client $MOUNT
5825         lctl set_param fail_loc=0
5826         sleep 2 # wait async osc connect to finish
5827         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5828                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5829                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5830                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5831         done
5832         remount_client $MOUNT
5833 }
5834 run_test 77j "client only supporting ADLER32"
5835
5836 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5837 rm -f $F77_TMP
5838 unset F77_TMP
5839
5840 test_78() { # bug 10901
5841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5842         remote_ost || { skip_env "local OST" && return; }
5843
5844         NSEQ=5
5845         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5846         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5847         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5848         echo "MemTotal: $MEMTOTAL"
5849
5850         # reserve 256MB of memory for the kernel and other running processes,
5851         # and then take 1/2 of the remaining memory for the read/write buffers.
5852         if [ $MEMTOTAL -gt 512 ] ;then
5853                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5854         else
5855                 # for those poor memory-starved high-end clusters...
5856                 MEMTOTAL=$((MEMTOTAL / 2))
5857         fi
5858         echo "Mem to use for directio: $MEMTOTAL"
5859
5860         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5861         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5862         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5863         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5864                 head -n1)
5865         echo "Smallest OST: $SMALLESTOST"
5866         [[ $SMALLESTOST -lt 10240 ]] &&
5867                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5868
5869         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5870                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5871
5872         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5873         echo "File size: $F78SIZE"
5874         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5875         for i in $(seq 1 $NSEQ); do
5876                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5877                 echo directIO rdwr round $i of $NSEQ
5878                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5879         done
5880
5881         rm -f $DIR/$tfile
5882 }
5883 run_test 78 "handle large O_DIRECT writes correctly ============"
5884
5885 test_79() { # bug 12743
5886         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5887         wait_delete_completed
5888
5889         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5890         BKFREE=$(calc_osc_kbytes kbytesfree)
5891         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5892
5893         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5894         DFTOTAL=`echo $STRING | cut -d, -f1`
5895         DFUSED=`echo $STRING  | cut -d, -f2`
5896         DFAVAIL=`echo $STRING | cut -d, -f3`
5897         DFFREE=$(($DFTOTAL - $DFUSED))
5898
5899         ALLOWANCE=$((64 * $OSTCOUNT))
5900
5901         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5902            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5903                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5904         fi
5905         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5906            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5907                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5908         fi
5909         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5910            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5911                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5912         fi
5913 }
5914 run_test 79 "df report consistency check ======================="
5915
5916 test_80() { # bug 10718
5917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5918         # relax strong synchronous semantics for slow backends like ZFS
5919         local soc="obdfilter.*.sync_on_lock_cancel"
5920         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5921         local hosts=
5922         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5923                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5924                           facet_active_host $host; done | sort -u)
5925                 do_nodes $hosts lctl set_param $soc=never
5926         fi
5927
5928         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5929         sync; sleep 1; sync
5930         local BEFORE=`date +%s`
5931         cancel_lru_locks osc
5932         local AFTER=`date +%s`
5933         local DIFF=$((AFTER-BEFORE))
5934         if [ $DIFF -gt 1 ] ; then
5935                 error "elapsed for 1M@1T = $DIFF"
5936         fi
5937
5938         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5939
5940         rm -f $DIR/$tfile
5941 }
5942 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5943
5944 test_81a() { # LU-456
5945         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5946         remote_ost_nodsh && skip "remote OST with nodsh" && return
5947         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5948         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5949         do_facet ost1 lctl set_param fail_loc=0x80000228
5950
5951         # write should trigger a retry and success
5952         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5953         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5954         RC=$?
5955         if [ $RC -ne 0 ] ; then
5956                 error "write should success, but failed for $RC"
5957         fi
5958 }
5959 run_test 81a "OST should retry write when get -ENOSPC ==============="
5960
5961 test_81b() { # LU-456
5962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5963         remote_ost_nodsh && skip "remote OST with nodsh" && return
5964         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5965         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5966         do_facet ost1 lctl set_param fail_loc=0x228
5967
5968         # write should retry several times and return -ENOSPC finally
5969         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5970         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5971         RC=$?
5972         ENOSPC=28
5973         if [ $RC -ne $ENOSPC ] ; then
5974                 error "dd should fail for -ENOSPC, but succeed."
5975         fi
5976 }
5977 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5978
5979 test_82() { # LU-1031
5980         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5981         local gid1=14091995
5982         local gid2=16022000
5983
5984         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5985         local MULTIPID1=$!
5986         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5987         local MULTIPID2=$!
5988         kill -USR1 $MULTIPID2
5989         sleep 2
5990         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5991                 error "First grouplock does not block second one"
5992         else
5993                 echo "Second grouplock blocks first one"
5994         fi
5995         kill -USR1 $MULTIPID1
5996         wait $MULTIPID1
5997         wait $MULTIPID2
5998 }
5999 run_test 82 "Basic grouplock test ==============================="
6000
6001 test_99a() {
6002         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6003                 return
6004         test_mkdir -p $DIR/d99cvsroot
6005         chown $RUNAS_ID $DIR/d99cvsroot
6006         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6007         cd $TMP
6008
6009         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6010         cd $oldPWD
6011 }
6012 run_test 99a "cvs init ========================================="
6013
6014 test_99b() {
6015         [ -z "$(which cvs 2>/dev/null)" ] &&
6016                 skip_env "could not find cvs" && return
6017         [ ! -d $DIR/d99cvsroot ] && test_99a
6018         cd /etc/init.d
6019         # some versions of cvs import exit(1) when asked to import links or
6020         # files they can't read.  ignore those files.
6021         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6022                         ! -perm +4 -printf '-I %f\n')
6023         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6024                 d99reposname vtag rtag
6025 }
6026 run_test 99b "cvs import ======================================="
6027
6028 test_99c() {
6029         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6030         [ ! -d $DIR/d99cvsroot ] && test_99b
6031         cd $DIR
6032         test_mkdir -p $DIR/d99reposname
6033         chown $RUNAS_ID $DIR/d99reposname
6034         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6035 }
6036 run_test 99c "cvs checkout ====================================="
6037
6038 test_99d() {
6039         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6040         [ ! -d $DIR/d99cvsroot ] && test_99c
6041         cd $DIR/d99reposname
6042         $RUNAS touch foo99
6043         $RUNAS cvs add -m 'addmsg' foo99
6044 }
6045 run_test 99d "cvs add =========================================="
6046
6047 test_99e() {
6048         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6049         [ ! -d $DIR/d99cvsroot ] && test_99c
6050         cd $DIR/d99reposname
6051         $RUNAS cvs update
6052 }
6053 run_test 99e "cvs update ======================================="
6054
6055 test_99f() {
6056         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6057         [ ! -d $DIR/d99cvsroot ] && test_99d
6058         cd $DIR/d99reposname
6059         $RUNAS cvs commit -m 'nomsg' foo99
6060     rm -fr $DIR/d99cvsroot
6061 }
6062 run_test 99f "cvs commit ======================================="
6063
6064 test_100() {
6065         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6066         [ "$NETTYPE" = tcp ] || \
6067                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6068                         return ; }
6069
6070         remote_ost_nodsh && skip "remote OST with nodsh" && return
6071         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6072         remote_servers || \
6073                 { skip "useless for local single node setup" && return; }
6074
6075         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6076                 [ "$PROT" != "tcp" ] && continue
6077                 RPORT=$(echo $REMOTE | cut -d: -f2)
6078                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6079
6080                 rc=0
6081                 LPORT=`echo $LOCAL | cut -d: -f2`
6082                 if [ $LPORT -ge 1024 ]; then
6083                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6084                         netstat -tna
6085                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6086                 fi
6087         done
6088         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6089 }
6090 run_test 100 "check local port using privileged port ==========="
6091
6092 function get_named_value()
6093 {
6094     local tag
6095
6096     tag=$1
6097     while read ;do
6098         line=$REPLY
6099         case $line in
6100         $tag*)
6101             echo $line | sed "s/^$tag[ ]*//"
6102             break
6103             ;;
6104         esac
6105     done
6106 }
6107
6108 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6109                    awk '/^max_cached_mb/ { print $2 }')
6110
6111 cleanup_101a() {
6112         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6113         trap 0
6114 }
6115
6116 test_101a() {
6117         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6118         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6119         local s
6120         local discard
6121         local nreads=10000
6122         local cache_limit=32
6123
6124         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6125         trap cleanup_101a EXIT
6126         $LCTL set_param -n llite.*.read_ahead_stats 0
6127         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6128
6129         #
6130         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6131         #
6132         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6133         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6134
6135         discard=0
6136         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6137                 get_named_value 'read but discarded' | cut -d" " -f1); do
6138                         discard=$(($discard + $s))
6139         done
6140         cleanup_101a
6141
6142         if [[ $(($discard * 10)) -gt $nreads ]]; then
6143                 $LCTL get_param osc.*-osc*.rpc_stats
6144                 $LCTL get_param llite.*.read_ahead_stats
6145                 error "too many ($discard) discarded pages"
6146         fi
6147         rm -f $DIR/$tfile || true
6148 }
6149 run_test 101a "check read-ahead for random reads ================"
6150
6151 setup_test101bc() {
6152         test_mkdir -p $DIR/$tdir
6153         local STRIPE_SIZE=$1
6154         local FILE_LENGTH=$2
6155         STRIPE_OFFSET=0
6156
6157         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6158
6159         local list=$(comma_list $(osts_nodes))
6160         set_osd_param $list '' read_cache_enable 0
6161         set_osd_param $list '' writethrough_cache_enable 0
6162
6163         trap cleanup_test101bc EXIT
6164         # prepare the read-ahead file
6165         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6166
6167         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6168                                 count=$FILE_SIZE_MB 2> /dev/null
6169
6170 }
6171
6172 cleanup_test101bc() {
6173         trap 0
6174         rm -rf $DIR/$tdir
6175         rm -f $DIR/$tfile
6176
6177         local list=$(comma_list $(osts_nodes))
6178         set_osd_param $list '' read_cache_enable 1
6179         set_osd_param $list '' writethrough_cache_enable 1
6180 }
6181
6182 calc_total() {
6183         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6184 }
6185
6186 ra_check_101() {
6187         local READ_SIZE=$1
6188         local STRIPE_SIZE=$2
6189         local FILE_LENGTH=$3
6190         local RA_INC=1048576
6191         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6192         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6193                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6194         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6195                         get_named_value 'read but discarded' |
6196                         cut -d" " -f1 | calc_total)
6197         if [[ $DISCARD -gt $discard_limit ]]; then
6198                 $LCTL get_param llite.*.read_ahead_stats
6199                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6200         else
6201                 echo "Read-ahead success for size ${READ_SIZE}"
6202         fi
6203 }
6204
6205 test_101b() {
6206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6207         [[ $OSTCOUNT -lt 2 ]] &&
6208                 skip_env "skipping stride IO stride-ahead test" && return
6209         local STRIPE_SIZE=1048576
6210         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6211         if [ $SLOW == "yes" ]; then
6212                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6213         else
6214                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6215         fi
6216
6217         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6218
6219         # prepare the read-ahead file
6220         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6221         cancel_lru_locks osc
6222         for BIDX in 2 4 8 16 32 64 128 256
6223         do
6224                 local BSIZE=$((BIDX*4096))
6225                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6226                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6227                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6228                 $LCTL set_param -n llite.*.read_ahead_stats 0
6229                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6230                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6231                 cancel_lru_locks osc
6232                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6233         done
6234         cleanup_test101bc
6235         true
6236 }
6237 run_test 101b "check stride-io mode read-ahead ================="
6238
6239 test_101c() {
6240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6241         local STRIPE_SIZE=1048576
6242         local FILE_LENGTH=$((STRIPE_SIZE*100))
6243         local nreads=10000
6244         local osc_rpc_stats
6245
6246         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6247
6248         cancel_lru_locks osc
6249         $LCTL set_param osc.*.rpc_stats 0
6250         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6251         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6252                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6253                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6254                 local size
6255
6256                 if [ $lines -le 20 ]; then
6257                         continue
6258                 fi
6259                 for size in 1 2 4 8; do
6260                         local rpc=$(echo "$stats" |
6261                                     awk '($1 == "'$size':") {print $2; exit; }')
6262                         [ $rpc != 0 ] &&
6263                                 error "Small $((size*4))k read IO $rpc !"
6264                 done
6265                 echo "$osc_rpc_stats check passed!"
6266         done
6267         cleanup_test101bc
6268         true
6269 }
6270 run_test 101c "check stripe_size aligned read-ahead ================="
6271
6272 set_read_ahead() {
6273         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6274         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6275 }
6276
6277 test_101d() {
6278         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6279         local file=$DIR/$tfile
6280         local sz_MB=${FILESIZE_101d:-500}
6281         local ra_MB=${READAHEAD_MB:-40}
6282
6283         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6284         [ $free_MB -lt $sz_MB ] &&
6285                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6286
6287         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6288         $SETSTRIPE -c -1 $file || error "setstripe failed"
6289
6290         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6291         echo Cancel LRU locks on lustre client to flush the client cache
6292         cancel_lru_locks osc
6293
6294         echo Disable read-ahead
6295         local old_READAHEAD=$(set_read_ahead 0)
6296
6297         echo Reading the test file $file with read-ahead disabled
6298         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6299
6300         echo Cancel LRU locks on lustre client to flush the client cache
6301         cancel_lru_locks osc
6302         echo Enable read-ahead with ${ra_MB}MB
6303         set_read_ahead $ra_MB
6304
6305         echo Reading the test file $file with read-ahead enabled
6306         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6307
6308         echo "read-ahead disabled time read $raOFF"
6309         echo "read-ahead enabled  time read $raON"
6310
6311         set_read_ahead $old_READAHEAD
6312         rm -f $file
6313         wait_delete_completed
6314
6315         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6316                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6317 }
6318 run_test 101d "file read with and without read-ahead enabled"
6319
6320 test_101e() {
6321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6322         local file=$DIR/$tfile
6323         local size_KB=500  #KB
6324         local count=100
6325         local bsize=1024
6326
6327         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6328         local need_KB=$((count * size_KB))
6329         [[ $free_KB -le $need_KB ]] &&
6330                 skip_env "Need free space $need_KB, have $free_KB" && return
6331
6332         echo "Creating $count ${size_KB}K test files"
6333         for ((i = 0; i < $count; i++)); do
6334                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6335         done
6336
6337         echo "Cancel LRU locks on lustre client to flush the client cache"
6338         cancel_lru_locks osc
6339
6340         echo "Reset readahead stats"
6341         $LCTL set_param -n llite.*.read_ahead_stats 0
6342
6343         for ((i = 0; i < $count; i++)); do
6344                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6345         done
6346
6347         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6348                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6349
6350         for ((i = 0; i < $count; i++)); do
6351                 rm -rf $file.$i 2>/dev/null
6352         done
6353
6354         #10000 means 20% reads are missing in readahead
6355         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6356 }
6357 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6358
6359 cleanup_test101f() {
6360     trap 0
6361     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6362     rm -rf $DIR/$tfile 2>/dev/null
6363 }
6364
6365 test_101f() {
6366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6367     local file=$DIR/$tfile
6368     local nreads=1000
6369
6370     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6371     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6372     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6373     trap cleanup_test101f EXIT
6374
6375     echo Cancel LRU locks on lustre client to flush the client cache
6376     cancel_lru_locks osc
6377
6378     echo Reset readahead stats
6379     $LCTL set_param -n llite.*.read_ahead_stats 0
6380     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6381     # readahead should read in 2M file on second read, so only miss
6382     # 2 pages.
6383     echo Random 4K reads on 2M file for 1000 times
6384     $READS -f $file -s 2097152 -b 4096 -n $nreads
6385
6386     echo checking missing pages
6387     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6388           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6389
6390     [ $miss -lt 3 ] || error "misses too much pages!"
6391     cleanup_test101f
6392 }
6393 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6394
6395 setup_test102() {
6396         test_mkdir -p $DIR/$tdir
6397         chown $RUNAS_ID $DIR/$tdir
6398         STRIPE_SIZE=65536
6399         STRIPE_OFFSET=1
6400         STRIPE_COUNT=$OSTCOUNT
6401         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6402
6403         trap cleanup_test102 EXIT
6404         cd $DIR
6405         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6406         cd $DIR/$tdir
6407         for num in 1 2 3 4; do
6408                 for count in $(seq 1 $STRIPE_COUNT); do
6409                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6410                                 local size=`expr $STRIPE_SIZE \* $num`
6411                                 local file=file"$num-$idx-$count"
6412                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6413                         done
6414                 done
6415         done
6416
6417         cd $DIR
6418         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6419 }
6420
6421 cleanup_test102() {
6422         trap 0
6423         rm -f $TMP/f102.tar
6424         rm -rf $DIR/d0.sanity/d102
6425 }
6426
6427 test_102a() {
6428         local testfile=$DIR/$tfile
6429
6430         touch $testfile
6431
6432         [ "$UID" != 0 ] && skip_env "must run as root" && return
6433         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6434                 skip_env "must have user_xattr" && return
6435
6436         [ -z "$(which setfattr 2>/dev/null)" ] &&
6437                 skip_env "could not find setfattr" && return
6438
6439         echo "set/get xattr..."
6440         setfattr -n trusted.name1 -v value1 $testfile ||
6441                 error "setfattr -n trusted.name1=value1 $testfile failed"
6442         getfattr -n trusted.name1 $testfile 2> /dev/null |
6443           grep "trusted.name1=.value1" ||
6444                 error "$testfile missing trusted.name1=value1"
6445
6446         setfattr -n user.author1 -v author1 $testfile ||
6447                 error "setfattr -n user.author1=author1 $testfile failed"
6448         getfattr -n user.author1 $testfile 2> /dev/null |
6449           grep "user.author1=.author1" ||
6450                 error "$testfile missing trusted.author1=author1"
6451
6452         echo "listxattr..."
6453         setfattr -n trusted.name2 -v value2 $testfile ||
6454                 error "$testfile unable to set trusted.name2"
6455         setfattr -n trusted.name3 -v value3 $testfile ||
6456                 error "$testfile unable to set trusted.name3"
6457         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6458             grep "trusted.name" | wc -l) -eq 3 ] ||
6459                 error "$testfile missing 3 trusted.name xattrs"
6460
6461         setfattr -n user.author2 -v author2 $testfile ||
6462                 error "$testfile unable to set user.author2"
6463         setfattr -n user.author3 -v author3 $testfile ||
6464                 error "$testfile unable to set user.author3"
6465         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6466             grep "user.author" | wc -l) -eq 3 ] ||
6467                 error "$testfile missing 3 user.author xattrs"
6468
6469         echo "remove xattr..."
6470         setfattr -x trusted.name1 $testfile ||
6471                 error "$testfile error deleting trusted.name1"
6472         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6473                 error "$testfile did not delete trusted.name1 xattr"
6474
6475         setfattr -x user.author1 $testfile ||
6476                 error "$testfile error deleting user.author1"
6477         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6478                 error "$testfile did not delete trusted.name1 xattr"
6479
6480         # b10667: setting lustre special xattr be silently discarded
6481         echo "set lustre special xattr ..."
6482         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6483                 error "$testfile allowed setting trusted.lov"
6484 }
6485 run_test 102a "user xattr test =================================="
6486
6487 test_102b() {
6488         [ -z "$(which setfattr 2>/dev/null)" ] &&
6489                 skip_env "could not find setfattr" && return
6490
6491         # b10930: get/set/list trusted.lov xattr
6492         echo "get/set/list trusted.lov xattr ..."
6493         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6494         local testfile=$DIR/$tfile
6495         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6496                 error "setstripe failed"
6497         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6498                 error "getstripe failed"
6499         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6500                 error "can't get trusted.lov from $testfile"
6501
6502         local testfile2=${testfile}2
6503         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6504                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6505
6506         $MCREATE $testfile2
6507         setfattr -n trusted.lov -v $value $testfile2
6508         local stripe_size=$($GETSTRIPE -S $testfile2)
6509         local stripe_count=$($GETSTRIPE -c $testfile2)
6510         [[ $stripe_size -eq 65536 ]] ||
6511                 error "stripe size $stripe_size != 65536"
6512         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6513                 error "stripe count $stripe_count != $STRIPECOUNT"
6514         rm -f $DIR/$tfile
6515 }
6516 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6517
6518 test_102c() {
6519         [ -z "$(which setfattr 2>/dev/null)" ] &&
6520                 skip_env "could not find setfattr" && return
6521
6522         # b10930: get/set/list lustre.lov xattr
6523         echo "get/set/list lustre.lov xattr ..."
6524         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6525         test_mkdir -p $DIR/$tdir
6526         chown $RUNAS_ID $DIR/$tdir
6527         local testfile=$DIR/$tdir/$tfile
6528         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6529                 error "setstripe failed"
6530         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6531                 error "getstripe failed"
6532         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6533         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6534
6535         local testfile2=${testfile}2
6536         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6537                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6538
6539         $RUNAS $MCREATE $testfile2
6540         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6541         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6542         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6543         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6544         [ $stripe_count -eq $STRIPECOUNT ] ||
6545                 error "stripe count $stripe_count != $STRIPECOUNT"
6546 }
6547 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6548
6549 compare_stripe_info1() {
6550         local stripe_index_all_zero=true
6551
6552         for num in 1 2 3 4; do
6553                 for count in $(seq 1 $STRIPE_COUNT); do
6554                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6555                                 local size=$((STRIPE_SIZE * num))
6556                                 local file=file"$num-$offset-$count"
6557                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6558                                 [[ $stripe_size -ne $size ]] &&
6559                                     error "$file: size $stripe_size != $size"
6560                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6561                                 # allow fewer stripes to be created, ORI-601
6562                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6563                                     error "$file: count $stripe_count != $count"
6564                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6565                                 [[ $stripe_index -ne 0 ]] &&
6566                                         stripe_index_all_zero=false
6567                         done
6568                 done
6569         done
6570         $stripe_index_all_zero &&
6571                 error "all files are being extracted starting from OST index 0"
6572         return 0
6573 }
6574
6575 find_lustre_tar() {
6576         [ -n "$(which tar 2>/dev/null)" ] &&
6577                 strings $(which tar) | grep -q "lustre" && echo tar
6578 }
6579
6580 test_102d() {
6581         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6582         # b10930: tar test for trusted.lov xattr
6583         TAR=$(find_lustre_tar)
6584         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6585         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6586         setup_test102
6587         test_mkdir -p $DIR/d102d
6588         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6589         cd $DIR/d102d/$tdir
6590         compare_stripe_info1
6591 }
6592 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6593
6594 test_102f() {
6595         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6596         # b10930: tar test for trusted.lov xattr
6597         TAR=$(find_lustre_tar)
6598         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6599         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6600         setup_test102
6601         test_mkdir -p $DIR/d102f
6602         cd $DIR
6603         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6604         cd $DIR/d102f/$tdir
6605         compare_stripe_info1
6606 }
6607 run_test 102f "tar copy files, not keep osts ==========="
6608
6609 grow_xattr() {
6610         local xsize=${1:-1024}  # in bytes
6611         local file=$DIR/$tfile
6612
6613         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6614                 skip "must have user_xattr" && return 0
6615         [ -z "$(which setfattr 2>/dev/null)" ] &&
6616                 skip_env "could not find setfattr" && return 0
6617         [ -z "$(which getfattr 2>/dev/null)" ] &&
6618                 skip_env "could not find getfattr" && return 0
6619
6620         touch $file
6621
6622         local value="$(generate_string $xsize)"
6623
6624         local xbig=trusted.big
6625         log "save $xbig on $file"
6626         setfattr -n $xbig -v $value $file ||
6627                 error "saving $xbig on $file failed"
6628
6629         local orig=$(get_xattr_value $xbig $file)
6630         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6631
6632         local xsml=trusted.sml
6633         log "save $xsml on $file"
6634         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6635
6636         local new=$(get_xattr_value $xbig $file)
6637         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6638
6639         log "grow $xsml on $file"
6640         setfattr -n $xsml -v "$value" $file ||
6641                 error "growing $xsml on $file failed"
6642
6643         new=$(get_xattr_value $xbig $file)
6644         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6645         log "$xbig still valid after growing $xsml"
6646
6647         rm -f $file
6648 }
6649
6650 test_102h() { # bug 15777
6651         grow_xattr 1024
6652 }
6653 run_test 102h "grow xattr from inside inode to external block"
6654
6655 test_102ha() {
6656         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6657         grow_xattr $(max_xattr_size)
6658 }
6659 run_test 102ha "grow xattr from inside inode to external inode"
6660
6661 test_102i() { # bug 17038
6662         [ -z "$(which getfattr 2>/dev/null)" ] &&
6663                 skip "could not find getfattr" && return
6664         touch $DIR/$tfile
6665         ln -s $DIR/$tfile $DIR/${tfile}link
6666         getfattr -n trusted.lov $DIR/$tfile ||
6667                 error "lgetxattr on $DIR/$tfile failed"
6668         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6669                 grep -i "no such attr" ||
6670                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6671         rm -f $DIR/$tfile $DIR/${tfile}link
6672 }
6673 run_test 102i "lgetxattr test on symbolic link ============"
6674
6675 test_102j() {
6676         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6677         TAR=$(find_lustre_tar)
6678         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6679         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6680         setup_test102 "$RUNAS"
6681         test_mkdir -p $DIR/d102j
6682         chown $RUNAS_ID $DIR/d102j
6683         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6684         cd $DIR/d102j/$tdir
6685         compare_stripe_info1 "$RUNAS"
6686 }
6687 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6688
6689 test_102k() {
6690         [ -z "$(which setfattr 2>/dev/null)" ] &&
6691                 skip "could not find setfattr" && return
6692         touch $DIR/$tfile
6693         # b22187 just check that does not crash for regular file.
6694         setfattr -n trusted.lov $DIR/$tfile
6695         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6696         local test_kdir=$DIR/d102k
6697         test_mkdir $test_kdir
6698         local default_size=`$GETSTRIPE -S $test_kdir`
6699         local default_count=`$GETSTRIPE -c $test_kdir`
6700         local default_offset=`$GETSTRIPE -i $test_kdir`
6701         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6702                 error 'dir setstripe failed'
6703         setfattr -n trusted.lov $test_kdir
6704         local stripe_size=`$GETSTRIPE -S $test_kdir`
6705         local stripe_count=`$GETSTRIPE -c $test_kdir`
6706         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6707         [ $stripe_size -eq $default_size ] ||
6708                 error "stripe size $stripe_size != $default_size"
6709         [ $stripe_count -eq $default_count ] ||
6710                 error "stripe count $stripe_count != $default_count"
6711         [ $stripe_offset -eq $default_offset ] ||
6712                 error "stripe offset $stripe_offset != $default_offset"
6713         rm -rf $DIR/$tfile $test_kdir
6714 }
6715 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6716
6717 test_102l() {
6718         [ -z "$(which getfattr 2>/dev/null)" ] &&
6719                 skip "could not find getfattr" && return
6720
6721         # LU-532 trusted. xattr is invisible to non-root
6722         local testfile=$DIR/$tfile
6723
6724         touch $testfile
6725
6726         echo "listxattr as user..."
6727         chown $RUNAS_ID $testfile
6728         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6729             grep -q "trusted" &&
6730                 error "$testfile trusted xattrs are user visible"
6731
6732         return 0;
6733 }
6734 run_test 102l "listxattr size test =================================="
6735
6736 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6737         local path=$DIR/$tfile
6738         touch $path
6739
6740         listxattr_size_check $path || error "listattr_size_check $path failed"
6741 }
6742 run_test 102m "Ensure listxattr fails on small bufffer ========"
6743
6744 cleanup_test102
6745
6746 getxattr() { # getxattr path name
6747         # Return the base64 encoding of the value of xattr name on path.
6748         local path=$1
6749         local name=$2
6750
6751         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6752         # file: $path
6753         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6754         #
6755         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6756
6757         getfattr --absolute-names --encoding=base64 --name=$name $path |
6758                 awk -F= -v name=$name '$1 == name {
6759                         print substr($0, index($0, "=") + 1);
6760         }'
6761 }
6762
6763 test_102n() { # LU-4101 mdt: protect internal xattrs
6764         local file0=$DIR/$tfile.0
6765         local file1=$DIR/$tfile.1
6766         local xattr0=$TMP/$tfile.0
6767         local xattr1=$TMP/$tfile.1
6768         local name
6769         local value
6770
6771         [ -z "$(which setfattr 2>/dev/null)" ] &&
6772                 skip "could not find setfattr" && return
6773
6774         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6775         then
6776                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6777                 return
6778         fi
6779
6780         rm -rf $file0 $file1 $xattr0 $xattr1
6781         touch $file0 $file1
6782
6783         # Get 'before' xattrs of $file1.
6784         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6785
6786         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6787                 # Try to copy xattr from $file0 to $file1.
6788                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6789
6790                 setfattr --name=trusted.$name --value="$value" $file1 ||
6791                         error "setxattr 'trusted.$name' failed"
6792
6793                 # Try to set a garbage xattr.
6794                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6795
6796                 setfattr --name=trusted.$name --value="$value" $file1 ||
6797                         error "setxattr 'trusted.$name' failed"
6798
6799                 # Try to remove the xattr from $file1. We don't care if this
6800                 # appears to succeed or fail, we just don't want there to be
6801                 # any changes or crashes.
6802                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6803         done
6804
6805         # Get 'after' xattrs of file1.
6806         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6807
6808         if ! diff $xattr0 $xattr1; then
6809                 error "before and after xattrs of '$file1' differ"
6810         fi
6811
6812         rm -rf $file0 $file1 $xattr0 $xattr1
6813
6814         return 0
6815 }
6816 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6817
6818 test_102p() { # LU-4703 setxattr did not check ownership
6819         local testfile=$DIR/$tfile
6820
6821         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6822                 skip "MDS needs to be at least 2.5.56" && return
6823
6824         touch $testfile
6825
6826         echo "setfacl as user..."
6827         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6828         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6829
6830         echo "setfattr as user..."
6831         setfacl -m "u:$RUNAS_ID:---" $testfile
6832         $RUNAS setfattr -x system.posix_acl_access $testfile
6833         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6834 }
6835 run_test 102p "check setxattr(2) correctly fails without permission"
6836
6837 run_acl_subtest()
6838 {
6839     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6840     return $?
6841 }
6842
6843 test_103a() {
6844         [ "$UID" != 0 ] && skip_env "must run as root" && return
6845         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6846                 skip "must have acl enabled" && return
6847         [ -z "$(which setfacl 2>/dev/null)" ] &&
6848                 skip_env "could not find setfacl" && return
6849         $GSS && skip "could not run under gss" && return
6850
6851         declare -a identity_old
6852
6853         for num in $(seq $MDSCOUNT); do
6854                 switch_identity $num true || identity_old[$num]=$?
6855         done
6856
6857         SAVE_UMASK=$(umask)
6858         umask 0022
6859         cd $DIR
6860
6861         echo "performing cp ..."
6862         run_acl_subtest cp || error "run_acl_subtest cp failed"
6863         echo "performing getfacl-noacl..."
6864         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6865         echo "performing misc..."
6866         run_acl_subtest misc || error  "misc test failed"
6867         echo "performing permissions..."
6868         run_acl_subtest permissions || error "permissions failed"
6869         echo "performing setfacl..."
6870         run_acl_subtest setfacl || error  "setfacl test failed"
6871
6872         # inheritance test got from HP
6873         echo "performing inheritance..."
6874         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6875         chmod +x make-tree || error "chmod +x failed"
6876         run_acl_subtest inheritance || error "inheritance test failed"
6877         rm -f make-tree
6878
6879         echo "LU-974 ignore umask when acl is enabled..."
6880         run_acl_subtest 974 || error "LU-974 umask test failed"
6881         if [ $MDSCOUNT -ge 2 ]; then
6882                 run_acl_subtest 974_remote ||
6883                         error "LU-974 umask test failed under remote dir"
6884         fi
6885
6886         echo "LU-2561 newly created file is same size as directory..."
6887         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6888                 run_acl_subtest 2561 || error "LU-2561 test failed"
6889         else
6890                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6891         fi
6892
6893         run_acl_subtest 4924 || error "LU-4924 test failed"
6894
6895         cd $SAVE_PWD
6896         umask $SAVE_UMASK
6897
6898         for num in $(seq $MDSCOUNT); do
6899                 if [ "${identity_old[$num]}" = 1 ]; then
6900                         switch_identity $num false || identity_old[$num]=$?
6901                 fi
6902         done
6903 }
6904 run_test 103a "acl test ========================================="
6905
6906 test_103b() {
6907         local noacl=false
6908         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
6909         local mountopts=$MDS_MOUNT_OPTS
6910
6911         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
6912                 noacl=true
6913         else
6914                 # stop the MDT
6915                 stop $SINGLEMDS || error "failed to stop MDT."
6916                 # remount the MDT
6917                 if [ -z "$MDS_MOUNT_OPTS" ]; then
6918                         MDS_MOUNT_OPTS="-o noacl"
6919                 else
6920                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
6921                 fi
6922                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6923                         error "failed to start MDT."
6924                 MDS_MOUNT_OPTS=$mountopts
6925         fi
6926
6927         touch $DIR/$tfile
6928         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
6929
6930         if ! $noacl; then
6931                 # stop the MDT
6932                 stop $SINGLEMDS || error "failed to stop MDT."
6933                 # remount the MDT
6934                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6935                         error "failed to start MDT."
6936         fi
6937
6938         true
6939 }
6940 run_test 103b "MDS mount option 'noacl'"
6941
6942 test_103c() {
6943         mkdir -p $DIR/$tdir
6944         cp -rp $DIR/$tdir $DIR/$tdir.bak
6945
6946         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
6947                 error "$DIR/$tdir shouldn't contain default ACL"
6948         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
6949                 error "$DIR/$tdir.bak shouldn't contain default ACL"
6950         true
6951 }
6952 run_test 103c "'cp -rp' won't set empty acl"
6953
6954 test_104a() {
6955         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6956         touch $DIR/$tfile
6957         lfs df || error "lfs df failed"
6958         lfs df -ih || error "lfs df -ih failed"
6959         lfs df -h $DIR || error "lfs df -h $DIR failed"
6960         lfs df -i $DIR || error "lfs df -i $DIR failed"
6961         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6962         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6963
6964         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6965         lctl --device %$OSC deactivate
6966         lfs df || error "lfs df with deactivated OSC failed"
6967         lctl --device %$OSC activate
6968         # wait the osc back to normal
6969         wait_osc_import_state client ost FULL
6970
6971         lfs df || error "lfs df with reactivated OSC failed"
6972         rm -f $DIR/$tfile
6973 }
6974 run_test 104a "lfs df [-ih] [path] test ========================="
6975
6976 test_104b() {
6977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6978         [ $RUNAS_ID -eq $UID ] &&
6979                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6980         chmod 666 /dev/obd
6981         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6982                         grep "Permission denied" | wc -l)))
6983         if [ $denied_cnt -ne 0 ]; then
6984                 error "lfs check servers test failed"
6985         fi
6986 }
6987 run_test 104b "$RUNAS lfs check servers test ===================="
6988
6989 test_105a() {
6990         # doesn't work on 2.4 kernels
6991         touch $DIR/$tfile
6992         if $(flock_is_enabled); then
6993                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6994         else
6995                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6996         fi
6997         rm -f $DIR/$tfile
6998 }
6999 run_test 105a "flock when mounted without -o flock test ========"
7000
7001 test_105b() {
7002         touch $DIR/$tfile
7003         if $(flock_is_enabled); then
7004                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7005         else
7006                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7007         fi
7008         rm -f $DIR/$tfile
7009 }
7010 run_test 105b "fcntl when mounted without -o flock test ========"
7011
7012 test_105c() {
7013         touch $DIR/$tfile
7014         if $(flock_is_enabled); then
7015                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7016         else
7017                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7018         fi
7019         rm -f $DIR/$tfile
7020 }
7021 run_test 105c "lockf when mounted without -o flock test ========"
7022
7023 test_105d() { # bug 15924
7024         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7025         test_mkdir -p $DIR/$tdir
7026         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7027         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7028         $LCTL set_param fail_loc=0x80000315
7029         flocks_test 2 $DIR/$tdir
7030 }
7031 run_test 105d "flock race (should not freeze) ========"
7032
7033 test_105e() { # bug 22660 && 22040
7034         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7035         touch $DIR/$tfile
7036         flocks_test 3 $DIR/$tfile
7037 }
7038 run_test 105e "Two conflicting flocks from same process ======="
7039
7040 test_106() { #bug 10921
7041         test_mkdir -p $DIR/$tdir
7042         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7043         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7044 }
7045 run_test 106 "attempt exec of dir followed by chown of that dir"
7046
7047 test_107() {
7048         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7049         CDIR=`pwd`
7050         cd $DIR
7051
7052         local file=core
7053         rm -f $file
7054
7055         local save_pattern=$(sysctl -n kernel.core_pattern)
7056         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7057         sysctl -w kernel.core_pattern=$file
7058         sysctl -w kernel.core_uses_pid=0
7059
7060         ulimit -c unlimited
7061         sleep 60 &
7062         SLEEPPID=$!
7063
7064         sleep 1
7065
7066         kill -s 11 $SLEEPPID
7067         wait $SLEEPPID
7068         if [ -e $file ]; then
7069                 size=`stat -c%s $file`
7070                 [ $size -eq 0 ] && error "Fail to create core file $file"
7071         else
7072                 error "Fail to create core file $file"
7073         fi
7074         rm -f $file
7075         sysctl -w kernel.core_pattern=$save_pattern
7076         sysctl -w kernel.core_uses_pid=$save_uses_pid
7077         cd $CDIR
7078 }
7079 run_test 107 "Coredump on SIG"
7080
7081 test_110() {
7082         test_mkdir -p $DIR/$tdir
7083         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7084                 error "mkdir with 255 char failed"
7085         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7086                 error "mkdir with 256 char should fail, but did not"
7087         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7088                 error "create with 255 char failed"
7089         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7090                 error "create with 256 char should fail, but did not"
7091
7092         ls -l $DIR/$tdir
7093         rm -rf $DIR/$tdir
7094 }
7095 run_test 110 "filename length checking"
7096
7097 test_115() {
7098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7099         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7100                 tail -1 | cut -c11-20)
7101         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7102         echo "Starting with $OSTIO_pre threads"
7103
7104         NUMTEST=20000
7105         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7106         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7107         echo "$NUMTEST creates/unlinks"
7108         test_mkdir -p $DIR/$tdir
7109         createmany -o $DIR/$tdir/$tfile $NUMTEST
7110         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7111
7112         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7113                 tail -1 | cut -c11-20)
7114
7115         # don't return an error
7116         [ $OSTIO_post == $OSTIO_pre ] && echo \
7117             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7118             echo "This may be fine, depending on what ran before this test" &&
7119             echo "and how fast this system is." && return
7120
7121         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7122 }
7123 run_test 115 "verify dynamic thread creation===================="
7124
7125 free_min_max () {
7126         wait_delete_completed
7127         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7128         echo OST kbytes available: ${AVAIL[@]}
7129         MAXI=0; MAXV=${AVAIL[0]}
7130         MINI=0; MINV=${AVAIL[0]}
7131         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7132                 #echo OST $i: ${AVAIL[i]}kb
7133                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7134                         MAXV=${AVAIL[i]}; MAXI=$i
7135                 fi
7136                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7137                         MINV=${AVAIL[i]}; MINI=$i
7138                 fi
7139         done
7140         echo Min free space: OST $MINI: $MINV
7141         echo Max free space: OST $MAXI: $MAXV
7142 }
7143
7144 test_116a() { # was previously test_116()
7145         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7146         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7147
7148         echo -n "Free space priority "
7149         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7150                 head -n1
7151         declare -a AVAIL
7152         free_min_max
7153
7154         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7155         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7156                 && return
7157         trap simple_cleanup_common EXIT
7158
7159
7160         # Check if we need to generate uneven OSTs
7161         test_mkdir -p $DIR/$tdir/OST${MINI}
7162         local FILL=$(($MINV / 4))
7163         local DIFF=$(($MAXV - $MINV))
7164         local DIFF2=$(($DIFF * 100 / $MINV))
7165
7166         local threshold=$(do_facet $SINGLEMDS \
7167                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7168         threshold=${threshold%%%}
7169         echo -n "Check for uneven OSTs: "
7170         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7171
7172         if [[ $DIFF2 -gt $threshold ]]; then
7173                 echo "ok"
7174                 echo "Don't need to fill OST$MINI"
7175         else
7176                 # generate uneven OSTs. Write 2% over the QOS threshold value
7177                 echo "no"
7178                 DIFF=$(($threshold - $DIFF2 + 2))
7179                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7180                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7181                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7182                         error "setstripe failed"
7183                 DIFF=$(($DIFF2 / 2048))
7184                 i=0
7185                 while [ $i -lt $DIFF ]; do
7186                         i=$(($i + 1))
7187                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7188                                 bs=2M count=1 2>/dev/null
7189                         echo -n .
7190                 done
7191                 echo .
7192                 sync
7193                 sleep_maxage
7194                 free_min_max
7195         fi
7196
7197         DIFF=$(($MAXV - $MINV))
7198         DIFF2=$(($DIFF * 100 / $MINV))
7199         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7200         if [[ $DIFF2 -gt $threshold ]]; then
7201                 echo "ok"
7202         else
7203                 echo "failed - QOS mode won't be used"
7204                 skip "QOS imbalance criteria not met"
7205                 simple_cleanup_common
7206                 return
7207         fi
7208
7209         MINI1=$MINI; MINV1=$MINV
7210         MAXI1=$MAXI; MAXV1=$MAXV
7211
7212         # now fill using QOS
7213         $SETSTRIPE -c 1 $DIR/$tdir
7214         FILL=$(($FILL / 200))
7215         if [ $FILL -gt 600 ]; then
7216                 FILL=600
7217         fi
7218         echo "writing $FILL files to QOS-assigned OSTs"
7219         i=0
7220         while [ $i -lt $FILL ]; do
7221                 i=$((i + 1))
7222                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7223                         count=1 2>/dev/null
7224                 echo -n .
7225         done
7226         echo "wrote $i 200k files"
7227         sync
7228         sleep_maxage
7229
7230         echo "Note: free space may not be updated, so measurements might be off"
7231         free_min_max
7232         DIFF2=$(($MAXV - $MINV))
7233         echo "free space delta: orig $DIFF final $DIFF2"
7234         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7235         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7236         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7237         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7238         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7239         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7240         [ $DIFF -gt 0 ] &&
7241                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7242
7243         # Figure out which files were written where
7244         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7245                   awk '/'$MINI1': / {print $2; exit}')
7246         echo $UUID
7247         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7248         echo "$MINC files created on smaller OST $MINI1"
7249         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7250                   awk '/'$MAXI1': / {print $2; exit}')
7251         echo $UUID
7252         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7253         echo "$MAXC files created on larger OST $MAXI1"
7254         FILL=$(($MAXC * 100 / $MINC - 100))
7255         [[ $MINC -gt 0 ]] &&
7256                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7257         [[ $MAXC -gt $MINC ]] ||
7258                 error_ignore LU-9 "stripe QOS didn't balance free space"
7259         simple_cleanup_common
7260 }
7261 run_test 116a "stripe QOS: free space balance ==================="
7262
7263 test_116b() { # LU-2093
7264         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7265         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7266                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7267 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7268         local old_rr
7269         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7270                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7271         do_facet $SINGLEMDS lctl set_param \
7272                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7273         mkdir -p $DIR/$tdir
7274         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7275         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7276         do_facet $SINGLEMDS lctl set_param fail_loc=0
7277         rm -rf $DIR/$tdir
7278         do_facet $SINGLEMDS lctl set_param \
7279                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7280 }
7281 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7282
7283 test_117() # bug 10891
7284 {
7285         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7286         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7287         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7288         lctl set_param fail_loc=0x21e
7289         > $DIR/$tfile || error "truncate failed"
7290         lctl set_param fail_loc=0
7291         echo "Truncate succeeded."
7292         rm -f $DIR/$tfile
7293 }
7294 run_test 117 "verify osd extend =========="
7295
7296 NO_SLOW_RESENDCOUNT=4
7297 export OLD_RESENDCOUNT=""
7298 set_resend_count () {
7299         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7300         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7301         lctl set_param -n $PROC_RESENDCOUNT $1
7302         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7303 }
7304
7305 # for reduce test_118* time (b=14842)
7306 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7307
7308 # Reset async IO behavior after error case
7309 reset_async() {
7310         FILE=$DIR/reset_async
7311
7312         # Ensure all OSCs are cleared
7313         $SETSTRIPE -c -1 $FILE
7314         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7315         sync
7316         rm $FILE
7317 }
7318
7319 test_118a() #bug 11710
7320 {
7321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7322         reset_async
7323
7324         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7325         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7326         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7327
7328         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7329                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7330                 return 1;
7331         fi
7332         rm -f $DIR/$tfile
7333 }
7334 run_test 118a "verify O_SYNC works =========="
7335
7336 test_118b()
7337 {
7338         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7339         remote_ost_nodsh && skip "remote OST with nodsh" && return
7340
7341         reset_async
7342
7343         #define OBD_FAIL_OST_ENOENT 0x217
7344         set_nodes_failloc "$(osts_nodes)" 0x217
7345         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7346         RC=$?
7347         set_nodes_failloc "$(osts_nodes)" 0
7348         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7349         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7350                     grep -c writeback)
7351
7352         if [[ $RC -eq 0 ]]; then
7353                 error "Must return error due to dropped pages, rc=$RC"
7354                 return 1;
7355         fi
7356
7357         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7358                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7359                 return 1;
7360         fi
7361
7362         echo "Dirty pages not leaked on ENOENT"
7363
7364         # Due to the above error the OSC will issue all RPCs syncronously
7365         # until a subsequent RPC completes successfully without error.
7366         $MULTIOP $DIR/$tfile Ow4096yc
7367         rm -f $DIR/$tfile
7368
7369         return 0
7370 }
7371 run_test 118b "Reclaim dirty pages on fatal error =========="
7372
7373 test_118c()
7374 {
7375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7376
7377         # for 118c, restore the original resend count, LU-1940
7378         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7379                                 set_resend_count $OLD_RESENDCOUNT
7380         remote_ost_nodsh && skip "remote OST with nodsh" && return
7381
7382         reset_async
7383
7384         #define OBD_FAIL_OST_EROFS               0x216
7385         set_nodes_failloc "$(osts_nodes)" 0x216
7386
7387         # multiop should block due to fsync until pages are written
7388         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7389         MULTIPID=$!
7390         sleep 1
7391
7392         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7393                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7394         fi
7395
7396         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7397                     grep -c writeback)
7398         if [[ $WRITEBACK -eq 0 ]]; then
7399                 error "No page in writeback, writeback=$WRITEBACK"
7400         fi
7401
7402         set_nodes_failloc "$(osts_nodes)" 0
7403         wait $MULTIPID
7404         RC=$?
7405         if [[ $RC -ne 0 ]]; then
7406                 error "Multiop fsync failed, rc=$RC"
7407         fi
7408
7409         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7410         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7411                     grep -c writeback)
7412         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7413                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7414         fi
7415
7416         rm -f $DIR/$tfile
7417         echo "Dirty pages flushed via fsync on EROFS"
7418         return 0
7419 }
7420 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7421
7422 # continue to use small resend count to reduce test_118* time (b=14842)
7423 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7424
7425 test_118d()
7426 {
7427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7428         remote_ost_nodsh && skip "remote OST with nodsh" && return
7429
7430         reset_async
7431
7432         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7433         set_nodes_failloc "$(osts_nodes)" 0x214
7434         # multiop should block due to fsync until pages are written
7435         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7436         MULTIPID=$!
7437         sleep 1
7438
7439         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7440                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7441         fi
7442
7443         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7444                     grep -c writeback)
7445         if [[ $WRITEBACK -eq 0 ]]; then
7446                 error "No page in writeback, writeback=$WRITEBACK"
7447         fi
7448
7449         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7450         set_nodes_failloc "$(osts_nodes)" 0
7451
7452         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7453         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7454                     grep -c writeback)
7455         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7456                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7457         fi
7458
7459         rm -f $DIR/$tfile
7460         echo "Dirty pages gaurenteed flushed via fsync"
7461         return 0
7462 }
7463 run_test 118d "Fsync validation inject a delay of the bulk =========="
7464
7465 test_118f() {
7466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7467         reset_async
7468
7469         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7470         lctl set_param fail_loc=0x8000040a
7471
7472         # Should simulate EINVAL error which is fatal
7473         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7474         RC=$?
7475         if [[ $RC -eq 0 ]]; then
7476                 error "Must return error due to dropped pages, rc=$RC"
7477         fi
7478
7479         lctl set_param fail_loc=0x0
7480
7481         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7482         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7483         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7484                     grep -c writeback)
7485         if [[ $LOCKED -ne 0 ]]; then
7486                 error "Locked pages remain in cache, locked=$LOCKED"
7487         fi
7488
7489         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7490                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7491         fi
7492
7493         rm -f $DIR/$tfile
7494         echo "No pages locked after fsync"
7495
7496         reset_async
7497         return 0
7498 }
7499 run_test 118f "Simulate unrecoverable OSC side error =========="
7500
7501 test_118g() {
7502         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7503         reset_async
7504
7505         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7506         lctl set_param fail_loc=0x406
7507
7508         # simulate local -ENOMEM
7509         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7510         RC=$?
7511
7512         lctl set_param fail_loc=0
7513         if [[ $RC -eq 0 ]]; then
7514                 error "Must return error due to dropped pages, rc=$RC"
7515         fi
7516
7517         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7518         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7519         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7520                         grep -c writeback)
7521         if [[ $LOCKED -ne 0 ]]; then
7522                 error "Locked pages remain in cache, locked=$LOCKED"
7523         fi
7524
7525         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7526                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7527         fi
7528
7529         rm -f $DIR/$tfile
7530         echo "No pages locked after fsync"
7531
7532         reset_async
7533         return 0
7534 }
7535 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7536
7537 test_118h() {
7538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7539         remote_ost_nodsh && skip "remote OST with nodsh" && return
7540
7541         reset_async
7542
7543         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7544         set_nodes_failloc "$(osts_nodes)" 0x20e
7545         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7546         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7547         RC=$?
7548
7549         set_nodes_failloc "$(osts_nodes)" 0
7550         if [[ $RC -eq 0 ]]; then
7551                 error "Must return error due to dropped pages, rc=$RC"
7552         fi
7553
7554         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7555         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7556         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7557                     grep -c writeback)
7558         if [[ $LOCKED -ne 0 ]]; then
7559                 error "Locked pages remain in cache, locked=$LOCKED"
7560         fi
7561
7562         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7563                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7564         fi
7565
7566         rm -f $DIR/$tfile
7567         echo "No pages locked after fsync"
7568
7569         return 0
7570 }
7571 run_test 118h "Verify timeout in handling recoverables errors  =========="
7572
7573 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7574
7575 test_118i() {
7576         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7577         remote_ost_nodsh && skip "remote OST with nodsh" && return
7578
7579         reset_async
7580
7581         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7582         set_nodes_failloc "$(osts_nodes)" 0x20e
7583
7584         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7585         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7586         PID=$!
7587         sleep 5
7588         set_nodes_failloc "$(osts_nodes)" 0
7589
7590         wait $PID
7591         RC=$?
7592         if [[ $RC -ne 0 ]]; then
7593                 error "got error, but should be not, rc=$RC"
7594         fi
7595
7596         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7597         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7598         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7599         if [[ $LOCKED -ne 0 ]]; then
7600                 error "Locked pages remain in cache, locked=$LOCKED"
7601         fi
7602
7603         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7604                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7605         fi
7606
7607         rm -f $DIR/$tfile
7608         echo "No pages locked after fsync"
7609
7610         return 0
7611 }
7612 run_test 118i "Fix error before timeout in recoverable error  =========="
7613
7614 [ "$SLOW" = "no" ] && set_resend_count 4
7615
7616 test_118j() {
7617         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7618         remote_ost_nodsh && skip "remote OST with nodsh" && return
7619
7620         reset_async
7621
7622         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7623         set_nodes_failloc "$(osts_nodes)" 0x220
7624
7625         # return -EIO from OST
7626         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7627         RC=$?
7628         set_nodes_failloc "$(osts_nodes)" 0x0
7629         if [[ $RC -eq 0 ]]; then
7630                 error "Must return error due to dropped pages, rc=$RC"
7631         fi
7632
7633         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7634         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7635         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7636         if [[ $LOCKED -ne 0 ]]; then
7637                 error "Locked pages remain in cache, locked=$LOCKED"
7638         fi
7639
7640         # in recoverable error on OST we want resend and stay until it finished
7641         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7642                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7643         fi
7644
7645         rm -f $DIR/$tfile
7646         echo "No pages locked after fsync"
7647
7648         return 0
7649 }
7650 run_test 118j "Simulate unrecoverable OST side error =========="
7651
7652 test_118k()
7653 {
7654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7655         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7656
7657         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7658         set_nodes_failloc "$(osts_nodes)" 0x20e
7659         test_mkdir -p $DIR/$tdir
7660
7661         for ((i=0;i<10;i++)); do
7662                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7663                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7664                 SLEEPPID=$!
7665                 sleep 0.500s
7666                 kill $SLEEPPID
7667                 wait $SLEEPPID
7668         done
7669
7670         set_nodes_failloc "$(osts_nodes)" 0
7671         rm -rf $DIR/$tdir
7672 }
7673 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7674
7675 test_118l()
7676 {
7677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7678         # LU-646
7679         test_mkdir -p $DIR/$tdir
7680         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7681         rm -rf $DIR/$tdir
7682 }
7683 run_test 118l "fsync dir ========="
7684
7685 test_118m() # LU-3066
7686 {
7687         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7688         test_mkdir -p $DIR/$tdir
7689         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7690         rm -rf $DIR/$tdir
7691 }
7692 run_test 118m "fdatasync dir ========="
7693
7694 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7695
7696 test_119a() # bug 11737
7697 {
7698         BSIZE=$((512 * 1024))
7699         directio write $DIR/$tfile 0 1 $BSIZE
7700         # We ask to read two blocks, which is more than a file size.
7701         # directio will indicate an error when requested and actual
7702         # sizes aren't equeal (a normal situation in this case) and
7703         # print actual read amount.
7704         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7705         if [ "$NOB" != "$BSIZE" ]; then
7706                 error "read $NOB bytes instead of $BSIZE"
7707         fi
7708         rm -f $DIR/$tfile
7709 }
7710 run_test 119a "Short directIO read must return actual read amount"
7711
7712 test_119b() # bug 11737
7713 {
7714         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7715
7716         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7717         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7718         sync
7719         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7720                 error "direct read failed"
7721         rm -f $DIR/$tfile
7722 }
7723 run_test 119b "Sparse directIO read must return actual read amount"
7724
7725 test_119c() # bug 13099
7726 {
7727         BSIZE=1048576
7728         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7729         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7730         rm -f $DIR/$tfile
7731 }
7732 run_test 119c "Testing for direct read hitting hole"
7733
7734 test_119d() # bug 15950
7735 {
7736         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7737         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7738         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7739         BSIZE=1048576
7740         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7741         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7742         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7743         lctl set_param fail_loc=0x40d
7744         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7745         pid_dio=$!
7746         sleep 1
7747         cat $DIR/$tfile > /dev/null &
7748         lctl set_param fail_loc=0
7749         pid_reads=$!
7750         wait $pid_dio
7751         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7752         sleep 2
7753         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7754         error "the read rpcs have not completed in 2s"
7755         rm -f $DIR/$tfile
7756         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7757 }
7758 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7759
7760 test_120a() {
7761         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7762         test_mkdir -p $DIR/$tdir
7763         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7764                skip "no early lock cancel on server" && return 0
7765
7766         lru_resize_disable mdc
7767         lru_resize_disable osc
7768         cancel_lru_locks mdc
7769         # asynchronous object destroy at MDT could cause bl ast to client
7770         cancel_lru_locks osc
7771
7772         stat $DIR/$tdir > /dev/null
7773         can1=$(do_facet $SINGLEMDS \
7774                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7775                awk '/ldlm_cancel/ {print $2}')
7776         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7777                awk '/ldlm_bl_callback/ {print $2}')
7778         test_mkdir -c1 $DIR/$tdir/d1
7779         can2=$(do_facet $SINGLEMDS \
7780                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7781                awk '/ldlm_cancel/ {print $2}')
7782         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7783                awk '/ldlm_bl_callback/ {print $2}')
7784         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7785         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7786         lru_resize_enable mdc
7787         lru_resize_enable osc
7788 }
7789 run_test 120a "Early Lock Cancel: mkdir test"
7790
7791 test_120b() {
7792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7793         test_mkdir $DIR/$tdir
7794         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7795                skip "no early lock cancel on server" && return 0
7796         lru_resize_disable mdc
7797         lru_resize_disable osc
7798         cancel_lru_locks mdc
7799         stat $DIR/$tdir > /dev/null
7800         can1=$(do_facet $SINGLEMDS \
7801                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7802                awk '/ldlm_cancel/ {print $2}')
7803         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7804                awk '/ldlm_bl_callback/ {print $2}')
7805         touch $DIR/$tdir/f1
7806         can2=$(do_facet $SINGLEMDS \
7807                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7808                awk '/ldlm_cancel/ {print $2}')
7809         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7810                awk '/ldlm_bl_callback/ {print $2}')
7811         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7812         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7813         lru_resize_enable mdc
7814         lru_resize_enable osc
7815 }
7816 run_test 120b "Early Lock Cancel: create test"
7817
7818 test_120c() {
7819         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7820         test_mkdir -c1 $DIR/$tdir
7821         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7822                skip "no early lock cancel on server" && return 0
7823         lru_resize_disable mdc
7824         lru_resize_disable osc
7825         test_mkdir -p -c1 $DIR/$tdir/d1
7826         test_mkdir -p -c1 $DIR/$tdir/d2
7827         touch $DIR/$tdir/d1/f1
7828         cancel_lru_locks mdc
7829         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7830         can1=$(do_facet $SINGLEMDS \
7831                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7832                awk '/ldlm_cancel/ {print $2}')
7833         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7834                awk '/ldlm_bl_callback/ {print $2}')
7835         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7836         can2=$(do_facet $SINGLEMDS \
7837                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7838                awk '/ldlm_cancel/ {print $2}')
7839         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7840                awk '/ldlm_bl_callback/ {print $2}')
7841         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7842         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7843         lru_resize_enable mdc
7844         lru_resize_enable osc
7845 }
7846 run_test 120c "Early Lock Cancel: link test"
7847
7848 test_120d() {
7849         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7850         test_mkdir -p -c1 $DIR/$tdir
7851         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7852                skip "no early lock cancel on server" && return 0
7853         lru_resize_disable mdc
7854         lru_resize_disable osc
7855         touch $DIR/$tdir
7856         cancel_lru_locks mdc
7857         stat $DIR/$tdir > /dev/null
7858         can1=$(do_facet $SINGLEMDS \
7859                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7860                awk '/ldlm_cancel/ {print $2}')
7861         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7862                awk '/ldlm_bl_callback/ {print $2}')
7863         chmod a+x $DIR/$tdir
7864         can2=$(do_facet $SINGLEMDS \
7865                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7866                awk '/ldlm_cancel/ {print $2}')
7867         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7868                awk '/ldlm_bl_callback/ {print $2}')
7869         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7870         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7871         lru_resize_enable mdc
7872         lru_resize_enable osc
7873 }
7874 run_test 120d "Early Lock Cancel: setattr test"
7875
7876 test_120e() {
7877         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7878         test_mkdir -p -c1 $DIR/$tdir
7879         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7880                skip "no early lock cancel on server" && return 0
7881         lru_resize_disable mdc
7882         lru_resize_disable osc
7883         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7884         cancel_lru_locks mdc
7885         cancel_lru_locks osc
7886         dd if=$DIR/$tdir/f1 of=/dev/null
7887         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7888         # XXX client can not do early lock cancel of OST lock
7889         # during unlink (LU-4206), so cancel osc lock now.
7890         cancel_lru_locks osc
7891         can1=$(do_facet $SINGLEMDS \
7892                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7893                awk '/ldlm_cancel/ {print $2}')
7894         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7895                awk '/ldlm_bl_callback/ {print $2}')
7896         unlink $DIR/$tdir/f1
7897         sleep 5
7898         can2=$(do_facet $SINGLEMDS \
7899                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7900                awk '/ldlm_cancel/ {print $2}')
7901         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7902                awk '/ldlm_bl_callback/ {print $2}')
7903         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7904         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7905         lru_resize_enable mdc
7906         lru_resize_enable osc
7907 }
7908 run_test 120e "Early Lock Cancel: unlink test"
7909
7910 test_120f() {
7911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7912         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7913                skip "no early lock cancel on server" && return 0
7914         test_mkdir -p -c1 $DIR/$tdir
7915         lru_resize_disable mdc
7916         lru_resize_disable osc
7917         test_mkdir -p -c1 $DIR/$tdir/d1
7918         test_mkdir -p -c1 $DIR/$tdir/d2
7919         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7920         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7921         cancel_lru_locks mdc
7922         cancel_lru_locks osc
7923         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7924         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7925         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7926         # XXX client can not do early lock cancel of OST lock
7927         # during rename (LU-4206), so cancel osc lock now.
7928         cancel_lru_locks osc
7929         can1=$(do_facet $SINGLEMDS \
7930                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7931                awk '/ldlm_cancel/ {print $2}')
7932         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7933                awk '/ldlm_bl_callback/ {print $2}')
7934         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7935         sleep 5
7936         can2=$(do_facet $SINGLEMDS \
7937                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7938                awk '/ldlm_cancel/ {print $2}')
7939         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7940                awk '/ldlm_bl_callback/ {print $2}')
7941         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7942         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7943         lru_resize_enable mdc
7944         lru_resize_enable osc
7945 }
7946 run_test 120f "Early Lock Cancel: rename test"
7947
7948 test_120g() {
7949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7950         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7951                skip "no early lock cancel on server" && return 0
7952         lru_resize_disable mdc
7953         lru_resize_disable osc
7954         count=10000
7955         echo create $count files
7956         test_mkdir -p $DIR/$tdir
7957         cancel_lru_locks mdc
7958         cancel_lru_locks osc
7959         t0=`date +%s`
7960
7961         can0=$(do_facet $SINGLEMDS \
7962                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7963                awk '/ldlm_cancel/ {print $2}')
7964         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7965                awk '/ldlm_bl_callback/ {print $2}')
7966         createmany -o $DIR/$tdir/f $count
7967         sync
7968         can1=$(do_facet $SINGLEMDS \
7969                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7970                awk '/ldlm_cancel/ {print $2}')
7971         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7972                awk '/ldlm_bl_callback/ {print $2}')
7973         t1=$(date +%s)
7974         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7975         echo rm $count files
7976         rm -r $DIR/$tdir
7977         sync
7978         can2=$(do_facet $SINGLEMDS \
7979                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7980                awk '/ldlm_cancel/ {print $2}')
7981         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7982                awk '/ldlm_bl_callback/ {print $2}')
7983         t2=$(date +%s)
7984         echo total: $count removes in $((t2-t1))
7985         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7986         sleep 2
7987         # wait for commitment of removal
7988         lru_resize_enable mdc
7989         lru_resize_enable osc
7990 }
7991 run_test 120g "Early Lock Cancel: performance test"
7992
7993 test_121() { #bug #10589
7994         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7995         rm -rf $DIR/$tfile
7996         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7997 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7998         lctl set_param fail_loc=0x310
7999         cancel_lru_locks osc > /dev/null
8000         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8001         lctl set_param fail_loc=0
8002         [[ $reads -eq $writes ]] ||
8003                 error "read $reads blocks, must be $writes blocks"
8004 }
8005 run_test 121 "read cancel race ========="
8006
8007 test_123a() { # was test 123, statahead(bug 11401)
8008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8009         SLOWOK=0
8010         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8011             log "testing on UP system. Performance may be not as good as expected."
8012                         SLOWOK=1
8013         fi
8014
8015         rm -rf $DIR/$tdir
8016         test_mkdir -p $DIR/$tdir
8017         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8018         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8019         MULT=10
8020         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8021                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8022
8023                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8024                 lctl set_param -n llite.*.statahead_max 0
8025                 lctl get_param llite.*.statahead_max
8026                 cancel_lru_locks mdc
8027                 cancel_lru_locks osc
8028                 stime=`date +%s`
8029                 time ls -l $DIR/$tdir | wc -l
8030                 etime=`date +%s`
8031                 delta=$((etime - stime))
8032                 log "ls $i files without statahead: $delta sec"
8033                 lctl set_param llite.*.statahead_max=$max
8034
8035                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8036                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8037                 cancel_lru_locks mdc
8038                 cancel_lru_locks osc
8039                 stime=`date +%s`
8040                 time ls -l $DIR/$tdir | wc -l
8041                 etime=`date +%s`
8042                 delta_sa=$((etime - stime))
8043                 log "ls $i files with statahead: $delta_sa sec"
8044                 lctl get_param -n llite.*.statahead_stats
8045                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8046
8047                 [[ $swrong -lt $ewrong ]] &&
8048                         log "statahead was stopped, maybe too many locks held!"
8049                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8050
8051                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8052                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8053                     lctl set_param -n llite.*.statahead_max 0
8054                     lctl get_param llite.*.statahead_max
8055                     cancel_lru_locks mdc
8056                     cancel_lru_locks osc
8057                     stime=`date +%s`
8058                     time ls -l $DIR/$tdir | wc -l
8059                     etime=`date +%s`
8060                     delta=$((etime - stime))
8061                     log "ls $i files again without statahead: $delta sec"
8062                     lctl set_param llite.*.statahead_max=$max
8063                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8064                         if [  $SLOWOK -eq 0 ]; then
8065                                 error "ls $i files is slower with statahead!"
8066                         else
8067                                 log "ls $i files is slower with statahead!"
8068                         fi
8069                         break
8070                     fi
8071                 fi
8072
8073                 [ $delta -gt 20 ] && break
8074                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8075                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8076         done
8077         log "ls done"
8078
8079         stime=`date +%s`
8080         rm -r $DIR/$tdir
8081         sync
8082         etime=`date +%s`
8083         delta=$((etime - stime))
8084         log "rm -r $DIR/$tdir/: $delta seconds"
8085         log "rm done"
8086         lctl get_param -n llite.*.statahead_stats
8087 }
8088 run_test 123a "verify statahead work"
8089
8090 test_123b () { # statahead(bug 15027)
8091         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8092         test_mkdir -p $DIR/$tdir
8093         createmany -o $DIR/$tdir/$tfile-%d 1000
8094
8095         cancel_lru_locks mdc
8096         cancel_lru_locks osc
8097
8098 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8099         lctl set_param fail_loc=0x80000803
8100         ls -lR $DIR/$tdir > /dev/null
8101         log "ls done"
8102         lctl set_param fail_loc=0x0
8103         lctl get_param -n llite.*.statahead_stats
8104         rm -r $DIR/$tdir
8105         sync
8106
8107 }
8108 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8109
8110 test_124a() {
8111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8112         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8113                 skip "no lru resize on server" && return 0
8114         local NR=2000
8115         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8116
8117         log "create $NR files at $DIR/$tdir"
8118         createmany -o $DIR/$tdir/f $NR ||
8119                 error "failed to create $NR files in $DIR/$tdir"
8120
8121         cancel_lru_locks mdc
8122         ls -l $DIR/$tdir > /dev/null
8123
8124         local NSDIR=""
8125         local LRU_SIZE=0
8126         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8127                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8128                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8129                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8130                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8131                         log "NSDIR=$NSDIR"
8132                         log "NS=$(basename $NSDIR)"
8133                         break
8134                 fi
8135         done
8136
8137         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8138                 skip "Not enough cached locks created!"
8139                 return 0
8140         fi
8141         log "LRU=$LRU_SIZE"
8142
8143         local SLEEP=30
8144
8145         # We know that lru resize allows one client to hold $LIMIT locks
8146         # for 10h. After that locks begin to be killed by client.
8147         local MAX_HRS=10
8148         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8149         log "LIMIT=$LIMIT"
8150
8151         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8152         # killing locks. Some time was spent for creating locks. This means
8153         # that up to the moment of sleep finish we must have killed some of
8154         # them (10-100 locks). This depends on how fast ther were created.
8155         # Many of them were touched in almost the same moment and thus will
8156         # be killed in groups.
8157         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8158
8159         # Use $LRU_SIZE_B here to take into account real number of locks
8160         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8161         local LRU_SIZE_B=$LRU_SIZE
8162         log "LVF=$LVF"
8163         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8164         log "OLD_LVF=$OLD_LVF"
8165         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8166
8167         # Let's make sure that we really have some margin. Client checks
8168         # cached locks every 10 sec.
8169         SLEEP=$((SLEEP+20))
8170         log "Sleep ${SLEEP} sec"
8171         local SEC=0
8172         while ((SEC<$SLEEP)); do
8173                 echo -n "..."
8174                 sleep 5
8175                 SEC=$((SEC+5))
8176                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8177                 echo -n "$LRU_SIZE"
8178         done
8179         echo ""
8180         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8181         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8182
8183         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8184                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8185                 unlinkmany $DIR/$tdir/f $NR
8186                 return
8187         }
8188
8189         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8190         log "unlink $NR files at $DIR/$tdir"
8191         unlinkmany $DIR/$tdir/f $NR
8192 }
8193 run_test 124a "lru resize ======================================="
8194
8195 get_max_pool_limit()
8196 {
8197         local limit=$($LCTL get_param \
8198                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8199         local max=0
8200         for l in $limit; do
8201                 if [[ $l -gt $max ]]; then
8202                         max=$l
8203                 fi
8204         done
8205         echo $max
8206 }
8207
8208 test_124b() {
8209         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8210         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8211                 skip "no lru resize on server" && return 0
8212
8213         LIMIT=$(get_max_pool_limit)
8214
8215         NR=$(($(default_lru_size)*20))
8216         if [[ $NR -gt $LIMIT ]]; then
8217                 log "Limit lock number by $LIMIT locks"
8218                 NR=$LIMIT
8219         fi
8220         lru_resize_disable mdc
8221         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8222                 error "failed to create $DIR/$tdir/disable_lru_resize"
8223
8224         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8225         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8226         cancel_lru_locks mdc
8227         stime=`date +%s`
8228         PID=""
8229         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8230         PID="$PID $!"
8231         sleep 2
8232         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8233         PID="$PID $!"
8234         sleep 2
8235         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8236         PID="$PID $!"
8237         wait $PID
8238         etime=`date +%s`
8239         nolruresize_delta=$((etime-stime))
8240         log "ls -la time: $nolruresize_delta seconds"
8241         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8242         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8243
8244         lru_resize_enable mdc
8245         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8246                 error "failed to create $DIR/$tdir/enable_lru_resize"
8247
8248         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8249         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8250         cancel_lru_locks mdc
8251         stime=`date +%s`
8252         PID=""
8253         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8254         PID="$PID $!"
8255         sleep 2
8256         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8257         PID="$PID $!"
8258         sleep 2
8259         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8260         PID="$PID $!"
8261         wait $PID
8262         etime=`date +%s`
8263         lruresize_delta=$((etime-stime))
8264         log "ls -la time: $lruresize_delta seconds"
8265         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8266
8267         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8268                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8269         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8270                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8271         else
8272                 log "lru resize performs the same with no lru resize"
8273         fi
8274         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8275 }
8276 run_test 124b "lru resize (performance test) ======================="
8277
8278 test_125() { # 13358
8279         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8280         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8281         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8282         test_mkdir -p $DIR/d125 || error "mkdir failed"
8283         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8284         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8285         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8286 }
8287 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8288
8289 test_126() { # bug 12829/13455
8290         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8291         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8292         $GSS && skip "must run as gss disabled" && return
8293
8294         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8295         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8296         rm -f $DIR/$tfile
8297         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8298 }
8299 run_test 126 "check that the fsgid provided by the client is taken into account"
8300
8301 test_127a() { # bug 15521
8302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8303         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8304         $LCTL set_param osc.*.stats=0
8305         FSIZE=$((2048 * 1024))
8306         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8307         cancel_lru_locks osc
8308         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8309
8310         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8311         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8312                 echo "got $COUNT $NAME"
8313                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8314                 eval $NAME=$COUNT || error "Wrong proc format"
8315
8316                 case $NAME in
8317                         read_bytes|write_bytes)
8318                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8319                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8320                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8321                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8322                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8323                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8324                                 error "sumsquare is too small: $SUMSQ"
8325                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8326                                 error "sumsquare is too big: $SUMSQ"
8327                         ;;
8328                         *) ;;
8329                 esac
8330         done < $DIR/${tfile}.tmp
8331
8332         #check that we actually got some stats
8333         [ "$read_bytes" ] || error "Missing read_bytes stats"
8334         [ "$write_bytes" ] || error "Missing write_bytes stats"
8335         [ "$read_bytes" != 0 ] || error "no read done"
8336         [ "$write_bytes" != 0 ] || error "no write done"
8337 }
8338 run_test 127a "verify the client stats are sane"
8339
8340 test_127b() { # bug LU-333
8341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8342         $LCTL set_param llite.*.stats=0
8343         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8344         # perform 2 reads and writes so MAX is different from SUM.
8345         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8346         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8347         cancel_lru_locks osc
8348         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8349         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8350
8351         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8352         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8353                 echo "got $COUNT $NAME"
8354                 eval $NAME=$COUNT || error "Wrong proc format"
8355
8356         case $NAME in
8357                 read_bytes)
8358                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8359                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8360                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8361                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8362                         ;;
8363                 write_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                         *) ;;
8370                 esac
8371         done < $TMP/${tfile}.tmp
8372
8373         #check that we actually got some stats
8374         [ "$read_bytes" ] || error "Missing read_bytes stats"
8375         [ "$write_bytes" ] || error "Missing write_bytes stats"
8376         [ "$read_bytes" != 0 ] || error "no read done"
8377         [ "$write_bytes" != 0 ] || error "no write done"
8378 }
8379 run_test 127b "verify the llite client stats are sane"
8380
8381 test_128() { # bug 15212
8382         touch $DIR/$tfile
8383         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8384                 find $DIR/$tfile
8385                 find $DIR/$tfile
8386         EOF
8387
8388         result=$(grep error $TMP/$tfile.log)
8389         rm -f $DIR/$tfile
8390         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8391 }
8392 run_test 128 "interactive lfs for 2 consecutive find's"
8393
8394 set_dir_limits () {
8395         local mntdev
8396         local canondev
8397         local node
8398
8399         local LDPROC=/proc/fs/ldiskfs
8400         local facets=$(get_facets MDS)
8401
8402         for facet in ${facets//,/ }; do
8403                 canondev=$(ldiskfs_canon \
8404                            *.$(convert_facet2label $facet).mntdev $facet)
8405                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8406                                                 LDPROC=/sys/fs/ldiskfs
8407                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8408         done
8409 }
8410
8411 test_129() {
8412         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8413         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8414                 skip "Only applicable to ldiskfs-based MDTs"
8415                 return
8416         fi
8417         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8418         ENOSPC=28
8419         EFBIG=27
8420
8421         rm -rf $DIR/$tdir
8422         test_mkdir -p $DIR/$tdir
8423
8424         # block size of mds1
8425         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8426         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8427         local MAX=$((MDSBLOCKSIZE * 3))
8428         set_dir_limits $MAX
8429         local I=$(stat -c%s "$DIR/$tdir")
8430         local J=0
8431         local STRIPE_COUNT=1
8432         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8433         MAX=$((MAX*STRIPE_COUNT))
8434         while [[ $I -le $MAX ]]; do
8435                 $MULTIOP $DIR/$tdir/$J Oc
8436                 rc=$?
8437                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8438                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8439                 #and EFBIG for previous versions
8440                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8441                         set_dir_limits 0
8442                         echo "return code $rc received as expected"
8443                         multiop $DIR/$tdir/$J Oc ||
8444                                 error_exit "multiop failed w/o dir size limit"
8445
8446                         I=$(stat -c%s "$DIR/$tdir")
8447
8448                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8449                                         $(version_code 2.4.51) ]
8450                         then
8451                                 [[ $I -eq $MAX ]] && return 0
8452                         else
8453                                 [[ $I -gt $MAX ]] && return 0
8454                         fi
8455                         error_exit "current dir size $I, previous limit $MAX"
8456                 elif [ $rc -ne 0 ]; then
8457                         set_dir_limits 0
8458                         error_exit "return code $rc received instead of expected " \
8459                                    "$EFBIG or $ENOSPC, files in dir $I"
8460                 fi
8461                 J=$((J+1))
8462                 I=$(stat -c%s "$DIR/$tdir")
8463         done
8464
8465         set_dir_limits 0
8466         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8467 }
8468 run_test 129 "test directory size limit ========================"
8469
8470 OLDIFS="$IFS"
8471 cleanup_130() {
8472         trap 0
8473         IFS="$OLDIFS"
8474 }
8475
8476 test_130a() {
8477         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8478         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8479                 return
8480
8481         trap cleanup_130 EXIT RETURN
8482
8483         local fm_file=$DIR/$tfile
8484         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8485         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8486                 error "dd failed for $fm_file"
8487
8488         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8489         filefrag -ves $fm_file
8490         RC=$?
8491         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8492                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8493         [ $RC != 0 ] && error "filefrag $fm_file failed"
8494
8495         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8496                       grep -v "ext:" | grep -v "found")
8497         lun=$($GETSTRIPE -i $fm_file)
8498
8499         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8500         IFS=$'\n'
8501         tot_len=0
8502         for line in $filefrag_op
8503         do
8504                 frag_lun=`echo $line | cut -d: -f5`
8505                 ext_len=`echo $line | cut -d: -f4`
8506                 if (( $frag_lun != $lun )); then
8507                         cleanup_130
8508                         error "FIEMAP on 1-stripe file($fm_file) failed"
8509                         return
8510                 fi
8511                 (( tot_len += ext_len ))
8512         done
8513
8514         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8515                 cleanup_130
8516                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8517                 return
8518         fi
8519
8520         cleanup_130
8521
8522         echo "FIEMAP on single striped file succeeded"
8523 }
8524 run_test 130a "FIEMAP (1-stripe file)"
8525
8526 test_130b() {
8527         [ "$OSTCOUNT" -lt "2" ] &&
8528                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8529
8530         [ "$OSTCOUNT" -ge "10" ] &&
8531                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8532
8533         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8534         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8535                 return
8536
8537         trap cleanup_130 EXIT RETURN
8538
8539         local fm_file=$DIR/$tfile
8540         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8541         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8542                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8543
8544         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8545                 error "dd failed on $fm_file"
8546
8547         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8548         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8549                       grep -v "ext:" | grep -v "found")
8550
8551         last_lun=$(echo $filefrag_op | cut -d: -f5)
8552
8553         IFS=$'\n'
8554         tot_len=0
8555         num_luns=1
8556         for line in $filefrag_op
8557         do
8558                 frag_lun=`echo $line | cut -d: -f5`
8559                 ext_len=`echo $line | cut -d: -f4`
8560                 if (( $frag_lun != $last_lun )); then
8561                         if (( tot_len != 1024 )); then
8562                                 cleanup_130
8563                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8564                                 return
8565                         else
8566                                 (( num_luns += 1 ))
8567                                 tot_len=0
8568                         fi
8569                 fi
8570                 (( tot_len += ext_len ))
8571                 last_lun=$frag_lun
8572         done
8573         if (( num_luns != 2 || tot_len != 1024 )); then
8574                 cleanup_130
8575                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8576                 return
8577         fi
8578
8579         cleanup_130
8580
8581         echo "FIEMAP on 2-stripe file succeeded"
8582 }
8583 run_test 130b "FIEMAP (2-stripe file)"
8584
8585 test_130c() {
8586         [ "$OSTCOUNT" -lt "2" ] &&
8587                 skip_env "skipping FIEMAP on 2-stripe file" && return
8588
8589         [ "$OSTCOUNT" -ge "10" ] &&
8590                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8591
8592         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8593         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8594                 return
8595
8596         trap cleanup_130 EXIT RETURN
8597
8598         local fm_file=$DIR/$tfile
8599         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8600         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8601                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8602
8603         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8604
8605         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8606         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8607
8608         last_lun=`echo $filefrag_op | cut -d: -f5`
8609
8610         IFS=$'\n'
8611         tot_len=0
8612         num_luns=1
8613         for line in $filefrag_op
8614         do
8615                 frag_lun=`echo $line | cut -d: -f5`
8616                 ext_len=`echo $line | cut -d: -f4`
8617                 if (( $frag_lun != $last_lun )); then
8618                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8619                         if (( logical != 512 )); then
8620                                 cleanup_130
8621                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8622                                 return
8623                         fi
8624                         if (( tot_len != 512 )); then
8625                                 cleanup_130
8626                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8627                                 return
8628                         else
8629                                 (( num_luns += 1 ))
8630                                 tot_len=0
8631                         fi
8632                 fi
8633                 (( tot_len += ext_len ))
8634                 last_lun=$frag_lun
8635         done
8636         if (( num_luns != 2 || tot_len != 512 )); then
8637                 cleanup_130
8638                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8639                 return
8640         fi
8641
8642         cleanup_130
8643
8644         echo "FIEMAP on 2-stripe file with hole succeeded"
8645 }
8646 run_test 130c "FIEMAP (2-stripe file with hole)"
8647
8648 test_130d() {
8649         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8650
8651         [ "$OSTCOUNT" -ge "10" ] &&
8652                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8653
8654         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8655         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8656
8657         trap cleanup_130 EXIT RETURN
8658
8659         local fm_file=$DIR/$tfile
8660         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8661         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8662                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8663
8664         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8665         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8666                 error "dd failed on $fm_file"
8667
8668         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8669         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8670                 grep -v "ext:" | grep -v "found"`
8671
8672         last_lun=`echo $filefrag_op | cut -d: -f5`
8673
8674         IFS=$'\n'
8675         tot_len=0
8676         num_luns=1
8677         for line in $filefrag_op
8678         do
8679                 frag_lun=`echo $line | cut -d: -f5`
8680                 ext_len=`echo $line | cut -d: -f4`
8681                 if (( $frag_lun != $last_lun )); then
8682                         if (( tot_len != 1024 )); then
8683                                 cleanup_130
8684                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8685                                 return
8686                         else
8687                                 (( num_luns += 1 ))
8688                                 tot_len=0
8689                         fi
8690                 fi
8691                 (( tot_len += ext_len ))
8692                 last_lun=$frag_lun
8693         done
8694         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8695                 cleanup_130
8696                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8697                 return
8698         fi
8699
8700         cleanup_130
8701
8702         echo "FIEMAP on N-stripe file succeeded"
8703 }
8704 run_test 130d "FIEMAP (N-stripe file)"
8705
8706 test_130e() {
8707         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8708
8709         [ "$OSTCOUNT" -ge "10" ] &&
8710                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8711
8712         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8713         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8714
8715         trap cleanup_130 EXIT RETURN
8716
8717         local fm_file=$DIR/$tfile
8718         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8719         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8720                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8721
8722         NUM_BLKS=512
8723         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8724         for ((i = 0; i < $NUM_BLKS; i++))
8725         do
8726                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8727         done
8728
8729         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8730         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8731
8732         last_lun=`echo $filefrag_op | cut -d: -f5`
8733
8734         IFS=$'\n'
8735         tot_len=0
8736         num_luns=1
8737         for line in $filefrag_op
8738         do
8739                 frag_lun=`echo $line | cut -d: -f5`
8740                 ext_len=`echo $line | cut -d: -f4`
8741                 if (( $frag_lun != $last_lun )); then
8742                         if (( tot_len != $EXPECTED_LEN )); then
8743                                 cleanup_130
8744                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8745                                 return
8746                         else
8747                                 (( num_luns += 1 ))
8748                                 tot_len=0
8749                         fi
8750                 fi
8751                 (( tot_len += ext_len ))
8752                 last_lun=$frag_lun
8753         done
8754         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8755                 cleanup_130
8756                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8757                 return
8758         fi
8759
8760         cleanup_130
8761
8762         echo "FIEMAP with continuation calls succeeded"
8763 }
8764 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8765
8766 # Test for writev/readv
8767 test_131a() {
8768         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8769         error "writev test failed"
8770         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8771         error "readv failed"
8772         rm -f $DIR/$tfile
8773 }
8774 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8775
8776 test_131b() {
8777         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8778         error "append writev test failed"
8779         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8780         error "append writev test failed"
8781         rm -f $DIR/$tfile
8782 }
8783 run_test 131b "test append writev"
8784
8785 test_131c() {
8786         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8787         error "NOT PASS"
8788 }
8789 run_test 131c "test read/write on file w/o objects"
8790
8791 test_131d() {
8792         rwv -f $DIR/$tfile -w -n 1 1572864
8793         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8794         if [ "$NOB" != 1572864 ]; then
8795                 error "Short read filed: read $NOB bytes instead of 1572864"
8796         fi
8797         rm -f $DIR/$tfile
8798 }
8799 run_test 131d "test short read"
8800
8801 test_131e() {
8802         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8803         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8804         error "read hitting hole failed"
8805         rm -f $DIR/$tfile
8806 }
8807 run_test 131e "test read hitting hole"
8808
8809 get_ost_param() {
8810         local token=$1
8811         local gl_sum=0
8812         for node in $(osts_nodes); do
8813                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8814                 [ x$gl = x"" ] && gl=0
8815                 gl_sum=$((gl_sum + gl))
8816         done
8817         echo $gl_sum
8818 }
8819
8820 som_mode_switch() {
8821         local som=$1
8822         local gl1=$2
8823         local gl2=$3
8824
8825         if [ x$som = x"enabled" ]; then
8826                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8827                 MOUNT_OPTS=`echo $MOUNT_OPTS |
8828                     sed 's/som_preview,\|,som_preview\|som_preview//g'`
8829                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8830         else
8831                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8832                 MOUNT_OPTS="${MOUNT_OPTS:+$MOUNT_OPTS,}som_preview"
8833                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8834         fi
8835
8836         # do remount to make new mount-conf parameters actual
8837         echo remounting...
8838         sync
8839         stopall
8840         setupall
8841 }
8842
8843 test_132() { #1028, SOM
8844         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8845         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8846         local num=$(get_mds_dir $DIR)
8847         local mymds=mds${num}
8848         local MOUNT_OPTS_SAVE=$MOUNT_OPTS
8849
8850         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8851         cancel_lru_locks osc
8852
8853         som1=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8854
8855         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8856         stat $DIR/$tfile >/dev/null
8857         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8858         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8859         rm $DIR/$tfile
8860         som_mode_switch $som1 $gl1 $gl2
8861
8862         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8863         cancel_lru_locks osc
8864
8865         som2=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8866         if [ $som1 == $som2 ]; then
8867             error "som is still "$som2
8868             if [ x$som2 = x"enabled" ]; then
8869                 som2="disabled"
8870             else
8871                 som2="enabled"
8872             fi
8873         fi
8874
8875         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8876         stat $DIR/$tfile >/dev/null
8877         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8878         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8879         som_mode_switch $som2 $gl1 $gl2
8880         MOUNT_OPTS=$MOUNT_OPTS_SAVE
8881 }
8882 run_test 132 "som avoids glimpse rpc"
8883
8884 check_stats() {
8885         local res
8886         local count
8887         case $1 in
8888         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8889                  ;;
8890         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8891                  ;;
8892         *) error "Wrong argument $1" ;;
8893         esac
8894         echo $res
8895         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8896         # if the argument $3 is zero, it means any stat increment is ok.
8897         if [[ $3 -gt 0 ]]; then
8898                 count=$(echo $res | awk '{ print $2 }')
8899                 [[ $count -ne $3 ]] &&
8900                         error "The $2 counter on $1 is wrong - expected $3"
8901         fi
8902 }
8903
8904 test_133a() {
8905         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8906         remote_ost_nodsh && skip "remote OST with nodsh" && return
8907         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8908
8909         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8910                 { skip "MDS doesn't support rename stats"; return; }
8911         local testdir=$DIR/${tdir}/stats_testdir
8912         mkdir -p $DIR/${tdir}
8913
8914         # clear stats.
8915         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8916         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8917
8918         # verify mdt stats first.
8919         mkdir ${testdir} || error "mkdir failed"
8920         check_stats $SINGLEMDS "mkdir" 1
8921         touch ${testdir}/${tfile} || "touch failed"
8922         check_stats $SINGLEMDS "open" 1
8923         check_stats $SINGLEMDS "close" 1
8924         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8925         check_stats $SINGLEMDS "mknod" 1
8926         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8927         check_stats $SINGLEMDS "unlink" 1
8928         rm -f ${testdir}/${tfile} || error "file remove failed"
8929         check_stats $SINGLEMDS "unlink" 2
8930
8931         # remove working dir and check mdt stats again.
8932         rmdir ${testdir} || error "rmdir failed"
8933         check_stats $SINGLEMDS "rmdir" 1
8934
8935         local testdir1=$DIR/${tdir}/stats_testdir1
8936         mkdir -p ${testdir}
8937         mkdir -p ${testdir1}
8938         touch ${testdir1}/test1
8939         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8940         check_stats $SINGLEMDS "crossdir_rename" 1
8941
8942         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8943         check_stats $SINGLEMDS "samedir_rename" 1
8944
8945         rm -rf $DIR/${tdir}
8946 }
8947 run_test 133a "Verifying MDT stats ========================================"
8948
8949 test_133b() {
8950         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8951         remote_ost_nodsh && skip "remote OST with nodsh" && return
8952         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8953         local testdir=$DIR/${tdir}/stats_testdir
8954         mkdir -p ${testdir} || error "mkdir failed"
8955         touch ${testdir}/${tfile} || "touch failed"
8956         cancel_lru_locks mdc
8957
8958         # clear stats.
8959         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8960         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8961
8962         # extra mdt stats verification.
8963         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8964         check_stats $SINGLEMDS "setattr" 1
8965         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8966         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8967         then            # LU-1740
8968                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8969                 check_stats $SINGLEMDS "getattr" 1
8970         fi
8971         $LFS df || error "lfs failed"
8972         check_stats $SINGLEMDS "statfs" 1
8973
8974         rm -rf $DIR/${tdir}
8975 }
8976 run_test 133b "Verifying extra MDT stats =================================="
8977
8978 test_133c() {
8979         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8980         remote_ost_nodsh && skip "remote OST with nodsh" && return
8981         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8982         local testdir=$DIR/${tdir}/stats_testdir
8983         test_mkdir -p ${testdir} || error "mkdir failed"
8984
8985         # verify obdfilter stats.
8986         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8987         sync
8988         cancel_lru_locks osc
8989         wait_delete_completed
8990
8991         # clear stats.
8992         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8993         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8994
8995         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8996         sync
8997         cancel_lru_locks osc
8998         check_stats ost "write" 1
8999
9000         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9001         check_stats ost "read" 1
9002
9003         > ${testdir}/${tfile} || error "truncate failed"
9004         check_stats ost "punch" 1
9005
9006         rm -f ${testdir}/${tfile} || error "file remove failed"
9007         wait_delete_completed
9008         check_stats ost "destroy" 1
9009
9010         rm -rf $DIR/${tdir}
9011 }
9012 run_test 133c "Verifying OST stats ========================================"
9013
9014 order_2() {
9015         local value=$1
9016         local orig=$value
9017         local order=1
9018
9019         while [ $value -ge 2 ]; do
9020                 order=$((order*2))
9021                 value=$((value/2))
9022         done
9023
9024         if [ $orig -gt $order ]; then
9025                 order=$((order*2))
9026         fi
9027         echo $order
9028 }
9029
9030 size_in_KMGT() {
9031     local value=$1
9032     local size=('K' 'M' 'G' 'T');
9033     local i=0
9034     local size_string=$value
9035
9036     while [ $value -ge 1024 ]; do
9037         if [ $i -gt 3 ]; then
9038             #T is the biggest unit we get here, if that is bigger,
9039             #just return XXXT
9040             size_string=${value}T
9041             break
9042         fi
9043         value=$((value >> 10))
9044         if [ $value -lt 1024 ]; then
9045             size_string=${value}${size[$i]}
9046             break
9047         fi
9048         i=$((i + 1))
9049     done
9050
9051     echo $size_string
9052 }
9053
9054 get_rename_size() {
9055     local size=$1
9056     local context=${2:-.}
9057     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9058                 grep -A1 $context |
9059                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9060     echo $sample
9061 }
9062
9063 test_133d() {
9064         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9065         remote_ost_nodsh && skip "remote OST with nodsh" && return
9066         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9067         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9068         { skip "MDS doesn't support rename stats"; return; }
9069
9070         local testdir1=$DIR/${tdir}/stats_testdir1
9071         local testdir2=$DIR/${tdir}/stats_testdir2
9072
9073         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9074
9075         mkdir -p ${testdir1} || error "mkdir failed"
9076         mkdir -p ${testdir2} || error "mkdir failed"
9077
9078         createmany -o $testdir1/test 512 || error "createmany failed"
9079
9080         # check samedir rename size
9081         mv ${testdir1}/test0 ${testdir1}/test_0
9082
9083         local testdir1_size=$(ls -l $DIR/${tdir} |
9084                 awk '/stats_testdir1/ {print $5}')
9085         local testdir2_size=$(ls -l $DIR/${tdir} |
9086                 awk '/stats_testdir2/ {print $5}')
9087
9088         testdir1_size=$(order_2 $testdir1_size)
9089         testdir2_size=$(order_2 $testdir2_size)
9090
9091         testdir1_size=$(size_in_KMGT $testdir1_size)
9092         testdir2_size=$(size_in_KMGT $testdir2_size)
9093
9094         echo "source rename dir size: ${testdir1_size}"
9095         echo "target rename dir size: ${testdir2_size}"
9096
9097         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9098         eval $cmd || error "$cmd failed"
9099         local samedir=$($cmd | grep 'same_dir')
9100         local same_sample=$(get_rename_size $testdir1_size)
9101         [ -z "$samedir" ] && error "samedir_rename_size count error"
9102         [[ $same_sample -eq 1 ]] ||
9103                 error "samedir_rename_size error $same_sample"
9104         echo "Check same dir rename stats success"
9105
9106         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9107
9108         # check crossdir rename size
9109         mv ${testdir1}/test_0 ${testdir2}/test_0
9110
9111         testdir1_size=$(ls -l $DIR/${tdir} |
9112                 awk '/stats_testdir1/ {print $5}')
9113         testdir2_size=$(ls -l $DIR/${tdir} |
9114                 awk '/stats_testdir2/ {print $5}')
9115
9116         testdir1_size=$(order_2 $testdir1_size)
9117         testdir2_size=$(order_2 $testdir2_size)
9118
9119         testdir1_size=$(size_in_KMGT $testdir1_size)
9120         testdir2_size=$(size_in_KMGT $testdir2_size)
9121
9122         echo "source rename dir size: ${testdir1_size}"
9123         echo "target rename dir size: ${testdir2_size}"
9124
9125         eval $cmd || error "$cmd failed"
9126         local crossdir=$($cmd | grep 'crossdir')
9127         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9128         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9129         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9130         [[ $src_sample -eq 1 ]] ||
9131                 error "crossdir_rename_size error $src_sample"
9132         [[ $tgt_sample -eq 1 ]] ||
9133                 error "crossdir_rename_size error $tgt_sample"
9134         echo "Check cross dir rename stats success"
9135         rm -rf $DIR/${tdir}
9136 }
9137 run_test 133d "Verifying rename_stats ========================================"
9138
9139 test_133e() {
9140         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9141         local testdir=$DIR/${tdir}/stats_testdir
9142         local ctr f0 f1 bs=32768 count=42 sum
9143
9144         remote_ost_nodsh && skip "remote OST with nodsh" && return
9145         mkdir -p ${testdir} || error "mkdir failed"
9146
9147         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9148
9149         for ctr in {write,read}_bytes; do
9150                 sync
9151                 cancel_lru_locks osc
9152
9153                 do_facet ost1 $LCTL set_param -n \
9154                         "obdfilter.*.exports.clear=clear"
9155
9156                 if [ $ctr = write_bytes ]; then
9157                         f0=/dev/zero
9158                         f1=${testdir}/${tfile}
9159                 else
9160                         f0=${testdir}/${tfile}
9161                         f1=/dev/null
9162                 fi
9163
9164                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9165                         error "dd failed"
9166                 sync
9167                 cancel_lru_locks osc
9168
9169                 sum=$(do_facet ost1 $LCTL get_param \
9170                         "obdfilter.*.exports.*.stats" |
9171                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9172                                 $1 == ctr { sum += $7 }
9173                                 END { printf("%0.0f", sum) }')
9174
9175                 if ((sum != bs * count)); then
9176                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9177                 fi
9178         done
9179
9180         rm -rf $DIR/${tdir}
9181 }
9182 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9183
9184 test_133f() {
9185         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
9186         local facet
9187
9188         # First without trusting modes.
9189         find $proc_dirs -exec cat '{}' \; &> /dev/null
9190
9191         # Second verifying readability.
9192         find $proc_dirs \
9193                 -type f \
9194                 -exec cat '{}' \; &> /dev/null ||
9195                         error "proc file read failed"
9196
9197         for facet in $SINGLEMDS ost1; do
9198                 do_facet $facet find $proc_dirs \
9199                         ! -name req_history \
9200                         -exec cat '{}' \\\; &> /dev/null
9201
9202                 do_facet $facet find $proc_dirs \
9203                         ! -name req_history \
9204                         -type f \
9205                         -exec cat '{}' \\\; &> /dev/null ||
9206                                 error "proc file read failed"
9207         done
9208 }
9209 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9210
9211 test_133g() {
9212         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
9213         local facet
9214
9215         # Second verifying readability.
9216         find $proc_dirs \
9217                 -type f \
9218                 -not -name force_lbug \
9219                 -not -name changelog_mask \
9220                 -exec badarea_io '{}' \; &> /dev/null ||
9221                 error "find $proc_dirs failed"
9222
9223         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9224                 skip "Too old lustre on MDS"
9225
9226         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9227                 skip "Too old lustre on ost1"
9228
9229         for facet in $SINGLEMDS ost1; do
9230                 do_facet $facet find $proc_dirs \
9231                         -type f \
9232                         -not -name force_lbug \
9233                         -not -name changelog_mask \
9234                         -exec badarea_io '{}' \\\; &> /dev/null ||
9235                 error "$facet find $proc_dirs failed"
9236
9237         done
9238
9239         # remount the FS in case writes/reads /proc break the FS
9240         cleanup || error "failed to unmount"
9241         setup || error "failed to setup"
9242         true
9243 }
9244 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9245
9246 test_140() { #bug-17379
9247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9248         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9249         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9250         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9251
9252         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9253         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9254         local i=0
9255         while i=`expr $i + 1`; do
9256                 test_mkdir -p $i || error "Creating dir $i"
9257                 cd $i || error "Changing to $i"
9258                 ln -s ../stat stat || error "Creating stat symlink"
9259                 # Read the symlink until ELOOP present,
9260                 # not LBUGing the system is considered success,
9261                 # we didn't overrun the stack.
9262                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9263                 [ $ret -ne 0 ] && {
9264                         if [ $ret -eq 40 ]; then
9265                                 break  # -ELOOP
9266                         else
9267                                 error "Open stat symlink"
9268                                 return
9269                         fi
9270                 }
9271         done
9272         i=`expr $i - 1`
9273         echo "The symlink depth = $i"
9274         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9275                                         error "Invalid symlink depth"
9276
9277         # Test recursive symlink
9278         ln -s symlink_self symlink_self
9279         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9280         echo "open symlink_self returns $ret"
9281         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9282 }
9283 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9284
9285 test_150() {
9286         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9287         local TF="$TMP/$tfile"
9288
9289         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9290         cp $TF $DIR/$tfile
9291         cancel_lru_locks osc
9292         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9293         remount_client $MOUNT
9294         df -P $MOUNT
9295         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9296
9297         $TRUNCATE $TF 6000
9298         $TRUNCATE $DIR/$tfile 6000
9299         cancel_lru_locks osc
9300         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9301
9302         echo "12345" >>$TF
9303         echo "12345" >>$DIR/$tfile
9304         cancel_lru_locks osc
9305         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9306
9307         echo "12345" >>$TF
9308         echo "12345" >>$DIR/$tfile
9309         cancel_lru_locks osc
9310         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9311
9312         rm -f $TF
9313         true
9314 }
9315 run_test 150 "truncate/append tests"
9316
9317 #LU-2902 roc_hit was not able to read all values from lproc
9318 function roc_hit_init() {
9319         local list=$(comma_list $(osts_nodes))
9320         local dir=$DIR/$tdir-check
9321         local file=$dir/file
9322         local BEFORE
9323         local AFTER
9324         local idx
9325
9326         test_mkdir -p $dir
9327         #use setstripe to do a write to every ost
9328         for i in $(seq 0 $((OSTCOUNT-1))); do
9329                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9330                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9331                 idx=$(printf %04x $i)
9332                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9333                         awk '$1 == "cache_access" {sum += $7}
9334                                 END { printf("%0.0f", sum) }')
9335
9336                 cancel_lru_locks osc
9337                 cat $file >/dev/null
9338
9339                 AFTER=$(get_osd_param $list *OST*$idx stats |
9340                         awk '$1 == "cache_access" {sum += $7}
9341                                 END { printf("%0.0f", sum) }')
9342
9343                 echo BEFORE:$BEFORE AFTER:$AFTER
9344                 if ! let "AFTER - BEFORE == 4"; then
9345                         rm -rf $dir
9346                         error "roc_hit is not safe to use"
9347                 fi
9348                 rm $file
9349         done
9350
9351         rm -rf $dir
9352 }
9353
9354 function roc_hit() {
9355         local list=$(comma_list $(osts_nodes))
9356         echo $(get_osd_param $list '' stats |
9357                 awk '$1 == "cache_hit" {sum += $7}
9358                         END { printf("%0.0f", sum) }')
9359 }
9360
9361 function set_cache() {
9362         local on=1
9363
9364         if [ "$2" == "off" ]; then
9365                 on=0;
9366         fi
9367         local list=$(comma_list $(osts_nodes))
9368         set_osd_param $list '' $1_cache_enable $on
9369
9370         cancel_lru_locks osc
9371 }
9372
9373 test_151() {
9374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9375         remote_ost_nodsh && skip "remote OST with nodsh" && return
9376
9377         local CPAGES=3
9378         local list=$(comma_list $(osts_nodes))
9379
9380         # check whether obdfilter is cache capable at all
9381         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9382                 echo "not cache-capable obdfilter"
9383                 return 0
9384         fi
9385
9386         # check cache is enabled on all obdfilters
9387         if get_osd_param $list '' read_cache_enable | grep 0; then
9388                 echo "oss cache is disabled"
9389                 return 0
9390         fi
9391
9392         set_osd_param $list '' writethrough_cache_enable 1
9393
9394         # check write cache is enabled on all obdfilters
9395         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9396                 echo "oss write cache is NOT enabled"
9397                 return 0
9398         fi
9399
9400         roc_hit_init
9401
9402         #define OBD_FAIL_OBD_NO_LRU  0x609
9403         do_nodes $list $LCTL set_param fail_loc=0x609
9404
9405         # pages should be in the case right after write
9406         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9407                 error "dd failed"
9408
9409         local BEFORE=$(roc_hit)
9410         cancel_lru_locks osc
9411         cat $DIR/$tfile >/dev/null
9412         local AFTER=$(roc_hit)
9413
9414         do_nodes $list $LCTL set_param fail_loc=0
9415
9416         if ! let "AFTER - BEFORE == CPAGES"; then
9417                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9418         fi
9419
9420         # the following read invalidates the cache
9421         cancel_lru_locks osc
9422         set_osd_param $list '' read_cache_enable 0
9423         cat $DIR/$tfile >/dev/null
9424
9425         # now data shouldn't be found in the cache
9426         BEFORE=$(roc_hit)
9427         cancel_lru_locks osc
9428         cat $DIR/$tfile >/dev/null
9429         AFTER=$(roc_hit)
9430         if let "AFTER - BEFORE != 0"; then
9431                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9432         fi
9433
9434         set_osd_param $list '' read_cache_enable 1
9435         rm -f $DIR/$tfile
9436 }
9437 run_test 151 "test cache on oss and controls ==============================="
9438
9439 test_152() {
9440         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9441         local TF="$TMP/$tfile"
9442
9443         # simulate ENOMEM during write
9444 #define OBD_FAIL_OST_NOMEM      0x226
9445         lctl set_param fail_loc=0x80000226
9446         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9447         cp $TF $DIR/$tfile
9448         sync || error "sync failed"
9449         lctl set_param fail_loc=0
9450
9451         # discard client's cache
9452         cancel_lru_locks osc
9453
9454         # simulate ENOMEM during read
9455         lctl set_param fail_loc=0x80000226
9456         cmp $TF $DIR/$tfile || error "cmp failed"
9457         lctl set_param fail_loc=0
9458
9459         rm -f $TF
9460 }
9461 run_test 152 "test read/write with enomem ============================"
9462
9463 test_153() {
9464         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9465 }
9466 run_test 153 "test if fdatasync does not crash ======================="
9467
9468 dot_lustre_fid_permission_check() {
9469         local fid=$1
9470         local ffid=$MOUNT/.lustre/fid/$fid
9471         local test_dir=$2
9472
9473         echo "stat fid $fid"
9474         stat $ffid > /dev/null || error "stat $ffid failed."
9475         echo "touch fid $fid"
9476         touch $ffid || error "touch $ffid failed."
9477         echo "write to fid $fid"
9478         cat /etc/hosts > $ffid || error "write $ffid failed."
9479         echo "read fid $fid"
9480         diff /etc/hosts $ffid || error "read $ffid failed."
9481         echo "append write to fid $fid"
9482         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9483         echo "rename fid $fid"
9484         mv $ffid $test_dir/$tfile.1 &&
9485                 error "rename $ffid to $tfile.1 should fail."
9486         touch $test_dir/$tfile.1
9487         mv $test_dir/$tfile.1 $ffid &&
9488                 error "rename $tfile.1 to $ffid should fail."
9489         rm -f $test_dir/$tfile.1
9490         echo "truncate fid $fid"
9491         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9492         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9493                 echo "link fid $fid"
9494                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9495         fi
9496         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9497                 echo "setfacl fid $fid"
9498                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9499                 echo "getfacl fid $fid"
9500                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9501         fi
9502         echo "unlink fid $fid"
9503         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9504         echo "mknod fid $fid"
9505         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9506
9507         fid=[0xf00000400:0x1:0x0]
9508         ffid=$MOUNT/.lustre/fid/$fid
9509
9510         echo "stat non-exist fid $fid"
9511         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9512         echo "write to non-exist fid $fid"
9513         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9514         echo "link new fid $fid"
9515         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9516
9517         mkdir -p $test_dir/$tdir
9518         touch $test_dir/$tdir/$tfile
9519         fid=$($LFS path2fid $test_dir/$tdir)
9520         rc=$?
9521         [ $rc -ne 0 ] &&
9522                 error "error: could not get fid for $test_dir/$dir/$tfile."
9523
9524         ffid=$MOUNT/.lustre/fid/$fid
9525
9526         echo "ls $fid"
9527         ls $ffid > /dev/null || error "ls $ffid failed."
9528         echo "touch $fid/$tfile.1"
9529         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9530
9531         echo "touch $MOUNT/.lustre/fid/$tfile"
9532         touch $MOUNT/.lustre/fid/$tfile && \
9533                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9534
9535         echo "setxattr to $MOUNT/.lustre/fid"
9536         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9537
9538         echo "listxattr for $MOUNT/.lustre/fid"
9539         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9540
9541         echo "delxattr from $MOUNT/.lustre/fid"
9542         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9543
9544         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9545         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9546                 error "touch invalid fid should fail."
9547
9548         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9549         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9550                 error "touch non-normal fid should fail."
9551
9552         echo "rename $tdir to $MOUNT/.lustre/fid"
9553         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9554                 error "rename to $MOUNT/.lustre/fid should fail."
9555
9556         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9557         then            # LU-3547
9558                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9559                 local new_obf_mode=777
9560
9561                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9562                 chmod $new_obf_mode $DIR/.lustre/fid ||
9563                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9564
9565                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9566                 [ $obf_mode -eq $new_obf_mode ] ||
9567                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9568
9569                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9570                 chmod $old_obf_mode $DIR/.lustre/fid ||
9571                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9572         fi
9573
9574         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9575         fid=$($LFS path2fid $test_dir/$tfile-2)
9576
9577         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9578         then # LU-5424
9579                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9580                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9581                         error "create lov data thru .lustre failed"
9582         fi
9583         echo "cp /etc/passwd $test_dir/$tfile-2"
9584         cp /etc/passwd $test_dir/$tfile-2 ||
9585                 error "copy to $test_dir/$tfile-2 failed."
9586         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9587         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9588                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9589
9590         rm -rf $test_dir/tfile.lnk
9591         rm -rf $test_dir/$tfile-2
9592 }
9593
9594 test_154A() {
9595         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9596                 skip "Need MDS version at least 2.4.1" && return
9597
9598         touch $DIR/$tfile
9599         local FID=$($LFS path2fid $DIR/$tfile)
9600         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9601
9602         # check that we get the same pathname back
9603         local FOUND=$($LFS fid2path $MOUNT $FID)
9604         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9605         [ "$FOUND" != "$DIR/$tfile" ] &&
9606                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9607
9608         rm -rf $DIR/$tfile
9609 }
9610 run_test 154A "lfs path2fid and fid2path basic checks"
9611
9612 test_154a() {
9613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9614         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9615                 { skip "Need MDS version at least 2.2.51"; return 0; }
9616         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9617
9618         cp /etc/hosts $DIR/$tfile
9619
9620         fid=$($LFS path2fid $DIR/$tfile)
9621         rc=$?
9622         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9623
9624         dot_lustre_fid_permission_check "$fid" $DIR ||
9625                 error "dot lustre permission check $fid failed"
9626
9627         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9628
9629         touch $MOUNT/.lustre/file &&
9630                 error "creation is not allowed under .lustre"
9631
9632         mkdir $MOUNT/.lustre/dir &&
9633                 error "mkdir is not allowed under .lustre"
9634
9635         rm -rf $DIR/$tfile
9636 }
9637 run_test 154a "Open-by-FID"
9638
9639 test_154b() {
9640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9641         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9642                 { skip "Need MDS version at least 2.2.51"; return 0; }
9643
9644         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9645
9646         local remote_dir=$DIR/$tdir/remote_dir
9647         local MDTIDX=1
9648         local rc=0
9649
9650         mkdir -p $DIR/$tdir
9651         $LFS mkdir -i $MDTIDX $remote_dir ||
9652                 error "create remote directory failed"
9653
9654         cp /etc/hosts $remote_dir/$tfile
9655
9656         fid=$($LFS path2fid $remote_dir/$tfile)
9657         rc=$?
9658         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9659
9660         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9661                 error "dot lustre permission check $fid failed"
9662         rm -rf $DIR/$tdir
9663 }
9664 run_test 154b "Open-by-FID for remote directory"
9665
9666 test_154c() {
9667         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9668                 skip "Need MDS version at least 2.4.1" && return
9669
9670         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9671         local FID1=$($LFS path2fid $DIR/$tfile.1)
9672         local FID2=$($LFS path2fid $DIR/$tfile.2)
9673         local FID3=$($LFS path2fid $DIR/$tfile.3)
9674
9675         local N=1
9676         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9677                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9678                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9679                 local want=FID$N
9680                 [ "$FID" = "${!want}" ] ||
9681                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9682                 N=$((N + 1))
9683         done
9684
9685         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9686                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9687                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9688                 N=$((N + 1))
9689         done
9690 }
9691 run_test 154c "lfs path2fid and fid2path multiple arguments"
9692
9693 test_154d() {
9694         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9695                 skip "Need MDS version at least 2.5.53" && return
9696
9697         if remote_mds; then
9698                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9699         else
9700                 nid="0@lo"
9701         fi
9702         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9703         local fd
9704         local cmd
9705
9706         rm -f $DIR/$tfile
9707         touch $DIR/$tfile
9708
9709         fid=$($LFS path2fid $DIR/$tfile)
9710         # Open the file
9711         fd=$(free_fd)
9712         cmd="exec $fd<$DIR/$tfile"
9713         eval $cmd
9714         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9715         echo $fid_list | grep $fid
9716         rc=$?
9717
9718         cmd="exec $fd>/dev/null"
9719         eval $cmd
9720         if [ $rc -ne 0 ]; then
9721                 error "FID $fid not found in open files list $fid_list"
9722         fi
9723 }
9724 run_test 154d "Verify open file fid"
9725
9726 test_154e()
9727 {
9728         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9729                 skip "Need MDS version at least 2.6.50" && return
9730
9731         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9732                 error ".lustre returned by readdir"
9733         fi
9734 }
9735 run_test 154e ".lustre is not returned by readdir"
9736
9737 test_155_small_load() {
9738     local temp=$TMP/$tfile
9739     local file=$DIR/$tfile
9740
9741     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9742         error "dd of=$temp bs=6096 count=1 failed"
9743     cp $temp $file
9744     cancel_lru_locks osc
9745     cmp $temp $file || error "$temp $file differ"
9746
9747     $TRUNCATE $temp 6000
9748     $TRUNCATE $file 6000
9749     cmp $temp $file || error "$temp $file differ (truncate1)"
9750
9751     echo "12345" >>$temp
9752     echo "12345" >>$file
9753     cmp $temp $file || error "$temp $file differ (append1)"
9754
9755     echo "12345" >>$temp
9756     echo "12345" >>$file
9757     cmp $temp $file || error "$temp $file differ (append2)"
9758
9759     rm -f $temp $file
9760     true
9761 }
9762
9763 test_155_big_load() {
9764     remote_ost_nodsh && skip "remote OST with nodsh" && return
9765     local temp=$TMP/$tfile
9766     local file=$DIR/$tfile
9767
9768     free_min_max
9769     local cache_size=$(do_facet ost$((MAXI+1)) \
9770         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9771     local large_file_size=$((cache_size * 2))
9772
9773     echo "OSS cache size: $cache_size KB"
9774     echo "Large file size: $large_file_size KB"
9775
9776     [ $MAXV -le $large_file_size ] && \
9777         skip_env "max available OST size needs > $large_file_size KB" && \
9778         return 0
9779
9780     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9781
9782     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9783         error "dd of=$temp bs=$large_file_size count=1k failed"
9784     cp $temp $file
9785     ls -lh $temp $file
9786     cancel_lru_locks osc
9787     cmp $temp $file || error "$temp $file differ"
9788
9789     rm -f $temp $file
9790     true
9791 }
9792
9793 test_155a() {
9794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9795         set_cache read on
9796         set_cache writethrough on
9797         test_155_small_load
9798 }
9799 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9800
9801 test_155b() {
9802         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9803         set_cache read on
9804         set_cache writethrough off
9805         test_155_small_load
9806 }
9807 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9808
9809 test_155c() {
9810         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9811         set_cache read off
9812         set_cache writethrough on
9813         test_155_small_load
9814 }
9815 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9816
9817 test_155d() {
9818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9819         set_cache read off
9820         set_cache writethrough off
9821         test_155_small_load
9822 }
9823 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9824
9825 test_155e() {
9826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9827         set_cache read on
9828         set_cache writethrough on
9829         test_155_big_load
9830 }
9831 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9832
9833 test_155f() {
9834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9835         set_cache read on
9836         set_cache writethrough off
9837         test_155_big_load
9838 }
9839 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9840
9841 test_155g() {
9842         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9843         set_cache read off
9844         set_cache writethrough on
9845         test_155_big_load
9846 }
9847 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9848
9849 test_155h() {
9850         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9851         set_cache read off
9852         set_cache writethrough off
9853         test_155_big_load
9854 }
9855 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9856
9857 test_156() {
9858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9859         local CPAGES=3
9860         local BEFORE
9861         local AFTER
9862         local file="$DIR/$tfile"
9863
9864         [ "$(facet_fstype ost1)" = "zfs" ] &&
9865                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9866                 return
9867
9868         roc_hit_init
9869
9870     log "Turn on read and write cache"
9871     set_cache read on
9872     set_cache writethrough on
9873
9874     log "Write data and read it back."
9875     log "Read should be satisfied from the cache."
9876     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9877     BEFORE=`roc_hit`
9878     cancel_lru_locks osc
9879     cat $file >/dev/null
9880     AFTER=`roc_hit`
9881     if ! let "AFTER - BEFORE == CPAGES"; then
9882         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9883     else
9884         log "cache hits:: before: $BEFORE, after: $AFTER"
9885     fi
9886
9887     log "Read again; it should be satisfied from the cache."
9888     BEFORE=$AFTER
9889     cancel_lru_locks osc
9890     cat $file >/dev/null
9891     AFTER=`roc_hit`
9892     if ! let "AFTER - BEFORE == CPAGES"; then
9893         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9894     else
9895         log "cache hits:: before: $BEFORE, after: $AFTER"
9896     fi
9897
9898
9899     log "Turn off the read cache and turn on the write cache"
9900     set_cache read off
9901     set_cache writethrough on
9902
9903     log "Read again; it should be satisfied from the cache."
9904     BEFORE=`roc_hit`
9905     cancel_lru_locks osc
9906     cat $file >/dev/null
9907     AFTER=`roc_hit`
9908     if ! let "AFTER - BEFORE == CPAGES"; then
9909         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9910     else
9911         log "cache hits:: before: $BEFORE, after: $AFTER"
9912     fi
9913
9914     log "Read again; it should not be satisfied from the cache."
9915     BEFORE=$AFTER
9916     cancel_lru_locks osc
9917     cat $file >/dev/null
9918     AFTER=`roc_hit`
9919     if ! let "AFTER - BEFORE == 0"; then
9920         error "IN CACHE: before: $BEFORE, after: $AFTER"
9921     else
9922         log "cache hits:: before: $BEFORE, after: $AFTER"
9923     fi
9924
9925     log "Write data and read it back."
9926     log "Read should be satisfied from the cache."
9927     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9928     BEFORE=`roc_hit`
9929     cancel_lru_locks osc
9930     cat $file >/dev/null
9931     AFTER=`roc_hit`
9932     if ! let "AFTER - BEFORE == CPAGES"; then
9933         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9934     else
9935         log "cache hits:: before: $BEFORE, after: $AFTER"
9936     fi
9937
9938     log "Read again; it should not be satisfied from the cache."
9939     BEFORE=$AFTER
9940     cancel_lru_locks osc
9941     cat $file >/dev/null
9942     AFTER=`roc_hit`
9943     if ! let "AFTER - BEFORE == 0"; then
9944         error "IN CACHE: before: $BEFORE, after: $AFTER"
9945     else
9946         log "cache hits:: before: $BEFORE, after: $AFTER"
9947     fi
9948
9949
9950     log "Turn off read and write cache"
9951     set_cache read off
9952     set_cache writethrough off
9953
9954     log "Write data and read it back"
9955     log "It should not be satisfied from the cache."
9956     rm -f $file
9957     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9958     cancel_lru_locks osc
9959     BEFORE=`roc_hit`
9960     cat $file >/dev/null
9961     AFTER=`roc_hit`
9962         if ! let "AFTER - BEFORE == 0"; then
9963                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9964         else
9965                 log "cache hits:: before: $BEFORE, after: $AFTER"
9966         fi
9967
9968     log "Turn on the read cache and turn off the write cache"
9969     set_cache read on
9970     set_cache writethrough off
9971
9972     log "Write data and read it back"
9973     log "It should not be satisfied from the cache."
9974     rm -f $file
9975     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9976     BEFORE=`roc_hit`
9977     cancel_lru_locks osc
9978     cat $file >/dev/null
9979     AFTER=`roc_hit`
9980         if ! let "AFTER - BEFORE == 0"; then
9981                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9982         else
9983                 log "cache hits:: before: $BEFORE, after: $AFTER"
9984         fi
9985
9986     log "Read again; it should be satisfied from the cache."
9987     BEFORE=`roc_hit`
9988     cancel_lru_locks osc
9989     cat $file >/dev/null
9990     AFTER=`roc_hit`
9991     if ! let "AFTER - BEFORE == CPAGES"; then
9992         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9993     else
9994         log "cache hits:: before: $BEFORE, after: $AFTER"
9995     fi
9996
9997     rm -f $file
9998 }
9999 run_test 156 "Verification of tunables ============================"
10000
10001 #Changelogs
10002 err17935 () {
10003         if [[ $MDSCOUNT -gt 1 ]]; then
10004                 error_ignore bz17935 $*
10005         else
10006                 error $*
10007         fi
10008 }
10009
10010 changelog_chmask()
10011 {
10012         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10013
10014         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10015
10016         if [ $MASK -eq 1 ]; then
10017                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10018         else
10019                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10020         fi
10021 }
10022
10023 changelog_extract_field() {
10024         local mdt=$1
10025         local cltype=$2
10026         local file=$3
10027         local identifier=$4
10028
10029         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10030                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10031                 tail -1
10032 }
10033
10034 test_160a() {
10035         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10036         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10037         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10038                 { skip "Need MDS version at least 2.2.0"; return; }
10039
10040         local CL_USERS="mdd.$MDT0.changelog_users"
10041         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10042         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10043         echo "Registered as changelog user $USER"
10044         $GET_CL_USERS | grep -q $USER ||
10045                 error "User $USER not found in changelog_users"
10046
10047         # change something
10048         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10049         touch $DIR/$tdir/pics/2008/zachy/timestamp
10050         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10051         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10052         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10053         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10054         rm $DIR/$tdir/pics/desktop.jpg
10055
10056         $LFS changelog $MDT0 | tail -5
10057
10058         echo "verifying changelog mask"
10059         changelog_chmask "MKDIR"
10060         changelog_chmask "CLOSE"
10061
10062         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10063         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10064
10065         changelog_chmask "MKDIR"
10066         changelog_chmask "CLOSE"
10067
10068         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10069         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10070
10071         $LFS changelog $MDT0
10072         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10073         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10074         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10075         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10076
10077         # verify contents
10078         echo "verifying target fid"
10079         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10080         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10081         [ "$fidc" == "$fidf" ] ||
10082                 err17935 "fid in changelog $fidc != file fid $fidf"
10083         echo "verifying parent fid"
10084         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10085         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10086         [ "$fidc" == "$fidf" ] ||
10087                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10088
10089         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10090         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10091         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10092         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10093         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10094                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10095
10096         MIN_REC=$($GET_CL_USERS |
10097                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10098         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10099         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10100         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10101                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10102
10103         # LU-3446 changelog index reset on MDT restart
10104         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10105         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10106         $LFS changelog_clear $MDT0 $USER 0
10107         stop $SINGLEMDS || error "Fail to stop MDT."
10108         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10109         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10110         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10111         [ $CUR_REC1 == $CUR_REC2 ] ||
10112                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10113
10114         echo "verifying user deregister"
10115         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10116         $GET_CL_USERS | grep -q $USER &&
10117                 error "User $USER still in changelog_users"
10118
10119         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10120         if [ $USERS -eq 0 ]; then
10121                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10122                 touch $DIR/$tdir/chloe
10123                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10124                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10125                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10126         else
10127                 echo "$USERS other changelog users; can't verify off"
10128         fi
10129 }
10130 run_test 160a "changelog sanity"
10131
10132 test_160b() { # LU-3587
10133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10134         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10135         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10136                 { skip "Need MDS version at least 2.2.0"; return; }
10137
10138         local CL_USERS="mdd.$MDT0.changelog_users"
10139         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10140         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10141         echo "Registered as changelog user $USER"
10142         $GET_CL_USERS | grep -q $USER ||
10143                 error "User $USER not found in changelog_users"
10144
10145         local LONGNAME1=$(str_repeat a 255)
10146         local LONGNAME2=$(str_repeat b 255)
10147
10148         cd $DIR
10149         echo "creating very long named file"
10150         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10151         echo "moving very long named file"
10152         mv $LONGNAME1 $LONGNAME2
10153
10154         $LFS changelog $MDT0 | grep RENME
10155
10156         echo "deregistering $USER"
10157         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10158
10159         rm -f $LONGNAME2
10160 }
10161 run_test 160b "Verify that very long rename doesn't crash in changelog"
10162
10163 test_160c() {
10164         local rc=0
10165         local server_version=$(lustre_version_code $SINGLEMDS)
10166
10167         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10168                 [[ $server_version -gt $(version_code 2.5.1) &&
10169                    $server_version -lt $(version_code 2.5.50) ]] ||
10170                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10171         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10172
10173         # Registration step
10174         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10175                 changelog_register -n)
10176
10177         rm -rf $DIR/$tdir
10178         mkdir -p $DIR/$tdir
10179         $MCREATE $DIR/$tdir/foo_160c
10180         changelog_chmask "TRUNC"
10181         $TRUNCATE $DIR/$tdir/foo_160c 200
10182         changelog_chmask "TRUNC"
10183         $TRUNCATE $DIR/$tdir/foo_160c 199
10184         $LFS changelog $MDT0
10185         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10186         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10187         $LFS changelog_clear $MDT0 $USER 0
10188
10189         # Deregistration step
10190         echo "deregistering $USER"
10191         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10192 }
10193 run_test 160c "verify that changelog log catch the truncate event"
10194
10195 test_161a() {
10196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10197         test_mkdir -p -c1 $DIR/$tdir
10198         cp /etc/hosts $DIR/$tdir/$tfile
10199         test_mkdir -c1 $DIR/$tdir/foo1
10200         test_mkdir -c1 $DIR/$tdir/foo2
10201         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10202         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10203         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10204         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10205         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10206         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10207                 $LFS fid2path $DIR $FID
10208                 err17935 "bad link ea"
10209         fi
10210     # middle
10211     rm $DIR/$tdir/foo2/zachary
10212     # last
10213     rm $DIR/$tdir/foo2/thor
10214     # first
10215     rm $DIR/$tdir/$tfile
10216     # rename
10217     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10218     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10219         then
10220         $LFS fid2path $DIR $FID
10221         err17935 "bad link rename"
10222     fi
10223     rm $DIR/$tdir/foo2/maggie
10224
10225         # overflow the EA
10226         local longname=filename_avg_len_is_thirty_two_
10227         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10228                 error "failed to hardlink many files"
10229         links=$($LFS fid2path $DIR $FID | wc -l)
10230         echo -n "${links}/1000 links in link EA"
10231         [[ $links -gt 60 ]] ||
10232                 err17935 "expected at least 60 links in link EA"
10233         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10234                 error "failed to unlink many hardlinks"
10235 }
10236 run_test 161a "link ea sanity"
10237
10238 test_161b() {
10239         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10240         [ $MDSCOUNT -lt 2 ] &&
10241                 skip "skipping remote directory test" && return
10242         local MDTIDX=1
10243         local remote_dir=$DIR/$tdir/remote_dir
10244
10245         mkdir -p $DIR/$tdir
10246         $LFS mkdir -i $MDTIDX $remote_dir ||
10247                 error "create remote directory failed"
10248
10249         cp /etc/hosts $remote_dir/$tfile
10250         mkdir -p $remote_dir/foo1
10251         mkdir -p $remote_dir/foo2
10252         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10253         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10254         ln $remote_dir/$tfile $remote_dir/foo1/luna
10255         ln $remote_dir/$tfile $remote_dir/foo2/thor
10256
10257         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10258                      tr -d ']')
10259         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10260                 $LFS fid2path $DIR $FID
10261                 err17935 "bad link ea"
10262         fi
10263         # middle
10264         rm $remote_dir/foo2/zachary
10265         # last
10266         rm $remote_dir/foo2/thor
10267         # first
10268         rm $remote_dir/$tfile
10269         # rename
10270         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10271         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10272         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10273                 $LFS fid2path $DIR $FID
10274                 err17935 "bad link rename"
10275         fi
10276         rm $remote_dir/foo2/maggie
10277
10278         # overflow the EA
10279         local longname=filename_avg_len_is_thirty_two_
10280         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10281                 error "failed to hardlink many files"
10282         links=$($LFS fid2path $DIR $FID | wc -l)
10283         echo -n "${links}/1000 links in link EA"
10284         [[ ${links} -gt 60 ]] ||
10285                 err17935 "expected at least 60 links in link EA"
10286         unlinkmany $remote_dir/foo2/$longname 1000 ||
10287         error "failed to unlink many hardlinks"
10288 }
10289 run_test 161b "link ea sanity under remote directory"
10290
10291 test_161c() {
10292         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10293         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10294                 skip "Need MDS version at least 2.1.5" && return
10295
10296         # define CLF_RENAME_LAST 0x0001
10297         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10298         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10299                 changelog_register -n)
10300         rm -rf $DIR/$tdir
10301         mkdir -p $DIR/$tdir
10302         touch $DIR/$tdir/foo_161c
10303         touch $DIR/$tdir/bar_161c
10304         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10305         $LFS changelog $MDT0 | grep RENME
10306         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10307                 cut -f5 -d' ')
10308         $LFS changelog_clear $MDT0 $USER 0
10309         if [ x$flags != "x0x1" ]; then
10310                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10311                         $USER
10312                 error "flag $flags is not 0x1"
10313         fi
10314         echo "rename overwrite a target having nlink = 1," \
10315                 "changelog record has flags of $flags"
10316
10317         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10318         touch $DIR/$tdir/foo_161c
10319         touch $DIR/$tdir/bar_161c
10320         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10321         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10322         $LFS changelog $MDT0 | grep RENME
10323         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10324         $LFS changelog_clear $MDT0 $USER 0
10325         if [ x$flags != "x0x0" ]; then
10326                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10327                         $USER
10328                 error "flag $flags is not 0x0"
10329         fi
10330         echo "rename overwrite a target having nlink > 1," \
10331                 "changelog record has flags of $flags"
10332
10333         # rename doesn't overwrite a target (changelog flag 0x0)
10334         touch $DIR/$tdir/foo_161c
10335         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10336         $LFS changelog $MDT0 | grep RENME
10337         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10338         $LFS changelog_clear $MDT0 $USER 0
10339         if [ x$flags != "x0x0" ]; then
10340                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10341                         $USER
10342                 error "flag $flags is not 0x0"
10343         fi
10344         echo "rename doesn't overwrite a target," \
10345                 "changelog record has flags of $flags"
10346
10347         # define CLF_UNLINK_LAST 0x0001
10348         # unlink a file having nlink = 1 (changelog flag 0x1)
10349         rm -f $DIR/$tdir/foo2_161c
10350         $LFS changelog $MDT0 | grep UNLNK
10351         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10352         $LFS changelog_clear $MDT0 $USER 0
10353         if [ x$flags != "x0x1" ]; then
10354                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10355                         $USER
10356                 error "flag $flags is not 0x1"
10357         fi
10358         echo "unlink a file having nlink = 1," \
10359                 "changelog record has flags of $flags"
10360
10361         # unlink a file having nlink > 1 (changelog flag 0x0)
10362         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10363         rm -f $DIR/$tdir/foobar_161c
10364         $LFS changelog $MDT0 | grep UNLNK
10365         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10366         $LFS changelog_clear $MDT0 $USER 0
10367         if [ x$flags != "x0x0" ]; then
10368                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10369                         $USER
10370                 error "flag $flags is not 0x0"
10371         fi
10372         echo "unlink a file having nlink > 1," \
10373                 "changelog record has flags of $flags"
10374         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10375 }
10376 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10377
10378 check_path() {
10379     local expected=$1
10380     shift
10381     local fid=$2
10382
10383     local path=$(${LFS} fid2path $*)
10384     RC=$?
10385
10386     if [ $RC -ne 0 ]; then
10387         err17935 "path looked up of $expected failed. Error $RC"
10388         return $RC
10389     elif [ "${path}" != "${expected}" ]; then
10390         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10391         return 2
10392     fi
10393     echo "fid $fid resolves to path $path (expected $expected)"
10394 }
10395
10396 test_162() {
10397         # Make changes to filesystem
10398         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10399         test_mkdir -p -c1 $DIR/$tdir/d2
10400         touch $DIR/$tdir/d2/$tfile
10401         touch $DIR/$tdir/d2/x1
10402         touch $DIR/$tdir/d2/x2
10403         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10404         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10405         # regular file
10406         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10407         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10408                 error "check path $tdir/d2/$tfile failed"
10409
10410         # softlink
10411         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10412         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10413         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10414                 error "check path $tdir/d2/p/q/r/slink failed"
10415
10416         # softlink to wrong file
10417         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10418         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10419         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10420                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10421
10422         # hardlink
10423         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10424         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10425         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10426         # fid2path dir/fsname should both work
10427         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10428                 error "check path $tdir/d2/a/b/c/new_file failed"
10429         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10430                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10431
10432         # hardlink count: check that there are 2 links
10433         # Doesnt work with CMD yet: 17935
10434         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10435                 err17935 "expected 2 links"
10436
10437         # hardlink indexing: remove the first link
10438         rm $DIR/$tdir/d2/p/q/r/hlink
10439         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10440                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10441
10442         return 0
10443 }
10444 run_test 162 "path lookup sanity"
10445
10446 test_162b() {
10447         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10448         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10449
10450         mkdir $DIR/$tdir
10451         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10452                                 error "create striped dir failed"
10453
10454         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10455                                         tail -n 1 | awk '{print $2}')
10456         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10457
10458         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10459         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10460
10461         # regular file
10462         for ((i=0;i<5;i++)); do
10463                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10464                         error "get fid for f$i failed"
10465                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10466                         error "check path $tdir/striped_dir/f$i failed"
10467
10468                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10469                         error "get fid for d$i failed"
10470                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10471                         error "check path $tdir/striped_dir/d$i failed"
10472         done
10473
10474         return 0
10475 }
10476 run_test 162b "striped directory path lookup sanity"
10477
10478 test_169() {
10479         # do directio so as not to populate the page cache
10480         log "creating a 10 Mb file"
10481         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10482         log "starting reads"
10483         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10484         log "truncating the file"
10485         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10486         log "killing dd"
10487         kill %+ || true # reads might have finished
10488         echo "wait until dd is finished"
10489         wait
10490         log "removing the temporary file"
10491         rm -rf $DIR/$tfile || error "tmp file removal failed"
10492 }
10493 run_test 169 "parallel read and truncate should not deadlock"
10494
10495 test_170() {
10496         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10497         $LCTL clear     # bug 18514
10498         $LCTL debug_daemon start $TMP/${tfile}_log_good
10499         touch $DIR/$tfile
10500         $LCTL debug_daemon stop
10501         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10502                error "sed failed to read log_good"
10503
10504         $LCTL debug_daemon start $TMP/${tfile}_log_good
10505         rm -rf $DIR/$tfile
10506         $LCTL debug_daemon stop
10507
10508         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10509                error "lctl df log_bad failed"
10510
10511         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10512         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10513
10514         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10515         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10516
10517         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10518                 error "bad_line good_line1 good_line2 are empty"
10519
10520         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10521         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10522         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10523
10524         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10525         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10526         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10527
10528         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10529                 error "bad_line_new good_line_new are empty"
10530
10531         local expected_good=$((good_line1 + good_line2*2))
10532
10533         rm -f $TMP/${tfile}*
10534         # LU-231, short malformed line may not be counted into bad lines
10535         if [ $bad_line -ne $bad_line_new ] &&
10536                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10537                 error "expected $bad_line bad lines, but got $bad_line_new"
10538                 return 1
10539         fi
10540
10541         if [ $expected_good -ne $good_line_new ]; then
10542                 error "expected $expected_good good lines, but got $good_line_new"
10543                 return 2
10544         fi
10545         true
10546 }
10547 run_test 170 "test lctl df to handle corrupted log ====================="
10548
10549 test_171() { # bug20592
10550         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10551 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10552         $LCTL set_param fail_loc=0x50e
10553         $LCTL set_param fail_val=3000
10554         multiop_bg_pause $DIR/$tfile O_s || true
10555         local MULTIPID=$!
10556         kill -USR1 $MULTIPID
10557         # cause log dump
10558         sleep 3
10559         wait $MULTIPID
10560         if dmesg | grep "recursive fault"; then
10561                 error "caught a recursive fault"
10562         fi
10563         $LCTL set_param fail_loc=0
10564         true
10565 }
10566 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10567
10568 # it would be good to share it with obdfilter-survey/iokit-libecho code
10569 setup_obdecho_osc () {
10570         local rc=0
10571         local ost_nid=$1
10572         local obdfilter_name=$2
10573         echo "Creating new osc for $obdfilter_name on $ost_nid"
10574         # make sure we can find loopback nid
10575         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10576
10577         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10578                            ${obdfilter_name}_osc_UUID || rc=2; }
10579         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10580                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10581         return $rc
10582 }
10583
10584 cleanup_obdecho_osc () {
10585         local obdfilter_name=$1
10586         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10587         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10588         return 0
10589 }
10590
10591 obdecho_test() {
10592         local OBD=$1
10593         local node=$2
10594         local pages=${3:-64}
10595         local rc=0
10596         local id
10597
10598         local count=10
10599         local obd_size=$(get_obd_size $node $OBD)
10600         local page_size=$(get_page_size $node)
10601         if [[ -n "$obd_size" ]]; then
10602                 local new_count=$((obd_size / (pages * page_size / 1024)))
10603                 [[ $new_count -ge $count ]] || count=$new_count
10604         fi
10605
10606         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10607         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10608                            rc=2; }
10609         if [ $rc -eq 0 ]; then
10610             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10611             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10612         fi
10613         echo "New object id is $id"
10614         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10615                            rc=4; }
10616         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10617                            "test_brw $count w v $pages $id" || rc=4; }
10618         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10619                            rc=4; }
10620         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10621                                         "cleanup" || rc=5; }
10622         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10623                                         "detach" || rc=6; }
10624         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10625         return $rc
10626 }
10627
10628 test_180a() {
10629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10630         remote_ost_nodsh && skip "remote OST with nodsh" && return
10631         local rc=0
10632         local rmmod_local=0
10633
10634         if ! module_loaded obdecho; then
10635             load_module obdecho/obdecho
10636             rmmod_local=1
10637         fi
10638
10639         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10640         local host=$(lctl get_param -n osc.$osc.import |
10641                              awk '/current_connection:/ {print $2}' )
10642         local target=$(lctl get_param -n osc.$osc.import |
10643                              awk '/target:/ {print $2}' )
10644         target=${target%_UUID}
10645
10646         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10647         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10648         [[ -n $target ]] && cleanup_obdecho_osc $target
10649         [ $rmmod_local -eq 1 ] && rmmod obdecho
10650         return $rc
10651 }
10652 run_test 180a "test obdecho on osc"
10653
10654 test_180b() {
10655         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10656         remote_ost_nodsh && skip "remote OST with nodsh" && return
10657         local rc=0
10658         local rmmod_remote=0
10659
10660         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10661                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10662                       "modprobe obdecho; }" && rmmod_remote=1
10663         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10664         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10665         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10666         return $rc
10667 }
10668 run_test 180b "test obdecho directly on obdfilter"
10669
10670 test_180c() { # LU-2598
10671         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10672         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10673                 skip "Need MDS version at least 2.4.0" && return
10674
10675         local rc=0
10676         local rmmod_remote=false
10677         local pages=16384 # 64MB bulk I/O RPC size
10678         local target
10679
10680         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10681                 rmmod_remote=true || error "failed to load module obdecho"
10682
10683         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10684                 head -n1)
10685         if [ -n "$target" ]; then
10686                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10687         else
10688                 echo "there is no obdfilter target on ost1"
10689                 rc=2
10690         fi
10691         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10692         return $rc
10693 }
10694 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10695
10696 test_181() { # bug 22177
10697         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10698         # create enough files to index the directory
10699         createmany -o $DIR/$tdir/foobar 4000
10700         # print attributes for debug purpose
10701         lsattr -d .
10702         # open dir
10703         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10704         MULTIPID=$!
10705         # remove the files & current working dir
10706         unlinkmany $DIR/$tdir/foobar 4000
10707         rmdir $DIR/$tdir
10708         kill -USR1 $MULTIPID
10709         wait $MULTIPID
10710         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10711         return 0
10712 }
10713 run_test 181 "Test open-unlinked dir ========================"
10714
10715 test_182() {
10716         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10717         # disable MDC RPC lock wouldn't crash client
10718         local fcount=1000
10719         local tcount=4
10720
10721         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10722 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10723         $LCTL set_param fail_loc=0x804
10724
10725         for (( i=0; i < $tcount; i++ )) ; do
10726                 mkdir $DIR/$tdir/$i
10727                 createmany -o $DIR/$tdir/$i/f- $fcount &
10728         done
10729         wait
10730
10731         for (( i=0; i < $tcount; i++ )) ; do
10732                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10733         done
10734         wait
10735
10736         rm -rf $DIR/$tdir
10737
10738         $LCTL set_param fail_loc=0
10739 }
10740 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10741
10742 test_183() { # LU-2275
10743         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10744                 skip "Need MDS version at least 2.3.56" && return
10745
10746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10747         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10748         echo aaa > $DIR/$tdir/$tfile
10749
10750 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10751         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10752
10753         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10754         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10755
10756         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10757
10758         # Flush negative dentry cache
10759         touch $DIR/$tdir/$tfile
10760
10761         # We are not checking for any leaked references here, they'll
10762         # become evident next time we do cleanup with module unload.
10763         rm -rf $DIR/$tdir
10764 }
10765 run_test 183 "No crash or request leak in case of strange dispositions ========"
10766
10767 # test suite 184 is for LU-2016, LU-2017
10768 test_184a() {
10769         check_swap_layouts_support && return 0
10770
10771         dir0=$DIR/$tdir/$testnum
10772         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10773         ref1=/etc/passwd
10774         ref2=/etc/group
10775         file1=$dir0/f1
10776         file2=$dir0/f2
10777         $SETSTRIPE -c1 $file1
10778         cp $ref1 $file1
10779         $SETSTRIPE -c2 $file2
10780         cp $ref2 $file2
10781         gen1=$($GETSTRIPE -g $file1)
10782         gen2=$($GETSTRIPE -g $file2)
10783
10784         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10785         gen=$($GETSTRIPE -g $file1)
10786         [[ $gen1 != $gen ]] ||
10787                 "Layout generation on $file1 does not change"
10788         gen=$($GETSTRIPE -g $file2)
10789         [[ $gen2 != $gen ]] ||
10790                 "Layout generation on $file2 does not change"
10791
10792         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10793         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10794 }
10795 run_test 184a "Basic layout swap"
10796
10797 test_184b() {
10798         check_swap_layouts_support && return 0
10799
10800         dir0=$DIR/$tdir/$testnum
10801         mkdir -p $dir0 || error "creating dir $dir0"
10802         file1=$dir0/f1
10803         file2=$dir0/f2
10804         file3=$dir0/f3
10805         dir1=$dir0/d1
10806         dir2=$dir0/d2
10807         mkdir $dir1 $dir2
10808         $SETSTRIPE -c1 $file1
10809         $SETSTRIPE -c2 $file2
10810         $SETSTRIPE -c1 $file3
10811         chown $RUNAS_ID $file3
10812         gen1=$($GETSTRIPE -g $file1)
10813         gen2=$($GETSTRIPE -g $file2)
10814
10815         $LFS swap_layouts $dir1 $dir2 &&
10816                 error "swap of directories layouts should fail"
10817         $LFS swap_layouts $dir1 $file1 &&
10818                 error "swap of directory and file layouts should fail"
10819         $RUNAS $LFS swap_layouts $file1 $file2 &&
10820                 error "swap of file we cannot write should fail"
10821         $LFS swap_layouts $file1 $file3 &&
10822                 error "swap of file with different owner should fail"
10823         /bin/true # to clear error code
10824 }
10825 run_test 184b "Forbidden layout swap (will generate errors)"
10826
10827 test_184c() {
10828         check_swap_layouts_support && return 0
10829
10830         local dir0=$DIR/$tdir/$testnum
10831         mkdir -p $dir0 || error "creating dir $dir0"
10832
10833         local ref1=$dir0/ref1
10834         local ref2=$dir0/ref2
10835         local file1=$dir0/file1
10836         local file2=$dir0/file2
10837         # create a file large enough for the concurent test
10838         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10839         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10840         echo "ref file size: ref1($(stat -c %s $ref1))," \
10841              "ref2($(stat -c %s $ref2))"
10842
10843         cp $ref2 $file2
10844         dd if=$ref1 of=$file1 bs=16k &
10845         local DD_PID=$!
10846
10847         # Make sure dd starts to copy file
10848         while [ ! -f $file1 ]; do sleep 0.1; done
10849
10850         $LFS swap_layouts $file1 $file2
10851         local rc=$?
10852         wait $DD_PID
10853         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10854         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10855
10856         # how many bytes copied before swapping layout
10857         local copied=$(stat -c %s $file2)
10858         local remaining=$(stat -c %s $ref1)
10859         remaining=$((remaining - copied))
10860         echo "Copied $copied bytes before swapping layout..."
10861
10862         cmp -n $copied $file1 $ref2 | grep differ &&
10863                 error "Content mismatch [0, $copied) of ref2 and file1"
10864         cmp -n $copied $file2 $ref1 ||
10865                 error "Content mismatch [0, $copied) of ref1 and file2"
10866         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10867                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10868
10869         # clean up
10870         rm -f $ref1 $ref2 $file1 $file2
10871 }
10872 run_test 184c "Concurrent write and layout swap"
10873
10874 test_184d() {
10875         check_swap_layouts_support && return 0
10876         [ -z "$(which getfattr 2>/dev/null)" ] &&
10877                 skip "no getfattr command" && return 0
10878
10879         local file1=$DIR/$tdir/$tfile-1
10880         local file2=$DIR/$tdir/$tfile-2
10881         local file3=$DIR/$tdir/$tfile-3
10882         local lovea1
10883         local lovea2
10884
10885         mkdir -p $DIR/$tdir
10886         touch $file1 || error "create $file1 failed"
10887         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10888                 error "create $file2 failed"
10889         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10890                 error "create $file3 failed"
10891         lovea1=$($LFS getstripe $file1 | sed 1d)
10892
10893         $LFS swap_layouts $file2 $file3 ||
10894                 error "swap $file2 $file3 layouts failed"
10895         $LFS swap_layouts $file1 $file2 ||
10896                 error "swap $file1 $file2 layouts failed"
10897
10898         lovea2=$($LFS getstripe $file2 | sed 1d)
10899         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10900
10901         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10902         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10903 }
10904 run_test 184d "allow stripeless layouts swap"
10905
10906
10907 test_185() { # LU-2441
10908         # LU-3553 - no volatile file support in old servers
10909         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10910                 { skip "Need MDS version at least 2.3.60"; return 0; }
10911
10912         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10913         touch $DIR/$tdir/spoo
10914         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10915         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10916                 error "cannot create/write a volatile file"
10917         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10918                 error "FID is still valid after close"
10919
10920         multiop_bg_pause $DIR/$tdir vVw4096_c
10921         local multi_pid=$!
10922
10923         local OLD_IFS=$IFS
10924         IFS=":"
10925         local fidv=($fid)
10926         IFS=$OLD_IFS
10927         # assume that the next FID for this client is sequential, since stdout
10928         # is unfortunately eaten by multiop_bg_pause
10929         local n=$((${fidv[1]} + 1))
10930         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10931         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10932                 error "FID is missing before close"
10933         kill -USR1 $multi_pid
10934         # 1 second delay, so if mtime change we will see it
10935         sleep 1
10936         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10937         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10938 }
10939 run_test 185 "Volatile file support"
10940
10941 test_187a() {
10942         local dir0=$DIR/$tdir/$testnum
10943         mkdir -p $dir0 || error "creating dir $dir0"
10944
10945         local file=$dir0/file1
10946         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10947         local dv1=$($LFS data_version $file)
10948         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10949         local dv2=$($LFS data_version $file)
10950         [[ $dv1 != $dv2 ]] ||
10951                 error "data version did not change on write $dv1 == $dv2"
10952
10953         # clean up
10954         rm -f $file1
10955 }
10956 run_test 187a "Test data version change"
10957
10958 test_187b() {
10959         local dir0=$DIR/$tdir/$testnum
10960         mkdir -p $dir0 || error "creating dir $dir0"
10961
10962         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10963         [[ ${DV[0]} != ${DV[1]} ]] ||
10964                 error "data version did not change on write"\
10965                       " ${DV[0]} == ${DV[1]}"
10966
10967         # clean up
10968         rm -f $file1
10969 }
10970 run_test 187b "Test data version change on volatile file"
10971
10972 test_200() {
10973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10974         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
10975
10976         local POOL=${POOL:-cea1}
10977         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
10978         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
10979         # Pool OST targets
10980         local first_ost=0
10981         local last_ost=$(($OSTCOUNT - 1))
10982         local ost_step=2
10983         local ost_list=$(seq $first_ost $ost_step $last_ost)
10984         local ost_range="$first_ost $last_ost $ost_step"
10985         local test_path=$POOL_ROOT/$POOL_DIR_NAME
10986         local file_dir=$POOL_ROOT/file_tst
10987
10988         local rc=0
10989         while : ; do
10990                 # former test_200a test_200b
10991                 pool_add $POOL                          || { rc=$? ; break; }
10992                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
10993                 # former test_200c test_200d
10994                 mkdir -p $test_path
10995                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
10996                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
10997                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
10998                                                         || { rc=$? ; break; }
10999                 # former test_200e test_200f
11000                 local files=$((OSTCOUNT*3))
11001                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11002                                                         || { rc=$? ; break; }
11003                 pool_create_files $POOL $file_dir $files "$ost_list" \
11004                                                         || { rc=$? ; break; }
11005                 # former test_200g test_200h
11006                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11007                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11008
11009                 # former test_201a test_201b test_201c
11010                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11011
11012                 local f=$test_path/$tfile
11013                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11014                 pool_remove $POOL $f                    || { rc=$? ; break; }
11015                 break
11016         done
11017
11018         cleanup_pools
11019         return $rc
11020 }
11021 run_test 200 "OST pools"
11022
11023 # usage: default_attr <count | size | offset>
11024 default_attr() {
11025         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11026 }
11027
11028 # usage: check_default_stripe_attr
11029 check_default_stripe_attr() {
11030         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11031         case $1 in
11032         --stripe-count|--count)
11033                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11034         --stripe-size|--size)
11035                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11036         --stripe-index|--index)
11037                 EXPECTED=-1;;
11038         *)
11039                 error "unknown getstripe attr '$1'"
11040         esac
11041
11042         [ $ACTUAL != $EXPECTED ] &&
11043                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11044 }
11045
11046 test_204a() {
11047         test_mkdir -p $DIR/$tdir
11048         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11049
11050         check_default_stripe_attr --stripe-count
11051         check_default_stripe_attr --stripe-size
11052         check_default_stripe_attr --stripe-index
11053
11054         return 0
11055 }
11056 run_test 204a "Print default stripe attributes ================="
11057
11058 test_204b() {
11059         test_mkdir -p $DIR/$tdir
11060         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11061
11062         check_default_stripe_attr --stripe-size
11063         check_default_stripe_attr --stripe-index
11064
11065         return 0
11066 }
11067 run_test 204b "Print default stripe size and offset  ==========="
11068
11069 test_204c() {
11070         test_mkdir -p $DIR/$tdir
11071         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11072
11073         check_default_stripe_attr --stripe-count
11074         check_default_stripe_attr --stripe-index
11075
11076         return 0
11077 }
11078 run_test 204c "Print default stripe count and offset ==========="
11079
11080 test_204d() {
11081         test_mkdir -p $DIR/$tdir
11082         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11083
11084         check_default_stripe_attr --stripe-count
11085         check_default_stripe_attr --stripe-size
11086
11087         return 0
11088 }
11089 run_test 204d "Print default stripe count and size ============="
11090
11091 test_204e() {
11092         test_mkdir -p $DIR/$tdir
11093         $SETSTRIPE -d $DIR/$tdir
11094
11095         check_default_stripe_attr --stripe-count --raw
11096         check_default_stripe_attr --stripe-size --raw
11097         check_default_stripe_attr --stripe-index --raw
11098
11099         return 0
11100 }
11101 run_test 204e "Print raw stripe attributes ================="
11102
11103 test_204f() {
11104         test_mkdir -p $DIR/$tdir
11105         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11106
11107         check_default_stripe_attr --stripe-size --raw
11108         check_default_stripe_attr --stripe-index --raw
11109
11110         return 0
11111 }
11112 run_test 204f "Print raw stripe size and offset  ==========="
11113
11114 test_204g() {
11115         test_mkdir -p $DIR/$tdir
11116         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11117
11118         check_default_stripe_attr --stripe-count --raw
11119         check_default_stripe_attr --stripe-index --raw
11120
11121         return 0
11122 }
11123 run_test 204g "Print raw stripe count and offset ==========="
11124
11125 test_204h() {
11126         test_mkdir -p $DIR/$tdir
11127         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11128
11129         check_default_stripe_attr --stripe-count --raw
11130         check_default_stripe_attr --stripe-size --raw
11131
11132         return 0
11133 }
11134 run_test 204h "Print raw stripe count and size ============="
11135
11136 # Figure out which job scheduler is being used, if any,
11137 # or use a fake one
11138 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11139         JOBENV=SLURM_JOB_ID
11140 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11141         JOBENV=LSB_JOBID
11142 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11143         JOBENV=PBS_JOBID
11144 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11145         JOBENV=LOADL_STEP_ID
11146 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11147         JOBENV=JOB_ID
11148 else
11149         JOBENV=FAKE_JOBID
11150 fi
11151
11152 verify_jobstats() {
11153         local cmd=$1
11154         local target=$2
11155
11156         # clear old jobstats
11157         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11158         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11159
11160         # use a new JobID for this test, or we might see an old one
11161         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11162
11163         JOBVAL=${!JOBENV}
11164         log "Test: $cmd"
11165         log "Using JobID environment variable $JOBENV=$JOBVAL"
11166
11167         if [ $JOBENV = "FAKE_JOBID" ]; then
11168                 FAKE_JOBID=$JOBVAL $cmd
11169         else
11170                 $cmd
11171         fi
11172
11173         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11174                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11175                 do_facet $FACET lctl get_param mdt.*.job_stats |
11176                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11177         fi
11178         if [ "$target" = "ost" -o "$target" = "both" ]; then
11179                 FACET=ost1
11180                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11181                         grep $JOBVAL || error "No job stats found on OST $FACET"
11182         fi
11183 }
11184
11185 jobstats_set() {
11186         trap 0
11187         NEW_JOBENV=${1:-$OLD_JOBENV}
11188         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11189         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11190 }
11191
11192 test_205() { # Job stats
11193         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11194         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11195                 skip "Server doesn't support jobstats" && return 0
11196         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11197
11198         local cmd
11199         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11200         if [ $OLD_JOBENV != $JOBENV ]; then
11201                 jobstats_set $JOBENV
11202                 trap jobstats_set EXIT
11203         fi
11204
11205         # mkdir
11206         cmd="mkdir $DIR/$tfile"
11207         verify_jobstats "$cmd" "mdt"
11208         # rmdir
11209         cmd="rm -fr $DIR/$tfile"
11210         verify_jobstats "$cmd" "mdt"
11211         # mknod
11212         cmd="mknod $DIR/$tfile c 1 3"
11213         verify_jobstats "$cmd" "mdt"
11214         # unlink
11215         cmd="rm -f $DIR/$tfile"
11216         verify_jobstats "$cmd" "mdt"
11217         # open & close
11218         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11219         verify_jobstats "$cmd" "mdt"
11220         # setattr
11221         cmd="touch $DIR/$tfile"
11222         verify_jobstats "$cmd" "both"
11223         # write
11224         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11225         verify_jobstats "$cmd" "ost"
11226         # read
11227         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11228         verify_jobstats "$cmd" "ost"
11229         # truncate
11230         cmd="$TRUNCATE $DIR/$tfile 0"
11231         verify_jobstats "$cmd" "both"
11232         # rename
11233         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11234         verify_jobstats "$cmd" "mdt"
11235
11236         # cleanup
11237         rm -f $DIR/jobstats_test_rename
11238
11239         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11240 }
11241 run_test 205 "Verify job stats"
11242
11243 # LU-1480, LU-1773 and LU-1657
11244 test_206() {
11245         mkdir -p $DIR/$tdir
11246         $SETSTRIPE -c -1 $DIR/$tdir
11247 #define OBD_FAIL_LOV_INIT 0x1403
11248         $LCTL set_param fail_loc=0xa0001403
11249         $LCTL set_param fail_val=1
11250         touch $DIR/$tdir/$tfile || true
11251 }
11252 run_test 206 "fail lov_init_raid0() doesn't lbug"
11253
11254 test_207a() {
11255         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11256         local fsz=`stat -c %s $DIR/$tfile`
11257         cancel_lru_locks mdc
11258
11259         # do not return layout in getattr intent
11260 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11261         $LCTL set_param fail_loc=0x170
11262         local sz=`stat -c %s $DIR/$tfile`
11263
11264         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11265
11266         rm -rf $DIR/$tfile
11267 }
11268 run_test 207a "can refresh layout at glimpse"
11269
11270 test_207b() {
11271         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11272         local cksum=`md5sum $DIR/$tfile`
11273         local fsz=`stat -c %s $DIR/$tfile`
11274         cancel_lru_locks mdc
11275         cancel_lru_locks osc
11276
11277         # do not return layout in getattr intent
11278 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11279         $LCTL set_param fail_loc=0x171
11280
11281         # it will refresh layout after the file is opened but before read issues
11282         echo checksum is "$cksum"
11283         echo "$cksum" |md5sum -c --quiet || error "file differs"
11284
11285         rm -rf $DIR/$tfile
11286 }
11287 run_test 207b "can refresh layout at open"
11288
11289 test_208() {
11290         # FIXME: in this test suite, only RD lease is used. This is okay
11291         # for now as only exclusive open is supported. After generic lease
11292         # is done, this test suite should be revised. - Jinshan
11293
11294         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11295                 { skip "Need MDS version at least 2.4.52"; return 0; }
11296
11297         echo "==== test 1: verify get lease work"
11298         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11299
11300         echo "==== test 2: verify lease can be broken by upcoming open"
11301         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11302         local PID=$!
11303         sleep 1
11304
11305         $MULTIOP $DIR/$tfile oO_RDONLY:c
11306         kill -USR1 $PID && wait $PID || error "break lease error"
11307
11308         echo "==== test 3: verify lease can't be granted if an open already exists"
11309         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11310         local PID=$!
11311         sleep 1
11312
11313         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11314         kill -USR1 $PID && wait $PID || error "open file error"
11315
11316         echo "==== test 4: lease can sustain over recovery"
11317         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11318         PID=$!
11319         sleep 1
11320
11321         fail mds1
11322
11323         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11324
11325         echo "==== test 5: lease broken can't be regained by replay"
11326         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11327         PID=$!
11328         sleep 1
11329
11330         # open file to break lease and then recovery
11331         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11332         fail mds1
11333
11334         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11335
11336         rm -f $DIR/$tfile
11337 }
11338 run_test 208 "Exclusive open"
11339
11340 test_209() {
11341         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11342                 skip_env "must have disp_stripe" && return
11343
11344         touch $DIR/$tfile
11345         sync; sleep 5; sync;
11346
11347         echo 3 > /proc/sys/vm/drop_caches
11348         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11349
11350         # open/close 500 times
11351         for i in $(seq 500); do
11352                 cat $DIR/$tfile
11353         done
11354
11355         echo 3 > /proc/sys/vm/drop_caches
11356         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11357
11358         echo "before: $req_before, after: $req_after"
11359         [ $((req_after - req_before)) -ge 300 ] &&
11360                 error "open/close requests are not freed"
11361         return 0
11362 }
11363 run_test 209 "read-only open/close requests should be freed promptly"
11364
11365 test_212() {
11366         size=`date +%s`
11367         size=$((size % 8192 + 1))
11368         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11369         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11370         rm -f $DIR/f212 $DIR/f212.xyz
11371 }
11372 run_test 212 "Sendfile test ============================================"
11373
11374 test_213() {
11375         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11376         cancel_lru_locks osc
11377         lctl set_param fail_loc=0x8000040f
11378         # generate a read lock
11379         cat $DIR/$tfile > /dev/null
11380         # write to the file, it will try to cancel the above read lock.
11381         cat /etc/hosts >> $DIR/$tfile
11382 }
11383 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11384
11385 test_214() { # for bug 20133
11386         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11387         for (( i=0; i < 340; i++ )) ; do
11388                 touch $DIR/$tdir/d214c/a$i
11389         done
11390
11391         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11392         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11393         ls $DIR/d214c || error "ls $DIR/d214c failed"
11394         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11395         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11396 }
11397 run_test 214 "hash-indexed directory test - bug 20133"
11398
11399 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11400 create_lnet_proc_files() {
11401         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
11402         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11403
11404         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11405         rm -f "$TMP/lnet_$1.sys_tmp"
11406 }
11407
11408 # counterpart of create_lnet_proc_files
11409 remove_lnet_proc_files() {
11410         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11411 }
11412
11413 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11414 # 3rd arg as regexp for body
11415 check_lnet_proc_stats() {
11416         local l=$(cat "$TMP/lnet_$1" |wc -l)
11417         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11418
11419         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11420 }
11421
11422 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11423 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11424 # optional and can be regexp for 2nd line (lnet.routes case)
11425 check_lnet_proc_entry() {
11426         local blp=2          # blp stands for 'position of 1st line of body'
11427         [ -z "$5" ] || blp=3 # lnet.routes case
11428
11429         local l=$(cat "$TMP/lnet_$1" |wc -l)
11430         # subtracting one from $blp because the body can be empty
11431         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11432
11433         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11434                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11435
11436         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11437                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11438
11439         # bail out if any unexpected line happened
11440         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11441         [ "$?" != 0 ] || error "$2 misformatted"
11442 }
11443
11444 test_215() { # for bugs 18102, 21079, 21517
11445         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11446         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11447         local P='[1-9][0-9]*'           # positive numeric
11448         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11449         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11450         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11451         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11452
11453         local L1 # regexp for 1st line
11454         local L2 # regexp for 2nd line (optional)
11455         local BR # regexp for the rest (body)
11456
11457         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
11458         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11459         create_lnet_proc_files "stats"
11460         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
11461         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11462         remove_lnet_proc_files "stats"
11463
11464         # /proc/sys/lnet/routes should look like this:
11465         # Routing disabled/enabled
11466         # net hops priority state router
11467         # where net is a string like tcp0, hops > 0, priority >= 0,
11468         # state is up/down,
11469         # router is a string like 192.168.1.1@tcp2
11470         L1="^Routing (disabled|enabled)$"
11471         L2="^net +hops +priority +state +router$"
11472         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11473         create_lnet_proc_files "routes"
11474         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
11475         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11476         remove_lnet_proc_files "routes"
11477
11478         # /proc/sys/lnet/routers should look like this:
11479         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11480         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11481         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11482         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11483         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11484         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11485         create_lnet_proc_files "routers"
11486         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
11487         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11488         remove_lnet_proc_files "routers"
11489
11490         # /proc/sys/lnet/peers should look like this:
11491         # nid refs state last max rtr min tx min queue
11492         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11493         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11494         # numeric (0 or >0 or <0), queue >= 0.
11495         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11496         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11497         create_lnet_proc_files "peers"
11498         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
11499         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11500         remove_lnet_proc_files "peers"
11501
11502         # /proc/sys/lnet/buffers  should look like this:
11503         # pages count credits min
11504         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11505         L1="^pages +count +credits +min$"
11506         BR="^ +$N +$N +$I +$I$"
11507         create_lnet_proc_files "buffers"
11508         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
11509         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11510         remove_lnet_proc_files "buffers"
11511
11512         # /proc/sys/lnet/nis should look like this:
11513         # nid status alive refs peer rtr max tx min
11514         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11515         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11516         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11517         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11518         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11519         create_lnet_proc_files "nis"
11520         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
11521         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11522         remove_lnet_proc_files "nis"
11523
11524         # can we successfully write to /proc/sys/lnet/stats?
11525         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
11526         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11527 }
11528 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
11529
11530 test_216() { # bug 20317
11531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11532         remote_ost_nodsh && skip "remote OST with nodsh" && return
11533
11534         local node
11535         local facets=$(get_facets OST)
11536         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11537
11538         save_lustre_params client "osc.*.contention_seconds" > $p
11539         save_lustre_params $facets \
11540                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11541         save_lustre_params $facets \
11542                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11543         save_lustre_params $facets \
11544                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11545         clear_osc_stats
11546
11547         # agressive lockless i/o settings
11548         for node in $(osts_nodes); do
11549                 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'
11550         done
11551         lctl set_param -n osc.*.contention_seconds 60
11552
11553         $DIRECTIO write $DIR/$tfile 0 10 4096
11554         $CHECKSTAT -s 40960 $DIR/$tfile
11555
11556         # disable lockless i/o
11557         for node in $(osts_nodes); do
11558                 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'
11559         done
11560         lctl set_param -n osc.*.contention_seconds 0
11561         clear_osc_stats
11562
11563         dd if=/dev/zero of=$DIR/$tfile count=0
11564         $CHECKSTAT -s 0 $DIR/$tfile
11565
11566         restore_lustre_params <$p
11567         rm -f $p
11568         rm $DIR/$tfile
11569 }
11570 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11571
11572 test_217() { # bug 22430
11573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11574         local node
11575         local nid
11576
11577         for node in $(nodes_list); do
11578                 nid=$(host_nids_address $node $NETTYPE)
11579                 if [[ $nid = *-* ]] ; then
11580                         echo "lctl ping $nid@$NETTYPE"
11581                         lctl ping $nid@$NETTYPE
11582                 else
11583                         echo "skipping $node (no hyphen detected)"
11584                 fi
11585         done
11586 }
11587 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11588
11589 test_218() {
11590        # do directio so as not to populate the page cache
11591        log "creating a 10 Mb file"
11592        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11593        log "starting reads"
11594        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11595        log "truncating the file"
11596        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11597        log "killing dd"
11598        kill %+ || true # reads might have finished
11599        echo "wait until dd is finished"
11600        wait
11601        log "removing the temporary file"
11602        rm -rf $DIR/$tfile || error "tmp file removal failed"
11603 }
11604 run_test 218 "parallel read and truncate should not deadlock ======================="
11605
11606 test_219() {
11607         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11608         # write one partial page
11609         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11610         # set no grant so vvp_io_commit_write will do sync write
11611         $LCTL set_param fail_loc=0x411
11612         # write a full page at the end of file
11613         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11614
11615         $LCTL set_param fail_loc=0
11616         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11617         $LCTL set_param fail_loc=0x411
11618         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11619
11620         # LU-4201
11621         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11622         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11623 }
11624 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11625
11626 test_220() { #LU-325
11627         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11628         remote_ost_nodsh && skip "remote OST with nodsh" && return
11629         local OSTIDX=0
11630
11631         test_mkdir -p $DIR/$tdir
11632         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11633                 awk '{print $2}' | sed -e 's/_UUID$//')
11634
11635         # on the mdt's osc
11636         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11637         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11638                         osc.$mdtosc_proc1.prealloc_last_id)
11639         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11640                         osc.$mdtosc_proc1.prealloc_next_id)
11641
11642         $LFS df -i
11643
11644         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11645         #define OBD_FAIL_OST_ENOINO              0x229
11646         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11647         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11648         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11649
11650         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11651
11652         MDSOBJS=$((last_id - next_id))
11653         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11654
11655         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11656         echo "OST still has $count kbytes free"
11657
11658         echo "create $MDSOBJS files @next_id..."
11659         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11660
11661         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11662                         osc.$mdtosc_proc1.prealloc_last_id)
11663         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11664                         osc.$mdtosc_proc1.prealloc_next_id)
11665
11666         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11667         $LFS df -i
11668
11669         echo "cleanup..."
11670
11671         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11672         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11673
11674         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11675         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11676         echo "unlink $MDSOBJS files @$next_id..."
11677         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11678 }
11679 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11680
11681 test_221() {
11682         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11683         dd if=`which date` of=$MOUNT/date oflag=sync
11684         chmod +x $MOUNT/date
11685
11686         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11687         $LCTL set_param fail_loc=0x80001401
11688
11689         $MOUNT/date > /dev/null
11690         rm -f $MOUNT/date
11691 }
11692 run_test 221 "make sure fault and truncate race to not cause OOM"
11693
11694 test_222a () {
11695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11696        rm -rf $DIR/$tdir
11697        test_mkdir -p $DIR/$tdir
11698        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11699        createmany -o $DIR/$tdir/$tfile 10
11700        cancel_lru_locks mdc
11701        cancel_lru_locks osc
11702        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11703        $LCTL set_param fail_loc=0x31a
11704        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11705        $LCTL set_param fail_loc=0
11706        rm -r $DIR/$tdir
11707 }
11708 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11709
11710 test_222b () {
11711         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11712        rm -rf $DIR/$tdir
11713        test_mkdir -p $DIR/$tdir
11714        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11715        createmany -o $DIR/$tdir/$tfile 10
11716        cancel_lru_locks mdc
11717        cancel_lru_locks osc
11718        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11719        $LCTL set_param fail_loc=0x31a
11720        rm -r $DIR/$tdir || "AGL for rmdir failed"
11721        $LCTL set_param fail_loc=0
11722 }
11723 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11724
11725 test_223 () {
11726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11727        rm -rf $DIR/$tdir
11728        test_mkdir -p $DIR/$tdir
11729        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11730        createmany -o $DIR/$tdir/$tfile 10
11731        cancel_lru_locks mdc
11732        cancel_lru_locks osc
11733        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11734        $LCTL set_param fail_loc=0x31b
11735        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11736        $LCTL set_param fail_loc=0
11737        rm -r $DIR/$tdir
11738 }
11739 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11740
11741 test_224a() { # LU-1039, MRP-303
11742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11743         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11744         $LCTL set_param fail_loc=0x508
11745         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11746         $LCTL set_param fail_loc=0
11747         df $DIR
11748 }
11749 run_test 224a "Don't panic on bulk IO failure"
11750
11751 test_224b() { # LU-1039, MRP-303
11752         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11753         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11754         cancel_lru_locks osc
11755         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11756         $LCTL set_param fail_loc=0x515
11757         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11758         $LCTL set_param fail_loc=0
11759         df $DIR
11760 }
11761 run_test 224b "Don't panic on bulk IO failure"
11762
11763 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11764 test_225a () {
11765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11766         if [ -z ${MDSSURVEY} ]; then
11767               skip_env "mds-survey not found" && return
11768         fi
11769
11770         [ $MDSCOUNT -ge 2 ] &&
11771                 skip "skipping now for more than one MDT" && return
11772
11773        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11774             { skip "Need MDS version at least 2.2.51"; return; }
11775
11776        local mds=$(facet_host $SINGLEMDS)
11777        local target=$(do_nodes $mds 'lctl dl' | \
11778                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11779
11780        local cmd1="file_count=1000 thrhi=4"
11781        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11782        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11783        local cmd="$cmd1 $cmd2 $cmd3"
11784
11785        rm -f ${TMP}/mds_survey*
11786        echo + $cmd
11787        eval $cmd || error "mds-survey with zero-stripe failed"
11788        cat ${TMP}/mds_survey*
11789        rm -f ${TMP}/mds_survey*
11790 }
11791 run_test 225a "Metadata survey sanity with zero-stripe"
11792
11793 test_225b () {
11794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11795
11796         if [ -z ${MDSSURVEY} ]; then
11797               skip_env "mds-survey not found" && return
11798         fi
11799         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11800             { skip "Need MDS version at least 2.2.51"; return; }
11801
11802         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11803               skip_env "Need to mount OST to test" && return
11804         fi
11805
11806         [ $MDSCOUNT -ge 2 ] &&
11807                 skip "skipping now for more than one MDT" && return
11808        local mds=$(facet_host $SINGLEMDS)
11809        local target=$(do_nodes $mds 'lctl dl' | \
11810                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11811
11812        local cmd1="file_count=1000 thrhi=4"
11813        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11814        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11815        local cmd="$cmd1 $cmd2 $cmd3"
11816
11817        rm -f ${TMP}/mds_survey*
11818        echo + $cmd
11819        eval $cmd || error "mds-survey with stripe_count failed"
11820        cat ${TMP}/mds_survey*
11821        rm -f ${TMP}/mds_survey*
11822 }
11823 run_test 225b "Metadata survey sanity with stripe_count = 1"
11824
11825 mcreate_path2fid () {
11826         local mode=$1
11827         local major=$2
11828         local minor=$3
11829         local name=$4
11830         local desc=$5
11831         local path=$DIR/$tdir/$name
11832         local fid
11833         local rc
11834         local fid_path
11835
11836         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11837                 error "cannot create $desc"
11838
11839         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11840         rc=$?
11841         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11842
11843         fid_path=$($LFS fid2path $MOUNT $fid)
11844         rc=$?
11845         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11846
11847         [ "$path" == "$fid_path" ] ||
11848                 error "fid2path returned $fid_path, expected $path"
11849
11850         echo "pass with $path and $fid"
11851 }
11852
11853 test_226a () {
11854         rm -rf $DIR/$tdir
11855         mkdir -p $DIR/$tdir
11856
11857         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11858         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11859         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11860         mcreate_path2fid 0040666 0 0 dir "directory"
11861         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11862         mcreate_path2fid 0100666 0 0 file "regular file"
11863         mcreate_path2fid 0120666 0 0 link "symbolic link"
11864         mcreate_path2fid 0140666 0 0 sock "socket"
11865 }
11866 run_test 226a "call path2fid and fid2path on files of all type"
11867
11868 test_226b () {
11869         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11870         rm -rf $DIR/$tdir
11871         local MDTIDX=1
11872
11873         mkdir -p $DIR/$tdir
11874         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11875                 error "create remote directory failed"
11876         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11877         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11878                                 "character special file (null)"
11879         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11880                                 "character special file (no device)"
11881         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11882         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11883                                 "block special file (loop)"
11884         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11885         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11886         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11887 }
11888 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11889
11890 # LU-1299 Executing or running ldd on a truncated executable does not
11891 # cause an out-of-memory condition.
11892 test_227() {
11893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11894         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
11895         dd if=$(which date) of=$MOUNT/date bs=1k count=1
11896         chmod +x $MOUNT/date
11897
11898         $MOUNT/date > /dev/null
11899         ldd $MOUNT/date > /dev/null
11900         rm -f $MOUNT/date
11901 }
11902 run_test 227 "running truncated executable does not cause OOM"
11903
11904 # LU-1512 try to reuse idle OI blocks
11905 test_228a() {
11906         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11907         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11908                 skip "non-ldiskfs backend" && return
11909
11910         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11911         local myDIR=$DIR/$tdir
11912
11913         mkdir -p $myDIR
11914         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11915         $LCTL set_param fail_loc=0x80001002
11916         createmany -o $myDIR/t- 10000
11917         $LCTL set_param fail_loc=0
11918         # The guard is current the largest FID holder
11919         touch $myDIR/guard
11920         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11921                     tr -d '[')
11922         local IDX=$(($SEQ % 64))
11923
11924         do_facet $SINGLEMDS sync
11925         # Make sure journal flushed.
11926         sleep 6
11927         local blk1=$(do_facet $SINGLEMDS \
11928                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11929                      grep Blockcount | awk '{print $4}')
11930
11931         # Remove old files, some OI blocks will become idle.
11932         unlinkmany $myDIR/t- 10000
11933         # Create new files, idle OI blocks should be reused.
11934         createmany -o $myDIR/t- 2000
11935         do_facet $SINGLEMDS sync
11936         # Make sure journal flushed.
11937         sleep 6
11938         local blk2=$(do_facet $SINGLEMDS \
11939                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11940                      grep Blockcount | awk '{print $4}')
11941
11942         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11943 }
11944 run_test 228a "try to reuse idle OI blocks"
11945
11946 test_228b() {
11947         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11948         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11949                 skip "non-ldiskfs backend" && return
11950
11951         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11952         local myDIR=$DIR/$tdir
11953
11954         mkdir -p $myDIR
11955         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11956         $LCTL set_param fail_loc=0x80001002
11957         createmany -o $myDIR/t- 10000
11958         $LCTL set_param fail_loc=0
11959         # The guard is current the largest FID holder
11960         touch $myDIR/guard
11961         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11962                     tr -d '[')
11963         local IDX=$(($SEQ % 64))
11964
11965         do_facet $SINGLEMDS sync
11966         # Make sure journal flushed.
11967         sleep 6
11968         local blk1=$(do_facet $SINGLEMDS \
11969                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11970                      grep Blockcount | awk '{print $4}')
11971
11972         # Remove old files, some OI blocks will become idle.
11973         unlinkmany $myDIR/t- 10000
11974
11975         # stop the MDT
11976         stop $SINGLEMDS || error "Fail to stop MDT."
11977         # remount the MDT
11978         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11979
11980         df $MOUNT || error "Fail to df."
11981         # Create new files, idle OI blocks should be reused.
11982         createmany -o $myDIR/t- 2000
11983         do_facet $SINGLEMDS sync
11984         # Make sure journal flushed.
11985         sleep 6
11986         local blk2=$(do_facet $SINGLEMDS \
11987                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11988                      grep Blockcount | awk '{print $4}')
11989
11990         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11991 }
11992 run_test 228b "idle OI blocks can be reused after MDT restart"
11993
11994 #LU-1881
11995 test_228c() {
11996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11997         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11998                 skip "non-ldiskfs backend" && return
11999
12000         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12001         local myDIR=$DIR/$tdir
12002
12003         mkdir -p $myDIR
12004         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12005         $LCTL set_param fail_loc=0x80001002
12006         # 20000 files can guarantee there are index nodes in the OI file
12007         createmany -o $myDIR/t- 20000
12008         $LCTL set_param fail_loc=0
12009         # The guard is current the largest FID holder
12010         touch $myDIR/guard
12011         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12012                     tr -d '[')
12013         local IDX=$(($SEQ % 64))
12014
12015         do_facet $SINGLEMDS sync
12016         # Make sure journal flushed.
12017         sleep 6
12018         local blk1=$(do_facet $SINGLEMDS \
12019                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12020                      grep Blockcount | awk '{print $4}')
12021
12022         # Remove old files, some OI blocks will become idle.
12023         unlinkmany $myDIR/t- 20000
12024         rm -f $myDIR/guard
12025         # The OI file should become empty now
12026
12027         # Create new files, idle OI blocks should be reused.
12028         createmany -o $myDIR/t- 2000
12029         do_facet $SINGLEMDS sync
12030         # Make sure journal flushed.
12031         sleep 6
12032         local blk2=$(do_facet $SINGLEMDS \
12033                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12034                      grep Blockcount | awk '{print $4}')
12035
12036         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12037 }
12038 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12039
12040 test_229() { # LU-2482, LU-3448
12041         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12042                 skip "No HSM support on MDS of $(get_lustre_version)," \
12043                          "need 2.4.53 at least" && return
12044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12045         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12046
12047         rm -f $DIR/$tfile
12048
12049         # Create a file with a released layout and stripe count 2.
12050         $MULTIOP $DIR/$tfile H2c ||
12051                 error "failed to create file with released layout"
12052
12053         $GETSTRIPE -v $DIR/$tfile
12054
12055         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12056         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12057
12058         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12059         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12060         stat $DIR/$tfile || error "failed to stat released file"
12061
12062         chown $RUNAS_ID $DIR/$tfile ||
12063                 error "chown $RUNAS_ID $DIR/$tfile failed"
12064
12065         chgrp $RUNAS_ID $DIR/$tfile ||
12066                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12067
12068         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12069         rm $DIR/$tfile || error "failed to remove released file"
12070 }
12071 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12072
12073 test_230a() {
12074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12075         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12076         local MDTIDX=1
12077
12078         mkdir -p $DIR/$tdir/test_230_local
12079         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12080         [ $mdt_idx -ne 0 ] &&
12081                 error "create local directory on wrong MDT $mdt_idx"
12082
12083         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12084                         error "create remote directory failed"
12085         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12086         [ $mdt_idx -ne $MDTIDX ] &&
12087                 error "create remote directory on wrong MDT $mdt_idx"
12088
12089         createmany -o $DIR/$tdir/test_230/t- 10 ||
12090                 error "create files on remote directory failed"
12091         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12092         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12093         rm -r $DIR/$tdir || error "unlink remote directory failed"
12094 }
12095 run_test 230a "Create remote directory and files under the remote directory"
12096
12097 test_230b() {
12098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12099         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12100         local MDTIDX=1
12101         local mdt_index
12102         local i
12103         local file
12104         local pid
12105         local stripe_count
12106         local migrate_dir=$DIR/$tdir/migrate_dir
12107         local other_dir=$DIR/$tdir/other_dir
12108
12109         mkdir -p $migrate_dir
12110         mkdir -p $other_dir
12111         for ((i=0; i<10; i++)); do
12112                 mkdir -p $migrate_dir/dir_${i}
12113                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12114                         error "create files under remote dir failed $i"
12115         done
12116
12117         cp /etc/passwd $migrate_dir/$tfile
12118         cp /etc/passwd $other_dir/$tfile
12119         chattr +SAD $migrate_dir
12120         chattr +SAD $migrate_dir/$tfile
12121
12122         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12123         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12124         local old_dir_mode=$(stat -c%f $migrate_dir)
12125         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12126
12127         mkdir -p $migrate_dir/dir_default_stripe2
12128         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12129         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12130
12131         mkdir -p $other_dir
12132         ln $migrate_dir/$tfile $other_dir/luna
12133         ln $migrate_dir/$tfile $migrate_dir/sofia
12134         ln $other_dir/$tfile $migrate_dir/david
12135         ln -s $migrate_dir/$tfile $other_dir/zachary
12136         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12137         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12138
12139         $LFS mv -v -M $MDTIDX $migrate_dir ||
12140                         error "migrate remote dir error"
12141
12142         echo "migratate to MDT1, then checking.."
12143         for ((i=0; i<10; i++)); do
12144                 for file in $(find $migrate_dir/dir_${i}); do
12145                         mdt_index=$($LFS getstripe -M $file)
12146                         [ $mdt_index == $MDTIDX ] ||
12147                                 error "$file is not on MDT${MDTIDX}"
12148                 done
12149         done
12150
12151         # the multiple link file should still in MDT0
12152         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12153         [ $mdt_index == 0 ] ||
12154                 error "$file is not on MDT${MDTIDX}"
12155
12156         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12157         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12158                 error " expect $old_dir_flag get $new_dir_flag"
12159
12160         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12161         [ "$old_file_flag" = "$new_file_flag" ] ||
12162                 error " expect $old_file_flag get $new_file_flag"
12163
12164         local new_dir_mode=$(stat -c%f $migrate_dir)
12165         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12166                 error "expect mode $old_dir_mode get $new_dir_mode"
12167
12168         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12169         [ "$old_file_mode" = "$new_file_mode" ] ||
12170                 error "expect mode $old_file_mode get $new_file_mode"
12171
12172         diff /etc/passwd $migrate_dir/$tfile ||
12173                 error "$tfile different after migration"
12174
12175         diff /etc/passwd $other_dir/luna ||
12176                 error "luna different after migration"
12177
12178         diff /etc/passwd $migrate_dir/sofia ||
12179                 error "sofia different after migration"
12180
12181         diff /etc/passwd $migrate_dir/david ||
12182                 error "david different after migration"
12183
12184         diff /etc/passwd $other_dir/zachary ||
12185                 error "zachary different after migration"
12186
12187         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12188                 error "${tfile}_ln different after migration"
12189
12190         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12191                 error "${tfile}_ln_other different after migration"
12192
12193         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12194         [ $stripe_count = 2 ] ||
12195                         error "dir strpe_count $d != 2 after migration."
12196
12197         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12198         [ $stripe_count = 2 ] ||
12199                         error "file strpe_count $d != 2 after migration."
12200
12201         #migrate back to MDT0
12202         MDTIDX=0
12203         $LFS mv -v -M $MDTIDX $migrate_dir ||
12204                         error "migrate remote dir error"
12205
12206         echo "migrate back to MDT0, checking.."
12207         for file in $(find $migrate_dir); do
12208                 mdt_index=$($LFS getstripe -M $file)
12209                 [ $mdt_index == $MDTIDX ] ||
12210                         error "$file is not on MDT${MDTIDX}"
12211         done
12212
12213         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12214         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12215                 error " expect $old_dir_flag get $new_dir_flag"
12216
12217         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12218         [ "$old_file_flag" = "$new_file_flag" ] ||
12219                 error " expect $old_file_flag get $new_file_flag"
12220
12221         local new_dir_mode=$(stat -c%f $migrate_dir)
12222         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12223                 error "expect mode $old_dir_mode get $new_dir_mode"
12224
12225         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12226         [ "$old_file_mode" = "$new_file_mode" ] ||
12227                 error "expect mode $old_file_mode get $new_file_mode"
12228
12229         diff /etc/passwd ${migrate_dir}/$tfile ||
12230                 error "$tfile different after migration"
12231
12232         diff /etc/passwd ${other_dir}/luna ||
12233                 error "luna different after migration"
12234
12235         diff /etc/passwd ${migrate_dir}/sofia ||
12236                 error "sofia different after migration"
12237
12238         diff /etc/passwd ${other_dir}/zachary ||
12239                 error "zachary different after migration"
12240
12241         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12242                 error "${tfile}_ln different after migration"
12243
12244         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12245                 error "${tfile}_ln_other different after migration"
12246
12247         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12248         [ $stripe_count = 2 ] ||
12249                 error "dir strpe_count $d != 2 after migration."
12250
12251         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12252         [ $stripe_count = 2 ] ||
12253                 error "file strpe_count $d != 2 after migration."
12254
12255         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12256 }
12257 run_test 230b "migrate directory"
12258
12259 test_230c() {
12260         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12261         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12262         local MDTIDX=1
12263         local mdt_index
12264         local file
12265
12266         #If migrating directory fails in the middle, all entries of
12267         #the directory is still accessiable.
12268         mkdir -p $DIR/$tdir
12269         stat $DIR/$tdir
12270         createmany -o $DIR/$tdir/f 10 ||
12271                 error "create files under ${tdir} failed"
12272
12273         #failed after migrating 5 entries
12274         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12275         do_facet mds1 lctl set_param fail_loc=0x20001801
12276         do_facet mds1 lctl  set_param fail_val=5
12277         local t=`ls $DIR/$tdir | wc -l`
12278         $LFS mv -M $MDTIDX $DIR/$tdir &&
12279                 error "migrate should failed after 5 entries"
12280         local u=`ls $DIR/$tdir | wc -l`
12281         [ "$u" == "$t" ] || error "$u != $t during migration"
12282
12283         for file in $(find $DIR/$tdir); do
12284                 stat $file || error "stat $file failed"
12285         done
12286
12287         do_facet mds1 lctl set_param fail_loc=0
12288         do_facet mds1 lctl set_param fail_val=0
12289
12290         $LFS mv -M $MDTIDX $DIR/$tdir ||
12291                 error "migrate open files should failed with open files"
12292
12293         echo "Finish migration, then checking.."
12294         for file in $(find $DIR/$tdir); do
12295                 mdt_index=$($LFS getstripe -M $file)
12296                 [ $mdt_index == $MDTIDX ] ||
12297                         error "$file is not on MDT${MDTIDX}"
12298         done
12299
12300         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12301 }
12302 run_test 230c "check directory accessiblity if migration is failed"
12303
12304 test_230d() {
12305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12306         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12307         local MDTIDX=1
12308         local mdt_index
12309         local i
12310         local j
12311
12312         mkdir -p $DIR/$tdir
12313
12314         for ((i=0; i<100; i++)); do
12315                 mkdir -p $DIR/$tdir/dir_${i}
12316                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12317                         error "create files under remote dir failed $i"
12318         done
12319
12320         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12321
12322         echo "Finish migration, then checking.."
12323         for file in $(find $DIR/$tdir); do
12324                 mdt_index=$($LFS getstripe -M $file)
12325                 [ $mdt_index == $MDTIDX ] ||
12326                         error "$file is not on MDT${MDTIDX}"
12327         done
12328
12329         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12330 }
12331 run_test 230d "check migrate big directory"
12332
12333 test_231a()
12334 {
12335         # For simplicity this test assumes that max_pages_per_rpc
12336         # is the same across all OSCs
12337         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12338         local bulk_size=$((max_pages * 4096))
12339
12340         mkdir -p $DIR/$tdir
12341
12342         # clear the OSC stats
12343         $LCTL set_param osc.*.stats=0 &>/dev/null
12344
12345         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12346         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12347                 oflag=direct &>/dev/null || error "dd failed"
12348
12349         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12350         if [ x$nrpcs != "x1" ]; then
12351                 error "found $nrpc ost_write RPCs, not 1 as expected"
12352         fi
12353
12354         # Drop the OSC cache, otherwise we will read from it
12355         cancel_lru_locks osc
12356
12357         # clear the OSC stats
12358         $LCTL set_param osc.*.stats=0 &>/dev/null
12359
12360         # Client reads $bulk_size.
12361         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12362                 iflag=direct &>/dev/null || error "dd failed"
12363
12364         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12365         if [ x$nrpcs != "x1" ]; then
12366                 error "found $nrpc ost_read RPCs, not 1 as expected"
12367         fi
12368 }
12369 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12370
12371 test_231b() {
12372         mkdir -p $DIR/$tdir
12373         local i
12374         for i in {0..1023}; do
12375                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12376                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12377                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12378         done
12379         sync
12380 }
12381 run_test 231b "must not assert on fully utilized OST request buffer"
12382
12383 test_232() {
12384         mkdir -p $DIR/$tdir
12385         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12386         $LCTL set_param fail_loc=0x31c
12387
12388         # ignore dd failure
12389         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12390
12391         $LCTL set_param fail_loc=0
12392         umount_client $MOUNT || error "umount failed"
12393         mount_client $MOUNT || error "mount failed"
12394 }
12395 run_test 232 "failed lock should not block umount"
12396
12397 test_233a() {
12398         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12399         { skip "Need MDS version at least 2.3.64"; return; }
12400
12401         local fid=$($LFS path2fid $MOUNT)
12402         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12403                 error "cannot access $MOUNT using its FID '$fid'"
12404 }
12405 run_test 233a "checking that OBF of the FS root succeeds"
12406
12407 test_233b() {
12408         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12409         { skip "Need MDS version at least 2.5.90"; return; }
12410
12411         local fid=$($LFS path2fid $MOUNT/.lustre)
12412         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12413                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12414
12415         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12416         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12417                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12418 }
12419 run_test 233b "checking that OBF of the FS .lustre succeeds"
12420
12421 test_234() {
12422         local p="$TMP/sanityN-$TESTNAME.parameters"
12423         save_lustre_params client "llite.*.xattr_cache" > $p
12424         lctl set_param llite.*.xattr_cache 1 ||
12425                 { skip "xattr cache is not supported"; return 0; }
12426
12427         mkdir -p $DIR/$tdir || error "mkdir failed"
12428         touch $DIR/$tdir/$tfile || error "touch failed"
12429         # OBD_FAIL_LLITE_XATTR_ENOMEM
12430         $LCTL set_param fail_loc=0x1405
12431         if [ ! -f /etc/SuSE-release ]; then
12432                 # attr pre-2.4.44-7 had a bug with rc
12433                 # LU-3703 - SLES clients have older attr
12434                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12435                         error "getfattr should have failed with ENOMEM"
12436         fi
12437         $LCTL set_param fail_loc=0x0
12438         rm -rf $DIR/$tdir
12439
12440         restore_lustre_params < $p
12441         rm -f $p
12442 }
12443 run_test 234 "xattr cache should not crash on ENOMEM"
12444
12445 test_235() {
12446         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12447                 skip "Need MDS version at least 2.4.52" && return
12448         flock_deadlock $DIR/$tfile
12449         local RC=$?
12450         case $RC in
12451                 0)
12452                 ;;
12453                 124) error "process hangs on a deadlock"
12454                 ;;
12455                 *) error "error executing flock_deadlock $DIR/$tfile"
12456                 ;;
12457         esac
12458 }
12459 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12460
12461 #LU-2935
12462 test_236() {
12463         check_swap_layouts_support && return 0
12464         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12465
12466         local ref1=/etc/passwd
12467         local ref2=/etc/group
12468         local file1=$DIR/$tdir/f1
12469         local file2=$DIR/$tdir/f2
12470
12471         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12472         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12473         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12474         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12475         local fd=$(free_fd)
12476         local cmd="exec $fd<>$file2"
12477         eval $cmd
12478         rm $file2
12479         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12480                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12481         cmd="exec $fd>&-"
12482         eval $cmd
12483         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12484
12485         #cleanup
12486         rm -rf $DIR/$tdir
12487 }
12488 run_test 236 "Layout swap on open unlinked file"
12489
12490 # test to verify file handle related system calls
12491 # (name_to_handle_at/open_by_handle_at)
12492 # The new system calls are supported in glibc >= 2.14.
12493
12494 test_237() {
12495         echo "Test file_handle syscalls" > $DIR/$tfile ||
12496                 error "write failed"
12497         check_fhandle_syscalls $DIR/$tfile ||
12498                 error "check_fhandle_syscalls failed"
12499 }
12500 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12501
12502 # LU-4659 linkea consistency
12503 test_238() {
12504         local server_version=$(lustre_version_code $SINGLEMDS)
12505
12506         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12507                 [[ $server_version -gt $(version_code 2.5.1) &&
12508                    $server_version -lt $(version_code 2.5.50) ]] ||
12509                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12510
12511         touch $DIR/$tfile
12512         ln $DIR/$tfile $DIR/$tfile.lnk
12513         touch $DIR/$tfile.new
12514         mv $DIR/$tfile.new $DIR/$tfile
12515         local fid1=$(lfs path2fid $DIR/$tfile)
12516         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12517         local path1=$(lfs fid2path $FSNAME $fid1)
12518         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12519         local path2=$(lfs fid2path $FSNAME $fid2)
12520         [ $tfile.lnk == $path2 ] ||
12521                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12522         rm -f $DIR/$tfile*
12523 }
12524 run_test 238 "Verify linkea consistency"
12525
12526 test_239() {
12527         local list=$(comma_list $(mdts_nodes))
12528
12529         mkdir -p $DIR/$tdir
12530         createmany -o $DIR/$tdir/f- 5000
12531         unlinkmany $DIR/$tdir/f- 5000
12532         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12533         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12534                         osc.*MDT*.sync_in_flight" | calc_sum)
12535         [ "$changes" -eq 0 ] || error "$changes not synced"
12536 }
12537 run_test 239 "osp_sync test"
12538
12539 test_240() {
12540         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12541
12542         mkdir -p $DIR/$tdir
12543
12544         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12545                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12546         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12547                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12548
12549         umount_client $MOUNT || error "umount failed"
12550         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12551         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12552         mount_client $MOUNT || error "failed to mount client"
12553
12554         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12555         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12556 }
12557 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12558
12559 cleanup_test_300() {
12560         trap 0
12561         umask $SAVE_UMASK
12562 }
12563 test_striped_dir() {
12564         local mdt_index=$1
12565         local stripe_count
12566         local stripe_index
12567
12568         mkdir -p $DIR/$tdir
12569
12570         SAVE_UMASK=$(umask)
12571         trap cleanup_test_300 RETURN EXIT
12572
12573         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
12574                                                 $DIR/$tdir/striped_dir ||
12575                 error "set striped dir error"
12576
12577         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
12578         [ "$mode" = "755" ] || error "expect 755 got $mode"
12579
12580         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12581         if [ "$stripe_count" != "2" ]; then
12582                 error "stripe_count is $stripe_count, expect 2"
12583         fi
12584
12585         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12586         if [ "$stripe_index" != "$mdt_index" ]; then
12587                 error "stripe_index is $stripe_index, expect $mdt_index"
12588         fi
12589
12590         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12591                 error "nlink error after create striped dir"
12592
12593         mkdir $DIR/$tdir/striped_dir/a
12594         mkdir $DIR/$tdir/striped_dir/b
12595
12596         stat $DIR/$tdir/striped_dir/a ||
12597                 error "create dir under striped dir failed"
12598         stat $DIR/$tdir/striped_dir/b ||
12599                 error "create dir under striped dir failed"
12600
12601         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12602                 error "nlink error after mkdir"
12603
12604         rmdir $DIR/$tdir/striped_dir/a
12605         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12606                 error "nlink error after rmdir"
12607
12608         rmdir $DIR/$tdir/striped_dir/b
12609         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12610                 error "nlink error after rmdir"
12611
12612         rmdir $DIR/$tdir/striped_dir ||
12613                 error "rmdir striped dir error"
12614
12615         cleanup_test_300
12616
12617         true
12618 }
12619
12620 test_300a() {
12621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12622         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12623
12624         test_striped_dir 0 || error "failed on striped dir on MDT0"
12625         test_striped_dir 1 || error "failed on striped dir on MDT0"
12626 }
12627 run_test 300a "basic striped dir sanity test"
12628
12629 test_300b() {
12630         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12631         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12632         local i
12633         local mtime1
12634         local mtime2
12635         local mtime3
12636
12637         test_mkdir $DIR/$tdir || error "mkdir fail"
12638         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12639                 error "set striped dir error"
12640         for ((i=0; i<10; i++)); do
12641                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12642                 sleep 1
12643                 touch $DIR/$tdir/striped_dir/file_$i ||
12644                                         error "touch error $i"
12645                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12646                 [ $mtime1 -eq $mtime2 ] &&
12647                         error "mtime not change after create"
12648                 sleep 1
12649                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12650                                         error "unlink error $i"
12651                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12652                 [ $mtime2 -eq $mtime3 ] &&
12653                         error "mtime did not change after unlink"
12654         done
12655         true
12656 }
12657 run_test 300b "check ctime/mtime for striped dir"
12658
12659 test_300c() {
12660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12661         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12662         local file_count
12663
12664         mkdir -p $DIR/$tdir
12665         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12666                 error "set striped dir error"
12667
12668         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12669                 error "chown striped dir failed"
12670
12671         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12672                 error "create 5k files failed"
12673
12674         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12675
12676         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12677
12678         rm -rf $DIR/$tdir
12679 }
12680 run_test 300c "chown && check ls under striped directory"
12681
12682 test_300d() {
12683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12684         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12685         local stripe_count
12686         local file
12687
12688         mkdir -p $DIR/$tdir
12689         $SETSTRIPE -c 2 $DIR/$tdir
12690
12691         #local striped directory
12692         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12693                 error "set striped dir error"
12694         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12695                 error "create 10 files failed"
12696
12697         #remote striped directory
12698         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12699                 error "set striped dir error"
12700         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12701                 error "create 10 files failed"
12702
12703         for file in $(find $DIR/$tdir); do
12704                 stripe_count=$($GETSTRIPE -c $file)
12705                 [ $stripe_count -eq 2 ] ||
12706                         error "wrong stripe $stripe_count for $file"
12707         done
12708
12709         rm -rf $DIR/$tdir
12710 }
12711 run_test 300d "check default stripe under striped directory"
12712
12713 test_300e() {
12714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12715         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12716         local stripe_count
12717         local file
12718
12719         mkdir -p $DIR/$tdir
12720
12721         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12722                 error "set striped dir error"
12723
12724         touch $DIR/$tdir/striped_dir/a
12725         touch $DIR/$tdir/striped_dir/b
12726         touch $DIR/$tdir/striped_dir/c
12727
12728         mkdir $DIR/$tdir/striped_dir/dir_a
12729         mkdir $DIR/$tdir/striped_dir/dir_b
12730         mkdir $DIR/$tdir/striped_dir/dir_c
12731
12732         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12733                 error "set striped dir under striped dir error"
12734
12735         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12736                 error "set striped dir under striped dir error"
12737
12738         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12739                 error "set striped dir under striped dir error"
12740
12741         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12742                 error "rename file under striped dir should fail"
12743
12744         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12745                 error "rename dir under striped dir should fail"
12746
12747         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12748                 error "rename dir under different stripes should fail"
12749
12750         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12751                 error "rename file under striped dir should succeed"
12752
12753         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12754                 error "rename dir under striped dir should succeed"
12755
12756         rm -rf $DIR/$tdir
12757 }
12758 run_test 300e "check rename under striped directory"
12759
12760 test_300f() {
12761         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12762         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12763         local stripe_count
12764         local file
12765
12766         rm -rf $DIR/$tdir
12767         mkdir -p $DIR/$tdir
12768
12769         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12770                 error "set striped dir error"
12771
12772         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12773                 error "set striped dir error"
12774
12775         touch $DIR/$tdir/striped_dir/a
12776         mkdir $DIR/$tdir/striped_dir/dir_a
12777         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12778                 error "create striped dir under striped dir fails"
12779
12780         touch $DIR/$tdir/striped_dir1/b
12781         mkdir $DIR/$tdir/striped_dir1/dir_b
12782         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12783                 error "create striped dir under striped dir fails"
12784
12785         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12786                 error "rename file under different striped dir should fail"
12787
12788         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12789                 error "rename dir under different striped dir should fail"
12790
12791         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12792                 error "rename striped dir under diff striped dir should fail"
12793
12794         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12795                 error "rename file under diff striped dirs fails"
12796
12797         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12798                 error "rename dir under diff striped dirs fails"
12799
12800         rm -rf $DIR/$tdir
12801 }
12802 run_test 300f "check rename cross striped directory"
12803
12804 test_300g() {
12805         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12806         local stripe_count
12807         local dir
12808
12809         mkdir $DIR/$tdir
12810         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
12811                                         $DIR/$tdir/striped_dir ||
12812                 error "set striped dir error"
12813
12814         $LFS setdirstripe -D -c $MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12815                 error "set default stripe on striped dir error"
12816
12817         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/striped_dir)
12818         [ $stripe_count -eq $MDSCOUNT ] ||
12819                 error "default stripe wrong expect $MDSCOUNT get $stripe_count"
12820
12821         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12822
12823         for dir in $(find $DIR/$tdir/striped_dir/*); do
12824                 stripe_count=$($LFS getdirstripe -c $dir)
12825                 [ $stripe_count -eq $MDSCOUNT ] ||
12826                         error "expect $MDSCOUNT get $stripe_count for $dir"
12827         done
12828
12829         rmdir $DIR/$tdir/striped_dir/* || error "rmdir1 failed"
12830         #change default stripe count to 2
12831         $LFS setdirstripe -D -c 2 -t all_char $DIR/$tdir/striped_dir ||
12832                 error "set default stripe on striped dir error"
12833
12834         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12835
12836         rmdir $DIR/$tdir/striped_dir/* || error "rmdir2 failed"
12837
12838         #change default stripe count to 1
12839         $LFS setdirstripe -D -c 1 -t all_char $DIR/$tdir/striped_dir ||
12840                 error "set default stripe on striped dir error"
12841
12842         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12843         for dir in $(find $DIR/$tdir/striped_dir/*); do
12844                 stripe_count=$($LFS getdirstripe -c $dir)
12845                 [ $stripe_count -eq 1 ] ||
12846                         error "expect 1 get $stripe_count for $dir"
12847         done
12848         rmdir $DIR/$tdir/striped_dir/* || error "rmdir3 failed"
12849 }
12850 run_test 300g "check default striped directory for striped directory"
12851
12852 test_300h() {
12853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12854         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12855         local stripe_count
12856         local file
12857
12858         mkdir $DIR/$tdir
12859
12860         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12861                 error "set striped dir error"
12862
12863         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
12864                 error "create files under striped dir failed"
12865
12866         # unfortunately, we need to umount to clear dir layout cache for now
12867         # once we fully implement dir layout, we can drop this
12868         umount_client $MOUNT || error "umount failed"
12869         mount_client $MOUNT || error "mount failed"
12870
12871         #set the stripe to be unknown hash type
12872         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
12873         $LCTL set_param fail_loc=0x1901
12874         for ((i = 0; i < 10; i++)); do
12875                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
12876                         error "stat f-$i failed"
12877                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
12878         done
12879
12880         touch $DIR/$tdir/striped_dir/f0 &&
12881                 error "create under striped dir with unknown hash should fail"
12882
12883         $LCTL set_param fail_loc=0
12884
12885         umount_client $MOUNT || error "umount failed"
12886         mount_client $MOUNT || error "mount failed"
12887
12888         return 0
12889 }
12890 run_test 300h "client handle unknown hash type striped directory"
12891
12892 test_400a() { # LU-1606, was conf-sanity test_74
12893         local extra_flags=''
12894         local out=$TMP/$tfile
12895         local prefix=/usr/include/lustre
12896         local prog
12897
12898         if ! which $CC > /dev/null 2>&1; then
12899                 skip_env "$CC is not installed"
12900                 return 0
12901         fi
12902
12903         if ! [[ -d $prefix ]]; then
12904                 # Assume we're running in tree and fixup the include path.
12905                 extra_flags+=" -I$LUSTRE/../libcfs/include"
12906                 extra_flags+=" -I$LUSTRE/include"
12907                 extra_flags+=" -L$LUSTRE/utils"
12908         fi
12909
12910         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
12911                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
12912                         error "client api broken"
12913         done
12914 }
12915 run_test 400a "Lustre client api program can compile and link"
12916
12917 test_400b() { # LU-1606, LU-5011
12918         local header
12919         local out=$TMP/$tfile
12920         local prefix=/usr/include/lustre
12921
12922         # We use a hard coded prefix so that this test will not fail
12923         # when run in tree. There are headers in lustre/include/lustre/
12924         # that are not packaged (like lustre_idl.h) and have more
12925         # complicated include dependencies (like config.h and lnet/types.h).
12926         # Since this test about correct packaging we just skip them when
12927         # they don't exist (see below) rather than try to fixup cppflags.
12928
12929         if ! which $CC > /dev/null 2>&1; then
12930                 skip_env "$CC is not installed"
12931                 return 0
12932         fi
12933
12934         for header in $prefix/*.h; do
12935                 if ! [[ -f "$header" ]]; then
12936                         continue
12937                 fi
12938
12939                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
12940                         continue # liblustreapi.h is deprecated.
12941                 fi
12942
12943                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
12944                         error "cannot compile '$header'"
12945         done
12946 }
12947 run_test 400b "packaged headers can be compiled"
12948
12949 #
12950 # tests that do cleanup/setup should be run at the end
12951 #
12952
12953 test_900() {
12954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12955         local ls
12956         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
12957         $LCTL set_param fail_loc=0x903
12958         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
12959         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
12960                 echo "clear" > $ls
12961         done
12962         FAIL_ON_ERROR=true cleanup
12963         FAIL_ON_ERROR=true setup
12964 }
12965 run_test 900 "umount should not race with any mgc requeue thread"
12966
12967 complete $SECONDS
12968 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
12969 check_and_cleanup_lustre
12970 if [ "$I_MOUNTED" != "yes" ]; then
12971         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
12972 fi
12973 exit_status