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