Whamcloud - gitweb
34593bf046b00a9924d8dcac617d4207a1edff33
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:autoindent:shiftwidth=4:tabstop=4:
4 #
5 # Run select tests by setting ONLY, or as arguments to the script.
6 # Skip specific tests by setting EXCEPT.
7 #
8 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
9 set -e
10
11 ONLY=${ONLY:-"$*"}
12 # bug number for skipped test:  13297 2108 9789 3637 9789 3561 12622 15528/2330 5188 10764 16410
13 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"27u  42a  42b  42c  42d  45   51d   62         68   75    76 $SANITY_EXCEPT"}
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
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=$(cd $(dirname $0); echo $PWD)
29 export PATH=$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 LFIND=${LFIND:-"$LFS find"}
39 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
40 LCTL=${LCTL:-lctl}
41 MCREATE=${MCREATE:-mcreate}
42 OPENFILE=${OPENFILE:-openfile}
43 OPENUNLINK=${OPENUNLINK:-openunlink}
44 READS=${READS:-"reads"}
45 TRUNCATE=${TRUNCATE:-truncate}
46 MUNLINK=${MUNLINK:-munlink}
47 SOCKETSERVER=${SOCKETSERVER:-socketserver}
48 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
49 IOPENTEST1=${IOPENTEST1:-iopentest1}
50 IOPENTEST2=${IOPENTEST2:-iopentest2}
51 MEMHOG=${MEMHOG:-memhog}
52 DIRECTIO=${DIRECTIO:-directio}
53 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
54 UMOUNT=${UMOUNT:-"umount -d"}
55 CHECK_GRANT=${CHECK_GRANT:-"yes"}
56 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
57
58 export NAME=${NAME:-local}
59
60 SAVE_PWD=$PWD
61
62 CLEANUP=${CLEANUP:-:}
63 SETUP=${SETUP:-:}
64 TRACE=${TRACE:-""}
65 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
66 . $LUSTRE/tests/test-framework.sh
67 init_test_env $@
68 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
69
70 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 36f 36g 51b 51c 60c 63 64b 68 71 73 77f 78 101 103 115 120g 124b"
71
72 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
73 FAIL_ON_ERROR=${FAIL_ON_ERROR:-false}
74
75 cleanup() {
76         echo -n "cln.."
77         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
78         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
79 }
80 setup() {
81         echo -n "mnt.."
82         load_modules
83         setupall || exit 10
84         echo "done"
85 }
86
87
88 check_kernel_version() {
89         VERSION_FILE=version
90         WANT_VER=$1
91         GOT_VER=$(lctl get_param -n $VERSION_FILE | awk '/kernel:/ {print $2}')
92         case $GOT_VER in
93         patchless|patchless_client) return 0;;
94         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
95         esac
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 assert_DIR
111
112 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
113 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
114 STRIPECOUNT=`lctl get_param -n lov.$LOVNAME.stripecount`
115 STRIPESIZE=`lctl get_param -n lov.$LOVNAME.stripesize`
116 ORIGFREE=`lctl get_param -n 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][0-9]*
122
123 # $RUNAS_ID may get set incorrectly somewhere else
124 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
125
126 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
127
128 build_test_filter
129
130 echo "preparing for tests involving mounts"
131 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
132 touch $EXT2_DEV
133 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
134 echo # add a newline after mke2fs.
135
136 umask 077
137
138 OLDDEBUG="`lctl get_param -n debug 2> /dev/null`"
139 lctl set_param debug=-1 2> /dev/null || true
140 test_0() {
141         touch $DIR/$tfile
142         $CHECKSTAT -t file $DIR/$tfile || error
143         rm $DIR/$tfile
144         $CHECKSTAT -a $DIR/$tfile || error
145 }
146 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
147
148 test_0b() {
149         chmod 0755 $DIR || error
150         $CHECKSTAT -p 0755 $DIR || error
151 }
152 run_test 0b "chmod 0755 $DIR ============================="
153
154 test_0c() {
155     $LCTL get_param mdc.*.import | grep  "state: FULL" || error "import not FULL"
156     $LCTL get_param mdc.*.import | grep  "target: $FSNAME-MDT" || error "bad target"
157 }
158 run_test 0c "check import proc ============================="
159
160 test_1a() {
161         mkdir $DIR/d1
162         mkdir $DIR/d1/d2
163         $CHECKSTAT -t dir $DIR/d1/d2 || error
164 }
165 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
166
167 test_1b() {
168         rmdir $DIR/d1/d2
169         rmdir $DIR/d1
170         $CHECKSTAT -a $DIR/d1 || error
171 }
172 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
173
174 test_2a() {
175         mkdir $DIR/d2
176         touch $DIR/d2/f
177         $CHECKSTAT -t file $DIR/d2/f || error
178 }
179 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
180
181 test_2b() {
182         rm -r $DIR/d2
183         $CHECKSTAT -a $DIR/d2 || error
184 }
185 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
186
187 test_3a() {
188         mkdir $DIR/d3
189         $CHECKSTAT -t dir $DIR/d3 || error
190 }
191 run_test 3a "mkdir .../d3 ======================================"
192
193 test_3b() {
194         if [ ! -d $DIR/d3 ]; then
195                 mkdir $DIR/d3
196         fi
197         touch $DIR/d3/f
198         $CHECKSTAT -t file $DIR/d3/f || error
199 }
200 run_test 3b "touch .../d3/f ===================================="
201
202 test_3c() {
203         rm -r $DIR/d3
204         $CHECKSTAT -a $DIR/d3 || error
205 }
206 run_test 3c "rm -r .../d3 ======================================"
207
208 test_4a() {
209         mkdir $DIR/d4
210         $CHECKSTAT -t dir $DIR/d4 || error
211 }
212 run_test 4a "mkdir .../d4 ======================================"
213
214 test_4b() {
215         if [ ! -d $DIR/d4 ]; then
216                 mkdir $DIR/d4
217         fi
218         mkdir $DIR/d4/d2
219         $CHECKSTAT -t dir $DIR/d4/d2 || error
220 }
221 run_test 4b "mkdir .../d4/d2 ==================================="
222
223 test_5() {
224         mkdir $DIR/d5
225         mkdir $DIR/d5/d2
226         chmod 0707 $DIR/d5/d2
227         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
228 }
229 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
230
231 test_6a() {
232         touch $DIR/f6a
233         chmod 0666 $DIR/f6a || error
234         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
235 }
236 run_test 6a "touch .../f6a; chmod .../f6a ======================"
237
238 test_6b() {
239         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
240         if [ ! -f $DIR/f6a ]; then
241                 touch $DIR/f6a
242                 chmod 0666 $DIR/f6a
243         fi
244         $RUNAS chmod 0444 $DIR/f6a && error
245         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
246 }
247 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
248
249 test_6c() {
250         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
251         touch $DIR/f6c
252         chown $RUNAS_ID $DIR/f6c || error
253         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
254 }
255 run_test 6c "touch .../f6c; chown .../f6c ======================"
256
257 test_6d() {
258         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
259         if [ ! -f $DIR/f6c ]; then
260                 touch $DIR/f6c
261                 chown $RUNAS_ID $DIR/f6c
262         fi
263         $RUNAS chown $UID $DIR/f6c && error
264         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
265 }
266 run_test 6d "$RUNAS chown .../f6c (should return error) =="
267
268 test_6e() {
269         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
270         touch $DIR/f6e
271         chgrp $RUNAS_ID $DIR/f6e || error
272         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
273 }
274 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
275
276 test_6f() {
277         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
278         if [ ! -f $DIR/f6e ]; then
279                 touch $DIR/f6e
280                 chgrp $RUNAS_ID $DIR/f6e
281         fi
282         $RUNAS chgrp $UID $DIR/f6e && error
283         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
284 }
285 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
286
287 test_6g() {
288         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
289         mkdir $DIR/d6g || error
290         chmod 777 $DIR/d6g || error
291         $RUNAS mkdir $DIR/d6g/d || error
292         chmod g+s $DIR/d6g/d || error
293         mkdir $DIR/d6g/d/subdir
294         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
295 }
296 run_test 6g "Is new dir in sgid dir inheriting group?"
297
298 test_6h() { # bug 7331
299         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
300         touch $DIR/f6h || error "touch failed"
301         chown $RUNAS_ID:$RUNAS_ID $DIR/f6h || error "initial chown failed"
302         $RUNAS -G$RUNAS_ID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
303         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_ID $DIR/f6h || error
304 }
305 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
306
307 test_7a() {
308         mkdir $DIR/d7
309         $MCREATE $DIR/d7/f
310         chmod 0666 $DIR/d7/f
311         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
312 }
313 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
314
315 test_7b() {
316         if [ ! -d $DIR/d7 ]; then
317                 mkdir $DIR/d7
318         fi
319         $MCREATE $DIR/d7/f2
320         echo -n foo > $DIR/d7/f2
321         [ "`cat $DIR/d7/f2`" = "foo" ] || error
322         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
323 }
324 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
325
326 test_8() {
327         mkdir $DIR/d8
328         touch $DIR/d8/f
329         chmod 0666 $DIR/d8/f
330         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
331 }
332 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
333
334 test_9() {
335         mkdir $DIR/d9
336         mkdir $DIR/d9/d2
337         mkdir $DIR/d9/d2/d3
338         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
339 }
340 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
341
342 test_10() {
343         mkdir $DIR/d10
344         mkdir $DIR/d10/d2
345         touch $DIR/d10/d2/f
346         $CHECKSTAT -t file $DIR/d10/d2/f || error
347 }
348 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
349
350 test_11() {
351         mkdir $DIR/d11
352         mkdir $DIR/d11/d2
353         chmod 0666 $DIR/d11/d2
354         chmod 0705 $DIR/d11/d2
355         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
356 }
357 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
358
359 test_12() {
360         mkdir $DIR/d12
361         touch $DIR/d12/f
362         chmod 0666 $DIR/d12/f
363         chmod 0654 $DIR/d12/f
364         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
365 }
366 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
367
368 test_13() {
369         mkdir $DIR/d13
370         dd if=/dev/zero of=$DIR/d13/f count=10
371         >  $DIR/d13/f
372         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
373 }
374 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
375
376 test_14() {
377         mkdir $DIR/d14
378         touch $DIR/d14/f
379         rm $DIR/d14/f
380         $CHECKSTAT -a $DIR/d14/f || error
381 }
382 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
383
384 test_15() {
385         mkdir $DIR/d15
386         touch $DIR/d15/f
387         mv $DIR/d15/f $DIR/d15/f2
388         $CHECKSTAT -t file $DIR/d15/f2 || error
389 }
390 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
391
392 test_16() {
393         mkdir $DIR/d16
394         touch $DIR/d16/f
395         rm -rf $DIR/d16/f
396         $CHECKSTAT -a $DIR/d16/f || error
397 }
398 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
399
400 test_17a() {
401         mkdir -p $DIR/d17
402         touch $DIR/d17/f
403         ln -s $DIR/d17/f $DIR/d17/l-exist
404         ls -l $DIR/d17
405         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
406         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
407         rm -f $DIR/d17/l-exist
408         $CHECKSTAT -a $DIR/d17/l-exist || error
409 }
410 run_test 17a "symlinks: create, remove (real) =================="
411
412 test_17b() {
413         mkdir -p $DIR/d17
414         ln -s no-such-file $DIR/d17/l-dangle
415         ls -l $DIR/d17
416         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
417         $CHECKSTAT -fa $DIR/d17/l-dangle || error
418         rm -f $DIR/d17/l-dangle
419         $CHECKSTAT -a $DIR/d17/l-dangle || error
420 }
421 run_test 17b "symlinks: create, remove (dangling) =============="
422
423 test_17c() { # bug 3440 - don't save failed open RPC for replay
424         mkdir -p $DIR/d17
425         ln -s foo $DIR/d17/f17c
426         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
427 }
428 run_test 17c "symlinks: open dangling (should return error) ===="
429
430 test_17d() {
431         mkdir -p $DIR/d17
432         ln -s foo $DIR/d17/f17d
433         touch $DIR/d17/f17d || error "creating to new symlink"
434 }
435 run_test 17d "symlinks: create dangling ========================"
436
437 test_17e() {
438         mkdir -p $DIR/$tdir
439         local foo=$DIR/$tdir/$tfile
440         ln -s $foo $foo || error "create symlink failed"
441         ls -l $foo || error "ls -l failed"
442         ls $foo && error "ls not failed" || true
443 }
444 run_test 17e "symlinks: create recursive symlink (should return error) ===="
445
446 test_17g() {
447         mkdir -p $DIR/$tdir
448         LONGSYMLINK="$(dd if=/dev/zero bs=4095 count=1 | tr '\0' 'x')"
449         ln -s $LONGSYMLINK $DIR/$tdir/$tfile
450         ls -l $DIR/$tdir
451 }
452 run_test 17g "symlinks: really long symlink name ==============================="
453
454 test_17h() { #bug 17378
455         mkdir -p $DIR/$tdir
456         $SETSTRIPE $DIR/$tdir -c -1
457 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
458         do_facet mds lctl set_param fail_loc=0x80000141
459         touch $DIR/$tdir/$tfile || true
460 }
461 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
462
463 test_17i() { #bug 20018
464         mkdir -p $DIR/$tdir
465         local foo=$DIR/$tdir/$tfile
466         ln -s $foo $foo || error "create symlink failed"
467 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
468         do_facet mds lctl set_param fail_loc=0x80000143
469         ls -l $foo && error "error not detected"
470         return 0
471 }
472 run_test 17i "don't panic on short symlink"
473
474 test_18() {
475         touch $DIR/f
476         ls $DIR || error
477 }
478 run_test 18 "touch .../f ; ls ... =============================="
479
480 test_19a() {
481         touch $DIR/f19
482         ls -l $DIR
483         rm $DIR/f19
484         $CHECKSTAT -a $DIR/f19 || error
485 }
486 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
487
488 test_19b() {
489         ls -l $DIR/f19 && error || true
490 }
491 run_test 19b "ls -l .../f19 (should return error) =============="
492
493 test_19c() {
494         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
495         $RUNAS touch $DIR/f19 && error || true
496 }
497 run_test 19c "$RUNAS touch .../f19 (should return error) =="
498
499 test_19d() {
500         cat $DIR/f19 && error || true
501 }
502 run_test 19d "cat .../f19 (should return error) =============="
503
504 test_20() {
505         touch $DIR/f
506         rm $DIR/f
507         log "1 done"
508         touch $DIR/f
509         rm $DIR/f
510         log "2 done"
511         touch $DIR/f
512         rm $DIR/f
513         log "3 done"
514         $CHECKSTAT -a $DIR/f || error
515 }
516 run_test 20 "touch .../f ; ls -l ... ==========================="
517
518 test_21() {
519         mkdir $DIR/d21
520         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
521         ln -s dangle $DIR/d21/link
522         echo foo >> $DIR/d21/link
523         cat $DIR/d21/dangle
524         $CHECKSTAT -t link $DIR/d21/link || error
525         $CHECKSTAT -f -t file $DIR/d21/link || error
526 }
527 run_test 21 "write to dangling link ============================"
528
529 test_22() {
530         WDIR=$DIR/$tdir
531         mkdir -p $WDIR
532         chown $RUNAS_ID $WDIR
533         (cd $WDIR || error "cd $WDIR failed";
534         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
535         $RUNAS tar xf -)
536         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
537         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
538         $CHECKSTAT -u \#$RUNAS_ID $WDIR/etc || error "checkstat -u failed"
539 }
540 run_test 22 "unpack tar archive as non-root user ==============="
541
542 # was test_23
543 test_23a() {
544         mkdir -p $DIR/$tdir
545         local file=$DIR/$tdir/$tfile
546
547         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
548         openfile -f O_CREAT:O_EXCL $file &&
549                 error "$file recreate succeeded" || true
550 }
551 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
552
553 test_23b() { # bug 18988
554         mkdir -p $DIR/$tdir
555         local file=$DIR/$tdir/$tfile
556
557         rm -f $file
558         echo foo > $file || error "write filed"
559         echo bar >> $file || error "append filed"
560         $CHECKSTAT -s 8 $file || error "wrong size"
561         rm $file
562 }
563 run_test 23b "O_APPEND check =========================="
564
565 test_24a() {
566         echo '== rename sanity =============================================='
567         echo '-- same directory rename'
568         mkdir $DIR/R1
569         touch $DIR/R1/f
570         mv $DIR/R1/f $DIR/R1/g
571         $CHECKSTAT -t file $DIR/R1/g || error
572 }
573 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
574
575 test_24b() {
576         mkdir $DIR/R2
577         touch $DIR/R2/{f,g}
578         mv $DIR/R2/f $DIR/R2/g
579         $CHECKSTAT -a $DIR/R2/f || error
580         $CHECKSTAT -t file $DIR/R2/g || error
581 }
582 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
583
584 test_24c() {
585         mkdir $DIR/R3
586         mkdir $DIR/R3/f
587         mv $DIR/R3/f $DIR/R3/g
588         $CHECKSTAT -a $DIR/R3/f || error
589         $CHECKSTAT -t dir $DIR/R3/g || error
590 }
591 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
592
593 test_24d() {
594         mkdir $DIR/R4
595         mkdir $DIR/R4/{f,g}
596         mrename $DIR/R4/f $DIR/R4/g
597         $CHECKSTAT -a $DIR/R4/f || error
598         $CHECKSTAT -t dir $DIR/R4/g || error
599 }
600 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
601
602 test_24e() {
603         echo '-- cross directory renames --'
604         mkdir $DIR/R5{a,b}
605         touch $DIR/R5a/f
606         mv $DIR/R5a/f $DIR/R5b/g
607         $CHECKSTAT -a $DIR/R5a/f || error
608         $CHECKSTAT -t file $DIR/R5b/g || error
609 }
610 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
611
612 test_24f() {
613         mkdir $DIR/R6{a,b}
614         touch $DIR/R6a/f $DIR/R6b/g
615         mv $DIR/R6a/f $DIR/R6b/g
616         $CHECKSTAT -a $DIR/R6a/f || error
617         $CHECKSTAT -t file $DIR/R6b/g || error
618 }
619 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
620
621 test_24g() {
622         mkdir $DIR/R7{a,b}
623         mkdir $DIR/R7a/d
624         mv $DIR/R7a/d $DIR/R7b/e
625         $CHECKSTAT -a $DIR/R7a/d || error
626         $CHECKSTAT -t dir $DIR/R7b/e || error
627 }
628 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R5b/e ======"
629
630 test_24h() {
631         mkdir $DIR/R8{a,b}
632         mkdir $DIR/R8a/d $DIR/R8b/e
633         mrename $DIR/R8a/d $DIR/R8b/e
634         $CHECKSTAT -a $DIR/R8a/d || error
635         $CHECKSTAT -t dir $DIR/R8b/e || error
636 }
637 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
638
639 test_24i() {
640         echo "-- rename error cases"
641         mkdir $DIR/R9
642         mkdir $DIR/R9/a
643         touch $DIR/R9/f
644         mrename $DIR/R9/f $DIR/R9/a
645         $CHECKSTAT -t file $DIR/R9/f || error
646         $CHECKSTAT -t dir  $DIR/R9/a || error
647         $CHECKSTAT -a $DIR/R9/a/f || error
648 }
649 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
650
651 test_24j() {
652         mkdir $DIR/R10
653         mrename $DIR/R10/f $DIR/R10/g
654         $CHECKSTAT -t dir $DIR/R10 || error
655         $CHECKSTAT -a $DIR/R10/f || error
656         $CHECKSTAT -a $DIR/R10/g || error
657 }
658 run_test 24j "source does not exist ============================"
659
660 test_24k() {
661         mkdir $DIR/R11a $DIR/R11a/d
662         touch $DIR/R11a/f
663         mv $DIR/R11a/f $DIR/R11a/d
664         $CHECKSTAT -a $DIR/R11a/f || error
665         $CHECKSTAT -t file $DIR/R11a/d/f || error
666 }
667 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
668
669 # bug 2429 - rename foo foo foo creates invalid file
670 test_24l() {
671         f="$DIR/f24l"
672         multiop $f OcNs || error
673 }
674 run_test 24l "Renaming a file to itself ========================"
675
676 test_24m() {
677         f="$DIR/f24m"
678         multiop $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
679         # on ext3 this does not remove either the source or target files
680         # though the "expected" operation would be to remove the source
681         $CHECKSTAT -t file ${f} || error "${f} missing"
682         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
683 }
684 run_test 24m "Renaming a file to a hard link to itself ========="
685
686 test_24n() {
687     f="$DIR/f24n"
688     # this stats the old file after it was renamed, so it should fail
689     touch ${f}
690     $CHECKSTAT ${f}
691     mv ${f} ${f}.rename
692     $CHECKSTAT ${f}.rename
693     $CHECKSTAT -a ${f}
694 }
695 run_test 24n "Statting the old file after renaming (Posix rename 2)"
696
697 test_24o() {
698         check_kernel_version 37 || return 0
699         mkdir -p $DIR/d24o
700         rename_many -s random -v -n 10 $DIR/d24o
701 }
702 run_test 24o "rename of files during htree split ==============="
703
704 test_24p() {
705         mkdir $DIR/R12{a,b}
706         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
707         mrename $DIR/R12a $DIR/R12b
708         $CHECKSTAT -a $DIR/R12a || error
709         $CHECKSTAT -t dir $DIR/R12b || error
710         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
711         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
712 }
713 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
714
715 test_24q() {
716         mkdir $DIR/R13{a,b}
717         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
718         multiop_bg_pause $DIR/R13b D_c || return 1
719         MULTIPID=$!
720
721         mrename $DIR/R13a $DIR/R13b
722         $CHECKSTAT -a $DIR/R13a || error
723         $CHECKSTAT -t dir $DIR/R13b || error
724         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
725         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
726         kill -USR1 $MULTIPID
727         wait $MULTIPID || error "multiop close failed"
728 }
729 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
730
731 test_24r() { #bug 3789
732         mkdir $DIR/R14a $DIR/R14a/b
733         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
734         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
735         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
736 }
737 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
738
739 test_24s() {
740         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
741         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
742         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
743         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
744 }
745 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
746 test_24t() {
747         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
748         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
749         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
750         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
751 }
752 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
753
754 test_24u() { # bug12192
755         multiop $DIR/$tfile C2w$((2048 * 1024))c || error
756         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
757 }
758 run_test 24u "create stripe file"
759
760 test_25a() {
761         echo '== symlink sanity ============================================='
762
763         mkdir $DIR/d25
764         ln -s d25 $DIR/s25
765         touch $DIR/s25/foo || error
766 }
767 run_test 25a "create file in symlinked directory ==============="
768
769 test_25b() {
770         [ ! -d $DIR/d25 ] && test_25a
771         $CHECKSTAT -t file $DIR/s25/foo || error
772 }
773 run_test 25b "lookup file in symlinked directory ==============="
774
775 test_26a() {
776         mkdir $DIR/d26
777         mkdir $DIR/d26/d26-2
778         ln -s d26/d26-2 $DIR/s26
779         touch $DIR/s26/foo || error
780 }
781 run_test 26a "multiple component symlink ======================="
782
783 test_26b() {
784         mkdir -p $DIR/d26b/d26-2
785         ln -s d26b/d26-2/foo $DIR/s26-2
786         touch $DIR/s26-2 || error
787 }
788 run_test 26b "multiple component symlink at end of lookup ======"
789
790 test_26c() {
791         mkdir $DIR/d26.2
792         touch $DIR/d26.2/foo
793         ln -s d26.2 $DIR/s26.2-1
794         ln -s s26.2-1 $DIR/s26.2-2
795         ln -s s26.2-2 $DIR/s26.2-3
796         chmod 0666 $DIR/s26.2-3/foo
797 }
798 run_test 26c "chain of symlinks ================================"
799
800 # recursive symlinks (bug 439)
801 test_26d() {
802         ln -s d26-3/foo $DIR/d26-3
803 }
804 run_test 26d "create multiple component recursive symlink ======"
805
806 test_26e() {
807         [ ! -h $DIR/d26-3 ] && test_26d
808         rm $DIR/d26-3
809 }
810 run_test 26e "unlink multiple component recursive symlink ======"
811
812 # recursive symlinks (bug 7022)
813 test_26f() {
814         mkdir -p $DIR/$tdir
815         mkdir $DIR/$tdir/$tfile        || error "mkdir $DIR/$tdir/$tfile failed"
816         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
817         mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
818         mkdir $tfile             || error "mkdir $tfile failed"
819         cd $tfile                || error "cd $tfile failed"
820         ln -s .. dotdot          || error "ln dotdot failed"
821         ln -s dotdot/lndir lndir || error "ln lndir failed"
822         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
823         output=`ls $tfile/$tfile/lndir/bar1`
824         [ "$output" = bar1 ] && error "unexpected output"
825         rm -r $tfile             || error "rm $tfile failed"
826         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
827 }
828 run_test 26f "rm -r of a directory which has recursive symlink ="
829
830 test_27a() {
831         echo '== stripe sanity =============================================='
832         mkdir -p $DIR/d27 || error "mkdir failed"
833         $GETSTRIPE $DIR/d27
834         $SETSTRIPE $DIR/d27/f0 -c 1 || error "lstripe failed"
835         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
836         pass
837         log "== test 27b: write to one stripe file ========================="
838         cp /etc/hosts $DIR/d27/f0 || error
839 }
840 run_test 27a "one stripe file =================================="
841
842 test_27c() {
843         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
844         mkdir -p $DIR/d27
845         $SETSTRIPE $DIR/d27/f01 -c 2 || error "lstripe failed"
846         [ `$GETSTRIPE $DIR/d27/f01 | grep -A 10 obdidx | wc -l` -eq 4 ] ||
847                 error "two-stripe file doesn't have two stripes"
848         pass
849         log "== test 27d: write to two stripe file file f01 ================"
850         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
851 }
852 run_test 27c "create two stripe file f01 ======================="
853
854 test_27d() {
855         mkdir -p $DIR/d27
856         $SETSTRIPE -c0 -i-1 -s0 $DIR/d27/fdef || error "lstripe failed"
857         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
858         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
859 }
860 run_test 27d "create file with default settings ================"
861
862 test_27e() {
863         mkdir -p $DIR/d27
864         $SETSTRIPE $DIR/d27/f12 -c 2 || error "lstripe failed"
865         $SETSTRIPE $DIR/d27/f12 -c 2 && error "lstripe succeeded twice"
866         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
867 }
868 run_test 27e "setstripe existing file (should return error) ======"
869
870 test_27f() {
871         mkdir -p $DIR/d27
872         $SETSTRIPE $DIR/d27/fbad -s 100 -i 0 -c 1 && error "lstripe failed"
873         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
874         $GETSTRIPE $DIR/d27/fbad || error "lfs getstripe failed"
875 }
876 run_test 27f "setstripe with bad stripe size (should return error)"
877
878 test_27g() {
879         mkdir -p $DIR/d27
880         $MCREATE $DIR/d27/fnone || error "mcreate failed"
881         pass
882         log "== test 27h: lfs getstripe with no objects ===================="
883         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" || error "has object"
884         pass
885         log "== test 27i: lfs getstripe with some objects =================="
886         touch $DIR/d27/fsome || error "touch failed"
887         $GETSTRIPE $DIR/d27/fsome | grep obdidx || error "missing objects"
888 }
889 run_test 27g "test lfs getstripe ==========================================="
890
891 test_27j() {
892         mkdir -p $DIR/d27
893         $SETSTRIPE $DIR/d27/f27j -i $OSTCOUNT && error "lstripe failed"||true
894 }
895 run_test 27j "setstripe with bad stripe offset (should return error)"
896
897 test_27k() { # bug 2844
898         mkdir -p $DIR/d27
899         FILE=$DIR/d27/f27k
900         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
901         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
902         $SETSTRIPE $FILE -s 67108864 || error "lstripe failed"
903         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
904         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
905         dd if=/dev/zero of=$FILE bs=4k count=1
906         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
907         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
908 }
909 run_test 27k "limit i_blksize for broken user apps ============="
910
911 test_27l() {
912         mkdir -p $DIR/d27
913         mcreate $DIR/f27l || error "creating file"
914         $RUNAS $SETSTRIPE $DIR/f27l -c 1 && \
915                 error "lstripe should have failed" || true
916 }
917 run_test 27l "check setstripe permissions (should return error)"
918
919 test_27m() {
920         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
921         if [ $ORIGFREE -gt $MAXFREE ]; then
922                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
923                 return
924         fi
925         mkdir -p $DIR/d27
926         $SETSTRIPE $DIR/d27/f27m_1 -i 0 -c 1
927         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE && \
928                 error "dd should fill OST0"
929         i=2
930         while $SETSTRIPE $DIR/d27/f27m_$i -i 0 -c 1 ; do
931                 i=`expr $i + 1`
932                 [ $i -gt 256 ] && break
933         done
934         i=`expr $i + 1`
935         touch $DIR/d27/f27m_$i
936         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
937                 error "OST0 was full but new created file still use it"
938         i=`expr $i + 1`
939         touch $DIR/d27/f27m_$i
940         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
941                 error "OST0 was full but new created file still use it"
942         rm -r $DIR/d27
943 }
944 run_test 27m "create file while OST0 was full =================="
945
946 sleep_maxage() {
947         local DELAY=$(do_facet mds lctl get_param -n lov.*.qos_maxage | awk '{print $1 + 2}')
948         sleep $DELAY
949 }
950
951 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
952 # if the OST isn't full anymore.
953 reset_enospc() {
954         local OSTIDX=${1:-""}
955
956         local list=$(comma_list $(osts_nodes))
957         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
958
959         do_nodes $list lctl set_param fail_loc=0
960         sleep_maxage
961 }
962
963 exhaust_precreations() {
964         local OSTIDX=$1
965         local FAILLOC=$2
966         local FAILIDX=${3:-$OSTIDX}
967
968         local OST=$(lfs osts | grep ${OSTIDX}": " | \
969                 awk '{print $2}' | sed -e 's/_UUID$//')
970
971         # on the mdt's osc
972         local mdtosc=$(get_mdtosc_proc_path $OST)
973         local last_id=$(do_facet mds lctl get_param -n osc.$mdtosc.prealloc_last_id)
974         local next_id=$(do_facet mds lctl get_param -n osc.$mdtosc.prealloc_next_id)
975
976         mkdir -p $DIR/$tdir/${OST}
977         $SETSTRIPE $DIR/$tdir/${OST} -i $OSTIDX -c 1
978         #define OBD_FAIL_OST_ENOSPC 0x215
979         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
980         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
981         echo "Creating to objid $last_id on ost $OST..."
982         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
983         do_facet mds "lctl get_param -n osc.$mdtosc.prealloc*" | grep '[0-9]'
984         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
985         sleep_maxage
986 }
987
988 exhaust_all_precreations() {
989         local i
990         for (( i=0; i < OSTCOUNT; i++ )) ; do
991                 exhaust_precreations $i $1 -1
992         done
993 }
994
995 test_27n() {
996         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
997         remote_mds_nodsh && skip "remote MDS with nodsh" && return
998         remote_ost_nodsh && skip "remote OST with nodsh" && return
999
1000         reset_enospc
1001         rm -f $DIR/$tdir/$tfile
1002         exhaust_precreations 0 0x80000215
1003         $SETSTRIPE -c -1 $DIR/$tdir
1004         touch $DIR/$tdir/$tfile || error
1005         $GETSTRIPE $DIR/$tdir/$tfile
1006         reset_enospc
1007 }
1008 run_test 27n "create file with some full OSTs =================="
1009
1010 test_27o() {
1011         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1012         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1013         remote_ost_nodsh && skip "remote OST with nodsh" && return
1014
1015         reset_enospc
1016         rm -f $DIR/$tdir/$tfile
1017         exhaust_all_precreations 0x215
1018
1019         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1020
1021         reset_enospc
1022         rm -rf $DIR/$tdir/*
1023 }
1024 run_test 27o "create file with all full OSTs (should error) ===="
1025
1026 test_27p() {
1027         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1028         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1029         remote_ost_nodsh && skip "remote OST with nodsh" && return
1030
1031         reset_enospc
1032         rm -f $DIR/$tdir/$tfile
1033         mkdir -p $DIR/$tdir
1034
1035         $MCREATE $DIR/$tdir/$tfile || error
1036         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error
1037         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error
1038
1039         exhaust_precreations 0 0x80000215
1040         echo foo >> $DIR/$tdir/$tfile || error
1041         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error
1042
1043         reset_enospc
1044 }
1045 run_test 27p "append to a truncated file with some full OSTs ==="
1046
1047 test_27q() {
1048         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1049         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1050         remote_ost_nodsh && skip "remote OST with nodsh" && return
1051
1052         reset_enospc
1053         rm -f $DIR/$tdir/$tfile
1054
1055         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1056         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1057         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1058
1059         exhaust_all_precreations 0x215
1060
1061         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1062         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1063
1064         reset_enospc
1065 }
1066 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1067
1068 test_27r() {
1069         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1070         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1071         remote_ost_nodsh && skip "remote OST with nodsh" && return
1072
1073         reset_enospc
1074         rm -f $DIR/$tdir/$tfile
1075         exhaust_precreations 0 0x80000215
1076
1077         $SETSTRIPE $DIR/$tdir/$tfile -i 0 -c 2 # && error
1078
1079         reset_enospc
1080 }
1081 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1082
1083 test_27s() { # bug 10725
1084         mkdir -p $DIR/$tdir
1085         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1086         local stripe_count=0
1087         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1088         $SETSTRIPE $DIR/$tdir -s $stripe_size -c $stripe_count && \
1089                 error "stripe width >= 2^32 succeeded" || true
1090 }
1091 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1092
1093 test_27t() { # bug 10864
1094         WDIR=`pwd`
1095         WLFS=`which lfs`
1096         cd $DIR
1097         touch $tfile
1098         $WLFS getstripe $tfile
1099         cd $WDIR
1100 }
1101 run_test 27t "check that utils parse path correctly"
1102
1103 test_27u() { # bug 4900
1104         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1105         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1106
1107         #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1108
1109         do_facet mds lctl set_param fail_loc=0x139
1110         mkdir -p $DIR/$tdir
1111         createmany -o $DIR/$tdir/t- 1000
1112         do_facet mds lctl set_param fail_loc=0
1113
1114         TLOG=$DIR/$tfile.getstripe
1115         $GETSTRIPE $DIR/$tdir > $TLOG
1116         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1117         unlinkmany $DIR/$tdir/t- 1000
1118         [ $OBJS -gt 0 ] && \
1119                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1120 }
1121 run_test 27u "skip object creation on OSC w/o objects =========="
1122
1123 test_27v() { # bug 4900
1124         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1125         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1126         remote_ost_nodsh && skip "remote OST with nodsh" && return
1127
1128         exhaust_all_precreations 0x215
1129         reset_enospc
1130
1131         mkdir -p $DIR/$tdir
1132         $SETSTRIPE $DIR/$tdir -c 1         # 1 stripe / file
1133
1134         touch $DIR/$tdir/$tfile
1135         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1136         # all except ost1
1137         for (( i=0; i < OSTCOUNT; i++ )) ; do
1138                 do_facet ost$i lctl set_param fail_loc=0x705
1139         done
1140         local START=`date +%s`
1141         createmany -o $DIR/$tdir/$tfile 32
1142
1143         local FINISH=`date +%s`
1144         local TIMEOUT=`lctl get_param -n timeout`
1145         [ $((FINISH - START)) -ge $((TIMEOUT / 2)) ] && \
1146                error "$FINISH - $START >= $TIMEOUT / 2"
1147
1148         reset_enospc
1149 }
1150 run_test 27v "skip object creation on slow OST ================="
1151
1152 test_27w() { # bug 10997
1153         mkdir -p $DIR/$tdir || error "mkdir failed"
1154         $SETSTRIPE $DIR/$tdir/f0 -s 65536 || error "lstripe failed"
1155         size=`$GETSTRIPE $DIR/$tdir/f0 -qs`
1156         [ $size -ne 65536 ] && error "stripe size $size != 65536" || true
1157
1158         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping multiple stripe count/offset test" && return
1159         for i in `seq 1 $OSTCOUNT`; do
1160                 offset=$(($i-1))
1161                 log setstripe $DIR/$tdir/f$i -c $i -i $offset
1162                 $SETSTRIPE $DIR/$tdir/f$i -c $i -i $offset || error "lstripe -c $i -i $offset failed"
1163                 count=`$GETSTRIPE -qc $DIR/$tdir/f$i`
1164                 index=`$GETSTRIPE -qo $DIR/$tdir/f$i`
1165                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1166                 [ $index -ne $offset ] && error "stripe offset $index != $offset" || true
1167         done
1168 }
1169 run_test 27w "check lfs setstripe -c -s -i options ============="
1170
1171 test_27x() {
1172         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1173         OFFSET=$(($OSTCOUNT - 1))
1174         OSTIDX=0
1175         local OST=$(lfs osts | awk '/'${OSTIDX}': / { print $2 }' | sed -e 's/_UUID$//')
1176
1177         mkdir -p $DIR/$tdir
1178         $SETSTRIPE $DIR/$tdir -c 1      # 1 stripe per file
1179         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1180         sleep_maxage
1181         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1182         for i in `seq 0 $OFFSET`; do
1183                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1184                 error "OST0 was degraded but new created file still use it"
1185         done
1186         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1187 }
1188 run_test 27x "create files while OST0 is degraded"
1189
1190 test_27y() {
1191         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1192         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1193
1194         MDS_OSCS=`do_facet mds lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
1195         OFFSET=$(($OSTCOUNT-1))
1196         OST=-1
1197         for OSC in $MDS_OSCS; do
1198                 if [ $OST == -1 ]; then {
1199                         OST=`osc_to_ost $OSC`
1200                 } else {
1201                         echo $OSC "is Deactivate:"
1202                         do_facet mds lctl --device  %$OSC deactivate
1203                 } fi
1204         done
1205
1206         OSTIDX=$(lfs osts | grep ${OST} | awk '{print $1}' | sed -e 's/://')
1207         mkdir -p $DIR/$tdir
1208         $SETSTRIPE $DIR/$tdir -c 1      # 1 stripe / file
1209
1210         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 1
1211         sleep_maxage
1212         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1213         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 0
1214
1215         for i in `seq 0 $OFFSET`; do
1216                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "$OSTIDX"` ] || \
1217                       error "files created on deactivated OSTs instead of degraded OST"
1218         done
1219         for OSC in $MDS_OSCS; do
1220                 [ `osc_to_ost $OSC` != $OST  ] && {
1221                         echo $OSC "is activate"
1222                         do_facet mds lctl --device %$OSC activate
1223                 }
1224         done
1225 }
1226 run_test 27y "create files while OST0 is degraded and the rest inactive"
1227
1228 # createtest also checks that device nodes are created and
1229 # then visible correctly (#2091)
1230 test_28() { # bug 2091
1231         mkdir $DIR/d28
1232         $CREATETEST $DIR/d28/ct || error
1233 }
1234 run_test 28 "create/mknod/mkdir with bad file types ============"
1235
1236 test_29() {
1237         cancel_lru_locks mdc
1238         mkdir $DIR/d29
1239         touch $DIR/d29/foo
1240         log 'first d29'
1241         ls -l $DIR/d29
1242         LOCKCOUNTORIG=`lctl get_param -n ldlm.namespaces.*mdc*.lock_count`
1243         LOCKUNUSEDCOUNTORIG=`lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count`
1244         [ -z $"LOCKCOUNTORIG" ] && error "No mdc lock count" && return 1
1245         log 'second d29'
1246         ls -l $DIR/d29
1247         log 'done'
1248         LOCKCOUNTCURRENT=`lctl get_param -n ldlm.namespaces.*mdc*.lock_count`
1249         LOCKUNUSEDCOUNTCURRENT=`lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count`
1250         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1251                 lctl set_param -n ldlm.dump_namespaces ""
1252                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1253                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1254                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1255                 return 2
1256         fi
1257         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1258                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1259                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1260                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1261                 return 3
1262         fi
1263 }
1264 run_test 29 "IT_GETATTR regression  ============================"
1265
1266 test_30() {
1267         cp `which ls` $DIR
1268         $DIR/ls /
1269         rm $DIR/ls
1270 }
1271 run_test 30 "run binary from Lustre (execve) ==================="
1272
1273 test_31a() {
1274         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1275         $CHECKSTAT -a $DIR/f31 || error
1276 }
1277 run_test 31a "open-unlink file =================================="
1278
1279 test_31b() {
1280         touch $DIR/f31 || error
1281         ln $DIR/f31 $DIR/f31b || error
1282         multiop $DIR/f31b Ouc || error
1283         $CHECKSTAT -t file $DIR/f31 || error
1284 }
1285 run_test 31b "unlink file with multiple links while open ======="
1286
1287 test_31c() {
1288         touch $DIR/f31 || error
1289         ln $DIR/f31 $DIR/f31c || error
1290         multiop_bg_pause $DIR/f31 O_uc || return 1
1291         MULTIPID=$!
1292         multiop $DIR/f31c Ouc
1293         kill -USR1 $MULTIPID
1294         wait $MULTIPID
1295 }
1296 run_test 31c "open-unlink file with multiple links ============="
1297
1298 test_31d() {
1299         opendirunlink $DIR/d31d $DIR/d31d || error
1300         $CHECKSTAT -a $DIR/d31d || error
1301 }
1302 run_test 31d "remove of open directory ========================="
1303
1304 test_31e() { # bug 2904
1305         check_kernel_version 34 || return 0
1306         openfilleddirunlink $DIR/d31e || error
1307 }
1308 run_test 31e "remove of open non-empty directory ==============="
1309
1310 test_31f() { # bug 4554
1311         set -vx
1312         mkdir $DIR/d31f
1313         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1314         cp /etc/hosts $DIR/d31f
1315         ls -l $DIR/d31f
1316         $GETSTRIPE $DIR/d31f/hosts
1317         multiop_bg_pause $DIR/d31f D_c || return 1
1318         MULTIPID=$!
1319
1320         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1321         mkdir $DIR/d31f
1322         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1323         cp /etc/hosts $DIR/d31f
1324         ls -l $DIR/d31f
1325         $DIR/d31f/hosts
1326         multiop_bg_pause $DIR/d31f D_c || return 1
1327         MULTIPID2=$!
1328
1329         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1330         wait $MULTIPID || error "first opendir $MULTIPID failed"
1331
1332         sleep 6
1333
1334         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1335         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1336         set +vx
1337 }
1338 run_test 31f "remove of open directory with open-unlink file ==="
1339
1340 test_32a() {
1341         echo "== more mountpoints and symlinks ================="
1342         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1343         mkdir -p $DIR/d32a/ext2-mountpoint
1344         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1345         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error
1346         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1347 }
1348 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1349
1350 test_32b() {
1351         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1352         mkdir -p $DIR/d32b/ext2-mountpoint
1353         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1354         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1355         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1356 }
1357 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1358
1359 test_32c() {
1360         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1361         mkdir -p $DIR/d32c/ext2-mountpoint
1362         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1363         mkdir -p $DIR/d32c/d2/test_dir
1364         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1365         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1366 }
1367 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1368
1369 test_32d() {
1370         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1371         mkdir -p $DIR/d32d/ext2-mountpoint
1372         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1373         mkdir -p $DIR/d32d/d2/test_dir
1374         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1375         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1376 }
1377 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1378
1379 test_32e() {
1380         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1381         mkdir -p $DIR/d32e/tmp
1382         TMP_DIR=$DIR/d32e/tmp
1383         ln -s $DIR/d32e $TMP_DIR/symlink11
1384         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1385         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1386         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1387 }
1388 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1389
1390 test_32f() {
1391         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1392         mkdir -p $DIR/d32f/tmp
1393         TMP_DIR=$DIR/d32f/tmp
1394         ln -s $DIR/d32f $TMP_DIR/symlink11
1395         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1396         ls $DIR/d32f/tmp/symlink11  || error
1397         ls $DIR/d32f/symlink01 || error
1398 }
1399 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1400
1401 test_32g() {
1402         TMP_DIR=$DIR/$tdir/tmp
1403         mkdir -p $TMP_DIR $DIR/${tdir}2
1404         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1405         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1406         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1407         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1408         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1409         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1410 }
1411 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1412
1413 test_32h() {
1414         rm -fr $DIR/$tdir $DIR/${tdir}2
1415         TMP_DIR=$DIR/$tdir/tmp
1416         mkdir -p $TMP_DIR $DIR/${tdir}2
1417         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1418         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1419         ls $TMP_DIR/symlink12 || error
1420         ls $DIR/$tdir/symlink02  || error
1421 }
1422 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1423
1424 test_32i() {
1425         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1426         mkdir -p $DIR/d32i/ext2-mountpoint
1427         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1428         touch $DIR/d32i/test_file
1429         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error
1430         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1431 }
1432 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1433
1434 test_32j() {
1435         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1436         mkdir -p $DIR/d32j/ext2-mountpoint
1437         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1438         touch $DIR/d32j/test_file
1439         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1440         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1441 }
1442 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1443
1444 test_32k() {
1445         rm -fr $DIR/d32k
1446         mkdir -p $DIR/d32k/ext2-mountpoint
1447         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint
1448         mkdir -p $DIR/d32k/d2
1449         touch $DIR/d32k/d2/test_file || error
1450         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1451         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1452 }
1453 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1454
1455 test_32l() {
1456         rm -fr $DIR/d32l
1457         mkdir -p $DIR/d32l/ext2-mountpoint
1458         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1459         mkdir -p $DIR/d32l/d2
1460         touch $DIR/d32l/d2/test_file
1461         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1462         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1463 }
1464 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1465
1466 test_32m() {
1467         rm -fr $DIR/d32m
1468         mkdir -p $DIR/d32m/tmp
1469         TMP_DIR=$DIR/d32m/tmp
1470         ln -s $DIR $TMP_DIR/symlink11
1471         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1472         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1473         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1474 }
1475 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1476
1477 test_32n() {
1478         rm -fr $DIR/d32n
1479         mkdir -p $DIR/d32n/tmp
1480         TMP_DIR=$DIR/d32n/tmp
1481         ln -s $DIR $TMP_DIR/symlink11
1482         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1483         ls -l $DIR/d32n/tmp/symlink11  || error
1484         ls -l $DIR/d32n/symlink01 || error
1485 }
1486 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1487
1488 test_32o() {
1489         rm -fr $DIR/d32o $DIR/$tfile
1490         touch $DIR/$tfile
1491         mkdir -p $DIR/d32o/tmp
1492         TMP_DIR=$DIR/d32o/tmp
1493         ln -s $DIR/$tfile $TMP_DIR/symlink12
1494         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1495         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1496         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1497         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1498         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1499 }
1500 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1501
1502 test_32p() {
1503     log 32p_1
1504         rm -fr $DIR/d32p
1505     log 32p_2
1506         rm -f $DIR/$tfile
1507     log 32p_3
1508         touch $DIR/$tfile
1509     log 32p_4
1510         mkdir -p $DIR/d32p/tmp
1511     log 32p_5
1512         TMP_DIR=$DIR/d32p/tmp
1513     log 32p_6
1514         ln -s $DIR/$tfile $TMP_DIR/symlink12
1515     log 32p_7
1516         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1517     log 32p_8
1518         cat $DIR/d32p/tmp/symlink12 || error
1519     log 32p_9
1520         cat $DIR/d32p/symlink02 || error
1521     log 32p_10
1522 }
1523 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1524
1525 test_32q() {
1526         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1527         mkdir -p $DIR/d32q
1528         touch $DIR/d32q/under_the_mount
1529         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1530         ls $DIR/d32q/under_the_mount && error || true
1531         $UMOUNT $DIR/d32q || error
1532 }
1533 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1534
1535 test_32r() {
1536         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1537         mkdir -p $DIR/d32r
1538         touch $DIR/d32r/under_the_mount
1539         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1540         ls $DIR/d32r | grep -q under_the_mount && error || true
1541         $UMOUNT $DIR/d32r || error
1542 }
1543 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1544
1545 test_33() {
1546         rm -f $DIR/$tfile
1547         touch $DIR/$tfile
1548         chmod 444 $DIR/$tfile
1549         chown $RUNAS_ID $DIR/$tfile
1550         log 33_1
1551         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1552         log 33_2
1553 }
1554 run_test 33 "write file with mode 444 (should return error) ===="
1555
1556 test_33a() {
1557         rm -fr $DIR/d33
1558         mkdir -p $DIR/d33
1559         chown $RUNAS_ID $DIR/d33
1560         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1561         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1562                 error "open RDWR" || true
1563 }
1564 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1565
1566 test_33b() {
1567         rm -fr $DIR/d33
1568         mkdir -p $DIR/d33
1569         chown $RUNAS_ID $DIR/d33
1570         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
1571 }
1572 run_test 33b "test open file with malformed flags (No panic)"
1573
1574 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1575 test_34a() {
1576         rm -f $DIR/f34
1577         $MCREATE $DIR/f34 || error
1578         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1579         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1580         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1581         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1582 }
1583 run_test 34a "truncate file that has not been opened ==========="
1584
1585 test_34b() {
1586         [ ! -f $DIR/f34 ] && test_34a
1587         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1588         $OPENFILE -f O_RDONLY $DIR/f34
1589         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1590         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1591 }
1592 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1593
1594 test_34c() {
1595         [ ! -f $DIR/f34 ] && test_34a
1596         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1597         $OPENFILE -f O_RDWR $DIR/f34
1598         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
1599         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1600 }
1601 run_test 34c "O_RDWR opening file-with-size works =============="
1602
1603 test_34d() {
1604         [ ! -f $DIR/f34 ] && test_34a
1605         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1606         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1607         rm $DIR/f34
1608 }
1609 run_test 34d "write to sparse file ============================="
1610
1611 test_34e() {
1612         rm -f $DIR/f34e
1613         $MCREATE $DIR/f34e || error
1614         $TRUNCATE $DIR/f34e 1000 || error
1615         $CHECKSTAT -s 1000 $DIR/f34e || error
1616         $OPENFILE -f O_RDWR $DIR/f34e
1617         $CHECKSTAT -s 1000 $DIR/f34e || error
1618 }
1619 run_test 34e "create objects, some with size and some without =="
1620
1621 test_34f() { # bug 6242, 6243
1622         SIZE34F=48000
1623         rm -f $DIR/f34f
1624         $MCREATE $DIR/f34f || error
1625         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
1626         dd if=$DIR/f34f of=$TMP/f34f
1627         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
1628         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
1629         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
1630         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
1631         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
1632 }
1633 run_test 34f "read from a file with no objects until EOF ======="
1634
1635 test_35a() {
1636         cp /bin/sh $DIR/f35a
1637         chmod 444 $DIR/f35a
1638         chown $RUNAS_ID $DIR/f35a
1639         $RUNAS $DIR/f35a && error || true
1640         rm $DIR/f35a
1641 }
1642 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1643
1644 test_36a() {
1645         rm -f $DIR/f36
1646         utime $DIR/f36 || error
1647 }
1648 run_test 36a "MDS utime check (mknod, utime) ==================="
1649
1650 test_36b() {
1651         echo "" > $DIR/f36
1652         utime $DIR/f36 || error
1653 }
1654 run_test 36b "OST utime check (open, utime) ===================="
1655
1656 test_36c() {
1657         rm -f $DIR/d36/f36
1658         mkdir $DIR/d36
1659         chown $RUNAS_ID $DIR/d36
1660         $RUNAS utime $DIR/d36/f36 || error
1661 }
1662 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1663
1664 test_36d() {
1665         [ ! -d $DIR/d36 ] && test_36c
1666         echo "" > $DIR/d36/f36
1667         $RUNAS utime $DIR/d36/f36 || error
1668 }
1669 run_test 36d "non-root OST utime check (open, utime) ==========="
1670
1671 test_36e() {
1672         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
1673         mkdir -p $DIR/$tdir
1674         touch $DIR/$tdir/$tfile
1675         $RUNAS utime $DIR/$tdir/$tfile && \
1676                 error "utime worked, expected failure" || true
1677 }
1678 run_test 36e "utime on non-owned file (should return error) ===="
1679
1680 test_36f() {
1681         export LANG=C LC_LANG=C # for date language
1682
1683         DATESTR="Dec 20  2000"
1684         mkdir -p $DIR/$tdir
1685         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1686         lctl set_param fail_loc=0x80000214
1687         date; date +%s
1688         cp /etc/hosts $DIR/$tdir/$tfile
1689         sync & # write RPC generated with "current" inode timestamp, but delayed
1690         sleep 1
1691         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
1692         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
1693         cancel_lru_locks osc
1694         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
1695         date; date +%s
1696         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
1697                 echo "BEFORE: $LS_BEFORE" && \
1698                 echo "AFTER : $LS_AFTER" && \
1699                 echo "WANT  : $DATESTR" && \
1700                 error "$DIR/$tdir/$tfile timestamps changed" || true
1701 }
1702 run_test 36f "utime on file racing with OST BRW write =========="
1703
1704 test_36g() {
1705         remote_ost_nodsh && skip "remote OST with nodsh" && return
1706
1707         mkdir -p $DIR/$tdir
1708         export FMD_MAX_AGE=`do_facet ost1 lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | head -n 1`
1709         FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1710         touch $DIR/$tdir/$tfile
1711         sleep $((FMD_MAX_AGE + 12))
1712         FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1713         [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
1714                 echo "AFTER : $FMD_AFTER > BEFORE $FMD_BEFORE" && \
1715                 error "fmd didn't expire after ping" || true
1716 }
1717 run_test 36g "filter mod data cache expiry ====================="
1718
1719 test_37() {
1720         mkdir -p $DIR/$tdir
1721         echo f > $DIR/$tdir/fbugfile
1722         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
1723         ls $DIR/$tdir | grep "\<fbugfile\>" && error
1724         $UMOUNT $DIR/$tdir || error
1725         rm -f $DIR/$tdir/fbugfile || error
1726 }
1727 run_test 37 "ls a mounted file system to check old content ====="
1728
1729 test_38() {
1730         local file=$DIR/$tfile
1731         touch $file
1732         openfile -f O_DIRECTORY $file
1733         local RC=$?
1734         local ENOTDIR=20
1735         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
1736         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
1737 }
1738 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
1739
1740 test_39() {
1741         touch $DIR/$tfile
1742         touch $DIR/${tfile}2
1743 #       ls -l  $DIR/$tfile $DIR/${tfile}2
1744 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
1745 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
1746         sleep 2
1747         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
1748         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
1749                 echo "mtime"
1750                 ls -l  $DIR/$tfile $DIR/${tfile}2
1751                 echo "atime"
1752                 ls -lu  $DIR/$tfile $DIR/${tfile}2
1753                 echo "ctime"
1754                 ls -lc  $DIR/$tfile $DIR/${tfile}2
1755                 error "O_TRUNC didn't change timestamps"
1756         fi
1757 }
1758 run_test 39 "mtime changed on create ==========================="
1759
1760 function get_times() {
1761         FILE=$1
1762         TIME=$2
1763
1764         i=0
1765         for time in `stat -c "%X %Y %Z" $FILE`; do
1766                 eval "$TIME[$i]=$time"
1767                 i=$(($i + 1))
1768         done
1769 }
1770
1771 test_39b() {
1772         ATIME=0
1773         MTIME=1
1774         CTIME=2
1775         mkdir -p $DIR/$tdir
1776         cp -p /etc/passwd $DIR/$tdir/fopen
1777         cp -p /etc/passwd $DIR/$tdir/flink
1778         cp -p /etc/passwd $DIR/$tdir/funlink
1779         cp -p /etc/passwd $DIR/$tdir/frename
1780         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
1781
1782         get_times $DIR/$tdir/fopen OPEN_OLD
1783         get_times $DIR/$tdir/flink LINK_OLD
1784         get_times $DIR/$tdir/funlink UNLINK_OLD
1785         get_times $DIR/$tdir/frename RENAME_OLD
1786
1787         sleep 1
1788         echo "aaaaaa" >> $DIR/$tdir/fopen
1789         echo "aaaaaa" >> $DIR/$tdir/flink
1790         echo "aaaaaa" >> $DIR/$tdir/funlink
1791         echo "aaaaaa" >> $DIR/$tdir/frename
1792
1793         get_times $DIR/$tdir/fopen OPEN_NEW
1794         get_times $DIR/$tdir/flink LINK_NEW
1795         get_times $DIR/$tdir/funlink UNLINK_NEW
1796         get_times $DIR/$tdir/frename RENAME_NEW
1797
1798         cat $DIR/$tdir/fopen > /dev/null
1799         ln $DIR/$tdir/flink $DIR/$tdir/flink2
1800         rm -f $DIR/$tdir/funlink2
1801         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
1802
1803         get_times $DIR/$tdir/fopen OPEN_NEW2
1804         get_times $DIR/$tdir/flink LINK_NEW2
1805         get_times $DIR/$tdir/funlink UNLINK_NEW2
1806         get_times $DIR/$tdir/frename2 RENAME_NEW2
1807         echo ${OPEN_OLD[1]},${OPEN_NEW[$MTIME]},${OPEN_NEW2[$MTIME]}
1808         echo ${LINK_OLD[1]},${LINK_NEW[$MTIME]},${LINK_NEW2[$MTIME]}
1809         echo ${UNLINK_OLD[1]},${UNLINK_NEW[$MTIME]},${UNLINK_NEW2[$MTIME]}
1810         echo ${RENAME_OLD[1]},${RENAME_NEW[$MTIME]},${RENAME_NEW2[$MTIME]}
1811
1812         [ ${OPEN_NEW2[$MTIME]} -eq ${OPEN_NEW[$MTIME]} ] || error "open file reverses mtime"
1813         [ ${LINK_NEW2[$MTIME]} -eq ${LINK_NEW[$MTIME]} ] || error "link file reverses mtime"
1814         [ ${UNLINK_NEW2[$MTIME]} -eq ${UNLINK_NEW[$MTIME]} ] || error "unlink file reverses mtime"
1815         [ ${RENAME_NEW2[$MTIME]} -eq ${RENAME_NEW[$MTIME]} ] || error "rename file reverses mtime"
1816 }
1817 run_test 39b "mtime change on close ============================"
1818
1819 # bug 11063
1820 test_39c() {
1821         touch -m -d "10 years ago" $DIR1/$tfile
1822         local MTIME1=`stat -c %y $DIR1/$tfile`
1823         echo hello >> $DIR1/$tfile
1824         local MTIME2=`stat -c %y $DIR1/$tfile`
1825         mv $DIR1/$tfile $DIR1/$tfile-1
1826         local MTIME3=`stat -c %y $DIR1/$tfile-1`
1827         [ "$MTIME2" = "$MTIME3" ] ||
1828                 error "mtime ($MTIME2) changed (to $MTIME3) on rename (BZ#11063)"
1829 }
1830 run_test 39c "mtime change on rename ==========================="
1831
1832 test_40() {
1833         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1834         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1835         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1836 }
1837 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1838
1839 test_41() {
1840         # bug 1553
1841         small_write $DIR/f41 18
1842 }
1843 run_test 41 "test small file write + fstat ====================="
1844
1845 count_ost_writes() {
1846         lctl get_param -n osc.*.stats |
1847             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1848 }
1849
1850 # decent default
1851 WRITEBACK_SAVE=500
1852 DIRTY_RATIO_SAVE=40
1853 MAX_DIRTY_RATIO=50
1854 BG_DIRTY_RATIO_SAVE=10
1855 MAX_BG_DIRTY_RATIO=25
1856
1857 start_writeback() {
1858         trap 0
1859         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
1860         # dirty_ratio, dirty_background_ratio
1861         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1862                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
1863                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
1864                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
1865         else
1866                 # if file not here, we are a 2.4 kernel
1867                 kill -CONT `pidof kupdated`
1868         fi
1869 }
1870
1871 stop_writeback() {
1872         # setup the trap first, so someone cannot exit the test at the
1873         # exact wrong time and mess up a machine
1874         trap start_writeback EXIT
1875         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1876         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1877                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
1878                 sysctl -w vm.dirty_writeback_centisecs=0
1879                 # save and increase /proc/sys/vm/dirty_ratio
1880                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
1881                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
1882                 # save and increase /proc/sys/vm/dirty_background_ratio
1883                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
1884                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
1885         else
1886                 # if file not here, we are a 2.4 kernel
1887                 kill -STOP `pidof kupdated`
1888         fi
1889 }
1890
1891 # ensure that all stripes have some grant before we test client-side cache
1892 setup_test42() {
1893         [ "$SETUP_TEST42" ] && return
1894         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1895                 dd if=/dev/zero of=$i bs=4k count=1
1896                 rm $i
1897         done
1898         SETUP_TEST42=DONE
1899 }
1900
1901 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1902 # file truncation, and file removal.
1903 test_42a() {
1904         setup_test42
1905         cancel_lru_locks osc
1906         stop_writeback
1907         sync; sleep 1; sync # just to be safe
1908         BEFOREWRITES=`count_ost_writes`
1909         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
1910         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1911         AFTERWRITES=`count_ost_writes`
1912         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1913                 error "$BEFOREWRITES < $AFTERWRITES"
1914         start_writeback
1915 }
1916 run_test 42a "ensure that we don't flush on close =============="
1917
1918 test_42b() {
1919         setup_test42
1920         cancel_lru_locks osc
1921         stop_writeback
1922         sync
1923         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1924         BEFOREWRITES=`count_ost_writes`
1925         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1926         AFTERWRITES=`count_ost_writes`
1927         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1928                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
1929         fi
1930         BEFOREWRITES=`count_ost_writes`
1931         sync || error "sync: $?"
1932         AFTERWRITES=`count_ost_writes`
1933         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1934                 error "$BEFOREWRITES < $AFTERWRITES on sync"
1935         fi
1936         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1937         start_writeback
1938         return 0
1939 }
1940 run_test 42b "test destroy of file with cached dirty data ======"
1941
1942 # if these tests just want to test the effect of truncation,
1943 # they have to be very careful.  consider:
1944 # - the first open gets a {0,EOF}PR lock
1945 # - the first write conflicts and gets a {0, count-1}PW
1946 # - the rest of the writes are under {count,EOF}PW
1947 # - the open for truncate tries to match a {0,EOF}PR
1948 #   for the filesize and cancels the PWs.
1949 # any number of fixes (don't get {0,EOF} on open, match
1950 # composite locks, do smarter file size management) fix
1951 # this, but for now we want these tests to verify that
1952 # the cancellation with truncate intent works, so we
1953 # start the file with a full-file pw lock to match against
1954 # until the truncate.
1955 trunc_test() {
1956         test=$1
1957         file=$DIR/$test
1958         offset=$2
1959         cancel_lru_locks osc
1960         stop_writeback
1961         # prime the file with 0,EOF PW to match
1962         touch $file
1963         $TRUNCATE $file 0
1964         sync; sync
1965         # now the real test..
1966         dd if=/dev/zero of=$file bs=1024 count=100
1967         BEFOREWRITES=`count_ost_writes`
1968         $TRUNCATE $file $offset
1969         cancel_lru_locks osc
1970         AFTERWRITES=`count_ost_writes`
1971         start_writeback
1972 }
1973
1974 test_42c() {
1975         trunc_test 42c 1024
1976         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1977             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
1978         rm $file
1979 }
1980 run_test 42c "test partial truncate of file with cached dirty data"
1981
1982 test_42d() {
1983         trunc_test 42d 0
1984         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1985             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1986         rm $file
1987 }
1988 run_test 42d "test complete truncate of file with cached dirty data"
1989
1990 test_43() {
1991         mkdir -p $DIR/$tdir
1992         cp -p /bin/ls $DIR/$tdir/$tfile
1993         multiop $DIR/$tdir/$tfile Ow_c &
1994         pid=$!
1995         # give multiop a chance to open
1996         sleep 1
1997
1998         $DIR/$tdir/$tfile && error || true
1999         kill -USR1 $pid
2000 }
2001 run_test 43 "execution of file opened for write should return -ETXTBSY"
2002
2003 test_43a() {
2004         mkdir -p $DIR/d43
2005         cp -p `which multiop` $DIR/d43/multiop
2006         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2007         MULTIOP_PID=$!
2008         multiop $DIR/d43/multiop Oc && error "expected error, got success"
2009         kill -USR1 $MULTIOP_PID || return 2
2010         wait $MULTIOP_PID || return 3
2011         rm $TMP/test43.junk
2012 }
2013 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
2014
2015 test_43b() {
2016         mkdir -p $DIR/d43
2017         cp -p `which multiop` $DIR/d43/multiop
2018         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2019         MULTIOP_PID=$!
2020         truncate $DIR/d43/multiop 0 && error "expected error, got success"
2021         kill -USR1 $MULTIOP_PID || return 2
2022         wait $MULTIOP_PID || return 3
2023         rm $TMP/test43.junk
2024 }
2025 run_test 43b "truncate of file being executed should return -ETXTBSY"
2026
2027 test_43c() {
2028         local testdir="$DIR/d43c"
2029         mkdir -p $testdir
2030         cp $SHELL $testdir/
2031         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
2032                 ( cd $testdir && md5sum -c)
2033 }
2034 run_test 43c "md5sum of copy into lustre========================"
2035
2036 test_44() {
2037         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
2038         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
2039         dd if=$DIR/f1 of=/dev/null bs=4k count=1
2040 }
2041 run_test 44 "zero length read from a sparse stripe ============="
2042
2043 test_44a() {
2044     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
2045                          awk '{print $2}'`
2046     [ -z "$nstripe" ] && skip "can't get stripe info" && return
2047     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
2048     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
2049                       awk '{print $2}'`
2050     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
2051         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
2052     fi
2053
2054     OFFSETS="0 $((stride/2)) $((stride-1))"
2055     for offset in $OFFSETS ; do
2056       for i in `seq 0 $((nstripe-1))`; do
2057         rm -f $DIR/d44a
2058         local GLOBALOFFSETS=""
2059         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
2060         ll_sparseness_write $DIR/d44a $size  || error "ll_sparseness_write"
2061         GLOBALOFFSETS="$GLOBALOFFSETS $size"
2062         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
2063                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2064
2065         for j in `seq 0 $((nstripe-1))`; do
2066             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
2067             ll_sparseness_write $DIR/d44a $size || error "ll_sparseness_write"
2068             GLOBALOFFSETS="$GLOBALOFFSETS $size"
2069         done
2070         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
2071                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2072       done
2073     done
2074 }
2075 run_test 44a "test sparse pwrite ==============================="
2076
2077 dirty_osc_total() {
2078         tot=0
2079         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
2080                 tot=$(($tot + d))
2081         done
2082         echo $tot
2083 }
2084 do_dirty_record() {
2085         before=`dirty_osc_total`
2086         echo executing "\"$*\""
2087         eval $*
2088         after=`dirty_osc_total`
2089         echo before $before, after $after
2090 }
2091 test_45() {
2092         f="$DIR/f45"
2093         # Obtain grants from OST if it supports it
2094         echo blah > ${f}_grant
2095         stop_writeback
2096         sync
2097         do_dirty_record "echo blah > $f"
2098         [ $before -eq $after ] && error "write wasn't cached"
2099         do_dirty_record "> $f"
2100         [ $before -gt $after ] || error "truncate didn't lower dirty count"
2101         do_dirty_record "echo blah > $f"
2102         [ $before -eq $after ] && error "write wasn't cached"
2103         do_dirty_record "sync"
2104         [ $before -gt $after ] || error "writeback didn't lower dirty count"
2105         do_dirty_record "echo blah > $f"
2106         [ $before -eq $after ] && error "write wasn't cached"
2107         do_dirty_record "cancel_lru_locks osc"
2108         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
2109         start_writeback
2110 }
2111 run_test 45 "osc io page accounting ============================"
2112
2113 page_size() {
2114         getconf PAGE_SIZE
2115 }
2116
2117 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
2118 # test tickles a bug where re-dirtying a page was failing to be mapped to the
2119 # objects offset and an assert hit when an rpc was built with 1023's mapped
2120 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
2121 test_46() {
2122         f="$DIR/f46"
2123         stop_writeback
2124         sync
2125         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2126         sync
2127         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
2128         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2129         sync
2130         start_writeback
2131 }
2132 run_test 46 "dirtying a previously written page ================"
2133
2134 # test_47 is removed "Device nodes check" is moved to test_28
2135
2136 test_48a() { # bug 2399
2137         check_kernel_version 34 || return 0
2138         mkdir -p $DIR/d48a
2139         cd $DIR/d48a
2140         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
2141         mkdir $DIR/d48a || error "recreate directory failed"
2142         touch foo || error "'touch foo' failed after recreating cwd"
2143         mkdir bar || error "'mkdir foo' failed after recreating cwd"
2144         if check_kernel_version 44; then
2145                 touch .foo || error "'touch .foo' failed after recreating cwd"
2146                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
2147         fi
2148         ls . > /dev/null || error "'ls .' failed after recreating cwd"
2149         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2150         cd . || error "'cd .' failed after recreating cwd"
2151         mkdir . && error "'mkdir .' worked after recreating cwd"
2152         rmdir . && error "'rmdir .' worked after recreating cwd"
2153         ln -s . baz || error "'ln -s .' failed after recreating cwd"
2154         cd .. || error "'cd ..' failed after recreating cwd"
2155 }
2156 run_test 48a "Access renamed working dir (should return errors)="
2157
2158 test_48b() { # bug 2399
2159         check_kernel_version 34 || return 0
2160         mkdir -p $DIR/d48b
2161         cd $DIR/d48b
2162         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
2163         touch foo && error "'touch foo' worked after removing cwd"
2164         mkdir foo && error "'mkdir foo' worked after removing cwd"
2165         if check_kernel_version 44; then
2166                 touch .foo && error "'touch .foo' worked after removing cwd"
2167                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2168         fi
2169         ls . > /dev/null && error "'ls .' worked after removing cwd"
2170         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2171         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
2172         mkdir . && error "'mkdir .' worked after removing cwd"
2173         rmdir . && error "'rmdir .' worked after removing cwd"
2174         ln -s . foo && error "'ln -s .' worked after removing cwd"
2175         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
2176 }
2177 run_test 48b "Access removed working dir (should return errors)="
2178
2179 test_48c() { # bug 2350
2180         check_kernel_version 36 || return 0
2181         #lctl set_param debug=-1
2182         #set -vx
2183         mkdir -p $DIR/d48c/dir
2184         cd $DIR/d48c/dir
2185         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
2186         $TRACE touch foo && error "'touch foo' worked after removing cwd"
2187         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
2188         if check_kernel_version 44; then
2189                 touch .foo && error "'touch .foo' worked after removing cwd"
2190                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2191         fi
2192         $TRACE ls . && error "'ls .' worked after removing cwd"
2193         $TRACE ls .. || error "'ls ..' failed after removing cwd"
2194         is_patchless || ( $TRACE cd . && error "'cd .' worked after removing cwd" )
2195         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
2196         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
2197         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
2198         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2199 }
2200 run_test 48c "Access removed working subdir (should return errors)"
2201
2202 test_48d() { # bug 2350
2203         check_kernel_version 36 || return 0
2204         #lctl set_param debug=-1
2205         #set -vx
2206         mkdir -p $DIR/d48d/dir
2207         cd $DIR/d48d/dir
2208         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2209         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
2210         $TRACE touch foo && error "'touch foo' worked after removing parent"
2211         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
2212         if check_kernel_version 44; then
2213                 touch .foo && error "'touch .foo' worked after removing parent"
2214                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
2215         fi
2216         $TRACE ls . && error "'ls .' worked after removing parent"
2217         $TRACE ls .. && error "'ls ..' worked after removing parent"
2218         is_patchless || ( $TRACE cd . && error "'cd .' worked after recreate parent" )
2219         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
2220         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
2221         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
2222         is_patchless || ( $TRACE cd .. && error "'cd ..' worked after removing parent" || true )
2223 }
2224 run_test 48d "Access removed parent subdir (should return errors)"
2225
2226 test_48e() { # bug 4134
2227         check_kernel_version 41 || return 0
2228         #lctl set_param debug=-1
2229         #set -vx
2230         mkdir -p $DIR/d48e/dir
2231         cd $DIR/d48e/dir
2232         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
2233         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
2234         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
2235         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
2236         # On a buggy kernel addition of "touch foo" after cd .. will
2237         # produce kernel oops in lookup_hash_it
2238         touch ../foo && error "'cd ..' worked after recreate parent"
2239         cd $DIR
2240         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
2241 }
2242 run_test 48e "Access to recreated parent subdir (should return errors)"
2243
2244 test_50() {
2245         # bug 1485
2246         mkdir $DIR/d50
2247         cd $DIR/d50
2248         ls /proc/$$/cwd || error
2249 }
2250 run_test 50 "special situations: /proc symlinks  ==============="
2251
2252 test_51a() {    # was test_51
2253         # bug 1516 - create an empty entry right after ".." then split dir
2254         mkdir $DIR/d51
2255         touch $DIR/d51/foo
2256         $MCREATE $DIR/d51/bar
2257         rm $DIR/d51/foo
2258         createmany -m $DIR/d51/longfile 201
2259         FNUM=202
2260         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
2261                 $MCREATE $DIR/d51/longfile$FNUM
2262                 FNUM=$(($FNUM + 1))
2263                 echo -n "+"
2264         done
2265         echo
2266         ls -l $DIR/d51 > /dev/null || error
2267 }
2268 run_test 51a "special situations: split htree with empty entry =="
2269
2270 export NUMTEST=70000
2271 test_51b() {
2272         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2273         [ $NUMFREE -lt 21000 ] && \
2274                 skip "not enough free inodes ($NUMFREE)" && \
2275                 return
2276
2277         check_kernel_version 40 || NUMTEST=31000
2278         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
2279
2280         mkdir -p $DIR/d51b
2281         createmany -d $DIR/d51b/t- $NUMTEST
2282 }
2283 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
2284
2285 test_51c() {
2286         [ ! -d $DIR/d51b ] && skip "$DIR/51b missing" && \
2287                 return
2288
2289         unlinkmany -d $DIR/d51b/t- $NUMTEST
2290 }
2291 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
2292
2293 test_51d() {
2294         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
2295         mkdir -p $DIR/d51d
2296         createmany -o $DIR/d51d/t- 1000
2297         $LFS getstripe $DIR/d51d > $TMP/files
2298         for N in `seq 0 $((OSTCOUNT - 1))`; do
2299             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
2300             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
2301             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
2302         done
2303         unlinkmany $DIR/d51d/t- 1000
2304
2305         NLAST=0
2306         for N in `seq 1 $((OSTCOUNT - 1))`; do
2307             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
2308                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2309             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
2310                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2311
2312             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
2313                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2314             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
2315                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2316             NLAST=$N
2317         done
2318 }
2319 run_test 51d "check object distribution ===================="
2320
2321 test_52a() {
2322         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
2323         mkdir -p $DIR/d52a
2324         touch $DIR/d52a/foo
2325         chattr +a $DIR/d52a/foo || error "chattr +a failed"
2326         echo bar >> $DIR/d52a/foo || error "append bar failed"
2327         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
2328         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
2329         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
2330         echo foo >> $DIR/d52a/foo || error "append foo failed"
2331         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
2332         # new lsattr displays 'e' flag for extents
2333         lsattr $DIR/d52a/foo | egrep -q "^-+a[-e]+ $DIR/d52a/foo" || error "lsattr"
2334         chattr -a $DIR/d52a/foo || error "chattr -a failed"
2335
2336         rm -fr $DIR/d52a || error "cleanup rm failed"
2337 }
2338 run_test 52a "append-only flag test (should return errors) ====="
2339
2340 test_52b() {
2341         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
2342         mkdir -p $DIR/d52b
2343         touch $DIR/d52b/foo
2344         chattr +i $DIR/d52b/foo || error "chattr +a failed"
2345         cat test > $DIR/d52b/foo && error "cat test worked"
2346         cp /etc/hosts $DIR/d52b/foo && error "cp worked"
2347         rm -f $DIR/d52b/foo 2>/dev/null && error "rm worked"
2348         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error "link worked"
2349         echo foo >> $DIR/d52b/foo && error "echo worked"
2350         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error "rename worked"
2351         [ -f $DIR/d52b/foo ] || error
2352         [ -f $DIR/d52b/foo_ren ] && error
2353         lsattr $DIR/d52b/foo | egrep -q "^-+i[-e]+ $DIR/d52b/foo" || error "lsattr"
2354         chattr -i $DIR/d52b/foo || error "chattr failed"
2355
2356         rm -fr $DIR/d52b || error "remove failed"
2357 }
2358 run_test 52b "immutable flag test (should return errors) ======="
2359
2360 test_52c() { # 12848 simulating client < 1.4.7
2361         [ -f $DIR/d52c/foo ] && chattr -i $DIR/d52b/foo
2362         mkdir -p $DIR/d52c
2363         touch $DIR/d52c/foo
2364         # skip MDS_BFLAG_EXT_FLAGS in mdc_getattr_pack
2365 #define OBD_FAIL_MDC_OLD_EXT_FLAGS       0x802
2366         lctl set_param fail_loc=0x802
2367         chattr +i $DIR/d52c/foo || error
2368         lsattr $DIR/d52c/foo | egrep -q "^-+i[-e]+ $DIR/d52c/foo" || error "lsattr failed"
2369         chattr -i $DIR/d52c/foo || error "chattr failed"
2370         lctl set_param -n fail_loc=0
2371
2372         rm -fr $DIR/d52c || error
2373 }
2374 run_test 52c "immutable flag test for client < 1.4.7 ======="
2375
2376 test_53() {
2377         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2378         remote_ost_nodsh && skip "remote OST with nodsh" && return
2379
2380         local param
2381         local ostname
2382         local mds_last
2383         local ost_last
2384         local ostnum
2385
2386         for VALUE in $(do_facet mds lctl get_param osc.*-osc.prealloc_last_id); do
2387                 param=`echo ${VALUE[0]} | cut -d "=" -f1`;
2388                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
2389                 mds_last=$(do_facet mds lctl get_param -n $param)
2390                 ostnum=$(echo $ostname | sed "s/${FSNAME}-OST//g" | awk '{print ($1+1)}' )
2391                 ost_last=$(do_facet ost$ostnum lctl get_param -n obdfilter.$ostname.last_id)
2392                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2393                 if [ $ost_last != $mds_last ]; then
2394                         error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2395                 fi
2396         done
2397 }
2398 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
2399
2400 test_54a() {
2401         [ ! -f "$SOCKETSERVER" ] && skip_env "no socketserver, skipping" && return
2402         [ ! -f "$SOCKETCLIENT" ] && skip_env "no socketclient, skipping" && return
2403         $SOCKETSERVER $DIR/socket
2404         $SOCKETCLIENT $DIR/socket || error
2405         $MUNLINK $DIR/socket
2406 }
2407 run_test 54a "unix domain socket test =========================="
2408
2409 test_54b() {
2410         f="$DIR/f54b"
2411         mknod $f c 1 3
2412         chmod 0666 $f
2413         dd if=/dev/zero of=$f bs=`page_size` count=1
2414 }
2415 run_test 54b "char device works in lustre ======================"
2416
2417 find_loop_dev() {
2418         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
2419         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
2420         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
2421
2422         for i in `seq 3 7`; do
2423                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
2424                 LOOPDEV=$LOOPBASE$i
2425                 LOOPNUM=$i
2426                 break
2427         done
2428 }
2429
2430 test_54c() {
2431         tfile="$DIR/f54c"
2432         tdir="$DIR/d54c"
2433         loopdev="$DIR/loop54c"
2434
2435         find_loop_dev
2436         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
2437         mknod $loopdev b 7 $LOOPNUM
2438         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
2439         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
2440         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
2441         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
2442         mkdir -p $tdir
2443         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
2444         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
2445         df $tdir
2446         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
2447         $UMOUNT $tdir
2448         losetup -d $loopdev
2449         rm $loopdev
2450 }
2451 run_test 54c "block device works in lustre ====================="
2452
2453 test_54d() {
2454         f="$DIR/f54d"
2455         string="aaaaaa"
2456         mknod $f p
2457         [ "$string" = `echo $string > $f | cat $f` ] || error
2458 }
2459 run_test 54d "fifo device works in lustre ======================"
2460
2461 test_54e() {
2462         check_kernel_version 46 || return 0
2463         f="$DIR/f54e"
2464         string="aaaaaa"
2465         cp -aL /dev/console $f
2466         echo $string > $f || error
2467 }
2468 run_test 54e "console/tty device works in lustre ======================"
2469
2470 check_fstype() {
2471         grep -q $FSTYPE /proc/filesystems && return 1
2472         modprobe $FSTYPE
2473         grep -q $FSTYPE /proc/filesystems && return 1
2474         insmod ../$FSTYPE/$FSTYPE.o
2475         grep -q $FSTYPE /proc/filesystems && return 1
2476         insmod ../$FSTYPE/$FSTYPE.ko
2477         grep -q $FSTYPE /proc/filesystems && return 1
2478         return 0
2479 }
2480
2481 test_55() {
2482         rm -rf $DIR/d55
2483         mkdir $DIR/d55
2484         client_only && skip "Not a server" && return
2485         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
2486         touch $DIR/d55/foo
2487         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
2488         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
2489         echo "check for $EXT2_DEV. Please wait..."
2490         rm -rf $DIR/d55/*
2491         $UMOUNT $DIR/d55 || error "unmounting"
2492 }
2493 run_test 55 "check iopen_connect_dentry() ======================"
2494
2495 test_56a() {    # was test_56
2496         rm -rf $DIR/d56
2497         $SETSTRIPE -d $DIR
2498         mkdir $DIR/d56
2499         mkdir $DIR/d56/dir
2500         NUMFILES=3
2501         NUMFILESx2=$(($NUMFILES * 2))
2502         for i in `seq 1 $NUMFILES` ; do
2503                 touch $DIR/d56/file$i
2504                 touch $DIR/d56/dir/file$i
2505         done
2506
2507         # test lfs getstripe with --recursive
2508         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
2509         [ $FILENUM -eq $NUMFILESx2 ] || error \
2510                 "lfs getstripe --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
2511         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
2512         [ $FILENUM -eq $NUMFILES ] || error \
2513                 "lfs getstripe $DIR/d56 without --recursive wrong: found $FILENUM, expected $NUMFILES"
2514         echo "lfs getstripe --recursive passed."
2515
2516         # test lfs getstripe with file instead of dir
2517         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
2518         [ $FILENUM  -eq 1 ] || error \
2519                  "lfs getstripe $DIR/d56/file1 wrong:found $FILENUM, expected 1"
2520         echo "lfs getstripe file passed."
2521
2522         #test lfs getstripe with --verbose
2523         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||\
2524                 error "lfs getstripe --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2525         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] || error \
2526                 "lfs getstripe $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2527         echo "lfs getstripe --verbose passed."
2528
2529         #test lfs getstripe with --obd
2530         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2531                 error "lfs getstripe --obd wrong_uuid should return error message"
2532
2533         [  "$OSTCOUNT" -lt 2 ] && \
2534                 skip_env "skipping other lfs getstripe --obd test" && return
2535         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1[    ]/p' | wc -l`
2536         OBDUUID=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1:/p' | awk '{print $2}'`
2537         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | wc -l`
2538         [ $FOUND -eq $FILENUM ] || \
2539                 error "lfs getstripe --obd wrong: found $FOUND, expected $FILENUM"
2540         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 | sed '/^[   ]*1[    ]/d' |\
2541                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] || \
2542                 error "lfs getstripe --obd wrong: should not show file on other obd"
2543         echo "lfs getstripe --obd passed."
2544 }
2545 run_test 56a "check lfs getstripe ===================================="
2546
2547 NUMFILES=3
2548 NUMDIRS=3
2549 setup_56() {
2550         LOCAL_NUMFILES=$1
2551         LOCAL_NUMDIRS=$2
2552         if [ ! -d "$DIR/${tdir}g" ] ; then
2553                 mkdir -p $DIR/${tdir}g
2554                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2555                         touch $DIR/${tdir}g/file$i
2556                 done
2557                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2558                         mkdir $DIR/${tdir}g/dir$i
2559                         for j in `seq 1 $LOCAL_NUMFILES` ; do
2560                                 touch $DIR/${tdir}g/dir$i/file$j
2561                         done
2562                 done
2563         fi
2564 }
2565
2566 setup_56_special() {
2567         LOCAL_NUMFILES=$1
2568         LOCAL_NUMDIRS=$2
2569         TDIR=$DIR/${tdir}g
2570         setup_56 $1 $2
2571         if [ ! -e "$TDIR/loop1b" ] ; then
2572                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2573                         mknod $TDIR/loop${i}b b 7 $i
2574                         mknod $TDIR/null${i}c c 1 3
2575                         ln -s $TDIR/file1 $TDIR/link${i}l
2576                 done
2577                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2578                         mknod $TDIR/dir$i/loop${i}b b 7 $i
2579                         mknod $TDIR/dir$i/null${i}c c 1 3
2580                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
2581                 done
2582         fi
2583 }
2584
2585 test_56g() {
2586         $SETSTRIPE -d $DIR
2587
2588         setup_56 $NUMFILES $NUMDIRS
2589
2590         EXPECTED=$(($NUMDIRS + 2))
2591         # test lfs find with -name
2592         for i in `seq 1 $NUMFILES` ; do
2593                 NUMS=`$LFIND -name "*$i" $DIR/${tdir}g | wc -l`
2594                 [ $NUMS -eq $EXPECTED ] || error \
2595                         "lfs find -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2596         done
2597         echo "lfs find -name passed."
2598 }
2599 run_test 56g "check lfs find -name ============================="
2600
2601 test_56h() {
2602         $SETSTRIPE -d $DIR
2603
2604         setup_56 $NUMFILES $NUMDIRS
2605
2606         EXPECTED=$((($NUMDIRS+1)*($NUMFILES-1)+$NUMFILES))
2607         # test lfs find with ! -name
2608         for i in `seq 1 $NUMFILES` ; do
2609                 NUMS=`$LFIND ! -name "*$i" $DIR/${tdir}g | wc -l`
2610                 [ $NUMS -eq $EXPECTED ] || error \
2611                         "lfs find ! -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2612         done
2613         echo "lfs find ! -name passed."
2614 }
2615 run_test 56h "check lfs find ! -name ============================="
2616
2617 test_56i() {
2618        tdir=${tdir}i
2619        mkdir -p $DIR/$tdir
2620        UUID=`$GETSTRIPE $DIR/$tdir | awk '/0: / { print $2 }'`
2621        OUT="`$LFIND -ost $UUID $DIR/$tdir`"
2622        [ "$OUT" ] && error "$LFIND returned directory '$OUT'" || true
2623 }
2624 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
2625
2626 test_56j() {
2627         setup_56_special $NUMFILES $NUMDIRS
2628
2629         EXPECTED=$((NUMDIRS+1))
2630         NUMS=`$LFIND -type d $DIR/${tdir}g | wc -l`
2631         [ $NUMS -eq $EXPECTED ] || \
2632                 error "lfs find -type d $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2633 }
2634 run_test 56j "check lfs find -type d ============================="
2635
2636 test_56k() {
2637         setup_56_special $NUMFILES $NUMDIRS
2638
2639         EXPECTED=$(((NUMDIRS+1) * NUMFILES))
2640         NUMS=`$LFIND -type f $DIR/${tdir}g | wc -l`
2641         [ $NUMS -eq $EXPECTED ] || \
2642                 error "lfs find -type f $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2643 }
2644 run_test 56k "check lfs find -type f ============================="
2645
2646 test_56l() {
2647         setup_56_special $NUMFILES $NUMDIRS
2648
2649         EXPECTED=$((NUMDIRS + NUMFILES))
2650         NUMS=`$LFIND -type b $DIR/${tdir}g | wc -l`
2651         [ $NUMS -eq $EXPECTED ] || \
2652                 error "lfs find -type b $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2653 }
2654 run_test 56l "check lfs find -type b ============================="
2655
2656 test_56m() {
2657         setup_56_special $NUMFILES $NUMDIRS
2658
2659         EXPECTED=$((NUMDIRS + NUMFILES))
2660         NUMS=`$LFIND -type c $DIR/${tdir}g | wc -l`
2661         [ $NUMS -eq $EXPECTED ] || \
2662                 error "lfs find -type c $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2663 }
2664 run_test 56m "check lfs find -type c ============================="
2665
2666 test_56n() {
2667         setup_56_special $NUMFILES $NUMDIRS
2668
2669         EXPECTED=$((NUMDIRS + NUMFILES))
2670         NUMS=`$LFIND -type l $DIR/${tdir}g | wc -l`
2671         [ $NUMS -eq $EXPECTED ] || \
2672                 error "lfs find -type l $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2673 }
2674 run_test 56n "check lfs find -type l ============================="
2675
2676 test_56o() {
2677         setup_56 $NUMFILES $NUMDIRS
2678         TDIR=$DIR/${tdir}g
2679
2680         utime $TDIR/file1 > /dev/null || error
2681         utime $TDIR/file2 > /dev/null || error
2682         utime $TDIR/dir1 > /dev/null || error
2683         utime $TDIR/dir2 > /dev/null || error
2684         utime $TDIR/dir1/file1 > /dev/null || error
2685
2686         EXPECTED=5
2687         NUMS=`$LFIND -mtime +1 $TDIR | wc -l`
2688         [ $NUMS -eq $EXPECTED ] || \
2689                 error "lfs find -mtime $TDIR wrong: found $NUMS, expected $EXPECTED"
2690 }
2691 run_test 56o "check lfs find -mtime for old files =========================="
2692
2693 test_56p() {
2694         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2695
2696         TDIR=$DIR/${tdir}g
2697         rm -rf $TDIR
2698
2699         setup_56 $NUMFILES $NUMDIRS
2700
2701         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
2702         EXPECTED=$NUMFILES
2703         NUMS="`$LFIND -uid $RUNAS_ID $TDIR | wc -l`"
2704         [ $NUMS -eq $EXPECTED ] || \
2705                 error "lfs find -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
2706
2707         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
2708         NUMS="`$LFIND ! -uid $RUNAS_ID $TDIR | wc -l`"
2709         [ $NUMS -eq $EXPECTED ] || \
2710                 error "lfs find ! -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
2711
2712         echo "lfs find -uid and ! -uid passed."
2713 }
2714 run_test 56p "check lfs find -uid and ! -uid ==============================="
2715
2716 test_56q() {
2717         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2718
2719         TDIR=$DIR/${tdir}g
2720         rm -rf $TDIR
2721
2722         setup_56 $NUMFILES $NUMDIRS
2723
2724         chgrp $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
2725         EXPECTED=$NUMFILES
2726         NUMS="`$LFIND -gid $RUNAS_ID $TDIR | wc -l`"
2727         [ $NUMS -eq $EXPECTED ] || \
2728                 error "lfs find -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
2729
2730         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
2731         NUMS="`$LFIND ! -gid $RUNAS_ID $TDIR | wc -l`"
2732         [ $NUMS -eq $EXPECTED ] || \
2733                 error "lfs find ! -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
2734
2735         echo "lfs find -gid and ! -gid passed."
2736 }
2737 run_test 56q "check lfs find -gid and ! -gid ==============================="
2738
2739 test_57a() {
2740         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2741
2742         local MNTDEV=$(get_mds_mntdev_proc_path)
2743         DEV=$(do_facet mds lctl get_param -n $MNTDEV)
2744         [ -z "$DEV" ] && error "can't access $MNTDEV"
2745         for DEV in $(do_facet mds lctl get_param -n $MNTDEV); do
2746                 do_facet mds $DUMPE2FS -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
2747                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2748                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2749                 rm $TMP/t57a.dump
2750         done
2751 }
2752 run_test 57a "verify MDS filesystem created with large inodes =="
2753
2754 test_57b() {
2755         local dir=$DIR/d57b
2756
2757         local FILECOUNT=100
2758         local FILE1=$dir/f1
2759         local FILEN=$dir/f$FILECOUNT
2760
2761         rm -rf $dir || error "removing $dir"
2762         mkdir -p $dir || error "creating $dir"
2763
2764         echo "mcreating $FILECOUNT files"
2765         createmany -m $dir/f 1 $FILECOUNT || \
2766                 error "creating files in $dir"
2767
2768         # verify that files do not have EAs yet
2769         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2770         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2771
2772         local fsstat_dev=$(get_mds_fsstat_proc_path)
2773         local MDSFREE=$(do_facet mds lctl get_param -n $fsstat_dev.*.kbytesfree)
2774         local MDCFREE=$(lctl get_param -n mdc.*.kbytesfree | head -n 1)
2775         echo "opening files to create objects/EAs"
2776         local FILE
2777         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
2778                 $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
2779         done
2780
2781         # verify that files have EAs now
2782         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2783         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2784
2785         sleep 1 # make sure we get new statfs data
2786         local MDSFREE2=$(do_facet mds lctl get_param -n $fsstat_dev.*.kbytesfree)
2787         local MDCFREE2=$(lctl get_param -n mdc.*.kbytesfree | head -n 1)
2788         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
2789                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
2790                         error "MDC before $MDCFREE != after $MDCFREE2"
2791                 else
2792                         echo "MDC before $MDCFREE != after $MDCFREE2"
2793                         echo "unable to confirm if MDS has large inodes"
2794                 fi
2795         fi
2796         rm -rf $dir
2797 }
2798 run_test 57b "default LOV EAs are stored inside large inodes ==="
2799
2800 test_58() {
2801     [ -z "$(which wiretest 2>/dev/null)" ] && skip_env "could not find wiretest" && return
2802     wiretest
2803 }
2804 run_test 58 "verify cross-platform wire constants =============="
2805
2806 test_59() {
2807         echo "touch 130 files"
2808         createmany -o $DIR/f59- 130
2809         echo "rm 130 files"
2810         unlinkmany $DIR/f59- 130
2811         sync
2812         sleep 2
2813         # wait for commitment of removal
2814 }
2815 run_test 59 "verify cancellation of llog records async ========="
2816
2817 TEST60_HEAD="test_60 run $RANDOM"
2818 test_60a() {    # was test_60
2819         [ ! -f run-llog.sh ] && skip_env "missing subtest run-llog.sh" && return
2820         log "$TEST60_HEAD - from kernel mode"
2821         sh run-llog.sh
2822 }
2823 run_test 60a "llog sanity tests run from kernel module =========="
2824
2825 test_60b() { # bug 6411
2826         dmesg > $DIR/$tfile
2827         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
2828                                  /llog.test/ {
2829                                          if (marker)
2830                                                  from_marker++
2831                                          from_begin++
2832                                  }
2833                                  END {
2834                                          if (marker)
2835                                                  print from_marker
2836                                          else
2837                                                  print from_begin
2838                                  }"`
2839         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
2840 }
2841 run_test 60b "limit repeated messages from CERROR/CWARN ========"
2842
2843 test_60c() {
2844         echo "create 5000 files"
2845         createmany -o $DIR/f60c- 5000
2846         #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
2847         lctl set_param fail_loc=0x80000137
2848         unlinkmany $DIR/f60c- 5000
2849 }
2850 run_test 60c "unlink file when mds full"
2851
2852 test_60d() {
2853         SAVEPRINTK=$(lctl get_param -n printk)
2854
2855         # verify "lctl mark" is even working"
2856         MESSAGE="test message ID $RANDOM $$"
2857         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
2858         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
2859
2860         lctl set_param printk=0 || error "set lnet.printk failed"
2861         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
2862         MESSAGE="new test message ID $RANDOM $$"
2863         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
2864         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
2865         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
2866
2867         lctl set_param -n printk="$SAVEPRINTK"
2868 }
2869 run_test 60d "test printk console message masking"
2870
2871 test_61() {
2872         f="$DIR/f61"
2873         dd if=/dev/zero of=$f bs=`page_size` count=1
2874         cancel_lru_locks osc
2875         multiop $f OSMWUc || error
2876         sync
2877 }
2878 run_test 61 "mmap() writes don't make sync hang ================"
2879
2880 # bug 2330 - insufficient obd_match error checking causes LBUG
2881 test_62() {
2882         f="$DIR/f62"
2883         echo foo > $f
2884         cancel_lru_locks osc
2885         #define OBD_FAIL_OSC_MATCH 0x405
2886         lctl set_param fail_loc=0x405
2887         cat $f && error "cat succeeded, expect -EIO"
2888         lctl set_param fail_loc=0
2889 }
2890 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
2891 # match every page all of the time.
2892 run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2893
2894 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2895 test_63a() {    # was test_63
2896         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
2897         lctl set_param -n osc.*.max_dirty_mb 0
2898         for i in `seq 10` ; do
2899                 dd if=/dev/zero of=$DIR/f63 bs=8k &
2900                 sleep 5
2901                 kill $!
2902                 sleep 1
2903         done
2904
2905         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
2906         rm -f $DIR/f63 || true
2907 }
2908 run_test 63a "Verify oig_wait interruption does not crash ======="
2909
2910 # bug 2248 - async write errors didn't return to application on sync
2911 # bug 3677 - async write errors left page locked
2912 test_63b() {
2913         debugsave
2914         lctl set_param debug=-1
2915
2916         # ensure we have a grant to do async writes
2917         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
2918         rm $DIR/$tfile
2919
2920         #define OBD_FAIL_OSC_BRW_PREP_REQ 0x406
2921         lctl set_param fail_loc=0x80000406
2922         multiop $DIR/$tfile Owy && \
2923                 error "sync didn't return ENOMEM"
2924         sync; sleep 2; sync     # do a real sync this time to flush page
2925         lctl get_param -n llite.*.dump_page_cache | grep locked && \
2926                 error "locked page left in cache after async error" || true
2927         debugrestore
2928 }
2929 run_test 63b "async write errors should be returned to fsync ==="
2930
2931 test_64a () {
2932         df $DIR
2933         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
2934 }
2935 run_test 64a "verify filter grant calculations (in kernel) ====="
2936
2937 test_64b () {
2938         [ ! -f oos.sh ] && skip_env "missing subtest oos.sh" && return
2939         sh oos.sh $MOUNT
2940 }
2941 run_test 64b "check out-of-space detection on client ==========="
2942
2943 # bug 1414 - set/get directories' stripe info
2944 test_65a() {
2945         mkdir -p $DIR/d65
2946         touch $DIR/d65/f1
2947         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
2948 }
2949 run_test 65a "directory with no stripe info ===================="
2950
2951 test_65b() {
2952         mkdir -p $DIR/d65
2953         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
2954         touch $DIR/d65/f2
2955         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
2956 }
2957 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
2958
2959 test_65c() {
2960         if [ $OSTCOUNT -gt 1 ]; then
2961                 mkdir -p $DIR/d65
2962                 $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 4)) -i 1 \
2963                         -c $(($OSTCOUNT - 1)) || error "setstripe"
2964                 touch $DIR/d65/f3
2965                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
2966         fi
2967 }
2968 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
2969
2970 test_65d() {
2971         mkdir -p $DIR/d65
2972         [ $STRIPECOUNT -le 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1))
2973         $SETSTRIPE $DIR/d65 -s $STRIPESIZE -c $sc || error "setstripe"
2974         touch $DIR/d65/f4 $DIR/d65/f5
2975         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
2976 }
2977 run_test 65d "directory setstripe $STRIPESIZE -1 stripe_count =============="
2978
2979 test_65e() {
2980         mkdir -p $DIR/d65
2981
2982         $SETSTRIPE $DIR/d65 || error "setstripe"
2983         $GETSTRIPE -v $DIR/d65 | grep "Default" || error "no stripe info failed"
2984         touch $DIR/d65/f6
2985         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
2986 }
2987 run_test 65e "directory setstripe defaults ======================="
2988
2989 test_65f() {
2990         mkdir -p $DIR/d65f
2991         $RUNAS $SETSTRIPE $DIR/d65f && error "setstripe succeeded" || true
2992 }
2993 run_test 65f "dir setstripe permission (should return error) ==="
2994
2995 test_65g() {
2996         mkdir -p $DIR/d65
2997         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
2998         $SETSTRIPE -d $DIR/d65 || error "setstripe"
2999         $GETSTRIPE -v $DIR/d65 | grep "Default" || \
3000                 error "delete default stripe failed"
3001 }
3002 run_test 65g "directory setstripe -d ==========================="
3003
3004 test_65h() {
3005         mkdir -p $DIR/d65
3006         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
3007         mkdir -p $DIR/d65/dd1
3008         [ "`$GETSTRIPE -v $DIR/d65 | grep "^count"`" == \
3009           "`$GETSTRIPE -v $DIR/d65/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
3010 }
3011 run_test 65h "directory stripe info inherit ===================="
3012
3013 test_65i() { # bug6367
3014         $SETSTRIPE $MOUNT -s 65536 -c -1
3015 }
3016 run_test 65i "set non-default striping on root directory (bug 6367)="
3017
3018 test_65j() { # bug6367
3019         sync; sleep 1
3020         # if we aren't already remounting for each test, do so for this test
3021         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
3022                 cleanup || error "failed to unmount"
3023                 setup
3024         fi
3025         $SETSTRIPE -d $MOUNT || error "setstripe failed"
3026 }
3027 run_test 65j "set default striping on root directory (bug 6367)="
3028
3029 test_65k() { # bug11679
3030         [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
3031         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3032
3033         echo "Check OST status: "
3034         MDS_OSCS=`do_facet mds lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
3035         for OSC in $MDS_OSCS; do
3036                 echo $OSC "is activate"
3037                 do_facet mds lctl --device %$OSC activate
3038         done
3039         do_facet client mkdir -p $DIR/$tdir
3040         for INACTIVE_OSC in $MDS_OSCS; do
3041                 echo $INACTIVE_OSC "is Deactivate:"
3042                 do_facet mds lctl --device  %$INACTIVE_OSC deactivate
3043                 for STRIPE_OSC in $MDS_OSCS; do
3044                         STRIPE_OST=`osc_to_ost $STRIPE_OSC`
3045                         STRIPE_INDEX=`do_facet mds lctl get_param -n lov.*md*.target_obd |
3046                                       grep $STRIPE_OST | awk -F: '{print $1}'`
3047                         echo "$SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1"
3048                         do_facet client $SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1
3049                         RC=$?
3050                         [ $RC -ne 0 ] && error "setstripe should have succeeded"
3051                 done
3052                 do_facet client rm -f $DIR/$tdir/*
3053                 echo $INACTIVE_OSC "is Activate."
3054                 do_facet mds lctl --device  %$INACTIVE_OSC activate
3055         done
3056 }
3057 run_test 65k "validate manual striping works properly with deactivated OSCs"
3058
3059 test_65l() { # bug 12836
3060         mkdir -p $DIR/$tdir/test_dir
3061         $SETSTRIPE $DIR/$tdir/test_dir -c -1
3062         $LFS find -mtime -1 $DIR/$tdir > /dev/null
3063 }
3064 run_test 65l "lfs find on -1 stripe dir ========================"
3065
3066 # bug 2543 - update blocks count on client
3067 test_66() {
3068         COUNT=${COUNT:-8}
3069         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
3070         sync; sleep 1; sync
3071         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
3072         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
3073 }
3074 run_test 66 "update inode blocks count on client ==============="
3075
3076 test_67a() { # was test_67 bug 3285 - supplementary group fails on MDS, passes on client
3077         [ "$RUNAS_ID" = "$UID" ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
3078         check_kernel_version 35 || return 0
3079         mkdir -p $DIR/$tdir
3080         chmod 771 $DIR/$tdir
3081         chgrp $RUNAS_ID $DIR/$tdir
3082         $RUNAS -u $RUNAS_ID -g $(($RUNAS_ID + 1)) -G1,2,$RUNAS_ID ls $DIR/$tdir
3083         RC=$?
3084         GROUP_UPCALL=$(do_facet mds lctl get_param -n mds.*.group_upcall)
3085         [ -z "$GROUP_UPCALL" ] && \
3086                 skip "lctl get_param failed! Useless to continue the test!" && return
3087         [ "$GROUP_UPCALL" = "NONE" -a $RC -eq 0 ] && \
3088                 error "no-upcall passed" || true
3089         [ "$GROUP_UPCALL" != "NONE" -a $RC -ne 0 ] && \
3090                 error "upcall failed" || true
3091 }
3092 run_test 67a "supplementary group failure (should return error) ="
3093
3094 cleanup_67b() {
3095         set +vx
3096         trap 0
3097         do_facet mds lctl set_param -n mds.*.group_upcall NONE
3098 }
3099
3100 test_67b() { # bug 3285 - supplementary group fails on MDS, passes on client
3101         # needs to be in /etc/groups on MDS, gid == uid
3102         # Let's use RUNAS_ID
3103         T67_UID=${T67_UID:-$RUNAS_ID}
3104
3105         [ "$UID" = "$T67_UID" ] && skip "UID = T67_UID = $UID -- skipping" && return
3106         check_kernel_version 35 || return 0
3107         do_facet mds grep -q ":$T67_UID:$T67_UID" /etc/passwd || \
3108                 { skip "Need gid=$T67_UID group and gid == uid on mds !" && return; }
3109
3110         GROUP_UPCALL=$(do_facet mds lctl get_param -n mds.*.group_upcall)
3111         [ -z "$GROUP_UPCALL" ] && \
3112                 skip "lctl get_param failed! Useless to continue the test!" && return
3113         [ "$GROUP_UPCALL" != "NONE" ] && \
3114                 skip "skip test - upcall=$GROUP_UPCALL" && return
3115         set -vx
3116         trap cleanup_67b EXIT
3117         mkdir -p $DIR/$tdir
3118         chmod 771 $DIR/$tdir
3119         chgrp $T67_UID $DIR/$tdir
3120         local l_getgroups=$(do_facet mds which l_getgroups)
3121         do_facet mds lctl set_param -n mds.*.group_upcall $l_getgroups
3122         do_facet mds $l_getgroups -d $T67_UID
3123         $RUNAS -u $T67_UID -g 999 -G8,9,$T67_UID touch $DIR/$tdir/$tfile || \
3124                 error "'touch $DIR/$tdir/$tfile' failed"
3125         [ -f $DIR/$tdir/$tfile ] || error "$DIR/$tdir/$tfile create error"
3126         cleanup_67b
3127 }
3128 run_test 67b "supplementary group test ========================="
3129
3130 LLOOP=
3131 cleanup_68() {
3132         trap 0
3133         if [ ! -z "$LLOOP" ]; then
3134                 swapoff $LLOOP || error "swapoff failed"
3135                 $LCTL blockdev_detach $LLOOP || error "detach failed"
3136                 rm -f $LLOOP
3137                 unset LLOOP
3138         fi
3139         rm -f $DIR/f68
3140 }
3141
3142 meminfo() {
3143         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
3144 }
3145
3146 swap_used() {
3147         swapon -s | awk '($1 == "'$1'") { print $4 }'
3148 }
3149
3150
3151 # excercise swapping to lustre by adding a high priority swapfile entry
3152 # and then consuming memory until it is used.
3153 test_68() {
3154         [ "$UID" != 0 ] && skip_env "must run as root" && return
3155         lctl get_param -n devices | grep -q obdfilter && \
3156                 skip "local OST" && return
3157
3158         grep -q llite_lloop /proc/modules
3159         [ $? -ne 0 ] && skip_env "can't find module llite_lloop" && return
3160
3161         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
3162                 skip "can't reliably test swap with TCP" && return
3163
3164         MEMTOTAL=`meminfo MemTotal`
3165         NR_BLOCKS=$((MEMTOTAL>>8))
3166         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
3167
3168         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
3169         dd if=/dev/zero of=$DIR/f68 bs=64k seek=$NR_BLOCKS count=1
3170         mkswap $DIR/f68
3171
3172         $LCTL blockdev_attach $DIR/f68 $LLOOP || error "attach failed"
3173
3174         trap cleanup_68 EXIT
3175
3176         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
3177
3178         echo "before: `swapon -s | grep $LLOOP`"
3179         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
3180         echo "after: `swapon -s | grep $LLOOP`"
3181         SWAPUSED=`swap_used $LLOOP`
3182
3183         cleanup_68
3184
3185         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
3186 }
3187 run_test 68 "support swapping to Lustre ========================"
3188
3189 # bug5265, obdfilter oa2dentry return -ENOENT
3190 # #define OBD_FAIL_OST_ENOENT 0x217
3191 test_69() {
3192         remote_ost_nodsh && skip "remote OST with nodsh" && return
3193
3194         f="$DIR/$tfile"
3195         $SETSTRIPE $f -c 1 -i 0
3196
3197         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
3198
3199         #define OBD_FAIL_OST_ENOENT 0x217
3200         do_facet ost1 lctl set_param fail_loc=0x217
3201         truncate $f 1 # vmtruncate() will ignore truncate() error.
3202         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
3203
3204         do_facet ost1 lctl set_param fail_loc=0
3205         $DIRECTIO write $f 0 2 || error "write error"
3206
3207         cancel_lru_locks osc
3208         $DIRECTIO read $f 0 1 || error "read error"
3209
3210         #define OBD_FAIL_OST_ENOENT 0x217
3211         do_facet ost1 lctl set_param fail_loc=0x217
3212         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
3213
3214         do_facet ost1 lctl set_param fail_loc=0
3215         rm -f $f
3216 }
3217 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
3218
3219 test_71() {
3220     mkdir -p $DIR/$tdir
3221     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
3222 }
3223 run_test 71 "Running dbench on lustre (don't segment fault) ===="
3224
3225 test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
3226         check_kernel_version 43 || return 0
3227         [ "$RUNAS_ID" = "$UID" ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3228
3229         # Check that testing environment is properly set up. Skip if not
3230         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
3231                 skip_env "User $RUNAS_ID does not exist - skipping"
3232                 return 0
3233         }
3234         touch $DIR/f72
3235         chmod 777 $DIR/f72
3236         chmod ug+s $DIR/f72
3237         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
3238         # See if we are still setuid/sgid
3239         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
3240         # Now test that MDS is updated too
3241         cancel_lru_locks mdc
3242         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
3243         true
3244 }
3245 run_test 72 "Test that remove suid works properly (bug5695) ===="
3246
3247 # bug 3462 - multiple simultaneous MDC requests
3248 test_73() {
3249         mkdir $DIR/d73-1
3250         mkdir $DIR/d73-2
3251         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
3252         pid1=$!
3253
3254         #define OBD_FAIL_MDS_PAUSE_OPEN 0x129
3255         lctl set_param fail_loc=0x80000129
3256         multiop $DIR/d73-1/f73-2 Oc &
3257         sleep 1
3258         lctl set_param fail_loc=0
3259
3260         multiop $DIR/d73-2/f73-3 Oc &
3261         pid3=$!
3262
3263         kill -USR1 $pid1
3264         wait $pid1 || return 1
3265
3266         sleep 25
3267
3268         $CHECKSTAT -t file $DIR/d73-1/f73-1 || error "$DIR/d73-1/f73-1 not file"
3269         $CHECKSTAT -t file $DIR/d73-1/f73-2 || error "$DIR/d73-1/f73-2 not file"
3270         $CHECKSTAT -t file $DIR/d73-2/f73-3 || error "$DIR/d73-2/f73-3 not file"
3271
3272         rm -rf $DIR/d73-*
3273 }
3274 run_test 73 "multiple MDC requests (should not deadlock)"
3275
3276 test_74a() { # bug 6149, 6184
3277         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
3278         #
3279         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
3280         # will spin in a tight reconnection loop
3281         touch $DIR/f74a
3282         lctl set_param fail_loc=0x8000030e
3283         # get any lock that won't be difficult - lookup works.
3284         ls $DIR/f74a
3285         lctl set_param fail_loc=0
3286         true
3287 }
3288 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
3289
3290 test_74b() { # bug 13310
3291         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
3292         #
3293         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
3294         # will spin in a tight reconnection loop
3295         lctl set_param fail_loc=0x8000030e
3296         # get a "difficult" lock
3297         touch $DIR/f74b
3298         lctl set_param fail_loc=0
3299         true
3300 }
3301 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
3302
3303 JOIN=${JOIN:-"lfs join"}
3304 F75=$DIR/f75
3305 F128k=${F75}_128k
3306 FHEAD=${F75}_head
3307 FTAIL=${F75}_tail
3308 export T75_PREP=no
3309 test75_prep() {
3310         [ $T75_PREP = "yes" ] && return
3311         echo "using F75=$F75, F128k=$F128k, FHEAD=$FHEAD, FTAIL=$FTAIL"
3312
3313         dd if=/dev/urandom of=${F75}_128k bs=128k count=1 || error "dd failed"
3314         log "finished dd"
3315         chmod 777 ${F128k}
3316         T75_PREP=yes
3317 }
3318
3319 test_75a() {
3320         test75_prep
3321
3322         cp -p ${F128k} ${FHEAD}
3323         log "finished cp to $FHEAD"
3324         cp -p ${F128k} ${FTAIL}
3325         log "finished cp to $FTAIL"
3326         cat ${F128k} ${F128k} > ${F75}_sim_sim
3327
3328         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3329         log "finished join $FHEAD to ${F75}_sim_sim"
3330         cmp ${FHEAD} ${F75}_sim_sim || error "${FHEAD} ${F75}_sim_sim differ"
3331         log "finished cmp $FHEAD to ${F75}_sim_sim"
3332         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} still exist after join"
3333 }
3334 run_test 75a "TEST join file ===================================="
3335
3336 test_75b() {
3337         test75_prep
3338
3339         cp -p ${F128k} ${FTAIL}
3340         cat ${F75}_sim_sim >> ${F75}_join_sim
3341         cat ${F128k} >> ${F75}_join_sim
3342         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3343         cmp ${FHEAD} ${F75}_join_sim || \
3344                 error "${FHEAD} ${F75}_join_sim are different"
3345         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join"
3346 }
3347 run_test 75b "TEST join file 2 =================================="
3348
3349 test_75c() {
3350         test75_prep
3351
3352         cp -p ${F128k} ${FTAIL}
3353         cat ${F128k} >> ${F75}_sim_join
3354         cat ${F75}_join_sim >> ${F75}_sim_join
3355         $JOIN ${FTAIL} ${FHEAD} || error "join error"
3356         cmp ${FTAIL} ${F75}_sim_join || \
3357                 error "${FTAIL} ${F75}_sim_join are different"
3358         $CHECKSTAT -a ${FHEAD} || error "tail ${FHEAD} exist after join"
3359 }
3360 run_test 75c "TEST join file 3 =================================="
3361
3362 test_75d() {
3363         test75_prep
3364
3365         cp -p ${F128k} ${FHEAD}
3366         cp -p ${F128k} ${FHEAD}_tmp
3367         cat ${F75}_sim_sim >> ${F75}_join_join
3368         cat ${F75}_sim_join >> ${F75}_join_join
3369         $JOIN ${FHEAD} ${FHEAD}_tmp || error "join ${FHEAD} ${FHEAD}_tmp error"
3370         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3371         cmp ${FHEAD} ${F75}_join_join ||error "${FHEAD} ${F75}_join_join differ"        $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join"
3372         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)"
3373 }
3374 run_test 75d "TEST join file 4 =================================="
3375
3376 test_75e() {
3377         test75_prep
3378
3379         rm -rf ${FHEAD} || "delete join file error"
3380 }
3381 run_test 75e "TEST join file 5 (remove joined file) ============="
3382
3383 test_75f() {
3384         test75_prep
3385
3386         cp -p ${F128k} ${F75}_join_10_compare
3387         cp -p ${F128k} ${F75}_join_10
3388         for ((i = 0; i < 10; i++)); do
3389                 cat ${F128k} >> ${F75}_join_10_compare
3390                 cp -p ${F128k} ${FTAIL}
3391                 $JOIN ${F75}_join_10 ${FTAIL} || \
3392                         error "join ${F75}_join_10 ${FTAIL} error"
3393                 $CHECKSTAT -a ${FTAIL} || error "tail file exist after join"
3394         done
3395         cmp ${F75}_join_10 ${F75}_join_10_compare || \
3396                 error "files ${F75}_join_10 ${F75}_join_10_compare differ"
3397 }
3398 run_test 75f "TEST join file 6 (join 10 files) =================="
3399
3400 test_75g() {
3401         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
3402         $LFS getstripe ${F75}_join_10
3403
3404         $OPENUNLINK ${F75}_join_10 ${F75}_join_10 || error "files unlink open"
3405
3406         ls -l $F75*
3407 }
3408 run_test 75g "TEST join file 7 (open unlink) ===================="
3409
3410 num_inodes() {
3411         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
3412 }
3413
3414 test_76() { # bug 1443
3415         DETH=$(grep deathrow /proc/kallsyms /proc/ksyms 2> /dev/null | wc -l)
3416         [ $DETH -eq 0 ] && skip "No _iget." && return 0
3417         BEFORE_INODES=`num_inodes`
3418         echo "before inodes: $BEFORE_INODES"
3419         local COUNT=1000
3420         [ "$SLOW" = "no" ] && COUNT=100
3421         for i in `seq $COUNT`; do
3422                 touch $DIR/$tfile
3423                 rm -f $DIR/$tfile
3424         done
3425         AFTER_INODES=`num_inodes`
3426         echo "after inodes: $AFTER_INODES"
3427         [ $AFTER_INODES -gt $((BEFORE_INODES + 32)) ] && \
3428                 error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
3429         true
3430 }
3431 run_test 76 "destroy duplicate inodes in client inode cache ===="
3432
3433 export ORIG_CSUM=""
3434 set_checksums()
3435 {
3436         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums |
3437                                        head -n1`
3438
3439         lctl set_param -n osc.*.checksums=$1
3440         return 0
3441 }
3442
3443 export ORIG_CSUM_TYPE=""
3444 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
3445 set_checksum_type()
3446 {
3447         [ "$ORIG_CSUM_TYPE" ] || \
3448                 ORIG_CSUM_TYPE=`lctl get_param -n osc.*osc-[^mM]*.checksum_type | sed 's/.*\[\(.*\)\].*/\1/g' \
3449                                 | head -n1`
3450         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
3451         log "set checksum type to $1"
3452         return 0
3453 }
3454 F77_TMP=$TMP/f77-temp
3455 F77SZ=8
3456 setup_f77() {
3457         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
3458                 error "error writing to $F77_TMP"
3459 }
3460
3461 test_77a() { # bug 10889
3462         [ ! -f $F77_TMP ] && setup_f77
3463         set_checksums 1
3464         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
3465         set_checksums 0
3466 }
3467 run_test 77a "normal checksum read/write operation ============="
3468
3469 test_77b() { # bug 10889
3470         [ ! -f $F77_TMP ] && setup_f77
3471         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3472         lctl set_param fail_loc=0x80000409
3473         set_checksums 1
3474         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
3475                 error "dd error: $?"
3476         lctl set_param fail_loc=0
3477         set_checksums 0
3478 }
3479 run_test 77b "checksum error on client write ===================="
3480
3481 test_77c() { # bug 10889
3482         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
3483         set_checksums 1
3484         for algo in $CKSUM_TYPES; do
3485                 cancel_lru_locks osc
3486                 set_checksum_type $algo
3487                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3488                 lctl set_param fail_loc=0x80000408
3489                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
3490                 lctl set_param fail_loc=0
3491         done
3492         set_checksums 0
3493         set_checksum_type $ORIG_CSUM_TYPE
3494 }
3495 run_test 77c "checksum error on client read ==================="
3496
3497 test_77d() { # bug 10889
3498         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3499         lctl set_param fail_loc=0x80000409
3500         set_checksums 1
3501         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3502                 error "direct write: rc=$?"
3503         lctl set_param fail_loc=0
3504         set_checksums 0
3505 }
3506 run_test 77d "checksum error on OST direct write ==============="
3507
3508 test_77e() { # bug 10889
3509         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
3510         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3511         lctl set_param fail_loc=0x80000408
3512         set_checksums 1
3513         cancel_lru_locks osc
3514         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3515                 error "direct read: rc=$?"
3516         lctl set_param fail_loc=0
3517         set_checksums 0
3518 }
3519 run_test 77e "checksum error on OST direct read ================"
3520
3521 test_77f() { # bug 10889
3522         set_checksums 1
3523         for algo in $CKSUM_TYPES; do
3524                 cancel_lru_locks osc
3525                 set_checksum_type $algo
3526                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3527                 lctl set_param fail_loc=0x409
3528                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
3529                         error "direct write succeeded"
3530                 lctl set_param fail_loc=0
3531         done
3532         set_checksum_type $ORIG_CSUM_TYPE
3533         set_checksums 0
3534 }
3535 run_test 77f "repeat checksum error on write (expect error) ===="
3536
3537 test_77g() { # bug 10889
3538         remote_ost_nodsh && skip "remote OST with nodsh" && return
3539
3540         [ ! -f $F77_TMP ] && setup_f77
3541
3542         $SETSTRIPE $DIR/f77g -c 1 -i 0
3543         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
3544         do_facet ost1 lctl set_param fail_loc=0x8000021a
3545         set_checksums 1
3546         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
3547                 error "write error: rc=$?"
3548         do_facet ost1 lctl set_param fail_loc=0
3549         set_checksums 0
3550 }
3551 run_test 77g "checksum error on OST write ======================"
3552
3553 test_77h() { # bug 10889
3554         remote_ost_nodsh && skip "remote OST with nodsh" && return
3555
3556         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
3557         cancel_lru_locks osc
3558         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
3559         do_facet ost1 lctl set_param fail_loc=0x8000021b
3560         set_checksums 1
3561         cmp $F77_TMP $DIR/f77g || error "file compare failed"
3562         do_facet ost1 lctl set_param fail_loc=0
3563         set_checksums 0
3564 }
3565 run_test 77h "checksum error on OST read ======================="
3566
3567 test_77i() { # bug 13805
3568         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
3569         lctl set_param fail_loc=0x40b
3570         remount_client $MOUNT
3571         lctl set_param fail_loc=0
3572         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
3573                 param=`echo ${VALUE[0]} | cut -d "=" -f1`
3574                 algo=`lctl get_param -n $param | sed 's/.*\[\(.*\)\].*/\1/g'`
3575                 [ "$algo" = "crc32" ] || error "algo set to $algo instead of crc32"
3576         done
3577         remount_client $MOUNT
3578 }
3579 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
3580
3581 test_77j() { # bug 13805
3582         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
3583         lctl set_param fail_loc=0x40c
3584         remount_client $MOUNT
3585         lctl set_param fail_loc=0
3586         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
3587                 param=`echo ${VALUE[0]} | cut -d "=" -f1`
3588                 algo=`lctl get_param -n $param | sed 's/.*\[\(.*\)\].*/\1/g'`
3589                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
3590         done
3591         remount_client $MOUNT
3592 }
3593 run_test 77j "client only supporting ADLER32 ===================="
3594
3595 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
3596 rm -f $F77_TMP
3597 unset F77_TMP
3598
3599 test_78() { # bug 10901
3600         NSEQ=5
3601         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
3602         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
3603         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
3604         echo "MemTotal: $MEMTOTAL"
3605 # reserve 256MB of memory for the kernel and other running processes,
3606 # and then take 1/2 of the remaining memory for the read/write buffers.
3607         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
3608         echo "Mem to use for directio: $MEMTOTAL"
3609         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
3610         [ $F78SIZE -gt 512 ] && F78SIZE=512
3611         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
3612         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
3613         echo "Smallest OST: $SMALLESTOST"
3614         [ $SMALLESTOST -lt 10240 ] && \
3615                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
3616
3617         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 5)) ] && \
3618                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 5))
3619         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
3620         echo "File size: $F78SIZE"
3621         $SETSTRIPE $DIR/$tfile -c -1 || error "setstripe failed"
3622         for i in `seq 1 $NSEQ`
3623         do
3624                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
3625                 echo directIO rdwr round $i of $NSEQ
3626                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
3627         done
3628
3629         rm -f $DIR/$tfile
3630 }
3631 run_test 78 "handle large O_DIRECT writes correctly ============"
3632
3633 test_79() { # bug 12743
3634         wait_delete_completed
3635
3636         BKTOTAL=$(calc_osc_kbytes kbytestotal)
3637         BKFREE=$(calc_osc_kbytes kbytesfree)
3638         BKAVAIL=$(calc_osc_kbytes kbytesavail)
3639         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
3640         DFTOTAL=`echo $STRING | cut -d, -f1`
3641         DFUSED=`echo $STRING  | cut -d, -f2`
3642         DFAVAIL=`echo $STRING | cut -d, -f3`
3643         DFFREE=$(($DFTOTAL - $DFUSED))
3644
3645         ALLOWANCE=$((64 * $OSTCOUNT))
3646
3647         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
3648            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
3649                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
3650         fi
3651         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
3652            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
3653                 error "df free($DFFREE) mismatch OST free($BKFREE)"
3654         fi
3655         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
3656            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
3657                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
3658         fi
3659 }
3660 run_test 79 "df report consistency check ======================="
3661
3662 test_80() { # bug 10718
3663         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
3664         sync; sleep 1; sync
3665         local BEFORE=`date +%s`
3666         cancel_lru_locks osc
3667         local AFTER=`date +%s`
3668         local DIFF=$((AFTER-BEFORE))
3669         if [ $DIFF -gt 1 ] ; then
3670                 error "elapsed for 1M@1T = $DIFF"
3671         fi
3672         true
3673 }
3674 run_test 80 "Page eviction is equally fast at high offsets too  ===="
3675
3676 test_99a() {
3677         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3678         mkdir -p $DIR/d99cvsroot || error "mkdir $DIR/d99cvsroot failed"
3679         chown $RUNAS_ID $DIR/d99cvsroot || error "chown $DIR/d99cvsroot failed"
3680         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
3681         cd $TMP
3682
3683         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
3684         cd $oldPWD
3685 }
3686 run_test 99a "cvs init ========================================="
3687
3688 test_99b() {
3689         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3690         [ ! -d $DIR/d99cvsroot ] && test_99a
3691         $RUNAS [ ! -w /tmp ] && skip "/tmp has wrong w permission -- skipping" && return
3692         cd /etc/init.d || error "cd /etc/init.d failed"
3693         # some versions of cvs import exit(1) when asked to import links or
3694         # files they can't read.  ignore those files.
3695         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
3696                         ! -perm +4 -printf '-I %f\n')
3697         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
3698                 d99reposname vtag rtag > /dev/null || error "cvs import failed"
3699 }
3700 run_test 99b "cvs import ======================================="
3701
3702 test_99c() {
3703         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3704         [ ! -d $DIR/d99cvsroot ] && test_99b
3705         cd $DIR || error "cd $DIR failed"
3706         mkdir -p $DIR/d99reposname || error "mkdir $DIR/d99reposname failed"
3707         chown $RUNAS_ID $DIR/d99reposname || \
3708                 error "chown $DIR/d99reposname failed"
3709         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname > /dev/null || \
3710                 error "cvs co d99reposname failed"
3711 }
3712 run_test 99c "cvs checkout ====================================="
3713
3714 test_99d() {
3715         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3716         [ ! -d $DIR/d99cvsroot ] && test_99c
3717         cd $DIR/d99reposname
3718         $RUNAS touch foo99
3719         $RUNAS cvs add -m 'addmsg' foo99
3720 }
3721 run_test 99d "cvs add =========================================="
3722
3723 test_99e() {
3724         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3725         [ ! -d $DIR/d99cvsroot ] && test_99c
3726         cd $DIR/d99reposname
3727         $RUNAS cvs update
3728 }
3729 run_test 99e "cvs update ======================================="
3730
3731 test_99f() {
3732         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3733         [ ! -d $DIR/d99cvsroot ] && test_99d
3734         cd $DIR/d99reposname
3735         $RUNAS cvs commit -m 'nomsg' foo99
3736 }
3737 run_test 99f "cvs commit ======================================="
3738
3739 test_100() {
3740         [ "$NETTYPE" = tcp ] || \
3741                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
3742                         return ; }
3743
3744         remote_ost_nodsh && skip "remote OST with nodsh" && return
3745         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3746         remote_servers || \
3747                 { skip "useless for local single node setup" && return; }
3748
3749         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
3750                 [ "$PROT" != "tcp" ] && continue
3751                 RPORT=$(echo $REMOTE | cut -d: -f2)
3752                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
3753
3754                 rc=0
3755                 LPORT=`echo $LOCAL | cut -d: -f2`
3756                 if [ $LPORT -ge 1024 ]; then
3757                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
3758                         netstat -tna
3759                         error_exit "local: $LPORT > 1024, remote: $RPORT"
3760                 fi
3761         done
3762         [ "$rc" = 0 ] || error_exit "privileged port not found" )
3763 }
3764 run_test 100 "check local port using privileged port ==========="
3765
3766 function get_named_value()
3767 {
3768     local tag
3769
3770     tag=$1
3771     while read ;do
3772         line=$REPLY
3773         case $line in
3774         $tag*)
3775             echo $line | sed "s/^$tag//"
3776             break
3777             ;;
3778         esac
3779     done
3780 }
3781
3782 export CACHE_MAX=`lctl get_param -n llite/*/max_cached_mb | head -n 1`
3783 cleanup_101() {
3784         lctl set_param -n llite.*.max_cached_mb $CACHE_MAX
3785         trap 0
3786 }
3787
3788 test_101() {
3789         local s
3790         local discard
3791         local nreads=10000
3792         [ "$CPU" = "UML" ] && nreads=1000
3793         local cache_limit=32
3794
3795         lctl set_param -n osc.*.rpc_stats 0
3796         trap cleanup_101 EXIT
3797
3798         lctl set_param -n llite.*.read_ahead_stats 0
3799         lctl set_param -n llite.*.max_cached_mb $cache_limit
3800
3801         #
3802         # randomly read 10000 of 64K chunks from file 3x 32MB in size
3803         #
3804         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
3805         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
3806
3807         discard=0
3808         for s in `lctl get_param -n llite.*.read_ahead_stats | \
3809                 get_named_value 'read but discarded' | cut -d" " -f1`; do
3810                         discard=$(($discard + $s))
3811         done
3812         cleanup_101
3813
3814         if [ $(($discard * 10)) -gt $nreads ] ;then
3815                 lctl get_param osc.*.rpc_stats
3816                 lctl get_param llite.*.read_ahead_stats
3817                 error "too many ($discard) discarded pages"
3818         fi
3819         rm -f $DIR/$tfile || true
3820 }
3821 run_test 101 "check read-ahead for random reads ================"
3822
3823 export SETUP_TEST101b=no
3824 setup_101b() {
3825         [ "$SETUP_TEST101b" = "yes" ] && return
3826         mkdir -p $DIR/$tdir
3827         STRIPE_SIZE=1048576
3828         STRIPE_COUNT=$OSTCOUNT
3829         STRIPE_OFFSET=0
3830
3831         trap cleanup_101 EXIT
3832         # prepare the read-ahead file
3833         $SETSTRIPE $DIR/$tfile -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT
3834
3835         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
3836         SETUP_TEST101b=yes
3837 }
3838
3839 cleanup_101() {
3840         trap 0
3841         rm -rf $DIR/$tdir $DIR/$tfile
3842         SETUP_TEST101b=no
3843 }
3844
3845 calc_total() {
3846         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
3847 }
3848
3849 ra_check_101b() {
3850         local READ_SIZE=$1
3851         local STRIPE_SIZE=1048576
3852         local RA_INC=1048576
3853         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
3854         local FILE_LENGTH=$((64*100))
3855         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
3856                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
3857         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
3858                         get_named_value 'read but discarded' | \
3859                         cut -d" " -f1 | calc_total`
3860
3861         if [ $DISCARD -gt $discard_limit ]; then
3862                 lctl get_param llite.*.read_ahead_stats
3863                 error "Too many ($DISCARD) discarded pages (size ${READ_SIZE})"
3864         else
3865                 echo "Read-ahead success for size ${READ_SIZE}"
3866         fi
3867 }
3868
3869 test_101b() {
3870         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs for stride-read" && return
3871         local STRIPE_SIZE=1048576
3872         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
3873         local FILE_LENGTH=$((STRIPE_SIZE*100))
3874         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
3875         # prepare the read-ahead file
3876         setup_101b
3877         cancel_lru_locks osc
3878         for BIDX in 2 4 8 16 32 64 128 256; do
3879                 local BSIZE=$((BIDX*4096))
3880                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
3881                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
3882                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
3883                 $LCTL set_param -n llite.*.read_ahead_stats 0
3884                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
3885                         -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
3886                 cancel_lru_locks osc
3887                 ra_check_101b $BSIZE
3888         done
3889         true
3890 }
3891 run_test 101b "check stride-io mode read-ahead ================="
3892
3893 test_101c() {
3894         local STRIPE_SIZE=1048576
3895         local FILE_LENGTH=$((STRIPE_SIZE*100))
3896         local nreads=10000
3897
3898         setup_101b
3899
3900         cancel_lru_locks osc
3901         $LCTL set_param osc.*.rpc_stats 0
3902         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
3903         for OSC in `$LCTL  get_param -N osc.*`
3904         do
3905                 if [ "$OSC" == "osc.num_refs" ]; then
3906                         continue
3907                 fi
3908                 lines=`$LCTL get_param -n ${OSC}.rpc_stats | wc | awk '{print $1}'`
3909                 if [ $lines -le 20 ]; then
3910                         continue
3911                 fi
3912
3913                 rpc4k=$($LCTL get_param -n $OSC | awk '$1 == "1:" { print $2; exit; }')
3914                 rpc8k=$($LCTL get_param -n $OSC | awk '$1 == "2:" { print $2; exit; }')
3915                 rpc16k=$($LCTL get_param -n $OSC | awk '$1 == "4:" { print $2; exit; }')
3916                 rpc32k=$($LCTL get_param -n $OSC | awk '$1 == "8:" { print $2; exit; }')
3917
3918                 [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
3919                 [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
3920                 [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
3921                 [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
3922
3923                 echo "Small rpc check passed!"
3924                 rpc64k=$($LCTL get_param -n $OSC | awk '$1 == "16:" { print $2; exit; }')
3925                 rpc128k=$($LCTL get_param -n $OSC | awk '$1 == "32:" { print $2; exit; }')
3926                 rpc256k=$($LCTL get_param -n $OSC | awk '$1 == "64:" { print $2; exit; }')
3927                 rpc512k=$($LCTL get_param -n $OSC | awk '$1 == "128:" { print $2; exit; }')
3928                 rpc1024k=$($LCTL get_param -n $OSC | awk '$1 == "256:" { print $2; exit; }')
3929
3930                 [ $rpc64k == 0 ]   && error "No 64k readahead IO ${rpc64k}"
3931                 [ $rpc128k == 0 ]  && error "No 128k readahead IO ${rpc128k}"
3932                 [ $rpc256k == 0 ]  && error "No 256k readahead IO ${rpc256k}"
3933                 [ $rpc512k == 0 ]  && error "No 512k readahead IO ${rpc256k}"
3934                 [ $rpc1024k == 0 ] && error "No 1024k readahead IO ${rpc1024k}"
3935                 echo "Big rpc check passed!"
3936         done
3937         cleanup_101
3938         true
3939 }
3940 run_test 101c "check stripe_size aligned read-ahead ================="
3941
3942 set_read_ahead() {
3943    lctl get_param -n llite.*.max_read_ahead_mb | head -n 1
3944    lctl set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
3945 }
3946
3947 test_101d() {
3948     local file=$DIR/$tfile
3949     local size=${FILESIZE_101c:-500}
3950     local ra_MB=${READAHEAD_MB:-40}
3951
3952     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
3953     [ $space -gt $((size / 1024)) ] ||
3954         { skip "Need free space ${size}M, have $space" && return; }
3955
3956     echo Creating ${size}M test file $file
3957     dd if=/dev/zero of=$file bs=1M count=$size
3958     echo Cancel LRU locks on lustre client to flush the client cache
3959     cancel_lru_locks osc
3960
3961     echo Disable read-ahead
3962     local old_READAHEAD=$(set_read_ahead 0)
3963
3964     echo Reading the test file $file with read-ahead disabled
3965     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
3966
3967     echo Cancel LRU locks on lustre client to flush the client cache
3968     cancel_lru_locks osc
3969     echo Enable read-ahead with ${ra_MB}MB
3970     set_read_ahead $ra_MB
3971
3972     echo Reading the test file $file with read-ahead enabled
3973     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
3974
3975     echo read-ahead disabled time read $time_ra_OFF
3976     echo read-ahead enabled  time read $time_ra_ON
3977
3978     set_read_ahead $old_READAHEAD
3979     rm -f $file
3980
3981     [ $time_ra_ON -lt $time_ra_OFF ] ||
3982         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
3983                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
3984 }
3985 run_test 101d "file read with and without read-ahead enabled  ================="
3986
3987 export SETUP_TEST102=no
3988 setup_test102() {
3989         [ "$SETUP_TEST102" = "yes" ] && return
3990         mkdir -p $DIR/$tdir
3991         chown $RUNAS_ID $DIR/$tdir
3992         STRIPE_SIZE=65536
3993         STRIPE_OFFSET=1
3994         STRIPE_COUNT=$OSTCOUNT
3995         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
3996
3997         trap cleanup_test102 EXIT
3998         cd $DIR
3999         $1 $SETSTRIPE $tdir -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT
4000         cd $DIR/$tdir
4001         for num in 1 2 3 4
4002         do
4003                 for count in `seq 1 $STRIPE_COUNT`
4004                 do
4005                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4006                         do
4007                                 local stripe_size=`expr $STRIPE_SIZE \* $num`
4008                                 local file=file"$num-$offset-$count"
4009                                 $1 $SETSTRIPE $file -s $stripe_size -i $offset -c $count
4010                         done
4011                 done
4012         done
4013
4014         cd $DIR
4015         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
4016         SETUP_TEST102=yes
4017 }
4018
4019 cleanup_test102() {
4020         trap 0
4021         [ "$SETUP_TEST102" = "yes" ] || return 0
4022         rm -f $TMP/f102.tar
4023         SETUP_TEST102=no
4024 }
4025
4026 test_102a() {
4027         local testfile=$DIR/xattr_testfile
4028
4029         rm -f $testfile
4030         touch $testfile
4031
4032         [ "$UID" != 0 ] && skip_env "must run as root" && return
4033         [ -z "`lctl get_param -n mdc.*.connect_flags | grep xattr`" ] &&
4034                 skip_env "must have user_xattr" && return
4035         [ -z "$(which setfattr 2>/dev/null)" ] && skip_env "could not find setfattr" && return
4036
4037         echo "set/get xattr..."
4038         setfattr -n trusted.name1 -v value1 $testfile || error
4039         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
4040         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
4041
4042         setfattr -n user.author1 -v author1 $testfile || error
4043         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
4044         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
4045
4046         echo "listxattr..."
4047         setfattr -n trusted.name2 -v value2 $testfile || error
4048         setfattr -n trusted.name3 -v value3 $testfile || error
4049         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4050         grep "trusted.name" | wc -l` -eq 3 ] || error
4051
4052
4053         setfattr -n user.author2 -v author2 $testfile || error
4054         setfattr -n user.author3 -v author3 $testfile || error
4055         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
4056         grep "user" | wc -l` -eq 3 ] || error
4057
4058         echo "remove xattr..."
4059         setfattr -x trusted.name1 $testfile || error
4060         getfattr -d -m trusted $testfile 2> /dev/null | \
4061         grep "trusted.name1" && error || true
4062
4063         setfattr -x user.author1 $testfile || error
4064         getfattr -d -m user $testfile 2> /dev/null | \
4065         grep "user.author1" && error || true
4066
4067         # b10667: setting lustre special xattr be silently discarded
4068         echo "set lustre special xattr ..."
4069         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
4070
4071         rm -f $testfile
4072 }
4073 run_test 102a "user xattr test =================================="
4074
4075 test_102b() {
4076         # b10930: get/set/list trusted.lov xattr
4077         echo "get/set/list trusted.lov xattr ..."
4078         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
4079         local testfile=$DIR/$tfile
4080         $SETSTRIPE -s 65536 -i 1 -c 2 $testfile || error "setstripe failed"
4081         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4082         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
4083
4084         local testfile2=${testfile}2
4085         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
4086                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
4087
4088         $MCREATE $testfile2
4089         setfattr -n trusted.lov -v $value $testfile2
4090         local tmp_file=${testfile}3
4091         $GETSTRIPE -v $testfile2 > $tmp_file
4092         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4093         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4094         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
4095         [ $stripe_count -eq 2 ] || error "stripe count $stripe_count != 2"
4096 }
4097 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
4098
4099 test_102c() {
4100         # b10930: get/set/list lustre.lov xattr
4101         echo "get/set/list lustre.lov xattr ..."
4102         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
4103         mkdir -p $DIR/$tdir
4104         chown $RUNAS_ID $DIR/$tdir
4105         local testfile=$DIR/$tdir/$tfile
4106         $RUNAS $SETSTRIPE -s 65536 -i 1 -c 2 $testfile||error "setstripe failed"
4107         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
4108         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
4109
4110         local testfile2=${testfile}2
4111         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
4112                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
4113
4114         $RUNAS $MCREATE $testfile2
4115         $RUNAS setfattr -n lustre.lov -v $value $testfile2
4116         local tmp_file=${testfile}3
4117         $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
4118         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4119         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4120         [ "$stripe_size" -eq 65536 ] || error "stripe size $stripe_size != 65536"
4121         [ "$stripe_count" -eq 2 ] || error "stripe count $stripe_count != 2"
4122 }
4123 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
4124
4125 compare_stripe_info1() {
4126         local stripe_index_all_zero=1
4127
4128         for num in 1 2 3 4
4129         do
4130                 for count in `seq 1 $STRIPE_COUNT`
4131                 do
4132                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4133                         do
4134                                 local size=`expr $STRIPE_SIZE \* $num`
4135                                 local file=file"$num-$offset-$count"
4136                                 get_stripe_info client $PWD/$file "$1"
4137                                 if [ $stripe_size -ne $size ]; then
4138                                         error "$file: different stripe size $stripe_size, expected $size" && return
4139                                 fi
4140                                 if [ $stripe_count -ne $count ]; then
4141                                         error "$file: different stripe count $stripe_count, expected $count" && return
4142                                 fi
4143                                 if [ $stripe_index -ne 0 ]; then
4144                                        stripe_index_all_zero=0
4145                                 fi
4146                         done
4147                 done
4148         done
4149         [ $stripe_index_all_zero -eq 1 ] && error "all files are being extracted starting from OST index 0"
4150         return 0
4151 }
4152
4153 find_lustre_tar() {
4154         [ -n "$(which tar 2>/dev/null)" ] && strings $(which tar) | grep -q lustre && echo tar
4155 }
4156
4157 test_102d() {
4158         # b10930: tar test for trusted.lov xattr
4159         TAR=$(find_lustre_tar)
4160         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4161         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4162         setup_test102
4163         mkdir -p $DIR/d102d
4164         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
4165         cd $DIR/d102d/$tdir
4166         compare_stripe_info1
4167 }
4168 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
4169
4170 test_102f() {
4171         # b10930: tar test for trusted.lov xattr
4172         TAR=$(find_lustre_tar)
4173         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4174         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4175         setup_test102
4176         mkdir -p $DIR/d102f
4177         cd $DIR
4178         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
4179         cd $DIR/d102f/$tdir
4180         compare_stripe_info1
4181 }
4182 run_test 102f "tar copy files, not keep osts ==========="
4183
4184 test_102h() { # bug 15777
4185         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
4186                 skip "must have user_xattr" && return
4187         [ -z "$(which setfattr 2>/dev/null)" ] &&
4188                 skip_env "could not find setfattr" && return
4189
4190         XBIG=trusted.big
4191         XSIZE=1024
4192         touch $DIR/$tfile
4193         VALUE=datadatadatadatadatadatadatadata
4194         while [ $(echo $VALUE | wc -c) -lt $XSIZE ]; do
4195                 VALUE="$VALUE$VALUE"
4196         done
4197         log "save $XBIG on $DIR/$tfile"
4198         setfattr -n $XBIG -v "$VALUE" $DIR/$tfile ||
4199                 error "saving $XBIG on $DIR/$tfile failed"
4200         ORIG=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4201         OSIZE=$(echo $ORIG | wc -c)
4202         [ $OSIZE -lt $XSIZE ] && error "set $XBIG too small ($OSIZE < $XSIZE)"
4203
4204         XSML=trusted.sml
4205         log "save $XSML on $DIR/$tfile"
4206         setfattr -n $XSML -v val $DIR/$tfile ||
4207                 error "saving $XSML on $DIR/$tfile failed"
4208         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4209         if [ "$NEW" != "$ORIG" ]; then
4210                 log "orig: $ORIG"
4211                 log "new: $NEW"
4212                 error "$XBIG different after saving $XSML"
4213         fi
4214
4215         log "grow $XSML on $DIR/$tfile"
4216         setfattr -n $XSML -v "$VALUE" $DIR/$tfile ||
4217                 error "growing $XSML on $DIR/$tfile failed"
4218         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4219         if [ "$NEW" != "$ORIG" ]; then
4220                 log "orig: $ORIG"
4221                 log "new: $NEW"
4222                 error "$XBIG different after growing $XSML"
4223         fi
4224         log "$XBIG still valid after growing $XSML"
4225 }
4226 run_test 102h "grow xattr from inside inode to external block"
4227
4228 test_102i() { # bug 17038
4229         touch $DIR/$tfile
4230         ln -s $DIR/$tfile $DIR/${tfile}link
4231         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
4232         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 | grep -i "no such attr" || error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
4233         rm -f $DIR/$tfile $DIR/${tfile}link
4234 }
4235 run_test 102i "lgetxattr test on symbolic link ============"
4236
4237 test_102j() {
4238         TAR=$(find_lustre_tar)
4239         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4240         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4241         setup_test102 "$RUNAS"
4242         mkdir -p $DIR/d102j
4243         chown $RUNAS_ID $DIR/d102j
4244         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
4245         cd $DIR/d102j/$tdir
4246         compare_stripe_info1 "$RUNAS"
4247 }
4248 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
4249
4250 cleanup_test102
4251
4252 run_acl_subtest()
4253 {
4254     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
4255     return $?
4256 }
4257
4258 test_103 () {
4259     [ "$UID" != 0 ] && skip_env "must run as root" && return
4260     [ -z "$(lctl get_param mdc.*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
4261     [ -z "$(which setfacl 2>/dev/null)" ] && skip_env "could not find setfacl" && return
4262
4263     SAVE_UMASK=`umask`
4264     umask 0022
4265     cd $DIR
4266
4267     echo "performing cp ..."
4268     run_acl_subtest cp || error
4269     echo "performing getfacl-noacl..."
4270     run_acl_subtest getfacl-noacl > /dev/null || error "getfacl-noacl test failed"
4271     echo "performing misc..."
4272     run_acl_subtest misc > /dev/null || error "misc test failed"
4273 #    XXX add back permission test when we support supplementary groups.
4274 #    echo "performing permissions..."
4275 #    run_acl_subtest permissions || error
4276     echo "performing setfacl..."
4277     run_acl_subtest setfacl > /dev/null || error "setfacl test failed"
4278
4279     # inheritance test got from HP
4280     echo "performing inheritance..."
4281     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
4282     chmod +x make-tree || error "chmod +x failed"
4283     run_acl_subtest inheritance > /dev/null || error "inheritance test failed"
4284     rm -f make-tree
4285
4286     cd $SAVE_PWD
4287     umask $SAVE_UMASK
4288 }
4289 run_test 103 "acl test ========================================="
4290
4291 test_104() {
4292         touch $DIR/$tfile
4293         lfs df || error "lfs df failed"
4294         lfs df -ih || error "lfs df -ih failed"
4295         lfs df -h $DIR || error "lfs df -h $DIR failed"
4296         lfs df -i $DIR || error "lfs df -i $DIR failed"
4297         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
4298         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
4299
4300         OSC=`lctl get_param -n devices | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
4301         lctl --device %$OSC deactivate
4302         lfs df || error "lfs df with deactivated OSC failed"
4303         lctl --device %$OSC recover
4304         lfs df || error "lfs df with reactivated OSC failed"
4305 }
4306 run_test 104 "lfs df [-ih] [path] test ========================="
4307
4308 test_105a() {
4309         # doesn't work on 2.4 kernels
4310         touch $DIR/$tfile
4311         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4312         then
4313                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
4314         else
4315                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
4316         fi
4317 }
4318 run_test 105a "flock when mounted without -o flock test ========"
4319
4320 test_105b() {
4321         touch $DIR/$tfile
4322         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4323         then
4324                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
4325         else
4326                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
4327         fi
4328 }
4329 run_test 105b "fcntl when mounted without -o flock test ========"
4330
4331 test_105c() {
4332         touch $DIR/$tfile
4333         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4334         then
4335                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
4336         else
4337                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
4338         fi
4339 }
4340 run_test 105c "lockf when mounted without -o flock test ========"
4341
4342 test_105d() { # bug 15924
4343         mkdir -p $DIR/$tdir
4344         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
4345                 skip "mount w/o flock enabled" && return
4346         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
4347         $LCTL set_param fail_loc=0x80000315
4348         flocks_test 2 $DIR/$tdir
4349 }
4350 run_test 105d "flock race (should not freeze) ========"
4351
4352 test_106() { #bug 10921
4353         mkdir -p $DIR/$tdir
4354         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
4355         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
4356 }
4357 run_test 106 "attempt exec of dir followed by chown of that dir"
4358
4359 test_107() {
4360         CDIR=`pwd`
4361         cd $DIR
4362
4363         local file=core
4364         rm -f $file
4365
4366         local save_pattern=$(sysctl -n kernel.core_pattern)
4367         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
4368         sysctl -w kernel.core_pattern=$file
4369         sysctl -w kernel.core_uses_pid=0
4370
4371         ulimit -c unlimited
4372         sleep 60 &
4373         SLEEPPID=$!
4374
4375         sleep 1
4376
4377         kill -s 11 $SLEEPPID
4378         wait $SLEEPPID
4379         if [ -e $file ]; then
4380                 size=`stat -c%s $file`
4381                 [ $size -eq 0 ] && error "Zero length core file $file"
4382         else
4383                 error "Fail to create core file $file"
4384         fi
4385         rm -f $file
4386         sysctl -w kernel.core_pattern=$save_pattern
4387         sysctl -w kernel.core_uses_pid=$save_uses_pid
4388         cd $CDIR
4389 }
4390 run_test 107 "Coredump on SIG"
4391
4392 test_115() {
4393         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4394             cut -c11-20)
4395         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
4396             return
4397         echo "Starting with $OSTIO_pre threads"
4398
4399         NUMTEST=20000
4400         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
4401         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
4402         echo "$NUMTEST creates/unlinks"
4403         mkdir -p $DIR/$tdir
4404         createmany -o $DIR/$tdir/$tfile $NUMTEST
4405         unlinkmany $DIR/$tdir/$tfile $NUMTEST
4406
4407         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4408             cut -c11-20)
4409
4410         # don't return an error
4411         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
4412             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&\
4413             echo "This may be fine, depending on what ran before this test" &&\
4414             echo "and how fast this system is." && return
4415
4416         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
4417 }
4418 run_test 115 "verify dynamic thread creation===================="
4419
4420 free_min_max () {
4421         wait_delete_completed
4422         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail))
4423         echo OST kbytes available: ${AVAIL[@]}
4424         MAXI=0; MAXV=${AVAIL[0]}
4425         MINI=0; MINV=${AVAIL[0]}
4426         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
4427             #echo OST $i: ${AVAIL[i]}kb
4428             if [ ${AVAIL[i]} -gt $MAXV ]; then
4429                 MAXV=${AVAIL[i]}; MAXI=$i
4430             fi
4431             if [ ${AVAIL[i]} -lt $MINV ]; then
4432                 MINV=${AVAIL[i]}; MINI=$i
4433             fi
4434         done
4435         echo Min free space: OST $MINI: $MINV
4436         echo Max free space: OST $MAXI: $MAXV
4437 }
4438
4439 test_116() {
4440         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
4441
4442         echo -n "Free space priority "
4443         lctl get_param -n lov.*.qos_prio_free
4444         declare -a AVAIL
4445         free_min_max
4446         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI" &&\
4447                 return
4448
4449         # generate uneven OSTs
4450         mkdir -p $DIR/$tdir/OST${MINI}
4451         declare -i FILL
4452         FILL=$(($MINV / 4))
4453         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
4454         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
4455         i=1
4456         while [ $FILL -gt 0 ]; do
4457             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
4458             FILL=$(($FILL - 2048))
4459             echo -n .
4460             i=$(($i + 1))
4461         done
4462         FILL=$(($MINV / 4))
4463         sync
4464         sleep_maxage
4465
4466         free_min_max
4467         DIFF=$(($MAXV - $MINV))
4468         DIFF2=$(($DIFF * 100 / $MINV))
4469         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
4470         if [ $DIFF2 -gt 20 ]; then
4471             echo "ok"
4472         else
4473             echo "failed - QOS mode won't be used"
4474             error_ignore "QOS imbalance criteria not met"
4475             return
4476         fi
4477
4478         MINI1=$MINI; MINV1=$MINV
4479         MAXI1=$MAXI; MAXV1=$MAXV
4480
4481         # now fill using QOS
4482         echo writing a bunch of files to QOS-assigned OSTs
4483         $SETSTRIPE $DIR/$tdir -c 1
4484         i=1
4485         while [ $FILL -gt 0 ]; do
4486             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
4487             FILL=$(($FILL - 200))
4488             echo -n .
4489             i=$(($i + 1))
4490         done
4491         echo "wrote $i 200k files"
4492         sync
4493         sleep_maxage
4494
4495         echo "Note: free space may not be updated, so measurements might be off"
4496         free_min_max
4497         DIFF2=$(($MAXV - $MINV))
4498         echo "free space delta: orig $DIFF final $DIFF2"
4499         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
4500         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
4501         echo "Wrote $DIFF to smaller OST $MINI1"
4502         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
4503         echo "Wrote $DIFF2 to larger OST $MAXI1"
4504         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
4505
4506         # Figure out which files were written where
4507         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd | awk '/'$MINI1': / {print $2; exit}')
4508         echo $UUID
4509         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4510         echo "$MINC files created on smaller OST $MINI1"
4511         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd | (awk '/'$MAXI1': / {print $2; exit}'))
4512         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4513         echo "$MAXC files created on larger OST $MAXI1"
4514         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
4515         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
4516
4517         rm -rf $DIR/$tdir/OST${MINI}
4518 }
4519 run_test 116 "stripe QOS: free space balance ==================="
4520
4521 test_117() # bug 10891
4522 {
4523         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
4524         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
4525         lctl set_param fail_loc=0x21e
4526         > $DIR/$tfile || error "truncate failed"
4527         lctl set_param fail_loc=0
4528         echo "Truncate succeeded."
4529 }
4530 run_test 117 "verify fsfilt_extend ============================="
4531
4532 export OLD_RESENDCOUNT=""
4533 set_resend_count () {
4534         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
4535         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
4536         lctl set_param -n $PROC_RESENDCOUNT $1
4537         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
4538 }
4539
4540 [ "$SLOW" = "no" ] && set_resend_count 4 # for reduce test_118* time (bug 14842)
4541
4542 # Reset async IO behavior after error case
4543 reset_async() {
4544         FILE=$DIR/reset_async
4545
4546         # Ensure all OSCs are cleared
4547         $SETSTRIPE -c -1 $FILE
4548         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
4549         sync
4550         rm $FILE
4551 }
4552
4553 test_118a() #bug 11710
4554 {
4555         reset_async
4556
4557         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4558         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
4559         WRITEBACK=$(lctl get_param "llite.*.dump_page_cache" | grep -c writeback)
4560
4561         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4562                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4563                 return 1;
4564         fi
4565 }
4566 run_test 118a "verify O_SYNC works =========="
4567
4568 test_118b()
4569 {
4570         remote_ost_nodsh && skip "remote OST with nodsh" && return
4571
4572         reset_async
4573
4574         #define OBD_FAIL_OST_ENOENT 0x217
4575         set_nodes_failloc "$(osts_nodes)" 0x217
4576         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4577         RC=$?
4578         set_nodes_failloc "$(osts_nodes)" 0
4579         DIRTY=$(lctl get_param llite.*.dump_page_cache | grep -c dirty)
4580         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4581
4582         if [[ $RC -eq 0 ]]; then
4583                 error "Must return error due to dropped pages, rc=$RC"
4584                 return 1;
4585         fi
4586
4587         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4588                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4589                 return 1;
4590         fi
4591
4592         echo "Dirty pages not leaked on ENOENT"
4593
4594         # Due to the above error the OSC will issue all RPCs syncronously
4595         # until a subsequent RPC completes successfully without error.
4596         multiop $DIR/$tfile Ow4096yc
4597         rm -f $DIR/$tfile
4598
4599         return 0
4600 }
4601 run_test 118b "Reclaim dirty pages on fatal error =========="
4602
4603 test_118c()
4604 {
4605         remote_ost_nodsh && skip "remote OST with nodsh" && return
4606
4607         reset_async
4608
4609         #define OBD_FAIL_OST_EROFS               0x216
4610         set_nodes_failloc "$(osts_nodes)" 0x216
4611
4612         # multiop should block due to fsync until pages are written
4613         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4614         MULTIPID=$!
4615         sleep 1
4616
4617         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4618                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4619         fi
4620
4621         WRITEBACK=$(lctl get_param -n llite/*/dump_page_cache | grep -c writeback)
4622         if [[ $WRITEBACK -eq 0 ]]; then
4623                 error "No page in writeback, writeback=$WRITEBACK"
4624         fi
4625
4626         set_nodes_failloc "$(osts_nodes)" 0
4627         wait $MULTIPID
4628         RC=$?
4629         if [[ $RC -ne 0 ]]; then
4630                 error "Multiop fsync failed, rc=$RC"
4631         fi
4632
4633         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4634         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4635         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4636                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4637         fi
4638
4639         rm -f $DIR/$tfile
4640         echo "Dirty pages flushed via fsync on EROFS"
4641         return 0
4642 }
4643 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
4644
4645 test_118d()
4646 {
4647         remote_ost_nodsh && skip "remote OST with nodsh" && return
4648
4649         reset_async
4650
4651         #define OBD_FAIL_OST_BRW_PAUSE_BULK
4652         set_nodes_failloc "$(osts_nodes)" 0x214
4653         # multiop should block due to fsync until pages are written
4654         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4655         MULTIPID=$!
4656         sleep 1
4657
4658         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4659                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4660         fi
4661
4662         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4663         if [[ $WRITEBACK -eq 0 ]]; then
4664                 error "No page in writeback, writeback=$WRITEBACK"
4665         fi
4666
4667         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
4668         set_nodes_failloc "$(osts_nodes)" 0
4669
4670         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4671         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4672         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4673                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4674         fi
4675
4676         rm -f $DIR/$tfile
4677         echo "Dirty pages gaurenteed flushed via fsync"
4678         return 0
4679 }
4680 run_test 118d "Fsync validation inject a delay of the bulk =========="
4681
4682 test_118f() {
4683         reset_async
4684
4685         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
4686         lctl set_param fail_loc=0x8000040a
4687
4688         # Should simulate EINVAL error which is fatal
4689         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4690         RC=$?
4691         if [[ $RC -eq 0 ]]; then
4692                 error "Must return error due to dropped pages, rc=$RC"
4693         fi
4694
4695         lctl set_param fail_loc=0x0
4696
4697         LOCKED=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c locked)
4698         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
4699         WRITEBACK=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c writeback)
4700         if [[ $LOCKED -ne 0 ]]; then
4701                 error "Locked pages remain in cache, locked=$LOCKED"
4702         fi
4703
4704         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4705                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4706         fi
4707
4708         rm -f $DIR/$tfile
4709         echo "No pages locked after fsync"
4710
4711         reset_async
4712         return 0
4713 }
4714 run_test 118f "Simulate unrecoverable OSC side error =========="
4715
4716 test_118g() {
4717         reset_async
4718
4719         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4720         lctl set_param fail_loc=0x406
4721
4722         # simulate local -ENOMEM
4723         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4724         RC=$?
4725
4726         lctl set_param fail_loc=0
4727         if [[ $RC -eq 0 ]]; then
4728                 error "Must return error due to dropped pages, rc=$RC"
4729         fi
4730
4731         LOCKED=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c locked)
4732         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
4733         WRITEBACK=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c writeback)
4734         if [[ $LOCKED -ne 0 ]]; then
4735                 error "Locked pages remain in cache, locked=$LOCKED"
4736         fi
4737
4738         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4739                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4740         fi
4741
4742         rm -f $DIR/$tfile
4743         echo "No pages locked after fsync"
4744
4745         reset_async
4746         return 0
4747 }
4748 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
4749
4750 test_118h() {
4751         remote_ost_nodsh && skip "remote OST with nodsh" && return
4752
4753         reset_async
4754
4755         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4756         set_nodes_failloc "$(osts_nodes)" 0x20e
4757         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4758         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4759         RC=$?
4760
4761         set_nodes_failloc "$(osts_nodes)" 0
4762         if [[ $RC -eq 0 ]]; then
4763                 error "Must return error due to dropped pages, rc=$RC"
4764         fi
4765
4766         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
4767         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4768         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writebac)
4769         if [[ $LOCKED -ne 0 ]]; then
4770                 error "Locked pages remain in cache, locked=$LOCKED"
4771         fi
4772
4773         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4774                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4775         fi
4776
4777         rm -f $DIR/$tfile
4778         echo "No pages locked after fsync"
4779
4780         return 0
4781 }
4782 run_test 118h "Verify timeout in handling recoverables errors  =========="
4783
4784 test_118i() {
4785         remote_ost_nodsh && skip "remote OST with nodsh" && return
4786
4787         reset_async
4788
4789         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4790         set_nodes_failloc "$(osts_nodes)" 0x20e
4791
4792         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4793         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4794         PID=$!
4795         sleep 5
4796         set_nodes_failloc "$(osts_nodes)" 0
4797
4798         wait $PID
4799         RC=$?
4800         if [[ $RC -ne 0 ]]; then
4801                 error "got error, but should be not, rc=$RC"
4802         fi
4803
4804         LOCKED=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c locked)
4805         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
4806         WRITEBACK=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c writeback)
4807         if [[ $LOCKED -ne 0 ]]; then
4808                 error "Locked pages remain in cache, locked=$LOCKED"
4809         fi
4810
4811         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4812                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4813         fi
4814
4815         rm -f $DIR/$tfile
4816         echo "No pages locked after fsync"
4817
4818         return 0
4819 }
4820 run_test 118i "Fix error before timeout in recoverable error  =========="
4821
4822 test_118j() {
4823         remote_ost_nodsh && skip "remote OST with nodsh" && return
4824
4825         reset_async
4826
4827         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
4828         set_nodes_failloc "$(osts_nodes)" 0x220
4829
4830         # return -EIO from OST
4831         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4832         RC=$?
4833         set_nodes_failloc "$(osts_nodes)" 0x0
4834         if [[ $RC -eq 0 ]]; then
4835                 error "Must return error due to dropped pages, rc=$RC"
4836         fi
4837
4838         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
4839         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4840         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4841         if [[ $LOCKED -ne 0 ]]; then
4842                 error "Locked pages remain in cache, locked=$LOCKED"
4843         fi
4844
4845         # in recoverable error on OST we want resend and stay until it finished
4846         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4847                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4848         fi
4849
4850         rm -f $DIR/$tfile
4851         echo "No pages locked after fsync"
4852
4853         return 0
4854 }
4855 run_test 118j "Simulate unrecoverable OST side error =========="
4856
4857 test_118k()
4858 {
4859         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
4860
4861         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4862         set_nodes_failloc "$(osts_nodes)" 0x20e
4863         mkdir -p $DIR/$tdir
4864
4865         for ((i=0;i<10;i++)); do
4866                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
4867                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
4868                 SLEEPPID=$!
4869                 sleep 0.500s
4870                 kill $SLEEPPID
4871                 wait $SLEEPPID
4872         done
4873
4874         set_nodes_failloc "$(osts_nodes)" 0
4875 }
4876 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
4877
4878 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
4879
4880 test_119a() # bug 11737
4881 {
4882         BSIZE=$((512 * 1024))
4883         directio write $DIR/$tfile 0 1 $BSIZE
4884         # We ask to read two blocks, which is more than a file size.
4885         # directio will indicate an error when requested and actual
4886         # sizes aren't equeal (a normal situation in this case) and
4887         # print actual read amount.
4888         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
4889         if [ "$NOB" != "$BSIZE" ]; then
4890                 error "read $NOB bytes instead of $BSIZE"
4891         fi
4892         rm -f $DIR/$tfile
4893 }
4894 run_test 119a "Short directIO read must return actual read amount"
4895
4896 test_119b() # bug 11737
4897 {
4898         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
4899
4900         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
4901         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
4902         sync
4903         multiop $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
4904                 error "direct read failed"
4905         rm -f $DIR/$tfile
4906 }
4907 run_test 119b "Sparse directIO read must return actual read amount"
4908
4909 test_119c() # bug 13099
4910 {
4911         BSIZE=1048576
4912         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
4913         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
4914         rm -f $DIR/$tfile
4915 }
4916 run_test 119c "Testing for direct read hitting hole"
4917
4918 test_119d() # bug 15950
4919 {
4920         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
4921         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
4922         BSIZE=1048576
4923         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
4924         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
4925         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
4926         lctl set_param fail_loc=0x40d
4927         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
4928         pid_dio=$!
4929         sleep 1
4930         cat $DIR/$tfile > /dev/null &
4931         lctl set_param fail_loc=0
4932         pid_reads=$!
4933         wait $pid_dio
4934         log "the DIO writes have completed, now wait for the reads (should not block very long)"
4935         sleep 2
4936         [ -n "`ps h -p $pid_reads -o comm`" ] && \
4937                 error "the read rpcs have not completed in 2s"
4938         rm -f $DIR/$tfile
4939         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
4940 }
4941 run_test 119d "The DIO path should try to send a new rpc once one is completed"
4942
4943 test_120a() {
4944         mkdir -p $DIR/$tdir
4945         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
4946                skip "no early lock cancel on server" && return 0
4947         lru_resize_disable mdc
4948         lru_resize_disable osc
4949         cancel_lru_locks mdc
4950         stat $DIR/$tdir > /dev/null
4951         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
4952         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
4953         mkdir $DIR/$tdir/d1
4954         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
4955         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
4956         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4957         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4958         lru_resize_enable mdc
4959         lru_resize_enable osc
4960 }
4961 run_test 120a "Early Lock Cancel: mkdir test ==================="
4962
4963 test_120b() {
4964         mkdir -p $DIR/$tdir
4965         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
4966                skip "no early lock cancel on server" && return 0
4967         lru_resize_disable mdc
4968         lru_resize_disable osc
4969         cancel_lru_locks mdc
4970         stat $DIR/$tdir > /dev/null
4971         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
4972         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
4973         touch $DIR/$tdir/f1
4974         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
4975         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
4976         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4977         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4978         lru_resize_enable mdc
4979         lru_resize_enable osc
4980 }
4981 run_test 120b "Early Lock Cancel: create test =================="
4982
4983 test_120c() {
4984         mkdir -p $DIR/$tdir
4985         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
4986                skip "no early lock cancel on server" && return 0
4987         lru_resize_disable mdc
4988         lru_resize_disable osc
4989         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
4990         touch $DIR/$tdir/d1/f1
4991         cancel_lru_locks mdc
4992         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
4993         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
4994         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
4995         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
4996         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
4997         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
4998         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4999         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5000         lru_resize_enable mdc
5001         lru_resize_enable osc
5002 }
5003 run_test 120c "Early Lock Cancel: link test ===================="
5004
5005 test_120d() {
5006         mkdir -p $DIR/$tdir
5007         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5008                skip "no early lock cancel on server" && return 0
5009         lru_resize_disable mdc
5010         lru_resize_disable osc
5011         touch $DIR/$tdir
5012         cancel_lru_locks mdc
5013         stat $DIR/$tdir > /dev/null
5014         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5015         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5016         chmod a+x $DIR/$tdir
5017         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5018         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5019         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5020         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5021         lru_resize_enable mdc
5022         lru_resize_enable osc
5023 }
5024 run_test 120d "Early Lock Cancel: setattr test ================="
5025
5026 test_120e() {
5027         mkdir -p $DIR/$tdir
5028         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5029                skip "no early lock cancel on server" && return 0
5030         lru_resize_disable mdc
5031         lru_resize_disable osc
5032         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
5033         cancel_lru_locks mdc
5034         cancel_lru_locks osc
5035         dd if=$DIR/$tdir/f1 of=/dev/null
5036         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
5037         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5038         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5039         unlink $DIR/$tdir/f1
5040         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5041         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5042         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5043         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5044         lru_resize_enable mdc
5045         lru_resize_enable osc
5046 }
5047 run_test 120e "Early Lock Cancel: unlink test =================="
5048
5049 test_120f() {
5050         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5051                skip "no early lock cancel on server" && return 0
5052         mkdir -p $DIR/$tdir
5053         lru_resize_disable mdc
5054         lru_resize_disable osc
5055         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
5056         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
5057         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
5058         cancel_lru_locks mdc
5059         cancel_lru_locks osc
5060         dd if=$DIR/$tdir/d1/f1 of=/dev/null
5061         dd if=$DIR/$tdir/d2/f2 of=/dev/null
5062         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
5063         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5064         blk1=`lctl get_param -n ldlm/services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5065         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
5066         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5067         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5068         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5069         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5070         lru_resize_enable mdc
5071         lru_resize_enable osc
5072 }
5073 run_test 120f "Early Lock Cancel: rename test =================="
5074
5075 test_120g() {
5076         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5077                skip "no early lock cancel on server" && return 0
5078         lru_resize_disable mdc
5079         lru_resize_disable osc
5080         count=10000
5081         echo create $count files
5082         mkdir -p $DIR/$tdir
5083         cancel_lru_locks mdc
5084         cancel_lru_locks osc
5085         t0=`date +%s`
5086
5087         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5088         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5089         createmany -o $DIR/$tdir/f $count
5090         sync
5091         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5092         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5093         t1=`date +%s`
5094         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
5095         echo rm $count files
5096         rm -r $DIR/$tdir
5097         sync
5098         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5099         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5100         t2=`date +%s`
5101         echo total: $count removes in $((t2-t1))
5102         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
5103         sleep 2
5104         # wait for commitment of removal
5105         lru_resize_enable mdc
5106         lru_resize_enable osc
5107 }
5108 run_test 120g "Early Lock Cancel: performance test ============="
5109
5110 test_121() { #bug 10589
5111         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
5112         lctl set_param fail_loc=0x310
5113         cancel_lru_locks osc > /dev/null
5114         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
5115         lctl set_param fail_loc=0
5116         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
5117 }
5118 run_test 121 "read cancel race ================================="
5119
5120 test_122() { #bug 11544
5121         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
5122         lctl set_param fail_loc=0x508
5123         dd if=/dev/zero of=$DIR/$tfile count=1
5124         sync
5125         lctl set_param fail_loc=0
5126 }
5127 run_test 122 "fail client bulk callback (shouldn't LBUG) ======="
5128
5129 test_123a() { # was test 123, statahead(bug 11401)
5130         SLOWOK=0
5131         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
5132                 log "testing on UP system. Performance may be not as good as expected."
5133                 SLOWOK=1
5134         fi
5135
5136         rm -rf $DIR/$tdir
5137         mkdir -p $DIR/$tdir
5138         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
5139         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
5140         MULT=10
5141         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
5142                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
5143
5144                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
5145                 lctl set_param -n llite.*.statahead_max 0
5146                 lctl get_param llite.*.statahead_max
5147                 cancel_lru_locks mdc
5148                 cancel_lru_locks osc
5149                 stime=`date +%s`
5150                 time ls -l $DIR/$tdir | wc -l
5151                 etime=`date +%s`
5152                 delta=$((etime - stime))
5153                 log "ls $i files without statahead: $delta sec"
5154                 lctl set_param llite.*.statahead_max=$max
5155
5156                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
5157                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
5158                 cancel_lru_locks mdc
5159                 cancel_lru_locks osc
5160                 stime=`date +%s`
5161                 time ls -l $DIR/$tdir | wc -l
5162                 etime=`date +%s`
5163                 delta_sa=$((etime - stime))
5164                 log "ls $i files with statahead: $delta_sa sec"
5165                 lctl get_param -n llite.*.statahead_stats
5166                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
5167
5168                 if [ $swrong -lt $ewrong ]; then
5169                         log "statahead was stopped, maybe too many locks held!"
5170                 fi
5171
5172                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
5173
5174                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
5175                         if [  $SLOWOK -eq 0 ]; then
5176                                 error "ls $i files is slower with statahead!"
5177                                 debugsave
5178
5179                                 lctl set_param debug=-1
5180                                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
5181                                 lctl set_param -n llite.*.statahead_max 0
5182                                 lctl get_param llite.*.statahead_max
5183                                 cancel_lru_locks mdc
5184                                 cancel_lru_locks osc
5185                                 $LCTL clear
5186                                 stime=`date +%s`
5187                                 time ls -l $DIR/$tdir | wc -l
5188                                 etime=`date +%s`
5189                                 error "ls $i files (again) without statahead: $((etime - stime)) sec"
5190
5191                                 lctl set_param debug=-1
5192                                 lctl set_param llite.*.statahead_max=$max
5193                                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
5194                                 cancel_lru_locks mdc
5195                                 cancel_lru_locks osc
5196                                 $LCTL clear
5197                                 stime=`date +%s`
5198                                 time ls -l $DIR/$tdir | wc -l
5199                                 etime=`date +%s`
5200                                 error "ls $i files (again) with statahead: $((etime - stime)) sec"
5201                                 lctl get_param -n llite.*.statahead_stats
5202
5203                                 debugrestore
5204                         else
5205                                 log "ls $i files is slower with statahead!"
5206                         fi
5207                         break
5208                 fi
5209
5210                 [ $delta -gt 20 ] && break
5211                 [ $delta -gt 8 ] && MULT=$((50 / delta))
5212                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
5213         done
5214         log "ls done"
5215
5216         stime=`date +%s`
5217         rm -r $DIR/$tdir
5218         sync
5219         etime=`date +%s`
5220         delta=$((etime - stime))
5221         log "rm -r $DIR/$tdir/: $delta seconds"
5222         log "rm done"
5223         lctl get_param -n llite.*.statahead_stats
5224 }
5225 run_test 123a "verify statahead work"
5226
5227 test_123b () { # statahead(bug 15027)
5228         mkdir -p $DIR/$tdir
5229         createmany -o $DIR/$tdir/$tfile-%d 1000
5230
5231         cancel_lru_locks mdc
5232         cancel_lru_locks osc
5233
5234 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
5235         lctl set_param fail_loc=0x80000803
5236         ls -lR $DIR/$tdir > /dev/null
5237         log "ls done"
5238         lctl set_param fail_loc=0x0
5239         lctl get_param -n llite.*.statahead_stats
5240         rm -r $DIR/$tdir
5241         sync
5242
5243 }
5244 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
5245
5246 test_124a() {
5247         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
5248                skip "no lru resize on server" && return 0
5249         local NR=2000
5250         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
5251
5252         log "create $NR files at $DIR/$tdir"
5253         createmany -o $DIR/$tdir/f $NR ||
5254                 error "failed to create $NR files in $DIR/$tdir"
5255
5256         cancel_lru_locks mdc
5257         ls -l $DIR/$tdir > /dev/null
5258
5259         local NSDIR=""
5260         local LRU_SIZE=0
5261         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
5262                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5263                 LRU_SIZE=$(lctl get_param -n $PARAM)
5264                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
5265                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
5266                         log "NS=$(basename $NSDIR)"
5267                         break
5268                 fi
5269         done
5270
5271         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
5272                 skip "Not enough cached locks created!"
5273                 return 0
5274         fi
5275         log "LRU=$LRU_SIZE"
5276
5277         local SLEEP=30
5278
5279         # We know that lru resize allows one client to hold $LIMIT locks
5280         # for 10h. After that locks begin to be killed by client.
5281         local MAX_HRS=10
5282         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
5283
5284         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
5285         # killing locks. Some time was spent for creating locks. This means
5286         # that up to the moment of sleep finish we must have killed some of
5287         # them (10-100 locks). This depends on how fast ther were created.
5288         # Many of them were touched in almost the same moment and thus will
5289         # be killed in groups.
5290         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
5291
5292         # Use $LRU_SIZE_B here to take into account real number of locks
5293         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
5294         local LRU_SIZE_B=$LRU_SIZE
5295         log "LVF=$LVF"
5296         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
5297         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
5298
5299         # Let's make sure that we really have some margin. Client checks
5300         # cached locks every 10 sec.
5301         SLEEP=$((SLEEP+20))
5302         log "Sleep ${SLEEP} sec"
5303         local SEC=0
5304         while ((SEC<$SLEEP)); do
5305                 echo -n "..."
5306                 sleep 5
5307                 SEC=$((SEC+5))
5308                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
5309                 echo -n "$LRU_SIZE"
5310         done
5311         echo ""
5312         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
5313         local LRU_SIZE_A=`lctl get_param -n $NSDIR/lru_size`
5314
5315         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
5316                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
5317                 unlinkmany $DIR/$tdir/f $NR
5318                 return
5319         }
5320
5321         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
5322         log "unlink $NR files at $DIR/$tdir"
5323         unlinkmany $DIR/$tdir/f $NR
5324 }
5325 run_test 124a "lru resize ======================================="
5326
5327 test_124b() {
5328         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
5329                skip "no lru resize on server" && return 0
5330
5331         # even for cmd no matter what metadata namespace to use for getting
5332         # the limit, we use appropriate.
5333         LIMIT=`lctl get_param -n ldlm.namespaces.*mdc*.pool.limit`
5334
5335         NR=$(($(default_lru_size)*20))
5336         if [ $NR -gt $LIMIT ]; then
5337                 NR=$LIMIT
5338         fi
5339         lru_resize_disable mdc
5340         mkdir -p $DIR/$tdir/disable_lru_resize ||
5341                 error "failed to create $DIR/$tdir/disable_lru_resize"
5342
5343         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
5344         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
5345         cancel_lru_locks mdc
5346         stime=`date +%s`
5347         PID=""
5348         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5349         PID="$PID $!"
5350         sleep 2
5351         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5352         PID="$PID $!"
5353         sleep 2
5354         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5355         PID="$PID $!"
5356         wait $PID
5357         etime=`date +%s`
5358         nolruresize_delta=$((etime-stime))
5359         log "ls -la time: $nolruresize_delta seconds"
5360         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
5361         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
5362
5363         lru_resize_enable mdc
5364         mkdir -p $DIR/$tdir/enable_lru_resize ||
5365                 error "failed to create $DIR/$tdir/enable_lru_resize"
5366
5367         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
5368         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
5369         cancel_lru_locks mdc
5370         stime=`date +%s`
5371         PID=""
5372         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5373         PID="$PID $!"
5374         sleep 2
5375         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5376         PID="$PID $!"
5377         sleep 2
5378         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5379         PID="$PID $!"
5380         wait $PID
5381         etime=`date +%s`
5382         lruresize_delta=$((etime-stime))
5383         log "ls -la time: $lruresize_delta seconds"
5384         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
5385
5386         if [ $lruresize_delta -gt $nolruresize_delta ]; then
5387                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
5388         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
5389                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
5390         else
5391                 log "lru resize performs the same with no lru resize"
5392         fi
5393         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
5394 }
5395 run_test 124b "lru resize (performance test) ======================="
5396
5397 test_125() { # 13358
5398         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
5399         mkdir -p $DIR/d125 || error "mkdir failed"
5400         $SETSTRIPE $DIR/d125 -s 65536 -c -1 || error "setstripe failed"
5401         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failes"
5402         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
5403 }
5404 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
5405
5406 test_126() { # bug 12829/13455
5407         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
5408         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
5409         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
5410         rm -f $DIR/$tfile
5411         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
5412 }
5413 run_test 126 "check that the fsgid provided by the client is taken into account"
5414
5415 test_127() { # bug 15521
5416         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
5417         $LCTL set_param osc.*.stats=0
5418         FSIZE=$((2048 * 1024))
5419         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
5420         cancel_lru_locks osc
5421         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
5422
5423         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
5424         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
5425                 echo "got $COUNT $NAME"
5426                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
5427                 eval $NAME=$COUNT || error "Wrong proc format"
5428
5429                 case $NAME in
5430                         read_bytes|write_bytes)
5431                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
5432                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
5433                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
5434                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
5435                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
5436                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
5437                                 error "sumsquare is too small: $SUMSQ"
5438                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
5439                                 error "sumsquare is too big: $SUMSQ"
5440                         ;;
5441                         *) ;;
5442                 esac
5443         done < $DIR/${tfile}.tmp
5444
5445         #check that we actually got some stats
5446         [ "$read_bytes" ] || error "Missing read_bytes stats"
5447         [ "$write_bytes" ] || error "Missing write_bytes stats"
5448         [ "$read_bytes" != 0 ] || error "no read done"
5449         [ "$write_bytes" != 0 ] || error "no write done"
5450 }
5451 run_test 127 "verify the client stats are sane"
5452
5453 test_128() { # bug 15212
5454         touch $DIR/$tfile
5455         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
5456                 find $DIR/$tfile
5457                 find $DIR/$tfile
5458         EOF
5459
5460         result=$(grep error $TMP/$tfile.log)
5461         rm -f $DIR/$tfile
5462         [ -z "$result" ] || error "consecutive find with interactive lfs failed"
5463 }
5464 run_test 128 "interactive lfs for 2 consecutive finds"
5465
5466 test_129() {
5467         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return 0
5468         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5469
5470         local MNTDEV=$(get_mds_mntdev_proc_path)
5471         DEV=$(basename $(do_facet mds lctl get_param -n $MNTDEV))
5472         [ -z "$DEV" ] && error "can't access mds mntdev"
5473         EFBIG=27
5474         LDPROC=/proc/fs/ldiskfs/$DEV/max_dir_size
5475         MAX=16384
5476
5477         do_facet mds "echo $MAX > $LDPROC"
5478
5479         mkdir -p $DIR/$tdir
5480
5481         I=0
5482         J=0
5483         while [ ! $I -gt $MAX ]; do
5484                 multiop $DIR/$tdir/$J Oc
5485                 rc=$?
5486                 if [ $rc -eq $EFBIG ]; then
5487                         do_facet mds "echo 0 >$LDPROC"
5488                         echo "return code $rc received as expected"
5489                         return 0
5490                 elif [ $rc -ne 0 ]; then
5491                         do_facet mds "echo 0 >$LDPROC"
5492                         error_exit "error $rc instead of expected $EFBIG"
5493                 fi
5494                 J=$((J+1))
5495                 I=$(stat -c%s "$DIR/$tdir")
5496         done
5497
5498         error "exceeded dir size limit: $I bytes"
5499         do_facet mds "echo 0 >$LDPROC"
5500 }
5501 run_test 129 "test directory size limit ========================"
5502
5503 OLDIFS="$IFS"
5504 cleanup_130() {
5505         trap 0
5506         IFS="$OLDIFS"
5507 }
5508
5509 test_130a() {
5510         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5511         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5512
5513         trap cleanup_130 EXIT RETURN
5514
5515         local fm_file=$DIR/$tfile
5516         lfs setstripe -s 65536 -c 1 $fm_file ||
5517                 error "setstripe failed on $fm_file"
5518         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
5519                 error "dd failed for $fm_file"
5520
5521         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5522         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5523
5524         lun=`$GETSTRIPE $fm_file  | grep -A 10 obdidx | awk '{print $1}' | grep -v "obdidx"`
5525
5526         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
5527         IFS=$'\n'
5528         tot_len=0
5529         for line in $filefrag_op
5530         do
5531                 frag_lun=`echo $line | cut -d: -f5`
5532                 ext_len=`echo $line | cut -d: -f4`
5533                 if (( $frag_lun != $lun )); then
5534                         cleanup_130
5535                         error "FIEMAP on 1-stripe file($fm_file) failed"
5536                         return
5537                 fi
5538                 (( tot_len += ext_len ))
5539         done
5540
5541         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
5542                 cleanup_130
5543                 error "FIEMAP on 1-stripe file($fm_file) failed;"
5544                 return
5545         fi
5546
5547         cleanup_130
5548
5549         echo "FIEMAP on single striped file succeeded"
5550 }
5551 run_test 130a "FIEMAP (1-stripe file)"
5552
5553 test_130b() {
5554         [ "$OSTCOUNT" -lt "2" ] && skip_env "FIEMAP on 2-stripe file test" && return
5555
5556         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5557         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5558
5559         trap cleanup_130 EXIT RETURN
5560
5561         local fm_file=$DIR/$tfile
5562         lfs setstripe -s 65536 -c 2 $fm_file ||
5563                 error "setstripe failed on $fm_file"
5564         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
5565                 error "dd failed on $fm_file"
5566
5567         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5568         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5569
5570         last_lun=`echo $filefrag_op | cut -d: -f5`
5571
5572         IFS=$'\n'
5573         tot_len=0
5574         num_luns=1
5575         for line in $filefrag_op; do
5576                 frag_lun=`echo $line | cut -d: -f5`
5577                 ext_len=`echo $line | cut -d: -f4`
5578                 if (( $frag_lun != $last_lun )); then
5579                         if (( tot_len != 1024 )); then
5580                                 cleanup_130
5581                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of 256"
5582                                 return
5583                         else
5584                                 (( num_luns += 1 ))
5585                                 tot_len=0
5586                         fi
5587                 fi
5588                 (( tot_len += ext_len ))
5589                 last_lun=$frag_lun
5590         done
5591         if (( num_luns != 2 || tot_len != 1024 )); then
5592                 cleanup_130
5593                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
5594                 return
5595         fi
5596
5597         cleanup_130
5598
5599         echo "FIEMAP on 2-stripe file succeeded"
5600 }
5601 run_test 130b "FIEMAP (2-stripe file)"
5602
5603 test_130c() {
5604         [ "$OSTCOUNT" -lt "2" ] && skip_env "FIEMAP on 2-stripe hole test" && return
5605
5606         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5607         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5608
5609         trap cleanup_130 EXIT RETURN
5610
5611         local fm_file=$DIR/$tfile
5612         lfs setstripe -s 65536 -c 2 $fm_file ||
5613                 error "setstripe failed on $fm_file"
5614         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
5615                 error "dd failed on $fm_file"
5616
5617         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5618         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5619
5620         last_lun=`echo $filefrag_op | cut -d: -f5`
5621
5622         IFS=$'\n'
5623         tot_len=0
5624         num_luns=1
5625         for line in $filefrag_op
5626         do
5627                 frag_lun=`echo $line | cut -d: -f5`
5628                 ext_len=`echo $line | cut -d: -f4`
5629                 if (( $frag_lun != $last_lun )); then
5630                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
5631                         if (( logical != 512 )); then
5632                                 cleanup_130
5633                                 error "FIEMAP $fm_file: logical start for LUN $logical instead of 512"
5634                                 return
5635                         fi
5636                         if (( tot_len != 512 )); then
5637                                 cleanup_130
5638                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of 1024"
5639                                 return
5640                         else
5641                                 (( num_luns += 1 ))
5642                                 tot_len=0
5643                         fi
5644                 fi
5645                 (( tot_len += ext_len ))
5646                 last_lun=$frag_lun
5647         done
5648         if (( num_luns != 2 || tot_len != 512 )); then
5649                 cleanup_130
5650                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
5651                 return
5652         fi
5653
5654         cleanup_130
5655
5656         echo "FIEMAP on 2-stripe file with hole succeeded"
5657 }
5658 run_test 130c "FIEMAP (2-stripe file with hole)"
5659
5660 test_130d() {
5661         [ "$OSTCOUNT" -lt "3" ] && skip_env "FIEMAP on N-stripe file test" && return
5662
5663         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5664         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5665
5666         trap cleanup_130 EXIT RETURN
5667
5668         local fm_file=$DIR/$tfile
5669         lfs setstripe -s 65536 -c $OSTCOUNT $fm_file ||
5670                 error "setstripe failed on $fm_file"
5671         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
5672                 error "dd failed on $fm_file"
5673
5674         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5675         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5676
5677         last_lun=`echo $filefrag_op | cut -d: -f5`
5678
5679         IFS=$'\n'
5680         tot_len=0
5681         num_luns=1
5682         for line in $filefrag_op
5683         do
5684                 frag_lun=`echo $line | cut -d: -f5`
5685                 ext_len=`echo $line | cut -d: -f4`
5686                 if (( $frag_lun != $last_lun )); then
5687                         if (( tot_len != 1024 )); then
5688                                 cleanup_130
5689                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of 1024"
5690                                 return
5691                         else
5692                                 (( num_luns += 1 ))
5693                                 tot_len=0
5694                         fi
5695                 fi
5696                 (( tot_len += ext_len ))
5697                 last_lun=$frag_lun
5698         done
5699         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
5700                 cleanup_130
5701                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
5702                 return
5703         fi
5704
5705         cleanup_130
5706
5707         echo "FIEMAP on N-stripe file succeeded"
5708 }
5709 run_test 130d "FIEMAP (N-stripe file)"
5710
5711 test_130e() {
5712         [ "$OSTCOUNT" -lt "2" ] && skip "continuation FIEMAP test" && return
5713
5714         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5715         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5716
5717         trap cleanup_130 EXIT RETURN
5718
5719         local fm_file=$DIR/$tfile
5720         lfs setstripe -s 131072 -c 2 $fm_file ||
5721                 error "setstripe failed on $fm_file"
5722         NUM_BLKS=512
5723         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
5724         for ((i = 0; i < $NUM_BLKS; i++)); do
5725                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
5726         done
5727
5728         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5729         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
5730
5731         last_lun=`echo $filefrag_op | cut -d: -f5`
5732
5733         IFS=$'\n'
5734         tot_len=0
5735         num_luns=1
5736         for line in $filefrag_op
5737         do
5738                 frag_lun=`echo $line | cut -d: -f5`
5739                 ext_len=`echo $line | cut -d: -f4`
5740                 if (( $frag_lun != $last_lun )); then
5741                         if (( tot_len != $EXPECTED_LEN )); then
5742                                 cleanup_130
5743                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
5744                                 return
5745                         else
5746                                 (( num_luns += 1 ))
5747                                 tot_len=0
5748                         fi
5749                 fi
5750                 (( tot_len += ext_len ))
5751                 last_lun=$frag_lun
5752         done
5753         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
5754                 cleanup_130
5755                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
5756                 return
5757         fi
5758
5759         cleanup_130
5760
5761         echo "FIEMAP with continuation calls succeeded"
5762 }
5763 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
5764
5765 test_140() { #bug-17379
5766         mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
5767         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
5768         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
5769
5770         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
5771         local i=0
5772         while i=`expr $i + 1`; do
5773                 mkdir -p $i || error "Creating dir $i"
5774                 cd $i || error "Changing to $i"
5775                 ln -s ../stat stat || error "Creating stat symlink"
5776                 # Read the symlink until ELOOP present,
5777                 # not LBUGing the system is considered success,
5778                 # we didn't overrun the stack.
5779                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
5780                 [ $ret -ne 0 ] && {
5781                         if [ $ret -eq 40 ]; then
5782                                 break  # -ELOOP
5783                         else
5784                                 error "Open stat symlink"
5785                                 return
5786                         fi
5787                 }
5788         done
5789         i=`expr $i - 1`
5790         echo "The symlink depth = $i"
5791         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 ] || error "Invalid symlink depth"
5792 }
5793 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
5794
5795 test_150() {
5796         local TF="$TMP/$tfile"
5797
5798         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
5799         cp $TF $DIR/$tfile
5800         cancel_lru_locks osc
5801         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
5802         remount_client $MOUNT
5803         df -P $MOUNT
5804         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
5805
5806         $TRUNCATE $TF 6000
5807         $TRUNCATE $DIR/$tfile 6000
5808         cancel_lru_locks osc
5809         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
5810
5811         echo "12345" >>$TF
5812         echo "12345" >>$DIR/$tfile
5813         cancel_lru_locks osc
5814         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
5815
5816         echo "12345" >>$TF
5817         echo "12345" >>$DIR/$tfile
5818         cancel_lru_locks osc
5819         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
5820
5821         rm -f $TF
5822         true
5823 }
5824 run_test 150 "truncate/append tests"
5825
5826 function roc_hit() {
5827     local list=$(comma_list $(osts_nodes))
5828
5829     ACCNUM=$(do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
5830         awk '/'cache_hit'/ {sum+=$2} END {print sum}')
5831     echo $ACCNUM
5832 }
5833
5834 function set_cache() {
5835     local on=1
5836
5837     if [ "$2" == "off" ]; then
5838         on=0;
5839     fi
5840     local list=$(comma_list $(osts_nodes))
5841     do_nodes $list lctl set_param obdfilter.*.${1}_cache_enable $on
5842
5843     cancel_lru_locks osc
5844 }
5845
5846 test_151() {
5847         remote_ost_nodsh && skip "remote OST with nodsh" && return
5848
5849         local list=$(comma_list $(osts_nodes))
5850         if ! do_nodes $list grep -q truncate_inode_pages_range /proc/kallsyms; then  #b=18718
5851                 skip "old RHEL4/SLES9 kernel" && return
5852         fi
5853
5854         local CPAGES=3
5855
5856         # check whether obdfilter is cache capable at all
5857         if ! do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable > /dev/null; then
5858                 echo "not cache-capable obdfilter"
5859                 return 0
5860         fi
5861
5862         # make sure cache is enabled on all obdfilters
5863         do_nodes $list $LCTL set_param obdfilter.*.read_cache_enable=1
5864         do_nodes $list $LCTL set_param obdfilter.*.writethrough_cache_enable=1
5865
5866         # pages should be in the case right after write
5867         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
5868         local BEFORE=`roc_hit`
5869         cancel_lru_locks osc
5870         cat $DIR/$tfile >/dev/null
5871         local AFTER=`roc_hit`
5872         if let "AFTER - BEFORE != CPAGES"; then
5873                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
5874         fi
5875
5876         # the following read invalidates the cache
5877         cancel_lru_locks osc
5878         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 0
5879         cat $DIR/$tfile >/dev/null
5880
5881         # now data shouldn't be found in the cache
5882         BEFORE=`roc_hit`
5883         cancel_lru_locks osc
5884         cat $DIR/$tfile >/dev/null
5885         AFTER=`roc_hit`
5886         if let "AFTER - BEFORE != 0"; then
5887                 error "IN CACHE: before: $BEFORE, after: $AFTER"
5888         fi
5889
5890         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=1
5891         do_nodes $list $LCTL set_param obdfilter.*.writethrough_cache_enable=1
5892         rm -f $DIR/$tfile
5893 }
5894 run_test 151 "test cache on oss and controls ==============================="
5895
5896 test_152() {
5897         local TF="$TMP/$tfile"
5898
5899         # simulate ENOMEM during write
5900 #define OBD_FAIL_OST_NOMEM      0x226
5901         lctl set_param fail_loc=0x80000226
5902         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
5903         cp $TF $DIR/$tfile
5904         sync || error "sync failed"
5905         lctl set_param fail_loc=0
5906
5907         # discard client's cache
5908         cancel_lru_locks osc
5909
5910         # simulate ENOMEM during read
5911         lctl set_param fail_loc=0x80000226
5912         cmp $TF $DIR/$tfile || error "cmp failed"
5913         lctl set_param fail_loc=0
5914
5915         rm -f $TF
5916 }
5917 run_test 152 "test read/write with enomem ============================"
5918
5919 test_153() {
5920         multiop $DIR/$tfile Ow4096Ycu || error "multiop failed"
5921 }
5922 run_test 153 "test if fdatasync does not crash ======================="
5923
5924 test_154() {
5925         # do directio so as not to populate the page cache
5926         log "creating a 10 Mb file"
5927         multiop $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
5928         log "starting reads"
5929         dd if=$DIR/$tfile of=/dev/null bs=4096 &
5930         log "truncating the file"
5931         multiop $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
5932         log "killing dd"
5933         kill %+ || true # reads might have finished
5934         echo "wait until dd is finished"
5935         wait
5936         log "removing the temporary file"
5937         rm -rf $DIR/$tfile || error "tmp file removal failed"
5938 }
5939 run_test 154 "parallel read and truncate should not deadlock ==="
5940
5941 test_155_load() {
5942     local temp=$TMP/$tfile
5943     local file=$DIR/$tfile
5944     local list=$(comma_list $(osts_nodes))
5945     local big=$(do_nodes $list grep "cache" /proc/cpuinfo | \
5946         awk '{sum+=$4} END{print sum}')
5947
5948     log big is $big K
5949
5950     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
5951         error "dd of=$temp bs=6096 count=1 failed"
5952     cp $temp $file
5953     cancel_lru_locks osc
5954     cmp $temp $file || error "$temp $file differ"
5955
5956     $TRUNCATE $temp 6000
5957     $TRUNCATE $file 6000
5958     cmp $temp $file || error "$temp $file differ (truncate1)"
5959
5960     echo "12345" >>$temp
5961     echo "12345" >>$file
5962     cmp $temp $file || error "$temp $file differ (append1)"
5963
5964     echo "12345" >>$temp
5965     echo "12345" >>$file
5966     cmp $temp $file || error "$temp $file differ (append2)"
5967
5968     dd if=/dev/urandom of=$temp bs=$((big*2)) count=1k || \
5969         error "dd of=$temp bs=$((big*2)) count=1k failed"
5970     cp $temp $file
5971     ls -lh $temp $file
5972     cancel_lru_locks osc
5973     cmp $temp $file || error "$temp $file differ"
5974
5975     rm -f $temp
5976     true
5977 }
5978
5979 test_155a() {
5980     set_cache read on
5981     set_cache writethrough on
5982     test_155_load
5983 }
5984 run_test 155a "Verification of correctness: read cache:on write_cache:on"
5985
5986 test_155b() {
5987     set_cache read on
5988     set_cache writethrough off
5989     test_155_load
5990 }
5991 run_test 155b "Verification of correctness: read cache:on write_cache:off"
5992
5993 test_155c() {
5994     set_cache read off
5995     set_cache writethrough on
5996     test_155_load
5997 }
5998 run_test 155c "Verification of correctness: read cache:off write_cache:on"
5999
6000 test_155d() {
6001     set_cache read off
6002     set_cache writethrough off
6003     test_155_load
6004 }
6005 run_test 155d "Verification of correctness: read cache:off write_cache:off "
6006
6007 test_156() {
6008     local CPAGES=3
6009     local BEFORE
6010     local AFTER
6011     local file="$DIR/$tfile"
6012
6013     log "Turn on read and write cache"
6014     set_cache read on
6015     set_cache writethrough on
6016
6017     log "Write data and read it back."
6018     log "Read should be satisfied from the cache."
6019     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6020     BEFORE=`roc_hit`
6021     cancel_lru_locks osc
6022     cat $file >/dev/null
6023     AFTER=`roc_hit`
6024     if ! let "AFTER - BEFORE == CPAGES"; then
6025         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6026     else
6027         log "cache hits:: before: $BEFORE, after: $AFTER"
6028     fi
6029
6030     log "Read again; it should be satisfied from the cache."
6031     BEFORE=$AFTER
6032     cancel_lru_locks osc
6033     cat $file >/dev/null
6034     AFTER=`roc_hit`
6035     if ! let "AFTER - BEFORE == CPAGES"; then
6036         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6037     else
6038         log "cache hits:: before: $BEFORE, after: $AFTER"
6039     fi
6040
6041
6042     log "Turn off the read cache and turn on the write cache"
6043     set_cache read off
6044     set_cache writethrough on
6045
6046     log "Read again; it should be satisfied from the cache."
6047     BEFORE=`roc_hit`
6048     cancel_lru_locks osc
6049     cat $file >/dev/null
6050     AFTER=`roc_hit`
6051     if ! let "AFTER - BEFORE == CPAGES"; then
6052         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6053     else
6054         log "cache hits:: before: $BEFORE, after: $AFTER"
6055     fi
6056
6057     log "Read again; it should not be satisfied from the cache."
6058     BEFORE=$AFTER
6059     cancel_lru_locks osc
6060     cat $file >/dev/null
6061     AFTER=`roc_hit`
6062     if ! let "AFTER - BEFORE == 0"; then
6063         error "IN CACHE: before: $BEFORE, after: $AFTER"
6064     else
6065         log "cache hits:: before: $BEFORE, after: $AFTER"
6066     fi
6067
6068     log "Write data and read it back."
6069     log "Read should be satisfied from the cache."
6070     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6071     BEFORE=`roc_hit`
6072     cancel_lru_locks osc
6073     cat $file >/dev/null
6074     AFTER=`roc_hit`
6075     if ! let "AFTER - BEFORE == CPAGES"; then
6076         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6077     else
6078         log "cache hits:: before: $BEFORE, after: $AFTER"
6079     fi
6080
6081     log "Read again; it should not be satisfied from the cache."
6082     BEFORE=$AFTER
6083     cancel_lru_locks osc
6084     cat $file >/dev/null
6085     AFTER=`roc_hit`
6086     if ! let "AFTER - BEFORE == 0"; then
6087         error "IN CACHE: before: $BEFORE, after: $AFTER"
6088     else
6089         log "cache hits:: before: $BEFORE, after: $AFTER"
6090     fi
6091
6092
6093     log "Turn off read and write cache"
6094     set_cache read off
6095     set_cache writethrough off
6096
6097     log "Write data and read it back"
6098     log "It should not be satisfied from the cache."
6099     rm -f $file
6100     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6101     cancel_lru_locks osc
6102     BEFORE=`roc_hit`
6103     cat $file >/dev/null
6104     AFTER=`roc_hit`
6105     if ! let "AFTER - BEFORE == 0"; then
6106         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
6107     else
6108         log "cache hits:: before: $BEFORE, after: $AFTER"
6109     fi
6110
6111
6112     log "Turn on the read cache and turn off the write cache"
6113     set_cache read on
6114     set_cache writethrough off
6115
6116     log "Write data and read it back"
6117     log "It should not be satisfied from the cache."
6118     rm -f $file
6119     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6120     BEFORE=`roc_hit`
6121     cancel_lru_locks osc
6122     cat $file >/dev/null
6123     AFTER=`roc_hit`
6124     if ! let "AFTER - BEFORE == 0"; then
6125         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
6126     else
6127         log "cache hits:: before: $BEFORE, after: $AFTER"
6128     fi
6129
6130     log "Read again; it should be satisfied from the cache."
6131     BEFORE=`roc_hit`
6132     cancel_lru_locks osc
6133     cat $file >/dev/null
6134     AFTER=`roc_hit`
6135     if ! let "AFTER - BEFORE == CPAGES"; then
6136         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6137     else
6138         log "cache hits:: before: $BEFORE, after: $AFTER"
6139     fi
6140
6141     rm -f $file
6142 }
6143 run_test 156 "Verification of ROC tunables ========================"
6144
6145 test_170() {
6146         $LCTL clear     # bug 18514
6147         $LCTL debug_daemon start $TMP/${tfile}_log_good
6148         touch $DIR/$tfile
6149         $LCTL debug_daemon stop
6150         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
6151                error "sed failed to read log_good"
6152
6153         $LCTL debug_daemon start $TMP/${tfile}_log_good
6154         rm -rf $DIR/$tfile
6155         $LCTL debug_daemon stop
6156
6157         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
6158                error "lctl df log_bad failed"
6159
6160         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
6161         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
6162
6163         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
6164         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
6165
6166         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
6167                 error "bad_line good_line1 good_line2 are empty"
6168
6169         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
6170         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
6171         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
6172
6173         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
6174         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
6175         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
6176
6177         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
6178                 error "bad_line_new good_line_new are empty"
6179
6180         local expected_good=$((good_line1 + good_line2*2))
6181
6182         rm -f $TMP/${tfile}*
6183         if [ $bad_line -ne $bad_line_new ]; then
6184                 error "expected $bad_line bad lines, but got $bad_line_new"
6185                 return 1
6186         fi
6187
6188         if [ $expected_good -ne $good_line_new ]; then
6189                 error "expected $expected_good good lines, but got $good_line_new"
6190                 return 2
6191         fi
6192         true
6193 }
6194 run_test 170 "test lctl df to handle corrupted log ====================="
6195
6196 test_171() { # bug20592
6197 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
6198         $LCTL set_param fail_loc=0x50e
6199         $LCTL set_param fail_val=3000
6200         multiop_bg_pause $DIR/$tfile Os || true
6201         # cause log dump
6202         sleep 3
6203         if dmesg | grep "recursive fault"; then
6204                 error "caught a recursive fault"
6205         fi
6206         $LCTL set_param fail_loc=0
6207         true
6208 }
6209 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
6210
6211 obdecho_create_test() {
6212         local OBD=$1
6213         local node=$2
6214         local rc=0
6215         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
6216         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" || rc=2; }
6217         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec create 1" || rc=3; }
6218         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec test_brw 0 w 1" || rc=4; }
6219         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec cleanup" || rc=5; }
6220         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec detach" || rc=6; }
6221         return $rc
6222 }
6223
6224 test_180() {
6225         local rc=0
6226         local rmmod_local=0
6227         local rmmod_remote=0
6228
6229         lsmod | grep -q obdecho || { load_module obdecho/obdecho && rmmod_local=1; }
6230
6231         OBD=`$LCTL  dl | awk ' /-osc-/ { print $4; exit; }'`
6232         [ "x$OBD" != "x" ] && { obdecho_create_test $OBD client || rc=2; }
6233         [ $rmmod_local -eq 1 ] && rmmod obdecho
6234         [ $rc -ne 0 ] && return $rc
6235
6236         do_facet ost "lsmod | grep -q obdecho || { insmod ${LUSTRE}/obdecho/obdecho.ko || modprobe obdecho; }" && rmmod_remote=1
6237
6238         OBD=$(do_facet ost "$LCTL  dl | awk '/obdfilter/ { print; exit; }'" | awk '{print $4;}')
6239         [ "x$OBD" != "x" ] && { obdecho_create_test $OBD ost || rc=3; }
6240         [ $rmmod_remote -eq 1 ] && do_facet ost "rmmod obdecho"
6241         [ $rc -ne 0 ] && return $rc
6242
6243         true
6244 }
6245 run_test 180 "test obdecho ============================================"
6246
6247 POOL=${POOL:-cea1}
6248 TGT_COUNT=$OSTCOUNT
6249 TGTPOOL_FIRST=1
6250 TGTPOOL_MAX=$(($TGT_COUNT - 1))
6251 TGTPOOL_STEP=2
6252 TGTPOOL_LIST=`seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`
6253 POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
6254 POOL_DIR=$POOL_ROOT/dir_tst
6255 POOL_FILE=$POOL_ROOT/file_tst
6256
6257 test_pools()
6258 {
6259         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep pools)" ] &&
6260                 skip "missing pools support on server" && return 1
6261         remote_mgs_nodsh && skip "remote MGS with nodsh" && return 1
6262         [ -z "$mdtlov" ] && mdtlov=$(get_mdtlov_proc_path $FSNAME)
6263         return 0
6264 }
6265
6266 check_file_in_pool()
6267 {
6268         file=$1
6269         res=$($GETSTRIPE $file | grep 0x | cut -f2)
6270         for i in $res
6271         do
6272                 found=$(echo :$TGTPOOL_LIST: | tr " " ":"  | grep :$i:)
6273                 if [[ "$found" == "" ]]
6274                 then
6275                         echo "pool list: $TGTPOOL_LIST"
6276                         echo "striping: $res"
6277                         error "$file not allocated in $POOL"
6278                         return 1
6279                 fi
6280         done
6281         return 0
6282 }
6283
6284 export mdtlov=
6285
6286 cleanup_200 () {
6287         trap 0
6288         test_pools || return 0
6289         destroy_pool $POOL
6290 }
6291
6292 test_200a() {
6293         test_pools || return 0
6294
6295         do_facet mgs $LCTL pool_new $FSNAME.$POOL
6296
6297         trap cleanup_200 EXIT
6298         CLEANUP_200=yes
6299
6300         # get param should return err until pool is created
6301         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "" || error "Pool creation of $POOL failed"
6302 }
6303 run_test 200a "Create new pool =========================================="
6304
6305 test_200b() {
6306         test_pools || return 0
6307         TGT=$(for i in `seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`; do printf "$FSNAME-OST%04x_UUID " $i; done)
6308         do_facet mgs $LCTL pool_add $FSNAME.$POOL \
6309                 $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]
6310         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | sort -u | tr '\n' ' ' " "$TGT" || error "Add to pool failed"
6311 }
6312 run_test 200b "Add targets to a pool ===================================="
6313
6314 test_200c() {
6315         test_pools || return 0
6316         mkdir -p $POOL_DIR
6317         $SETSTRIPE -c 2 -p $POOL $POOL_DIR
6318         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
6319 }
6320 run_test 200c "Set pool on a directory ================================="
6321
6322 test_200d() {
6323         test_pools || return 0
6324         res=$($GETSTRIPE --pool $POOL_DIR | awk '/^pool:/ {print $2}')
6325         [ "$res" = $POOL ] || error "Pool on $POOL_DIR is $res, not $POOL"
6326 }
6327 run_test 200d "Check pool on a directory ==============================="
6328
6329 test_200e() {
6330         test_pools || return 0
6331         failed=0
6332         for i in $(seq -w 1 $(($TGT_COUNT * 3))); do
6333                 file=$POOL_DIR/file-$i
6334                 touch $file
6335                 check_file_in_pool $file
6336                 if [[ $? != 0 ]]; then
6337                         failed=$(($failed + 1))
6338                 fi
6339         done
6340         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
6341 }
6342 run_test 200e "Check files allocation from directory pool =============="
6343
6344 test_200f() {
6345         test_pools || return 0
6346         mkdir -p $POOL_FILE
6347         failed=0
6348         for i in $(seq -w 1 $(($TGT_COUNT * 3))); do
6349                 file=$POOL_FILE/spoo-$i
6350                 $SETSTRIPE -p $POOL $file
6351                 check_file_in_pool $file
6352                 if [[ $? != 0 ]]; then
6353                         failed=$(($failed + 1))
6354                 fi
6355         done
6356         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
6357 }
6358 run_test 200f "Create files in a pool ==================================="
6359
6360 test_200g() {
6361         test_pools || return 0
6362
6363         TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
6364         res=$($LFS df --pool $FSNAME.$POOL | awk '{print $1}' | grep "$FSNAME-OST")
6365         [ "$res" = "$TGT" ] || error "Pools OSTS '$TGT' is not '$res' that lfs df reports"
6366 }
6367 run_test 200g "lfs df a pool ============================================"
6368
6369 test_201a() {
6370         test_pools || return 0
6371
6372         TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
6373         do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
6374         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | grep $TGT" "" || error "$TGT not removed from $FSNAME.$POOL"
6375 }
6376 run_test 201a "Remove a target from a pool ============================="
6377
6378 test_201b() {
6379         test_pools || return 0
6380
6381         for TGT in $($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | sort -u)
6382         do
6383                 do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
6384         done
6385         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL" ""\
6386             || error "Pool $FSNAME.$POOL cannot be drained"
6387         # striping on an empty/nonexistant pool should fall back to "pool of everything"
6388         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for empty pool"
6389         # setstripe on an empty pool should fail
6390         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
6391                 error "expected failure when creating file with empty pool"
6392         return 0
6393 }
6394 run_test 201b "Remove all targets from a pool =========================="
6395
6396 test_201c() {
6397         test_pools || return 0
6398
6399         do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
6400         
6401         sleep 2                        
6402     # striping on an empty/nonexistant pool should fall back to "pool of everything"
6403         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for missing pool"
6404         # setstripe on an empty pool should fail
6405         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
6406                 error "expected failure when creating file with missing pool"
6407
6408         # get param should return err once pool is gone
6409         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "foo" && unset CLEANUP_200 && trap 0 && return 0
6410         error "Pool $FSNAME.$POOL is not destroyed"
6411 }
6412 run_test 201c "Remove a pool ============================================"
6413
6414 [ "$CLEANUP_200" ] && cleanup_200
6415
6416 test_202() {
6417         $LFS setstripe -c 2 -s 1048576 $DIR/$tfile
6418         multiop $DIR/$tfile oO_WRONLY:O_APPEND:O_DIRECT:b1048548b130c || \
6419                 error "direct write failed"
6420         multiop $DIR/${tfile}2 oO_WRONLY:O_CREAT:w1048548w130c || \
6421                 error "cached write failed"
6422         cmp $DIR/$tfile $DIR/${tfile}2 || error "cmp failed"
6423         rm -f $DIR/${tfile}2
6424 }
6425 run_test 202 "O_APPEND+O_DIRECT multistripe write ========================"
6426
6427 #
6428 # tests that do cleanup/setup should be run at the end
6429 #
6430
6431 test_900() {
6432         local ls
6433         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
6434         $LCTL set_param fail_loc=0x903
6435         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
6436         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
6437                 echo "clear" > $ls
6438         done
6439         FAIL_ON_ERROR=true cleanup
6440         FAIL_ON_ERROR=true setup
6441 }
6442 run_test 900 "umount should not race with any mgc requeue thread"
6443
6444 log "cleanup: ======================================================"
6445 check_and_cleanup_lustre
6446 if [ "$I_MOUNTED" != "yes" ]; then
6447         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
6448 fi
6449
6450 echo '=========================== finished ==============================='
6451 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
6452 echo "$0: completed"