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