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