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