Whamcloud - gitweb
b=19781
[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 # osc's keep a NOSPC stick flag that gets unset with rmdir
945 reset_enospc() {
946         local FAIL_LOC=${1:-0}
947         local OSTIDX=${2:-""}
948
949         mkdir -p $DIR/d27/nospc
950         rmdir $DIR/d27/nospc
951         local list=$(comma_list $(osts_nodes))
952         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
953
954         do_nodes $list lctl set_param fail_loc=$FAIL_LOC
955 }
956
957 exhaust_precreations() {
958         local OSTIDX=$1
959
960         local OST=$(lfs osts | grep ${OSTIDX}": " | \
961                 awk '{print $2}' | sed -e 's/_UUID$//')
962
963         # on the mdt's osc
964         local mdtosc=$(get_mdtosc_proc_path $OST)
965         local last_id=$(do_facet mds lctl get_param -n osc.$mdtosc.prealloc_last_id)
966         local next_id=$(do_facet mds lctl get_param -n osc.$mdtosc.prealloc_next_id)
967
968         mkdir -p $DIR/d27/${OST}
969         $SETSTRIPE $DIR/d27/${OST} -i $OSTIDX -c 1
970         #define OBD_FAIL_OST_ENOSPC 0x215
971         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
972         echo "Creating to objid $last_id on ost $OST..."
973         createmany -o $DIR/d27/${OST}/f $next_id $((last_id - next_id + 2))
974         do_facet mds "lctl get_param -n osc.$mdtosc.prealloc*" | grep '[0-9]'
975         reset_enospc $2 $OSTIDX
976 }
977
978 exhaust_all_precreations() {
979         local i
980         for (( i=0; i < OSTCOUNT; i++ )) ; do
981                 exhaust_precreations $i 0x215
982         done
983         reset_enospc $1
984 }
985
986 test_27n() {
987         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
988         remote_mds_nodsh && skip "remote MDS with nodsh" && return
989         remote_ost_nodsh && skip "remote OST with nodsh" && return
990
991         reset_enospc
992         rm -f $DIR/d27/f27n
993         exhaust_precreations 0 0x80000215
994         $SETSTRIPE -c -1 $DIR/d27
995         touch $DIR/d27/f27n || error
996         $GETSTRIPE $DIR/d27/f27n
997         reset_enospc
998 }
999 run_test 27n "create file with some full OSTs =================="
1000
1001 test_27o() {
1002         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1003         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1004         remote_ost_nodsh && skip "remote OST with nodsh" && return
1005
1006         reset_enospc
1007         rm -f $DIR/d27/f27o
1008         exhaust_all_precreations 0x215
1009         sleep 5
1010
1011         touch $DIR/d27/f27o && error "able to create $DIR/d27/f27o"
1012
1013         reset_enospc
1014 }
1015 run_test 27o "create file with all full OSTs (should error) ===="
1016
1017 test_27p() {
1018         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1019         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1020         remote_ost_nodsh && skip "remote OST with nodsh" && return
1021
1022         reset_enospc
1023         rm -f $DIR/d27/f27p
1024
1025         $MCREATE $DIR/d27/f27p || error
1026         $TRUNCATE $DIR/d27/f27p 80000000 || error
1027         $CHECKSTAT -s 80000000 $DIR/d27/f27p || error
1028
1029         exhaust_precreations 0 0x80000215
1030         echo foo >> $DIR/d27/f27p || error
1031         $CHECKSTAT -s 80000004 $DIR/d27/f27p || error
1032
1033         reset_enospc
1034 }
1035 run_test 27p "append to a truncated file with some full OSTs ==="
1036
1037 test_27q() {
1038         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1039         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1040         remote_ost_nodsh && skip "remote OST with nodsh" && return
1041
1042         reset_enospc
1043         rm -f $DIR/d27/f27q
1044
1045         $MCREATE $DIR/d27/f27q || error "mcreate $DIR/d27/f27q failed"
1046         $TRUNCATE $DIR/d27/f27q 80000000 ||error "truncate $DIR/d27/f27q failed"
1047         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat failed"
1048
1049         exhaust_all_precreations 0x215
1050
1051         echo foo >> $DIR/d27/f27q && error "append succeeded"
1052         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat 2 failed"
1053
1054         reset_enospc
1055 }
1056 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1057
1058 test_27r() {
1059         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1060         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1061         remote_ost_nodsh && skip "remote OST with nodsh" && return
1062
1063         reset_enospc
1064         rm -f $DIR/d27/f27r
1065         exhaust_precreations 0 0x80000215
1066
1067         $SETSTRIPE $DIR/d27/f27r -i 0 -c 2 # && error
1068
1069         reset_enospc
1070 }
1071 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1072
1073 test_27s() { # bug 10725
1074         mkdir -p $DIR/$tdir
1075         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1076         local stripe_count=0
1077         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1078         $SETSTRIPE $DIR/$tdir -s $stripe_size -c $stripe_count && \
1079                 error "stripe width >= 2^32 succeeded" || true
1080 }
1081 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1082
1083 test_27t() { # bug 10864
1084         WDIR=`pwd`
1085         WLFS=`which lfs`
1086         cd $DIR
1087         touch $tfile
1088         $WLFS getstripe $tfile
1089         cd $WDIR
1090 }
1091 run_test 27t "check that utils parse path correctly"
1092
1093 test_27u() { # bug 4900
1094         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1095         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1096
1097         #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1098
1099         do_facet mds lctl set_param fail_loc=0x139
1100         mkdir -p $DIR/d27u
1101         createmany -o $DIR/d27u/t- 1000
1102         do_facet mds lctl set_param fail_loc=0
1103
1104         TLOG=$DIR/$tfile.getstripe
1105         $GETSTRIPE $DIR/d27u > $TLOG
1106         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1107         unlinkmany $DIR/d27u/t- 1000
1108         [ $OBJS -gt 0 ] && \
1109                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1110 }
1111 run_test 27u "skip object creation on OSC w/o objects =========="
1112
1113 test_27v() { # bug 4900
1114         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1115         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1116         remote_ost_nodsh && skip "remote OST with nodsh" && return
1117
1118         exhaust_all_precreations
1119
1120         mkdir -p $DIR/$tdir
1121         $SETSTRIPE $DIR/$tdir -c 1         # 1 stripe / file
1122
1123         touch $DIR/$tdir/$tfile
1124         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1125         # all except ost1
1126         for (( i=0; i < OSTCOUNT; i++ )) ; do
1127                 do_facet ost$i lctl set_param fail_loc=0x705
1128         done
1129         local START=`date +%s`
1130         createmany -o $DIR/$tdir/$tfile 32
1131
1132         reset_enospc
1133
1134         local FINISH=`date +%s`
1135         local TIMEOUT=`lctl get_param -n timeout`
1136         [ $((FINISH - START)) -ge $((TIMEOUT / 2)) ] && \
1137                error "$FINISH - $START >= $TIMEOUT / 2"
1138
1139         reset_enospc
1140 }
1141 run_test 27v "skip object creation on slow OST ================="
1142
1143 test_27w() { # bug 10997
1144         mkdir -p $DIR/d27w || error "mkdir failed"
1145         $SETSTRIPE $DIR/d27w/f0 -s 65536 || error "lstripe failed"
1146         size=`$GETSTRIPE $DIR/d27w/f0 -qs`
1147         [ $size -ne 65536 ] && error "stripe size $size != 65536" || true
1148
1149         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping multiple stripe count/offset test" && return
1150         for i in `seq 1 $OSTCOUNT`; do
1151                 offset=$(($i-1))
1152                 log setstripe $DIR/d27w/f$i -c $i -i $offset
1153                 $SETSTRIPE $DIR/d27w/f$i -c $i -i $offset || error "lstripe -c $i -i $offset failed"
1154                 count=`$GETSTRIPE -qc $DIR/d27w/f$i`
1155                 index=`$GETSTRIPE -qo $DIR/d27w/f$i`
1156                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1157                 [ $index -ne $offset ] && error "stripe offset $index != $offset" || true
1158         done
1159 }
1160 run_test 27w "check lfs setstripe -c -s -i options ============="
1161
1162 test_27x() {
1163         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1164         DELAY=$(do_facet mds lctl get_param -n lov.*.qos_maxage | awk '{print $1 + 2}')
1165         OFFSET=$(($OSTCOUNTi - 1))
1166         OSTIDX=0
1167         local OST=$(lfs osts | awk '/'${OSTIDX}': / { print $2 }' | sed -e 's/_UUID$//')
1168
1169         mkdir -p $DIR/$tdir
1170         $SETSTRIPE $DIR/$tdir -c 1      # 1 stripe per file
1171         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 1
1172         sleep $DELAY
1173         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1174         for i in `seq 0 $OFFSET`; do
1175                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1176                 error "OST0 was degraded but new created file still use it"
1177         done
1178         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 0
1179 }
1180 run_test 27x "create files while OST0 is degraded"
1181
1182 test_27y() {
1183         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1184         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1185
1186         MDS_OSCS=`do_facet mds lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
1187         DELAY=$(do_facet mds lctl get_param -n lov.*.qos_maxage | awk '{print $1 + 2}')
1188         OFFSET=$(($OSTCOUNT-1))
1189         OST=-1
1190         for OSC in $MDS_OSCS; do
1191                 if [ $OST == -1 ]; then {
1192                         OST=`osc_to_ost $OSC`
1193                 } else {
1194                         echo $OSC "is Deactivate:"
1195                         do_facet mds lctl --device  %$OSC deactivate
1196                 } fi
1197         done
1198
1199         OSTIDX=$(lfs osts | grep ${OST} | awk '{print $1}' | sed -e 's/://')
1200         mkdir -p $DIR/$tdir
1201         $SETSTRIPE $DIR/$tdir -c 1      # 1 stripe / file
1202
1203         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 1
1204         sleep $DELAY
1205         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1206         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 0
1207
1208         for i in `seq 0 $OFFSET`; do
1209                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "$OSTIDX"` ] || \
1210                       error "files created on deactivated OSTs instead of degraded OST"
1211         done
1212         for OSC in $MDS_OSCS; do
1213                 [ `osc_to_ost $OSC` != $OST  ] && {
1214                         echo $OSC "is activate"
1215                         do_facet mds lctl --device %$OSC activate
1216                 }
1217         done
1218 }
1219 run_test 27y "create files while OST0 is degraded and the rest inactive"
1220
1221 # createtest also checks that device nodes are created and
1222 # then visible correctly (#2091)
1223 test_28() { # bug 2091
1224         mkdir $DIR/d28
1225         $CREATETEST $DIR/d28/ct || error
1226 }
1227 run_test 28 "create/mknod/mkdir with bad file types ============"
1228
1229 test_29() {
1230         cancel_lru_locks mdc
1231         mkdir $DIR/d29
1232         touch $DIR/d29/foo
1233         log 'first d29'
1234         ls -l $DIR/d29
1235         LOCKCOUNTORIG=`lctl get_param -n ldlm.namespaces.*mdc*.lock_count`
1236         LOCKUNUSEDCOUNTORIG=`lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count`
1237         [ -z $"LOCKCOUNTORIG" ] && error "No mdc lock count" && return 1
1238         log 'second d29'
1239         ls -l $DIR/d29
1240         log 'done'
1241         LOCKCOUNTCURRENT=`lctl get_param -n ldlm.namespaces.*mdc*.lock_count`
1242         LOCKUNUSEDCOUNTCURRENT=`lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count`
1243         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1244                 lctl set_param -n ldlm.dump_namespaces ""
1245                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1246                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1247                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1248                 return 2
1249         fi
1250         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1251                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1252                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1253                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1254                 return 3
1255         fi
1256 }
1257 run_test 29 "IT_GETATTR regression  ============================"
1258
1259 test_30() {
1260         cp `which ls` $DIR
1261         $DIR/ls /
1262         rm $DIR/ls
1263 }
1264 run_test 30 "run binary from Lustre (execve) ==================="
1265
1266 test_31a() {
1267         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1268         $CHECKSTAT -a $DIR/f31 || error
1269 }
1270 run_test 31a "open-unlink file =================================="
1271
1272 test_31b() {
1273         touch $DIR/f31 || error
1274         ln $DIR/f31 $DIR/f31b || error
1275         multiop $DIR/f31b Ouc || error
1276         $CHECKSTAT -t file $DIR/f31 || error
1277 }
1278 run_test 31b "unlink file with multiple links while open ======="
1279
1280 test_31c() {
1281         touch $DIR/f31 || error
1282         ln $DIR/f31 $DIR/f31c || error
1283         multiop_bg_pause $DIR/f31 O_uc || return 1
1284         MULTIPID=$!
1285         multiop $DIR/f31c Ouc
1286         kill -USR1 $MULTIPID
1287         wait $MULTIPID
1288 }
1289 run_test 31c "open-unlink file with multiple links ============="
1290
1291 test_31d() {
1292         opendirunlink $DIR/d31d $DIR/d31d || error
1293         $CHECKSTAT -a $DIR/d31d || error
1294 }
1295 run_test 31d "remove of open directory ========================="
1296
1297 test_31e() { # bug 2904
1298         check_kernel_version 34 || return 0
1299         openfilleddirunlink $DIR/d31e || error
1300 }
1301 run_test 31e "remove of open non-empty directory ==============="
1302
1303 test_31f() { # bug 4554
1304         set -vx
1305         mkdir $DIR/d31f
1306         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1307         cp /etc/hosts $DIR/d31f
1308         ls -l $DIR/d31f
1309         $GETSTRIPE $DIR/d31f/hosts
1310         multiop_bg_pause $DIR/d31f D_c || return 1
1311         MULTIPID=$!
1312
1313         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1314         mkdir $DIR/d31f
1315         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1316         cp /etc/hosts $DIR/d31f
1317         ls -l $DIR/d31f
1318         $DIR/d31f/hosts
1319         multiop_bg_pause $DIR/d31f D_c || return 1
1320         MULTIPID2=$!
1321
1322         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1323         wait $MULTIPID || error "first opendir $MULTIPID failed"
1324
1325         sleep 6
1326
1327         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1328         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1329         set +vx
1330 }
1331 run_test 31f "remove of open directory with open-unlink file ==="
1332
1333 test_32a() {
1334         echo "== more mountpoints and symlinks ================="
1335         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1336         mkdir -p $DIR/d32a/ext2-mountpoint
1337         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1338         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error
1339         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1340 }
1341 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1342
1343 test_32b() {
1344         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1345         mkdir -p $DIR/d32b/ext2-mountpoint
1346         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1347         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1348         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1349 }
1350 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1351
1352 test_32c() {
1353         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1354         mkdir -p $DIR/d32c/ext2-mountpoint
1355         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1356         mkdir -p $DIR/d32c/d2/test_dir
1357         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1358         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1359 }
1360 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1361
1362 test_32d() {
1363         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1364         mkdir -p $DIR/d32d/ext2-mountpoint
1365         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1366         mkdir -p $DIR/d32d/d2/test_dir
1367         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1368         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1369 }
1370 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1371
1372 test_32e() {
1373         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1374         mkdir -p $DIR/d32e/tmp
1375         TMP_DIR=$DIR/d32e/tmp
1376         ln -s $DIR/d32e $TMP_DIR/symlink11
1377         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1378         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1379         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1380 }
1381 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1382
1383 test_32f() {
1384         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1385         mkdir -p $DIR/d32f/tmp
1386         TMP_DIR=$DIR/d32f/tmp
1387         ln -s $DIR/d32f $TMP_DIR/symlink11
1388         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1389         ls $DIR/d32f/tmp/symlink11  || error
1390         ls $DIR/d32f/symlink01 || error
1391 }
1392 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1393
1394 test_32g() {
1395         TMP_DIR=$DIR/$tdir/tmp
1396         mkdir -p $TMP_DIR $DIR/${tdir}2
1397         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1398         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1399         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1400         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1401         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1402         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1403 }
1404 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1405
1406 test_32h() {
1407         rm -fr $DIR/$tdir $DIR/${tdir}2
1408         TMP_DIR=$DIR/$tdir/tmp
1409         mkdir -p $TMP_DIR $DIR/${tdir}2
1410         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1411         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1412         ls $TMP_DIR/symlink12 || error
1413         ls $DIR/$tdir/symlink02  || error
1414 }
1415 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1416
1417 test_32i() {
1418         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1419         mkdir -p $DIR/d32i/ext2-mountpoint
1420         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1421         touch $DIR/d32i/test_file
1422         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error
1423         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1424 }
1425 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1426
1427 test_32j() {
1428         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1429         mkdir -p $DIR/d32j/ext2-mountpoint
1430         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1431         touch $DIR/d32j/test_file
1432         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1433         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1434 }
1435 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1436
1437 test_32k() {
1438         rm -fr $DIR/d32k
1439         mkdir -p $DIR/d32k/ext2-mountpoint
1440         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint
1441         mkdir -p $DIR/d32k/d2
1442         touch $DIR/d32k/d2/test_file || error
1443         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1444         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1445 }
1446 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1447
1448 test_32l() {
1449         rm -fr $DIR/d32l
1450         mkdir -p $DIR/d32l/ext2-mountpoint
1451         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1452         mkdir -p $DIR/d32l/d2
1453         touch $DIR/d32l/d2/test_file
1454         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1455         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1456 }
1457 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1458
1459 test_32m() {
1460         rm -fr $DIR/d32m
1461         mkdir -p $DIR/d32m/tmp
1462         TMP_DIR=$DIR/d32m/tmp
1463         ln -s $DIR $TMP_DIR/symlink11
1464         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1465         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1466         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1467 }
1468 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1469
1470 test_32n() {
1471         rm -fr $DIR/d32n
1472         mkdir -p $DIR/d32n/tmp
1473         TMP_DIR=$DIR/d32n/tmp
1474         ln -s $DIR $TMP_DIR/symlink11
1475         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1476         ls -l $DIR/d32n/tmp/symlink11  || error
1477         ls -l $DIR/d32n/symlink01 || error
1478 }
1479 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1480
1481 test_32o() {
1482         rm -fr $DIR/d32o $DIR/$tfile
1483         touch $DIR/$tfile
1484         mkdir -p $DIR/d32o/tmp
1485         TMP_DIR=$DIR/d32o/tmp
1486         ln -s $DIR/$tfile $TMP_DIR/symlink12
1487         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1488         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1489         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1490         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1491         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1492 }
1493 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1494
1495 test_32p() {
1496     log 32p_1
1497         rm -fr $DIR/d32p
1498     log 32p_2
1499         rm -f $DIR/$tfile
1500     log 32p_3
1501         touch $DIR/$tfile
1502     log 32p_4
1503         mkdir -p $DIR/d32p/tmp
1504     log 32p_5
1505         TMP_DIR=$DIR/d32p/tmp
1506     log 32p_6
1507         ln -s $DIR/$tfile $TMP_DIR/symlink12
1508     log 32p_7
1509         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1510     log 32p_8
1511         cat $DIR/d32p/tmp/symlink12 || error
1512     log 32p_9
1513         cat $DIR/d32p/symlink02 || error
1514     log 32p_10
1515 }
1516 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1517
1518 test_32q() {
1519         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1520         mkdir -p $DIR/d32q
1521         touch $DIR/d32q/under_the_mount
1522         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1523         ls $DIR/d32q/under_the_mount && error || true
1524         $UMOUNT $DIR/d32q || error
1525 }
1526 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1527
1528 test_32r() {
1529         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1530         mkdir -p $DIR/d32r
1531         touch $DIR/d32r/under_the_mount
1532         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1533         ls $DIR/d32r | grep -q under_the_mount && error || true
1534         $UMOUNT $DIR/d32r || error
1535 }
1536 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1537
1538 test_33() {
1539         rm -f $DIR/$tfile
1540         touch $DIR/$tfile
1541         chmod 444 $DIR/$tfile
1542         chown $RUNAS_ID $DIR/$tfile
1543         log 33_1
1544         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1545         log 33_2
1546 }
1547 run_test 33 "write file with mode 444 (should return error) ===="
1548
1549 test_33a() {
1550         rm -fr $DIR/d33
1551         mkdir -p $DIR/d33
1552         chown $RUNAS_ID $DIR/d33
1553         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1554         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1555                 error "open RDWR" || true
1556 }
1557 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1558
1559 test_33b() {
1560         rm -fr $DIR/d33
1561         mkdir -p $DIR/d33
1562         chown $RUNAS_ID $DIR/d33
1563         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
1564 }
1565 run_test 33b "test open file with malformed flags (No panic)"
1566
1567 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1568 test_34a() {
1569         rm -f $DIR/f34
1570         $MCREATE $DIR/f34 || error
1571         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1572         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1573         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1574         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1575 }
1576 run_test 34a "truncate file that has not been opened ==========="
1577
1578 test_34b() {
1579         [ ! -f $DIR/f34 ] && test_34a
1580         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1581         $OPENFILE -f O_RDONLY $DIR/f34
1582         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1583         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1584 }
1585 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1586
1587 test_34c() {
1588         [ ! -f $DIR/f34 ] && test_34a
1589         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1590         $OPENFILE -f O_RDWR $DIR/f34
1591         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
1592         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1593 }
1594 run_test 34c "O_RDWR opening file-with-size works =============="
1595
1596 test_34d() {
1597         [ ! -f $DIR/f34 ] && test_34a
1598         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1599         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1600         rm $DIR/f34
1601 }
1602 run_test 34d "write to sparse file ============================="
1603
1604 test_34e() {
1605         rm -f $DIR/f34e
1606         $MCREATE $DIR/f34e || error
1607         $TRUNCATE $DIR/f34e 1000 || error
1608         $CHECKSTAT -s 1000 $DIR/f34e || error
1609         $OPENFILE -f O_RDWR $DIR/f34e
1610         $CHECKSTAT -s 1000 $DIR/f34e || error
1611 }
1612 run_test 34e "create objects, some with size and some without =="
1613
1614 test_34f() { # bug 6242, 6243
1615         SIZE34F=48000
1616         rm -f $DIR/f34f
1617         $MCREATE $DIR/f34f || error
1618         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
1619         dd if=$DIR/f34f of=$TMP/f34f
1620         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
1621         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
1622         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
1623         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
1624         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
1625 }
1626 run_test 34f "read from a file with no objects until EOF ======="
1627
1628 test_35a() {
1629         cp /bin/sh $DIR/f35a
1630         chmod 444 $DIR/f35a
1631         chown $RUNAS_ID $DIR/f35a
1632         $RUNAS $DIR/f35a && error || true
1633         rm $DIR/f35a
1634 }
1635 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1636
1637 test_36a() {
1638         rm -f $DIR/f36
1639         utime $DIR/f36 || error
1640 }
1641 run_test 36a "MDS utime check (mknod, utime) ==================="
1642
1643 test_36b() {
1644         echo "" > $DIR/f36
1645         utime $DIR/f36 || error
1646 }
1647 run_test 36b "OST utime check (open, utime) ===================="
1648
1649 test_36c() {
1650         rm -f $DIR/d36/f36
1651         mkdir $DIR/d36
1652         chown $RUNAS_ID $DIR/d36
1653         $RUNAS utime $DIR/d36/f36 || error
1654 }
1655 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1656
1657 test_36d() {
1658         [ ! -d $DIR/d36 ] && test_36c
1659         echo "" > $DIR/d36/f36
1660         $RUNAS utime $DIR/d36/f36 || error
1661 }
1662 run_test 36d "non-root OST utime check (open, utime) ==========="
1663
1664 test_36e() {
1665         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
1666         mkdir -p $DIR/$tdir
1667         touch $DIR/$tdir/$tfile
1668         $RUNAS utime $DIR/$tdir/$tfile && \
1669                 error "utime worked, expected failure" || true
1670 }
1671 run_test 36e "utime on non-owned file (should return error) ===="
1672
1673 test_36f() {
1674         export LANG=C LC_LANG=C # for date language
1675
1676         DATESTR="Dec 20  2000"
1677         mkdir -p $DIR/$tdir
1678         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1679         lctl set_param fail_loc=0x80000214
1680         date; date +%s
1681         cp /etc/hosts $DIR/$tdir/$tfile
1682         sync & # write RPC generated with "current" inode timestamp, but delayed
1683         sleep 1
1684         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
1685         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
1686         cancel_lru_locks osc
1687         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
1688         date; date +%s
1689         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
1690                 echo "BEFORE: $LS_BEFORE" && \
1691                 echo "AFTER : $LS_AFTER" && \
1692                 echo "WANT  : $DATESTR" && \
1693                 error "$DIR/$tdir/$tfile timestamps changed" || true
1694 }
1695 run_test 36f "utime on file racing with OST BRW write =========="
1696
1697 test_36g() {
1698         remote_ost_nodsh && skip "remote OST with nodsh" && return
1699
1700         mkdir -p $DIR/$tdir
1701         export FMD_MAX_AGE=`do_facet ost1 lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | head -n 1`
1702         FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1703         touch $DIR/$tdir/$tfile
1704         sleep $((FMD_MAX_AGE + 12))
1705         FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1706         [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
1707                 echo "AFTER : $FMD_AFTER > BEFORE $FMD_BEFORE" && \
1708                 error "fmd didn't expire after ping" || true
1709 }
1710 run_test 36g "filter mod data cache expiry ====================="
1711
1712 test_37() {
1713         mkdir -p $DIR/$tdir
1714         echo f > $DIR/$tdir/fbugfile
1715         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
1716         ls $DIR/$tdir | grep "\<fbugfile\>" && error
1717         $UMOUNT $DIR/$tdir || error
1718         rm -f $DIR/$tdir/fbugfile || error
1719 }
1720 run_test 37 "ls a mounted file system to check old content ====="
1721
1722 test_38() {
1723         local file=$DIR/$tfile
1724         touch $file
1725         openfile -f O_DIRECTORY $file
1726         local RC=$?
1727         local ENOTDIR=20
1728         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
1729         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
1730 }
1731 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
1732
1733 test_39() {
1734         touch $DIR/$tfile
1735         touch $DIR/${tfile}2
1736 #       ls -l  $DIR/$tfile $DIR/${tfile}2
1737 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
1738 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
1739         sleep 2
1740         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
1741         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
1742                 echo "mtime"
1743                 ls -l  $DIR/$tfile $DIR/${tfile}2
1744                 echo "atime"
1745                 ls -lu  $DIR/$tfile $DIR/${tfile}2
1746                 echo "ctime"
1747                 ls -lc  $DIR/$tfile $DIR/${tfile}2
1748                 error "O_TRUNC didn't change timestamps"
1749         fi
1750 }
1751 run_test 39 "mtime changed on create ==========================="
1752
1753 function get_times() {
1754         FILE=$1
1755         TIME=$2
1756
1757         i=0
1758         for time in `stat -c "%X %Y %Z" $FILE`; do
1759                 eval "$TIME[$i]=$time"
1760                 i=$(($i + 1))
1761         done
1762 }
1763
1764 test_39b() {
1765         ATIME=0
1766         MTIME=1
1767         CTIME=2
1768         mkdir -p $DIR/$tdir
1769         cp -p /etc/passwd $DIR/$tdir/fopen
1770         cp -p /etc/passwd $DIR/$tdir/flink
1771         cp -p /etc/passwd $DIR/$tdir/funlink
1772         cp -p /etc/passwd $DIR/$tdir/frename
1773         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
1774
1775         get_times $DIR/$tdir/fopen OPEN_OLD
1776         get_times $DIR/$tdir/flink LINK_OLD
1777         get_times $DIR/$tdir/funlink UNLINK_OLD
1778         get_times $DIR/$tdir/frename RENAME_OLD
1779
1780         sleep 1
1781         echo "aaaaaa" >> $DIR/$tdir/fopen
1782         echo "aaaaaa" >> $DIR/$tdir/flink
1783         echo "aaaaaa" >> $DIR/$tdir/funlink
1784         echo "aaaaaa" >> $DIR/$tdir/frename
1785
1786         get_times $DIR/$tdir/fopen OPEN_NEW
1787         get_times $DIR/$tdir/flink LINK_NEW
1788         get_times $DIR/$tdir/funlink UNLINK_NEW
1789         get_times $DIR/$tdir/frename RENAME_NEW
1790
1791         cat $DIR/$tdir/fopen > /dev/null
1792         ln $DIR/$tdir/flink $DIR/$tdir/flink2
1793         rm -f $DIR/$tdir/funlink2
1794         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
1795
1796         get_times $DIR/$tdir/fopen OPEN_NEW2
1797         get_times $DIR/$tdir/flink LINK_NEW2
1798         get_times $DIR/$tdir/funlink UNLINK_NEW2
1799         get_times $DIR/$tdir/frename2 RENAME_NEW2
1800         echo ${OPEN_OLD[1]},${OPEN_NEW[$MTIME]},${OPEN_NEW2[$MTIME]}
1801         echo ${LINK_OLD[1]},${LINK_NEW[$MTIME]},${LINK_NEW2[$MTIME]}
1802         echo ${UNLINK_OLD[1]},${UNLINK_NEW[$MTIME]},${UNLINK_NEW2[$MTIME]}
1803         echo ${RENAME_OLD[1]},${RENAME_NEW[$MTIME]},${RENAME_NEW2[$MTIME]}
1804
1805         [ ${OPEN_NEW2[$MTIME]} -eq ${OPEN_NEW[$MTIME]} ] || error "open file reverses mtime"
1806         [ ${LINK_NEW2[$MTIME]} -eq ${LINK_NEW[$MTIME]} ] || error "link file reverses mtime"
1807         [ ${UNLINK_NEW2[$MTIME]} -eq ${UNLINK_NEW[$MTIME]} ] || error "unlink file reverses mtime"
1808         [ ${RENAME_NEW2[$MTIME]} -eq ${RENAME_NEW[$MTIME]} ] || error "rename file reverses mtime"
1809 }
1810 run_test 39b "mtime change on close ============================"
1811
1812 # bug 11063
1813 test_39c() {
1814         touch -m -d "10 years ago" $DIR1/$tfile
1815         local MTIME1=`stat -c %y $DIR1/$tfile`
1816         echo hello >> $DIR1/$tfile
1817         local MTIME2=`stat -c %y $DIR1/$tfile`
1818         mv $DIR1/$tfile $DIR1/$tfile-1
1819         local MTIME3=`stat -c %y $DIR1/$tfile-1`
1820         [ "$MTIME2" = "$MTIME3" ] ||
1821                 error "mtime ($MTIME2) changed (to $MTIME3) on rename (BZ#11063)"
1822 }
1823 run_test 39c "mtime change on rename ==========================="
1824
1825 test_40() {
1826         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1827         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1828         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1829 }
1830 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1831
1832 test_41() {
1833         # bug 1553
1834         small_write $DIR/f41 18
1835 }
1836 run_test 41 "test small file write + fstat ====================="
1837
1838 count_ost_writes() {
1839         lctl get_param -n osc.*.stats |
1840             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1841 }
1842
1843 # decent default
1844 WRITEBACK_SAVE=500
1845 DIRTY_RATIO_SAVE=40
1846 MAX_DIRTY_RATIO=50
1847 BG_DIRTY_RATIO_SAVE=10
1848 MAX_BG_DIRTY_RATIO=25
1849
1850 start_writeback() {
1851         trap 0
1852         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
1853         # dirty_ratio, dirty_background_ratio
1854         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1855                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
1856                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
1857                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
1858         else
1859                 # if file not here, we are a 2.4 kernel
1860                 kill -CONT `pidof kupdated`
1861         fi
1862 }
1863
1864 stop_writeback() {
1865         # setup the trap first, so someone cannot exit the test at the
1866         # exact wrong time and mess up a machine
1867         trap start_writeback EXIT
1868         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1869         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1870                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
1871                 sysctl -w vm.dirty_writeback_centisecs=0
1872                 # save and increase /proc/sys/vm/dirty_ratio
1873                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
1874                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
1875                 # save and increase /proc/sys/vm/dirty_background_ratio
1876                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
1877                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
1878         else
1879                 # if file not here, we are a 2.4 kernel
1880                 kill -STOP `pidof kupdated`
1881         fi
1882 }
1883
1884 # ensure that all stripes have some grant before we test client-side cache
1885 setup_test42() {
1886         [ "$SETUP_TEST42" ] && return
1887         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1888                 dd if=/dev/zero of=$i bs=4k count=1
1889                 rm $i
1890         done
1891         SETUP_TEST42=DONE
1892 }
1893
1894 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1895 # file truncation, and file removal.
1896 test_42a() {
1897         setup_test42
1898         cancel_lru_locks osc
1899         stop_writeback
1900         sync; sleep 1; sync # just to be safe
1901         BEFOREWRITES=`count_ost_writes`
1902         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
1903         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1904         AFTERWRITES=`count_ost_writes`
1905         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1906                 error "$BEFOREWRITES < $AFTERWRITES"
1907         start_writeback
1908 }
1909 run_test 42a "ensure that we don't flush on close =============="
1910
1911 test_42b() {
1912         setup_test42
1913         cancel_lru_locks osc
1914         stop_writeback
1915         sync
1916         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1917         BEFOREWRITES=`count_ost_writes`
1918         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1919         AFTERWRITES=`count_ost_writes`
1920         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1921                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
1922         fi
1923         BEFOREWRITES=`count_ost_writes`
1924         sync || error "sync: $?"
1925         AFTERWRITES=`count_ost_writes`
1926         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1927                 error "$BEFOREWRITES < $AFTERWRITES on sync"
1928         fi
1929         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1930         start_writeback
1931         return 0
1932 }
1933 run_test 42b "test destroy of file with cached dirty data ======"
1934
1935 # if these tests just want to test the effect of truncation,
1936 # they have to be very careful.  consider:
1937 # - the first open gets a {0,EOF}PR lock
1938 # - the first write conflicts and gets a {0, count-1}PW
1939 # - the rest of the writes are under {count,EOF}PW
1940 # - the open for truncate tries to match a {0,EOF}PR
1941 #   for the filesize and cancels the PWs.
1942 # any number of fixes (don't get {0,EOF} on open, match
1943 # composite locks, do smarter file size management) fix
1944 # this, but for now we want these tests to verify that
1945 # the cancellation with truncate intent works, so we
1946 # start the file with a full-file pw lock to match against
1947 # until the truncate.
1948 trunc_test() {
1949         test=$1
1950         file=$DIR/$test
1951         offset=$2
1952         cancel_lru_locks osc
1953         stop_writeback
1954         # prime the file with 0,EOF PW to match
1955         touch $file
1956         $TRUNCATE $file 0
1957         sync; sync
1958         # now the real test..
1959         dd if=/dev/zero of=$file bs=1024 count=100
1960         BEFOREWRITES=`count_ost_writes`
1961         $TRUNCATE $file $offset
1962         cancel_lru_locks osc
1963         AFTERWRITES=`count_ost_writes`
1964         start_writeback
1965 }
1966
1967 test_42c() {
1968         trunc_test 42c 1024
1969         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1970             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
1971         rm $file
1972 }
1973 run_test 42c "test partial truncate of file with cached dirty data"
1974
1975 test_42d() {
1976         trunc_test 42d 0
1977         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1978             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1979         rm $file
1980 }
1981 run_test 42d "test complete truncate of file with cached dirty data"
1982
1983 test_43() {
1984         mkdir -p $DIR/$tdir
1985         cp -p /bin/ls $DIR/$tdir/$tfile
1986         multiop $DIR/$tdir/$tfile Ow_c &
1987         pid=$!
1988         # give multiop a chance to open
1989         sleep 1
1990
1991         $DIR/$tdir/$tfile && error || true
1992         kill -USR1 $pid
1993 }
1994 run_test 43 "execution of file opened for write should return -ETXTBSY"
1995
1996 test_43a() {
1997         mkdir -p $DIR/d43
1998         cp -p `which multiop` $DIR/d43/multiop
1999         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2000         MULTIOP_PID=$!
2001         multiop $DIR/d43/multiop Oc && error "expected error, got success"
2002         kill -USR1 $MULTIOP_PID || return 2
2003         wait $MULTIOP_PID || return 3
2004         rm $TMP/test43.junk
2005 }
2006 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
2007
2008 test_43b() {
2009         mkdir -p $DIR/d43
2010         cp -p `which multiop` $DIR/d43/multiop
2011         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2012         MULTIOP_PID=$!
2013         truncate $DIR/d43/multiop 0 && error "expected error, got success"
2014         kill -USR1 $MULTIOP_PID || return 2
2015         wait $MULTIOP_PID || return 3
2016         rm $TMP/test43.junk
2017 }
2018 run_test 43b "truncate of file being executed should return -ETXTBSY"
2019
2020 test_43c() {
2021         local testdir="$DIR/d43c"
2022         mkdir -p $testdir
2023         cp $SHELL $testdir/
2024         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
2025                 ( cd $testdir && md5sum -c)
2026 }
2027 run_test 43c "md5sum of copy into lustre========================"
2028
2029 test_44() {
2030         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
2031         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
2032         dd if=$DIR/f1 of=/dev/null bs=4k count=1
2033 }
2034 run_test 44 "zero length read from a sparse stripe ============="
2035
2036 test_44a() {
2037     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
2038                          awk '{print $2}'`
2039     [ -z "$nstripe" ] && skip "can't get stripe info" && return
2040     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
2041     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
2042                       awk '{print $2}'`
2043     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
2044         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
2045     fi
2046
2047     OFFSETS="0 $((stride/2)) $((stride-1))"
2048     for offset in $OFFSETS ; do
2049       for i in `seq 0 $((nstripe-1))`; do
2050         rm -f $DIR/d44a
2051         local GLOBALOFFSETS=""
2052         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
2053         ll_sparseness_write $DIR/d44a $size  || error "ll_sparseness_write"
2054         GLOBALOFFSETS="$GLOBALOFFSETS $size"
2055         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
2056                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2057
2058         for j in `seq 0 $((nstripe-1))`; do
2059             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
2060             ll_sparseness_write $DIR/d44a $size || error "ll_sparseness_write"
2061             GLOBALOFFSETS="$GLOBALOFFSETS $size"
2062         done
2063         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
2064                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2065       done
2066     done
2067 }
2068 run_test 44a "test sparse pwrite ==============================="
2069
2070 dirty_osc_total() {
2071         tot=0
2072         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
2073                 tot=$(($tot + d))
2074         done
2075         echo $tot
2076 }
2077 do_dirty_record() {
2078         before=`dirty_osc_total`
2079         echo executing "\"$*\""
2080         eval $*
2081         after=`dirty_osc_total`
2082         echo before $before, after $after
2083 }
2084 test_45() {
2085         f="$DIR/f45"
2086         # Obtain grants from OST if it supports it
2087         echo blah > ${f}_grant
2088         stop_writeback
2089         sync
2090         do_dirty_record "echo blah > $f"
2091         [ $before -eq $after ] && error "write wasn't cached"
2092         do_dirty_record "> $f"
2093         [ $before -gt $after ] || error "truncate didn't lower dirty count"
2094         do_dirty_record "echo blah > $f"
2095         [ $before -eq $after ] && error "write wasn't cached"
2096         do_dirty_record "sync"
2097         [ $before -gt $after ] || error "writeback didn't lower dirty count"
2098         do_dirty_record "echo blah > $f"
2099         [ $before -eq $after ] && error "write wasn't cached"
2100         do_dirty_record "cancel_lru_locks osc"
2101         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
2102         start_writeback
2103 }
2104 run_test 45 "osc io page accounting ============================"
2105
2106 page_size() {
2107         getconf PAGE_SIZE
2108 }
2109
2110 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
2111 # test tickles a bug where re-dirtying a page was failing to be mapped to the
2112 # objects offset and an assert hit when an rpc was built with 1023's mapped
2113 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
2114 test_46() {
2115         f="$DIR/f46"
2116         stop_writeback
2117         sync
2118         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2119         sync
2120         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
2121         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2122         sync
2123         start_writeback
2124 }
2125 run_test 46 "dirtying a previously written page ================"
2126
2127 # test_47 is removed "Device nodes check" is moved to test_28
2128
2129 test_48a() { # bug 2399
2130         check_kernel_version 34 || return 0
2131         mkdir -p $DIR/d48a
2132         cd $DIR/d48a
2133         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
2134         mkdir $DIR/d48a || error "recreate directory failed"
2135         touch foo || error "'touch foo' failed after recreating cwd"
2136         mkdir bar || error "'mkdir foo' failed after recreating cwd"
2137         if check_kernel_version 44; then
2138                 touch .foo || error "'touch .foo' failed after recreating cwd"
2139                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
2140         fi
2141         ls . > /dev/null || error "'ls .' failed after recreating cwd"
2142         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2143         cd . || error "'cd .' failed after recreating cwd"
2144         mkdir . && error "'mkdir .' worked after recreating cwd"
2145         rmdir . && error "'rmdir .' worked after recreating cwd"
2146         ln -s . baz || error "'ln -s .' failed after recreating cwd"
2147         cd .. || error "'cd ..' failed after recreating cwd"
2148 }
2149 run_test 48a "Access renamed working dir (should return errors)="
2150
2151 test_48b() { # bug 2399
2152         check_kernel_version 34 || return 0
2153         mkdir -p $DIR/d48b
2154         cd $DIR/d48b
2155         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
2156         touch foo && error "'touch foo' worked after removing cwd"
2157         mkdir foo && error "'mkdir foo' worked after removing cwd"
2158         if check_kernel_version 44; then
2159                 touch .foo && error "'touch .foo' worked after removing cwd"
2160                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2161         fi
2162         ls . > /dev/null && error "'ls .' worked after removing cwd"
2163         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2164         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
2165         mkdir . && error "'mkdir .' worked after removing cwd"
2166         rmdir . && error "'rmdir .' worked after removing cwd"
2167         ln -s . foo && error "'ln -s .' worked after removing cwd"
2168         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
2169 }
2170 run_test 48b "Access removed working dir (should return errors)="
2171
2172 test_48c() { # bug 2350
2173         check_kernel_version 36 || return 0
2174         #lctl set_param debug=-1
2175         #set -vx
2176         mkdir -p $DIR/d48c/dir
2177         cd $DIR/d48c/dir
2178         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
2179         $TRACE touch foo && error "'touch foo' worked after removing cwd"
2180         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
2181         if check_kernel_version 44; then
2182                 touch .foo && error "'touch .foo' worked after removing cwd"
2183                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2184         fi
2185         $TRACE ls . && error "'ls .' worked after removing cwd"
2186         $TRACE ls .. || error "'ls ..' failed after removing cwd"
2187         is_patchless || ( $TRACE cd . && error "'cd .' worked after removing cwd" )
2188         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
2189         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
2190         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
2191         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2192 }
2193 run_test 48c "Access removed working subdir (should return errors)"
2194
2195 test_48d() { # bug 2350
2196         check_kernel_version 36 || return 0
2197         #lctl set_param debug=-1
2198         #set -vx
2199         mkdir -p $DIR/d48d/dir
2200         cd $DIR/d48d/dir
2201         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2202         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
2203         $TRACE touch foo && error "'touch foo' worked after removing parent"
2204         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
2205         if check_kernel_version 44; then
2206                 touch .foo && error "'touch .foo' worked after removing parent"
2207                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
2208         fi
2209         $TRACE ls . && error "'ls .' worked after removing parent"
2210         $TRACE ls .. && error "'ls ..' worked after removing parent"
2211         is_patchless || ( $TRACE cd . && error "'cd .' worked after recreate parent" )
2212         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
2213         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
2214         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
2215         is_patchless || ( $TRACE cd .. && error "'cd ..' worked after removing parent" || true )
2216 }
2217 run_test 48d "Access removed parent subdir (should return errors)"
2218
2219 test_48e() { # bug 4134
2220         check_kernel_version 41 || return 0
2221         #lctl set_param debug=-1
2222         #set -vx
2223         mkdir -p $DIR/d48e/dir
2224         cd $DIR/d48e/dir
2225         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
2226         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
2227         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
2228         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
2229         # On a buggy kernel addition of "touch foo" after cd .. will
2230         # produce kernel oops in lookup_hash_it
2231         touch ../foo && error "'cd ..' worked after recreate parent"
2232         cd $DIR
2233         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
2234 }
2235 run_test 48e "Access to recreated parent subdir (should return errors)"
2236
2237 test_50() {
2238         # bug 1485
2239         mkdir $DIR/d50
2240         cd $DIR/d50
2241         ls /proc/$$/cwd || error
2242 }
2243 run_test 50 "special situations: /proc symlinks  ==============="
2244
2245 test_51a() {    # was test_51
2246         # bug 1516 - create an empty entry right after ".." then split dir
2247         mkdir $DIR/d51
2248         touch $DIR/d51/foo
2249         $MCREATE $DIR/d51/bar
2250         rm $DIR/d51/foo
2251         createmany -m $DIR/d51/longfile 201
2252         FNUM=202
2253         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
2254                 $MCREATE $DIR/d51/longfile$FNUM
2255                 FNUM=$(($FNUM + 1))
2256                 echo -n "+"
2257         done
2258         echo
2259         ls -l $DIR/d51 > /dev/null || error
2260 }
2261 run_test 51a "special situations: split htree with empty entry =="
2262
2263 export NUMTEST=70000
2264 test_51b() {
2265         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2266         [ $NUMFREE -lt 21000 ] && \
2267                 skip "not enough free inodes ($NUMFREE)" && \
2268                 return
2269
2270         check_kernel_version 40 || NUMTEST=31000
2271         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
2272
2273         mkdir -p $DIR/d51b
2274         createmany -d $DIR/d51b/t- $NUMTEST
2275 }
2276 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
2277
2278 test_51c() {
2279         [ ! -d $DIR/d51b ] && skip "$DIR/51b missing" && \
2280                 return
2281
2282         unlinkmany -d $DIR/d51b/t- $NUMTEST
2283 }
2284 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
2285
2286 test_51d() {
2287         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
2288         mkdir -p $DIR/d51d
2289         createmany -o $DIR/d51d/t- 1000
2290         $LFS getstripe $DIR/d51d > $TMP/files
2291         for N in `seq 0 $((OSTCOUNT - 1))`; do
2292             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
2293             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
2294             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
2295         done
2296         unlinkmany $DIR/d51d/t- 1000
2297
2298         NLAST=0
2299         for N in `seq 1 $((OSTCOUNT - 1))`; do
2300             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
2301                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2302             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
2303                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2304
2305             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
2306                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2307             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
2308                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2309             NLAST=$N
2310         done
2311 }
2312 run_test 51d "check object distribution ===================="
2313
2314 test_52a() {
2315         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
2316         mkdir -p $DIR/d52a
2317         touch $DIR/d52a/foo
2318         chattr +a $DIR/d52a/foo || error "chattr +a failed"
2319         echo bar >> $DIR/d52a/foo || error "append bar failed"
2320         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
2321         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
2322         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
2323         echo foo >> $DIR/d52a/foo || error "append foo failed"
2324         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
2325         # new lsattr displays 'e' flag for extents
2326         lsattr $DIR/d52a/foo | egrep -q "^-+a[-e]+ $DIR/d52a/foo" || error "lsattr"
2327         chattr -a $DIR/d52a/foo || error "chattr -a failed"
2328
2329         rm -fr $DIR/d52a || error "cleanup rm failed"
2330 }
2331 run_test 52a "append-only flag test (should return errors) ====="
2332
2333 test_52b() {
2334         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
2335         mkdir -p $DIR/d52b
2336         touch $DIR/d52b/foo
2337         chattr +i $DIR/d52b/foo || error "chattr +a failed"
2338         cat test > $DIR/d52b/foo && error "cat test worked"
2339         cp /etc/hosts $DIR/d52b/foo && error "cp worked"
2340         rm -f $DIR/d52b/foo 2>/dev/null && error "rm worked"
2341         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error "link worked"
2342         echo foo >> $DIR/d52b/foo && error "echo worked"
2343         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error "rename worked"
2344         [ -f $DIR/d52b/foo ] || error
2345         [ -f $DIR/d52b/foo_ren ] && error
2346         lsattr $DIR/d52b/foo | egrep -q "^-+i[-e]+ $DIR/d52b/foo" || error "lsattr"
2347         chattr -i $DIR/d52b/foo || error "chattr failed"
2348
2349         rm -fr $DIR/d52b || error "remove failed"
2350 }
2351 run_test 52b "immutable flag test (should return errors) ======="
2352
2353 test_52c() { # 12848 simulating client < 1.4.7
2354         [ -f $DIR/d52c/foo ] && chattr -i $DIR/d52b/foo
2355         mkdir -p $DIR/d52c
2356         touch $DIR/d52c/foo
2357         # skip MDS_BFLAG_EXT_FLAGS in mdc_getattr_pack
2358 #define OBD_FAIL_MDC_OLD_EXT_FLAGS       0x802
2359         lctl set_param fail_loc=0x802
2360         chattr +i $DIR/d52c/foo || error
2361         lsattr $DIR/d52c/foo | egrep -q "^-+i[-e]+ $DIR/d52c/foo" || error "lsattr failed"
2362         chattr -i $DIR/d52c/foo || error "chattr failed"
2363         lctl set_param -n fail_loc=0
2364
2365         rm -fr $DIR/d52c || error
2366 }
2367 run_test 52c "immutable flag test for client < 1.4.7 ======="
2368
2369 test_53() {
2370         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2371         remote_ost_nodsh && skip "remote OST with nodsh" && return
2372
2373         local param
2374         local ostname
2375         local mds_last
2376         local ost_last
2377         local ostnum
2378
2379         for VALUE in $(do_facet mds lctl get_param osc.*-osc.prealloc_last_id); do
2380                 param=`echo ${VALUE[0]} | cut -d "=" -f1`;
2381                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
2382                 mds_last=$(do_facet mds lctl get_param -n $param)
2383                 ostnum=$(echo $ostname | sed "s/${FSNAME}-OST//g" | awk '{print ($1+1)}' )
2384                 ost_last=$(do_facet ost$ostnum lctl get_param -n obdfilter.$ostname.last_id)
2385                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2386                 if [ $ost_last != $mds_last ]; then
2387                         error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2388                 fi
2389         done
2390 }
2391 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
2392
2393 test_54a() {
2394         [ ! -f "$SOCKETSERVER" ] && skip_env "no socketserver, skipping" && return
2395         [ ! -f "$SOCKETCLIENT" ] && skip_env "no socketclient, skipping" && return
2396         $SOCKETSERVER $DIR/socket
2397         $SOCKETCLIENT $DIR/socket || error
2398         $MUNLINK $DIR/socket
2399 }
2400 run_test 54a "unix domain socket test =========================="
2401
2402 test_54b() {
2403         f="$DIR/f54b"
2404         mknod $f c 1 3
2405         chmod 0666 $f
2406         dd if=/dev/zero of=$f bs=`page_size` count=1
2407 }
2408 run_test 54b "char device works in lustre ======================"
2409
2410 find_loop_dev() {
2411         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
2412         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
2413         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
2414
2415         for i in `seq 3 7`; do
2416                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
2417                 LOOPDEV=$LOOPBASE$i
2418                 LOOPNUM=$i
2419                 break
2420         done
2421 }
2422
2423 test_54c() {
2424         tfile="$DIR/f54c"
2425         tdir="$DIR/d54c"
2426         loopdev="$DIR/loop54c"
2427
2428         find_loop_dev
2429         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
2430         mknod $loopdev b 7 $LOOPNUM
2431         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
2432         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
2433         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
2434         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
2435         mkdir -p $tdir
2436         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
2437         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
2438         df $tdir
2439         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
2440         $UMOUNT $tdir
2441         losetup -d $loopdev
2442         rm $loopdev
2443 }
2444 run_test 54c "block device works in lustre ====================="
2445
2446 test_54d() {
2447         f="$DIR/f54d"
2448         string="aaaaaa"
2449         mknod $f p
2450         [ "$string" = `echo $string > $f | cat $f` ] || error
2451 }
2452 run_test 54d "fifo device works in lustre ======================"
2453
2454 test_54e() {
2455         check_kernel_version 46 || return 0
2456         f="$DIR/f54e"
2457         string="aaaaaa"
2458         cp -aL /dev/console $f
2459         echo $string > $f || error
2460 }
2461 run_test 54e "console/tty device works in lustre ======================"
2462
2463 check_fstype() {
2464         grep -q $FSTYPE /proc/filesystems && return 1
2465         modprobe $FSTYPE
2466         grep -q $FSTYPE /proc/filesystems && return 1
2467         insmod ../$FSTYPE/$FSTYPE.o
2468         grep -q $FSTYPE /proc/filesystems && return 1
2469         insmod ../$FSTYPE/$FSTYPE.ko
2470         grep -q $FSTYPE /proc/filesystems && return 1
2471         return 0
2472 }
2473
2474 test_55() {
2475         rm -rf $DIR/d55
2476         mkdir $DIR/d55
2477         check_fstype && skip_env "can't find fs $FSTYPE" && return
2478         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
2479         touch $DIR/d55/foo
2480         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
2481         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
2482         echo "check for $EXT2_DEV. Please wait..."
2483         rm -rf $DIR/d55/*
2484         $UMOUNT $DIR/d55 || error "unmounting"
2485 }
2486 run_test 55 "check iopen_connect_dentry() ======================"
2487
2488 test_56a() {    # was test_56
2489         rm -rf $DIR/d56
2490         $SETSTRIPE -d $DIR
2491         mkdir $DIR/d56
2492         mkdir $DIR/d56/dir
2493         NUMFILES=3
2494         NUMFILESx2=$(($NUMFILES * 2))
2495         for i in `seq 1 $NUMFILES` ; do
2496                 touch $DIR/d56/file$i
2497                 touch $DIR/d56/dir/file$i
2498         done
2499
2500         # test lfs getstripe with --recursive
2501         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
2502         [ $FILENUM -eq $NUMFILESx2 ] || error \
2503                 "lfs getstripe --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
2504         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
2505         [ $FILENUM -eq $NUMFILES ] || error \
2506                 "lfs getstripe $DIR/d56 without --recursive wrong: found $FILENUM, expected $NUMFILES"
2507         echo "lfs getstripe --recursive passed."
2508
2509         # test lfs getstripe with file instead of dir
2510         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
2511         [ $FILENUM  -eq 1 ] || error \
2512                  "lfs getstripe $DIR/d56/file1 wrong:found $FILENUM, expected 1"
2513         echo "lfs getstripe file passed."
2514
2515         #test lfs getstripe with --verbose
2516         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||\
2517                 error "lfs getstripe --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2518         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] || error \
2519                 "lfs getstripe $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2520         echo "lfs getstripe --verbose passed."
2521
2522         #test lfs getstripe with --obd
2523         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2524                 error "lfs getstripe --obd wrong_uuid should return error message"
2525
2526         [  "$OSTCOUNT" -lt 2 ] && \
2527                 skip_env "skipping other lfs getstripe --obd test" && return
2528         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1[    ]/p' | wc -l`
2529         OBDUUID=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1:/p' | awk '{print $2}'`
2530         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | wc -l`
2531         [ $FOUND -eq $FILENUM ] || \
2532                 error "lfs getstripe --obd wrong: found $FOUND, expected $FILENUM"
2533         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 | sed '/^[   ]*1[    ]/d' |\
2534                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] || \
2535                 error "lfs getstripe --obd wrong: should not show file on other obd"
2536         echo "lfs getstripe --obd passed."
2537 }
2538 run_test 56a "check lfs getstripe ===================================="
2539
2540 NUMFILES=3
2541 NUMDIRS=3
2542 setup_56() {
2543         LOCAL_NUMFILES=$1
2544         LOCAL_NUMDIRS=$2
2545         if [ ! -d "$DIR/${tdir}g" ] ; then
2546                 mkdir -p $DIR/${tdir}g
2547                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2548                         touch $DIR/${tdir}g/file$i
2549                 done
2550                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2551                         mkdir $DIR/${tdir}g/dir$i
2552                         for j in `seq 1 $LOCAL_NUMFILES` ; do
2553                                 touch $DIR/${tdir}g/dir$i/file$j
2554                         done
2555                 done
2556         fi
2557 }
2558
2559 setup_56_special() {
2560         LOCAL_NUMFILES=$1
2561         LOCAL_NUMDIRS=$2
2562         TDIR=$DIR/${tdir}g
2563         setup_56 $1 $2
2564         if [ ! -e "$TDIR/loop1b" ] ; then
2565                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2566                         mknod $TDIR/loop${i}b b 7 $i
2567                         mknod $TDIR/null${i}c c 1 3
2568                         ln -s $TDIR/file1 $TDIR/link${i}l
2569                 done
2570                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2571                         mknod $TDIR/dir$i/loop${i}b b 7 $i
2572                         mknod $TDIR/dir$i/null${i}c c 1 3
2573                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
2574                 done
2575         fi
2576 }
2577
2578 test_56g() {
2579         $SETSTRIPE -d $DIR
2580
2581         setup_56 $NUMFILES $NUMDIRS
2582
2583         EXPECTED=$(($NUMDIRS + 2))
2584         # test lfs find with -name
2585         for i in `seq 1 $NUMFILES` ; do
2586                 NUMS=`$LFIND -name "*$i" $DIR/${tdir}g | wc -l`
2587                 [ $NUMS -eq $EXPECTED ] || error \
2588                         "lfs find -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2589         done
2590         echo "lfs find -name passed."
2591 }
2592 run_test 56g "check lfs find -name ============================="
2593
2594 test_56h() {
2595         $SETSTRIPE -d $DIR
2596
2597         setup_56 $NUMFILES $NUMDIRS
2598
2599         EXPECTED=$((($NUMDIRS+1)*($NUMFILES-1)+$NUMFILES))
2600         # test lfs find with ! -name
2601         for i in `seq 1 $NUMFILES` ; do
2602                 NUMS=`$LFIND ! -name "*$i" $DIR/${tdir}g | wc -l`
2603                 [ $NUMS -eq $EXPECTED ] || error \
2604                         "lfs find ! -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2605         done
2606         echo "lfs find ! -name passed."
2607 }
2608 run_test 56h "check lfs find ! -name ============================="
2609
2610 test_56i() {
2611        tdir=${tdir}i
2612        mkdir -p $DIR/$tdir
2613        UUID=`$GETSTRIPE $DIR/$tdir | awk '/0: / { print $2 }'`
2614        OUT="`$LFIND -ost $UUID $DIR/$tdir`"
2615        [ "$OUT" ] && error "$LFIND returned directory '$OUT'" || true
2616 }
2617 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
2618
2619 test_56j() {
2620         setup_56_special $NUMFILES $NUMDIRS
2621
2622         EXPECTED=$((NUMDIRS+1))
2623         NUMS=`$LFIND -type d $DIR/${tdir}g | wc -l`
2624         [ $NUMS -eq $EXPECTED ] || \
2625                 error "lfs find -type d $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2626 }
2627 run_test 56j "check lfs find -type d ============================="
2628
2629 test_56k() {
2630         setup_56_special $NUMFILES $NUMDIRS
2631
2632         EXPECTED=$(((NUMDIRS+1) * NUMFILES))
2633         NUMS=`$LFIND -type f $DIR/${tdir}g | wc -l`
2634         [ $NUMS -eq $EXPECTED ] || \
2635                 error "lfs find -type f $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2636 }
2637 run_test 56k "check lfs find -type f ============================="
2638
2639 test_56l() {
2640         setup_56_special $NUMFILES $NUMDIRS
2641
2642         EXPECTED=$((NUMDIRS + NUMFILES))
2643         NUMS=`$LFIND -type b $DIR/${tdir}g | wc -l`
2644         [ $NUMS -eq $EXPECTED ] || \
2645                 error "lfs find -type b $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2646 }
2647 run_test 56l "check lfs find -type b ============================="
2648
2649 test_56m() {
2650         setup_56_special $NUMFILES $NUMDIRS
2651
2652         EXPECTED=$((NUMDIRS + NUMFILES))
2653         NUMS=`$LFIND -type c $DIR/${tdir}g | wc -l`
2654         [ $NUMS -eq $EXPECTED ] || \
2655                 error "lfs find -type c $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2656 }
2657 run_test 56m "check lfs find -type c ============================="
2658
2659 test_56n() {
2660         setup_56_special $NUMFILES $NUMDIRS
2661
2662         EXPECTED=$((NUMDIRS + NUMFILES))
2663         NUMS=`$LFIND -type l $DIR/${tdir}g | wc -l`
2664         [ $NUMS -eq $EXPECTED ] || \
2665                 error "lfs find -type l $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2666 }
2667 run_test 56n "check lfs find -type l ============================="
2668
2669 test_56o() {
2670         setup_56 $NUMFILES $NUMDIRS
2671         TDIR=$DIR/${tdir}g
2672
2673         utime $TDIR/file1 > /dev/null || error
2674         utime $TDIR/file2 > /dev/null || error
2675         utime $TDIR/dir1 > /dev/null || error
2676         utime $TDIR/dir2 > /dev/null || error
2677         utime $TDIR/dir1/file1 > /dev/null || error
2678
2679         EXPECTED=5
2680         NUMS=`$LFIND -mtime +1 $TDIR | wc -l`
2681         [ $NUMS -eq $EXPECTED ] || \
2682                 error "lfs find -mtime $TDIR wrong: found $NUMS, expected $EXPECTED"
2683 }
2684 run_test 56o "check lfs find -mtime for old files =========================="
2685
2686 test_56p() {
2687         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2688
2689         TDIR=$DIR/${tdir}g
2690         rm -rf $TDIR
2691
2692         setup_56 $NUMFILES $NUMDIRS
2693
2694         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
2695         EXPECTED=$NUMFILES
2696         NUMS="`$LFIND -uid $RUNAS_ID $TDIR | wc -l`"
2697         [ $NUMS -eq $EXPECTED ] || \
2698                 error "lfs find -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
2699
2700         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
2701         NUMS="`$LFIND ! -uid $RUNAS_ID $TDIR | wc -l`"
2702         [ $NUMS -eq $EXPECTED ] || \
2703                 error "lfs find ! -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
2704
2705         echo "lfs find -uid and ! -uid passed."
2706 }
2707 run_test 56p "check lfs find -uid and ! -uid ==============================="
2708
2709 test_56q() {
2710         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2711
2712         TDIR=$DIR/${tdir}g
2713         rm -rf $TDIR
2714
2715         setup_56 $NUMFILES $NUMDIRS
2716
2717         chgrp $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
2718         EXPECTED=$NUMFILES
2719         NUMS="`$LFIND -gid $RUNAS_ID $TDIR | wc -l`"
2720         [ $NUMS -eq $EXPECTED ] || \
2721                 error "lfs find -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
2722
2723         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
2724         NUMS="`$LFIND ! -gid $RUNAS_ID $TDIR | wc -l`"
2725         [ $NUMS -eq $EXPECTED ] || \
2726                 error "lfs find ! -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
2727
2728         echo "lfs find -gid and ! -gid passed."
2729 }
2730 run_test 56q "check lfs find -gid and ! -gid ==============================="
2731
2732 test_57a() {
2733         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2734
2735         local MNTDEV=$(get_mds_mntdev_proc_path)
2736         DEV=$(do_facet mds lctl get_param -n $MNTDEV)
2737         [ -z "$DEV" ] && error "can't access $MNTDEV"
2738         for DEV in $(do_facet mds lctl get_param -n $MNTDEV); do
2739                 do_facet mds $DUMPE2FS -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
2740                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2741                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2742                 rm $TMP/t57a.dump
2743         done
2744 }
2745 run_test 57a "verify MDS filesystem created with large inodes =="
2746
2747 test_57b() {
2748         local dir=$DIR/d57b
2749
2750         local FILECOUNT=100
2751         local FILE1=$dir/f1
2752         local FILEN=$dir/f$FILECOUNT
2753
2754         rm -rf $dir || error "removing $dir"
2755         mkdir -p $dir || error "creating $dir"
2756
2757         echo "mcreating $FILECOUNT files"
2758         createmany -m $dir/f 1 $FILECOUNT || \
2759                 error "creating files in $dir"
2760
2761         # verify that files do not have EAs yet
2762         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2763         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2764
2765         local fsstat_dev=$(get_mds_fsstat_proc_path)
2766         local MDSFREE=$(do_facet mds lctl get_param -n $fsstat_dev.*.kbytesfree)
2767         local MDCFREE=$(lctl get_param -n mdc.*.kbytesfree | head -n 1)
2768         echo "opening files to create objects/EAs"
2769         local FILE
2770         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
2771                 $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
2772         done
2773
2774         # verify that files have EAs now
2775         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2776         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2777
2778         sleep 1 # make sure we get new statfs data
2779         local MDSFREE2=$(do_facet mds lctl get_param -n $fsstat_dev.*.kbytesfree)
2780         local MDCFREE2=$(lctl get_param -n mdc.*.kbytesfree | head -n 1)
2781         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
2782                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
2783                         error "MDC before $MDCFREE != after $MDCFREE2"
2784                 else
2785                         echo "MDC before $MDCFREE != after $MDCFREE2"
2786                         echo "unable to confirm if MDS has large inodes"
2787                 fi
2788         fi
2789         rm -rf $dir
2790 }
2791 run_test 57b "default LOV EAs are stored inside large inodes ==="
2792
2793 test_58() {
2794     [ -z "$(which wiretest 2>/dev/null)" ] && skip_env "could not find wiretest" && return
2795     wiretest
2796 }
2797 run_test 58 "verify cross-platform wire constants =============="
2798
2799 test_59() {
2800         echo "touch 130 files"
2801         createmany -o $DIR/f59- 130
2802         echo "rm 130 files"
2803         unlinkmany $DIR/f59- 130
2804         sync
2805         sleep 2
2806         # wait for commitment of removal
2807 }
2808 run_test 59 "verify cancellation of llog records async ========="
2809
2810 TEST60_HEAD="test_60 run $RANDOM"
2811 test_60a() {    # was test_60
2812         [ ! -f run-llog.sh ] && skip_env "missing subtest run-llog.sh" && return
2813         log "$TEST60_HEAD - from kernel mode"
2814         sh run-llog.sh
2815 }
2816 run_test 60a "llog sanity tests run from kernel module =========="
2817
2818 test_60b() { # bug 6411
2819         dmesg > $DIR/$tfile
2820         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
2821                                  /llog.test/ {
2822                                          if (marker)
2823                                                  from_marker++
2824                                          from_begin++
2825                                  }
2826                                  END {
2827                                          if (marker)
2828                                                  print from_marker
2829                                          else
2830                                                  print from_begin
2831                                  }"`
2832         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
2833 }
2834 run_test 60b "limit repeated messages from CERROR/CWARN ========"
2835
2836 test_60c() {
2837         echo "create 5000 files"
2838         createmany -o $DIR/f60c- 5000
2839         #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
2840         lctl set_param fail_loc=0x80000137
2841         unlinkmany $DIR/f60c- 5000
2842 }
2843 run_test 60c "unlink file when mds full"
2844
2845 test_60d() {
2846         SAVEPRINTK=$(lctl get_param -n printk)
2847
2848         # verify "lctl mark" is even working"
2849         MESSAGE="test message ID $RANDOM $$"
2850         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
2851         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
2852
2853         lctl set_param printk=0 || error "set lnet.printk failed"
2854         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
2855         MESSAGE="new test message ID $RANDOM $$"
2856         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
2857         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
2858         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
2859
2860         lctl set_param -n printk="$SAVEPRINTK"
2861 }
2862 run_test 60d "test printk console message masking"
2863
2864 test_61() {
2865         f="$DIR/f61"
2866         dd if=/dev/zero of=$f bs=`page_size` count=1
2867         cancel_lru_locks osc
2868         multiop $f OSMWUc || error
2869         sync
2870 }
2871 run_test 61 "mmap() writes don't make sync hang ================"
2872
2873 # bug 2330 - insufficient obd_match error checking causes LBUG
2874 test_62() {
2875         f="$DIR/f62"
2876         echo foo > $f
2877         cancel_lru_locks osc
2878         #define OBD_FAIL_OSC_MATCH 0x405
2879         lctl set_param fail_loc=0x405
2880         cat $f && error "cat succeeded, expect -EIO"
2881         lctl set_param fail_loc=0
2882 }
2883 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
2884 # match every page all of the time.
2885 run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2886
2887 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2888 test_63a() {    # was test_63
2889         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
2890         lctl set_param -n osc.*.max_dirty_mb 0
2891         for i in `seq 10` ; do
2892                 dd if=/dev/zero of=$DIR/f63 bs=8k &
2893                 sleep 5
2894                 kill $!
2895                 sleep 1
2896         done
2897
2898         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
2899         rm -f $DIR/f63 || true
2900 }
2901 run_test 63a "Verify oig_wait interruption does not crash ======="
2902
2903 # bug 2248 - async write errors didn't return to application on sync
2904 # bug 3677 - async write errors left page locked
2905 test_63b() {
2906         debugsave
2907         lctl set_param debug=-1
2908
2909         # ensure we have a grant to do async writes
2910         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
2911         rm $DIR/$tfile
2912
2913         #define OBD_FAIL_OSC_BRW_PREP_REQ 0x406
2914         lctl set_param fail_loc=0x80000406
2915         multiop $DIR/$tfile Owy && \
2916                 error "sync didn't return ENOMEM"
2917         sync; sleep 2; sync     # do a real sync this time to flush page
2918         lctl get_param -n llite.*.dump_page_cache | grep locked && \
2919                 error "locked page left in cache after async error" || true
2920         debugrestore
2921 }
2922 run_test 63b "async write errors should be returned to fsync ==="
2923
2924 test_64a () {
2925         df $DIR
2926         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
2927 }
2928 run_test 64a "verify filter grant calculations (in kernel) ====="
2929
2930 test_64b () {
2931         [ ! -f oos.sh ] && skip_env "missing subtest oos.sh" && return
2932         sh oos.sh $MOUNT
2933 }
2934 run_test 64b "check out-of-space detection on client ==========="
2935
2936 # bug 1414 - set/get directories' stripe info
2937 test_65a() {
2938         mkdir -p $DIR/d65
2939         touch $DIR/d65/f1
2940         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
2941 }
2942 run_test 65a "directory with no stripe info ===================="
2943
2944 test_65b() {
2945         mkdir -p $DIR/d65
2946         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
2947         touch $DIR/d65/f2
2948         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
2949 }
2950 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
2951
2952 test_65c() {
2953         if [ $OSTCOUNT -gt 1 ]; then
2954                 mkdir -p $DIR/d65
2955                 $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 4)) -i 1 \
2956                         -c $(($OSTCOUNT - 1)) || error "setstripe"
2957                 touch $DIR/d65/f3
2958                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
2959         fi
2960 }
2961 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
2962
2963 test_65d() {
2964         mkdir -p $DIR/d65
2965         [ $STRIPECOUNT -le 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1))
2966         $SETSTRIPE $DIR/d65 -s $STRIPESIZE -c $sc || error "setstripe"
2967         touch $DIR/d65/f4 $DIR/d65/f5
2968         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
2969 }
2970 run_test 65d "directory setstripe $STRIPESIZE -1 stripe_count =============="
2971
2972 test_65e() {
2973         mkdir -p $DIR/d65
2974
2975         $SETSTRIPE $DIR/d65 || error "setstripe"
2976         $GETSTRIPE -v $DIR/d65 | grep "Default" || error "no stripe info failed"
2977         touch $DIR/d65/f6
2978         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
2979 }
2980 run_test 65e "directory setstripe defaults ======================="
2981
2982 test_65f() {
2983         mkdir -p $DIR/d65f
2984         $RUNAS $SETSTRIPE $DIR/d65f && error "setstripe succeeded" || true
2985 }
2986 run_test 65f "dir setstripe permission (should return error) ==="
2987
2988 test_65g() {
2989         mkdir -p $DIR/d65
2990         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
2991         $SETSTRIPE -d $DIR/d65 || error "setstripe"
2992         $GETSTRIPE -v $DIR/d65 | grep "Default" || \
2993                 error "delete default stripe failed"
2994 }
2995 run_test 65g "directory setstripe -d ==========================="
2996
2997 test_65h() {
2998         mkdir -p $DIR/d65
2999         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
3000         mkdir -p $DIR/d65/dd1
3001         [ "`$GETSTRIPE -v $DIR/d65 | grep "^count"`" == \
3002           "`$GETSTRIPE -v $DIR/d65/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
3003 }
3004 run_test 65h "directory stripe info inherit ===================="
3005
3006 test_65i() { # bug6367
3007         $SETSTRIPE $MOUNT -s 65536 -c -1
3008 }
3009 run_test 65i "set non-default striping on root directory (bug 6367)="
3010
3011 test_65j() { # bug6367
3012         sync; sleep 1
3013         # if we aren't already remounting for each test, do so for this test
3014         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
3015                 cleanup || error "failed to unmount"
3016                 setup
3017         fi
3018         $SETSTRIPE -d $MOUNT || error "setstripe failed"
3019 }
3020 run_test 65j "set default striping on root directory (bug 6367)="
3021
3022 test_65k() { # bug11679
3023         [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
3024         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3025
3026         echo "Check OST status: "
3027         MDS_OSCS=`do_facet mds lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
3028         for OSC in $MDS_OSCS; do
3029                 echo $OSC "is activate"
3030                 do_facet mds lctl --device %$OSC activate
3031         done
3032         do_facet client mkdir -p $DIR/$tdir
3033         for INACTIVE_OSC in $MDS_OSCS; do
3034                 echo $INACTIVE_OSC "is Deactivate:"
3035                 do_facet mds lctl --device  %$INACTIVE_OSC deactivate
3036                 for STRIPE_OSC in $MDS_OSCS; do
3037                         STRIPE_OST=`osc_to_ost $STRIPE_OSC`
3038                         STRIPE_INDEX=`do_facet mds lctl get_param -n lov.*md*.target_obd |
3039                                       grep $STRIPE_OST | awk -F: '{print $1}'`
3040                         echo "$SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1"
3041                         do_facet client $SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1
3042                         RC=$?
3043                         [ $RC -ne 0 ] && error "setstripe should have succeeded"
3044                 done
3045                 do_facet client rm -f $DIR/$tdir/*
3046                 echo $INACTIVE_OSC "is Activate."
3047                 do_facet mds lctl --device  %$INACTIVE_OSC activate
3048         done
3049 }
3050 run_test 65k "validate manual striping works properly with deactivated OSCs"
3051
3052 test_65l() { # bug 12836
3053         mkdir -p $DIR/$tdir/test_dir
3054         $SETSTRIPE $DIR/$tdir/test_dir -c -1
3055         $LFS find -mtime -1 $DIR/$tdir > /dev/null
3056 }
3057 run_test 65l "lfs find on -1 stripe dir ========================"
3058
3059 # bug 2543 - update blocks count on client
3060 test_66() {
3061         COUNT=${COUNT:-8}
3062         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
3063         sync; sleep 1; sync
3064         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
3065         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
3066 }
3067 run_test 66 "update inode blocks count on client ==============="
3068
3069 test_67a() { # was test_67 bug 3285 - supplementary group fails on MDS, passes on client
3070         [ "$RUNAS_ID" = "$UID" ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
3071         check_kernel_version 35 || return 0
3072         mkdir -p $DIR/$tdir
3073         chmod 771 $DIR/$tdir
3074         chgrp $RUNAS_ID $DIR/$tdir
3075         $RUNAS -u $RUNAS_ID -g $(($RUNAS_ID + 1)) -G1,2,$RUNAS_ID ls $DIR/$tdir
3076         RC=$?
3077         GROUP_UPCALL=$(do_facet mds lctl get_param -n mds.*.group_upcall)
3078         [ -z "$GROUP_UPCALL" ] && \
3079                 skip "lctl get_param failed! Useless to continue the test!" && return
3080         [ "$GROUP_UPCALL" = "NONE" -a $RC -eq 0 ] && \
3081                 error "no-upcall passed" || true
3082         [ "$GROUP_UPCALL" != "NONE" -a $RC -ne 0 ] && \
3083                 error "upcall failed" || true
3084 }
3085 run_test 67a "supplementary group failure (should return error) ="
3086
3087 cleanup_67b() {
3088         set +vx
3089         trap 0
3090         do_facet mds lctl set_param -n mds.*.group_upcall NONE
3091 }
3092
3093 test_67b() { # bug 3285 - supplementary group fails on MDS, passes on client
3094         # needs to be in /etc/groups on MDS, gid == uid
3095         # Let's use RUNAS_ID
3096         T67_UID=${T67_UID:-$RUNAS_ID}
3097
3098         [ "$UID" = "$T67_UID" ] && skip "UID = T67_UID = $UID -- skipping" && return
3099         check_kernel_version 35 || return 0
3100         do_facet mds grep -q ":$T67_UID:$T67_UID" /etc/passwd || \
3101                 { skip "Need gid=$T67_UID group and gid == uid on mds !" && return; }
3102
3103         GROUP_UPCALL=$(do_facet mds lctl get_param -n mds.*.group_upcall)
3104         [ -z "$GROUP_UPCALL" ] && \
3105                 skip "lctl get_param failed! Useless to continue the test!" && return
3106         [ "$GROUP_UPCALL" != "NONE" ] && \
3107                 skip "skip test - upcall=$GROUP_UPCALL" && return
3108         set -vx
3109         trap cleanup_67b EXIT
3110         mkdir -p $DIR/$tdir
3111         chmod 771 $DIR/$tdir
3112         chgrp $T67_UID $DIR/$tdir
3113         local l_getgroups=$(do_facet mds which l_getgroups)
3114         do_facet mds lctl set_param -n mds.*.group_upcall $l_getgroups
3115         do_facet mds $l_getgroups -d $T67_UID
3116         $RUNAS -u $T67_UID -g 999 -G8,9,$T67_UID touch $DIR/$tdir/$tfile || \
3117                 error "'touch $DIR/$tdir/$tfile' failed"
3118         [ -f $DIR/$tdir/$tfile ] || error "$DIR/$tdir/$tfile create error"
3119         cleanup_67b
3120 }
3121 run_test 67b "supplementary group test ========================="
3122
3123 LLOOP=
3124 cleanup_68() {
3125         trap 0
3126         if [ ! -z "$LLOOP" ]; then
3127                 swapoff $LLOOP || error "swapoff failed"
3128                 $LCTL blockdev_detach $LLOOP || error "detach failed"
3129                 rm -f $LLOOP
3130                 unset LLOOP
3131         fi
3132         rm -f $DIR/f68
3133 }
3134
3135 meminfo() {
3136         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
3137 }
3138
3139 swap_used() {
3140         swapon -s | awk '($1 == "'$1'") { print $4 }'
3141 }
3142
3143
3144 # excercise swapping to lustre by adding a high priority swapfile entry
3145 # and then consuming memory until it is used.
3146 test_68() {
3147         [ "$UID" != 0 ] && skip_env "must run as root" && return
3148         lctl get_param -n devices | grep -q obdfilter && \
3149                 skip "local OST" && return
3150
3151         grep -q llite_lloop /proc/modules
3152         [ $? -ne 0 ] && skip_env "can't find module llite_lloop" && return
3153
3154         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
3155                 skip "can't reliably test swap with TCP" && return
3156
3157         MEMTOTAL=`meminfo MemTotal`
3158         NR_BLOCKS=$((MEMTOTAL>>8))
3159         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
3160
3161         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
3162         dd if=/dev/zero of=$DIR/f68 bs=64k seek=$NR_BLOCKS count=1
3163         mkswap $DIR/f68
3164
3165         $LCTL blockdev_attach $DIR/f68 $LLOOP || error "attach failed"
3166
3167         trap cleanup_68 EXIT
3168
3169         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
3170
3171         echo "before: `swapon -s | grep $LLOOP`"
3172         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
3173         echo "after: `swapon -s | grep $LLOOP`"
3174         SWAPUSED=`swap_used $LLOOP`
3175
3176         cleanup_68
3177
3178         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
3179 }
3180 run_test 68 "support swapping to Lustre ========================"
3181
3182 # bug5265, obdfilter oa2dentry return -ENOENT
3183 # #define OBD_FAIL_OST_ENOENT 0x217
3184 test_69() {
3185         remote_ost_nodsh && skip "remote OST with nodsh" && return
3186
3187         f="$DIR/$tfile"
3188         $SETSTRIPE $f -c 1 -i 0
3189
3190         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
3191
3192         #define OBD_FAIL_OST_ENOENT 0x217
3193         do_facet ost1 lctl set_param fail_loc=0x217
3194         truncate $f 1 # vmtruncate() will ignore truncate() error.
3195         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
3196
3197         do_facet ost1 lctl set_param fail_loc=0
3198         $DIRECTIO write $f 0 2 || error "write error"
3199
3200         cancel_lru_locks osc
3201         $DIRECTIO read $f 0 1 || error "read error"
3202
3203         #define OBD_FAIL_OST_ENOENT 0x217
3204         do_facet ost1 lctl set_param fail_loc=0x217
3205         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
3206
3207         do_facet ost1 lctl set_param fail_loc=0
3208         rm -f $f
3209 }
3210 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
3211
3212 test_71() {
3213     mkdir -p $DIR/$tdir
3214     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
3215 }
3216 run_test 71 "Running dbench on lustre (don't segment fault) ===="
3217
3218 test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
3219         check_kernel_version 43 || return 0
3220         [ "$RUNAS_ID" = "$UID" ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3221
3222         # Check that testing environment is properly set up. Skip if not
3223         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
3224                 skip_env "User $RUNAS_ID does not exist - skipping"
3225                 return 0
3226         }
3227         touch $DIR/f72
3228         chmod 777 $DIR/f72
3229         chmod ug+s $DIR/f72
3230         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
3231         # See if we are still setuid/sgid
3232         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
3233         # Now test that MDS is updated too
3234         cancel_lru_locks mdc
3235         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
3236         true
3237 }
3238 run_test 72 "Test that remove suid works properly (bug5695) ===="
3239
3240 # bug 3462 - multiple simultaneous MDC requests
3241 test_73() {
3242         mkdir $DIR/d73-1
3243         mkdir $DIR/d73-2
3244         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
3245         pid1=$!
3246
3247         #define OBD_FAIL_MDS_PAUSE_OPEN 0x129
3248         lctl set_param fail_loc=0x80000129
3249         multiop $DIR/d73-1/f73-2 Oc &
3250         sleep 1
3251         lctl set_param fail_loc=0
3252
3253         multiop $DIR/d73-2/f73-3 Oc &
3254         pid3=$!
3255
3256         kill -USR1 $pid1
3257         wait $pid1 || return 1
3258
3259         sleep 25
3260
3261         $CHECKSTAT -t file $DIR/d73-1/f73-1 || error "$DIR/d73-1/f73-1 not file"
3262         $CHECKSTAT -t file $DIR/d73-1/f73-2 || error "$DIR/d73-1/f73-2 not file"
3263         $CHECKSTAT -t file $DIR/d73-2/f73-3 || error "$DIR/d73-2/f73-3 not file"
3264
3265         rm -rf $DIR/d73-*
3266 }
3267 run_test 73 "multiple MDC requests (should not deadlock)"
3268
3269 test_74a() { # bug 6149, 6184
3270         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
3271         #
3272         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
3273         # will spin in a tight reconnection loop
3274         touch $DIR/f74a
3275         lctl set_param fail_loc=0x8000030e
3276         # get any lock that won't be difficult - lookup works.
3277         ls $DIR/f74a
3278         lctl set_param fail_loc=0
3279         true
3280 }
3281 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
3282
3283 test_74b() { # bug 13310
3284         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
3285         #
3286         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
3287         # will spin in a tight reconnection loop
3288         lctl set_param fail_loc=0x8000030e
3289         # get a "difficult" lock
3290         touch $DIR/f74b
3291         lctl set_param fail_loc=0
3292         true
3293 }
3294 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
3295
3296 JOIN=${JOIN:-"lfs join"}
3297 F75=$DIR/f75
3298 F128k=${F75}_128k
3299 FHEAD=${F75}_head
3300 FTAIL=${F75}_tail
3301 export T75_PREP=no
3302 test75_prep() {
3303         [ $T75_PREP = "yes" ] && return
3304         echo "using F75=$F75, F128k=$F128k, FHEAD=$FHEAD, FTAIL=$FTAIL"
3305
3306         dd if=/dev/urandom of=${F75}_128k bs=128k count=1 || error "dd failed"
3307         log "finished dd"
3308         chmod 777 ${F128k}
3309         T75_PREP=yes
3310 }
3311
3312 test_75a() {
3313         test75_prep
3314
3315         cp -p ${F128k} ${FHEAD}
3316         log "finished cp to $FHEAD"
3317         cp -p ${F128k} ${FTAIL}
3318         log "finished cp to $FTAIL"
3319         cat ${F128k} ${F128k} > ${F75}_sim_sim
3320
3321         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3322         log "finished join $FHEAD to ${F75}_sim_sim"
3323         cmp ${FHEAD} ${F75}_sim_sim || error "${FHEAD} ${F75}_sim_sim differ"
3324         log "finished cmp $FHEAD to ${F75}_sim_sim"
3325         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} still exist after join"
3326 }
3327 run_test 75a "TEST join file ===================================="
3328
3329 test_75b() {
3330         test75_prep
3331
3332         cp -p ${F128k} ${FTAIL}
3333         cat ${F75}_sim_sim >> ${F75}_join_sim
3334         cat ${F128k} >> ${F75}_join_sim
3335         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3336         cmp ${FHEAD} ${F75}_join_sim || \
3337                 error "${FHEAD} ${F75}_join_sim are different"
3338         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join"
3339 }
3340 run_test 75b "TEST join file 2 =================================="
3341
3342 test_75c() {
3343         test75_prep
3344
3345         cp -p ${F128k} ${FTAIL}
3346         cat ${F128k} >> ${F75}_sim_join
3347         cat ${F75}_join_sim >> ${F75}_sim_join
3348         $JOIN ${FTAIL} ${FHEAD} || error "join error"
3349         cmp ${FTAIL} ${F75}_sim_join || \
3350                 error "${FTAIL} ${F75}_sim_join are different"
3351         $CHECKSTAT -a ${FHEAD} || error "tail ${FHEAD} exist after join"
3352 }
3353 run_test 75c "TEST join file 3 =================================="
3354
3355 test_75d() {
3356         test75_prep
3357
3358         cp -p ${F128k} ${FHEAD}
3359         cp -p ${F128k} ${FHEAD}_tmp
3360         cat ${F75}_sim_sim >> ${F75}_join_join
3361         cat ${F75}_sim_join >> ${F75}_join_join
3362         $JOIN ${FHEAD} ${FHEAD}_tmp || error "join ${FHEAD} ${FHEAD}_tmp error"
3363         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3364         cmp ${FHEAD} ${F75}_join_join ||error "${FHEAD} ${F75}_join_join differ"        $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join"
3365         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)"
3366 }
3367 run_test 75d "TEST join file 4 =================================="
3368
3369 test_75e() {
3370         test75_prep
3371
3372         rm -rf ${FHEAD} || "delete join file error"
3373 }
3374 run_test 75e "TEST join file 5 (remove joined file) ============="
3375
3376 test_75f() {
3377         test75_prep
3378
3379         cp -p ${F128k} ${F75}_join_10_compare
3380         cp -p ${F128k} ${F75}_join_10
3381         for ((i = 0; i < 10; i++)); do
3382                 cat ${F128k} >> ${F75}_join_10_compare
3383                 cp -p ${F128k} ${FTAIL}
3384                 $JOIN ${F75}_join_10 ${FTAIL} || \
3385                         error "join ${F75}_join_10 ${FTAIL} error"
3386                 $CHECKSTAT -a ${FTAIL} || error "tail file exist after join"
3387         done
3388         cmp ${F75}_join_10 ${F75}_join_10_compare || \
3389                 error "files ${F75}_join_10 ${F75}_join_10_compare differ"
3390 }
3391 run_test 75f "TEST join file 6 (join 10 files) =================="
3392
3393 test_75g() {
3394         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
3395         $LFS getstripe ${F75}_join_10
3396
3397         $OPENUNLINK ${F75}_join_10 ${F75}_join_10 || error "files unlink open"
3398
3399         ls -l $F75*
3400 }
3401 run_test 75g "TEST join file 7 (open unlink) ===================="
3402
3403 num_inodes() {
3404         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
3405 }
3406
3407 test_76() { # bug 1443
3408         DETH=$(grep deathrow /proc/kallsyms /proc/ksyms 2> /dev/null | wc -l)
3409         [ $DETH -eq 0 ] && skip "No _iget." && return 0
3410         BEFORE_INODES=`num_inodes`
3411         echo "before inodes: $BEFORE_INODES"
3412         local COUNT=1000
3413         [ "$SLOW" = "no" ] && COUNT=100
3414         for i in `seq $COUNT`; do
3415                 touch $DIR/$tfile
3416                 rm -f $DIR/$tfile
3417         done
3418         AFTER_INODES=`num_inodes`
3419         echo "after inodes: $AFTER_INODES"
3420         [ $AFTER_INODES -gt $((BEFORE_INODES + 32)) ] && \
3421                 error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
3422         true
3423 }
3424 run_test 76 "destroy duplicate inodes in client inode cache ===="
3425
3426 export ORIG_CSUM=""
3427 set_checksums()
3428 {
3429         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums |
3430                                        head -n1`
3431
3432         lctl set_param -n osc.*.checksums=$1
3433         return 0
3434 }
3435
3436 export ORIG_CSUM_TYPE=""
3437 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
3438 set_checksum_type()
3439 {
3440         [ "$ORIG_CSUM_TYPE" ] || \
3441                 ORIG_CSUM_TYPE=`lctl get_param -n osc.*osc-[^mM]*.checksum_type | sed 's/.*\[\(.*\)\].*/\1/g' \
3442                                 | head -n1`
3443         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
3444         log "set checksum type to $1"
3445         return 0
3446 }
3447 F77_TMP=$TMP/f77-temp
3448 F77SZ=8
3449 setup_f77() {
3450         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
3451                 error "error writing to $F77_TMP"
3452 }
3453
3454 test_77a() { # bug 10889
3455         [ ! -f $F77_TMP ] && setup_f77
3456         set_checksums 1
3457         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
3458         set_checksums 0
3459 }
3460 run_test 77a "normal checksum read/write operation ============="
3461
3462 test_77b() { # bug 10889
3463         [ ! -f $F77_TMP ] && setup_f77
3464         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3465         lctl set_param fail_loc=0x80000409
3466         set_checksums 1
3467         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
3468                 error "dd error: $?"
3469         lctl set_param fail_loc=0
3470         set_checksums 0
3471 }
3472 run_test 77b "checksum error on client write ===================="
3473
3474 test_77c() { # bug 10889
3475         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
3476         set_checksums 1
3477         for algo in $CKSUM_TYPES; do
3478                 cancel_lru_locks osc
3479                 set_checksum_type $algo
3480                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3481                 lctl set_param fail_loc=0x80000408
3482                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
3483                 lctl set_param fail_loc=0
3484         done
3485         set_checksums 0
3486         set_checksum_type $ORIG_CSUM_TYPE
3487 }
3488 run_test 77c "checksum error on client read ==================="
3489
3490 test_77d() { # bug 10889
3491         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3492         lctl set_param fail_loc=0x80000409
3493         set_checksums 1
3494         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3495                 error "direct write: rc=$?"
3496         lctl set_param fail_loc=0
3497         set_checksums 0
3498 }
3499 run_test 77d "checksum error on OST direct write ==============="
3500
3501 test_77e() { # bug 10889
3502         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
3503         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3504         lctl set_param fail_loc=0x80000408
3505         set_checksums 1
3506         cancel_lru_locks osc
3507         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3508                 error "direct read: rc=$?"
3509         lctl set_param fail_loc=0
3510         set_checksums 0
3511 }
3512 run_test 77e "checksum error on OST direct read ================"
3513
3514 test_77f() { # bug 10889
3515         set_checksums 1
3516         for algo in $CKSUM_TYPES; do
3517                 cancel_lru_locks osc
3518                 set_checksum_type $algo
3519                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3520                 lctl set_param fail_loc=0x409
3521                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
3522                         error "direct write succeeded"
3523                 lctl set_param fail_loc=0
3524         done
3525         set_checksum_type $ORIG_CSUM_TYPE
3526         set_checksums 0
3527 }
3528 run_test 77f "repeat checksum error on write (expect error) ===="
3529
3530 test_77g() { # bug 10889
3531         remote_ost_nodsh && skip "remote OST with nodsh" && return
3532
3533         [ ! -f $F77_TMP ] && setup_f77
3534
3535         $SETSTRIPE $DIR/f77g -c 1 -i 0
3536         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
3537         do_facet ost1 lctl set_param fail_loc=0x8000021a
3538         set_checksums 1
3539         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
3540                 error "write error: rc=$?"
3541         do_facet ost1 lctl set_param fail_loc=0
3542         set_checksums 0
3543 }
3544 run_test 77g "checksum error on OST write ======================"
3545
3546 test_77h() { # bug 10889
3547         remote_ost_nodsh && skip "remote OST with nodsh" && return
3548
3549         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
3550         cancel_lru_locks osc
3551         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
3552         do_facet ost1 lctl set_param fail_loc=0x8000021b
3553         set_checksums 1
3554         cmp $F77_TMP $DIR/f77g || error "file compare failed"
3555         do_facet ost1 lctl set_param fail_loc=0
3556         set_checksums 0
3557 }
3558 run_test 77h "checksum error on OST read ======================="
3559
3560 test_77i() { # bug 13805
3561         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
3562         lctl set_param fail_loc=0x40b
3563         remount_client $MOUNT
3564         lctl set_param fail_loc=0
3565         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
3566                 param=`echo ${VALUE[0]} | cut -d "=" -f1`
3567                 algo=`lctl get_param -n $param | sed 's/.*\[\(.*\)\].*/\1/g'`
3568                 [ "$algo" = "crc32" ] || error "algo set to $algo instead of crc32"
3569         done
3570         remount_client $MOUNT
3571 }
3572 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
3573
3574 test_77j() { # bug 13805
3575         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
3576         lctl set_param fail_loc=0x40c
3577         remount_client $MOUNT
3578         lctl set_param fail_loc=0
3579         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
3580                 param=`echo ${VALUE[0]} | cut -d "=" -f1`
3581                 algo=`lctl get_param -n $param | sed 's/.*\[\(.*\)\].*/\1/g'`
3582                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
3583         done
3584         remount_client $MOUNT
3585 }
3586 run_test 77j "client only supporting ADLER32 ===================="
3587
3588 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
3589 rm -f $F77_TMP
3590 unset F77_TMP
3591
3592 test_78() { # bug 10901
3593         NSEQ=5
3594         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
3595         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
3596         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
3597         echo "MemTotal: $MEMTOTAL"
3598 # reserve 256MB of memory for the kernel and other running processes,
3599 # and then take 1/2 of the remaining memory for the read/write buffers.
3600         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
3601         echo "Mem to use for directio: $MEMTOTAL"
3602         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
3603         [ $F78SIZE -gt 512 ] && F78SIZE=512
3604         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
3605         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
3606         echo "Smallest OST: $SMALLESTOST"
3607         [ $SMALLESTOST -lt 10240 ] && \
3608                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
3609
3610         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 5)) ] && \
3611                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 5))
3612         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
3613         echo "File size: $F78SIZE"
3614         $SETSTRIPE $DIR/$tfile -c -1 || error "setstripe failed"
3615         for i in `seq 1 $NSEQ`
3616         do
3617                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
3618                 echo directIO rdwr round $i of $NSEQ
3619                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
3620         done
3621
3622         rm -f $DIR/$tfile
3623 }
3624 run_test 78 "handle large O_DIRECT writes correctly ============"
3625
3626 test_79() { # bug 12743
3627         wait_delete_completed
3628
3629         BKTOTAL=$(calc_osc_kbytes kbytestotal)
3630         BKFREE=$(calc_osc_kbytes kbytesfree)
3631         BKAVAIL=$(calc_osc_kbytes kbytesavail)
3632         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
3633         DFTOTAL=`echo $STRING | cut -d, -f1`
3634         DFUSED=`echo $STRING  | cut -d, -f2`
3635         DFAVAIL=`echo $STRING | cut -d, -f3`
3636         DFFREE=$(($DFTOTAL - $DFUSED))
3637
3638         ALLOWANCE=$((64 * $OSTCOUNT))
3639
3640         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
3641            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
3642                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
3643         fi
3644         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
3645            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
3646                 error "df free($DFFREE) mismatch OST free($BKFREE)"
3647         fi
3648         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
3649            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
3650                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
3651         fi
3652 }
3653 run_test 79 "df report consistency check ======================="
3654
3655 test_80() { # bug 10718
3656         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
3657         sync; sleep 1; sync
3658         local BEFORE=`date +%s`
3659         cancel_lru_locks osc
3660         local AFTER=`date +%s`
3661         local DIFF=$((AFTER-BEFORE))
3662         if [ $DIFF -gt 1 ] ; then
3663                 error "elapsed for 1M@1T = $DIFF"
3664         fi
3665         true
3666 }
3667 run_test 80 "Page eviction is equally fast at high offsets too  ===="
3668
3669 test_99a() {
3670         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3671         mkdir -p $DIR/d99cvsroot || error "mkdir $DIR/d99cvsroot failed"
3672         chown $RUNAS_ID $DIR/d99cvsroot || error "chown $DIR/d99cvsroot failed"
3673         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
3674         cd $TMP
3675
3676         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
3677         cd $oldPWD
3678 }
3679 run_test 99a "cvs init ========================================="
3680
3681 test_99b() {
3682         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3683         [ ! -d $DIR/d99cvsroot ] && test_99a
3684         $RUNAS [ ! -w /tmp ] && skip "/tmp has wrong w permission -- skipping" && return
3685         cd /etc/init.d || error "cd /etc/init.d failed"
3686         # some versions of cvs import exit(1) when asked to import links or
3687         # files they can't read.  ignore those files.
3688         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
3689                         ! -perm +4 -printf '-I %f\n')
3690         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
3691                 d99reposname vtag rtag > /dev/null || error "cvs import failed"
3692 }
3693 run_test 99b "cvs import ======================================="
3694
3695 test_99c() {
3696         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3697         [ ! -d $DIR/d99cvsroot ] && test_99b
3698         cd $DIR || error "cd $DIR failed"
3699         mkdir -p $DIR/d99reposname || error "mkdir $DIR/d99reposname failed"
3700         chown $RUNAS_ID $DIR/d99reposname || \
3701                 error "chown $DIR/d99reposname failed"
3702         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname > /dev/null || \
3703                 error "cvs co d99reposname failed"
3704 }
3705 run_test 99c "cvs checkout ====================================="
3706
3707 test_99d() {
3708         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3709         [ ! -d $DIR/d99cvsroot ] && test_99c
3710         cd $DIR/d99reposname
3711         $RUNAS touch foo99
3712         $RUNAS cvs add -m 'addmsg' foo99
3713 }
3714 run_test 99d "cvs add =========================================="
3715
3716 test_99e() {
3717         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3718         [ ! -d $DIR/d99cvsroot ] && test_99c
3719         cd $DIR/d99reposname
3720         $RUNAS cvs update
3721 }
3722 run_test 99e "cvs update ======================================="
3723
3724 test_99f() {
3725         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3726         [ ! -d $DIR/d99cvsroot ] && test_99d
3727         cd $DIR/d99reposname
3728         $RUNAS cvs commit -m 'nomsg' foo99
3729 }
3730 run_test 99f "cvs commit ======================================="
3731
3732 test_100() {
3733         [ "$NETTYPE" = tcp ] || \
3734                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
3735                         return ; }
3736
3737         remote_ost_nodsh && skip "remote OST with nodsh" && return
3738         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3739         remote_servers || \
3740                 { skip "useless for local single node setup" && return; }
3741
3742         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
3743                 [ "$PROT" != "tcp" ] && continue
3744                 RPORT=$(echo $REMOTE | cut -d: -f2)
3745                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
3746
3747                 rc=0
3748                 LPORT=`echo $LOCAL | cut -d: -f2`
3749                 if [ $LPORT -ge 1024 ]; then
3750                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
3751                         netstat -tna
3752                         error_exit "local: $LPORT > 1024, remote: $RPORT"
3753                 fi
3754         done
3755         [ "$rc" = 0 ] || error_exit "privileged port not found" )
3756 }
3757 run_test 100 "check local port using privileged port ==========="
3758
3759 function get_named_value()
3760 {
3761     local tag
3762
3763     tag=$1
3764     while read ;do
3765         line=$REPLY
3766         case $line in
3767         $tag*)
3768             echo $line | sed "s/^$tag//"
3769             break
3770             ;;
3771         esac
3772     done
3773 }
3774
3775 export CACHE_MAX=`lctl get_param -n llite/*/max_cached_mb | head -n 1`
3776 cleanup_101() {
3777         lctl set_param -n llite.*.max_cached_mb $CACHE_MAX
3778         trap 0
3779 }
3780
3781 test_101() {
3782         local s
3783         local discard
3784         local nreads=10000
3785         [ "$CPU" = "UML" ] && nreads=1000
3786         local cache_limit=32
3787
3788         lctl set_param -n osc.*.rpc_stats 0
3789         trap cleanup_101 EXIT
3790
3791         lctl set_param -n llite.*.read_ahead_stats 0
3792         lctl set_param -n llite.*.max_cached_mb $cache_limit
3793
3794         #
3795         # randomly read 10000 of 64K chunks from file 3x 32MB in size
3796         #
3797         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
3798         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
3799
3800         discard=0
3801         for s in `lctl get_param -n llite.*.read_ahead_stats | \
3802                 get_named_value 'read but discarded' | cut -d" " -f1`; do
3803                         discard=$(($discard + $s))
3804         done
3805         cleanup_101
3806
3807         if [ $(($discard * 10)) -gt $nreads ] ;then
3808                 lctl get_param osc.*.rpc_stats
3809                 lctl get_param llite.*.read_ahead_stats
3810                 error "too many ($discard) discarded pages"
3811         fi
3812         rm -f $DIR/$tfile || true
3813 }
3814 run_test 101 "check read-ahead for random reads ================"
3815
3816 export SETUP_TEST101b=no
3817 setup_101b() {
3818         [ "$SETUP_TEST101b" = "yes" ] && return
3819         mkdir -p $DIR/$tdir
3820         STRIPE_SIZE=1048576
3821         STRIPE_COUNT=$OSTCOUNT
3822         STRIPE_OFFSET=0
3823
3824         trap cleanup_101 EXIT
3825         # prepare the read-ahead file
3826         $SETSTRIPE $DIR/$tfile -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT
3827
3828         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
3829         SETUP_TEST101b=yes
3830 }
3831
3832 cleanup_101() {
3833         trap 0
3834         rm -rf $DIR/$tdir $DIR/$tfile
3835         SETUP_TEST101b=no
3836 }
3837
3838 calc_total() {
3839         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
3840 }
3841
3842 ra_check_101b() {
3843         local READ_SIZE=$1
3844         local STRIPE_SIZE=1048576
3845         local RA_INC=1048576
3846         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
3847         local FILE_LENGTH=$((64*100))
3848         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
3849                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
3850         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
3851                         get_named_value 'read but discarded' | \
3852                         cut -d" " -f1 | calc_total`
3853
3854         if [ $DISCARD -gt $discard_limit ]; then
3855                 lctl get_param llite.*.read_ahead_stats
3856                 error "Too many ($DISCARD) discarded pages (size ${READ_SIZE})"
3857         else
3858                 echo "Read-ahead success for size ${READ_SIZE}"
3859         fi
3860 }
3861
3862 test_101b() {
3863         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs for stride-read" && return
3864         local STRIPE_SIZE=1048576
3865         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
3866         local FILE_LENGTH=$((STRIPE_SIZE*100))
3867         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
3868         # prepare the read-ahead file
3869         setup_101b
3870         cancel_lru_locks osc
3871         for BIDX in 2 4 8 16 32 64 128 256; do
3872                 local BSIZE=$((BIDX*4096))
3873                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
3874                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
3875                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
3876                 $LCTL set_param -n llite.*.read_ahead_stats 0
3877                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
3878                         -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
3879                 cancel_lru_locks osc
3880                 ra_check_101b $BSIZE
3881         done
3882         true
3883 }
3884 run_test 101b "check stride-io mode read-ahead ================="
3885
3886 test_101c() {
3887         local STRIPE_SIZE=1048576
3888         local FILE_LENGTH=$((STRIPE_SIZE*100))
3889         local nreads=10000
3890
3891         setup_101b
3892
3893         cancel_lru_locks osc
3894         $LCTL set_param osc.*.rpc_stats 0
3895         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
3896         for OSC in `$LCTL  get_param -N osc.*`
3897         do
3898                 if [ "$OSC" == "osc.num_refs" ]; then
3899                         continue
3900                 fi
3901                 lines=`$LCTL get_param -n ${OSC}.rpc_stats | wc | awk '{print $1}'`
3902                 if [ $lines -le 20 ]; then
3903                         continue
3904                 fi
3905
3906                 rpc4k=$($LCTL get_param -n $OSC | awk '$1 == "1:" { print $2; exit; }')
3907                 rpc8k=$($LCTL get_param -n $OSC | awk '$1 == "2:" { print $2; exit; }')
3908                 rpc16k=$($LCTL get_param -n $OSC | awk '$1 == "4:" { print $2; exit; }')
3909                 rpc32k=$($LCTL get_param -n $OSC | awk '$1 == "8:" { print $2; exit; }')
3910
3911                 [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
3912                 [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
3913                 [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
3914                 [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
3915
3916                 echo "Small rpc check passed!"
3917                 rpc64k=$($LCTL get_param -n $OSC | awk '$1 == "16:" { print $2; exit; }')
3918                 rpc128k=$($LCTL get_param -n $OSC | awk '$1 == "32:" { print $2; exit; }')
3919                 rpc256k=$($LCTL get_param -n $OSC | awk '$1 == "64:" { print $2; exit; }')
3920                 rpc512k=$($LCTL get_param -n $OSC | awk '$1 == "128:" { print $2; exit; }')
3921                 rpc1024k=$($LCTL get_param -n $OSC | awk '$1 == "256:" { print $2; exit; }')
3922
3923                 [ $rpc64k == 0 ]   && error "No 64k readahead IO ${rpc64k}"
3924                 [ $rpc128k == 0 ]  && error "No 128k readahead IO ${rpc128k}"
3925                 [ $rpc256k == 0 ]  && error "No 256k readahead IO ${rpc256k}"
3926                 [ $rpc512k == 0 ]  && error "No 512k readahead IO ${rpc256k}"
3927                 [ $rpc1024k == 0 ] && error "No 1024k readahead IO ${rpc1024k}"
3928                 echo "Big rpc check passed!"
3929         done
3930         cleanup_101
3931         true
3932 }
3933 run_test 101c "check stripe_size aligned read-ahead ================="
3934
3935 set_read_ahead() {
3936    lctl get_param -n llite.*.max_read_ahead_mb | head -n 1
3937    lctl set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
3938 }
3939
3940 test_101d() {
3941     local file=$DIR/$tfile
3942     local size=${FILESIZE_101c:-500}
3943     local ra_MB=${READAHEAD_MB:-40}
3944
3945     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
3946     [ $space -gt $((size / 1024)) ] ||
3947         { skip "Need free space ${size}M, have $space" && return; }
3948
3949     echo Creating ${size}M test file $file
3950     dd if=/dev/zero of=$file bs=1M count=$size
3951     echo Cancel LRU locks on lustre client to flush the client cache
3952     cancel_lru_locks osc
3953
3954     echo Disable read-ahead
3955     local old_READAHEAD=$(set_read_ahead 0)
3956
3957     echo Reading the test file $file with read-ahead disabled
3958     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
3959
3960     echo Cancel LRU locks on lustre client to flush the client cache
3961     cancel_lru_locks osc
3962     echo Enable read-ahead with ${ra_MB}MB
3963     set_read_ahead $ra_MB
3964
3965     echo Reading the test file $file with read-ahead enabled
3966     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
3967
3968     echo read-ahead disabled time read $time_ra_OFF
3969     echo read-ahead enabled  time read $time_ra_ON
3970
3971     set_read_ahead $old_READAHEAD
3972     rm -f $file
3973
3974     [ $time_ra_ON -lt $time_ra_OFF ] ||
3975         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
3976                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
3977 }
3978 run_test 101d "file read with and without read-ahead enabled  ================="
3979
3980 export SETUP_TEST102=no
3981 setup_test102() {
3982         [ "$SETUP_TEST102" = "yes" ] && return
3983         mkdir -p $DIR/$tdir
3984         chown $RUNAS_ID $DIR/$tdir
3985         STRIPE_SIZE=65536
3986         STRIPE_OFFSET=1
3987         STRIPE_COUNT=$OSTCOUNT
3988         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
3989
3990         trap cleanup_test102 EXIT
3991         cd $DIR
3992         $1 $SETSTRIPE $tdir -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT
3993         cd $DIR/$tdir
3994         for num in 1 2 3 4
3995         do
3996                 for count in `seq 1 $STRIPE_COUNT`
3997                 do
3998                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
3999                         do
4000                                 local stripe_size=`expr $STRIPE_SIZE \* $num`
4001                                 local file=file"$num-$offset-$count"
4002                                 $1 $SETSTRIPE $file -s $stripe_size -i $offset -c $count
4003                         done
4004                 done
4005         done
4006
4007         cd $DIR
4008         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
4009         SETUP_TEST102=yes
4010 }
4011
4012 cleanup_test102() {
4013         trap 0
4014         [ "$SETUP_TEST102" = "yes" ] || return 0
4015         rm -f $TMP/f102.tar
4016         SETUP_TEST102=no
4017 }
4018
4019 test_102a() {
4020         local testfile=$DIR/xattr_testfile
4021
4022         rm -f $testfile
4023         touch $testfile
4024
4025         [ "$UID" != 0 ] && skip_env "must run as root" && return
4026         [ -z "`lctl get_param -n mdc.*.connect_flags | grep xattr`" ] &&
4027                 skip_env "must have user_xattr" && return
4028         [ -z "$(which setfattr 2>/dev/null)" ] && skip_env "could not find setfattr" && return
4029
4030         echo "set/get xattr..."
4031         setfattr -n trusted.name1 -v value1 $testfile || error
4032         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
4033         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
4034
4035         setfattr -n user.author1 -v author1 $testfile || error
4036         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
4037         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
4038
4039         echo "listxattr..."
4040         setfattr -n trusted.name2 -v value2 $testfile || error
4041         setfattr -n trusted.name3 -v value3 $testfile || error
4042         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4043         grep "trusted.name" | wc -l` -eq 3 ] || error
4044
4045
4046         setfattr -n user.author2 -v author2 $testfile || error
4047         setfattr -n user.author3 -v author3 $testfile || error
4048         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
4049         grep "user" | wc -l` -eq 3 ] || error
4050
4051         echo "remove xattr..."
4052         setfattr -x trusted.name1 $testfile || error
4053         getfattr -d -m trusted $testfile 2> /dev/null | \
4054         grep "trusted.name1" && error || true
4055
4056         setfattr -x user.author1 $testfile || error
4057         getfattr -d -m user $testfile 2> /dev/null | \
4058         grep "user.author1" && error || true
4059
4060         # b10667: setting lustre special xattr be silently discarded
4061         echo "set lustre special xattr ..."
4062         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
4063
4064         rm -f $testfile
4065 }
4066 run_test 102a "user xattr test =================================="
4067
4068 test_102b() {
4069         # b10930: get/set/list trusted.lov xattr
4070         echo "get/set/list trusted.lov xattr ..."
4071         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
4072         local testfile=$DIR/$tfile
4073         $SETSTRIPE -s 65536 -i 1 -c 2 $testfile || error "setstripe failed"
4074         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4075         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
4076
4077         local testfile2=${testfile}2
4078         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
4079                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
4080
4081         $MCREATE $testfile2
4082         setfattr -n trusted.lov -v $value $testfile2
4083         local tmp_file=${testfile}3
4084         $GETSTRIPE -v $testfile2 > $tmp_file
4085         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4086         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4087         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
4088         [ $stripe_count -eq 2 ] || error "stripe count $stripe_count != 2"
4089 }
4090 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
4091
4092 test_102c() {
4093         # b10930: get/set/list lustre.lov xattr
4094         echo "get/set/list lustre.lov xattr ..."
4095         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
4096         mkdir -p $DIR/$tdir
4097         chown $RUNAS_ID $DIR/$tdir
4098         local testfile=$DIR/$tdir/$tfile
4099         $RUNAS $SETSTRIPE -s 65536 -i 1 -c 2 $testfile||error "setstripe failed"
4100         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
4101         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
4102
4103         local testfile2=${testfile}2
4104         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
4105                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
4106
4107         $RUNAS $MCREATE $testfile2
4108         $RUNAS setfattr -n lustre.lov -v $value $testfile2
4109         local tmp_file=${testfile}3
4110         $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
4111         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4112         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4113         [ "$stripe_size" -eq 65536 ] || error "stripe size $stripe_size != 65536"
4114         [ "$stripe_count" -eq 2 ] || error "stripe count $stripe_count != 2"
4115 }
4116 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
4117
4118 compare_stripe_info1() {
4119         local stripe_index_all_zero=1
4120
4121         for num in 1 2 3 4
4122         do
4123                 for count in `seq 1 $STRIPE_COUNT`
4124                 do
4125                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4126                         do
4127                                 local size=`expr $STRIPE_SIZE \* $num`
4128                                 local file=file"$num-$offset-$count"
4129                                 get_stripe_info client $PWD/$file "$1"
4130                                 if [ $stripe_size -ne $size ]; then
4131                                         error "$file: different stripe size $stripe_size, expected $size" && return
4132                                 fi
4133                                 if [ $stripe_count -ne $count ]; then
4134                                         error "$file: different stripe count $stripe_count, expected $count" && return
4135                                 fi
4136                                 if [ $stripe_index -ne 0 ]; then
4137                                        stripe_index_all_zero=0
4138                                 fi
4139                         done
4140                 done
4141         done
4142         [ $stripe_index_all_zero -eq 1 ] && error "all files are being extracted starting from OST index 0"
4143         return 0
4144 }
4145
4146 find_lustre_tar() {
4147         [ -n "$(which tar 2>/dev/null)" ] && strings $(which tar) | grep -q lustre && echo tar
4148 }
4149
4150 test_102d() {
4151         # b10930: tar test for trusted.lov xattr
4152         TAR=$(find_lustre_tar)
4153         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4154         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4155         setup_test102
4156         mkdir -p $DIR/d102d
4157         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
4158         cd $DIR/d102d/$tdir
4159         compare_stripe_info1
4160 }
4161 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
4162
4163 test_102f() {
4164         # b10930: tar test for trusted.lov xattr
4165         TAR=$(find_lustre_tar)
4166         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4167         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4168         setup_test102
4169         mkdir -p $DIR/d102f
4170         cd $DIR
4171         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
4172         cd $DIR/d102f/$tdir
4173         compare_stripe_info1
4174 }
4175 run_test 102f "tar copy files, not keep osts ==========="
4176
4177 test_102h() { # bug 15777
4178         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
4179                 skip "must have user_xattr" && return
4180         [ -z "$(which setfattr 2>/dev/null)" ] &&
4181                 skip_env "could not find setfattr" && return
4182
4183         XBIG=trusted.big
4184         XSIZE=1024
4185         touch $DIR/$tfile
4186         VALUE=datadatadatadatadatadatadatadata
4187         while [ $(echo $VALUE | wc -c) -lt $XSIZE ]; do
4188                 VALUE="$VALUE$VALUE"
4189         done
4190         log "save $XBIG on $DIR/$tfile"
4191         setfattr -n $XBIG -v "$VALUE" $DIR/$tfile ||
4192                 error "saving $XBIG on $DIR/$tfile failed"
4193         ORIG=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4194         OSIZE=$(echo $ORIG | wc -c)
4195         [ $OSIZE -lt $XSIZE ] && error "set $XBIG too small ($OSIZE < $XSIZE)"
4196
4197         XSML=trusted.sml
4198         log "save $XSML on $DIR/$tfile"
4199         setfattr -n $XSML -v val $DIR/$tfile ||
4200                 error "saving $XSML on $DIR/$tfile failed"
4201         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4202         if [ "$NEW" != "$ORIG" ]; then
4203                 log "orig: $ORIG"
4204                 log "new: $NEW"
4205                 error "$XBIG different after saving $XSML"
4206         fi
4207
4208         log "grow $XSML on $DIR/$tfile"
4209         setfattr -n $XSML -v "$VALUE" $DIR/$tfile ||
4210                 error "growing $XSML on $DIR/$tfile failed"
4211         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4212         if [ "$NEW" != "$ORIG" ]; then
4213                 log "orig: $ORIG"
4214                 log "new: $NEW"
4215                 error "$XBIG different after growing $XSML"
4216         fi
4217         log "$XBIG still valid after growing $XSML"
4218 }
4219 run_test 102h "grow xattr from inside inode to external block"
4220
4221 test_102i() { # bug 17038
4222         touch $DIR/$tfile
4223         ln -s $DIR/$tfile $DIR/${tfile}link
4224         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
4225         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"
4226         rm -f $DIR/$tfile $DIR/${tfile}link
4227 }
4228 run_test 102i "lgetxattr test on symbolic link ============"
4229
4230 test_102j() {
4231         TAR=$(find_lustre_tar)
4232         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4233         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4234         setup_test102 "$RUNAS"
4235         mkdir -p $DIR/d102j
4236         chown $RUNAS_ID $DIR/d102j
4237         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
4238         cd $DIR/d102j/$tdir
4239         compare_stripe_info1 "$RUNAS"
4240 }
4241 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
4242
4243 cleanup_test102
4244
4245 run_acl_subtest()
4246 {
4247     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
4248     return $?
4249 }
4250
4251 test_103 () {
4252     [ "$UID" != 0 ] && skip_env "must run as root" && return
4253     [ -z "$(lctl get_param mdc.*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
4254     [ -z "$(which setfacl 2>/dev/null)" ] && skip_env "could not find setfacl" && return
4255
4256     SAVE_UMASK=`umask`
4257     umask 0022
4258     cd $DIR
4259
4260     echo "performing cp ..."
4261     run_acl_subtest cp || error
4262     echo "performing getfacl-noacl..."
4263     run_acl_subtest getfacl-noacl > /dev/null || error "getfacl-noacl test failed"
4264     echo "performing misc..."
4265     run_acl_subtest misc > /dev/null || error "misc test failed"
4266 #    XXX add back permission test when we support supplementary groups.
4267 #    echo "performing permissions..."
4268 #    run_acl_subtest permissions || error
4269     echo "performing setfacl..."
4270     run_acl_subtest setfacl > /dev/null || error "setfacl test failed"
4271
4272     # inheritance test got from HP
4273     echo "performing inheritance..."
4274     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
4275     chmod +x make-tree || error "chmod +x failed"
4276     run_acl_subtest inheritance > /dev/null || error "inheritance test failed"
4277     rm -f make-tree
4278
4279     cd $SAVE_PWD
4280     umask $SAVE_UMASK
4281 }
4282 run_test 103 "acl test ========================================="
4283
4284 test_104() {
4285         touch $DIR/$tfile
4286         lfs df || error "lfs df failed"
4287         lfs df -ih || error "lfs df -ih failed"
4288         lfs df -h $DIR || error "lfs df -h $DIR failed"
4289         lfs df -i $DIR || error "lfs df -i $DIR failed"
4290         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
4291         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
4292
4293         OSC=`lctl get_param -n devices | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
4294         lctl --device %$OSC deactivate
4295         lfs df || error "lfs df with deactivated OSC failed"
4296         lctl --device %$OSC recover
4297         lfs df || error "lfs df with reactivated OSC failed"
4298 }
4299 run_test 104 "lfs df [-ih] [path] test ========================="
4300
4301 test_105a() {
4302         # doesn't work on 2.4 kernels
4303         touch $DIR/$tfile
4304         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4305         then
4306                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
4307         else
4308                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
4309         fi
4310 }
4311 run_test 105a "flock when mounted without -o flock test ========"
4312
4313 test_105b() {
4314         touch $DIR/$tfile
4315         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4316         then
4317                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
4318         else
4319                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
4320         fi
4321 }
4322 run_test 105b "fcntl when mounted without -o flock test ========"
4323
4324 test_105c() {
4325         touch $DIR/$tfile
4326         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4327         then
4328                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
4329         else
4330                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
4331         fi
4332 }
4333 run_test 105c "lockf when mounted without -o flock test ========"
4334
4335 test_105d() { # bug 15924
4336         mkdir -p $DIR/$tdir
4337         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
4338                 skip "mount w/o flock enabled" && return
4339         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
4340         $LCTL set_param fail_loc=0x80000315
4341         flocks_test 2 $DIR/$tdir
4342 }
4343 run_test 105d "flock race (should not freeze) ========"
4344
4345 test_106() { #bug 10921
4346         mkdir -p $DIR/$tdir
4347         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
4348         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
4349 }
4350 run_test 106 "attempt exec of dir followed by chown of that dir"
4351
4352 test_107() {
4353         CDIR=`pwd`
4354         cd $DIR
4355
4356         local file=core
4357         rm -f $file
4358
4359         local save_pattern=$(sysctl -n kernel.core_pattern)
4360         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
4361         sysctl -w kernel.core_pattern=$file
4362         sysctl -w kernel.core_uses_pid=0
4363
4364         ulimit -c unlimited
4365         sleep 60 &
4366         SLEEPPID=$!
4367
4368         sleep 1
4369
4370         kill -s 11 $SLEEPPID
4371         wait $SLEEPPID
4372         if [ -e $file ]; then
4373                 size=`stat -c%s $file`
4374                 [ $size -eq 0 ] && error "Zero length core file $file"
4375         else
4376                 error "Fail to create core file $file"
4377         fi
4378         rm -f $file
4379         sysctl -w kernel.core_pattern=$save_pattern
4380         sysctl -w kernel.core_uses_pid=$save_uses_pid
4381         cd $CDIR
4382 }
4383 run_test 107 "Coredump on SIG"
4384
4385 test_115() {
4386         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4387             cut -c11-20)
4388         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
4389             return
4390         echo "Starting with $OSTIO_pre threads"
4391
4392         NUMTEST=20000
4393         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
4394         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
4395         echo "$NUMTEST creates/unlinks"
4396         mkdir -p $DIR/$tdir
4397         createmany -o $DIR/$tdir/$tfile $NUMTEST
4398         unlinkmany $DIR/$tdir/$tfile $NUMTEST
4399
4400         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4401             cut -c11-20)
4402
4403         # don't return an error
4404         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
4405             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&\
4406             echo "This may be fine, depending on what ran before this test" &&\
4407             echo "and how fast this system is." && return
4408
4409         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
4410 }
4411 run_test 115 "verify dynamic thread creation===================="
4412
4413 free_min_max () {
4414         wait_delete_completed
4415         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail))
4416         echo OST kbytes available: ${AVAIL[@]}
4417         MAXI=0; MAXV=${AVAIL[0]}
4418         MINI=0; MINV=${AVAIL[0]}
4419         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
4420             #echo OST $i: ${AVAIL[i]}kb
4421             if [ ${AVAIL[i]} -gt $MAXV ]; then
4422                 MAXV=${AVAIL[i]}; MAXI=$i
4423             fi
4424             if [ ${AVAIL[i]} -lt $MINV ]; then
4425                 MINV=${AVAIL[i]}; MINI=$i
4426             fi
4427         done
4428         echo Min free space: OST $MINI: $MINV
4429         echo Max free space: OST $MAXI: $MAXV
4430 }
4431
4432 test_116() {
4433         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
4434
4435         echo -n "Free space priority "
4436         lctl get_param -n lov.*.qos_prio_free
4437         DELAY=$(lctl get_param -n lov.*.qos_maxage | head -1 | awk '{print $1}')
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 $DELAY
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 $DELAY
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 #
6368 # tests that do cleanup/setup should be run at the end
6369 #
6370
6371 test_900() {
6372         local ls
6373         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
6374         $LCTL set_param fail_loc=0x903
6375         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
6376         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
6377                 echo "clear" > $ls
6378         done
6379         FAIL_ON_ERROR=true cleanup
6380         FAIL_ON_ERROR=true setup
6381 }
6382 run_test 900 "umount should not race with any mgc requeue thread"
6383
6384 log "cleanup: ======================================================"
6385 check_and_cleanup_lustre
6386 if [ "$I_MOUNTED" != "yes" ]; then
6387         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
6388 fi
6389
6390 echo '=========================== finished ==============================='
6391 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
6392 echo "$0: completed"