Whamcloud - gitweb
b=14512
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test: 4900 4900 2108 9789 3637 9789 3561 12622 13310 10764
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"27o  27q  42a  42b  42c  42d  45  51d   74b   75 $SANITY_EXCEPT" }
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 36f 36g 51b 51c 60c 63 64b 68 71 73 78 101 103 115 120g"
15
16 # Tests that fail on uml, maybe elsewhere, FIXME
17 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
18 #                                    buffer i/o errs             sock spc runas
19 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 27m 27n 27o 27p 27q 27r 31d 54a  64b 99a 99b 99c 99d 99e 99f 101"
20
21 case `uname -r` in
22 2.4*) FSTYPE=${FSTYPE:-ext3};    ALWAYS_EXCEPT="$ALWAYS_EXCEPT 76"
23         [ "$CPU" = "UML" ] && ALWAYS_EXCEPT="$ALWAYS_EXCEPT 105a";;
24 2.6*) FSTYPE=${FSTYPE:-ldiskfs}; ALWAYS_EXCEPT="$ALWAYS_EXCEPT " ;;
25 *) error "unsupported kernel" ;;
26 esac
27
28 SRCDIR=`dirname $0`
29 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH:/sbin
30
31 TMP=${TMP:-/tmp}
32
33 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
34 CREATETEST=${CREATETEST:-createtest}
35 LFS=${LFS:-lfs}
36 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
37 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
38 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
39 LFIND=${LFIND:-"$LFS find"}
40 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
41 LSTRIPEINFO=${LSTRIPEINFO:-ll_getstripe_info}
42 LCTL=${LCTL:-lctl}
43 MCREATE=${MCREATE:-mcreate}
44 OPENFILE=${OPENFILE:-openfile}
45 OPENUNLINK=${OPENUNLINK:-openunlink}
46 RANDOM_READS=${RANDOM_READS:-"random-reads"}
47 TOEXCL=${TOEXCL:-toexcl}
48 TRUNCATE=${TRUNCATE:-truncate}
49 MUNLINK=${MUNLINK:-munlink}
50 SOCKETSERVER=${SOCKETSERVER:-socketserver}
51 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
52 IOPENTEST1=${IOPENTEST1:-iopentest1}
53 IOPENTEST2=${IOPENTEST2:-iopentest2}
54 MEMHOG=${MEMHOG:-memhog}
55 DIRECTIO=${DIRECTIO:-directio}
56 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
57 UMOUNT=${UMOUNT:-"umount -d"}
58 CHECK_GRANT=${CHECK_GRANT:-"yes"}
59 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
60
61 export NAME=${NAME:-local}
62
63 SAVE_PWD=$PWD
64
65 CLEANUP=${CLEANUP:-:}
66 SETUP=${SETUP:-:}
67 TRACE=${TRACE:-""}
68 LUSTRE=${LUSTRE:-`dirname $0`/..}
69 . $LUSTRE/tests/test-framework.sh
70 init_test_env $@
71 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
72
73 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
74 FAIL_ON_ERROR=false
75
76 cleanup() {
77         echo -n "cln.."
78         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
79         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
80 }
81 setup() {
82         echo -n "mnt.."
83         load_modules
84         setupall || exit 10
85         echo "done"
86 }
87
88
89 check_kernel_version() {
90         VERSION_FILE=$LPROC/version
91         WANT_VER=$1
92         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
93         GOT_VER=$(awk '/kernel:/ {print $2}' $VERSION_FILE)
94         [ $GOT_VER == "patchless" ] && return 0
95         [ $GOT_VER -ge $WANT_VER ] && return 0
96         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
97         return 1
98 }
99
100 if [ "$ONLY" == "cleanup" ]; then
101         sh llmountcleanup.sh
102         exit 0
103 fi
104
105 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
106
107 check_and_setup_lustre
108
109 DIR=${DIR:-$MOUNT}
110 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
111
112 LOVNAME=`cat $LPROC/llite/*/lov/common_name | tail -n 1`
113 OSTCOUNT=`cat $LPROC/lov/$LOVNAME/numobd`
114 STRIPECOUNT=`cat $LPROC/lov/$LOVNAME/stripecount`
115 STRIPESIZE=`cat $LPROC/lov/$LOVNAME/stripesize`
116 ORIGFREE=`cat $LPROC/lov/$LOVNAME/kbytesavail`
117 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
118
119 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
120 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
121 rm -rf $DIR/[Rdfs][1-9]*
122
123 if [ $UID -ne 0 ]; then
124         log "running as non-root uid $UID"
125         RUNAS_ID="$UID"
126         RUNAS=""
127 else
128         RUNAS_ID=${RUNAS_ID:-500}
129         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
130
131         # $RUNAS_ID may get set incorrectly somewhere else
132         [ $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
133 fi
134
135 check_runas_id $RUNAS_ID $RUNAS
136
137 build_test_filter
138
139 echo "preparing for tests involving mounts"
140 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
141 touch $EXT2_DEV
142 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
143 echo # add a newline after mke2fs.
144
145 umask 077
146
147 OLDDEBUG="`sysctl lnet.debug 2> /dev/null`"
148 sysctl -w lnet.debug=-1 2> /dev/null || true
149 test_0() {
150         touch $DIR/$tfile
151         $CHECKSTAT -t file $DIR/$tfile || error
152         rm $DIR/$tfile
153         $CHECKSTAT -a $DIR/$tfile || error
154 }
155 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
156
157 test_0b() {
158         chmod 0755 $DIR || error
159         $CHECKSTAT -p 0755 $DIR || error
160 }
161 run_test 0b "chmod 0755 $DIR ============================="
162
163 test_1a() {
164         mkdir $DIR/d1
165         mkdir $DIR/d1/d2
166         $CHECKSTAT -t dir $DIR/d1/d2 || error
167 }
168 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
169
170 test_1b() {
171         rmdir $DIR/d1/d2
172         rmdir $DIR/d1
173         $CHECKSTAT -a $DIR/d1 || error
174 }
175 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
176
177 test_2a() {
178         mkdir $DIR/d2
179         touch $DIR/d2/f
180         $CHECKSTAT -t file $DIR/d2/f || error
181 }
182 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
183
184 test_2b() {
185         rm -r $DIR/d2
186         $CHECKSTAT -a $DIR/d2 || error
187 }
188 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
189
190 test_3a() {
191         mkdir $DIR/d3
192         $CHECKSTAT -t dir $DIR/d3 || error
193 }
194 run_test 3a "mkdir .../d3 ======================================"
195
196 test_3b() {
197         if [ ! -d $DIR/d3 ]; then
198                 mkdir $DIR/d3
199         fi
200         touch $DIR/d3/f
201         $CHECKSTAT -t file $DIR/d3/f || error
202 }
203 run_test 3b "touch .../d3/f ===================================="
204
205 test_3c() {
206         rm -r $DIR/d3
207         $CHECKSTAT -a $DIR/d3 || error
208 }
209 run_test 3c "rm -r .../d3 ======================================"
210
211 test_4a() {
212         mkdir $DIR/d4
213         $CHECKSTAT -t dir $DIR/d4 || error
214 }
215 run_test 4a "mkdir .../d4 ======================================"
216
217 test_4b() {
218         if [ ! -d $DIR/d4 ]; then
219                 mkdir $DIR/d4
220         fi
221         mkdir $DIR/d4/d2
222         $CHECKSTAT -t dir $DIR/d4/d2 || error
223 }
224 run_test 4b "mkdir .../d4/d2 ==================================="
225
226 test_5() {
227         mkdir $DIR/d5
228         mkdir $DIR/d5/d2
229         chmod 0707 $DIR/d5/d2
230         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
231 }
232 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
233
234 test_6a() {
235         touch $DIR/f6a
236         chmod 0666 $DIR/f6a || error
237         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
238 }
239 run_test 6a "touch .../f6a; chmod .../f6a ======================"
240
241 test_6b() {
242         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
243         if [ ! -f $DIR/f6a ]; then
244                 touch $DIR/f6a
245                 chmod 0666 $DIR/f6a
246         fi
247         $RUNAS chmod 0444 $DIR/f6a && error
248         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
249 }
250 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
251
252 test_6c() {
253         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
254         touch $DIR/f6c
255         chown $RUNAS_ID $DIR/f6c || error
256         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
257 }
258 run_test 6c "touch .../f6c; chown .../f6c ======================"
259
260 test_6d() {
261         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
262         if [ ! -f $DIR/f6c ]; then
263                 touch $DIR/f6c
264                 chown $RUNAS_ID $DIR/f6c
265         fi
266         $RUNAS chown $UID $DIR/f6c && error
267         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
268 }
269 run_test 6d "$RUNAS chown .../f6c (should return error) =="
270
271 test_6e() {
272         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
273         touch $DIR/f6e
274         chgrp $RUNAS_ID $DIR/f6e || error
275         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
276 }
277 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
278
279 test_6f() {
280         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
281         if [ ! -f $DIR/f6e ]; then
282                 touch $DIR/f6e
283                 chgrp $RUNAS_ID $DIR/f6e
284         fi
285         $RUNAS chgrp $UID $DIR/f6e && error
286         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
287 }
288 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
289
290 test_6g() {
291         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
292         mkdir $DIR/d6g || error
293         chmod 777 $DIR/d6g || error
294         $RUNAS mkdir $DIR/d6g/d || error
295         chmod g+s $DIR/d6g/d || error
296         mkdir $DIR/d6g/d/subdir
297         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
298 }
299 run_test 6g "Is new dir in sgid dir inheriting group?"
300
301 test_6h() { # bug 7331
302         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
303         touch $DIR/f6h || error "touch failed"
304         chown $RUNAS_ID:$RUNAS_ID $DIR/f6h || error "initial chown failed"
305         $RUNAS -G$RUNAS_ID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
306         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_ID $DIR/f6h || error
307 }
308 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
309
310 test_7a() {
311         mkdir $DIR/d7
312         $MCREATE $DIR/d7/f
313         chmod 0666 $DIR/d7/f
314         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
315 }
316 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
317
318 test_7b() {
319         if [ ! -d $DIR/d7 ]; then
320                 mkdir $DIR/d7
321         fi
322         $MCREATE $DIR/d7/f2
323         echo -n foo > $DIR/d7/f2
324         [ "`cat $DIR/d7/f2`" = "foo" ] || error
325         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
326 }
327 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
328
329 test_8() {
330         mkdir $DIR/d8
331         touch $DIR/d8/f
332         chmod 0666 $DIR/d8/f
333         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
334 }
335 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
336
337 test_9() {
338         mkdir $DIR/d9
339         mkdir $DIR/d9/d2
340         mkdir $DIR/d9/d2/d3
341         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
342 }
343 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
344
345 test_10() {
346         mkdir $DIR/d10
347         mkdir $DIR/d10/d2
348         touch $DIR/d10/d2/f
349         $CHECKSTAT -t file $DIR/d10/d2/f || error
350 }
351 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
352
353 test_11() {
354         mkdir $DIR/d11
355         mkdir $DIR/d11/d2
356         chmod 0666 $DIR/d11/d2
357         chmod 0705 $DIR/d11/d2
358         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
359 }
360 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
361
362 test_12() {
363         mkdir $DIR/d12
364         touch $DIR/d12/f
365         chmod 0666 $DIR/d12/f
366         chmod 0654 $DIR/d12/f
367         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
368 }
369 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
370
371 test_13() {
372         mkdir $DIR/d13
373         dd if=/dev/zero of=$DIR/d13/f count=10
374         >  $DIR/d13/f
375         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
376 }
377 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
378
379 test_14() {
380         mkdir $DIR/d14
381         touch $DIR/d14/f
382         rm $DIR/d14/f
383         $CHECKSTAT -a $DIR/d14/f || error
384 }
385 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
386
387 test_15() {
388         mkdir $DIR/d15
389         touch $DIR/d15/f
390         mv $DIR/d15/f $DIR/d15/f2
391         $CHECKSTAT -t file $DIR/d15/f2 || error
392 }
393 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
394
395 test_16() {
396         mkdir $DIR/d16
397         touch $DIR/d16/f
398         rm -rf $DIR/d16/f
399         $CHECKSTAT -a $DIR/d16/f || error
400 }
401 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
402
403 test_17a() {
404         mkdir -p $DIR/d17
405         touch $DIR/d17/f
406         ln -s $DIR/d17/f $DIR/d17/l-exist
407         ls -l $DIR/d17
408         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
409         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
410         rm -f $DIR/d17/l-exist
411         $CHECKSTAT -a $DIR/d17/l-exist || error
412 }
413 run_test 17a "symlinks: create, remove (real) =================="
414
415 test_17b() {
416         mkdir -p $DIR/d17
417         ln -s no-such-file $DIR/d17/l-dangle
418         ls -l $DIR/d17
419         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
420         $CHECKSTAT -fa $DIR/d17/l-dangle || error
421         rm -f $DIR/d17/l-dangle
422         $CHECKSTAT -a $DIR/d17/l-dangle || error
423 }
424 run_test 17b "symlinks: create, remove (dangling) =============="
425
426 test_17c() { # bug 3440 - don't save failed open RPC for replay
427         mkdir -p $DIR/d17
428         ln -s foo $DIR/d17/f17c
429         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
430 }
431 run_test 17c "symlinks: open dangling (should return error) ===="
432
433 test_17d() {
434         mkdir -p $DIR/d17
435         ln -s foo $DIR/d17/f17d
436         touch $DIR/d17/f17d || error "creating to new symlink"
437 }
438 run_test 17d "symlinks: create dangling ========================"
439
440 test_17e() {
441         mkdir -p $DIR/$tdir
442         local foo=$DIR/$tdir/$tfile
443         ln -s $foo $foo || error "create symlink failed"
444         ls -l $foo || error "ls -l failed"
445         ls $foo && error "ls not failed" || true
446 }
447 run_test 17e "symlinks: create recursive symlink (should return error) ===="
448
449 test_18() {
450         touch $DIR/f
451         ls $DIR || error
452 }
453 run_test 18 "touch .../f ; ls ... =============================="
454
455 test_19a() {
456         touch $DIR/f19
457         ls -l $DIR
458         rm $DIR/f19
459         $CHECKSTAT -a $DIR/f19 || error
460 }
461 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
462
463 test_19b() {
464         ls -l $DIR/f19 && error || true
465 }
466 run_test 19b "ls -l .../f19 (should return error) =============="
467
468 test_19c() {
469         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
470         $RUNAS touch $DIR/f19 && error || true
471 }
472 run_test 19c "$RUNAS touch .../f19 (should return error) =="
473
474 test_19d() {
475         cat $DIR/f19 && error || true
476 }
477 run_test 19d "cat .../f19 (should return error) =============="
478
479 test_20() {
480         touch $DIR/f
481         rm $DIR/f
482         log "1 done"
483         touch $DIR/f
484         rm $DIR/f
485         log "2 done"
486         touch $DIR/f
487         rm $DIR/f
488         log "3 done"
489         $CHECKSTAT -a $DIR/f || error
490 }
491 run_test 20 "touch .../f ; ls -l ... ==========================="
492
493 test_21() {
494         mkdir $DIR/d21
495         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
496         ln -s dangle $DIR/d21/link
497         echo foo >> $DIR/d21/link
498         cat $DIR/d21/dangle
499         $CHECKSTAT -t link $DIR/d21/link || error
500         $CHECKSTAT -f -t file $DIR/d21/link || error
501 }
502 run_test 21 "write to dangling link ============================"
503
504 test_22() {
505         WDIR=$DIR/$tdir
506         chown $RUNAS_ID $WDIR
507         (cd $WDIR || error "cd $WDIR failed";
508         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
509         $RUNAS tar xf -)
510         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
511         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
512         $CHECKSTAT -u \#$RUNAS_ID $WDIR/etc || error "checkstat -u failed"
513 }
514 run_test 22 "unpack tar archive as non-root user ==============="
515
516 test_23() {
517         mkdir $DIR/d23
518         $TOEXCL $DIR/d23/f23
519         $TOEXCL -e $DIR/d23/f23 || error
520 }
521 run_test 23 "O_CREAT|O_EXCL in subdir =========================="
522
523 test_24a() {
524         echo '== rename sanity =============================================='
525         echo '-- same directory rename'
526         mkdir $DIR/R1
527         touch $DIR/R1/f
528         mv $DIR/R1/f $DIR/R1/g
529         $CHECKSTAT -t file $DIR/R1/g || error
530 }
531 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
532
533 test_24b() {
534         mkdir $DIR/R2
535         touch $DIR/R2/{f,g}
536         mv $DIR/R2/f $DIR/R2/g
537         $CHECKSTAT -a $DIR/R2/f || error
538         $CHECKSTAT -t file $DIR/R2/g || error
539 }
540 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
541
542 test_24c() {
543         mkdir $DIR/R3
544         mkdir $DIR/R3/f
545         mv $DIR/R3/f $DIR/R3/g
546         $CHECKSTAT -a $DIR/R3/f || error
547         $CHECKSTAT -t dir $DIR/R3/g || error
548 }
549 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
550
551 test_24d() {
552         mkdir $DIR/R4
553         mkdir $DIR/R4/{f,g}
554         mrename $DIR/R4/f $DIR/R4/g
555         $CHECKSTAT -a $DIR/R4/f || error
556         $CHECKSTAT -t dir $DIR/R4/g || error
557 }
558 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
559
560 test_24e() {
561         echo '-- cross directory renames --' 
562         mkdir $DIR/R5{a,b}
563         touch $DIR/R5a/f
564         mv $DIR/R5a/f $DIR/R5b/g
565         $CHECKSTAT -a $DIR/R5a/f || error
566         $CHECKSTAT -t file $DIR/R5b/g || error
567 }
568 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
569
570 test_24f() {
571         mkdir $DIR/R6{a,b}
572         touch $DIR/R6a/f $DIR/R6b/g
573         mv $DIR/R6a/f $DIR/R6b/g
574         $CHECKSTAT -a $DIR/R6a/f || error
575         $CHECKSTAT -t file $DIR/R6b/g || error
576 }
577 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
578
579 test_24g() {
580         mkdir $DIR/R7{a,b}
581         mkdir $DIR/R7a/d
582         mv $DIR/R7a/d $DIR/R7b/e
583         $CHECKSTAT -a $DIR/R7a/d || error
584         $CHECKSTAT -t dir $DIR/R7b/e || error
585 }
586 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R5b/e ======"
587
588 test_24h() {
589         mkdir $DIR/R8{a,b}
590         mkdir $DIR/R8a/d $DIR/R8b/e
591         mrename $DIR/R8a/d $DIR/R8b/e
592         $CHECKSTAT -a $DIR/R8a/d || error
593         $CHECKSTAT -t dir $DIR/R8b/e || error
594 }
595 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
596
597 test_24i() {
598         echo "-- rename error cases"
599         mkdir $DIR/R9
600         mkdir $DIR/R9/a
601         touch $DIR/R9/f
602         mrename $DIR/R9/f $DIR/R9/a
603         $CHECKSTAT -t file $DIR/R9/f || error
604         $CHECKSTAT -t dir  $DIR/R9/a || error
605         $CHECKSTAT -a file $DIR/R9/a/f || error
606 }
607 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
608
609 test_24j() {
610         mkdir $DIR/R10
611         mrename $DIR/R10/f $DIR/R10/g
612         $CHECKSTAT -t dir $DIR/R10 || error
613         $CHECKSTAT -a $DIR/R10/f || error
614         $CHECKSTAT -a $DIR/R10/g || error
615 }
616 run_test 24j "source does not exist ============================" 
617
618 test_24k() {
619         mkdir $DIR/R11a $DIR/R11a/d
620         touch $DIR/R11a/f
621         mv $DIR/R11a/f $DIR/R11a/d
622         $CHECKSTAT -a $DIR/R11a/f || error
623         $CHECKSTAT -t file $DIR/R11a/d/f || error
624 }
625 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
626
627 # bug 2429 - rename foo foo foo creates invalid file
628 test_24l() {
629         f="$DIR/f24l"
630         multiop $f OcNs || error
631 }
632 run_test 24l "Renaming a file to itself ========================"
633
634 test_24m() {
635         f="$DIR/f24m"
636         multiop $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
637         # on ext3 this does not remove either the source or target files
638         # though the "expected" operation would be to remove the source
639         $CHECKSTAT -t file ${f} || error "${f} missing"
640         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
641 }
642 run_test 24m "Renaming a file to a hard link to itself ========="
643
644 test_24n() {
645     f="$DIR/f24n"
646     # this stats the old file after it was renamed, so it should fail
647     touch ${f}
648     $CHECKSTAT ${f}
649     mv ${f} ${f}.rename
650     $CHECKSTAT ${f}.rename
651     $CHECKSTAT -a ${f}
652 }
653 run_test 24n "Statting the old file after renaming (Posix rename 2)"
654
655 test_24o() {
656         check_kernel_version 37 || return 0
657         mkdir -p $DIR/d24o
658         rename_many -s random -v -n 10 $DIR/d24o
659 }
660 run_test 24o "rename of files during htree split ==============="
661
662 test_24p() {
663         mkdir $DIR/R12{a,b}
664         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
665         mrename $DIR/R12a $DIR/R12b
666         $CHECKSTAT -a $DIR/R12a || error
667         $CHECKSTAT -t dir $DIR/R12b || error
668         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
669         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
670 }
671 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
672
673 test_24q() {
674         mkdir $DIR/R13{a,b}
675         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
676         multiop $DIR/R13b D_c &
677         MULTIPID=$!
678         usleep 500
679
680         mrename $DIR/R13a $DIR/R13b
681         $CHECKSTAT -a $DIR/R13a || error
682         $CHECKSTAT -t dir $DIR/R13b || error
683         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
684         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
685         kill -USR1 $MULTIPID
686         wait $MULTIPID || error "multiop close failed"
687 }
688 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
689
690 test_24r() { #bug 3789
691         mkdir $DIR/R14a $DIR/R14a/b
692         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
693         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
694         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
695 }
696 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
697
698 test_24s() {
699         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
700         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
701         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
702         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
703 }
704 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
705 test_24t() {
706         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
707         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
708         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
709         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
710 }
711 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
712
713 test_24u() { # bug12192
714         multiop $DIR/$tfile C2w$((2048 * 1024))c || error
715         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
716 }
717 run_test 24u "create stripe file"
718
719 test_25a() {
720         echo '== symlink sanity ============================================='
721
722         mkdir $DIR/d25
723         ln -s d25 $DIR/s25
724         touch $DIR/s25/foo || error
725 }
726 run_test 25a "create file in symlinked directory ==============="
727
728 test_25b() {
729         [ ! -d $DIR/d25 ] && test_25a
730         $CHECKSTAT -t file $DIR/s25/foo || error
731 }
732 run_test 25b "lookup file in symlinked directory ==============="
733
734 test_26a() {
735         mkdir $DIR/d26
736         mkdir $DIR/d26/d26-2
737         ln -s d26/d26-2 $DIR/s26
738         touch $DIR/s26/foo || error
739 }
740 run_test 26a "multiple component symlink ======================="
741
742 test_26b() {
743         mkdir -p $DIR/d26b/d26-2
744         ln -s d26b/d26-2/foo $DIR/s26-2
745         touch $DIR/s26-2 || error
746 }
747 run_test 26b "multiple component symlink at end of lookup ======"
748
749 test_26c() {
750         mkdir $DIR/d26.2
751         touch $DIR/d26.2/foo
752         ln -s d26.2 $DIR/s26.2-1
753         ln -s s26.2-1 $DIR/s26.2-2
754         ln -s s26.2-2 $DIR/s26.2-3
755         chmod 0666 $DIR/s26.2-3/foo
756 }
757 run_test 26c "chain of symlinks ================================"
758
759 # recursive symlinks (bug 439)
760 test_26d() {
761         ln -s d26-3/foo $DIR/d26-3
762 }
763 run_test 26d "create multiple component recursive symlink ======"
764
765 test_26e() {
766         [ ! -h $DIR/d26-3 ] && test_26d
767         rm $DIR/d26-3
768 }
769 run_test 26e "unlink multiple component recursive symlink ======"
770
771 # recursive symlinks (bug 7022)
772 test_26f() {
773         mkdir $DIR/$tdir/$tfile        || error "mkdir $DIR/$tdir/$tfile failed"
774         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
775         mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
776         mkdir $tfile             || error "mkdir $tfile failed"
777         cd $tfile                || error "cd $tfile failed"
778         ln -s .. dotdot          || error "ln dotdot failed"
779         ln -s dotdot/lndir lndir || error "ln lndir failed"
780         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
781         output=`ls $tfile/$tfile/lndir/bar1`
782         [ "$output" = bar1 ] && error "unexpected output"
783         rm -r $tfile             || error "rm $tfile failed"
784         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
785 }
786 run_test 26f "rm -r of a directory which has recursive symlink ="
787
788 test_27a() {
789         echo '== stripe sanity =============================================='
790         mkdir -p $DIR/d27 || error "mkdir failed"
791         $SETSTRIPE $DIR/d27/f0 -c 1 || error "lstripe failed"
792         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
793         pass
794         log "== test 27b: write to one stripe file ========================="
795         cp /etc/hosts $DIR/d27/f0 || error
796 }
797 run_test 27a "one stripe file =================================="
798
799 test_27c() {
800         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
801         mkdir -p $DIR/d27
802         $SETSTRIPE $DIR/d27/f01 -c 2 || error "lstripe failed"
803         [ `$GETSTRIPE $DIR/d27/f01 | grep -A 10 obdidx | wc -l` -eq 4 ] ||
804                 error "two-stripe file doesn't have two stripes"
805         pass
806         log "== test 27d: write to two stripe file file f01 ================"
807         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
808 }
809 run_test 27c "create two stripe file f01 ======================="
810
811 test_27d() {
812         mkdir -p $DIR/d27
813         $SETSTRIPE $DIR/d27/fdef 0 -1 0 || error "lstripe failed"
814         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
815         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
816 }
817 run_test 27d "create file with default settings ================"
818
819 test_27e() {
820         mkdir -p $DIR/d27
821         $SETSTRIPE $DIR/d27/f12 -c 2 || error "lstripe failed"
822         $SETSTRIPE $DIR/d27/f12 -c 2 && error "lstripe succeeded twice"
823         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
824 }
825 run_test 27e "lstripe existing file (should return error) ======"
826
827 test_27f() {
828         mkdir -p $DIR/d27
829         $SETSTRIPE $DIR/d27/fbad -s 100 -i 0 -c 1 && error "lstripe failed"
830         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
831         $GETSTRIPE $DIR/d27/fbad || error "lfs getstripe failed"
832 }
833 run_test 27f "lstripe with bad stripe size (should return error)"
834
835 test_27g() {
836         mkdir -p $DIR/d27
837         $MCREATE $DIR/d27/fnone || error "mcreate failed"
838         pass
839         log "== test 27h: lfs getstripe with no objects ===================="
840         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" || error "has object"
841         pass
842         log "== test 27i: lfs getstripe with some objects =================="
843         touch $DIR/d27/fsome || error "touch failed"
844         $GETSTRIPE $DIR/d27/fsome | grep obdidx || error "missing objects"
845 }
846 run_test 27g "test lfs getstripe ==========================================="
847
848 test_27j() {
849         mkdir -p $DIR/d27
850         $SETSTRIPE $DIR/d27/f27j -i $OSTCOUNT && error "lstripe failed"||true
851 }
852 run_test 27j "lstripe with bad stripe offset (should return error)"
853
854 test_27k() { # bug 2844
855         mkdir -p $DIR/d27
856         FILE=$DIR/d27/f27k
857         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
858         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
859         $SETSTRIPE $FILE -s 67108864 || error "lstripe failed"
860         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
861         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
862         dd if=/dev/zero of=$FILE bs=4k count=1
863         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
864         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
865 }
866 run_test 27k "limit i_blksize for broken user apps ============="
867
868 test_27l() {
869         mkdir -p $DIR/d27
870         mcreate $DIR/f27l || error "creating file"
871         $RUNAS $SETSTRIPE $DIR/f27l -c 1 && \
872                 error "lstripe should have failed" || true
873 }
874 run_test 27l "check setstripe permissions (should return error)"
875
876 test_27m() {
877         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2 OSTs -- skipping" && return
878         if [ $ORIGFREE -gt $MAXFREE ]; then
879                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
880                 return
881         fi
882         mkdir -p $DIR/d27
883         $SETSTRIPE $DIR/d27/f27m_1 -i 0 -c 1
884         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE && \
885                 error "dd should fill OST0"
886         i=2
887         while $SETSTRIPE $DIR/d27/f27m_$i -i 0 -c 1 ; do
888                 i=`expr $i + 1`
889                 [ $i -gt 256 ] && break
890         done
891         i=`expr $i + 1`
892         touch $DIR/d27/f27m_$i
893         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
894                 error "OST0 was full but new created file still use it"
895         i=`expr $i + 1`
896         touch $DIR/d27/f27m_$i
897         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
898                 error "OST0 was full but new created file still use it"
899         rm -r $DIR/d27
900 }
901 run_test 27m "create file while OST0 was full =================="
902
903 # osc's keep a NOSPC stick flag that gets unset with rmdir
904 reset_enospc() {
905         [ "$1" ] && FAIL_LOC=$1 || FAIL_LOC=0
906         mkdir -p $DIR/d27/nospc
907         rmdir $DIR/d27/nospc
908         sysctl -w lustre.fail_loc=$FAIL_LOC
909 }
910
911 exhaust_precreations() {
912         OSTIDX=$1
913         OST=$(grep ${OSTIDX}": " $LPROC/lov/${LOVNAME}/target_obd | \
914             awk '{print $2}' | sed -e 's/_UUID$//')
915         # on the mdt's osc
916         last_id=$(cat $LPROC/osc/${OST}-osc/prealloc_last_id)
917         next_id=$(cat $LPROC/osc/${OST}-osc/prealloc_next_id)
918
919         mkdir -p $DIR/d27/${OST}
920         $SETSTRIPE $DIR/d27/${OST} -i $OSTIDX -c 1
921         #define OBD_FAIL_OST_ENOSPC 0x215
922         sysctl -w lustre.fail_loc=0x215
923         echo "Creating to objid $last_id on ost $OST..."
924         createmany -o $DIR/d27/${OST}/f $next_id $((last_id - next_id + 2))
925         grep '[0-9]' $LPROC/osc/${OST}-osc/prealloc*
926         reset_enospc $2
927 }
928
929 exhaust_all_precreations() {
930         local i
931         for (( i=0; i < OSTCOUNT; i++ )) ; do
932                 exhaust_precreations $i 0x215
933         done
934         reset_enospc $1
935 }
936
937 test_27n() {
938         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
939         remote_mds && skip "remote MDS" && return
940
941         reset_enospc
942         rm -f $DIR/d27/f27n
943         exhaust_precreations 0 0x80000215
944
945         touch $DIR/d27/f27n || error
946
947         reset_enospc
948 }
949 run_test 27n "create file with some full OSTs =================="
950
951 test_27o() {
952         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
953         remote_mds && skip "remote MDS" && return
954
955         reset_enospc
956         rm -f $DIR/d27/f27o
957         exhaust_all_precreations 0x215
958         sleep 5
959
960         touch $DIR/d27/f27o && error "able to create $DIR/d27/f27o"
961
962         reset_enospc
963 }
964 run_test 27o "create file with all full OSTs (should error) ===="
965
966 test_27p() {
967         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
968         remote_mds && skip "remote MDS" && return
969
970         reset_enospc
971         rm -f $DIR/d27/f27p
972
973         $MCREATE $DIR/d27/f27p || error
974         $TRUNCATE $DIR/d27/f27p 80000000 || error
975         $CHECKSTAT -s 80000000 $DIR/d27/f27p || error
976
977         exhaust_precreations 0 0x80000215
978         echo foo >> $DIR/d27/f27p || error
979         $CHECKSTAT -s 80000004 $DIR/d27/f27p || error
980
981         reset_enospc
982 }
983 run_test 27p "append to a truncated file with some full OSTs ==="
984
985 test_27q() {
986         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
987         remote_mds && skip "remote MDS" && return
988
989         reset_enospc
990         rm -f $DIR/d27/f27q
991
992         $MCREATE $DIR/d27/f27q || error "mcreate $DIR/d27/f27q failed"
993         $TRUNCATE $DIR/d27/f27q 80000000 ||error "truncate $DIR/d27/f27q failed"
994         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat failed"
995
996         exhaust_all_precreations 0x215
997
998         echo foo >> $DIR/d27/f27q && error "append succeeded"
999         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat 2 failed"
1000
1001         reset_enospc
1002 }
1003 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1004
1005 test_27r() {
1006         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1007         remote_mds && skip "remote MDS" && return
1008
1009         reset_enospc
1010         rm -f $DIR/d27/f27r
1011         exhaust_precreations 0 0x80000215
1012
1013         $SETSTRIPE $DIR/d27/f27r -i 0 -c 2 # && error
1014
1015         reset_enospc
1016 }
1017 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1018
1019 test_27s() { # bug 10725
1020         mkdir -p $DIR/$tdir
1021         $LSTRIPE $DIR/$tdir $((2048 * 1024 * 1024)) -1 2 && \
1022                 error "stripe width >= 2^32 succeeded" || true
1023 }
1024 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1025
1026 test_27t() { # bug 10864
1027         WDIR=`pwd`
1028         WLFS=`which lfs`
1029         cd $DIR
1030         touch $tfile
1031         $WLFS getstripe $tfile
1032         cd $WDIR
1033 }
1034 run_test 27t "check that utils parse path correctly"
1035
1036 test_27u() { # bug 4900
1037         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1038         remote_mds && skip "remote MDS" && return
1039
1040         #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1041
1042         sysctl -w lustre.fail_loc=0x139
1043         mkdir -p $DIR/d27u
1044         createmany -o $DIR/d27u/t- 1000
1045         sysctl -w lustre.fail_loc=0
1046
1047         TLOG=$DIR/$tfile.getstripe
1048         $GETSTRIPE $DIR/d27u > $TLOG
1049         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1050         unlinkmany $DIR/d27u/t- 1000
1051         [ $OBJS -gt 0 ] && \
1052                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1053 }
1054 run_test 27u "skip object creation on OSC w/o objects =========="
1055
1056 test_27v() { # bug 4900
1057         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1058         remote_mds && skip "remote MDS" && return
1059
1060         exhaust_all_precreations
1061
1062         mkdir -p $DIR/$tdir
1063         $SETSTRIPE $DIR/$tdir -c 1         # 1 stripe / file
1064
1065         touch $DIR/$tdir/$tfile
1066         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1067         sysctl -w lustre.fail_loc=0x705
1068         START=`date +%s`
1069         for F in `seq 1 32`; do
1070                 touch $DIR/$tdir/$tfile.$F
1071         done
1072         sysctl -w lustre.fail_loc=0
1073
1074         FINISH=`date +%s`
1075         TIMEOUT=`sysctl -n lustre.timeout`
1076         [ $((FINISH - START)) -ge $((TIMEOUT / 2)) ] && \
1077                error "$FINISH - $START >= $TIMEOUT / 2"
1078
1079         reset_enospc
1080 }
1081 run_test 27v "skip object creation on slow OST ================="
1082
1083 test_27w() { # bug 10997
1084         mkdir -p $DIR/d27w || error "mkdir failed"
1085         $LSTRIPE $DIR/d27w/f0 -s 65536 || error "lstripe failed"
1086         size=`$LSTRIPEINFO $DIR/d27w/f0 | awk {'print $1'}`
1087         [ $size -ne 65536 ] && error "stripe size $size != 65536" || true
1088
1089         [ "$OSTCOUNT" -lt "2" ] && skip "skipping multiple stripe count/offset test" && return
1090         for i in `seq 1 $OSTCOUNT`; do
1091                 offset=$(($i-1))
1092                 $LSTRIPE $DIR/d27w/f$i -c $i -i $offset || error "lstripe -c $i -i $offset failed"
1093                 count=`$LSTRIPEINFO $DIR/d27w/f$i | awk {'print $2'}`
1094                 index=`$LSTRIPEINFO $DIR/d27w/f$i | awk {'print $3'}`
1095                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1096                 [ $index -ne $offset ] && error "stripe offset $index != $offset" || true
1097         done
1098 }
1099 run_test 27w "check lfs setstripe -c -s -i options ============="
1100
1101 test_28() {
1102         mkdir $DIR/d28
1103         $CREATETEST $DIR/d28/ct || error
1104 }
1105 run_test 28 "create/mknod/mkdir with bad file types ============"
1106
1107 test_29() {
1108         cancel_lru_locks mdc
1109         mkdir $DIR/d29
1110         touch $DIR/d29/foo
1111         log 'first d29'
1112         ls -l $DIR/d29
1113         MDCDIR=${MDCDIR:-`find $LPROC/ldlm/namespaces | grep mdc | head -1`}
1114         LOCKCOUNTORIG=`cat $MDCDIR/lock_count`
1115         LOCKUNUSEDCOUNTORIG=`cat $MDCDIR/lock_unused_count`
1116         [ -z $"LOCKCOUNTORIG" ] && echo "No mdc lock count" && return 1
1117         log 'second d29'
1118         ls -l $DIR/d29
1119         log 'done'
1120         LOCKCOUNTCURRENT=`cat $MDCDIR/lock_count`
1121         LOCKUNUSEDCOUNTCURRENT=`cat $MDCDIR/lock_unused_count`
1122         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1123                 echo > $LPROC/ldlm/dump_namespaces
1124                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1125                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1126                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1127                 return 2
1128         fi
1129         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1130                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1131                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1132                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1133                 return 3
1134         fi
1135 }
1136 run_test 29 "IT_GETATTR regression  ============================"
1137
1138 test_30() {
1139         cp `which ls` $DIR
1140         $DIR/ls /
1141         rm $DIR/ls
1142 }
1143 run_test 30 "run binary from Lustre (execve) ==================="
1144
1145 test_31a() {
1146         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1147         $CHECKSTAT -a $DIR/f31 || error
1148 }
1149 run_test 31a "open-unlink file =================================="
1150
1151 test_31b() {
1152         touch $DIR/f31 || error
1153         ln $DIR/f31 $DIR/f31b || error
1154         multiop $DIR/f31b Ouc || error
1155         $CHECKSTAT -t file $DIR/f31 || error
1156 }
1157 run_test 31b "unlink file with multiple links while open ======="
1158
1159 test_31c() {
1160         touch $DIR/f31 || error
1161         ln $DIR/f31 $DIR/f31c || error
1162         multiop $DIR/f31 O_uc &
1163         MULTIPID=$!
1164         multiop $DIR/f31c Ouc
1165         usleep 500
1166         kill -USR1 $MULTIPID
1167         wait $MULTIPID
1168 }
1169 run_test 31c "open-unlink file with multiple links ============="
1170
1171 test_31d() {
1172         opendirunlink $DIR/d31d $DIR/d31d || error
1173         $CHECKSTAT -a $DIR/d31d || error
1174 }
1175 run_test 31d "remove of open directory ========================="
1176
1177 test_31e() { # bug 2904
1178         check_kernel_version 34 || return 0
1179         openfilleddirunlink $DIR/d31e || error
1180 }
1181 run_test 31e "remove of open non-empty directory ==============="
1182
1183 test_31f() { # bug 4554
1184         set -vx
1185         mkdir $DIR/d31f
1186         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1187         cp /etc/hosts $DIR/d31f
1188         ls -l $DIR/d31f
1189         $GETSTRIPE $DIR/d31f/hosts
1190         multiop $DIR/d31f D_c &
1191         MULTIPID=$!
1192
1193         sleep 1
1194
1195         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1196         mkdir $DIR/d31f
1197         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1198         cp /etc/hosts $DIR/d31f
1199         ls -l $DIR/d31f
1200          $DIR/d31f/hosts
1201         multiop $DIR/d31f D_c &
1202         MULTIPID2=$!
1203
1204         sleep 6
1205
1206         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1207         wait $MULTIPID || error "first opendir $MULTIPID failed"
1208
1209         sleep 6
1210
1211         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1212         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1213         set +vx
1214 }
1215 run_test 31f "remove of open directory with open-unlink file ==="
1216
1217 test_32a() {
1218         echo "== more mountpoints and symlinks ================="
1219         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1220         mkdir -p $DIR/d32a/ext2-mountpoint 
1221         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1222         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error  
1223         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1224 }
1225 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1226
1227 test_32b() {
1228         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1229         mkdir -p $DIR/d32b/ext2-mountpoint 
1230         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1231         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1232         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1233 }
1234 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1235  
1236 test_32c() {
1237         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1238         mkdir -p $DIR/d32c/ext2-mountpoint 
1239         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1240         mkdir -p $DIR/d32c/d2/test_dir    
1241         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1242         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1243 }
1244 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1245
1246 test_32d() {
1247         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1248         mkdir -p $DIR/d32d/ext2-mountpoint 
1249         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1250         mkdir -p $DIR/d32d/d2/test_dir    
1251         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1252         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1253 }
1254 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1255
1256 test_32e() {
1257         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1258         mkdir -p $DIR/d32e/tmp    
1259         TMP_DIR=$DIR/d32e/tmp       
1260         ln -s $DIR/d32e $TMP_DIR/symlink11 
1261         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1262         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1263         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1264 }
1265 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1266
1267 test_32f() {
1268         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1269         mkdir -p $DIR/d32f/tmp    
1270         TMP_DIR=$DIR/d32f/tmp       
1271         ln -s $DIR/d32f $TMP_DIR/symlink11 
1272         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1273         ls $DIR/d32f/tmp/symlink11  || error
1274         ls $DIR/d32f/symlink01 || error
1275 }
1276 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1277
1278 test_32g() {
1279         TMP_DIR=$DIR/$tdir/tmp       
1280         mkdir -p $TMP_DIR $DIR/${tdir}2
1281         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1282         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1283         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1284         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1285         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1286         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1287 }
1288 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1289
1290 test_32h() {
1291         rm -fr $DIR/$tdir $DIR/${tdir}2
1292         TMP_DIR=$DIR/$tdir/tmp       
1293         mkdir -p $TMP_DIR $DIR/${tdir}2 
1294         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1295         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1296         ls $TMP_DIR/symlink12 || error
1297         ls $DIR/$tdir/symlink02  || error
1298 }
1299 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1300
1301 test_32i() {
1302         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1303         mkdir -p $DIR/d32i/ext2-mountpoint 
1304         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1305         touch $DIR/d32i/test_file
1306         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error  
1307         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1308 }
1309 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1310
1311 test_32j() {
1312         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1313         mkdir -p $DIR/d32j/ext2-mountpoint 
1314         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1315         touch $DIR/d32j/test_file
1316         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1317         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1318 }
1319 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1320
1321 test_32k() {
1322         rm -fr $DIR/d32k
1323         mkdir -p $DIR/d32k/ext2-mountpoint 
1324         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint  
1325         mkdir -p $DIR/d32k/d2
1326         touch $DIR/d32k/d2/test_file || error
1327         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1328         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1329 }
1330 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1331
1332 test_32l() {
1333         rm -fr $DIR/d32l
1334         mkdir -p $DIR/d32l/ext2-mountpoint 
1335         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1336         mkdir -p $DIR/d32l/d2
1337         touch $DIR/d32l/d2/test_file
1338         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1339         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1340 }
1341 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1342
1343 test_32m() {
1344         rm -fr $DIR/d32m
1345         mkdir -p $DIR/d32m/tmp    
1346         TMP_DIR=$DIR/d32m/tmp       
1347         ln -s $DIR $TMP_DIR/symlink11 
1348         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1349         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1350         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1351 }
1352 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1353
1354 test_32n() {
1355         rm -fr $DIR/d32n
1356         mkdir -p $DIR/d32n/tmp    
1357         TMP_DIR=$DIR/d32n/tmp       
1358         ln -s $DIR $TMP_DIR/symlink11 
1359         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1360         ls -l $DIR/d32n/tmp/symlink11  || error
1361         ls -l $DIR/d32n/symlink01 || error
1362 }
1363 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1364
1365 test_32o() {
1366         rm -fr $DIR/d32o $DIR/$tfile
1367         touch $DIR/$tfile 
1368         mkdir -p $DIR/d32o/tmp    
1369         TMP_DIR=$DIR/d32o/tmp       
1370         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1371         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1372         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1373         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1374         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1375         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1376 }
1377 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1378
1379 test_32p() {
1380     log 32p_1
1381         rm -fr $DIR/d32p
1382     log 32p_2
1383         rm -f $DIR/$tfile
1384     log 32p_3
1385         touch $DIR/$tfile 
1386     log 32p_4
1387         mkdir -p $DIR/d32p/tmp    
1388     log 32p_5
1389         TMP_DIR=$DIR/d32p/tmp       
1390     log 32p_6
1391         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1392     log 32p_7
1393         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1394     log 32p_8
1395         cat $DIR/d32p/tmp/symlink12 || error
1396     log 32p_9
1397         cat $DIR/d32p/symlink02 || error
1398     log 32p_10
1399 }
1400 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1401
1402 test_32q() {
1403         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1404         mkdir -p $DIR/d32q
1405         touch $DIR/d32q/under_the_mount
1406         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1407         ls $DIR/d32q/under_the_mount && error || true
1408         $UMOUNT $DIR/d32q || error
1409 }
1410 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1411
1412 test_32r() {
1413         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1414         mkdir -p $DIR/d32r
1415         touch $DIR/d32r/under_the_mount
1416         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1417         ls $DIR/d32r | grep -q under_the_mount && error || true
1418         $UMOUNT $DIR/d32r || error
1419 }
1420 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1421
1422 test_33() {
1423         rm -f $DIR/$tfile
1424         touch $DIR/$tfile
1425         chmod 444 $DIR/$tfile
1426         chown $RUNAS_ID $DIR/$tfile
1427         log 33_1
1428         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1429         log 33_2
1430 }
1431 run_test 33 "write file with mode 444 (should return error) ===="
1432
1433 test_33a() {
1434         rm -fr $DIR/d33
1435         mkdir -p $DIR/d33
1436         chown $RUNAS_ID $DIR/d33
1437         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1438         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1439                 error "open RDWR" || true
1440 }
1441 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1442
1443 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1444 test_34a() {
1445         rm -f $DIR/f34
1446         $MCREATE $DIR/f34 || error
1447         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1448         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1449         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1450         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1451 }
1452 run_test 34a "truncate file that has not been opened ==========="
1453
1454 test_34b() {
1455         [ ! -f $DIR/f34 ] && test_34a
1456         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1457         $OPENFILE -f O_RDONLY $DIR/f34
1458         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1459         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1460 }
1461 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1462
1463 test_34c() {
1464         [ ! -f $DIR/f34 ] && test_34a 
1465         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1466         $OPENFILE -f O_RDWR $DIR/f34
1467         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
1468         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1469 }
1470 run_test 34c "O_RDWR opening file-with-size works =============="
1471
1472 test_34d() {
1473         [ ! -f $DIR/f34 ] && test_34a 
1474         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1475         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1476         rm $DIR/f34
1477 }
1478 run_test 34d "write to sparse file ============================="
1479
1480 test_34e() {
1481         rm -f $DIR/f34e
1482         $MCREATE $DIR/f34e || error
1483         $TRUNCATE $DIR/f34e 1000 || error
1484         $CHECKSTAT -s 1000 $DIR/f34e || error
1485         $OPENFILE -f O_RDWR $DIR/f34e
1486         $CHECKSTAT -s 1000 $DIR/f34e || error
1487 }
1488 run_test 34e "create objects, some with size and some without =="
1489
1490 test_34f() { # bug 6242, 6243
1491         SIZE34F=48000
1492         rm -f $DIR/f34f
1493         $MCREATE $DIR/f34f || error
1494         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
1495         dd if=$DIR/f34f of=$TMP/f34f
1496         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
1497         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
1498         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
1499         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
1500         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
1501 }
1502 run_test 34f "read from a file with no objects until EOF ======="
1503
1504 test_35a() {
1505         cp /bin/sh $DIR/f35a
1506         chmod 444 $DIR/f35a
1507         chown $RUNAS_ID $DIR/f35a
1508         $RUNAS $DIR/f35a && error || true
1509         rm $DIR/f35a
1510 }
1511 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1512
1513 test_36a() {
1514         rm -f $DIR/f36
1515         utime $DIR/f36 || error
1516 }
1517 run_test 36a "MDS utime check (mknod, utime) ==================="
1518
1519 test_36b() {
1520         echo "" > $DIR/f36
1521         utime $DIR/f36 || error
1522 }
1523 run_test 36b "OST utime check (open, utime) ===================="
1524
1525 test_36c() {
1526         rm -f $DIR/d36/f36
1527         mkdir $DIR/d36
1528         chown $RUNAS_ID $DIR/d36
1529         $RUNAS utime $DIR/d36/f36 || error
1530 }
1531 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1532
1533 test_36d() {
1534         [ ! -d $DIR/d36 ] && test_36c
1535         echo "" > $DIR/d36/f36
1536         $RUNAS utime $DIR/d36/f36 || error
1537 }
1538 run_test 36d "non-root OST utime check (open, utime) ==========="
1539
1540 test_36e() {
1541         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
1542         mkdir -p $DIR/$tdir
1543         touch $DIR/$tdir/$tfile
1544         $RUNAS utime $DIR/$tdir/$tfile && \
1545                 error "utime worked, expected failure" || true
1546 }
1547 run_test 36e "utime on non-owned file (should return error) ===="
1548
1549 test_36f() {
1550         export LANG=C LC_LANG=C # for date language
1551
1552         DATESTR="Dec 20  2000"
1553         mkdir -p $DIR/$tdir
1554         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1555         sysctl -w lustre.fail_loc=0x80000214
1556         date; date +%s
1557         cp /etc/hosts $DIR/$tdir/$tfile
1558         sync & # write RPC generated with "current" inode timestamp, but delayed
1559         sleep 1
1560         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
1561         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
1562         cancel_lru_locks osc
1563         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
1564         date; date +%s
1565         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
1566                 echo "BEFORE: $LS_BEFORE" && \
1567                 echo "AFTER : $LS_AFTER" && \
1568                 echo "WANT  : $DATESTR" && \
1569                 error "$DIR/$tdir/$tfile timestamps changed" || true
1570 }
1571 run_test 36f "utime on file racing with OST BRW write =========="
1572
1573 export FMD_MAX_AGE=`do_facet ost1 cat $LPROC/obdfilter/*/client_cache_seconds 2> /dev/null | head -n 1`
1574 test_36g() {
1575         [ -z "$FMD_MAX_AGE" ] && skip "skip test for remote OST" && return
1576         FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1577         touch $DIR/d36/$tfile
1578         sleep $((FMD_MAX_AGE + 12))
1579         FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1580         [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
1581                 echo "AFTER : $FMD_AFTER > BEFORE $FMD_BEFORE" && \
1582                 error "fmd didn't expire after ping" || true
1583 }
1584 run_test 36g "filter mod data cache expiry ====================="
1585
1586 test_37() {
1587         mkdir -p $DIR/$tdir
1588         echo f > $DIR/$tdir/fbugfile
1589         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
1590         ls $DIR/$tdir | grep "\<fbugfile\>" && error
1591         $UMOUNT $DIR/$tdir || error
1592         rm -f $DIR/$tdir/fbugfile || error
1593 }
1594 run_test 37 "ls a mounted file system to check old content ====="
1595
1596 test_38() {
1597         o_directory $DIR/$tfile
1598 }
1599 run_test 38 "open a regular file with O_DIRECTORY =============="
1600
1601 test_39() {
1602         touch $DIR/$tfile
1603         touch $DIR/${tfile}2
1604 #       ls -l  $DIR/$tfile $DIR/${tfile}2
1605 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
1606 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
1607         sleep 2
1608         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
1609         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
1610                 echo "mtime"
1611                 ls -l  $DIR/$tfile $DIR/${tfile}2
1612                 echo "atime"
1613                 ls -lu  $DIR/$tfile $DIR/${tfile}2
1614                 echo "ctime"
1615                 ls -lc  $DIR/$tfile $DIR/${tfile}2
1616                 error "O_TRUNC didn't change timestamps"
1617         fi
1618 }
1619 run_test 39 "mtime changed on create ==========================="
1620
1621 test_40() {
1622         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1623         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1624         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1625 }
1626 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1627
1628 test_41() {
1629         # bug 1553
1630         small_write $DIR/f41 18
1631 }
1632 run_test 41 "test small file write + fstat ====================="
1633
1634 count_ost_writes() {
1635         cat $LPROC/osc/*/stats |
1636             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1637 }
1638
1639 # decent default
1640 WRITEBACK_SAVE=500
1641 DIRTY_RATIO_SAVE=40
1642 MAX_DIRTY_RATIO=50
1643 BG_DIRTY_RATIO_SAVE=10
1644 MAX_BG_DIRTY_RATIO=25
1645
1646 start_writeback() {
1647         trap 0
1648         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
1649         # dirty_ratio, dirty_background_ratio
1650         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1651                 echo $WRITEBACK_SAVE > /proc/sys/vm/dirty_writeback_centisecs
1652                 echo $BG_DIRTY_RATIO_SAVE > /proc/sys/vm/dirty_background_ratio
1653                 echo $DIRTY_RATIO_SAVE > /proc/sys/vm/dirty_ratio
1654         else
1655                 # if file not here, we are a 2.4 kernel
1656                 kill -CONT `pidof kupdated`
1657         fi
1658 }
1659
1660 stop_writeback() {
1661         # setup the trap first, so someone cannot exit the test at the
1662         # exact wrong time and mess up a machine
1663         trap start_writeback EXIT
1664         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1665         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1666                 WRITEBACK_SAVE=`cat /proc/sys/vm/dirty_writeback_centisecs`
1667                 echo 0 > /proc/sys/vm/dirty_writeback_centisecs
1668                 # save and increase /proc/sys/vm/dirty_ratio
1669                 DIRTY_RATIO_SAVE=`cat /proc/sys/vm/dirty_ratio`
1670                 echo $MAX_DIRTY_RATIO > /proc/sys/vm/dirty_ratio
1671                 # save and increase /proc/sys/vm/dirty_background_ratio
1672                 BG_DIRTY_RATIO_SAVE=`cat /proc/sys/vm/dirty_background_ratio`
1673                 echo $MAX_BG_DIRTY_RATIO > /proc/sys/vm/dirty_background_ratio
1674         else
1675                 # if file not here, we are a 2.4 kernel
1676                 kill -STOP `pidof kupdated`
1677         fi
1678 }
1679
1680 # ensure that all stripes have some grant before we test client-side cache
1681 setup_test42() {
1682         [ "$SETUP_TEST42" ] && return
1683         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1684                 dd if=/dev/zero of=$i bs=4k count=1
1685                 rm $i
1686         done
1687         SETUP_TEST42=DONE
1688 }
1689
1690 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1691 # file truncation, and file removal.
1692 test_42a() {
1693         setup_test42
1694         cancel_lru_locks osc
1695         stop_writeback
1696         sync; sleep 1; sync # just to be safe
1697         BEFOREWRITES=`count_ost_writes`
1698         grep "[0-9]" $LPROC/osc/*[oO][sS][cC][_-]*/cur_grant_bytes
1699         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1700         AFTERWRITES=`count_ost_writes`
1701         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1702                 error "$BEFOREWRITES < $AFTERWRITES"
1703         start_writeback
1704 }
1705 run_test 42a "ensure that we don't flush on close =============="
1706
1707 test_42b() {
1708         setup_test42
1709         cancel_lru_locks osc
1710         stop_writeback
1711         sync
1712         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1713         BEFOREWRITES=`count_ost_writes`
1714         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1715         AFTERWRITES=`count_ost_writes`
1716         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1717                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
1718         fi
1719         BEFOREWRITES=`count_ost_writes`
1720         sync || error "sync: $?"
1721         AFTERWRITES=`count_ost_writes`
1722         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1723                 error "$BEFOREWRITES < $AFTERWRITES on sync"
1724         fi
1725         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1726         start_writeback
1727         return 0
1728 }
1729 run_test 42b "test destroy of file with cached dirty data ======"
1730
1731 # if these tests just want to test the effect of truncation,
1732 # they have to be very careful.  consider:
1733 # - the first open gets a {0,EOF}PR lock
1734 # - the first write conflicts and gets a {0, count-1}PW
1735 # - the rest of the writes are under {count,EOF}PW
1736 # - the open for truncate tries to match a {0,EOF}PR
1737 #   for the filesize and cancels the PWs.
1738 # any number of fixes (don't get {0,EOF} on open, match
1739 # composite locks, do smarter file size management) fix
1740 # this, but for now we want these tests to verify that
1741 # the cancellation with truncate intent works, so we
1742 # start the file with a full-file pw lock to match against
1743 # until the truncate.
1744 trunc_test() {
1745         test=$1
1746         file=$DIR/$test
1747         offset=$2
1748         cancel_lru_locks osc
1749         stop_writeback
1750         # prime the file with 0,EOF PW to match
1751         touch $file
1752         $TRUNCATE $file 0
1753         sync; sync
1754         # now the real test..
1755         dd if=/dev/zero of=$file bs=1024 count=100
1756         BEFOREWRITES=`count_ost_writes`
1757         $TRUNCATE $file $offset
1758         cancel_lru_locks osc
1759         AFTERWRITES=`count_ost_writes`
1760         start_writeback
1761 }
1762
1763 test_42c() {
1764         trunc_test 42c 1024
1765         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1766             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
1767         rm $file
1768 }
1769 run_test 42c "test partial truncate of file with cached dirty data"
1770
1771 test_42d() {
1772         trunc_test 42d 0
1773         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1774             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1775         rm $file
1776 }
1777 run_test 42d "test complete truncate of file with cached dirty data"
1778
1779 test_43() {
1780         cp -p /bin/ls $DIR/$tdir/$tfile
1781         multiop $DIR/$tdir/$tfile Ow_c &
1782         pid=$!
1783         # give multiop a chance to open
1784         sleep 1
1785
1786         $DIR/$tdir/$tfile && error || true
1787         kill -USR1 $pid
1788 }
1789 run_test 43 "execution of file opened for write should return -ETXTBSY"
1790
1791 test_43a() {
1792         mkdir -p $DIR/d43
1793         cp -p `which multiop` $DIR/d43/multiop
1794         $DIR/d43/multiop $TMP/test43.junk O_c &
1795         MULTIPID=$!
1796         sleep 1
1797         multiop $DIR/d43/multiop Oc && error "expected error, got success"
1798         kill -USR1 $MULTIPID || return 2
1799         wait $MULTIPID || return 3
1800         rm $TMP/test43.junk
1801 }
1802 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
1803
1804 test_43b() {
1805         mkdir -p $DIR/d43
1806         cp -p `which multiop` $DIR/d43/multiop
1807         $DIR/d43/multiop $TMP/test43.junk O_c &
1808         MULTIPID=$!
1809         sleep 1
1810         truncate $DIR/d43/multiop 0 && error "expected error, got success"
1811         kill -USR1 $MULTIPID || return 2
1812         wait $MULTIPID || return 3
1813         rm $TMP/test43.junk
1814 }
1815 run_test 43b "truncate of file being executed should return -ETXTBSY"
1816
1817 test_43c() {
1818         local testdir="$DIR/d43c"
1819         mkdir -p $testdir
1820         cp $SHELL $testdir/
1821         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
1822                 ( cd $testdir && md5sum -c)
1823 }
1824 run_test 43c "md5sum of copy into lustre========================"
1825
1826 test_44() {
1827         [  "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
1828         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
1829         dd if=$DIR/f1 of=/dev/null bs=4k count=1
1830 }
1831 run_test 44 "zero length read from a sparse stripe ============="
1832
1833 test_44a() {
1834     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
1835                          awk '{print $2}'`
1836     [ -z "$nstripe" ] && skip "can't get stripe info" && return
1837     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
1838     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
1839                       awk '{print $2}'`
1840     if [ $nstripe -eq 0 ] ; then
1841         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
1842     fi
1843
1844     OFFSETS="0 $((stride/2)) $((stride-1))"
1845     for offset in $OFFSETS ; do
1846       for i in `seq 0 $((nstripe-1))`; do
1847         rm -f $DIR/d44a
1848         local GLOBALOFFSETS=""
1849         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
1850         ll_sparseness_write $DIR/d44a $size  || error "ll_sparseness_write"
1851         GLOBALOFFSETS="$GLOBALOFFSETS $size"
1852         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1853                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1854
1855         for j in `seq 0 $((nstripe-1))`; do
1856             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
1857             ll_sparseness_write $DIR/d44a $size || error "ll_sparseness_write"
1858             GLOBALOFFSETS="$GLOBALOFFSETS $size"
1859         done
1860         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1861                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1862       done
1863     done
1864 }
1865 run_test 44a "test sparse pwrite ==============================="
1866
1867 dirty_osc_total() {
1868         tot=0
1869         for d in $LPROC/osc/*/cur_dirty_bytes; do
1870                 tot=$(($tot + `cat $d`))
1871         done
1872         echo $tot
1873 }
1874 do_dirty_record() {
1875         before=`dirty_osc_total`
1876         echo executing "\"$*\""
1877         eval $*
1878         after=`dirty_osc_total`
1879         echo before $before, after $after
1880 }
1881 test_45() {
1882         f="$DIR/f45"
1883         # Obtain grants from OST if it supports it
1884         echo blah > ${f}_grant
1885         stop_writeback
1886         sync
1887         do_dirty_record "echo blah > $f"
1888         [ $before -eq $after ] && error "write wasn't cached"
1889         do_dirty_record "> $f"
1890         [ $before -gt $after ] || error "truncate didn't lower dirty count"
1891         do_dirty_record "echo blah > $f"
1892         [ $before -eq $after ] && error "write wasn't cached"
1893         do_dirty_record "sync"
1894         [ $before -gt $after ] || error "writeback didn't lower dirty count"
1895         do_dirty_record "echo blah > $f"
1896         [ $before -eq $after ] && error "write wasn't cached"
1897         do_dirty_record "cancel_lru_locks osc"
1898         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
1899         start_writeback
1900 }
1901 run_test 45 "osc io page accounting ============================"
1902
1903 page_size() {
1904         getconf PAGE_SIZE
1905 }
1906
1907 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
1908 # test tickles a bug where re-dirtying a page was failing to be mapped to the
1909 # objects offset and an assert hit when an rpc was built with 1023's mapped 
1910 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
1911 test_46() {
1912         f="$DIR/f46"
1913         stop_writeback
1914         sync
1915         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1916         sync
1917         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
1918         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1919         sync
1920         start_writeback
1921 }
1922 run_test 46 "dirtying a previously written page ================"
1923
1924 # Check that device nodes are created and then visible correctly (#2091)
1925 test_47() {
1926         cmknod $DIR/test_47_node || error
1927 }
1928 run_test 47 "Device nodes check ================================"
1929
1930 test_48a() { # bug 2399
1931         check_kernel_version 34 || return 0
1932         mkdir -p $DIR/d48a
1933         cd $DIR/d48a
1934         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
1935         mkdir $DIR/d48a || error "recreate directory failed"
1936         touch foo || error "'touch foo' failed after recreating cwd"
1937         mkdir bar || error "'mkdir foo' failed after recreating cwd"
1938         if check_kernel_version 44; then
1939                 touch .foo || error "'touch .foo' failed after recreating cwd"
1940                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
1941         fi
1942         ls . > /dev/null || error "'ls .' failed after recreating cwd"
1943         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
1944         cd . || error "'cd .' failed after recreating cwd"
1945         mkdir . && error "'mkdir .' worked after recreating cwd"
1946         rmdir . && error "'rmdir .' worked after recreating cwd"
1947         ln -s . baz || error "'ln -s .' failed after recreating cwd"
1948         cd .. || error "'cd ..' failed after recreating cwd"
1949 }
1950 run_test 48a "Access renamed working dir (should return errors)="
1951
1952 test_48b() { # bug 2399
1953         check_kernel_version 34 || return 0
1954         mkdir -p $DIR/d48b
1955         cd $DIR/d48b
1956         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
1957         touch foo && error "'touch foo' worked after removing cwd"
1958         mkdir foo && error "'mkdir foo' worked after removing cwd"
1959         if check_kernel_version 44; then
1960                 touch .foo && error "'touch .foo' worked after removing cwd"
1961                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
1962         fi
1963         ls . > /dev/null && error "'ls .' worked after removing cwd"
1964         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
1965         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
1966         mkdir . && error "'mkdir .' worked after removing cwd"
1967         rmdir . && error "'rmdir .' worked after removing cwd"
1968         ln -s . foo && error "'ln -s .' worked after removing cwd"
1969         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
1970 }
1971 run_test 48b "Access removed working dir (should return errors)="
1972
1973 test_48c() { # bug 2350
1974         check_kernel_version 36 || return 0
1975         #sysctl -w lnet.debug=-1
1976         #set -vx
1977         mkdir -p $DIR/d48c/dir
1978         cd $DIR/d48c/dir
1979         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
1980         $TRACE touch foo && error "'touch foo' worked after removing cwd"
1981         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
1982         if check_kernel_version 44; then
1983                 touch .foo && error "'touch .foo' worked after removing cwd"
1984                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
1985         fi
1986         $TRACE ls . && error "'ls .' worked after removing cwd"
1987         $TRACE ls .. || error "'ls ..' failed after removing cwd"
1988         is_patchless || ( $TRACE cd . && error "'cd .' worked after removing cwd" )
1989         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
1990         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
1991         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
1992         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
1993 }
1994 run_test 48c "Access removed working subdir (should return errors)"
1995
1996 test_48d() { # bug 2350
1997         check_kernel_version 36 || return 0
1998         #sysctl -w lnet.debug=-1
1999         #set -vx
2000         mkdir -p $DIR/d48d/dir
2001         cd $DIR/d48d/dir
2002         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2003         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
2004         $TRACE touch foo && error "'touch foo' worked after removing parent"
2005         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
2006         if check_kernel_version 44; then
2007                 touch .foo && error "'touch .foo' worked after removing parent"
2008                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
2009         fi
2010         $TRACE ls . && error "'ls .' worked after removing parent"
2011         $TRACE ls .. && error "'ls ..' worked after removing parent"
2012         is_patchless || ( $TRACE cd . && error "'cd .' worked after recreate parent" )
2013         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
2014         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
2015         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
2016         is_patchless || ( $TRACE cd .. && error "'cd ..' worked after removing parent" || true )
2017 }
2018 run_test 48d "Access removed parent subdir (should return errors)"
2019
2020 test_48e() { # bug 4134
2021         check_kernel_version 41 || return 0
2022         #sysctl -w lnet.debug=-1
2023         #set -vx
2024         mkdir -p $DIR/d48e/dir
2025         cd $DIR/d48e/dir
2026         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
2027         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
2028         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
2029         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
2030         # On a buggy kernel addition of "touch foo" after cd .. will
2031         # produce kernel oops in lookup_hash_it
2032         touch ../foo && error "'cd ..' worked after recreate parent"
2033         cd $DIR
2034         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
2035 }
2036 run_test 48e "Access to recreated parent subdir (should return errors)"
2037
2038 test_50() {
2039         # bug 1485
2040         mkdir $DIR/d50
2041         cd $DIR/d50
2042         ls /proc/$$/cwd || error
2043 }
2044 run_test 50 "special situations: /proc symlinks  ==============="
2045
2046 test_51() {
2047         # bug 1516 - create an empty entry right after ".." then split dir
2048         mkdir $DIR/d51
2049         touch $DIR/d51/foo
2050         $MCREATE $DIR/d51/bar
2051         rm $DIR/d51/foo
2052         createmany -m $DIR/d51/longfile 201
2053         FNUM=202
2054         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
2055                 $MCREATE $DIR/d51/longfile$FNUM
2056                 FNUM=$(($FNUM + 1))
2057                 echo -n "+"
2058         done
2059         echo
2060         ls -l $DIR/d51 > /dev/null || error
2061 }
2062 run_test 51 "special situations: split htree with empty entry =="
2063
2064 export NUMTEST=70000
2065 test_51b() {
2066         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2067         [ $NUMFREE -lt 21000 ] && \
2068                 skip "not enough free inodes ($NUMFREE)" && \
2069                 return
2070
2071         check_kernel_version 40 || NUMTEST=31000
2072         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
2073
2074         mkdir -p $DIR/d51b
2075         createmany -d $DIR/d51b/t- $NUMTEST
2076 }
2077 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
2078
2079 test_51c() {
2080         [ ! -d $DIR/d51b ] && skip "$DIR/51b missing" && \
2081                 return
2082
2083         unlinkmany -d $DIR/d51b/t- $NUMTEST
2084 }
2085 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
2086
2087 test_51d() {
2088         [  "$OSTCOUNT" -lt "3" ] && skip "skipping test with few OSTs" && return
2089         mkdir -p $DIR/d51d
2090         createmany -o $DIR/d51d/t- 1000
2091         $LFS getstripe $DIR/d51d > $TMP/files
2092         for N in `seq 0 $((OSTCOUNT - 1))`; do
2093             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
2094             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
2095             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
2096         done
2097         unlinkmany $DIR/d51d/t- 1000
2098
2099         NLAST=0
2100         for N in `seq 1 $((OSTCOUNT - 1))`; do
2101             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
2102                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2103             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
2104                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2105             
2106             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
2107                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2108             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
2109                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2110             NLAST=$N
2111         done
2112 }
2113 run_test 51d "check object distribution ===================="
2114
2115 test_52a() {
2116         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
2117         mkdir -p $DIR/d52a
2118         touch $DIR/d52a/foo
2119         chattr =a $DIR/d52a/foo || error "chattr =a failed"
2120         echo bar >> $DIR/d52a/foo || error "append bar failed"
2121         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
2122         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
2123         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
2124         echo foo >> $DIR/d52a/foo || error "append foo failed"
2125         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
2126         lsattr $DIR/d52a/foo | egrep -q "^-+a-+ $DIR/d52a/foo" || error "lsattr"
2127         chattr -a $DIR/d52a/foo || error "chattr -a failed"
2128
2129         rm -fr $DIR/d52a || error "cleanup rm failed"
2130 }
2131 run_test 52a "append-only flag test (should return errors) ====="
2132
2133 test_52b() {
2134         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
2135         mkdir -p $DIR/d52b
2136         touch $DIR/d52b/foo
2137         chattr =i $DIR/d52b/foo || error
2138         cat test > $DIR/d52b/foo && error
2139         cp /etc/hosts $DIR/d52b/foo && error
2140         rm -f $DIR/d52b/foo 2>/dev/null && error
2141         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error
2142         echo foo >> $DIR/d52b/foo && error
2143         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error
2144         [ -f $DIR/d52b/foo ] || error
2145         [ -f $DIR/d52b/foo_ren ] && error
2146         lsattr $DIR/d52b/foo | egrep -q "^-+i-+ $DIR/d52b/foo" || error
2147         chattr -i $DIR/d52b/foo || error
2148
2149         rm -fr $DIR/d52b || error
2150 }
2151 run_test 52b "immutable flag test (should return errors) ======="
2152
2153 test_52c() { # 12848 simulating client < 1.4.7
2154         [ -f $DIR/d52c/foo ] && chattr -i $DIR/d52b/foo
2155         mkdir -p $DIR/d52c
2156         touch $DIR/d52c/foo
2157         # skip MDS_BFLAG_EXT_FLAGS in mdc_getattr_pack
2158 #define OBD_FAIL_MDC_OLD_EXT_FLAGS       0x802
2159         sysctl -w lustre.fail_loc=0x802
2160         chattr =i $DIR/d52c/foo || error
2161         lsattr $DIR/d52c/foo | egrep -q "^-+i-+ $DIR/d52c/foo" || error
2162         chattr -i $DIR/d52c/foo || error
2163         sysctl -w lustre.fail_loc=0
2164
2165         rm -fr $DIR/d52c || error
2166 }
2167 run_test 52c "immutable flag test for client < 1.4.7 ======="
2168
2169 test_53() {
2170         remote_mds && skip "remote MDS" && return
2171         
2172         for i in `ls -d $LPROC/osc/*-osc 2> /dev/null` ; do
2173                 ostname=`basename $i | cut -d - -f 1-2`
2174                 ost_last=`cat $LPROC/obdfilter/$ostname/last_id`
2175                 mds_last=`cat $i/prealloc_last_id`
2176                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2177                 if [ $ost_last != $mds_last ]; then
2178                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2179                 fi
2180         done
2181 }
2182 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
2183
2184 test_54a() {
2185         [ ! -f "$SOCKETSERVER" ] && skip "no socketserver, skipping" && return
2186         [ ! -f "$SOCKETCLIENT" ] && skip "no socketclient, skipping" && return
2187         $SOCKETSERVER $DIR/socket
2188         $SOCKETCLIENT $DIR/socket || error
2189         $MUNLINK $DIR/socket
2190 }
2191 run_test 54a "unix domain socket test =========================="
2192
2193 test_54b() {
2194         f="$DIR/f54b"
2195         mknod $f c 1 3
2196         chmod 0666 $f
2197         dd if=/dev/zero of=$f bs=`page_size` count=1 
2198 }
2199 run_test 54b "char device works in lustre ======================"
2200
2201 find_loop_dev() {
2202         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
2203         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
2204         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
2205
2206         for i in `seq 3 7`; do
2207                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
2208                 LOOPDEV=$LOOPBASE$i
2209                 LOOPNUM=$i
2210                 break
2211         done
2212 }
2213
2214 test_54c() {
2215         tfile="$DIR/f54c"
2216         tdir="$DIR/d54c"
2217         loopdev="$DIR/loop54c"
2218
2219         find_loop_dev 
2220         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
2221         mknod $loopdev b 7 $LOOPNUM
2222         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
2223         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
2224         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
2225         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
2226         mkdir -p $tdir
2227         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
2228         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
2229         df $tdir
2230         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
2231         $UMOUNT $tdir
2232         losetup -d $loopdev
2233         rm $loopdev
2234 }
2235 run_test 54c "block device works in lustre ====================="
2236
2237 test_54d() {
2238         f="$DIR/f54d"
2239         string="aaaaaa"
2240         mknod $f p
2241         [ "$string" = `echo $string > $f | cat $f` ] || error
2242 }
2243 run_test 54d "fifo device works in lustre ======================"
2244
2245 test_54e() {
2246         check_kernel_version 46 || return 0
2247         f="$DIR/f54e"
2248         string="aaaaaa"
2249         cp -aL /dev/console $f
2250         echo $string > $f || error
2251 }
2252 run_test 54e "console/tty device works in lustre ======================"
2253
2254 check_fstype() {
2255         grep -q $FSTYPE /proc/filesystems && return 1
2256         modprobe $FSTYPE
2257         grep -q $FSTYPE /proc/filesystems && return 1
2258         insmod ../$FSTYPE/$FSTYPE.o
2259         grep -q $FSTYPE /proc/filesystems && return 1
2260         insmod ../$FSTYPE/$FSTYPE.ko
2261         grep -q $FSTYPE /proc/filesystems && return 1
2262         return 0
2263 }
2264
2265 test_55() {
2266         rm -rf $DIR/d55
2267         mkdir $DIR/d55
2268         check_fstype && skip "can't find fs $FSTYPE" && return
2269         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
2270         touch $DIR/d55/foo
2271         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
2272         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
2273         echo "check for $EXT2_DEV. Please wait..."
2274         rm -rf $DIR/d55/*
2275         $UMOUNT $DIR/d55 || error "unmounting"
2276 }
2277 run_test 55 "check iopen_connect_dentry() ======================"
2278
2279 test_56() {
2280         rm -rf $DIR/d56
2281         $SETSTRIPE -d $DIR
2282         mkdir $DIR/d56
2283         mkdir $DIR/d56/dir
2284         NUMFILES=3
2285         NUMFILESx2=$(($NUMFILES * 2))
2286         for i in `seq 1 $NUMFILES` ; do
2287                 touch $DIR/d56/file$i
2288                 touch $DIR/d56/dir/file$i
2289         done
2290
2291         # test lfs getstripe with --recursive
2292         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
2293         [ $FILENUM -eq $NUMFILESx2 ] || error \
2294                 "lfs getstripe --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
2295         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
2296         [ $FILENUM -eq $NUMFILES ] || error \
2297                 "lfs getstripe $DIR/d56 without --recursive wrong: found $FILENUM, expected $NUMFILES"
2298         echo "lfs getstripe --recursive passed."
2299
2300         # test lfs getstripe with file instead of dir
2301         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
2302         [ $FILENUM  -eq 1 ] || error \
2303                  "lfs getstripe $DIR/d56/file1 wrong:found $FILENUM, expected 1"
2304         echo "lfs getstripe file passed."
2305
2306         #test lfs getstripe with --verbose
2307         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||\
2308                 error "lfs getstripe --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2309         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] || error \
2310                 "lfs getstripe $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2311         echo "lfs getstripe --verbose passed."
2312
2313         #test lfs getstripe with --obd
2314         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2315                 error "lfs getstripe --obd wrong_uuid should return error message"
2316
2317         [  "$OSTCOUNT" -lt 2 ] && \
2318                 skip "skipping other lfs getstripe --obd test" && return
2319         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1[    ]/p' | wc -l`
2320         OBDUUID=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1:/p' | awk '{print $2}'`
2321         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | wc -l`
2322         [ $FOUND -eq $FILENUM ] || \
2323                 error "lfs getstripe --obd wrong: found $FOUND, expected $FILENUM"
2324         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 | sed '/^[   ]*1[    ]/d' |\
2325                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] || \
2326                 error "lfs getstripe --obd wrong: should not show file on other obd"
2327         echo "lfs getstripe --obd passed."
2328 }
2329 run_test 56 "check lfs getstripe ===================================="
2330
2331 NUMFILES=3
2332 NUMDIRS=3
2333 setup_56() {
2334         LOCAL_NUMFILES=$1
2335         LOCAL_NUMDIRS=$2
2336         if [ ! -d "$DIR/${tdir}g" ] ; then
2337                 mkdir -p $DIR/${tdir}g
2338                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2339                         touch $DIR/${tdir}g/file$i
2340                 done
2341                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2342                         mkdir $DIR/${tdir}g/dir$i
2343                         for j in `seq 1 $LOCAL_NUMFILES` ; do
2344                                 touch $DIR/${tdir}g/dir$i/file$j
2345                         done
2346                 done
2347         fi
2348 }
2349
2350 setup_56_special() {
2351         LOCAL_NUMFILES=$1
2352         LOCAL_NUMDIRS=$2
2353         TDIR=$DIR/${tdir}g
2354         setup_56 $1 $2
2355         if [ ! -e "$TDIR/loop1b" ] ; then
2356                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2357                         mknod $TDIR/loop${i}b b 7 $i
2358                         mknod $TDIR/null${i}c c 1 3
2359                         ln -s $TDIR/file1 $TDIR/link${i}l
2360                 done
2361                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2362                         mknod $TDIR/dir$i/loop${i}b b 7 $i
2363                         mknod $TDIR/dir$i/null${i}c c 1 3
2364                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
2365                 done
2366         fi
2367 }
2368
2369 test_56g() {
2370         $LSTRIPE -d $DIR
2371
2372         setup_56 $NUMFILES $NUMDIRS
2373
2374         EXPECTED=$(($NUMDIRS + 2))
2375         # test lfs find with -name
2376         for i in `seq 1 $NUMFILES` ; do
2377                 NUMS=`$LFIND -name "*$i" $DIR/${tdir}g | wc -l`
2378                 [ $NUMS -eq $EXPECTED ] || error \
2379                         "lfs find -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2380         done
2381         echo "lfs find -name passed."
2382 }
2383 run_test 56g "check lfs find -name ============================="
2384
2385 test_56h() {
2386         $LSTRIPE -d $DIR
2387
2388         setup_56 $NUMFILES $NUMDIRS
2389
2390         EXPECTED=$((($NUMDIRS+1)*($NUMFILES-1)+$NUMFILES))
2391         # test lfs find with ! -name
2392         for i in `seq 1 $NUMFILES` ; do
2393                 NUMS=`$LFIND ! -name "*$i" $DIR/${tdir}g | wc -l`
2394                 [ $NUMS -eq $EXPECTED ] || error \
2395                         "lfs find ! -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2396         done
2397         echo "lfs find ! -name passed."
2398 }
2399 run_test 56h "check lfs find ! -name ============================="
2400
2401 test_56i() {
2402        tdir=${tdir}i
2403        mkdir -p $DIR/$tdir
2404        UUID=`$GETSTRIPE $DIR/$tdir | awk '/0: / { print $2 }'`
2405        OUT="`$LFIND -ost $UUID $DIR/$tdir`"
2406        [ "$OUT" ] && error "$LFIND returned directory '$OUT'" || true
2407 }
2408 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
2409
2410 test_56j() {
2411         setup_56_special $NUMFILES $NUMDIRS
2412
2413         EXPECTED=$((NUMDIRS+1))
2414         NUMS=`$LFIND -type d $DIR/${tdir}g | wc -l`
2415         [ $NUMS -eq $EXPECTED ] || \
2416                 error "lfs find -type d $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2417 }
2418 run_test 56j "check lfs find -type d ============================="
2419
2420 test_56k() {
2421         setup_56_special $NUMFILES $NUMDIRS
2422
2423         EXPECTED=$(((NUMDIRS+1) * NUMFILES))
2424         NUMS=`$LFIND -type f $DIR/${tdir}g | wc -l`
2425         [ $NUMS -eq $EXPECTED ] || \
2426                 error "lfs find -type f $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2427 }
2428 run_test 56k "check lfs find -type f ============================="
2429
2430 test_56l() {
2431         setup_56_special $NUMFILES $NUMDIRS
2432
2433         EXPECTED=$((NUMDIRS + NUMFILES))
2434         NUMS=`$LFIND -type b $DIR/${tdir}g | wc -l`
2435         [ $NUMS -eq $EXPECTED ] || \
2436                 error "lfs find -type b $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2437 }
2438 run_test 56l "check lfs find -type b ============================="
2439
2440 test_56m() {
2441         setup_56_special $NUMFILES $NUMDIRS
2442
2443         EXPECTED=$((NUMDIRS + NUMFILES))
2444         NUMS=`$LFIND -type c $DIR/${tdir}g | wc -l`
2445         [ $NUMS -eq $EXPECTED ] || \
2446                 error "lfs find -type c $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2447 }
2448 run_test 56m "check lfs find -type c ============================="
2449
2450 test_56n() {
2451         setup_56_special $NUMFILES $NUMDIRS
2452
2453         EXPECTED=$((NUMDIRS + NUMFILES))
2454         NUMS=`$LFIND -type l $DIR/${tdir}g | wc -l`
2455         [ $NUMS -eq $EXPECTED ] || \
2456                 error "lfs find -type l $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2457 }
2458 run_test 56n "check lfs find -type l ============================="
2459
2460 test_56o() {
2461         setup_56 $NUMFILES $NUMDIRS
2462         TDIR=$DIR/${tdir}g
2463
2464         utime $TDIR/file1 > /dev/null || error
2465         utime $TDIR/file2 > /dev/null || error
2466         utime $TDIR/dir1 > /dev/null || error
2467         utime $TDIR/dir2 > /dev/null || error
2468         utime $TDIR/dir1/file1 > /dev/null || error
2469
2470         EXPECTED=5
2471         NUMS=`$LFIND -mtime +1 $TDIR | wc -l`
2472         [ $NUMS -eq $EXPECTED ] || \
2473                 error "lfs find -mtime $TDIR wrong: found $NUMS, expected $EXPECTED"
2474 }
2475 run_test 56o "check lfs find -mtime for old files =========================="
2476
2477 test_57a() {
2478         remote_mds && skip "remote MDS" && return
2479
2480         for DEV in `cat $LPROC/mds/*/mntdev`; do
2481                 dumpe2fs -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
2482                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2483                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2484                 rm $TMP/t57a.dump
2485         done
2486 }
2487 run_test 57a "verify MDS filesystem created with large inodes =="
2488
2489 test_57b() {
2490         FILECOUNT=100
2491         FILE1=$DIR/d57b/f1
2492         FILEN=$DIR/d57b/f$FILECOUNT
2493         rm -rf $DIR/d57b || error "removing $DIR/d57b"
2494         mkdir -p $DIR/d57b || error "creating $DIR/d57b"
2495         echo "mcreating $FILECOUNT files"
2496         createmany -m $DIR/d57b/f 1 $FILECOUNT || \
2497                 error "creating files in $DIR/d57b"
2498
2499         # verify that files do not have EAs yet
2500         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2501         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2502
2503         MDSFREE="`cat $LPROC/mds/*/kbytesfree 2> /dev/null`"
2504         MDCFREE="`cat $LPROC/mdc/*/kbytesfree | head -n 1`"
2505         echo "opening files to create objects/EAs"
2506         for FILE in `seq -f $DIR/d57b/f%g 1 $FILECOUNT`; do
2507                 $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
2508         done
2509
2510         # verify that files have EAs now
2511         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2512         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2513
2514         sleep 1 # make sure we get new statfs data
2515         MDSFREE2="`cat $LPROC/mds/*/kbytesfree 2> /dev/null`"
2516         MDCFREE2="`cat $LPROC/mdc/*/kbytesfree | head -n 1`"
2517         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
2518                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
2519                         error "MDC before $MDCFREE != after $MDCFREE2"
2520                 else
2521                         echo "MDC before $MDCFREE != after $MDCFREE2"
2522                         echo "unable to confirm if MDS has large inodes"
2523                 fi
2524         fi
2525         rm -rf $DIR/d57b
2526 }
2527 run_test 57b "default LOV EAs are stored inside large inodes ==="
2528
2529 test_58() {
2530     [ -z "$(which wiretest 2>/dev/null)" ] && skip "could not find wiretest" && return
2531     wiretest
2532 }
2533 run_test 58 "verify cross-platform wire constants =============="
2534
2535 test_59() {
2536         echo "touch 130 files"
2537         createmany -o $DIR/f59- 130
2538         echo "rm 130 files"
2539         unlinkmany $DIR/f59- 130
2540         sync
2541         sleep 2
2542         # wait for commitment of removal
2543 }
2544 run_test 59 "verify cancellation of llog records async ========="
2545
2546 TEST60_HEAD="test_60 run $RANDOM"
2547 test_60() {
2548         [ ! -f run-llog.sh ] && skip "missing subtest run-llog.sh" && return
2549         log "$TEST60_HEAD - from kernel mode"
2550         sh run-llog.sh
2551 }
2552 run_test 60 "llog sanity tests run from kernel module =========="
2553
2554 test_60b() { # bug 6411
2555         dmesg > $DIR/$tfile
2556         LLOG_COUNT=`dmesg | grep -A 1000 "$TEST60_HEAD" | grep -c llog_test`
2557         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages"|| true
2558 }
2559 run_test 60b "limit repeated messages from CERROR/CWARN ========"
2560
2561 test_60c() {
2562         echo "create 5000 files" 
2563         createmany -o $DIR/f60c- 5000
2564         #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
2565         sysctl -w lustre.fail_loc=0x80000137
2566         unlinkmany $DIR/f60c- 5000
2567 }
2568 run_test 60c "unlink file when mds full"
2569
2570 test_61() {
2571         f="$DIR/f61"
2572         dd if=/dev/zero of=$f bs=`page_size` count=1
2573         cancel_lru_locks osc
2574         multiop $f OSMWUc || error
2575         sync
2576 }
2577 run_test 61 "mmap() writes don't make sync hang ================"
2578
2579 # bug 2330 - insufficient obd_match error checking causes LBUG
2580 test_62() {
2581         f="$DIR/f62"
2582         echo foo > $f
2583         cancel_lru_locks osc
2584         #define OBD_FAIL_OSC_MATCH 0x405
2585         sysctl -w lustre.fail_loc=0x405
2586         cat $f && error "cat succeeded, expect -EIO"
2587         sysctl -w lustre.fail_loc=0
2588 }
2589 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
2590 # match every page all of the time.
2591 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2592
2593 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2594 test_63() {
2595         MAX_DIRTY_MB=`cat $LPROC/osc/*/max_dirty_mb | head -n 1`
2596         for i in $LPROC/osc/*/max_dirty_mb ; do
2597                 echo 0 > $i
2598         done
2599         for i in `seq 10` ; do
2600                 dd if=/dev/zero of=$DIR/f63 bs=8k &
2601                 sleep 5
2602                 kill $!
2603                 sleep 1
2604         done
2605
2606         for i in $LPROC/osc/*/max_dirty_mb ; do
2607                 echo $MAX_DIRTY_MB > $i
2608         done
2609         rm -f $DIR/f63 || true
2610 }
2611 run_test 63 "Verify oig_wait interruption does not crash ======="
2612
2613 # bug 2248 - async write errors didn't return to application on sync
2614 # bug 3677 - async write errors left page locked
2615 test_63b() {
2616         debugsave
2617         sysctl -w lnet.debug=-1
2618
2619         # ensure we have a grant to do async writes
2620         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
2621         rm $DIR/$tfile
2622
2623         #define OBD_FAIL_OSC_BRW_PREP_REQ 0x406
2624         sysctl -w lustre.fail_loc=0x80000406
2625         multiop $DIR/$tfile Owy && \
2626                 error "sync didn't return ENOMEM"
2627         sync; sleep 2; sync     # do a real sync this time to flush page
2628         grep locked $LPROC/llite/*/dump_page_cache && \
2629                 error "locked page left in cache after async error" || true
2630         debugrestore
2631 }
2632 run_test 63b "async write errors should be returned to fsync ==="
2633
2634 test_64a () {
2635         df $DIR
2636         grep "[0-9]" $LPROC/osc/*[oO][sS][cC][_-]*/cur*
2637 }
2638 run_test 64a "verify filter grant calculations (in kernel) ====="
2639
2640 test_64b () {
2641         [ ! -f oos.sh ] && skip "missing subtest oos.sh" && return
2642         sh oos.sh $MOUNT
2643 }
2644 run_test 64b "check out-of-space detection on client ==========="
2645
2646 # bug 1414 - set/get directories' stripe info
2647 test_65a() {
2648         mkdir -p $DIR/d65
2649         touch $DIR/d65/f1
2650         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
2651 }
2652 run_test 65a "directory with no stripe info ===================="
2653
2654 test_65b() {
2655         mkdir -p $DIR/d65
2656         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
2657         touch $DIR/d65/f2
2658         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
2659 }
2660 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
2661
2662 test_65c() {
2663         if [ $OSTCOUNT -gt 1 ]; then
2664                 mkdir -p $DIR/d65
2665                 $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 4)) -i 1 \
2666                         -c $(($OSTCOUNT - 1)) || error "setstripe"
2667                 touch $DIR/d65/f3
2668                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
2669         fi
2670 }
2671 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
2672
2673 test_65d() {
2674         mkdir -p $DIR/d65
2675         [ $STRIPECOUNT -le 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1))
2676         $SETSTRIPE $DIR/d65 -s $STRIPESIZE -c $sc || error "setstripe"
2677         touch $DIR/d65/f4 $DIR/d65/f5
2678         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
2679 }
2680 run_test 65d "directory setstripe $STRIPESIZE -1 stripe_count =============="
2681
2682 test_65e() {
2683         mkdir -p $DIR/d65
2684
2685         $SETSTRIPE $DIR/d65 || error "setstripe"
2686         $GETSTRIPE -v $DIR/d65 | grep "Default" || error "no stripe info failed"
2687         touch $DIR/d65/f6
2688         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
2689 }
2690 run_test 65e "directory setstripe 0 -1 0 ======================="
2691
2692 test_65f() {
2693         mkdir -p $DIR/d65f
2694         $RUNAS $SETSTRIPE $DIR/d65f && error "setstripe succeeded" || true
2695 }
2696 run_test 65f "dir setstripe permission (should return error) ==="
2697
2698 test_65g() {
2699         mkdir -p $DIR/d65
2700         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
2701         $SETSTRIPE -d $DIR/d65 || error "setstripe"
2702         $GETSTRIPE -v $DIR/d65 | grep "Default" || \
2703                 error "delete default stripe failed"
2704 }
2705 run_test 65g "directory setstripe -d ==========================="
2706
2707 test_65h() {
2708         mkdir -p $DIR/d65
2709         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
2710         mkdir -p $DIR/d65/dd1
2711         [ "`$GETSTRIPE -v $DIR/d65 | grep "^count"`" == \
2712           "`$GETSTRIPE -v $DIR/d65/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
2713 }
2714 run_test 65h "directory stripe info inherit ===================="
2715  
2716 test_65i() { # bug6367
2717         $SETSTRIPE $MOUNT -s 65536 -c -1 
2718 }
2719 run_test 65i "set non-default striping on root directory (bug 6367)="
2720
2721 test_65j() { # bug6367
2722         # if we aren't already remounting for each test, do so for this test
2723         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
2724                 cleanup -f || error "failed to unmount"
2725                 setup
2726         fi
2727         $SETSTRIPE -d $MOUNT || error "setstripe failed"
2728 }
2729 run_test 65j "set default striping on root directory (bug 6367)="
2730
2731 test_65k() { # bug11679
2732         [ "$OSTCOUNT" -lt 2 ] && skip "too few OSTs" && return
2733
2734         echo "Check OST status: "
2735         MDS_OSCS=`do_facet mds lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
2736         for OSC in $MDS_OSCS; do
2737                 echo $OSC "is activate"
2738                 do_facet mds lctl --device %$OSC activate
2739         done
2740         do_facet client mkdir -p $DIR/$tdir
2741         for INACTIVE_OSC in $MDS_OSCS; do
2742                 echo $INACTIVE_OSC "is Deactivate:"
2743                 do_facet mds lctl --device  %$INACTIVE_OSC deactivate
2744                 for STRIPE_OSC in $MDS_OSCS; do
2745                         STRIPE_OST=`osc_to_ost $STRIPE_OSC`
2746                         STRIPE_INDEX=`do_facet mds cat $LPROC/lov/*md*/target_obd |
2747                                       grep $STRIPE_OST | awk -F: '{print $1}'`
2748                         echo "$SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1"
2749                         do_facet client $SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1
2750                         RC=$?
2751                         [ $RC -ne 0 ] && error "setstripe should have succeeded"
2752                 done
2753                 do_facet client rm -f $DIR/$tdir/*
2754                 echo $INACTIVE_OSC "is Activate."
2755                 do_facet mds lctl --device  %$INACTIVE_OSC activate
2756         done
2757 }
2758 run_test 65k "validate manual striping works properly with deactivated OSCs"
2759
2760 test_65l() { # bug 12836
2761         mkdir -p $DIR/$tdir
2762         $SETSTRIPE $DIR/$tdir -c -1
2763         $LFS find -mtime -1 $DIR >/dev/null
2764 }
2765 run_test 65l "lfs find on -1 stripe dir ========================"
2766
2767 # bug 2543 - update blocks count on client
2768 test_66() {
2769         COUNT=${COUNT:-8}
2770         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
2771         sync; sleep 1; sync
2772         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
2773         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
2774 }
2775 run_test 66 "update inode blocks count on client ==============="
2776
2777 test_67() { # bug 3285 - supplementary group fails on MDS, passes on client
2778         [ "$RUNAS_ID" = "$UID" ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
2779         check_kernel_version 35 || return 0
2780         mkdir $DIR/$tdir
2781         chmod 771 $DIR/$tdir
2782         chgrp $RUNAS_ID $DIR/$tdir
2783         $RUNAS -u $RUNAS_ID -g $(($RUNAS_ID + 1)) -G1,2,$RUNAS_ID ls $DIR/$tdir
2784         RC=$?
2785         MDS=$(\ls $LPROC/mds 2> /dev/null | grep -v num_refs | tail -n 1)
2786         if [ "$MDS" ]; then
2787                 # can't tell which is correct otherwise
2788                 GROUP_UPCALL=`cat $LPROC/mds/$MDS/group_upcall`
2789                 [ "$GROUP_UPCALL" = "NONE" -a $RC -eq 0 ] && \
2790                         error "no-upcall passed" || true
2791                 [ "$GROUP_UPCALL" != "NONE" -a $RC -ne 0 ] && \
2792                         error "upcall failed" || true
2793         fi
2794 }
2795 run_test 67 "supplementary group failure (should return error) ="
2796
2797 cleanup_67b() {
2798         set +vx
2799         trap 0
2800         echo NONE > $LPROC/mds/$MDS/group_upcall
2801 }
2802
2803 test_67b() { # bug 3285 - supplementary group fails on MDS, passes on client
2804         T67_UID=${T67_UID:-1}   # needs to be in /etc/groups on MDS, gid == uid
2805         [ "$UID" = "$T67_UID" ] && skip "UID = T67_UID = $UID -- skipping" && return
2806         check_kernel_version 35 || return 0
2807         remote_mds && skip "remote MDS" && return
2808         GROUP_UPCALL=`cat $LPROC/mds/$MDS/group_upcall`
2809         [ "$GROUP_UPCALL" != "NONE" ] && skip "skip test - upcall" &&return
2810         set -vx
2811         trap cleanup_67b EXIT
2812         mkdir -p $DIR/$tdir
2813         chmod 771 $DIR/$tdir
2814         chgrp $T67_UID $DIR/$tdir
2815         echo `which l_getgroups` > $LPROC/mds/$MDS/group_upcall
2816         l_getgroups -d $T67_UID
2817         $RUNAS -u $T67_UID -g 999 -G8,9,$T67_UID touch $DIR/$tdir/$tfile || \
2818                 error "'touch $DIR/$tdir/$tfile' failed"
2819         [ -f $DIR/$tdir/$tfile ] || error "$DIR/$tdir/$tfile create error"
2820         cleanup_67b
2821 }
2822 run_test 67b "supplementary group test ========================="
2823
2824 LLOOP=
2825 cleanup_68() {
2826         trap 0
2827         if [ ! -z "$LLOOP" ]; then
2828                 swapoff $LLOOP || error "swapoff failed"
2829                 $LCTL blockdev_detach $LLOOP || error "detach failed"
2830                 rm -f $LLOOP
2831                 unset LLOOP
2832         fi
2833         rm -f $DIR/f68
2834 }
2835
2836 meminfo() {
2837         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
2838 }
2839
2840 swap_used() {
2841         swapon -s | awk '($1 == "'$1'") { print $4 }'
2842 }
2843
2844
2845 # excercise swapping to lustre by adding a high priority swapfile entry
2846 # and then consuming memory until it is used.
2847 test_68() {
2848         [ "$UID" != 0 ] && skip "must run as root" && return
2849         grep -q obdfilter $LPROC/devices && \
2850                 skip "local OST" && return
2851
2852         grep -q llite_lloop /proc/modules
2853         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
2854
2855         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
2856                 skip "can't reliably test swap with TCP" && return
2857
2858         MEMTOTAL=`meminfo MemTotal`
2859         NR_BLOCKS=$((MEMTOTAL>>8))
2860         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
2861
2862         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
2863         dd if=/dev/zero of=$DIR/f68 bs=64k seek=$NR_BLOCKS count=1
2864         mkswap $DIR/f68
2865
2866         $LCTL blockdev_attach $DIR/f68 $LLOOP || error "attach failed"
2867
2868         trap cleanup_68 EXIT
2869
2870         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
2871
2872         echo "before: `swapon -s | grep $LLOOP`"
2873         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
2874         echo "after: `swapon -s | grep $LLOOP`"
2875         SWAPUSED=`swap_used $LLOOP`
2876
2877         cleanup_68
2878
2879         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
2880 }
2881 run_test 68 "support swapping to Lustre ========================"
2882
2883 # bug5265, obdfilter oa2dentry return -ENOENT
2884 # #define OBD_FAIL_OST_ENOENT 0x217
2885 test_69() {
2886         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] &&
2887                 skip "skipping test for remote OST" && return
2888
2889         f="$DIR/$tfile"
2890         touch $f
2891
2892         if ! $DIRECTIO write ${f}.2 0 1; then
2893                 skip "O_DIRECT not implemented"
2894                 return 0
2895         fi
2896
2897         #define OBD_FAIL_OST_ENOENT 0x217
2898         sysctl -w lustre.fail_loc=0x217
2899         truncate $f 1 # vmtruncate() will ignore truncate() error.
2900         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
2901
2902         sysctl -w lustre.fail_loc=0
2903         $DIRECTIO write $f 0 2 || error "write error"
2904
2905         cancel_lru_locks osc
2906         $DIRECTIO read $f 0 1 || error "read error"
2907
2908         #define OBD_FAIL_OST_ENOENT 0x217
2909         sysctl -w lustre.fail_loc=0x217
2910         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
2911
2912         sysctl -w lustre.fail_loc=0
2913         rm -f $f
2914 }
2915 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
2916
2917 test_71() {
2918         which dbench > /dev/null 2>&1 || skip "dbench not installed, skip this test" && return 0
2919         DBENCH_LIB=${DBENCH_LIB:-/usr/lib/dbench}
2920         PATH=${DBENCH_LIB}:${PATH}
2921         cp `which dbench` $DIR
2922
2923         TGT=$DIR/client.txt
2924         SRC=${SRC:-$DBENCH_LIB/client.txt}
2925         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2926         SRC=$DBENCH_LIB/client_plain.txt
2927         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2928
2929         echo "copying necessary lib to $DIR"
2930         [ -d /lib64 ] && LIB71=/lib64 || LIB71=/lib
2931         mkdir -p $DIR$LIB71 || error "can't create $DIR$LIB71"
2932         cp $LIB71/libc* $DIR$LIB71 || error "can't copy $LIB71/libc*"
2933         cp $LIB71/ld-* $DIR$LIB71 || error "can't create $LIB71/ld-*"
2934
2935         echo "chroot $DIR /dbench -c client.txt 2"
2936         chroot $DIR /dbench -c client.txt 2
2937         RC=$?
2938
2939         rm -rf $DIR/dbench $TGT $DIR$LIB71
2940
2941         return $RC
2942 }
2943 run_test 71 "Running dbench on lustre (don't segment fault) ===="
2944
2945 test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
2946         check_kernel_version 43 || return 0
2947         [ "$RUNAS_ID" = "$UID" ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
2948         touch $DIR/f72
2949         chmod 777 $DIR/f72
2950         chmod ug+s $DIR/f72
2951         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
2952         # See if we are still setuid/sgid
2953         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
2954         # Now test that MDS is updated too
2955         cancel_lru_locks mdc
2956         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
2957         true
2958 }
2959 run_test 72 "Test that remove suid works properly (bug5695) ===="
2960
2961 # bug 3462 - multiple simultaneous MDC requests
2962 test_73() {
2963         mkdir $DIR/d73-1 
2964         mkdir $DIR/d73-2
2965         multiop $DIR/d73-1/f73-1 O_c &
2966         pid1=$!
2967         #give multiop a chance to open
2968         usleep 500
2969
2970         #define OBD_FAIL_MDS_PAUSE_OPEN 0x129
2971         sysctl -w lustre.fail_loc=0x80000129
2972         multiop $DIR/d73-1/f73-2 Oc &
2973         sleep 1
2974         sysctl -w lustre.fail_loc=0
2975
2976         multiop $DIR/d73-2/f73-3 Oc &
2977         pid3=$!
2978
2979         kill -USR1 $pid1
2980         wait $pid1 || return 1
2981
2982         sleep 25
2983
2984         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
2985         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5 
2986         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6 
2987
2988         rm -rf $DIR/d73-*
2989 }
2990 run_test 73 "multiple MDC requests (should not deadlock)"
2991
2992 test_74a() { # bug 6149, 6184
2993         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
2994         #
2995         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
2996         # will spin in a tight reconnection loop
2997         touch $DIR/f74a
2998         sysctl -w lustre.fail_loc=0x8000030e
2999         # get any lock that won't be difficult - lookup works.
3000         ls $DIR/f74a
3001         sysctl -w lustre.fail_loc=0
3002         true
3003 }
3004 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
3005
3006 test_74b() { # bug 13310
3007         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
3008         #
3009         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
3010         # will spin in a tight reconnection loop
3011         sysctl -w lustre.fail_loc=0x8000030e
3012         # get a "difficult" lock
3013         touch $DIR/f74b
3014         sysctl -w lustre.fail_loc=0
3015         true
3016 }
3017 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
3018
3019 JOIN=${JOIN:-"lfs join"}
3020 F75=$DIR/f75
3021 F128k=${F75}_128k
3022 FHEAD=${F75}_head
3023 FTAIL=${F75}_tail
3024 export T75_PREP=no
3025 test75_prep() {
3026         [ $T75_PREP = "yes" ] && return
3027         echo "using F75=$F75, F128k=$F128k, FHEAD=$FHEAD, FTAIL=$FTAIL"
3028  
3029         dd if=/dev/urandom of=${F75}_128k bs=128k count=1 || error "dd failed"
3030         log "finished dd"
3031         chmod 777 ${F128k}
3032         T75_PREP=yes
3033 }
3034  
3035 test_75a() {
3036         test75_prep
3037  
3038         cp -p ${F128k} ${FHEAD}
3039         log "finished cp to $FHEAD"
3040         cp -p ${F128k} ${FTAIL}
3041         log "finished cp to $FTAIL"
3042         cat ${F128k} ${F128k} > ${F75}_sim_sim
3043  
3044         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3045         log "finished join $FHEAD to ${F75}_sim_sim"
3046         cmp ${FHEAD} ${F75}_sim_sim || error "${FHEAD} ${F75}_sim_sim differ"
3047         log "finished cmp $FHEAD to ${F75}_sim_sim"
3048         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} still exist after join"
3049 }
3050 run_test 75a "TEST join file ===================================="
3051  
3052 test_75b() {
3053         test75_prep
3054  
3055         cp -p ${F128k} ${FTAIL}
3056         cat ${F75}_sim_sim >> ${F75}_join_sim
3057         cat ${F128k} >> ${F75}_join_sim
3058         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3059         cmp ${FHEAD} ${F75}_join_sim || \
3060                 error "${FHEAD} ${F75}_join_sim are different"
3061         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join"
3062 }
3063 run_test 75b "TEST join file 2 =================================="
3064  
3065 test_75c() {
3066         test75_prep
3067  
3068         cp -p ${F128k} ${FTAIL}
3069         cat ${F128k} >> ${F75}_sim_join
3070         cat ${F75}_join_sim >> ${F75}_sim_join
3071         $JOIN ${FTAIL} ${FHEAD} || error "join error"
3072         cmp ${FTAIL} ${F75}_sim_join || \
3073                 error "${FTAIL} ${F75}_sim_join are different"
3074         $CHECKSTAT -a ${FHEAD} || error "tail ${FHEAD} exist after join"
3075 }
3076 run_test 75c "TEST join file 3 =================================="
3077  
3078 test_75d() {
3079         test75_prep
3080  
3081         cp -p ${F128k} ${FHEAD}
3082         cp -p ${F128k} ${FHEAD}_tmp
3083         cat ${F75}_sim_sim >> ${F75}_join_join
3084         cat ${F75}_sim_join >> ${F75}_join_join
3085         $JOIN ${FHEAD} ${FHEAD}_tmp || error "join ${FHEAD} ${FHEAD}_tmp error"
3086         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3087         cmp ${FHEAD} ${F75}_join_join ||error "${FHEAD} ${F75}_join_join differ"        $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join"
3088         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)"
3089 }
3090 run_test 75d "TEST join file 4 =================================="
3091  
3092 test_75e() {
3093         test75_prep
3094  
3095         rm -rf ${FHEAD} || "delete join file error"
3096 }
3097 run_test 75e "TEST join file 5 (remove joined file) ============="
3098  
3099 test_75f() {
3100         test75_prep
3101  
3102         cp -p ${F128k} ${F75}_join_10_compare
3103         cp -p ${F128k} ${F75}_join_10
3104         for ((i = 0; i < 10; i++)); do
3105                 cat ${F128k} >> ${F75}_join_10_compare
3106                 cp -p ${F128k} ${FTAIL}
3107                 $JOIN ${F75}_join_10 ${FTAIL} || \
3108                         error "join ${F75}_join_10 ${FTAIL} error"
3109                 $CHECKSTAT -a ${FTAIL} || error "tail file exist after join"
3110         done
3111         cmp ${F75}_join_10 ${F75}_join_10_compare || \
3112                 error "files ${F75}_join_10 ${F75}_join_10_compare differ"
3113 }
3114 run_test 75f "TEST join file 6 (join 10 files) =================="
3115  
3116 test_75g() {
3117         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
3118         $LFS getstripe ${F75}_join_10
3119  
3120         $OPENUNLINK ${F75}_join_10 ${F75}_join_10 || error "files unlink open"
3121  
3122         ls -l $F75*
3123 }
3124 run_test 75g "TEST join file 7 (open unlink) ===================="
3125
3126 num_inodes() {
3127         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
3128 }
3129
3130 test_76() { # bug 1443
3131         DETH=$(grep deathrow /proc/kallsyms /proc/ksyms 2> /dev/null | wc -l)
3132         [ $DETH -eq 0 ] && skip "No _iget." && return 0
3133         BEFORE_INODES=`num_inodes`
3134         echo "before inodes: $BEFORE_INODES"
3135         for i in `seq 1000`; do
3136                 touch $DIR/$tfile
3137                 rm -f $DIR/$tfile
3138         done
3139         AFTER_INODES=`num_inodes`
3140         echo "after inodes: $AFTER_INODES"
3141         [ $AFTER_INODES -gt $((BEFORE_INODES + 32)) ] && \
3142                 error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
3143         true
3144 }
3145 run_test 76 "destroy duplicate inodes in client inode cache ===="
3146
3147 export ORIG_CSUM=""
3148 set_checksums()
3149 {
3150         [ "$ORIG_CSUM" ] || ORIG_CSUM=`cat $LPROC/osc/*/checksums | head -n1`
3151         for f in $LPROC/osc/*/checksums; do
3152                 echo $1 >> $f
3153         done
3154
3155         return 0
3156 }
3157
3158 F77_TMP=$TMP/f77-temp
3159 F77SZ=8
3160 setup_f77() {
3161         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
3162                 error "error writing to $F77_TMP"
3163 }
3164
3165 test_77a() { # bug 10889
3166         [ ! -f $F77_TMP ] && setup_f77
3167         set_checksums 1
3168         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
3169         set_checksums 0
3170 }
3171 run_test 77a "normal checksum read/write operation ============="
3172
3173 test_77b() { # bug 10889
3174         [ ! -f $F77_TMP ] && setup_f77
3175         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3176         sysctl -w lustre.fail_loc=0x80000409
3177         set_checksums 1
3178         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
3179                 error "dd error: $?"
3180         sysctl -w lustre.fail_loc=0
3181         set_checksums 0
3182 }
3183 run_test 77b "checksum error on client write ===================="
3184
3185 test_77c() { # bug 10889
3186         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return  
3187         cancel_lru_locks osc
3188         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3189         sysctl -w lustre.fail_loc=0x80000408
3190         set_checksums 1
3191         cmp $F77_TMP $DIR/f77b || error "file compare failed"
3192         sysctl -w lustre.fail_loc=0
3193         set_checksums 0
3194 }
3195 run_test 77c "checksum error on client read ==================="
3196
3197 test_77d() { # bug 10889
3198         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3199         sysctl -w lustre.fail_loc=0x80000409
3200         set_checksums 1
3201         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3202                 error "direct write: rc=$?"
3203         sysctl -w lustre.fail_loc=0
3204         set_checksums 0
3205 }
3206 run_test 77d "checksum error on OST direct write ==============="
3207
3208 test_77e() { # bug 10889
3209         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return  
3210         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3211         sysctl -w lustre.fail_loc=0x80000408
3212         set_checksums 1
3213         cancel_lru_locks osc
3214         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3215                 error "direct read: rc=$?"
3216         sysctl -w lustre.fail_loc=0
3217         set_checksums 0
3218 }
3219 run_test 77e "checksum error on OST direct read ================"
3220
3221 test_77f() { # bug 10889
3222         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3223         sysctl -w lustre.fail_loc=0x409
3224         set_checksums 1
3225         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
3226                 error "direct write succeeded"
3227         sysctl -w lustre.fail_loc=0
3228         set_checksums 0
3229 }
3230 run_test 77f "repeat checksum error on write (expect error) ===="
3231
3232 test_77g() { # bug 10889
3233         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] && \
3234                 skip "remote OST" && return
3235         [ ! -f $F77_TMP ] && setup_f77
3236         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
3237         sysctl -w lustre.fail_loc=0x8000021a
3238         set_checksums 1
3239         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
3240                 error "write error: rc=$?"
3241         sysctl -w lustre.fail_loc=0
3242         set_checksums 0
3243 }
3244 run_test 77g "checksum error on OST write ======================"
3245
3246 test_77h() { # bug 10889
3247         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] && \
3248                 skip "remote OST" && return
3249         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return  
3250         cancel_lru_locks osc
3251         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
3252         sysctl -w lustre.fail_loc=0x8000021b
3253         set_checksums 1
3254         cmp $F77_TMP $DIR/f77g || error "file compare failed"
3255         sysctl -w lustre.fail_loc=0
3256         set_checksums 0
3257 }
3258 run_test 77h "checksum error on OST read ======================="
3259
3260 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
3261 rm -f $F77_TMP
3262 unset F77_TMP
3263
3264 test_78() { # bug 10901
3265         NSEQ=5
3266         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
3267         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
3268         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 2048))
3269         echo "MemTotal: $((MEMTOTAL * 2))"
3270         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
3271         [ $F78SIZE -gt 512 ] && F78SIZE=512
3272         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
3273         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
3274         echo "Smallest OST: $SMALLESTOST"
3275         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024)) ] && \
3276                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024))
3277         echo "File size: $F78SIZE"
3278         $SETSTRIPE $DIR/$tfile -c -1 || error "setstripe failed"
3279         for i in `seq 1 $NSEQ`
3280         do
3281                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
3282                 echo directIO rdwr round $i of $NSEQ
3283                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
3284         done
3285
3286         rm -f $DIR/$tfile
3287 }
3288 run_test 78 "handle large O_DIRECT writes correctly ============"
3289
3290 test_79() { # bug 12743
3291         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] &&
3292                 skip "skipping test for remote OST" && return
3293
3294         wait_delete_completed
3295
3296         BKTOTAL=`awk 'BEGIN{total=0}; {total+=$1}; END{print total}' \
3297                  $LPROC/obdfilter/*/kbytestotal`
3298         BKFREE=`awk 'BEGIN{free=0}; {free+=$1}; END{print free}' \
3299                 $LPROC/obdfilter/*/kbytesfree`
3300         BKAVAIL=`awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}' \
3301                  $LPROC/obdfilter/*/kbytesavail`
3302         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
3303         DFTOTAL=`echo $STRING | cut -d, -f1`
3304         DFUSED=`echo $STRING  | cut -d, -f2`
3305         DFAVAIL=`echo $STRING | cut -d, -f3`
3306         DFFREE=$(($DFTOTAL - $DFUSED))
3307
3308         ALLOWANCE=$((64 * $OSTCOUNT))
3309
3310         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||  
3311            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
3312                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
3313         fi
3314         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] || 
3315            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
3316                 error "df free($DFFREE) mismatch OST free($BKFREE)"
3317         fi
3318         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] || 
3319            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
3320                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
3321         fi
3322 }
3323 run_test 79 "df report consistency check ======================="
3324
3325 test_80() { # bug 10718
3326         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
3327         sync; sleep 1; sync
3328         BEFORE=`date +%s`
3329         cancel_lru_locks OSC
3330         AFTER=`date +%s`
3331         DIFF=$((AFTER-BEFORE))
3332         if [ $DIFF -gt 1 ] ; then
3333                 error "elapsed for 1M@1T = $DIFF"
3334         fi
3335         true
3336 }
3337 run_test 80 "Page eviction is equally fast at high offsets too  ===="
3338
3339 # on the LLNL clusters, runas will still pick up root's $TMP settings,
3340 # which will not be writable for the runas user, and then you get a CVS
3341 # error message with a corrupt path string (CVS bug) and panic.
3342 # We're not using much space, so just stick it in /tmp, which is safe.
3343 OLDTMPDIR=$TMPDIR
3344 OLDTMP=$TMP
3345 TMPDIR=/tmp
3346 TMP=/tmp
3347 OLDHOME=$HOME
3348 [ $RUNAS_ID -ne $UID ] && HOME=/tmp
3349
3350 test_99a() {
3351         mkdir -p $DIR/d99cvsroot || error "mkdir $DIR/d99cvsroot failed"
3352         chown $RUNAS_ID $DIR/d99cvsroot || error "chown $DIR/d99cvsroot failed"
3353         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
3354 }
3355 run_test 99a "cvs init ========================================="
3356
3357 test_99b() {
3358         [ ! -d $DIR/d99cvsroot ] && test_99a
3359         $RUNAS [ ! -w /tmp ] && skip "/tmp has wrong w permission -- skipping" && return
3360         cd /etc/init.d || error "cd /etc/init.d failed"
3361         # some versions of cvs import exit(1) when asked to import links or
3362         # files they can't read.  ignore those files.
3363         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
3364                         ! -perm +4 -printf '-I %f\n')
3365         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
3366                 d99reposname vtag rtag > /dev/null || error "cvs import failed"
3367 }
3368 run_test 99b "cvs import ======================================="
3369
3370 test_99c() {
3371         [ ! -d $DIR/d99cvsroot ] && test_99b
3372         cd $DIR || error "cd $DIR failed"
3373         mkdir -p $DIR/d99reposname || error "mkdir $DIR/d99reposname failed"
3374         chown $RUNAS_ID $DIR/d99reposname || \
3375                 error "chown $DIR/d99reposname failed"
3376         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname > /dev/null || \
3377                 error "cvs co d99reposname failed"
3378 }
3379 run_test 99c "cvs checkout ====================================="
3380
3381 test_99d() {
3382         [ ! -d $DIR/d99cvsroot ] && test_99c
3383         cd $DIR/d99reposname
3384         $RUNAS touch foo99
3385         $RUNAS cvs add -m 'addmsg' foo99
3386 }
3387 run_test 99d "cvs add =========================================="
3388
3389 test_99e() {
3390         [ ! -d $DIR/d99cvsroot ] && test_99c
3391         cd $DIR/d99reposname
3392         $RUNAS cvs update
3393 }
3394 run_test 99e "cvs update ======================================="
3395
3396 test_99f() {
3397         [ ! -d $DIR/d99cvsroot ] && test_99d
3398         cd $DIR/d99reposname
3399         $RUNAS cvs commit -m 'nomsg' foo99
3400 }
3401 run_test 99f "cvs commit ======================================="
3402
3403 test_100() {
3404         netstat -tna | while read PROT SND RCV LOCAL REMOTE STAT; do
3405                 [ "$PROT" != "tcp" ] && continue
3406                 RPORT=`echo $REMOTE | cut -d: -f2`
3407                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
3408                 LPORT=`echo $LOCAL | cut -d: -f2`
3409                 if [ $LPORT -ge 1024 ]; then
3410                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
3411                         netstat -tna
3412                         error "local: $LPORT > 1024, remote: $RPORT"
3413                 fi
3414         done
3415         true
3416 }
3417 run_test 100 "check local port using privileged port ==========="
3418
3419 function get_named_value()
3420 {
3421     local tag
3422
3423     tag=$1
3424     while read ;do
3425         line=$REPLY
3426         case $line in
3427         $tag*)
3428             echo $line | sed "s/^$tag//"
3429             break
3430             ;;
3431         esac
3432     done
3433 }
3434
3435 export CACHE_MAX=`cat $LPROC/llite/*/max_cached_mb | head -n 1`
3436 cleanup_101() {
3437         for s in $LPROC/llite/*/max_cached_mb; do
3438                 echo $CACHE_MAX > $s
3439         done
3440         trap 0
3441 }
3442
3443 test_101() {
3444         local s
3445         local discard
3446         local nreads=10000
3447         [ "$CPU" = "UML" ] && nreads=1000
3448         local cache_limit=32
3449
3450         for s in $LPROC/osc/*/rpc_stats; do
3451                 echo 0 > $s
3452         done
3453         trap cleanup_101 EXIT
3454         for s in $LPROC/llite/*; do
3455                 echo 0 > $s/read_ahead_stats
3456                 echo $cache_limit > $s/max_cached_mb
3457         done
3458
3459         #
3460         # randomly read 10000 of 64K chunks from file 3x 32MB in size
3461         #
3462         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
3463         $RANDOM_READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
3464
3465         discard=0
3466         for s in $LPROC/llite/*; do
3467                 discard=$(($discard + $(cat $s/read_ahead_stats | get_named_value 'read but discarded')))
3468         done
3469         cleanup_101
3470
3471         if [ $(($discard * 10)) -gt $nreads ] ;then
3472                 for s in $LPROC/osc/*/rpc_stats; do
3473                         echo $s; cat $s
3474                 done
3475                 for s in $LPROC/llite/*/read_ahead_stats; do
3476                         echo $s; cat $s
3477                 done
3478                 error "too many ($discard) discarded pages" 
3479         fi
3480         rm -f $DIR/$tfile || true
3481 }
3482 run_test 101 "check read-ahead for random reads ================"
3483
3484 export SETUP_TEST102=no
3485 setup_test102() {
3486         [ "$SETUP_TEST102" = "yes" ] && return
3487         mkdir -p $DIR/$tdir
3488         STRIPE_SIZE=65536
3489         STRIPE_COUNT=4 
3490         STRIPE_OFFSET=2
3491
3492         trap cleanup_test102 EXIT
3493         cd $DIR
3494         $SETSTRIPE $tdir -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT
3495         cd $DIR/$tdir 
3496         for num in 1 2 3 4
3497         do
3498                 for count in 1 2 3 4
3499                 do
3500                         for offset in 0 1 2 3 
3501                         do
3502                                 local stripe_size=`expr $STRIPE_SIZE \* $num`
3503                                 local file=file"$num-$offset-$count"
3504                                 $SETSTRIPE $file -s $stripe_size -i $offset -c $count
3505                         done
3506                 done
3507         done
3508
3509         cd $DIR
3510         star -c  f=$TMP/f102.tar $tdir 
3511         SETUP_TEST102=yes
3512 }
3513
3514 cleanup_test102() {
3515         [ "$SETUP_TEST102" = "yes" ] || return
3516         trap 0
3517         rm -f $TMP/f102.tar
3518         rm -rf $DIR/$tdir
3519         SETUP_TEST102=no
3520 }
3521
3522 test_102a() {
3523         local testfile=$DIR/xattr_testfile
3524
3525         rm -f $testfile
3526         touch $testfile
3527
3528         [ "$UID" != 0 ] && skip "must run as root" && return
3529         [ -z "`grep xattr $LPROC/mdc/*[mM][dD][cC]*/connect_flags`" ] && skip "must have user_xattr" && return
3530         [ -z "$(which setfattr 2>/dev/null)" ] && skip "could not find setfattr" && return
3531
3532         echo "set/get xattr..."
3533         setfattr -n trusted.name1 -v value1 $testfile || error
3534         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
3535         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
3536  
3537         setfattr -n user.author1 -v author1 $testfile || error
3538         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
3539         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
3540
3541         echo "listxattr..."
3542         setfattr -n trusted.name2 -v value2 $testfile || error
3543         setfattr -n trusted.name3 -v value3 $testfile || error
3544         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3545         grep "trusted.name" | wc -l` -eq 3 ] || error
3546
3547  
3548         setfattr -n user.author2 -v author2 $testfile || error
3549         setfattr -n user.author3 -v author3 $testfile || error
3550         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
3551         grep "user" | wc -l` -eq 3 ] || error
3552
3553         echo "remove xattr..."
3554         setfattr -x trusted.name1 $testfile || error
3555         getfattr -d -m trusted $testfile 2> /dev/null | \
3556         grep "trusted.name1" && error || true
3557
3558         setfattr -x user.author1 $testfile || error
3559         getfattr -d -m user $testfile 2> /dev/null | \
3560         grep "user.author1" && error || true
3561
3562         # b10667: setting lustre special xattr be silently discarded
3563         echo "set lustre special xattr ..."
3564         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
3565
3566         rm -f $testfile
3567 }
3568 run_test 102a "user xattr test =================================="
3569
3570 test_102b() {
3571         # b10930: get/set/list trusted.lov xattr
3572         echo "get/set/list trusted.lov xattr ..."
3573         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
3574         local testfile=$DIR/$tfile
3575         $SETSTRIPE $testfile -s 65536 -i 1 -c 2
3576         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3577         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
3578
3579         local testfile2=${testfile}2
3580         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
3581                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
3582         
3583         $MCREATE $testfile2
3584         setfattr -n trusted.lov -v $value $testfile2    
3585         local tmp_file=${testfile}3
3586         $GETSTRIPE -v $testfile2 > $tmp_file
3587         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
3588         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
3589         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
3590         [ $stripe_count -eq 2 ] || error "stripe count $stripe_count != 2"
3591 }
3592 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
3593
3594 test_102c() {
3595         # b10930: get/set/list lustre.lov xattr
3596         echo "get/set/list lustre.lov xattr ..."
3597         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
3598         mkdir -p $DIR/$tdir
3599         chown $RUNAS_ID $DIR/$tdir
3600         local testfile=$DIR/$tdir/$tfile
3601         $RUNAS $SETSTRIPE $testfile -s 65536 -i 1 -c 2
3602         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
3603         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
3604
3605         local testfile2=${testfile}2
3606         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
3607                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
3608         
3609         $RUNAS $MCREATE $testfile2
3610         $RUNAS setfattr -n lustre.lov -v $value $testfile2      
3611         local tmp_file=${testfile}3
3612         $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
3613         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
3614         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
3615         [ "$stripe_size" -eq 65536 ] || error "stripe size $stripe_size != 65536"
3616         [ "$stripe_count" -eq 2 ] || error "stripe count $stripe_count != 2"
3617 }
3618 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
3619
3620 get_stripe_info() {
3621         stripe_size=0
3622         stripe_count=0
3623         stripe_offset=0
3624         local lines=`sed -n '/obdidx/=' $1`
3625         stripe_size=`awk '{if($1~/size/) print $2}' $1`
3626         stripe_count=`awk '{if($1~/count/) print $2}' $1`
3627         lines=`expr $lines + 1`
3628         stripe_offset=`sed -n ${lines}p $1 |awk '{print $1}'`
3629 }
3630
3631 compare_stripe_info1() {
3632         for num in 1 2 3 4
3633         do
3634                 for count in 1 2 3 4
3635                 do
3636                         for offset in 0 1 2 3 
3637                         do
3638                                 local size=`expr $STRIPE_SIZE \* $num`
3639                                 local file=file"$num-$offset-$count"
3640                                 local tmp_file=out
3641                                 $GETSTRIPE -v $file > $tmp_file 
3642                                 get_stripe_info  $tmp_file
3643                                 if test $stripe_size -ne $size
3644                                 then
3645                                         error "$file: different stripe size" && return
3646                                 fi
3647                                 if test $stripe_count -ne $count
3648                                 then
3649                                         error "$file: different stripe count" && return
3650                                 fi
3651                                 if test $stripe_offset -ne 0
3652                                 then
3653                                         error "$file: different stripe offset" && return
3654                                 fi
3655                                 rm -f $tmp_file
3656                         done
3657                 done
3658         done
3659 }
3660
3661 compare_stripe_info2() {
3662         for num in 1 2 3 4
3663         do
3664                 for count in 1 2 3 4
3665                 do
3666                         for offset in 0 1 2 3 
3667                         do
3668                                 local size=`expr $STRIPE_SIZE \* $num`
3669                                 local file=file"$num-$offset-$count"
3670                                 local tmp_file=out
3671                                 $GETSTRIPE -v $file > $tmp_file
3672                                 get_stripe_info  $tmp_file
3673                                 if test $stripe_size -ne $size
3674                                 then
3675                                         error "$file: different stripe size" && return  
3676                                 fi
3677                                 if test $stripe_count -ne $count
3678                                 then
3679                                         error "$file: different stripe count" && return
3680                                 fi
3681                                 if test $stripe_offset -ne $offset
3682                                 then
3683                                         error "$file: different stripe offset" && return
3684                                 fi
3685                                 rm -f $tmp_file
3686                         done
3687                 done
3688         done
3689 }
3690
3691 test_102d() {
3692         # b10930: star test for trusted.lov xattr
3693         star --xhelp 2>&1 | grep -q nolustre  
3694         if [ $? -ne 0 ]
3695         then
3696                 skip "being skipped because a lustre-aware star is not installed." && return
3697         fi
3698         [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
3699         setup_test102
3700         mkdir -p $DIR/d102d
3701         star -x  f=$TMP/f102.tar -C $DIR/d102d
3702         cd $DIR/d102d/$tdir
3703         compare_stripe_info1
3704
3705 }
3706 run_test 102d "star restore stripe info from tarfile,not keep osts ==========="
3707
3708 test_102e() {
3709         # b10930: star test for trusted.lov xattr
3710         star --xhelp 2>&1 | grep -q nolustre  
3711         if [ $? -ne 0 ]
3712         then
3713                 skip "being skipped because a lustre-aware star is not installed." && return
3714         fi
3715         [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
3716         setup_test102
3717         mkdir -p $DIR/d102e
3718         star -x  -preserve-osts f=$TMP/f102.tar -C $DIR/d102e
3719         cd $DIR/d102e/$tdir
3720         compare_stripe_info2
3721 }
3722 run_test 102e "star restore stripe info from tarfile, keep osts ==========="
3723
3724 test_102f() {
3725         # b10930: star test for trusted.lov xattr
3726         star --xhelp 2>&1 | grep -q nolustre  
3727         if [ $? -ne 0 ]
3728         then
3729                 skip "being skipped because a lustre-aware star is not installed." && return
3730         fi
3731         [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
3732         setup_test102
3733         mkdir -p $DIR/d102f
3734         cd $DIR
3735         star -copy  $tdir $DIR/d102f
3736         cd $DIR/d102f/$tdir
3737         compare_stripe_info1
3738 }
3739 run_test 102f "star copy files, not keep osts ==========="
3740
3741 test_102g() {
3742         # b10930: star test for trusted.lov xattr
3743         star --xhelp 2>&1 | grep -q nolustre  
3744         if [ $? -ne 0 ]
3745         then
3746                 skip "being skipped because a lustre-aware star is not installed." && return
3747         fi
3748         [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
3749         setup_test102
3750         mkdir -p $DIR/d102g
3751         cd $DIR
3752         star -copy -preserve-osts $tdir $DIR/d102g
3753         cd $DIR/d102g/$tdir
3754         compare_stripe_info2
3755         cleanup_test102
3756 }
3757 run_test 102g "star copy files, keep osts ==========="
3758
3759 run_acl_subtest()
3760 {
3761     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
3762     return $?
3763 }
3764
3765 test_103 () {
3766     [ "$UID" != 0 ] && skip "must run as root" && return
3767     [ -z "$(grep acl $LPROC/mdc/*[mM][dD][cC]*/connect_flags)" ] && skip "must have acl enabled" && return
3768     [ -z "$(which setfacl 2>/dev/null)" ] && skip "could not find setfacl" && return
3769
3770     SAVE_UMASK=`umask`
3771     umask 0022
3772     cd $DIR
3773
3774     echo "performing cp ..."
3775     run_acl_subtest cp || error
3776     echo "performing getfacl-noacl..."
3777     run_acl_subtest getfacl-noacl > /dev/null || error
3778     echo "performing misc..."
3779     run_acl_subtest misc > /dev/null || error
3780 #    XXX add back permission test when we support supplementary groups.
3781 #    echo "performing permissions..."
3782 #    run_acl_subtest permissions || error
3783     echo "performing setfacl..."
3784     run_acl_subtest setfacl > /dev/null || error
3785
3786     # inheritance test got from HP
3787     echo "performing inheritance..."
3788     cp $LUSTRE/tests/acl/make-tree . || error
3789     chmod +x make-tree || error
3790     run_acl_subtest inheritance > /dev/null || error
3791     rm -f make-tree
3792
3793     cd $SAVE_PWD
3794     umask $SAVE_UMASK
3795 }
3796 run_test 103 "acl test ========================================="
3797
3798 test_104() {
3799         touch $DIR/$tfile
3800         lfs df || error "lfs df failed"
3801         lfs df -ih || error "lfs df -ih failed"
3802         lfs df -h $DIR || error "lfs df -h $DIR failed"
3803         lfs df -i $DIR || error "lfs df -i $DIR failed"
3804         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
3805         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
3806         
3807         OSC=`awk '/-osc-|OSC.*MNT/ {print $4}' $LPROC/devices | head -n 1`
3808         lctl --device %$OSC deactivate
3809         lfs df || error "lfs df with deactivated OSC failed"
3810         lctl --device %$OSC recover
3811         lfs df || error "lfs df with reactivated OSC failed"
3812 }
3813 run_test 104 "lfs df [-ih] [path] test ========================="
3814
3815 test_105a() {
3816         # doesn't work on 2.4 kernels
3817         touch $DIR/$tfile
3818         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3819         then
3820                 flocks_test on -f $DIR/$tfile || error "fail flock on"
3821         else
3822                 flocks_test off -f $DIR/$tfile || error "fail flock off"
3823         fi
3824 }
3825 run_test 105a "flock when mounted without -o flock test ========"
3826
3827 test_105b() {
3828         touch $DIR/$tfile
3829         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3830         then
3831                 flocks_test on -c $DIR/$tfile || error "fail flock on"
3832         else
3833                 flocks_test off -c $DIR/$tfile || error "fail flock off"
3834         fi
3835 }
3836 run_test 105b "fcntl when mounted without -o flock test ========"
3837
3838 test_105c() {
3839         touch $DIR/$tfile
3840         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3841         then
3842                 flocks_test on -l $DIR/$tfile || error "fail flock on"
3843         else
3844                 flocks_test off -l $DIR/$tfile || error "fail flock off"
3845         fi
3846 }
3847 run_test 105c "lockf when mounted without -o flock test ========"
3848
3849 test_106() { #bug 10921
3850         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
3851         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
3852 }
3853 run_test 106 "attempt exec of dir followed by chown of that dir"
3854
3855 test_107() {
3856         CDIR=`pwd`
3857         cd $DIR
3858         ulimit -c unlimited
3859         sleep 60 &
3860         SLEEPPID=$!
3861
3862         file=`cat /proc/sys/kernel/core_pattern`
3863         core_pid=`cat /proc/sys/kernel/core_uses_pid`
3864         [ $core_pid -eq 1 ] && file=$file.$SLEEPPID
3865         rm -f $file
3866         sleep 1
3867
3868         kill -s 11 $SLEEPPID
3869         wait $SLEEPPID
3870         if [ -e $file ]; then
3871                 size=`stat -c%s $file`
3872                 [ $size -eq 0 ] && error "Zero length core file $file"
3873         else
3874                 error "Fail to create core file $file"
3875         fi
3876         rm -f $file
3877         cd $CDIR
3878 }
3879 run_test 107 "Coredump on SIG"
3880
3881 test_115() {
3882         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
3883             cut -c11-20)
3884         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
3885             return
3886         echo "Starting with $OSTIO_pre threads"
3887
3888         NUMTEST=20000
3889         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3890         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
3891         echo "$NUMTEST creates/unlinks"
3892         mkdir -p $DIR/$tdir
3893         createmany -o $DIR/$tdir/$tfile $NUMTEST
3894         unlinkmany $DIR/$tdir/$tfile $NUMTEST
3895
3896         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
3897             cut -c11-20)
3898
3899         # don't return an error
3900         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
3901             "FAIL: No addition ll_ost_io threads were created ($OSTIO_pre)" &&\
3902             echo "This may be fine, depending on what ran before this test" &&\
3903             echo "and how fast this system is." && return
3904
3905         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
3906 }
3907 run_test 115 "verify dynamic thread creation===================="
3908
3909 free_min_max () {
3910         wait_delete_completed
3911         AVAIL=($(cat $LPROC/osc/*[oO][sS][cC][-_]*/kbytesavail))
3912         echo OST kbytes available: ${AVAIL[@]}
3913         MAXI=0; MAXV=${AVAIL[0]}
3914         MINI=0; MINV=${AVAIL[0]}
3915         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
3916             #echo OST $i: ${AVAIL[i]}kb
3917             if [ ${AVAIL[i]} -gt $MAXV ]; then
3918                 MAXV=${AVAIL[i]}; MAXI=$i
3919             fi
3920             if [ ${AVAIL[i]} -lt $MINV ]; then
3921                 MINV=${AVAIL[i]}; MINI=$i
3922             fi
3923         done
3924         echo Min free space: OST $MINI: $MINV 
3925         echo Max free space: OST $MAXI: $MAXV 
3926 }
3927
3928 test_116() {
3929         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
3930         remote_mds && skip "remote MDS" && return
3931
3932         echo -n "Free space priority "
3933         cat $LPROC/lov/*/qos_prio_free
3934         DELAY=$(cat $LPROC/lov/*/qos_maxage | head -1 | awk '{print $1}')
3935         declare -a AVAIL
3936         free_min_max
3937         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI" &&\
3938                 return
3939
3940         # generate uneven OSTs
3941         mkdir -p $DIR/$tdir/OST${MINI}
3942         declare -i FILL
3943         FILL=$(($MINV / 4))
3944         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
3945         $SETSTRIPE $DIR/$tdir/OST${MINI} -i $MINI -c 1
3946         i=1
3947         while [ $FILL -gt 0 ]; do
3948             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
3949             FILL=$(($FILL - 2048))
3950             echo -n .
3951             i=$(($i + 1))
3952         done
3953         FILL=$(($MINV / 4))
3954         sync
3955         sleep $DELAY
3956
3957         free_min_max
3958         DIFF=$(($MAXV - $MINV))
3959         DIFF2=$(($DIFF * 100 / $MINV))
3960         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
3961         if [ $DIFF2 -gt 20 ]; then
3962             echo "ok"
3963         else
3964             echo "failed - QOS mode won't be used"
3965             error "QOS imbalance criteria not met"
3966             return
3967         fi
3968
3969         MINI1=$MINI; MINV1=$MINV
3970         MAXI1=$MAXI; MAXV1=$MAXV
3971
3972         # now fill using QOS
3973         echo writing a bunch of files to QOS-assigned OSTs
3974         $SETSTRIPE $DIR/$tdir -c 1
3975         i=1
3976         while [ $FILL -gt 0 ]; do
3977             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
3978             FILL=$(($FILL - 200))
3979             echo -n .
3980             i=$(($i + 1))
3981         done
3982         echo "wrote $i 200k files"
3983         sync
3984         sleep $DELAY
3985
3986         echo "Note: free space may not be updated, so measurements might be off"
3987         free_min_max
3988         DIFF2=$(($MAXV - $MINV))
3989         echo "free space delta: orig $DIFF final $DIFF2"
3990         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!" 
3991         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
3992         echo "Wrote $DIFF to smaller OST $MINI1"
3993         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
3994         echo "Wrote $DIFF2 to larger OST $MAXI1"
3995         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
3996
3997         # Figure out which files were written where 
3998         UUID=$(awk '/'$MINI1': / {print $2; exit}' $LPROC/lov/${FSNAME}-clilov-*/target_obd)
3999         echo $UUID
4000         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4001         echo "$MINC files created on smaller OST $MINI1"
4002         UUID=$(awk '/'$MAXI1': / {print $2; exit}' $LPROC/lov/${FSNAME}-clilov-*/target_obd)
4003         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4004         echo "$MAXC files created on larger OST $MAXI1"
4005         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
4006         [ $MAXC -gt $MINC ] || error "stripe QOS didn't balance free space"
4007 }
4008 run_test 116 "stripe QOS: free space balance ==================="
4009
4010 test_117() # bug 10891
4011 {
4012         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
4013         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
4014         sysctl -w lustre.fail_loc=0x21e
4015         > $DIR/$tfile || error "truncate failed"
4016         sysctl -w lustre.fail_loc=0
4017         echo "Truncate succeeded."
4018 }
4019 run_test 117 "verify fsfilt_extend ============================="
4020
4021 # Reset async IO behavior after error case
4022 reset_async() {
4023         FILE=$DIR/reset_async
4024
4025         # Ensure all OSCs are cleared
4026         $LSTRIPE $FILE 0 -1 -1
4027         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
4028         sync
4029         rm $FILE
4030 }
4031
4032 test_118a() #bug 11710
4033 {
4034         reset_async
4035         
4036         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4037         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4038         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4039
4040         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4041                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4042                 return 1;
4043         fi
4044 }
4045 run_test 118a "verify O_SYNC works =========="
4046
4047 test_118b()
4048 {
4049         reset_async
4050
4051         #define OBD_FAIL_OST_ENOENT 0x217
4052         do_facet ost sysctl -w lustre.fail_loc=0x217
4053         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4054         RC=$?
4055         do_facet ost sysctl -w lustre.fail_loc=0
4056         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4057         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4058
4059         if [[ $RC -eq 0 ]]; then
4060                 error "Must return error due to dropped pages, rc=$RC"
4061                 return 1;
4062         fi
4063
4064         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4065                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4066                 return 1;
4067         fi
4068
4069         echo "Dirty pages not leaked on ENOENT"
4070
4071         # Due to the above error the OSC will issue all RPCs syncronously
4072         # until a subsequent RPC completes successfully without error.
4073         multiop $DIR/$tfile Ow4096yc
4074         rm -f $DIR/$tfile
4075         
4076         return 0
4077 }
4078 run_test 118b "Reclaim dirty pages on fatal error =========="
4079
4080 test_118c()
4081 {
4082         reset_async
4083
4084         #define OBD_FAIL_OST_EROFS               0x216
4085         do_facet ost sysctl -w lustre.fail_loc=0x216
4086
4087         # multiop should block due to fsync until pages are written
4088         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4089         MULTIPID=$!
4090         sleep 1
4091
4092         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4093                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4094         fi
4095
4096         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4097         if [[ $WRITEBACK -eq 0 ]]; then
4098                 error "No page in writeback, writeback=$WRITEBACK"
4099         fi
4100
4101         do_facet ost sysctl -w lustre.fail_loc=0
4102         wait $MULTIPID
4103         RC=$?
4104         if [[ $RC -ne 0 ]]; then
4105                 error "Multiop fsync failed, rc=$RC"
4106         fi
4107
4108         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4109         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4110         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4111                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4112         fi
4113         
4114         rm -f $DIR/$tfile
4115         echo "Dirty pages flushed via fsync on EROFS"
4116         return 0
4117 }
4118 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
4119
4120 test_118d()
4121 {
4122         reset_async
4123
4124         #define OBD_FAIL_OST_BRW_PAUSE_BULK
4125         do_facet ost sysctl -w lustre.fail_loc=0x214
4126         # multiop should block due to fsync until pages are written
4127         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &     
4128         MULTIPID=$!
4129         sleep 1
4130
4131         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4132                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4133         fi
4134
4135         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4136         if [[ $WRITEBACK -eq 0 ]]; then
4137                 error "No page in writeback, writeback=$WRITEBACK"
4138         fi
4139
4140         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
4141         do_facet ost sysctl -w lustre.fail_loc=0
4142
4143         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4144         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)   
4145         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4146                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4147         fi
4148
4149         rm -f $DIR/$tfile
4150         echo "Dirty pages gaurenteed flushed via fsync"
4151         return 0
4152 }
4153 run_test 118d "Fsync validation inject a delay of the bulk =========="
4154
4155 test_118f() {
4156         reset_async
4157
4158         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
4159         sysctl -w lustre.fail_loc=0x8000040a
4160
4161         # Should simulate EINVAL error which is fatal
4162         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4163         RC=$?
4164         if [[ $RC -eq 0 ]]; then
4165                 error "Must return error due to dropped pages, rc=$RC"
4166         fi
4167         
4168         sysctl -w lustre.fail_loc=0x0
4169         
4170         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4171         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4172         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4173         if [[ $LOCKED -ne 0 ]]; then
4174                 error "Locked pages remain in cache, locked=$LOCKED"
4175         fi
4176
4177         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4178                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4179         fi
4180
4181         rm -f $DIR/$tfile
4182         echo "No pages locked after fsync"
4183
4184         reset_async
4185         return 0
4186 }
4187 run_test 118f "Simulate unrecoverable OSC side error =========="
4188
4189 test_118g() {
4190         reset_async
4191
4192         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4193         sysctl -w lustre.fail_loc=0x406
4194
4195         # simulate local -ENOMEM
4196         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4197         RC=$?
4198         
4199         sysctl -w lustre.fail_loc=0
4200         if [[ $RC -eq 0 ]]; then
4201                 error "Must return error due to dropped pages, rc=$RC"
4202         fi
4203
4204         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4205         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4206         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4207         if [[ $LOCKED -ne 0 ]]; then
4208                 error "Locked pages remain in cache, locked=$LOCKED"
4209         fi
4210         
4211         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4212                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4213         fi
4214
4215         rm -f $DIR/$tfile
4216         echo "No pages locked after fsync"
4217
4218         reset_async
4219         return 0
4220 }
4221 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
4222
4223 test_118h() {
4224         reset_async
4225
4226         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4227         do_facet ost sysctl -w lustre.fail_loc=0x20e
4228         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4229         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4230         RC=$?
4231         
4232         do_facet ost sysctl -w lustre.fail_loc=0
4233         if [[ $RC -eq 0 ]]; then
4234                 error "Must return error due to dropped pages, rc=$RC"
4235         fi
4236
4237         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4238         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4239         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4240         if [[ $LOCKED -ne 0 ]]; then
4241                 error "Locked pages remain in cache, locked=$LOCKED"
4242         fi
4243         
4244         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4245                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4246         fi
4247
4248         rm -f $DIR/$tfile
4249         echo "No pages locked after fsync"
4250
4251         return 0
4252 }
4253 run_test 118h "Verify timeout in handling recoverables errors  =========="
4254
4255 test_118i() {
4256         reset_async
4257
4258         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4259         do_facet ost sysctl -w lustre.fail_loc=0x20e
4260         
4261         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4262         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4263         PID=$!
4264         sleep 5
4265         do_facet ost sysctl -w lustre.fail_loc=0
4266         
4267         wait $PID
4268         RC=$?
4269         if [[ $RC -ne 0 ]]; then
4270                 error "got error, but should be not, rc=$RC"
4271         fi
4272
4273         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4274         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4275         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4276         if [[ $LOCKED -ne 0 ]]; then
4277                 error "Locked pages remain in cache, locked=$LOCKED"
4278         fi
4279         
4280         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4281                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4282         fi
4283
4284         rm -f $DIR/$tfile
4285         echo "No pages locked after fsync"
4286
4287         return 0
4288 }
4289 run_test 118i "Fix error before timeout in recoverable error  =========="
4290
4291 test_118j() {
4292         reset_async
4293
4294         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
4295         do_facet ost sysctl -w lustre.fail_loc=0x220
4296
4297         # return -EIO from OST
4298         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4299         RC=$?
4300         do_facet ost sysctl -w lustre.fail_loc=0x0
4301         if [[ $RC -eq 0 ]]; then
4302                 error "Must return error due to dropped pages, rc=$RC"
4303         fi
4304
4305         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4306         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4307         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4308         if [[ $LOCKED -ne 0 ]]; then
4309                 error "Locked pages remain in cache, locked=$LOCKED"
4310         fi
4311         
4312         # in recoverable error on OST we want resend and stay until it finished
4313         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4314                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4315         fi
4316
4317         rm -f $DIR/$tfile
4318         echo "No pages locked after fsync"
4319
4320         return 0
4321 }
4322 run_test 118j "Simulate unrecoverable OST side error =========="
4323
4324 test_118k()
4325 {
4326         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4327         do_facet ost sysctl -w lustre.fail_loc=0x20e
4328         mkdir -p $DIR/$tdir
4329
4330         for ((i=0;i<10;i++)); do
4331                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
4332                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
4333                 SLEEPPID=$!
4334                 sleep 0.500s
4335                 kill $SLEEPPID
4336                 wait $SLEEPPID
4337         done
4338
4339         sysctl -w lustre.fail_loc=0
4340 }
4341 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
4342
4343 test_119a() # bug 11737
4344 {
4345         BSIZE=$((512 * 1024))
4346         directio write $DIR/$tfile 0 1 $BSIZE
4347         # We ask to read two blocks, which is more than a file size.
4348         # directio will indicate an error when requested and actual
4349         # sizes aren't equeal (a normal situation in this case) and
4350         # print actual read amount.
4351         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
4352         if [ "$NOB" != "$BSIZE" ]; then
4353                 error "read $NOB bytes instead of $BSIZE"
4354         fi
4355         rm -f $DIR/$tfile
4356 }
4357 run_test 119a "Short directIO read must return actual read amount"
4358
4359 test_119b() # bug 11737
4360 {
4361         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
4362
4363         $SETSTRIPE $DIR/$tfile -c 2
4364         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
4365         sync
4366         multiop $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
4367                 error "direct read failed"
4368         rm -f $DIR/$tfile
4369 }
4370 run_test 119b "Sparse directIO read must return actual read amount"
4371
4372 test_119c() # bug 13099
4373 {
4374         BSIZE=1048576
4375         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
4376         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
4377         rm -f $DIR/$tfile
4378 }
4379 run_test 119c "Testing for direct read hitting hole"
4380
4381 LDLM_POOL_CTL_RECALC=1
4382 LDLM_POOL_CTL_SHRINK=2
4383
4384 disable_pool_recalc() {
4385         for NSD in $LPROC/ldlm/namespaces/*$1*; do
4386                 if test -f $NSD/pool/control; then
4387                         CONTROL=`cat $NSD/pool/control`
4388                         CONTROL=$((CONTROL & ~LDLM_POOL_CTL_RECALC))
4389                         echo "$CONTROL" > $NSD/pool/control
4390                 fi
4391         done
4392 }
4393
4394 enable_pool_recalc() {
4395         for NSD in $LPROC/ldlm/namespaces/*$1*; do
4396                 if test -f $NSD/pool/control; then
4397                         CONTROL=`cat $NSD/pool/control`
4398                         CONTROL=$((CONTROL | LDLM_POOL_CTL_RECALC))
4399                         echo "$CONTROL" > $NSD/pool/control
4400                 fi
4401         done
4402 }
4403
4404 disable_pool_shrink() {
4405         for NSD in $LPROC/ldlm/namespaces/*$1*; do
4406                 if test -f $NSD/pool/control; then
4407                         CONTROL=`cat $NSD/pool/control`
4408                         CONTROL=$((CONTROL & ~LDLM_POOL_CTL_SHRINK))
4409                         echo "$CONTROL" > $NSD/pool/control
4410                 fi
4411         done
4412 }
4413
4414 enable_pool_shrink() {
4415         for NSD in $LPROC/ldlm/namespaces/*$1*; do
4416                 if test -f $NSD/pool/control; then
4417                         CONTROL=`cat $NSD/pool/control`
4418                         CONTROL=$((CONTROL | LDLM_POOL_CTL_SHRINK))
4419                         echo "$CONTROL" > $NSD/pool/control
4420                 fi
4421         done
4422 }
4423
4424 disable_pool() {
4425         disable_pool_shrink $1
4426         disable_pool_recalc $1
4427 }
4428
4429 enable_pool() {
4430         enable_pool_shrink $1
4431         enable_pool_recalc $1
4432 }
4433
4434 lru_resize_enable()
4435 {
4436         enable_pool osc
4437         enable_pool "filter-$FSNAME"
4438         enable_pool mdc
4439         enable_pool "mds-$FSNAME"
4440 }
4441
4442 lru_resize_disable()
4443 {
4444         disable_pool osc
4445         disable_pool "filter-$FSNAME"
4446         disable_pool mdc
4447         disable_pool "mds-$FSNAME"
4448 }
4449
4450 test_120a() {
4451         [ -z "`grep early_lock_cancel $LPROC/mdc/*/connect_flags`" ] && \
4452                skip "no early lock cancel on server" && return 0
4453         lru_resize_disable
4454         cancel_lru_locks mdc
4455         stat $DIR/$tdir > /dev/null
4456         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4457         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4458         mkdir -p $DIR/$tdir/d1
4459         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4460         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4461         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4462         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4463         lru_resize_enable
4464 }
4465 run_test 120a "Early Lock Cancel: mkdir test ==================="
4466
4467 test_120b() {
4468         [ -z "`grep early_lock_cancel $LPROC/mdc/*/connect_flags`" ] && \
4469                skip "no early lock cancel on server" && return 0
4470         lru_resize_disable
4471         cancel_lru_locks mdc
4472         stat $DIR/$tdir > /dev/null
4473         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4474         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4475         touch $DIR/$tdir/f1
4476         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4477         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4478         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4479         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4480         lru_resize_enable
4481 }
4482 run_test 120b "Early Lock Cancel: create test =================="
4483
4484 test_120c() {
4485         [ -z "`grep early_lock_cancel $LPROC/mdc/*/connect_flags`" ] && \
4486                skip "no early lock cancel on server" && return 0
4487         lru_resize_disable
4488         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
4489         touch $DIR/$tdir/d1/f1
4490         cancel_lru_locks mdc
4491         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
4492         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4493         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4494         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
4495         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4496         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4497         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4498         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4499         lru_resize_enable
4500 }
4501 run_test 120c "Early Lock Cancel: link test ===================="
4502
4503 test_120d() {
4504         [ -z "`grep early_lock_cancel $LPROC/mdc/*/connect_flags`" ] && \
4505                skip "no early lock cancel on server" && return 0
4506         lru_resize_disable
4507         touch $DIR/$tdir
4508         cancel_lru_locks mdc
4509         stat $DIR/$tdir > /dev/null
4510         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4511         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4512         chmod a+x $DIR/$tdir
4513         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4514         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4515         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4516         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4517         lru_resize_enable
4518 }
4519 run_test 120d "Early Lock Cancel: setattr test ================="
4520
4521 test_120e() {
4522         [ -z "`grep early_lock_cancel $LPROC/mdc/*/connect_flags`" ] && \
4523                skip "no early lock cancel on server" && return 0
4524         lru_resize_disable
4525         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
4526         cancel_lru_locks mdc
4527         cancel_lru_locks osc
4528         dd if=$DIR/$tdir/f1 of=/dev/null
4529         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
4530         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4531         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4532         unlink $DIR/$tdir/f1
4533         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4534         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4535         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4536         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4537         lru_resize_enable
4538 }
4539 run_test 120e "Early Lock Cancel: unlink test =================="
4540
4541 test_120f() {
4542         [ -z "`grep early_lock_cancel $LPROC/mdc/*/connect_flags`" ] && \
4543                skip "no early lock cancel on server" && return 0
4544         lru_resize_disable
4545         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
4546         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
4547         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
4548         cancel_lru_locks mdc
4549         cancel_lru_locks osc
4550         dd if=$DIR/$tdir/d1/f1 of=/dev/null
4551         dd if=$DIR/$tdir/d2/f2 of=/dev/null
4552         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
4553         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4554         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4555         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
4556         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4557         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4558         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4559         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4560         lru_resize_enable
4561 }
4562 run_test 120f "Early Lock Cancel: rename test =================="
4563
4564 test_120g() {
4565         [ -z "`grep early_lock_cancel $LPROC/mdc/*/connect_flags`" ] && \
4566                skip "no early lock cancel on server" && return 0
4567         lru_resize_disable
4568         count=10000
4569         echo create $count files
4570         mkdir -p $DIR/$tdir
4571         cancel_lru_locks mdc
4572         cancel_lru_locks osc
4573         t0=`date +%s`
4574         
4575         can0=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4576         blk0=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4577         createmany -o $DIR/$tdir/f $count
4578         sync
4579         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4580         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4581         t1=`date +%s`
4582         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
4583         echo rm $count files
4584         rm -r $DIR/$tdir
4585         sync
4586         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4587         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4588         t2=`date +%s`
4589         echo total: $count removes in $((t2-t1))
4590         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
4591         sleep 2
4592         # wait for commitment of removal
4593         lru_resize_enable
4594 }
4595 run_test 120g "Early Lock Cancel: performance test ============="
4596
4597 test_121() { #bug 10589
4598         writes=`dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}'`
4599         sysctl -w lustre.fail_loc=0x310
4600         cancel_lru_locks osc > /dev/null
4601         reads=`dd if=$DIR/$tfile of=/dev/null 2>&1 | awk 'BEGIN { FS="+" } /in/ {print $1}'`
4602         sysctl -w lustre.fail_loc=0
4603         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
4604 }
4605 run_test 121 "read cancel race ================================="
4606
4607 test_122() { #bug 11544
4608         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
4609         sysctl -w lustre.fail_loc=0x508
4610         dd if=/dev/zero of=$DIR/$tfile count=1
4611         sync
4612         sysctl -w lustre.fail_loc=0
4613 }
4614 run_test 122 "fail client bulk callback (shouldn't LBUG) ======="
4615
4616 test_123() # statahead(bug 11401)
4617 {
4618         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
4619                 log "testing on UP system. Performance may be not as good as expected."
4620         fi
4621
4622         mkdir -p $DIR/$tdir
4623
4624         for ((i=1, j=0; i<=100000; j=$i, i=$((i * 10)) )); do
4625                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
4626
4627                 grep '[0-9]' $LPROC/llite/*/statahead_max
4628                 cancel_lru_locks osc
4629                 stime=`date +%s`
4630                 ls -l $DIR/$tdir > /dev/null
4631                 etime=`date +%s`
4632                 delta_sa=$((etime - stime))
4633                 log "ls $i files with statahead:    $delta_sa sec"
4634
4635                 for client in $LPROC/llite/*; do
4636                         max=`cat $client/statahead_max`
4637                         cat $client/statahead_stats
4638                         echo 0 > $client/statahead_max
4639                 done
4640
4641                 grep '[0-9]' $LPROC/llite/*/statahead_max
4642                 cancel_lru_locks osc
4643                 stime=`date +%s`
4644                 ls -l $DIR/$tdir > /dev/null
4645                 etime=`date +%s`
4646                 delta=$((etime - stime))
4647                 log "ls $i files without statahead: $delta sec"
4648
4649                 for client in /proc/fs/lustre/llite/*; do
4650                         cat $client/statahead_stats
4651                         echo $max > $client/statahead_max
4652                 done
4653
4654                 if [ $delta_sa -gt $delta ]; then
4655                         log "ls $i files is slower with statahead!"
4656                 fi
4657
4658                 [ $delta -gt 20 ] && break
4659                 [ "$SLOW" = "no" -a $delta -gt 3 ] && break             
4660         done
4661         log "ls done"
4662
4663         stime=`date +%s`
4664         rm -r $DIR/$tdir
4665         sync
4666         etime=`date +%s`
4667         delta=$((etime - stime))
4668         log "rm -r $DIR/$tdir/: $delta seconds"
4669         log "rm done"
4670         cat $LPROC/llite/*/statahead_stats
4671         # wait for commitment of removal
4672         sleep 2
4673 }
4674 run_test 123 "verify statahead work"
4675
4676 test_124a() {
4677         [ -z "`grep lru_resize $LPROC/mdc/*/connect_flags`" ] && \
4678                skip "no lru resize on server" && return 0
4679         cancel_lru_locks mdc
4680         lru_resize_enable
4681         NSDIR=`find $LPROC/ldlm/namespaces | grep mdc | head -1`
4682
4683         # we want to test main pool functionality, that is cancel based on SLV
4684         # this is why shrinkers are disabled
4685         disable_pool_shrink "mds-$FSNAME"
4686         disable_pool_shrink mdc
4687
4688         NR=2000
4689         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
4690
4691         LRU_SIZE=`cat $NSDIR/lru_size`
4692
4693         # use touch to produce $NR new locks
4694         log "create $NR files at $DIR/$tdir"
4695         for ((i=0;i<$NR;i++)); do touch $DIR/$tdir/f$i; done
4696
4697         LRU_SIZE_B=`cat $NSDIR/lru_size`
4698         if test $LRU_SIZE -ge $LRU_SIZE_B; then
4699                 skip "No cached locks created!"
4700                 cat $NSDIR/pool/state
4701                 return 0
4702         fi
4703         LRU_SIZE_B=$((LRU_SIZE_B-LRU_SIZE))
4704         log "created $LRU_SIZE_B lock(s)"
4705
4706         # we want to sleep 30s to not make test too long
4707         SLEEP=30
4708         SLEEP_ADD=2
4709
4710         # we know that lru resize allows one client to hold $LIMIT locks for 10h
4711         MAX_HRS=10
4712
4713         # get the pool limit
4714         LIMIT=`cat $NSDIR/pool/limit`
4715
4716         # calculate lock volume factor taking into account data set size and the
4717         # rule that number of locks will be getting smaller durring sleep interval
4718         # and we need to additionally enforce LVF to take this into account.
4719         # Use $LRU_SIZE_B here to take into account real number of locks created
4720         # in the case of CMD, LRU_SIZE_B != $NR in most of cases
4721         LVF=$(($MAX_HRS * 60 * 60 * $LIMIT / $SLEEP))
4722         log "make client drop locks $LVF times faster so that ${SLEEP}s is enough to cancel $LRU_SIZE_B lock(s)"
4723         OLD_LVF=`cat $NSDIR/pool/lock_volume_factor`
4724         echo "$LVF" > $NSDIR/pool/lock_volume_factor
4725         log "sleep for $((SLEEP+SLEEP_ADD))s"
4726         sleep $((SLEEP+SLEEP_ADD))
4727         echo "$OLD_LVF" > $NSDIR/pool/lock_volume_factor
4728         LRU_SIZE_A=`cat $NSDIR/lru_size`
4729
4730         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
4731                 error "No locks dropped in "$((SLEEP+SLEEP_ADD))"s. LRU size: $LRU_SIZE_A"
4732                 lru_resize_enable
4733                 unlinkmany $DIR/$tdir/f $NR
4734                 return
4735         }
4736
4737         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in "$((SLEEP+SLEEP_ADD))"s"
4738         lru_resize_enable
4739         log "unlink $NR files at $DIR/$tdir"
4740         unlinkmany $DIR/$tdir/f $NR
4741 }
4742 run_test 124a "lru resize ======================================="
4743
4744 test_124b() {
4745         [ -z "`grep lru_resize $LPROC/mdc/*/connect_flags`" ] && \
4746                skip "no lru resize on server" && return 0
4747
4748         NSDIR=`find $LPROC/ldlm/namespaces | grep mdc | head -1`
4749         LIMIT=`cat $NSDIR/pool/limit`
4750
4751         #define LDLM_DEFAULT_LRU_SIZE (100 * num_online_cpus())
4752         NR_CPU=$(awk '/processor/' /proc/cpuinfo | wc -l)
4753         test $NR_CPU -gt 1 && SUFFIX="(s)" || SUFFIX=""
4754         # 100 locks here is default value for non-shrinkable lru as well
4755         # as the order to switch to static lru managing policy
4756         LDLM_DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4757         log "$NR_CPU CPU${SUFFIX} detected, LDLM_DEFAULT_LRU_SIZE = $LDLM_DEFAULT_LRU_SIZE"
4758
4759         log "disable lru resize for $(basename $NSDIR)"
4760         echo $LDLM_DEFAULT_LRU_SIZE > $NSDIR/lru_size
4761
4762         NR=$((LIMIT-(LIMIT/3)))
4763         mkdir -p $DIR/$tdir/disable_lru_resize || 
4764                 error "failed to create $DIR/$tdir/disable_lru_resize"
4765
4766         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
4767         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
4768         stime=`date +%s`
4769         ls -la $DIR/$tdir/disable_lru_resize > /dev/null
4770         ls -la $DIR/$tdir/disable_lru_resize > /dev/null
4771         ls -la $DIR/$tdir/disable_lru_resize > /dev/null
4772         etime=`date +%s`
4773         nolruresize_delta=$((etime-stime))
4774         log "ls -la time: $nolruresize_delta seconds"
4775         log "lru_size = $(cat $NSDIR/lru_size)"
4776
4777         mkdir -p $DIR/$tdir/enable_lru_resize || 
4778                 error "failed to create $DIR/$tdir/enable_lru_resize"
4779         
4780         # 0 locks means here flush lru and switch to lru resize policy 
4781         log "enable lru resize for $(basename $NSDIR)"
4782         echo 0 > $NSDIR/lru_size
4783
4784         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
4785         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
4786         stime=`date +%s`
4787         ls -la $DIR/$tdir/enable_lru_resize > /dev/null
4788         ls -la $DIR/$tdir/enable_lru_resize > /dev/null
4789         ls -la $DIR/$tdir/enable_lru_resize > /dev/null
4790         etime=`date +%s`
4791         lruresize_delta=$((etime-stime))
4792         log "ls -la time: $lruresize_delta seconds"
4793         log "lru_size = $(cat $NSDIR/lru_size)"
4794
4795         if test $lruresize_delta -gt $nolruresize_delta; then
4796                 log "ls -la is $((lruresize_delta - $nolruresize_delta))s slower with lru resize enabled"
4797         elif test $nolruresize_delta -gt $lruresize_delta; then
4798                 log "ls -la is $((nolruresize_delta - $lruresize_delta))s faster with lru resize enabled"
4799         else
4800                 log "lru resize performs the same with no lru resize"
4801         fi
4802 }
4803 run_test 124b "lru resize (performance test) ======================="
4804
4805 test_125() { # 13358
4806         [ -z "$(grep acl $LPROC/mdc/*-mdc-*/connect_flags)" ] && skip "must have acl enabled" && return
4807         mkdir -p $DIR/d125 || error "mkdir failed"
4808         $SETSTRIPE $DIR/d125 -s 65536 -c -1 || error "setstripe failed"
4809         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failes"
4810         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
4811 }
4812 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
4813
4814 test_126() { # bug 12829/13455
4815         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
4816         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
4817         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
4818         rm -f $DIR/$tfile
4819         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
4820 }
4821 run_test 126 "check that the fsgid provided by the client is taken into account"
4822
4823 TMPDIR=$OLDTMPDIR
4824 TMP=$OLDTMP
4825 HOME=$OLDHOME
4826
4827 log "cleanup: ======================================================"
4828 check_and_cleanup_lustre
4829 if [ "$I_MOUNTED" != "yes" ]; then
4830         sysctl -w lnet.debug="$OLDDEBUG" 2> /dev/null || true
4831 fi
4832
4833 echo '=========================== finished ==============================='
4834 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
4835 echo "$0: completed"