Whamcloud - gitweb
fixes for running in more user environments
[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: 4900 4900 2108 9789 3637 9789 3561 5188/5749 10764
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"27o 27q  42a  42b  42c  42d  45   68        75"}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 [ "$SLOW" = "no" ] && EXCEPT="$EXCEPT 24o 27m 36f 36g 51b 51c 63 64b 71 73 77 101 107 108"
15
16 # Tests that fail on uml, maybe elsewhere, FIXME
17 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
18 #                                    buffer i/o errs             sock spc runas
19 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 27m 27n 27o 27p 27q 27r 31d 54a  64b 99a 99b 99c 99d 99e 99f 101"
20
21 case `uname -r` in
22 2.4*) FSTYPE=${FSTYPE:-ext3};    ALWAYS_EXCEPT="$ALWAYS_EXCEPT 76"
23         [ "$CPU" = "UML" ] && ALWAYS_EXCEPT="$ALWAYS_EXCEPT 105a";;
24 2.6*) FSTYPE=${FSTYPE:-ldiskfs}; ALWAYS_EXCEPT="$ALWAYS_EXCEPT " ;;
25 *) error "unsupported kernel" ;;
26 esac
27
28 SRCDIR=`dirname $0`
29 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH:/sbin
30
31 TMP=${TMP:-/tmp}
32
33 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
34 CREATETEST=${CREATETEST:-createtest}
35 LFS=${LFS:-lfs}
36 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
37 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
38 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
39 LFIND=${LFIND:-"$LFS find"}
40 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
41 LCTL=${LCTL:-lctl}
42 MCREATE=${MCREATE:-mcreate}
43 OPENFILE=${OPENFILE:-openfile}
44 OPENUNLINK=${OPENUNLINK:-openunlink}
45 RANDOM_READS=${RANDOM_READS:-"random-reads"}
46 TOEXCL=${TOEXCL:-toexcl}
47 TRUNCATE=${TRUNCATE:-truncate}
48 MUNLINK=${MUNLINK:-munlink}
49 SOCKETSERVER=${SOCKETSERVER:-socketserver}
50 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
51 IOPENTEST1=${IOPENTEST1:-iopentest1}
52 IOPENTEST2=${IOPENTEST2:-iopentest2}
53 MEMHOG=${MEMHOG:-memhog}
54 DIRECTIO=${DIRECTIO:-directio}
55 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
56 UMOUNT=${UMOUNT:-"umount -d"}
57
58 if [ $UID -ne 0 ]; then
59         echo "Warning: running as non-root uid $UID"
60         RUNAS_ID="$UID"
61         RUNAS=""
62 else
63         RUNAS_ID=${RUNAS_ID:-500}
64         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
65
66         # $RUNAS_ID may get set incorrectly somewhere else
67         if [ $RUNAS_ID -eq 0 ]; then
68                 echo "Error: \$RUNAS_ID set to 0, but \$UID is also 0!"
69                 exit 1
70         fi
71 fi
72
73 SANITYLOG=${SANITYLOG:-/tmp/sanity.log}
74
75 export NAME=${NAME:-local}
76
77 SAVE_PWD=$PWD
78
79 LUSTRE=${LUSTRE:-`dirname $0`/..}
80 . $LUSTRE/tests/test-framework.sh
81 init_test_env $@
82 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
83
84 cleanup() {
85         echo -n "cln.."
86         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
87 }
88 CLEANUP=${CLEANUP:-:}
89
90 setup() {
91         echo -n "mnt.."
92         load_modules
93         setupall || exit 10
94         echo "done"
95 }
96 SETUP=${SETUP:-:}
97
98 log() {
99         echo "$*"
100         $LCTL mark "$*" 2> /dev/null || true
101 }
102
103 trace() {
104         log "STARTING: $*"
105         strace -o $TMP/$1.strace -ttt $*
106         RC=$?
107         log "FINISHED: $*: rc $RC"
108         return 1
109 }
110 TRACE=${TRACE:-""}
111
112 check_kernel_version() {
113         VERSION_FILE=$LPROC/version
114         WANT_VER=$1
115         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
116         GOT_VER=$(awk '/kernel:/ {print $2}' $VERSION_FILE)
117         [ $GOT_VER == "patchless" ] && return 0
118         [ $GOT_VER -ge $WANT_VER ] && return 0
119         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
120         return 1
121 }
122
123 _basetest() {
124     echo $*
125 }
126
127 basetest() {
128     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
129 }
130
131 run_one() {
132         if ! grep -q $DIR /proc/mounts; then
133                 $SETUP
134         fi
135         testnum=$1
136         message=$2
137         BEFORE=`date +%s`
138         log "== test $testnum: $message= `date +%H:%M:%S` ($BEFORE)"
139         export TESTNAME=test_$testnum
140         export tfile=f${testnum}
141         export tdir=d${base}
142         test_${testnum} || error "exit with rc=$?"
143         unset TESTNAME
144         pass "($((`date +%s` - $BEFORE))s)"
145         cd $SAVE_PWD
146         $CLEANUP
147 }
148
149 build_test_filter() {
150         [ "$ALWAYS_EXCEPT$EXCEPT$SANITY_EXCEPT" ] && \
151             echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT $SANITY_EXCEPT`"
152
153         for O in $ONLY; do
154             eval ONLY_${O}=true
155         done
156         for E in $EXCEPT $ALWAYS_EXCEPT $SANITY_EXCEPT; do
157             eval EXCEPT_${E}=true
158         done
159 }
160
161 _basetest() {
162         echo $*
163 }
164
165 basetest() {
166         IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
167 }
168
169 run_test() {
170          export base=`basetest $1`
171          if [ "$ONLY" ]; then
172                  testname=ONLY_$1
173                  if [ ${!testname}x != x ]; then
174                         run_one $1 "$2"
175                         return $?
176                  fi
177                  testname=ONLY_$base
178                  if [ ${!testname}x != x ]; then
179                          run_one $1 "$2"
180                          return $?
181                  fi
182                  echo -n "."
183                  return 0
184         fi
185         testname=EXCEPT_$1
186         if [ ${!testname}x != x ]; then
187                  echo "skipping excluded test $1"
188                  return 0
189         fi
190         testname=EXCEPT_$base
191         if [ ${!testname}x != x ]; then
192                  echo "skipping excluded test $1 (base $base)"
193                  return 0
194         fi
195         run_one $1 "$2"
196         return $?
197 }
198
199 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
200
201 error() { 
202         sysctl -w lustre.fail_loc=0
203         log "$0: FAIL: $TESTNAME $@"
204         $LCTL dk $TMP/lustre-log-$TESTNAME.log
205         if [ "$SANITYLOG" ]; then
206                 echo "$0: FAIL: $TESTNAME $@" >> $SANITYLOG
207         else
208                 exit 1
209         fi
210         sysctl -w lustre.fail_loc=0
211 }
212
213 pass() { 
214         echo PASS $@
215 }
216
217 mounted_lustre_filesystems() {
218         awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
219 }
220
221 MOUNTED="`mounted_lustre_filesystems`"
222 if [ -z "$MOUNTED" ]; then
223         formatall
224         setupall
225         MOUNTED="`mounted_lustre_filesystems`"
226         [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
227         I_MOUNTED=yes
228 fi
229
230 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
231
232 DIR=${DIR:-$MOUNT}
233 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
234
235 LOVNAME=`cat $LPROC/llite/*/lov/common_name | tail -n 1`
236 OSTCOUNT=`cat $LPROC/lov/$LOVNAME/numobd`
237 STRIPECOUNT=`cat $LPROC/lov/$LOVNAME/stripecount`
238 STRIPESIZE=`cat $LPROC/lov/$LOVNAME/stripesize`
239 ORIGFREE=`cat $LPROC/lov/$LOVNAME/kbytesavail`
240 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
241 MDS=$(\ls $LPROC/mds 2> /dev/null | grep -v num_refs | tail -n 1)
242
243 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
244 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
245 rm -rf $DIR/[Rdfs][1-9]*
246
247 build_test_filter
248
249 echo "preparing for tests involving mounts"
250 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
251 touch $EXT2_DEV
252 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
253 echo # add a newline after mke2fs.
254
255 umask 077
256
257 test_0() {
258         touch $DIR/$tfile
259         $CHECKSTAT -t file $DIR/$tfile || error
260         rm $DIR/$tfile
261         $CHECKSTAT -a $DIR/$tfile || error
262 }
263 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
264
265 test_0b() {
266         chmod 0755 $DIR || error
267         $CHECKSTAT -p 0755 $DIR || error
268 }
269 run_test 0b "chmod 0755 $DIR ============================="
270
271 test_1a() {
272         mkdir $DIR/d1
273         mkdir $DIR/d1/d2
274         $CHECKSTAT -t dir $DIR/d1/d2 || error
275 }
276 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
277
278 test_1b() {
279         rmdir $DIR/d1/d2
280         rmdir $DIR/d1
281         $CHECKSTAT -a $DIR/d1 || error
282 }
283 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
284
285 test_2a() {
286         mkdir $DIR/d2
287         touch $DIR/d2/f
288         $CHECKSTAT -t file $DIR/d2/f || error
289 }
290 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
291
292 test_2b() {
293         rm -r $DIR/d2
294         $CHECKSTAT -a $DIR/d2 || error
295 }
296 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
297
298 test_3a() {
299         mkdir $DIR/d3
300         $CHECKSTAT -t dir $DIR/d3 || error
301 }
302 run_test 3a "mkdir .../d3 ======================================"
303
304 test_3b() {
305         if [ ! -d $DIR/d3 ]; then
306                 mkdir $DIR/d3
307         fi
308         touch $DIR/d3/f
309         $CHECKSTAT -t file $DIR/d3/f || error
310 }
311 run_test 3b "touch .../d3/f ===================================="
312
313 test_3c() {
314         rm -r $DIR/d3
315         $CHECKSTAT -a $DIR/d3 || error
316 }
317 run_test 3c "rm -r .../d3 ======================================"
318
319 test_4a() {
320         mkdir $DIR/d4
321         $CHECKSTAT -t dir $DIR/d4 || error
322 }
323 run_test 4a "mkdir .../d4 ======================================"
324
325 test_4b() {
326         if [ ! -d $DIR/d4 ]; then
327                 mkdir $DIR/d4
328         fi
329         mkdir $DIR/d4/d2
330         $CHECKSTAT -t dir $DIR/d4/d2 || error
331 }
332 run_test 4b "mkdir .../d4/d2 ==================================="
333
334 test_5() {
335         mkdir $DIR/d5
336         mkdir $DIR/d5/d2
337         chmod 0707 $DIR/d5/d2
338         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
339 }
340 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
341
342 test_6a() {
343         touch $DIR/f6a
344         chmod 0666 $DIR/f6a || error
345         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
346 }
347 run_test 6a "touch .../f6a; chmod .../f6a ======================"
348
349 test_6b() {
350         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
351         if [ ! -f $DIR/f6a ]; then
352                 touch $DIR/f6a
353                 chmod 0666 $DIR/f6a
354         fi
355         $RUNAS chmod 0444 $DIR/f6a && error
356         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
357 }
358 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
359
360 test_6c() {
361         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
362         touch $DIR/f6c
363         chown $RUNAS_ID $DIR/f6c || error
364         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
365 }
366 run_test 6c "touch .../f6c; chown .../f6c ======================"
367
368 test_6d() {
369         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
370         if [ ! -f $DIR/f6c ]; then
371                 touch $DIR/f6c
372                 chown $RUNAS_ID $DIR/f6c
373         fi
374         $RUNAS chown $UID $DIR/f6c && error
375         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
376 }
377 run_test 6d "$RUNAS chown .../f6c (should return error) =="
378
379 test_6e() {
380         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
381         touch $DIR/f6e
382         chgrp $RUNAS_ID $DIR/f6e || error
383         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
384 }
385 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
386
387 test_6f() {
388         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
389         if [ ! -f $DIR/f6e ]; then
390                 touch $DIR/f6e
391                 chgrp $RUNAS_ID $DIR/f6e
392         fi
393         $RUNAS chgrp $UID $DIR/f6e && error
394         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
395 }
396 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
397
398 test_6g() {
399         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
400         mkdir $DIR/d6g || error
401         chmod 777 $DIR/d6g || error
402         $RUNAS mkdir $DIR/d6g/d || error
403         chmod g+s $DIR/d6g/d || error
404         mkdir $DIR/d6g/d/subdir
405         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
406 }
407 run_test 6g "Is new dir in sgid dir inheriting group?"
408
409 test_6h() { # bug 7331
410         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
411         touch $DIR/f6h || error "touch failed"
412         chown $RUNAS_ID:$RUNAS_ID $DIR/f6h || error "initial chown failed"
413         $RUNAS -G$RUNAS_ID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
414         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_ID $DIR/f6h || error
415 }
416 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
417
418 test_7a() {
419         mkdir $DIR/d7
420         $MCREATE $DIR/d7/f
421         chmod 0666 $DIR/d7/f
422         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
423 }
424 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
425
426 test_7b() {
427         if [ ! -d $DIR/d7 ]; then
428                 mkdir $DIR/d7
429         fi
430         $MCREATE $DIR/d7/f2
431         echo -n foo > $DIR/d7/f2
432         [ "`cat $DIR/d7/f2`" = "foo" ] || error
433         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
434 }
435 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
436
437 test_8() {
438         mkdir $DIR/d8
439         touch $DIR/d8/f
440         chmod 0666 $DIR/d8/f
441         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
442 }
443 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
444
445 test_9() {
446         mkdir $DIR/d9
447         mkdir $DIR/d9/d2
448         mkdir $DIR/d9/d2/d3
449         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
450 }
451 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
452
453 test_10() {
454         mkdir $DIR/d10
455         mkdir $DIR/d10/d2
456         touch $DIR/d10/d2/f
457         $CHECKSTAT -t file $DIR/d10/d2/f || error
458 }
459 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
460
461 test_11() {
462         mkdir $DIR/d11
463         mkdir $DIR/d11/d2
464         chmod 0666 $DIR/d11/d2
465         chmod 0705 $DIR/d11/d2
466         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
467 }
468 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
469
470 test_12() {
471         mkdir $DIR/d12
472         touch $DIR/d12/f
473         chmod 0666 $DIR/d12/f
474         chmod 0654 $DIR/d12/f
475         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
476 }
477 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
478
479 test_13() {
480         mkdir $DIR/d13
481         dd if=/dev/zero of=$DIR/d13/f count=10
482         >  $DIR/d13/f
483         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
484 }
485 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
486
487 test_14() {
488         mkdir $DIR/d14
489         touch $DIR/d14/f
490         rm $DIR/d14/f
491         $CHECKSTAT -a $DIR/d14/f || error
492 }
493 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
494
495 test_15() {
496         mkdir $DIR/d15
497         touch $DIR/d15/f
498         mv $DIR/d15/f $DIR/d15/f2
499         $CHECKSTAT -t file $DIR/d15/f2 || error
500 }
501 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
502
503 test_16() {
504         mkdir $DIR/d16
505         touch $DIR/d16/f
506         rm -rf $DIR/d16/f
507         $CHECKSTAT -a $DIR/d16/f || error
508 }
509 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
510
511 test_17a() {
512         mkdir -p $DIR/d17
513         touch $DIR/d17/f
514         ln -s $DIR/d17/f $DIR/d17/l-exist
515         ls -l $DIR/d17
516         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
517         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
518         rm -f $DIR/d17/l-exist
519         $CHECKSTAT -a $DIR/d17/l-exist || error
520 }
521 run_test 17a "symlinks: create, remove (real) =================="
522
523 test_17b() {
524         mkdir -p $DIR/d17
525         ln -s no-such-file $DIR/d17/l-dangle
526         ls -l $DIR/d17
527         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
528         $CHECKSTAT -fa $DIR/d17/l-dangle || error
529         rm -f $DIR/d17/l-dangle
530         $CHECKSTAT -a $DIR/d17/l-dangle || error
531 }
532 run_test 17b "symlinks: create, remove (dangling) =============="
533
534 test_17c() { # bug 3440 - don't save failed open RPC for replay
535         mkdir -p $DIR/d17
536         ln -s foo $DIR/d17/f17c
537         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
538 }
539 run_test 17c "symlinks: open dangling (should return error) ===="
540
541 test_17d() {
542         mkdir -p $DIR/d17
543         ln -s foo $DIR/d17/f17d
544         touch $DIR/d17/f17d || error "creating to new symlink"
545 }
546 run_test 17d "symlinks: create dangling ========================"
547
548 test_18() {
549         touch $DIR/f
550         ls $DIR || error
551 }
552 run_test 18 "touch .../f ; ls ... =============================="
553
554 test_19a() {
555         touch $DIR/f19
556         ls -l $DIR
557         rm $DIR/f19
558         $CHECKSTAT -a $DIR/f19 || error
559 }
560 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
561
562 test_19b() {
563         ls -l $DIR/f19 && error || true
564 }
565 run_test 19b "ls -l .../f19 (should return error) =============="
566
567 test_19c() {
568         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
569         $RUNAS touch $DIR/f19 && error || true
570 }
571 run_test 19c "$RUNAS touch .../f19 (should return error) =="
572
573 test_19d() {
574         cat $DIR/f19 && error || true
575 }
576 run_test 19d "cat .../f19 (should return error) =============="
577
578 test_20() {
579         touch $DIR/f
580         rm $DIR/f
581         log "1 done"
582         touch $DIR/f
583         rm $DIR/f
584         log "2 done"
585         touch $DIR/f
586         rm $DIR/f
587         log "3 done"
588         $CHECKSTAT -a $DIR/f || error
589 }
590 run_test 20 "touch .../f ; ls -l ... ==========================="
591
592 test_21() {
593         mkdir $DIR/d21
594         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
595         ln -s dangle $DIR/d21/link
596         echo foo >> $DIR/d21/link
597         cat $DIR/d21/dangle
598         $CHECKSTAT -t link $DIR/d21/link || error
599         $CHECKSTAT -f -t file $DIR/d21/link || error
600 }
601 run_test 21 "write to dangling link ============================"
602
603 test_22() {
604         mkdir $DIR/d22
605         chown $RUNAS_ID $DIR/d22
606         # Tar gets pissy if it can't access $PWD *sigh*
607         (cd $TMP || error "cd $TMP failed";
608         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
609         $RUNAS tar xfC - $DIR/d22)
610         ls -lR $DIR/d22/etc || error "ls -lR $DIR/d22/etc failed"
611         $CHECKSTAT -t dir $DIR/d22/etc || error "checkstat -t dir failed"
612         $CHECKSTAT -u \#$RUNAS_ID $DIR/d22/etc || error "checkstat -u failed"
613 }
614 run_test 22 "unpack tar archive as non-root user ==============="
615
616 test_23() {
617         mkdir $DIR/d23
618         $TOEXCL $DIR/d23/f23
619         $TOEXCL -e $DIR/d23/f23 || error
620 }
621 run_test 23 "O_CREAT|O_EXCL in subdir =========================="
622
623 test_24a() {
624         echo '== rename sanity =============================================='
625         echo '-- same directory rename'
626         mkdir $DIR/R1
627         touch $DIR/R1/f
628         mv $DIR/R1/f $DIR/R1/g
629         $CHECKSTAT -t file $DIR/R1/g || error
630 }
631 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
632
633 test_24b() {
634         mkdir $DIR/R2
635         touch $DIR/R2/{f,g}
636         mv $DIR/R2/f $DIR/R2/g
637         $CHECKSTAT -a $DIR/R2/f || error
638         $CHECKSTAT -t file $DIR/R2/g || error
639 }
640 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
641
642 test_24c() {
643         mkdir $DIR/R3
644         mkdir $DIR/R3/f
645         mv $DIR/R3/f $DIR/R3/g
646         $CHECKSTAT -a $DIR/R3/f || error
647         $CHECKSTAT -t dir $DIR/R3/g || error
648 }
649 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
650
651 test_24d() {
652         mkdir $DIR/R4
653         mkdir $DIR/R4/{f,g}
654         mrename $DIR/R4/f $DIR/R4/g
655         $CHECKSTAT -a $DIR/R4/f || error
656         $CHECKSTAT -t dir $DIR/R4/g || error
657 }
658 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
659
660 test_24e() {
661         echo '-- cross directory renames --' 
662         mkdir $DIR/R5{a,b}
663         touch $DIR/R5a/f
664         mv $DIR/R5a/f $DIR/R5b/g
665         $CHECKSTAT -a $DIR/R5a/f || error
666         $CHECKSTAT -t file $DIR/R5b/g || error
667 }
668 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
669
670 test_24f() {
671         mkdir $DIR/R6{a,b}
672         touch $DIR/R6a/f $DIR/R6b/g
673         mv $DIR/R6a/f $DIR/R6b/g
674         $CHECKSTAT -a $DIR/R6a/f || error
675         $CHECKSTAT -t file $DIR/R6b/g || error
676 }
677 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
678
679 test_24g() {
680         mkdir $DIR/R7{a,b}
681         mkdir $DIR/R7a/d
682         mv $DIR/R7a/d $DIR/R7b/e
683         $CHECKSTAT -a $DIR/R7a/d || error
684         $CHECKSTAT -t dir $DIR/R7b/e || error
685 }
686 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R5b/e ======"
687
688 test_24h() {
689         mkdir $DIR/R8{a,b}
690         mkdir $DIR/R8a/d $DIR/R8b/e
691         mrename $DIR/R8a/d $DIR/R8b/e
692         $CHECKSTAT -a $DIR/R8a/d || error
693         $CHECKSTAT -t dir $DIR/R8b/e || error
694 }
695 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
696
697 test_24i() {
698         echo "-- rename error cases"
699         mkdir $DIR/R9
700         mkdir $DIR/R9/a
701         touch $DIR/R9/f
702         mrename $DIR/R9/f $DIR/R9/a
703         $CHECKSTAT -t file $DIR/R9/f || error
704         $CHECKSTAT -t dir  $DIR/R9/a || error
705         $CHECKSTAT -a file $DIR/R9/a/f || error
706 }
707 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
708
709 test_24j() {
710         mkdir $DIR/R10
711         mrename $DIR/R10/f $DIR/R10/g
712         $CHECKSTAT -t dir $DIR/R10 || error
713         $CHECKSTAT -a $DIR/R10/f || error
714         $CHECKSTAT -a $DIR/R10/g || error
715 }
716 run_test 24j "source does not exist ============================" 
717
718 test_24k() {
719         mkdir $DIR/R11a $DIR/R11a/d
720         touch $DIR/R11a/f
721         mv $DIR/R11a/f $DIR/R11a/d
722         $CHECKSTAT -a $DIR/R11a/f || error
723         $CHECKSTAT -t file $DIR/R11a/d/f || error
724 }
725 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
726
727 # bug 2429 - rename foo foo foo creates invalid file
728 test_24l() {
729         f="$DIR/f24l"
730         multiop $f OcNs || error
731 }
732 run_test 24l "Renaming a file to itself ========================"
733
734 test_24m() {
735         f="$DIR/f24m"
736         multiop $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
737         # on ext3 this does not remove either the source or target files
738         # though the "expected" operation would be to remove the source
739         $CHECKSTAT -t file ${f} || error "${f} missing"
740         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
741 }
742 run_test 24m "Renaming a file to a hard link to itself ========="
743
744 test_24n() {
745     f="$DIR/f24n"
746     # this stats the old file after it was renamed, so it should fail
747     touch ${f}
748     $CHECKSTAT ${f}
749     mv ${f} ${f}.rename
750     $CHECKSTAT ${f}.rename
751     $CHECKSTAT -a ${f}
752 }
753 run_test 24n "Statting the old file after renaming (Posix rename 2)"
754
755 test_24o() {
756         check_kernel_version 37 || return 0
757         mkdir -p $DIR/d24o
758         rename_many -s random -v -n 10 $DIR/d24o
759 }
760 run_test 24o "rename of files during htree split ==============="
761
762 test_24p() {
763         mkdir $DIR/R12{a,b}
764         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
765         mrename $DIR/R12a $DIR/R12b
766         $CHECKSTAT -a $DIR/R12a || error
767         $CHECKSTAT -t dir $DIR/R12b || error
768         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
769         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
770 }
771 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
772
773 test_24q() {
774         mkdir $DIR/R13{a,b}
775         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
776         multiop $DIR/R13b D_c &
777         MULTIPID=$!
778         usleep 500
779
780         mrename $DIR/R13a $DIR/R13b
781         $CHECKSTAT -a $DIR/R13a || error
782         $CHECKSTAT -t dir $DIR/R13b || error
783         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
784         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
785         kill -USR1 $MULTIPID
786         wait $MULTIPID || error "multiop close failed"
787 }
788 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
789
790 test_24r() { #bug 3789
791         mkdir $DIR/R14a $DIR/R14a/b
792         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
793         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
794         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
795 }
796 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
797
798 test_24s() {
799         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
800         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
801         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
802         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
803 }
804 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
805 test_24t() {
806         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
807         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
808         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
809         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
810 }
811 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
812
813 test_25a() {
814         echo '== symlink sanity ============================================='
815
816         mkdir $DIR/d25
817         ln -s d25 $DIR/s25
818         touch $DIR/s25/foo || error
819 }
820 run_test 25a "create file in symlinked directory ==============="
821
822 test_25b() {
823         [ ! -d $DIR/d25 ] && test_25a
824         $CHECKSTAT -t file $DIR/s25/foo || error
825 }
826 run_test 25b "lookup file in symlinked directory ==============="
827
828 test_26a() {
829         mkdir $DIR/d26
830         mkdir $DIR/d26/d26-2
831         ln -s d26/d26-2 $DIR/s26
832         touch $DIR/s26/foo || error
833 }
834 run_test 26a "multiple component symlink ======================="
835
836 test_26b() {
837         mkdir -p $DIR/d26b/d26-2
838         ln -s d26b/d26-2/foo $DIR/s26-2
839         touch $DIR/s26-2 || error
840 }
841 run_test 26b "multiple component symlink at end of lookup ======"
842
843 test_26c() {
844         mkdir $DIR/d26.2
845         touch $DIR/d26.2/foo
846         ln -s d26.2 $DIR/s26.2-1
847         ln -s s26.2-1 $DIR/s26.2-2
848         ln -s s26.2-2 $DIR/s26.2-3
849         chmod 0666 $DIR/s26.2-3/foo
850 }
851 run_test 26c "chain of symlinks ================================"
852
853 # recursive symlinks (bug 439)
854 test_26d() {
855         ln -s d26-3/foo $DIR/d26-3
856 }
857 run_test 26d "create multiple component recursive symlink ======"
858
859 test_26e() {
860         [ ! -h $DIR/d26-3 ] && test_26d
861         rm $DIR/d26-3
862 }
863 run_test 26e "unlink multiple component recursive symlink ======"
864
865 # recursive symlinks (bug 7022)
866 test_26f() {
867         mkdir $DIR/$tfile        || error "mkdir $DIR/$tfile failed"
868         cd $DIR/$tfile           || error "cd $DIR/$tfile failed"
869         mkdir -p $tdir/bar1      || error "mkdir $tdir/bar1 failed"
870         mkdir $tfile             || error "mkdir $tfile failed"
871         cd $tfile                || error "cd $tfile failed"
872         ln -s .. dotdot          || error "ln dotdot failed"
873         ln -s dotdot/$tdir $tdir || error "ln $tdir failed"
874         cd ../..                 || error "cd ../.. failed"
875         output=`ls $tfile/$tfile/$tdir/bar1`
876         [ "$output" = bar1 ] && error "unexpected output"
877         rm -r $tfile             || error "rm $tfile failed"
878         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
879 }
880 run_test 26f "rm -r of a directory which has recursive symlink ="
881
882 test_27a() {
883         echo '== stripe sanity =============================================='
884         mkdir -p $DIR/d27 || error "mkdir failed"
885         $SETSTRIPE $DIR/d27/f0 65536 0 1 || error "lstripe failed"
886         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
887         pass
888         log "== test_27b: write to one stripe file ========================="
889         cp /etc/hosts $DIR/d27/f0 || error
890 }
891 run_test 27a "one stripe file =================================="
892
893 test_27c() {
894         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
895         mkdir -p $DIR/d27
896         $SETSTRIPE $DIR/d27/f01 65536 0 2 || error "lstripe failed"
897         [ `$GETSTRIPE $DIR/d27/f01 | grep -A 10 obdidx | wc -l` -eq 4 ] ||
898                 error "two-stripe file doesn't have two stripes"
899         pass
900         log "== test_27d: write to two stripe file file f01 ================"
901         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
902 }
903 run_test 27c "create two stripe file f01 ======================="
904
905 test_27d() {
906         mkdir -p $DIR/d27
907         $SETSTRIPE $DIR/d27/fdef 0 -1 0 || error "lstripe failed"
908         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
909         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
910 }
911 run_test 27d "create file with default settings ================"
912
913 test_27e() {
914         mkdir -p $DIR/d27
915         $SETSTRIPE $DIR/d27/f12 65536 0 2 || error "lstripe failed"
916         $SETSTRIPE $DIR/d27/f12 65536 0 2 && error "lstripe succeeded twice"
917         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
918 }
919 run_test 27e "lstripe existing file (should return error) ======"
920
921 test_27f() {
922         mkdir -p $DIR/d27
923         $SETSTRIPE $DIR/d27/fbad 100 0 1 && error "lstripe failed"
924         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
925         $GETSTRIPE $DIR/d27/fbad || error "lfs getstripe failed"
926 }
927 run_test 27f "lstripe with bad stripe size (should return error)"
928
929 test_27g() {
930         mkdir -p $DIR/d27
931         $MCREATE $DIR/d27/fnone || error "mcreate failed"
932         pass
933         log "== test 27h: lfs getstripe with no objects ===================="
934         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" || error "has object"
935         pass
936         log "== test 27i: lfs getstripe with some objects =================="
937         touch $DIR/d27/fsome || error "touch failed"
938         $GETSTRIPE $DIR/d27/fsome | grep obdidx || error "missing objects"
939 }
940 run_test 27g "test lfs getstripe ==========================================="
941
942 test_27j() {
943         mkdir -p $DIR/d27
944         $SETSTRIPE $DIR/d27/f27j 65536 $OSTCOUNT 1 && error "lstripe failed"||true
945 }
946 run_test 27j "lstripe with bad stripe offset (should return error)"
947
948 test_27k() { # bug 2844
949         mkdir -p $DIR/d27
950         FILE=$DIR/d27/f27k
951         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
952         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
953         $SETSTRIPE $FILE 67108864 -1 0 || error "lstripe failed"
954         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
955         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
956         dd if=/dev/zero of=$FILE bs=4k count=1
957         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
958         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
959 }
960 run_test 27k "limit i_blksize for broken user apps ============="
961
962 test_27l() {
963         mkdir -p $DIR/d27
964         mcreate $DIR/f27l || error "creating file"
965         $RUNAS $SETSTRIPE $DIR/f27l 65536 -1 1 && \
966                 error "lstripe should have failed" || true
967 }
968 run_test 27l "check setstripe permissions (should return error)"
969
970 test_27m() {
971         [ "$OSTCOUNT" -lt "2" ] && echo "skipping out-of-space test on OST0" && return
972         if [ $ORIGFREE -gt $MAXFREE ]; then
973                 echo "skipping out-of-space test on OST0"
974                 return
975         fi
976         mkdir -p $DIR/d27
977         $SETSTRIPE $DIR/d27/f27m_1 0 0 1
978         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE && \
979                 error "dd should fill OST0"
980         i=2
981         while $SETSTRIPE $DIR/d27/f27m_$i 0 0 1 ; do
982                 i=`expr $i + 1`
983                 [ $i -gt 256 ] && break
984         done
985         i=`expr $i + 1`
986         touch $DIR/d27/f27m_$i
987         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
988                 error "OST0 was full but new created file still use it"
989         i=`expr $i + 1`
990         touch $DIR/d27/f27m_$i
991         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
992                 error "OST0 was full but new created file still use it"
993         rm -r $DIR/d27
994 }
995 run_test 27m "create file while OST0 was full =================="
996
997 # osc's keep a NOSPC stick flag that gets unset with rmdir
998 reset_enospc() {
999         [ "$1" ] && FAIL_LOC=$1 || FAIL_LOC=0
1000         mkdir -p $DIR/d27/nospc
1001         rmdir $DIR/d27/nospc
1002         sysctl -w lustre.fail_loc=$FAIL_LOC
1003 }
1004
1005 exhaust_precreations() {
1006         OSTIDX=$1
1007         OST=$(grep ${OSTIDX}": " $LPROC/lov/${LOVNAME}/target_obd | \
1008             awk '{print $2}' | sed -e 's/_UUID$//')
1009         # on the mdt's osc
1010         last_id=$(cat $LPROC/osc/${OST}-osc/prealloc_last_id)
1011         next_id=$(cat $LPROC/osc/${OST}-osc/prealloc_next_id)
1012
1013         mkdir -p $DIR/d27/${OST}
1014         $SETSTRIPE $DIR/d27/${OST} 0 $OSTIDX 1
1015 #define OBD_FAIL_OST_ENOSPC              0x215
1016         sysctl -w lustre.fail_loc=0x215
1017         echo "Creating to objid $last_id on ost $OST..."
1018         createmany -o $DIR/d27/${OST}/f $next_id $((last_id - next_id + 2))
1019         grep '[0-9]' $LPROC/osc/${OST}-osc/prealloc*
1020         reset_enospc $2
1021 }
1022
1023 exhaust_all_precreations() {
1024         local i
1025         for (( i=0; i < OSTCOUNT; i++ )) ; do
1026                 exhaust_precreations $i 0x215
1027         done
1028         reset_enospc $1
1029 }
1030
1031 test_27n() {
1032         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && \
1033                 echo "skip $TESTNAME for remote MDS or OST count" && return
1034
1035         reset_enospc
1036         rm -f $DIR/d27/f27n
1037         exhaust_precreations 0 0x80000215
1038
1039         touch $DIR/d27/f27n || error
1040
1041         reset_enospc
1042 }
1043 run_test 27n "create file with some full OSTs =================="
1044
1045 test_27o() {
1046         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1047
1048         reset_enospc
1049         rm -f $DIR/d27/f27o
1050         exhaust_all_precreations 0x215
1051         sleep 5
1052
1053         touch $DIR/d27/f27o && error "able to create $DIR/d27/f27o"
1054
1055         reset_enospc
1056 }
1057 run_test 27o "create file with all full OSTs (should error) ===="
1058
1059 test_27p() {
1060         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1061
1062         reset_enospc
1063         rm -f $DIR/d27/f27p
1064
1065         $MCREATE $DIR/d27/f27p || error
1066         $TRUNCATE $DIR/d27/f27p 80000000 || error
1067         $CHECKSTAT -s 80000000 $DIR/d27/f27p || error
1068
1069         exhaust_precreations 0 0x80000215
1070         echo foo >> $DIR/d27/f27p || error
1071         $CHECKSTAT -s 80000004 $DIR/d27/f27p || error
1072
1073         reset_enospc
1074 }
1075 run_test 27p "append to a truncated file with some full OSTs ==="
1076
1077 test_27q() {
1078         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1079
1080         reset_enospc
1081         rm -f $DIR/d27/f27q
1082
1083         $MCREATE $DIR/d27/f27q || error "mcreate $DIR/d27/f27q failed"
1084         $TRUNCATE $DIR/d27/f27q 80000000 ||error "truncate $DIR/d27/f27q failed"
1085         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat failed"
1086
1087         exhaust_all_precreations 0x215
1088
1089         echo foo >> $DIR/d27/f27q && error "append succeeded"
1090         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat 2 failed"
1091
1092         reset_enospc
1093 }
1094 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1095
1096 test_27r() {
1097         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1098
1099         reset_enospc
1100         rm -f $DIR/d27/f27r
1101         exhaust_precreations 0 0x80000215
1102
1103         $SETSTRIPE $DIR/d27/f27r 0 0 2 # && error
1104
1105         reset_enospc
1106 }
1107 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1108
1109 test_27s() { # bug 10725
1110         mkdir -p $DIR/$tdir
1111         $LSTRIPE $DIR/$tdir $((2048 * 1024 * 1024)) -1 2 && \
1112                 error "stripe width >= 2^32 succeeded" || true
1113 }
1114 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1115
1116 test_27t() { # bug 10864
1117         WDIR=`pwd`
1118         WLFS=`which lfs`
1119         cd $DIR
1120         touch $tfile
1121         $WLFS getstripe $tfile
1122         cd $WDIR
1123 }
1124 run_test 27t "check that utils parse path correctly"
1125
1126 test_28() {
1127         mkdir $DIR/d28
1128         $CREATETEST $DIR/d28/ct || error
1129 }
1130 run_test 28 "create/mknod/mkdir with bad file types ============"
1131
1132 test_29() {
1133         cancel_lru_locks mdc
1134         mkdir $DIR/d29
1135         touch $DIR/d29/foo
1136         log 'first d29'
1137         ls -l $DIR/d29
1138         MDCDIR=${MDCDIR:-`find $LPROC/ldlm/namespaces | grep mdc | head -1`}
1139         LOCKCOUNTORIG=`cat $MDCDIR/lock_count`
1140         LOCKUNUSEDCOUNTORIG=`cat $MDCDIR/lock_unused_count`
1141         [ -z $"LOCKCOUNTORIG" ] && echo "No mdc lock count" && return 1
1142         log 'second d29'
1143         ls -l $DIR/d29
1144         log 'done'
1145         LOCKCOUNTCURRENT=`cat $MDCDIR/lock_count`
1146         LOCKUNUSEDCOUNTCURRENT=`cat $MDCDIR/lock_unused_count`
1147         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1148                 echo > $LPROC/ldlm/dump_namespaces
1149                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1150                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1151                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1152                 return 2
1153         fi
1154         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1155                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1156                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1157                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1158                 return 3
1159         fi
1160 }
1161 run_test 29 "IT_GETATTR regression  ============================"
1162
1163 test_30() {
1164         cp `which ls` $DIR
1165         $DIR/ls /
1166         rm $DIR/ls
1167 }
1168 run_test 30 "run binary from Lustre (execve) ==================="
1169
1170 test_31a() {
1171         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1172         $CHECKSTAT -a $DIR/f31 || error
1173 }
1174 run_test 31a "open-unlink file =================================="
1175
1176 test_31b() {
1177         touch $DIR/f31 || error
1178         ln $DIR/f31 $DIR/f31b || error
1179         multiop $DIR/f31b Ouc || error
1180         $CHECKSTAT -t file $DIR/f31 || error
1181 }
1182 run_test 31b "unlink file with multiple links while open ======="
1183
1184 test_31c() {
1185         touch $DIR/f31 || error
1186         ln $DIR/f31 $DIR/f31c || error
1187         multiop $DIR/f31 O_uc &
1188         MULTIPID=$!
1189         multiop $DIR/f31c Ouc
1190         usleep 500
1191         kill -USR1 $MULTIPID
1192         wait $MULTIPID
1193 }
1194 run_test 31c "open-unlink file with multiple links ============="
1195
1196 test_31d() {
1197         opendirunlink $DIR/d31d $DIR/d31d || error
1198         $CHECKSTAT -a $DIR/d31d || error
1199 }
1200 run_test 31d "remove of open directory ========================="
1201
1202 test_31e() { # bug 2904
1203         check_kernel_version 34 || return 0
1204         openfilleddirunlink $DIR/d31e || error
1205 }
1206 run_test 31e "remove of open non-empty directory ==============="
1207
1208 test_31f() { # bug 4554
1209         set -vx
1210         mkdir $DIR/d31f
1211         lfs setstripe $DIR/d31f 1048576 -1 1
1212         cp /etc/hosts $DIR/d31f
1213         ls -l $DIR/d31f
1214         lfs getstripe $DIR/d31f/hosts
1215         multiop $DIR/d31f D_c &
1216         MULTIPID=$!
1217
1218         sleep 1
1219
1220         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1221         mkdir $DIR/d31f
1222         lfs setstripe $DIR/d31f 1048576 -1 1
1223         cp /etc/hosts $DIR/d31f
1224         ls -l $DIR/d31f
1225         lfs getstripe $DIR/d31f/hosts
1226         multiop $DIR/d31f D_c &
1227         MULTIPID2=$!
1228
1229         sleep 6
1230
1231         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1232         wait $MULTIPID || error "first opendir $MULTIPID failed"
1233
1234         sleep 6
1235
1236         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1237         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1238         set +vx
1239 }
1240 run_test 31f "remove of open directory with open-unlink file ==="
1241
1242 test_32a() {
1243         echo "== more mountpoints and symlinks ================="
1244         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1245         mkdir -p $DIR/d32a/ext2-mountpoint 
1246         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1247         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error  
1248         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1249 }
1250 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1251
1252 test_32b() {
1253         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1254         mkdir -p $DIR/d32b/ext2-mountpoint 
1255         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1256         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1257         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1258 }
1259 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1260  
1261 test_32c() {
1262         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1263         mkdir -p $DIR/d32c/ext2-mountpoint 
1264         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1265         mkdir -p $DIR/d32c/d2/test_dir    
1266         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1267         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1268 }
1269 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1270
1271 test_32d() {
1272         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1273         mkdir -p $DIR/d32d/ext2-mountpoint 
1274         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1275         mkdir -p $DIR/d32d/d2/test_dir    
1276         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1277         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1278 }
1279 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1280
1281 test_32e() {
1282         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1283         mkdir -p $DIR/d32e/tmp    
1284         TMP_DIR=$DIR/d32e/tmp       
1285         ln -s $DIR/d32e $TMP_DIR/symlink11 
1286         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1287         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1288         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1289 }
1290 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1291
1292 test_32f() {
1293         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1294         mkdir -p $DIR/d32f/tmp    
1295         TMP_DIR=$DIR/d32f/tmp       
1296         ln -s $DIR/d32f $TMP_DIR/symlink11 
1297         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1298         ls $DIR/d32f/tmp/symlink11  || error
1299         ls $DIR/d32f/symlink01 || error
1300 }
1301 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1302
1303 test_32g() {
1304         TMP_DIR=$DIR/$tdir/tmp       
1305         mkdir -p $TMP_DIR $DIR/${tdir}2
1306         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1307         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1308         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1309         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1310         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1311         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1312 }
1313 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1314
1315 test_32h() {
1316         rm -fr $DIR/$tdir $DIR/${tdir}2
1317         TMP_DIR=$DIR/$tdir/tmp       
1318         mkdir -p $TMP_DIR $DIR/${tdir}2 
1319         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1320         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1321         ls $TMP_DIR/symlink12 || error
1322         ls $DIR/$tdir/symlink02  || error
1323 }
1324 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1325
1326 test_32i() {
1327         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1328         mkdir -p $DIR/d32i/ext2-mountpoint 
1329         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1330         touch $DIR/d32i/test_file
1331         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error  
1332         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1333 }
1334 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1335
1336 test_32j() {
1337         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1338         mkdir -p $DIR/d32j/ext2-mountpoint 
1339         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1340         touch $DIR/d32j/test_file
1341         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1342         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1343 }
1344 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1345
1346 test_32k() {
1347         rm -fr $DIR/d32k
1348         mkdir -p $DIR/d32k/ext2-mountpoint 
1349         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint  
1350         mkdir -p $DIR/d32k/d2
1351         touch $DIR/d32k/d2/test_file || error
1352         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1353         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1354 }
1355 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1356
1357 test_32l() {
1358         rm -fr $DIR/d32l
1359         mkdir -p $DIR/d32l/ext2-mountpoint 
1360         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1361         mkdir -p $DIR/d32l/d2
1362         touch $DIR/d32l/d2/test_file
1363         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1364         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1365 }
1366 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1367
1368 test_32m() {
1369         rm -fr $DIR/d32m
1370         mkdir -p $DIR/d32m/tmp    
1371         TMP_DIR=$DIR/d32m/tmp       
1372         ln -s $DIR $TMP_DIR/symlink11 
1373         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1374         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1375         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1376 }
1377 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1378
1379 test_32n() {
1380         rm -fr $DIR/d32n
1381         mkdir -p $DIR/d32n/tmp    
1382         TMP_DIR=$DIR/d32n/tmp       
1383         ln -s $DIR $TMP_DIR/symlink11 
1384         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1385         ls -l $DIR/d32n/tmp/symlink11  || error
1386         ls -l $DIR/d32n/symlink01 || error
1387 }
1388 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1389
1390 test_32o() {
1391         rm -fr $DIR/d32o $DIR/$tfile
1392         touch $DIR/$tfile 
1393         mkdir -p $DIR/d32o/tmp    
1394         TMP_DIR=$DIR/d32o/tmp       
1395         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1396         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1397         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1398         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1399         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1400         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1401 }
1402 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1403
1404 test_32p() {
1405     log 32p_1
1406         rm -fr $DIR/d32p
1407     log 32p_2
1408         rm -f $DIR/$tfile
1409     log 32p_3
1410         touch $DIR/$tfile 
1411     log 32p_4
1412         mkdir -p $DIR/d32p/tmp    
1413     log 32p_5
1414         TMP_DIR=$DIR/d32p/tmp       
1415     log 32p_6
1416         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1417     log 32p_7
1418         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1419     log 32p_8
1420         cat $DIR/d32p/tmp/symlink12 || error
1421     log 32p_9
1422         cat $DIR/d32p/symlink02 || error
1423     log 32p_10
1424 }
1425 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1426
1427 test_32q() {
1428         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1429         mkdir -p $DIR/d32q
1430         touch $DIR/d32q/under_the_mount
1431         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1432         ls $DIR/d32q/under_the_mount && error || true
1433         $UMOUNT $DIR/d32q || error
1434 }
1435 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1436
1437 test_32r() {
1438         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1439         mkdir -p $DIR/d32r
1440         touch $DIR/d32r/under_the_mount
1441         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1442         ls $DIR/d32r | grep -q under_the_mount && error || true
1443         $UMOUNT $DIR/d32r || error
1444 }
1445 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1446
1447 test_33() {
1448         rm -f $DIR/$tfile
1449         touch $DIR/$tfile
1450         chmod 444 $DIR/$tfile
1451         chown $RUNAS_ID $DIR/$tfile
1452         log 33_1
1453         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1454         log 33_2
1455 }
1456 run_test 33 "write file with mode 444 (should return error) ===="
1457
1458 test_33a() {
1459         rm -fr $DIR/d33
1460         mkdir -p $DIR/d33
1461         chown $RUNAS_ID $DIR/d33
1462         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1463         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1464                 error "open RDWR" || true
1465 }
1466 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1467
1468 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1469 test_34a() {
1470         rm -f $DIR/f34
1471         $MCREATE $DIR/f34 || error
1472         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1473         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1474         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1475         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1476 }
1477 run_test 34a "truncate file that has not been opened ==========="
1478
1479 test_34b() {
1480         [ ! -f $DIR/f34 ] && test_34a
1481         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1482         $OPENFILE -f O_RDONLY $DIR/f34
1483         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1484         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1485 }
1486 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1487
1488 test_34c() {
1489         [ ! -f $DIR/f34 ] && test_34a 
1490         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1491         $OPENFILE -f O_RDWR $DIR/f34
1492         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
1493         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1494 }
1495 run_test 34c "O_RDWR opening file-with-size works =============="
1496
1497 test_34d() {
1498         [ ! -f $DIR/f34 ] && test_34a 
1499         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1500         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1501         rm $DIR/f34
1502 }
1503 run_test 34d "write to sparse file ============================="
1504
1505 test_34e() {
1506         rm -f $DIR/f34e
1507         $MCREATE $DIR/f34e || error
1508         $TRUNCATE $DIR/f34e 1000 || error
1509         $CHECKSTAT -s 1000 $DIR/f34e || error
1510         $OPENFILE -f O_RDWR $DIR/f34e
1511         $CHECKSTAT -s 1000 $DIR/f34e || error
1512 }
1513 run_test 34e "create objects, some with size and some without =="
1514
1515 test_34f() { # bug 6242, 6243
1516         SIZE34F=48000
1517         rm -f $DIR/f34f
1518         $MCREATE $DIR/f34f || error
1519         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
1520         dd if=$DIR/f34f of=$TMP/f34f
1521         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
1522         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
1523         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
1524         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
1525         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
1526 }
1527 run_test 34f "read from a file with no objects until EOF ======="
1528
1529 test_35a() {
1530         cp /bin/sh $DIR/f35a
1531         chmod 444 $DIR/f35a
1532         chown $RUNAS_ID $DIR/f35a
1533         $RUNAS $DIR/f35a && error || true
1534         rm $DIR/f35a
1535 }
1536 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1537
1538 test_36a() {
1539         rm -f $DIR/f36
1540         utime $DIR/f36 || error
1541 }
1542 run_test 36a "MDS utime check (mknod, utime) ==================="
1543
1544 test_36b() {
1545         echo "" > $DIR/f36
1546         utime $DIR/f36 || error
1547 }
1548 run_test 36b "OST utime check (open, utime) ===================="
1549
1550 test_36c() {
1551         rm -f $DIR/d36/f36
1552         mkdir $DIR/d36
1553         chown $RUNAS_ID $DIR/d36
1554         $RUNAS utime $DIR/d36/f36 || error
1555 }
1556 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1557
1558 test_36d() {
1559         [ ! -d $DIR/d36 ] && test_36c
1560         echo "" > $DIR/d36/f36
1561         $RUNAS utime $DIR/d36/f36 || error
1562 }
1563 run_test 36d "non-root OST utime check (open, utime) ==========="
1564
1565 test_36e() {
1566         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
1567         mkdir -p $DIR/$tdir
1568         touch $DIR/$tdir/$tfile
1569         $RUNAS utime $DIR/$tdir/$tfile && \
1570                 error "utime worked, expected failure" || true
1571 }
1572 run_test 36e "utime on non-owned file (should return error) ===="
1573
1574 test_36f() {
1575         export LANG=C LC_LANG=C # for date language
1576
1577         DATESTR="Dec 20  2000"
1578         mkdir -p $DIR/$tdir
1579         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1580         sysctl -w lustre.fail_loc=0x80000214
1581         date; date +%s
1582         cp /etc/hosts $DIR/$tdir/$tfile
1583         sync & # write RPC generated with "current" inode timestamp, but delayed
1584         sleep 1
1585         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
1586         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
1587         cancel_lru_locks osc
1588         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
1589         date; date +%s
1590         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
1591                 echo "BEFORE: $LS_BEFORE" && \
1592                 echo "AFTER : $LS_AFTER" && \
1593                 echo "WANT  : $DATESTR" && \
1594                 error "$DIR/$tdir/$tfile timestamps changed" || true
1595 }
1596 run_test 36f "utime on file racing with OST BRW write =========="
1597
1598 export FMD_MAX_AGE=`cat $LPROC/obdfilter/*/client_cache_seconds 2> /dev/null | head -n 1`
1599 test_36g() {
1600         [ -z "$FMD_MAX_AGE" ] && echo "skip $TESTNAME for remote OST" && return
1601         FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1602         touch $DIR/d36/$tfile
1603         sleep $((FMD_MAX_AGE + 12))
1604         FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1605         [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
1606                 echo "AFTER : $FMD_AFTER > BEFORE $FMD_BEFORE" && \
1607                 error "fmd didn't expire after ping" || true
1608 }
1609 run_test 36g "filter mod data cache expiry ====================="
1610
1611 test_37() {
1612         mkdir -p $DIR/$tdir
1613         echo f > $DIR/$tdir/fbugfile
1614         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
1615         ls $DIR/$tdir | grep "\<fbugfile\>" && error
1616         $UMOUNT $DIR/$tdir || error
1617         rm -f $DIR/$tdir/fbugfile || error
1618 }
1619 run_test 37 "ls a mounted file system to check old content ====="
1620
1621 test_38() {
1622         o_directory $DIR/$tfile
1623 }
1624 run_test 38 "open a regular file with O_DIRECTORY =============="
1625
1626 test_39() {
1627         touch $DIR/$tfile
1628         touch $DIR/${tfile}2
1629 #       ls -l  $DIR/$tfile $DIR/${tfile}2
1630 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
1631 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
1632         sleep 2
1633         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
1634         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
1635                 echo "mtime"
1636                 ls -l  $DIR/$tfile $DIR/${tfile}2
1637                 echo "atime"
1638                 ls -lu  $DIR/$tfile $DIR/${tfile}2
1639                 echo "ctime"
1640                 ls -lc  $DIR/$tfile $DIR/${tfile}2
1641                 error "O_TRUNC didn't change timestamps"
1642         fi
1643 }
1644 run_test 39 "mtime changed on create ==========================="
1645
1646 test_40() {
1647         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1648         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1649         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1650 }
1651 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1652
1653 test_41() {
1654         # bug 1553
1655         small_write $DIR/f41 18
1656 }
1657 run_test 41 "test small file write + fstat ====================="
1658
1659 count_ost_writes() {
1660         cat $LPROC/osc/*/stats |
1661             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1662 }
1663
1664 # decent default
1665 WRITEBACK_SAVE=500
1666
1667 start_writeback() {
1668         trap 0
1669         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs
1670         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1671                 echo $WRITEBACK_SAVE > /proc/sys/vm/dirty_writeback_centisecs
1672         else
1673                 # if file not here, we are a 2.4 kernel
1674                 kill -CONT `pidof kupdated`
1675         fi
1676 }
1677 stop_writeback() {
1678         # setup the trap first, so someone cannot exit the test at the
1679         # exact wrong time and mess up a machine
1680         trap start_writeback EXIT
1681         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1682         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1683                 WRITEBACK_SAVE=`cat /proc/sys/vm/dirty_writeback_centisecs`
1684                 echo 0 > /proc/sys/vm/dirty_writeback_centisecs
1685         else
1686                 # if file not here, we are a 2.4 kernel
1687                 kill -STOP `pidof kupdated`
1688         fi
1689 }
1690
1691 # ensure that all stripes have some grant before we test client-side cache
1692 setup_test42() {
1693         [ "$SETUP_TEST42" ] && return
1694         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1695                 dd if=/dev/zero of=$i bs=4k count=1
1696                 rm $i
1697         done
1698         SETUP_TEST42=DONE
1699 }
1700
1701 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1702 # file truncation, and file removal.
1703 test_42a() {
1704         setup_test42
1705         cancel_lru_locks osc
1706         stop_writeback
1707         sync; sleep 1; sync # just to be safe
1708         BEFOREWRITES=`count_ost_writes`
1709         grep "[0-9]" $LPROC/osc/*[oO][sS][cC]*/cur_grant_bytes
1710         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1711         AFTERWRITES=`count_ost_writes`
1712         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1713                 error "$BEFOREWRITES < $AFTERWRITES"
1714         start_writeback
1715 }
1716 run_test 42a "ensure that we don't flush on close =============="
1717
1718 test_42b() {
1719         setup_test42
1720         cancel_lru_locks osc
1721         stop_writeback
1722         sync
1723         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1724         BEFOREWRITES=`count_ost_writes`
1725         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1726         AFTERWRITES=`count_ost_writes`
1727         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1728                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
1729         fi
1730         BEFOREWRITES=`count_ost_writes`
1731         sync || error "sync: $?"
1732         AFTERWRITES=`count_ost_writes`
1733         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1734                 error "$BEFOREWRITES < $AFTERWRITES on sync"
1735         fi
1736         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1737         start_writeback
1738         return 0
1739 }
1740 run_test 42b "test destroy of file with cached dirty data ======"
1741
1742 # if these tests just want to test the effect of truncation,
1743 # they have to be very careful.  consider:
1744 # - the first open gets a {0,EOF}PR lock
1745 # - the first write conflicts and gets a {0, count-1}PW
1746 # - the rest of the writes are under {count,EOF}PW
1747 # - the open for truncate tries to match a {0,EOF}PR
1748 #   for the filesize and cancels the PWs.
1749 # any number of fixes (don't get {0,EOF} on open, match
1750 # composite locks, do smarter file size management) fix
1751 # this, but for now we want these tests to verify that
1752 # the cancellation with truncate intent works, so we
1753 # start the file with a full-file pw lock to match against
1754 # until the truncate.
1755 trunc_test() {
1756         test=$1
1757         file=$DIR/$test
1758         offset=$2
1759         cancel_lru_locks osc
1760         stop_writeback
1761         # prime the file with 0,EOF PW to match
1762         touch $file
1763         $TRUNCATE $file 0
1764         sync; sync
1765         # now the real test..
1766         dd if=/dev/zero of=$file bs=1024 count=100
1767         BEFOREWRITES=`count_ost_writes`
1768         $TRUNCATE $file $offset
1769         cancel_lru_locks osc
1770         AFTERWRITES=`count_ost_writes`
1771         start_writeback
1772 }
1773
1774 test_42c() {
1775         trunc_test 42c 1024
1776         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1777             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
1778         rm $file
1779 }
1780 run_test 42c "test partial truncate of file with cached dirty data"
1781
1782 test_42d() {
1783         trunc_test 42d 0
1784         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1785             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1786         rm $file
1787 }
1788 run_test 42d "test complete truncate of file with cached dirty data"
1789
1790 test_43() {
1791         mkdir $DIR/$tdir
1792         cp -p /bin/ls $DIR/$tdir/$tfile
1793         exec 100>> $DIR/$tdir/$tfile
1794         $DIR/$tdir/$tfile && error || true
1795         exec 100<&-
1796 }
1797 run_test 43 "execution of file opened for write should return -ETXTBSY"
1798
1799 test_43a() {
1800         mkdir -p $DIR/d43
1801         cp -p `which multiop` $DIR/d43/multiop
1802         $DIR/d43/multiop $TMP/test43.junk O_c &
1803         MULTIPID=$!
1804         sleep 1
1805         multiop $DIR/d43/multiop Oc && error "expected error, got success"
1806         kill -USR1 $MULTIPID || return 2
1807         wait $MULTIPID || return 3
1808         rm $TMP/test43.junk
1809 }
1810 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
1811
1812 test_43b() {
1813         mkdir -p $DIR/d43
1814         cp -p `which multiop` $DIR/d43/multiop
1815         $DIR/d43/multiop $TMP/test43.junk O_c &
1816         MULTIPID=$!
1817         sleep 1
1818         truncate $DIR/d43/multiop 0 && error "expected error, got success"
1819         kill -USR1 $MULTIPID || return 2
1820         wait $MULTIPID || return 3
1821         rm $TMP/test43.junk
1822 }
1823 run_test 43b "truncate of file being executed should return -ETXTBSY"
1824
1825 test_43c() {
1826         local testdir="$DIR/d43c"
1827         mkdir -p $testdir
1828         cp $SHELL $testdir/
1829         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
1830                 ( cd $testdir && md5sum -c)
1831 }
1832 run_test 43c "md5sum of copy into lustre========================"
1833
1834 test_44() {
1835         [  "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
1836         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
1837         dd if=$DIR/f1 bs=4k count=1
1838 }
1839 run_test 44 "zero length read from a sparse stripe ============="
1840
1841 test_44a() {
1842     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
1843                          awk '{print $2}'`
1844     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
1845                       awk '{print $2}'`
1846     if [ $nstripe -eq 0 ] ; then
1847         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
1848     fi
1849     [ -z "$nstripe" ] && error "can't get stripe info"
1850
1851     OFFSETS="0 $((stride/2)) $((stride-1))"
1852     for offset in $OFFSETS ; do
1853       for i in `seq 0 $((nstripe-1))`; do
1854         rm -f $DIR/d44a
1855         local GLOBALOFFSETS=""
1856         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
1857         ll_sparseness_write $DIR/d44a $size  || error "ll_sparseness_write"
1858         GLOBALOFFSETS="$GLOBALOFFSETS $size"
1859         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1860                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1861
1862         for j in `seq 0 $((nstripe-1))`; do
1863             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
1864             ll_sparseness_write $DIR/d44a $size || error "ll_sparseness_write"
1865             GLOBALOFFSETS="$GLOBALOFFSETS $size"
1866         done
1867         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1868                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1869       done
1870     done
1871 }
1872 run_test 44a "test sparse pwrite ==============================="
1873
1874 dirty_osc_total() {
1875         tot=0
1876         for d in $LPROC/osc/*/cur_dirty_bytes; do
1877                 tot=$(($tot + `cat $d`))
1878         done
1879         echo $tot
1880 }
1881 do_dirty_record() {
1882         before=`dirty_osc_total`
1883         echo executing "\"$*\""
1884         eval $*
1885         after=`dirty_osc_total`
1886         echo before $before, after $after
1887 }
1888 test_45() {
1889         f="$DIR/f45"
1890         # Obtain grants from OST if it supports it
1891         echo blah > ${f}_grant
1892         stop_writeback
1893         sync
1894         do_dirty_record "echo blah > $f"
1895         [ $before -eq $after ] && error "write wasn't cached"
1896         do_dirty_record "> $f"
1897         [ $before -gt $after ] || error "truncate didn't lower dirty count"
1898         do_dirty_record "echo blah > $f"
1899         [ $before -eq $after ] && error "write wasn't cached"
1900         do_dirty_record "sync"
1901         [ $before -gt $after ] || error "writeback didn't lower dirty count"
1902         do_dirty_record "echo blah > $f"
1903         [ $before -eq $after ] && error "write wasn't cached"
1904         do_dirty_record "cancel_lru_locks osc"
1905         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
1906         start_writeback
1907 }
1908 run_test 45 "osc io page accounting ============================"
1909
1910 page_size() {
1911         getconf PAGE_SIZE
1912 }
1913
1914 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
1915 # test tickles a bug where re-dirtying a page was failing to be mapped to the
1916 # objects offset and an assert hit when an rpc was built with 1023's mapped 
1917 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
1918 test_46() {
1919         f="$DIR/f46"
1920         stop_writeback
1921         sync
1922         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1923         sync
1924         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
1925         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1926         sync
1927         start_writeback
1928 }
1929 run_test 46 "dirtying a previously written page ================"
1930
1931 # Check that device nodes are created and then visible correctly (#2091)
1932 test_47() {
1933         cmknod $DIR/test_47_node || error
1934 }
1935 run_test 47 "Device nodes check ================================"
1936
1937 test_48a() { # bug 2399
1938         check_kernel_version 34 || return 0
1939         mkdir -p $DIR/d48a
1940         cd $DIR/d48a
1941         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
1942         mkdir $DIR/d48a || error "recreate directory failed"
1943         touch foo || error "'touch foo' failed after recreating cwd"
1944         mkdir bar || error "'mkdir foo' failed after recreating cwd"
1945         if check_kernel_version 44; then
1946                 touch .foo || error "'touch .foo' failed after recreating cwd"
1947                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
1948         fi
1949         ls . || error "'ls .' failed after recreating cwd"
1950         ls .. || error "'ls ..' failed after removing cwd"
1951         cd . || error "'cd .' failed after recreating cwd"
1952         mkdir . && error "'mkdir .' worked after recreating cwd"
1953         rmdir . && error "'rmdir .' worked after recreating cwd"
1954         ln -s . baz || error "'ln -s .' failed after recreating cwd"
1955         cd .. || error "'cd ..' failed after recreating cwd"
1956 }
1957 run_test 48a "Access renamed working dir (should return errors)="
1958
1959 test_48b() { # bug 2399
1960         check_kernel_version 34 || return 0
1961         mkdir -p $DIR/d48b
1962         cd $DIR/d48b
1963         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
1964         touch foo && error "'touch foo' worked after removing cwd"
1965         mkdir foo && error "'mkdir foo' worked after removing cwd"
1966         if check_kernel_version 44; then
1967                 touch .foo && error "'touch .foo' worked after removing cwd"
1968                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
1969         fi
1970         ls . && error "'ls .' worked after removing cwd"
1971         ls .. || error "'ls ..' failed after removing cwd"
1972         cd . && error "'cd .' worked after removing cwd"
1973         mkdir . && error "'mkdir .' worked after removing cwd"
1974         rmdir . && error "'rmdir .' worked after removing cwd"
1975         ln -s . foo && error "'ln -s .' worked after removing cwd"
1976         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
1977 }
1978 run_test 48b "Access removed working dir (should return errors)="
1979
1980 test_48c() { # bug 2350
1981         check_kernel_version 36 || return 0
1982         #sysctl -w lnet.debug=-1
1983         #set -vx
1984         mkdir -p $DIR/d48c/dir
1985         cd $DIR/d48c/dir
1986         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
1987         $TRACE touch foo && error "'touch foo' worked after removing cwd"
1988         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
1989         if check_kernel_version 44; then
1990                 touch .foo && error "'touch .foo' worked after removing cwd"
1991                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
1992         fi
1993         $TRACE ls . && error "'ls .' worked after removing cwd"
1994         $TRACE ls .. || error "'ls ..' failed after removing cwd"
1995         $TRACE cd . && error "'cd .' worked after removing cwd"
1996         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
1997         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
1998         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
1999         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2000 }
2001 run_test 48c "Access removed working subdir (should return errors)"
2002
2003 test_48d() { # bug 2350
2004         check_kernel_version 36 || return 0
2005         #sysctl -w lnet.debug=-1
2006         #set -vx
2007         mkdir -p $DIR/d48d/dir
2008         cd $DIR/d48d/dir
2009         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2010         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
2011         $TRACE touch foo && error "'touch foo' worked after removing parent"
2012         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
2013         if check_kernel_version 44; then
2014                 touch .foo && error "'touch .foo' worked after removing parent"
2015                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
2016         fi
2017         $TRACE ls . && error "'ls .' worked after removing parent"
2018         $TRACE ls .. && error "'ls ..' worked after removing parent"
2019         $TRACE cd . && error "'cd .' worked after recreate parent"
2020         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
2021         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
2022         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
2023         $TRACE cd .. && error "'cd ..' worked after removing parent" || true
2024 }
2025 run_test 48d "Access removed parent subdir (should return errors)"
2026
2027 test_48e() { # bug 4134
2028         check_kernel_version 41 || return 0
2029         #sysctl -w lnet.debug=-1
2030         #set -vx
2031         mkdir -p $DIR/d48e/dir
2032         cd $DIR/d48e/dir
2033         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
2034         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
2035         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
2036         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
2037         # On a buggy kernel addition of "touch foo" after cd .. will
2038         # produce kernel oops in lookup_hash_it
2039         touch ../foo && error "'cd ..' worked after recreate parent"
2040         cd $DIR
2041         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
2042 }
2043 run_test 48e "Access to recreated parent subdir (should return errors)"
2044
2045 test_50() {
2046         # bug 1485
2047         mkdir $DIR/d50
2048         cd $DIR/d50
2049         ls /proc/$$/cwd || error
2050 }
2051 run_test 50 "special situations: /proc symlinks  ==============="
2052
2053 test_51() {
2054         # bug 1516 - create an empty entry right after ".." then split dir
2055         mkdir $DIR/d51
2056         touch $DIR/d51/foo
2057         $MCREATE $DIR/d51/bar
2058         rm $DIR/d51/foo
2059         createmany -m $DIR/d51/longfile 201
2060         FNUM=202
2061         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
2062                 $MCREATE $DIR/d51/longfile$FNUM
2063                 FNUM=$(($FNUM + 1))
2064                 echo -n "+"
2065         done
2066         ls -l $DIR/d51 > /dev/null || error
2067 }
2068 run_test 51 "special situations: split htree with empty entry =="
2069
2070 export NUMTEST=70000
2071 test_51b() {
2072         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2073         [ $NUMFREE -lt 21000 ] && \
2074                 echo "skipping $TESTNAME, not enough free inodes ($NUMFREE)" && \
2075                 return
2076
2077         check_kernel_version 40 || NUMTEST=31000
2078         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
2079
2080         mkdir -p $DIR/d51b
2081         createmany -d $DIR/d51b/t- $NUMTEST
2082 }
2083 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
2084
2085 test_51c() {
2086         [ ! -d $DIR/d51b ] && echo "skipping $TESTNAME: $DIR/51b missing" && \
2087                 return
2088
2089         unlinkmany -d $DIR/d51b/t- $NUMTEST
2090 }
2091 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
2092
2093 test_51d() {
2094         [  "$OSTCOUNT" -lt "3" ] && echo "skipping test with few OSTs" && return
2095         mkdir -p $DIR/d51d
2096         createmany -o $DIR/d51d/t- 1000
2097         $LFS getstripe $DIR/d51d > $TMP/files
2098         for N in `seq 0 $((OSTCOUNT - 1))`; do
2099             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
2100             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
2101             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
2102         done
2103         unlinkmany $DIR/d51d/t- 1000
2104
2105         NLAST=0
2106         for N in `seq 1 $((OSTCOUNT - 1))`; do
2107             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
2108                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2109             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
2110                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2111             
2112             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
2113                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2114             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
2115                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2116             NLAST=$N
2117         done
2118 }
2119 run_test 51d "check object distribution ===================="
2120
2121 test_52a() {
2122         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
2123         mkdir -p $DIR/d52a
2124         touch $DIR/d52a/foo
2125         chattr =a $DIR/d52a/foo || error "chattr =a failed"
2126         echo bar >> $DIR/d52a/foo || error "append bar failed"
2127         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
2128         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
2129         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
2130         echo foo >> $DIR/d52a/foo || error "append foo failed"
2131         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
2132         lsattr $DIR/d52a/foo | egrep -q "^-+a-+ $DIR/d52a/foo" || error "lsattr"
2133         chattr -a $DIR/d52a/foo || error "chattr -a failed"
2134
2135         rm -fr $DIR/d52a || error "cleanup rm failed"
2136 }
2137 run_test 52a "append-only flag test (should return errors) ====="
2138
2139 test_52b() {
2140         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
2141         mkdir -p $DIR/d52b
2142         touch $DIR/d52b/foo
2143         chattr =i $DIR/d52b/foo || error
2144         cat test > $DIR/d52b/foo && error
2145         cp /etc/hosts $DIR/d52b/foo && error
2146         rm -f $DIR/d52b/foo 2>/dev/null && error
2147         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error
2148         echo foo >> $DIR/d52b/foo && error
2149         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error
2150         [ -f $DIR/d52b/foo ] || error
2151         [ -f $DIR/d52b/foo_ren ] && error
2152         lsattr $DIR/d52b/foo | egrep -q "^-+i-+ $DIR/d52b/foo" || error
2153         chattr -i $DIR/d52b/foo || error
2154
2155         rm -fr $DIR/d52b || error
2156 }
2157 run_test 52b "immutable flag test (should return errors) ======="
2158
2159 test_53() {
2160         [ -z "$MDS" ] && echo "skipping $TESTNAME with remote MDS" && return
2161         
2162         for i in `ls -d $LPROC/osc/*-osc 2> /dev/null` ; do
2163                 ostname=`basename $i | cut -d - -f 1-2`
2164                 ost_last=`cat $LPROC/obdfilter/$ostname/last_id`
2165                 mds_last=`cat $i/prealloc_last_id`
2166                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2167                 if [ $ost_last != $mds_last ]; then
2168                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2169                 fi
2170         done
2171 }
2172 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
2173
2174 test_54a() {
2175         [ ! -f "$SOCKETSERVER" ] && echo "no socketserver, skipping" && return
2176         [ ! -f "$SOCKETCLIENT" ] && echo "no socketclient, skipping" && return
2177         $SOCKETSERVER $DIR/socket
2178         $SOCKETCLIENT $DIR/socket || error
2179         $MUNLINK $DIR/socket
2180 }
2181 run_test 54a "unix domain socket test =========================="
2182
2183 test_54b() {
2184         f="$DIR/f54b"
2185         mknod $f c 1 3
2186         chmod 0666 $f
2187         dd if=/dev/zero of=$f bs=`page_size` count=1 
2188 }
2189 run_test 54b "char device works in lustre ======================"
2190
2191 find_loop_dev() {
2192         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
2193         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
2194         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
2195
2196         for i in `seq 3 7`; do
2197                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
2198                 LOOPDEV=$LOOPBASE$i
2199                 LOOPNUM=$i
2200                 break
2201         done
2202 }
2203
2204 test_54c() {
2205         tfile="$DIR/f54c"
2206         tdir="$DIR/d54c"
2207         loopdev="$DIR/loop54c"
2208
2209         find_loop_dev 
2210         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
2211         mknod $loopdev b 7 $LOOPNUM
2212         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
2213         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
2214         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
2215         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
2216         mkdir -p $tdir
2217         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
2218         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
2219         df $tdir
2220         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
2221         $UMOUNT $tdir
2222         losetup -d $loopdev
2223         rm $loopdev
2224 }
2225 run_test 54c "block device works in lustre ====================="
2226
2227 test_54d() {
2228         f="$DIR/f54d"
2229         string="aaaaaa"
2230         mknod $f p
2231         [ "$string" = `echo $string > $f | cat $f` ] || error
2232 }
2233 run_test 54d "fifo device works in lustre ======================"
2234
2235 test_54e() {
2236         check_kernel_version 46 || return 0
2237         f="$DIR/f54e"
2238         string="aaaaaa"
2239         mknod $f c 4 0
2240         echo $string > $f || error
2241 }
2242 run_test 54e "console/tty device works in lustre ======================"
2243
2244 check_fstype() {
2245         grep -q $FSTYPE /proc/filesystems && return 1
2246         modprobe $FSTYPE
2247         grep -q $FSTYPE /proc/filesystems && return 1
2248         insmod ../$FSTYPE/$FSTYPE.o
2249         grep -q $FSTYPE /proc/filesystems && return 1
2250         insmod ../$FSTYPE/$FSTYPE.ko
2251         grep -q $FSTYPE /proc/filesystems && return 1
2252         return 0
2253 }
2254
2255 test_55() {
2256         rm -rf $DIR/d55
2257         mkdir $DIR/d55
2258         check_fstype && echo "can't find fs $FSTYPE, skipping $TESTNAME" && return
2259         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
2260         touch $DIR/d55/foo
2261         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
2262         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
2263         echo "check for $EXT2_DEV. Please wait..."
2264         rm -rf $DIR/d55/*
2265         $UMOUNT $DIR/d55 || error "unmounting"
2266 }
2267 run_test 55 "check iopen_connect_dentry() ======================"
2268
2269 test_56() {
2270         rm -rf $DIR/d56
2271         $SETSTRIPE -d $DIR
2272         mkdir $DIR/d56
2273         mkdir $DIR/d56/dir
2274         NUMFILES=3
2275         NUMFILESx2=$(($NUMFILES * 2))
2276         for i in `seq 1 $NUMFILES` ; do
2277                 touch $DIR/d56/file$i
2278                 touch $DIR/d56/dir/file$i
2279         done
2280
2281         # test lfs getstripe with --recursive
2282         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
2283         [ $FILENUM -eq $NUMFILESx2 ] || error \
2284                 "lfs getstripe --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
2285         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
2286         [ $FILENUM -eq $NUMFILES ] || error \
2287                 "lfs getstripe $DIR/d56 without --recursive wrong: found $FILENUM, expected $NUMFILES"
2288         echo "lfs getstripe --recursive passed."
2289
2290         # test lfs getstripe with file instead of dir
2291         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
2292         [ $FILENUM  -eq 1 ] || error \
2293                  "lfs getstripe $DIR/d56/file1 wrong:found $FILENUM, expected 1"
2294         echo "lfs getstripe file passed."
2295
2296         #test lfs getstripe with --verbose
2297         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||\
2298                 error "lfs getstripe --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2299         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] || error \
2300                 "lfs getstripe $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2301         echo "lfs getstripe --verbose passed."
2302
2303         #test lfs getstripe with --obd
2304         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2305                 error "lfs getstripe --obd wrong_uuid should return error message"
2306
2307         [  "$OSTCOUNT" -lt 2 ] && \
2308                 echo "skipping other lfs getstripe --obd test" && return
2309         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1[    ]/p' | wc -l`
2310         OBDUUID=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1:/p' | awk '{print $2}'`
2311         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | wc -l`
2312         [ $FOUND -eq $FILENUM ] || \
2313                 error "lfs getstripe --obd wrong: found $FOUND, expected $FILENUM"
2314         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 | sed '/^[   ]*1[    ]/d' |\
2315                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] || \
2316                 error "lfs getstripe --obd wrong: should not show file on other obd"
2317         echo "lfs getstripe --obd passed."
2318 }
2319 run_test 56 "check lfs getstripe ===================================="
2320
2321 NUMFILES=3
2322 NUMDIRS=3
2323 setup_56() {
2324         LOCAL_NUMFILES=$1
2325         LOCAL_NUMDIRS=$2
2326         if [ ! -d "$DIR/${tdir}g" ] ; then
2327                 mkdir -p $DIR/${tdir}g
2328                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2329                         touch $DIR/${tdir}g/file$i
2330                 done
2331                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2332                         mkdir $DIR/${tdir}g/dir$i
2333                         for j in `seq 1 $LOCAL_NUMFILES` ; do
2334                                 touch $DIR/${tdir}g/dir$i/file$j
2335                         done
2336                 done
2337         fi
2338 }
2339
2340 test_56g() {
2341         $LSTRIPE -d $DIR
2342
2343         setup_56 $NUMFILES $NUMDIRS
2344
2345         EXPECTED=$(($NUMDIRS + 2))
2346         # test lfs find with -name
2347         for i in `seq 1 $NUMFILES` ; do
2348                 NUMS=`$LFIND -name "*$i" $DIR/${tdir}g | wc -l`
2349                 [ $NUMS -eq $EXPECTED ] || error \
2350                         "lfs find -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2351         done
2352         echo "lfs find -name passed."
2353 }
2354 run_test 56g "check lfs find -name ============================="
2355
2356 test_56h() {
2357         $LSTRIPE -d $DIR
2358
2359         setup_56 $NUMFILES $NUMDIRS
2360
2361         EXPECTED=$((($NUMDIRS+1)*($NUMFILES-1)+$NUMFILES))
2362         # test lfs find with ! -name
2363         for i in `seq 1 $NUMFILES` ; do
2364                 NUMS=`$LFIND ! -name "*$i" $DIR/${tdir}g | wc -l`
2365                 [ $NUMS -eq $EXPECTED ] || error \
2366                         "lfs find ! -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2367         done
2368         echo "lfs find ! -name passed."
2369 }
2370 run_test 56h "check lfs find ! -name ============================="
2371
2372 test_57a() {
2373         [ -z "$MDS" ] && echo "skipping $TESTNAME for remote MDS" && return
2374         for DEV in `cat $LPROC/mds/*/mntdev`; do
2375                 dumpe2fs -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
2376                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2377                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2378                 rm $TMP/t57a.dump
2379         done
2380 }
2381 run_test 57a "verify MDS filesystem created with large inodes =="
2382
2383 test_57b() {
2384         FILECOUNT=100
2385         FILE1=$DIR/d57b/f1
2386         FILEN=$DIR/d57b/f$FILECOUNT
2387         rm -rf $DIR/d57b || error "removing $DIR/d57b"
2388         mkdir -p $DIR/d57b || error "creating $DIR/d57b"
2389         echo "mcreating $FILECOUNT files"
2390         createmany -m $DIR/d57b/f 1 $FILECOUNT || \
2391                 error "creating files in $DIR/d57b"
2392
2393         # verify that files do not have EAs yet
2394         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2395         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2396
2397         MDSFREE="`cat $LPROC/mds/*/kbytesfree 2> /dev/null`"
2398         MDCFREE="`cat $LPROC/mdc/*/kbytesfree | head -n 1`"
2399         echo "opening files to create objects/EAs"
2400         for FILE in `seq -f $DIR/d57b/f%g 1 $FILECOUNT`; do
2401                 $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
2402         done
2403
2404         # verify that files have EAs now
2405         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2406         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2407
2408         sleep 1 # make sure we get new statfs data
2409         MDSFREE2="`cat $LPROC/mds/*/kbytesfree 2> /dev/null`"
2410         MDCFREE2="`cat $LPROC/mdc/*/kbytesfree | head -n 1`"
2411         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
2412                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
2413                         error "MDC before $MDCFREE != after $MDCFREE2"
2414                 else
2415                         echo "MDC before $MDCFREE != after $MDCFREE2"
2416                         echo "unable to confirm if MDS has large inodes"
2417                 fi
2418         fi
2419         rm -rf $DIR/d57b
2420 }
2421 run_test 57b "default LOV EAs are stored inside large inodes ==="
2422
2423 test_58() {
2424     [ -z "$(which wiretest 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find wiretest)" && return
2425     wiretest
2426 }
2427 run_test 58 "verify cross-platform wire constants =============="
2428
2429 test_59() {
2430         echo "touch 130 files"
2431         createmany -o $DIR/f59- 130
2432         echo "rm 130 files"
2433         unlinkmany $DIR/f59- 130
2434         sync
2435         sleep 2
2436         # wait for commitment of removal
2437 }
2438 run_test 59 "verify cancellation of llog records async ========="
2439
2440 TEST60_HEAD="test_60 run $RANDOM"
2441 test_60() {
2442         [ ! -f run-llog.sh ] && echo "missing subtest, skipping" && return
2443         log "$TEST60_HEAD - from kernel mode"
2444         sh run-llog.sh
2445 }
2446 run_test 60 "llog sanity tests run from kernel module =========="
2447
2448 test_60b() { # bug 6411
2449         dmesg > $DIR/$tfile
2450         LLOG_COUNT=`dmesg | grep -A 1000 "$TEST60_HEAD" | grep -c llog_test`
2451         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages"|| true
2452 }
2453 run_test 60b "limit repeated messages from CERROR/CWARN ========"
2454
2455 test_61() {
2456         f="$DIR/f61"
2457         dd if=/dev/zero of=$f bs=`page_size` count=1
2458         cancel_lru_locks osc
2459         multiop $f OSMWUc || error
2460         sync
2461 }
2462 run_test 61 "mmap() writes don't make sync hang ================"
2463
2464 # bug 2330 - insufficient obd_match error checking causes LBUG
2465 test_62() {
2466         f="$DIR/f62"
2467         echo foo > $f
2468         cancel_lru_locks osc
2469         sysctl -w lustre.fail_loc=0x405
2470         cat $f && error "cat succeeded, expect -EIO"
2471         sysctl -w lustre.fail_loc=0
2472 }
2473 run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2474
2475 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2476 test_63() {
2477         MAX_DIRTY_MB=`cat $LPROC/osc/*/max_dirty_mb | head -n 1`
2478         for i in $LPROC/osc/*/max_dirty_mb ; do
2479                 echo 0 > $i
2480         done
2481         for i in `seq 10` ; do
2482                 dd if=/dev/zero of=$DIR/f63 bs=8k &
2483                 sleep 5
2484                 kill $!
2485                 sleep 1
2486         done
2487
2488         for i in $LPROC/osc/*/max_dirty_mb ; do
2489                 echo $MAX_DIRTY_MB > $i
2490         done
2491         rm -f $DIR/f63 || true
2492 }
2493 run_test 63 "Verify oig_wait interruption does not crash ======="
2494
2495 # bug 2248 - async write errors didn't return to application on sync
2496 # bug 3677 - async write errors left page locked
2497 test_63b() {
2498         DBG_SAVE="`sysctl -n lnet.debug`"
2499         sysctl -w lnet.debug=-1
2500
2501         # ensure we have a grant to do async writes
2502         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
2503         rm $DIR/$tfile
2504
2505         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
2506         sysctl -w lustre.fail_loc=0x80000406
2507         multiop $DIR/$tfile Owy && \
2508                 $LCTL dk /tmp/test63b.debug && \
2509                 sysctl -w lnet.debug="$DBG_SAVE" && \
2510                 error "sync didn't return ENOMEM"
2511         sync; sleep 2; sync     # do a real sync this time to flush page
2512         grep locked $LPROC/llite/*/dump_page_cache && \
2513                 $LCTL dk /tmp/test63b.debug && \
2514                 sysctl -w lnet.debug="$DBG_SAVE" && \
2515                 error "locked page left in cache after async error" || true
2516         sysctl -w lnet.debug="$DBG_SAVE"
2517 }
2518 run_test 63b "async write errors should be returned to fsync ==="
2519
2520 test_64a () {
2521         df $DIR
2522         grep "[0-9]" $LPROC/osc/*[oO][sS][cC]*/cur*
2523 }
2524 run_test 64a "verify filter grant calculations (in kernel) ====="
2525
2526 test_64b () {
2527         [ ! -f oos.sh ] && echo "missing subtest, skipping" && return
2528         sh oos.sh $MOUNT
2529 }
2530 run_test 64b "check out-of-space detection on client ==========="
2531
2532 # bug 1414 - set/get directories' stripe info
2533 test_65a() {
2534         mkdir -p $DIR/d65
2535         touch $DIR/d65/f1
2536         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
2537 }
2538 run_test 65a "directory with no stripe info ===================="
2539
2540 test_65b() {
2541         mkdir -p $DIR/d65
2542         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2543         touch $DIR/d65/f2
2544         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
2545 }
2546 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
2547
2548 test_65c() {
2549         if [ $OSTCOUNT -gt 1 ]; then
2550                 mkdir -p $DIR/d65
2551                 $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 4)) 1 \
2552                         $(($OSTCOUNT - 1)) || error "setstripe"
2553                 touch $DIR/d65/f3
2554                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
2555         fi
2556 }
2557 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
2558
2559 [ $STRIPECOUNT -eq 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1))
2560
2561 test_65d() {
2562         mkdir -p $DIR/d65
2563         $SETSTRIPE $DIR/d65 $STRIPESIZE -1 $sc || error "setstripe"
2564         touch $DIR/d65/f4 $DIR/d65/f5
2565         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
2566 }
2567 run_test 65d "directory setstripe $STRIPESIZE -1 $sc =============="
2568
2569 test_65e() {
2570         mkdir -p $DIR/d65
2571
2572         $SETSTRIPE $DIR/d65 0 -1 0 || error "setstripe"
2573         $GETSTRIPE -v $DIR/d65 | grep "has no stripe info" || error "no stripe info failed"
2574         touch $DIR/d65/f6
2575         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
2576 }
2577 run_test 65e "directory setstripe 0 -1 0 ======================="
2578
2579 test_65f() {
2580         mkdir -p $DIR/d65f
2581         $RUNAS $SETSTRIPE $DIR/d65f 0 -1 0 && error "setstripe succeeded" || true
2582 }
2583 run_test 65f "dir setstripe permission (should return error) ==="
2584
2585 test_65g() {
2586         mkdir -p $DIR/d65
2587         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2588         $SETSTRIPE -d $DIR/d65 || error "setstripe"
2589         $GETSTRIPE -v $DIR/d65 | grep "has no stripe info" || \
2590                 error "delete default stripe failed"
2591 }
2592 run_test 65g "directory setstripe -d ==========================="
2593
2594 test_65h() {
2595         mkdir -p $DIR/d65
2596         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2597         mkdir -p $DIR/d65/dd1
2598         [ "`$GETSTRIPE -v $DIR/d65 | grep "^count"`" == \
2599           "`$GETSTRIPE -v $DIR/d65/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
2600 }
2601 run_test 65h "directory stripe info inherit ===================="
2602  
2603 test_65i() { # bug6367
2604         $SETSTRIPE $MOUNT 65536 -1 -1
2605 }
2606 run_test 65i "set non-default striping on root directory (bug 6367)="
2607
2608 test_65j() { # bug6367
2609         # if we aren't already remounting for each test, do so for this test
2610         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
2611                 cleanup -f || error "failed to unmount"
2612                 setup
2613         fi
2614         $SETSTRIPE -d $MOUNT
2615 }
2616 run_test 65j "set default striping on root directory (bug 6367)="
2617
2618 # bug 2543 - update blocks count on client
2619 test_66() {
2620         COUNT=${COUNT:-8}
2621         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
2622         sync; sleep 1; sync
2623         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
2624         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
2625 }
2626 run_test 66 "update inode blocks count on client ==============="
2627
2628 test_67() { # bug 3285 - supplementary group fails on MDS, passes on client
2629         [ "$RUNAS_ID" = "$UID" ] && echo "skipping $TESTNAME" && return
2630         check_kernel_version 35 || return 0
2631         mkdir $DIR/$tdir
2632         chmod 771 $DIR/$tdir
2633         chgrp $RUNAS_ID $DIR/$tdir
2634         $RUNAS -u $RUNAS_ID -g $(($RUNAS_ID + 1)) -G1,2,$RUNAS_ID ls $DIR/$tdir
2635         RC=$?
2636         if [ "$MDS" ]; then
2637                 # can't tell which is correct otherwise
2638                 GROUP_UPCALL=`cat $LPROC/mds/$MDS/group_upcall`
2639                 [ "$GROUP_UPCALL" = "NONE" -a $RC -eq 0 ] && \
2640                         error "no-upcall passed" || true
2641                 [ "$GROUP_UPCALL" != "NONE" -a $RC -ne 0 ] && \
2642                         error "upcall failed" || true
2643         fi
2644 }
2645 run_test 67 "supplementary group failure (should return error) ="
2646
2647 cleanup_67b() {
2648         trap 0
2649         echo NONE > $LPROC/mds/$MDS/group_upcall
2650         set +vx
2651 }
2652
2653 test_67b() { # bug 3285 - supplementary group fails on MDS, passes on client
2654         T67_UID=${T67_UID:-1}   # needs to be in /etc/groups on MDS, gid == uid
2655         [ "$UID" = "$T67_UID" ] && echo "skipping $TESTNAME" && return
2656         check_kernel_version 35 || return 0
2657         [ -z "$MDS" ] && echo "skipping $TESTNAME - no MDS" && return
2658         GROUP_UPCALL=`cat $LPROC/mds/$MDS/group_upcall`
2659         [ "$GROUP_UPCALL" != "NONE" ] && echo "skip $TESTNAME - upcall" &&return
2660         set -vx
2661         trap cleanup_67b EXIT
2662         mkdir -p $DIR/$tdir
2663         chmod 771 $DIR/$tdir
2664         chgrp $T67_UID $DIR/$tdir
2665         echo `which l_getgroups` > $LPROC/mds/$MDS/group_upcall
2666         l_getgroups -d $T67_UID
2667         $RUNAS -u $T67_UID -g $((T67_UID + 1)) -G8,9 id
2668         $RUNAS -u $T67_UID -g 999 -G8,9,$T67_UID touch $DIR/$tdir/$tfile || \
2669                 error "'touch $DIR/$tdir/$tfile' failed"
2670         [ -f $DIR/$tdir/$tfile ] || error "$DIR/$tdir/$tfile create error"
2671         cleanup_67b
2672 }
2673 run_test 67b "supplementary group test ========================="
2674
2675 cleanup_68() {
2676         trap 0
2677         if [ "$LOOPDEV" ]; then
2678                 swapoff $LOOPDEV || error "swapoff failed"
2679                 losetup -d $LOOPDEV || error "losetup -d failed"
2680                 unset LOOPDEV LOOPNUM
2681         fi
2682         rm -f $DIR/f68
2683 }
2684
2685 meminfo() {
2686         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
2687 }
2688
2689 swap_used() {
2690         swapon -s | awk '($1 == "'$1'") { print $4 }'
2691 }
2692
2693 # excercise swapping to lustre by adding a high priority swapfile entry
2694 # and then consuming memory until it is used.
2695 test_68() {
2696         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
2697         [ "`lsmod|grep obdfilter`" ] && echo "skipping $TESTNAME (local OST)" && \
2698                 return
2699
2700         find_loop_dev
2701         dd if=/dev/zero of=$DIR/f68 bs=64k count=1024
2702
2703         trap cleanup_68 EXIT
2704
2705         losetup $LOOPDEV $DIR/f68 || error "losetup $LOOPDEV failed"
2706         mkswap $LOOPDEV
2707         swapon -p 32767 $LOOPDEV || error "swapon $LOOPDEV failed"
2708
2709         echo "before: `swapon -s | grep $LOOPDEV`"
2710         KBFREE=`meminfo MemTotal`
2711         $MEMHOG $KBFREE || error "error allocating $KBFREE kB"
2712         echo "after: `swapon -s | grep $LOOPDEV`"
2713         SWAPUSED=`swap_used $LOOPDEV`
2714
2715         cleanup_68
2716
2717         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
2718 }
2719 run_test 68 "support swapping to Lustre ========================"
2720
2721 # bug5265, obdfilter oa2dentry return -ENOENT
2722 # #define OBD_FAIL_OST_ENOENT 0x217
2723 test_69() {
2724         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] &&
2725                 echo "skipping $TESTNAME for remote OST" && return
2726
2727         f="$DIR/$tfile"
2728         touch $f
2729
2730         if ! $DIRECTIO write ${f}.2 0 1; then
2731                 echo "skipping $TESTNAME - O_DIRECT not implemented"
2732                 return 0
2733         fi
2734
2735         sysctl -w lustre.fail_loc=0x217
2736         truncate $f 1 # vmtruncate() will ignore truncate() error.
2737         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
2738
2739         sysctl -w lustre.fail_loc=0
2740         $DIRECTIO write $f 0 2 || error "write error"
2741
2742         cancel_lru_locks osc
2743         $DIRECTIO read $f 0 1 || error "read error"
2744
2745         sysctl -w lustre.fail_loc=0x217
2746         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
2747
2748         sysctl -w lustre.fail_loc=0
2749         rm -f $f
2750 }
2751 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
2752
2753 test_71() {
2754         which dbench > /dev/null 2>&1 || echo "dbench not installed, skip this test" && return 0
2755         DBENCH_LIB=${DBENCH_LIB:-/usr/lib/dbench}
2756         PATH=${DBENCH_LIB}:${PATH}
2757         cp `which dbench` $DIR
2758
2759         TGT=$DIR/client.txt
2760         SRC=${SRC:-$DBENCH_LIB/client.txt}
2761         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2762         SRC=$DBENCH_LIB/client_plain.txt
2763         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2764
2765         echo "copying necessary lib to $DIR"
2766         [ -d /lib64 ] && LIB71=/lib64 || LIB71=/lib
2767         mkdir -p $DIR$LIB71 || error "can't create $DIR$LIB71"
2768         cp $LIB71/libc* $DIR$LIB71 || error "can't copy $LIB71/libc*"
2769         cp $LIB71/ld-* $DIR$LIB71 || error "can't create $LIB71/ld-*"
2770
2771         echo "chroot $DIR /dbench -c client.txt 2"
2772         chroot $DIR /dbench -c client.txt 2
2773         RC=$?
2774
2775         rm -rf $DIR/dbench $TGT $DIR$LIB71
2776
2777         return $RC
2778 }
2779 run_test 71 "Running dbench on lustre (don't segment fault) ===="
2780
2781 test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
2782         check_kernel_version 43 || return 0
2783         [ "$RUNAS_ID" = "$UID" ] && echo "skipping $TESTNAME" && return
2784         touch $DIR/f72
2785         chmod 777 $DIR/f72
2786         chmod ug+s $DIR/f72
2787         $RUNAS -u $(($RUNAS_ID + 1)) dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
2788         # See if we are still setuid/sgid
2789         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
2790         # Now test that MDS is updated too
2791         cancel_lru_locks mdc
2792         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
2793         true
2794 }
2795 run_test 72 "Test that remove suid works properly (bug5695) ===="
2796
2797 # bug 3462 - multiple simultaneous MDC requests
2798 test_73() {
2799         mkdir $DIR/d73-1 
2800         mkdir $DIR/d73-2
2801         multiop $DIR/d73-1/f73-1 O_c &
2802         pid1=$!
2803         #give multiop a chance to open
2804         usleep 500
2805
2806         echo 0x80000129 > /proc/sys/lustre/fail_loc
2807         multiop $DIR/d73-1/f73-2 Oc &
2808         sleep 1
2809         echo 0 > /proc/sys/lustre/fail_loc
2810
2811         multiop $DIR/d73-2/f73-3 Oc &
2812         pid3=$!
2813
2814         kill -USR1 $pid1
2815         wait $pid1 || return 1
2816
2817         sleep 25
2818
2819         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
2820         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5 
2821         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6 
2822
2823         rm -rf $DIR/d73-*
2824 }
2825 run_test 73 "multiple MDC requests (should not deadlock)"
2826
2827 test_74() { # bug 6149, 6184
2828         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
2829         #
2830         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
2831         # will spin in a tight reconnection loop
2832         sysctl -w lustre.fail_loc=0x8000030e
2833         # get any lock
2834         touch $DIR/f74
2835         sysctl -w lustre.fail_loc=0
2836         true
2837 }
2838 run_test 74 "ldlm_enqueue freed-export error path (shouldn't LBUG)"
2839
2840 JOIN=${JOIN:-"lfs join"}
2841 F75=$DIR/f75
2842 F128k=${F75}_128k
2843 FHEAD=${F75}_head
2844 FTAIL=${F75}_tail
2845 export T75_PREP=no
2846 test75_prep() {
2847         [ $T75_PREP = "yes" ] && return
2848         echo "using F75=$F75, F128k=$F128k, FHEAD=$FHEAD, FTAIL=$FTAIL"
2849  
2850         dd if=/dev/urandom of=${F75}_128k bs=128k count=1 || error "dd failed"
2851         log "finished dd"
2852         chmod 777 ${F128k}
2853         T75_PREP=yes
2854 }
2855  
2856 test_75a() {
2857         test75_prep
2858  
2859         cp -p ${F128k} ${FHEAD}
2860         log "finished cp to $FHEAD"
2861         cp -p ${F128k} ${FTAIL}
2862         log "finished cp to $FTAIL"
2863         cat ${F128k} ${F128k} > ${F75}_sim_sim
2864  
2865         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2866         log "finished join $FHEAD to ${F75}_sim_sim"
2867         cmp ${FHEAD} ${F75}_sim_sim || error "${FHEAD} ${F75}_sim_sim differ"
2868         log "finished cmp $FHEAD to ${F75}_sim_sim"
2869         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} still exist after join"
2870 }
2871 run_test 75a "TEST join file ===================================="
2872  
2873 test_75b() {
2874         test75_prep
2875  
2876         cp -p ${F128k} ${FTAIL}
2877         cat ${F75}_sim_sim >> ${F75}_join_sim
2878         cat ${F128k} >> ${F75}_join_sim
2879         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2880         cmp ${FHEAD} ${F75}_join_sim || \
2881                 error "${FHEAD} ${F75}_join_sim are different"
2882         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join"
2883 }
2884 run_test 75b "TEST join file 2 =================================="
2885  
2886 test_75c() {
2887         test75_prep
2888  
2889         cp -p ${F128k} ${FTAIL}
2890         cat ${F128k} >> ${F75}_sim_join
2891         cat ${F75}_join_sim >> ${F75}_sim_join
2892         $JOIN ${FTAIL} ${FHEAD} || error "join error"
2893         cmp ${FTAIL} ${F75}_sim_join || \
2894                 error "${FTAIL} ${F75}_sim_join are different"
2895         $CHECKSTAT -a ${FHEAD} || error "tail ${FHEAD} exist after join"
2896 }
2897 run_test 75c "TEST join file 3 =================================="
2898  
2899 test_75d() {
2900         test75_prep
2901  
2902         cp -p ${F128k} ${FHEAD}
2903         cp -p ${F128k} ${FHEAD}_tmp
2904         cat ${F75}_sim_sim >> ${F75}_join_join
2905         cat ${F75}_sim_join >> ${F75}_join_join
2906         $JOIN ${FHEAD} ${FHEAD}_tmp || error "join ${FHEAD} ${FHEAD}_tmp error"
2907         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2908         cmp ${FHEAD} ${F75}_join_join ||error "${FHEAD} ${F75}_join_join differ"        $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join"
2909         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)"
2910 }
2911 run_test 75d "TEST join file 4 =================================="
2912  
2913 test_75e() {
2914         test75_prep
2915  
2916         rm -rf ${FHEAD} || "delete join file error"
2917 }
2918 run_test 75e "TEST join file 5 (remove joined file) ============="
2919  
2920 test_75f() {
2921         test75_prep
2922  
2923         cp -p ${F128k} ${F75}_join_10_compare
2924         cp -p ${F128k} ${F75}_join_10
2925         for ((i = 0; i < 10; i++)); do
2926                 cat ${F128k} >> ${F75}_join_10_compare
2927                 cp -p ${F128k} ${FTAIL}
2928                 $JOIN ${F75}_join_10 ${FTAIL} || \
2929                         error "join ${F75}_join_10 ${FTAIL} error"
2930                 $CHECKSTAT -a ${FTAIL} || error "tail file exist after join"
2931         done
2932         cmp ${F75}_join_10 ${F75}_join_10_compare || \
2933                 error "files ${F75}_join_10 ${F75}_join_10_compare differ"
2934 }
2935 run_test 75f "TEST join file 6 (join 10 files) =================="
2936  
2937 test_75g() {
2938         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
2939         $LFS getstripe ${F75}_join_10
2940  
2941         $OPENUNLINK ${F75}_join_10 ${F75}_join_10 || error "files unlink open"
2942  
2943         ls -l $F75*
2944 }
2945 run_test 75g "TEST join file 7 (open unlink) ===================="
2946
2947 num_inodes() {
2948         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
2949 }
2950
2951 test_76() { # bug 1443
2952         BEFORE_INODES=`num_inodes`
2953         echo "before inodes: $BEFORE_INODES"
2954         for i in `seq 1000`; do
2955                 touch $DIR/$tfile
2956                 rm -f $DIR/$tfile
2957         done
2958         AFTER_INODES=`num_inodes`
2959         echo "after inodes: $AFTER_INODES"
2960         [ $AFTER_INODES -gt $((BEFORE_INODES + 32)) ] && \
2961                 error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
2962         true
2963 }
2964 run_test 76 "destroy duplicate inodes in client inode cache ===="
2965
2966 F77_TMP=$TMP/f77-temp
2967 test_77a() { # bug 10889
2968         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
2969         if [ ! -f $F77_TMP ]; then
2970                 dd if=/dev/urandom of=$F77_TMP bs=1M count=8 || \
2971                         error "error writing to $F77_TMP"
2972         fi
2973         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=8 || error "dd error"
2974         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
2975 }
2976 run_test 77a "normal checksum read/write operation ============="
2977
2978 test_77b() { # bug 10889
2979         [ ! -f $F77_TMP ] && echo "requires 77a" && return  
2980         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
2981         sysctl -w lustre.fail_loc=0x80000409
2982         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
2983         dd if=$F77_TMP of=$DIR/f77b bs=8M count=1 conv=sync || \
2984                 error "write error: rc=$?"
2985         sysctl -w lustre.fail_loc=0
2986         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
2987 }
2988 run_test 77b "checksum error on client write ===================="
2989
2990 test_77c() { # bug 10889
2991         [ ! -f $F77_TMP ] && echo "requires 77a" && return  
2992         cancel_lru_locks osc
2993         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
2994         sysctl -w lustre.fail_loc=0x80000408
2995         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
2996         cmp $F77_TMP $DIR/f77b || error "file compare failed"
2997         sysctl -w lustre.fail_loc=0
2998         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
2999 }
3000 run_test 77c "checksum error on client read ==================="
3001
3002 test_77d() { # bug 10889
3003         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3004         sysctl -w lustre.fail_loc=0x80000409
3005         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
3006         directio write $DIR/f77  0 1 || error "direct write: rc=$?"
3007         sysctl -w lustre.fail_loc=0
3008         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
3009 }
3010 run_test 77d "checksum error on OST direct write ==============="
3011
3012 test_77e() { # bug 10889
3013         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3014         sysctl -w lustre.fail_loc=0x80000408
3015         for f in $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
3016         cancel_lru_locks osc
3017         directio read $DIR/f77 0 1 || error "direct read: rc=$?"
3018         sysctl -w lustre.fail_loc=0
3019         for f in $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
3020 }
3021 run_test 77e "checksum error on OST direct read ================"
3022
3023 test_77f() { # bug 10889
3024         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3025         sysctl -w lustre.fail_loc=0x409
3026         for f in $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
3027         directio write $DIR/f77 0 1 && error "direct write succeeded"
3028         sysctl -w lustre.fail_loc=0
3029         for f in $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
3030 }
3031 run_test 77f "repeat checksum error on write (expect error) ===="
3032
3033 test_77g() { # bug 10889
3034         [ ! -f $F77_TMP ] && echo "requires 77a" && return  
3035         [ -z "`lsmod|grep obdfilter`" ] &&
3036                 echo "skipping $TESTNAME (remote OST)" && return
3037         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
3038         sysctl -w lustre.fail_loc=0x8000021a
3039         for f in  $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
3040         dd if=$F77_TMP of=$DIR/f77 bs=8M count=1 || error "write error: rc=$?"
3041         sysctl -w lustre.fail_loc=0
3042         for f in $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
3043 }
3044 run_test 77g "checksum error on OST write ======================"
3045
3046 test_77h() { # bug 10889
3047         [ ! -f $DIR/f77 ] && echo "requires 77a,g" && return  
3048         [ -z "`lsmod|grep obdfilter`" ] &&
3049                 echo "skipping $TESTNAME (remote OST)" && return
3050         cancel_lru_locks osc
3051         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
3052         sysctl -w lustre.fail_loc=0x8000021b
3053         for f in $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 1 >> $f ; done
3054         cmp $F77_TMP $DIR/f77 || error "file compare failed"
3055         sysctl -w lustre.fail_loc=0
3056         for f in $LPROC/llite/${FSNAME}-*/checksum_pages ; do echo 0 >> $f ; done
3057 }
3058 run_test 77h "checksum error on OST read ======================="
3059
3060 rm -f $F77_TMP
3061 unset F77_TMP
3062
3063 test_78() { # bug 10901
3064         MEMFREE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
3065         [ $MEMFREE -gt 512 ] && MEMFREE=512
3066         $DIRECTIO rdwr $DIR/$tfile 0 $MEMFREE 1048576
3067 }
3068 run_test 78 "handle large O_DIRECT writes correctly ============"
3069
3070 # on the LLNL clusters, runas will still pick up root's $TMP settings,
3071 # which will not be writable for the runas user, and then you get a CVS
3072 # error message with a corrupt path string (CVS bug) and panic.
3073 # We're not using much space, so just stick it in /tmp, which is safe.
3074 OLDTMPDIR=$TMPDIR
3075 OLDTMP=$TMP
3076 TMPDIR=/tmp
3077 TMP=/tmp
3078 OLDHOME=$HOME
3079 [ $RUNAS_ID -ne $UID ] && HOME=/tmp
3080
3081 test_99a() {
3082         mkdir -p $DIR/d99cvsroot
3083         chown $RUNAS_ID $DIR/d99cvsroot
3084         $RUNAS cvs -d $DIR/d99cvsroot init || error
3085 }
3086 run_test 99a "cvs init ========================================="
3087
3088 test_99b() {
3089         [ ! -d $DIR/d99cvsroot ] && test_99a
3090         cd /etc/init.d
3091         # some versions of cvs import exit(1) when asked to import links or
3092         # files they can't read.  ignore those files.
3093         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
3094                         ! -perm +4 -printf '-I %f\n')
3095         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
3096                 d99reposname vtag rtag
3097 }
3098 run_test 99b "cvs import ======================================="
3099
3100 test_99c() {
3101         [ ! -d $DIR/d99cvsroot ] && test_99b
3102         cd $DIR
3103         mkdir -p $DIR/d99reposname
3104         chown $RUNAS_ID $DIR/d99reposname
3105         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
3106 }
3107 run_test 99c "cvs checkout ====================================="
3108
3109 test_99d() {
3110         [ ! -d $DIR/d99cvsroot ] && test_99c
3111         cd $DIR/d99reposname
3112         $RUNAS touch foo99
3113         $RUNAS cvs add -m 'addmsg' foo99
3114 }
3115 run_test 99d "cvs add =========================================="
3116
3117 test_99e() {
3118         [ ! -d $DIR/d99cvsroot ] && test_99c
3119         cd $DIR/d99reposname
3120         $RUNAS cvs update
3121 }
3122 run_test 99e "cvs update ======================================="
3123
3124 test_99f() {
3125         [ ! -d $DIR/d99cvsroot ] && test_99d
3126         cd $DIR/d99reposname
3127         $RUNAS cvs commit -m 'nomsg' foo99
3128 }
3129 run_test 99f "cvs commit ======================================="
3130
3131 test_100() {
3132         netstat -tna | while read PROT SND RCV LOCAL REMOTE STAT; do
3133                 [ "$PROT" != "tcp" ] && continue
3134                 RPORT=`echo $REMOTE | cut -d: -f2`
3135                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
3136                 LPORT=`echo $LOCAL | cut -d: -f2`
3137                 if [ $LPORT -ge 1024 ]; then
3138                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
3139                         netstat -tna
3140                         error "local: $LPORT > 1024, remote: $RPORT"
3141                 fi
3142         done
3143         true
3144 }
3145 run_test 100 "check local port using privileged port ==========="
3146
3147 function get_named_value()
3148 {
3149     local tag
3150
3151     tag=$1
3152     while read ;do
3153         line=$REPLY
3154         case $line in
3155         $tag*)
3156             echo $line | sed "s/^$tag//"
3157             break
3158             ;;
3159         esac
3160     done
3161 }
3162
3163 export CACHE_MAX=`cat /proc/fs/lustre/llite/*/max_cached_mb | head -n 1`
3164 cleanup_101() {
3165         for s in $LPROC/llite/*/max_cached_mb; do
3166                 echo $CACHE_MAX > $s
3167         done
3168         trap 0
3169 }
3170
3171 test_101() {
3172         local s
3173         local discard
3174         local nreads=10000
3175         [ "$CPU" = "UML" ] && nreads=1000
3176         local cache_limit=32
3177
3178         for s in $LPROC/osc/*/rpc_stats; do
3179                 echo 0 > $s
3180         done
3181         trap cleanup_101 EXIT
3182         for s in $LPROC/llite/*; do
3183                 echo 0 > $s/read_ahead_stats
3184                 echo $cache_limit > $s/max_cached_mb
3185         done
3186
3187         #
3188         # randomly read 10000 of 64K chunks from file 3x 32MB in size
3189         #
3190         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
3191         $RANDOM_READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
3192
3193         discard=0
3194         for s in $LPROC/llite/*; do
3195                 discard=$(($discard + $(cat $s/read_ahead_stats | get_named_value 'read but discarded')))
3196         done
3197         cleanup_101
3198
3199         if [ $(($discard * 10)) -gt $nreads ] ;then
3200                 for s in $LPROC/osc/*/rpc_stats; do
3201                         echo $s; cat $s
3202                 done
3203                 for s in $LPROC/llite/*/read_ahead_stats; do
3204                         echo $s; cat $s
3205                 done
3206                 error "too many ($discard) discarded pages" 
3207         fi
3208         rm -f $DIR/$tfile || true
3209 }
3210 run_test 101 "check read-ahead for random reads ================"
3211
3212 export SETUP_TEST102=no
3213 setup_test102() {
3214         [ "$SETUP_TEST102" = "yes" ] && return
3215         mkdir -p $DIR/$tdir
3216         STRIPE_SIZE=65536
3217         STRIPE_COUNT=4 
3218         STRIPE_OFFSET=2
3219
3220         trap cleanup_test102 EXIT
3221         cd $DIR
3222         $SETSTRIPE $tdir $STRIPE_SIZE  $STRIPE_OFFSET $STRIPE_COUNT
3223         cd $DIR/$tdir 
3224         for num in 1 2 3 4
3225         do
3226                 for count in 1 2 3 4
3227                 do
3228                         for offset in 0 1 2 3 
3229                         do
3230                                 local stripe_size=`expr $STRIPE_SIZE \* $num`
3231                                 local file=file"$num-$offset-$count"
3232                                 $SETSTRIPE $file $stripe_size  $offset $count
3233                         done
3234                 done
3235         done
3236
3237         cd ..
3238         star -c  f=$TMP/f102.tar $tdir 
3239         SETUP_TEST102=yes
3240 }
3241
3242 cleanup_test102() {
3243         [ "SETUP_TEST102" = "YES" ] || return
3244         trap 0
3245         rm -f $TMP/f102.tar
3246         rm -rf $DIR/$tdir
3247         SETUP_TEST102=no
3248 }
3249
3250 test_102a() {
3251         local testfile=$DIR/xattr_testfile
3252
3253         rm -f $testfile
3254         touch $testfile
3255
3256         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
3257         [ -z "`grep xattr $LPROC/mdc/*[mM][dD][cC]*/connect_flags`" ] && echo "skipping $TESTNAME (must have user_xattr)" && return
3258         [ -z "$(which setfattr 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find setfattr)" && return
3259
3260         echo "set/get xattr..."
3261         setfattr -n trusted.name1 -v value1 $testfile || error
3262         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
3263         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
3264  
3265         setfattr -n user.author1 -v author1 $testfile || error
3266         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
3267         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
3268
3269         echo "listxattr..."
3270         setfattr -n trusted.name2 -v value2 $testfile || error
3271         setfattr -n trusted.name3 -v value3 $testfile || error
3272         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3273         grep "trusted.name" | wc -l` -eq 3 ] || error
3274
3275  
3276         setfattr -n user.author2 -v author2 $testfile || error
3277         setfattr -n user.author3 -v author3 $testfile || error
3278         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
3279         grep "user" | wc -l` -eq 3 ] || error
3280
3281         echo "remove xattr..."
3282         setfattr -x trusted.name1 $testfile || error
3283         getfattr -d -m trusted $testfile 2> /dev/null | \
3284         grep "trusted.name1" && error || true
3285
3286         setfattr -x user.author1 $testfile || error
3287         getfattr -d -m user $testfile 2> /dev/null | \
3288         grep "user.author1" && error || true
3289
3290         # b10667: setting lustre special xattr be silently discarded
3291         echo "set lustre special xattr ..."
3292         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
3293
3294         rm -f $testfile
3295 }
3296 run_test 102a "user xattr test =================================="
3297
3298 test_102b() {
3299         # b10930: get/set/list trusted.lov xattr
3300         echo "get/set/list trusted.lov xattr ..."
3301         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
3302         local testfile=$DIR/$tfile
3303         $SETSTRIPE $testfile 65536 1 2
3304         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3305         grep "trusted.lov" || error
3306
3307         local testfile2=${testfile}2
3308         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
3309                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
3310         
3311         $MCREATE $testfile2
3312         setfattr -n trusted.lov -v $value $testfile2    
3313         local tmp_file=${testfile}3
3314         $GETSTRIPE -v $testfile2 > $tmp_file
3315         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
3316         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
3317         [ $stripe_size -eq 65536 ] || error "different stripe size"
3318         [ $stripe_count -eq 2 ] || error "different stripe count"
3319 }
3320 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
3321
3322 test_102c() {
3323         # b10930: get/set/list trusted.lov xattr
3324         echo "get/set/list trusted.lov xattr ..."
3325         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
3326         mkdir -p $DIR/$tdir
3327         chown $RUNAS_ID $DIR/$tdir
3328         local testfile=$DIR/$tdir/$tfile
3329         $RUNAS $SETSTRIPE $testfile 65536 1 2
3330         $RUNAS getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3331         grep "trusted.lov" || error
3332
3333         local testfile2=${testfile}2
3334         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
3335                      grep "trusted.lov" |sed -e 's/[^=]\+=//'  `
3336         
3337         $RUNAS $MCREATE $testfile2
3338         $RUNAS setfattr -n trusted.lov -v $value $testfile2     
3339         local tmp_file=${testfile}3
3340         $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
3341         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
3342         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
3343         [ $stripe_size -eq 65536 ] || error "different stripe size"
3344         [ $stripe_count -eq 2 ] || error "different stripe count"
3345 }
3346 run_test 102c "non-root getfattr/setfattr for trusted.lov EAs ==========="
3347
3348 get_stripe_info() {
3349         stripe_size=0
3350         stripe_count=0
3351         stripe_offset=0
3352         local lines=`sed -n '/obdidx/=' $1`
3353         stripe_size=`awk '{if($1~/size/) print $2}' $1`
3354         stripe_count=`awk '{if($1~/count/) print $2}' $1`
3355         lines=`expr $lines + 1`
3356         stripe_offset=`sed -n ${lines}p $1 |awk '{print $1}'`
3357 }
3358
3359 compare_stripe_info1() {
3360         for num in 1 2 3 4
3361         do
3362                 for count in 1 2 3 4
3363                 do
3364                         for offset in 0 1 2 3 
3365                         do
3366                                 local size=`expr $STRIPE_SIZE \* $num`
3367                                 local file=file"$num-$offset-$count"
3368                                 local tmp_file=out
3369                                 $GETSTRIPE -v $file > $tmp_file 
3370                                 get_stripe_info  $tmp_file
3371                                 if test $stripe_size -ne $size
3372                                 then
3373                                         error "$file: different stripe size" && return
3374                                 fi
3375                                 if test $stripe_count -ne $count
3376                                 then
3377                                         error "$file: different stripe count" && return
3378                                 fi
3379                                 if test $stripe_offset -ne 0
3380                                 then
3381                                         error "$file: different stripe offset" && return
3382                                 fi
3383                                 rm -f $tmp_file
3384                         done
3385                 done
3386         done
3387 }
3388
3389 compare_stripe_info2() {
3390         for num in 1 2 3 4
3391         do
3392                 for count in 1 2 3 4
3393                 do
3394                         for offset in 0 1 2 3 
3395                         do
3396                                 local size=`expr $STRIPE_SIZE \* $num`
3397                                 local file=file"$num-$offset-$count"
3398                                 local tmp_file=out
3399                                 $GETSTRIPE -v $file > $tmp_file
3400                                 get_stripe_info  $tmp_file
3401                                 if test $stripe_size -ne $size
3402                                 then
3403                                         error "$file: different stripe size" && return  
3404                                 fi
3405                                 if test $stripe_count -ne $count
3406                                 then
3407                                         error "$file: different stripe count" && return
3408                                 fi
3409                                 if test $stripe_offset -ne $offset
3410                                 then
3411                                         error "$file: different stripe offset" && return
3412                                 fi
3413                                 rm -f $tmp_file
3414                         done
3415                 done
3416         done
3417 }
3418
3419 test_102d() {
3420         # b10930: star test for trusted.lov xattr
3421         star --xhelp 2>&1 | grep -q nolustre  
3422         if [ $? -ne 0 ]
3423         then
3424                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3425         fi
3426         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3427         setup_test102
3428         mkdir -p $DIR/d102d
3429         star -x  f=$TMP/f102.tar -C $DIR/d102d
3430         cd $DIR/d102d/$tdir
3431         compare_stripe_info1
3432
3433 }
3434 run_test 102d "star restore stripe info from tarfile,not keep osts ==========="
3435
3436 test_102e() {
3437         # b10930: star test for trusted.lov xattr
3438         star --xhelp 2>&1 | grep -q nolustre  
3439         if [ $? -ne 0 ]
3440         then
3441                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3442         fi
3443         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3444         setup_test102
3445         mkdir -p $DIR/d102e
3446         star -x  -preserve-osts f=$TMP/f102.tar -C $DIR/d102e
3447         cd $DIR/d102e/$tdir
3448         compare_stripe_info2
3449 }
3450 run_test 102e "star restore stripe info from tarfile, keep osts ==========="
3451
3452 test_102f() {
3453         # b10930: star test for trusted.lov xattr
3454         star --xhelp 2>&1 | grep -q nolustre  
3455         if [ $? -ne 0 ]
3456         then
3457                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3458         fi
3459         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3460         setup_test102
3461         mkdir -p $DIR/d102f
3462         cd $DIR
3463         star -copy  $tdir $DIR/d102f
3464         cd $DIR/d102f/$tdir
3465         compare_stripe_info1
3466 }
3467 run_test 102f "star copy files, not keep osts ==========="
3468
3469 test_102g() {
3470         # b10930: star test for trusted.lov xattr
3471         star --xhelp 2>&1 | grep -q nolustre  
3472         if [ $? -ne 0 ]
3473         then
3474                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3475         fi
3476         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3477         setup_test102
3478         mkdir -p $DIR/d102g
3479         cd $DIR
3480         star -copy -preserve-osts $tdir $DIR/d102g
3481         cd $DIR/d102g/$tdir
3482         compare_stripe_info2
3483         cleanup_test102
3484 }
3485 run_test 102g "star copy files, keep osts ==========="
3486
3487 run_acl_subtest()
3488 {
3489     $SAVE_PWD/acl/run $SAVE_PWD/acl/$1.test
3490     return $?
3491 }
3492
3493 test_103 () {
3494     [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
3495     [ -z "$(grep acl $LPROC/mdc/*[mM][dD][cC]*/connect_flags)" ] && echo "skipping $TESTNAME (must have acl enabled)" && return
3496     [ -z "$(which setfacl 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find setfacl)" && return
3497
3498     SAVE_UMASK=`umask`
3499     umask 0022
3500     cd $DIR
3501
3502     echo "performing cp ..."
3503     run_acl_subtest cp || error
3504     echo "performing getfacl-noacl..."
3505     run_acl_subtest getfacl-noacl || error
3506     echo "performing misc..."
3507     run_acl_subtest misc || error
3508 #    XXX add back permission test when we support supplementary groups.
3509 #    echo "performing permissions..."
3510 #    run_acl_subtest permissions || error
3511     echo "performing setfacl..."
3512     run_acl_subtest setfacl || error
3513
3514     # inheritance test got from HP
3515     echo "performing inheritance..."
3516     cp $SAVE_PWD/acl/make-tree . || error
3517     chmod +x make-tree || error
3518     run_acl_subtest inheritance || error
3519     rm -f make-tree
3520
3521     cd $SAVE_PWD
3522     umask $SAVE_UMASK
3523 }
3524 run_test 103 "acl test ========================================="
3525
3526 test_104() {
3527         touch $DIR/$tfile
3528         lfs df || error "lfs df failed"
3529         lfs df -ih || error "lfs df -ih failed"
3530         lfs df -h $DIR || error "lfs df -h $DIR failed"
3531         lfs df -i $DIR || error "lfs df -i $DIR failed"
3532         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
3533         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
3534         
3535         OSC=`awk '/-osc-|OSC.*MNT/ {print $4}' $LPROC/devices | head -n 1`
3536         lctl --device %$OSC deactivate
3537         lfs df || error "lfs df with deactivated OSC failed"
3538         lctl --device %$OSC recover
3539         lfs df || error "lfs df with reactivated OSC failed"
3540 }
3541 run_test 104 "lfs df [-ih] [path] test ========================="
3542
3543 test_105a() {
3544         # doesn't work on 2.4 kernels
3545         touch $DIR/$tfile
3546         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3547         then
3548                 flocks_test on -f $DIR/$tfile || error "fail flock on"
3549         else
3550                 flocks_test off -f $DIR/$tfile || error "fail flock off"
3551         fi
3552 }
3553 run_test 105a "flock when mounted without -o flock test ========"
3554
3555 test_105b() {
3556         touch $DIR/$tfile
3557         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3558         then
3559                 flocks_test on -c $DIR/$tfile || error "fail flock on"
3560         else
3561                 flocks_test off -c $DIR/$tfile || error "fail flock off"
3562         fi
3563 }
3564 run_test 105b "fcntl when mounted without -o flock test ========"
3565
3566 test_105c() {
3567         touch $DIR/$tfile
3568         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3569         then
3570                 flocks_test on -l $DIR/$tfile || error "fail flock on"
3571         else
3572                 flocks_test off -l $DIR/$tfile || error "fail flock off"
3573         fi
3574 }
3575 run_test 105c "lockf when mounted without -o flock test ========"
3576
3577 test_106() { #10921
3578         mkdir $DIR/d106
3579         $DIR/d106 && error
3580         chmod 777 $DIR/d106 || error
3581 }
3582 run_test 106 "attempt exec of dir followed by chown of that dir"
3583
3584 test_107() {
3585         CDIR=`pwd`
3586         cd $DIR
3587         ulimit -c unlimited
3588         sleep 60 &
3589         SLEEPPID=$!
3590
3591         file=`cat /proc/sys/kernel/core_pattern`
3592         core_pid=`cat /proc/sys/kernel/core_uses_pid`
3593         [ $core_pid -eq 1 ] && file=$file.$SLEEPPID
3594         rm -f $file
3595         sleep 1
3596
3597         kill -s 11 $SLEEPPID
3598         wait $SLEEPPID
3599         if [ -e $file ]; then
3600                 size=`stat -c%s $file`
3601                 [ $size -eq 0 ] && error "Fail to create core file $file"
3602         else
3603                 error "Fail to create core file $file"
3604         fi
3605         rm -f $file
3606         cd $CDIR
3607 }
3608 run_test 107 "Coredump on SIG"
3609
3610 test_115() {
3611         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
3612             cut -c11-20)
3613         [ -z "$OSTIO_pre" ] && echo "skipping $TESTNAME: no OSS threads" && \
3614             return
3615         echo "Starting with $OSTIO_pre threads"
3616
3617         NUMTEST=20000
3618         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3619         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
3620         echo "$NUMTEST creates/unlinks"
3621         mkdir -p $DIR/$tdir
3622         createmany -o $DIR/$tdir/$tfile $NUMTEST
3623         unlinkmany $DIR/$tdir/$tfile $NUMTEST
3624
3625         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
3626             cut -c11-20)
3627
3628         # don't return an error
3629         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
3630             "FAIL: No addition ll_ost_io threads were created ($OSTIO_pre)" &&\
3631             echo "This may be fine, depending on what ran before this test" &&\
3632             echo "and how fast this system is." && return
3633
3634         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
3635 }
3636 run_test 115 "verify dynamic thread creation===================="
3637
3638 free_min_max () {
3639         AVAIL=($(cat $LPROC/osc/*[oO][sS][cC]-*/kbytesavail))
3640         echo OST kbytes available: ${AVAIL[@]}
3641         MAXI=0; MAXV=${AVAIL[0]}
3642         MINI=0; MINV=${AVAIL[0]}
3643         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
3644             #echo OST $i: ${AVAIL[i]}kb
3645             if [ ${AVAIL[i]} -gt $MAXV ]; then
3646                 MAXV=${AVAIL[i]}; MAXI=$i
3647             fi
3648             if [ ${AVAIL[i]} -lt $MINV ]; then
3649                 MINV=${AVAIL[i]}; MINI=$i
3650             fi
3651         done
3652         echo Min free space: OST $MINI: $MINV 
3653         echo Max free space: OST $MAXI: $MAXV 
3654 }
3655
3656 test_116() {
3657         [ "$OSTCOUNT" -lt "2" ] && echo "not enough OSTs" && return
3658
3659         echo -n "Free space priority "
3660         cat $LPROC/lov/*/qos_prio_free
3661         DELAY=$(cat $LPROC/lov/*/qos_maxage | head -1 | awk '{print $1}')
3662         declare -a AVAIL
3663         free_min_max
3664         [ $MINV -gt 960000 ] && echo "too much free space in OST$MINI, skip" &&\
3665                 return
3666
3667         # generate uneven OSTs
3668         mkdir -p $DIR/$tdir/OST${MINI}
3669         declare -i FILL
3670         FILL=$(($MINV / 4))
3671         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
3672         $SETSTRIPE $DIR/$tdir/OST${MINI} 0 $MINI 1
3673         i=1
3674         while [ $FILL -gt 0 ]; do
3675             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
3676             FILL=$(($FILL - 2048))
3677             echo -n .
3678             i=$(($i + 1))
3679         done
3680         FILL=$(($MINV / 4))
3681         sync
3682         sleep $DELAY
3683
3684         free_min_max
3685         DIFF=$(($MAXV - $MINV))
3686         DIFF2=$(($MINV * 2 / 10))
3687         echo -n "diff=$DIFF must be > 20%=$DIFF2 for QOS mode..."
3688         if [ $DIFF -gt $DIFF2 ]; then
3689             echo "ok"
3690         else
3691             echo "failed - QOS mode won't be used"
3692             error "QOS imbalance criteria not met"
3693             return
3694         fi
3695
3696         MINI1=$MINI; MINV1=$MINV
3697         MAXI1=$MAXI; MAXV1=$MAXV
3698
3699         # now fill using QOS
3700         echo writing a bunch of files to QOS-assigned OSTs
3701         i=1
3702         while [ $FILL -gt 0 ]; do
3703             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
3704             FILL=$(($FILL - 200))
3705             echo -n .
3706             i=$(($i + 1))
3707         done
3708         echo "wrote $i 200k files"
3709         sync
3710         sleep $DELAY
3711
3712         echo "Note: free space may not be updated, so measurements might be off"
3713         free_min_max
3714         DIFF2=$(($MAXV - $MINV))
3715         echo "free space delta: orig $DIFF final $DIFF2"
3716         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!" 
3717         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
3718         echo "Wrote $DIFF to OST $MINI1"
3719         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
3720         echo "Wrote $DIFF2 to OST $MAXI1"
3721         echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more to OST $MAXI1"
3722
3723         # Figure out which files were written where 
3724         UUID=$(awk '/'$MINI1': / {print $2; exit}' $LPROC/lov/${FSNAME}-clilov-*/target_obd)
3725         echo $UUID
3726         MINC=$($LFS getstripe --obd $UUID $DIR/$tdir | wc -l)
3727         echo "$MINC files created on smaller OST $MINI1"
3728         UUID=$(awk '/'$MAXI1': / {print $2; exit}' $LPROC/lov/${FSNAME}-clilov-*/target_obd)
3729         MAXC=$($LFS getstripe --obd $UUID $DIR/$tdir | wc -l)
3730         echo "$MAXC files created on larger OST $MAXI1"
3731         echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to OST $MAXI1"
3732         [ $MAXC -gt $MINC ] || error "stripe QOS didn't balance free space"
3733 }
3734 run_test 116 "stripe QOS: free space balance ==================="
3735
3736 test_117() # bug 10891
3737 {
3738         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
3739         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
3740         sysctl -w lustre.fail_loc=0x21e
3741         > $DIR/$tfile || error "truncate failed"
3742         sysctl -w lustre.fail_loc=0
3743         echo "Truncate succeeded."
3744 }
3745 run_test 117 "verify fsfilt_extend =========="
3746
3747 TMPDIR=$OLDTMPDIR
3748 TMP=$OLDTMP
3749 HOME=$OLDHOME
3750
3751 log "cleanup: ======================================================"
3752 if [ "`mount | grep $MOUNT`" ]; then
3753     rm -rf $DIR/[Rdfs][1-9]*
3754 fi
3755 if [ "$I_MOUNTED" = "yes" ]; then
3756     cleanupall -f || error "cleanup failed"
3757 fi
3758
3759
3760 echo '=========================== finished ==============================='
3761 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true
3762 echo "$0: completed"