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