Whamcloud - gitweb
LU-15 slow IO with read intense application
[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 init_logging
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         sleep 2 # wait async osc connect to finish
3803         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
3804                 param=`echo ${VALUE[0]} | cut -d "=" -f1`
3805                 algo=`lctl get_param -n $param | sed 's/.*\[\(.*\)\].*/\1/g'`
3806                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
3807         done
3808         remount_client $MOUNT
3809 }
3810 run_test 77j "client only supporting ADLER32 ===================="
3811
3812 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
3813 rm -f $F77_TMP
3814 unset F77_TMP
3815
3816 test_78() { # bug 10901
3817         remote_ost || { skip_env "local OST" && return; }
3818
3819         cancel_lru_locks osc
3820         NSEQ=5
3821         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
3822         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
3823         # directio allocates the buffer twice, one for writes and another
3824         # one for reads, so that it can check the data consistency
3825         F78SIZE=$((F78SIZE / 2))
3826         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
3827         echo "MemTotal: $MEMTOTAL"
3828         # reserve 256MB of memory for the kernel and other running processes,
3829         # and then take 1/2 of the remaining memory for the read/write buffers.
3830         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
3831         echo "Mem to use for directio: $MEMTOTAL"
3832         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
3833         [ $F78SIZE -gt 512 ] && F78SIZE=512
3834         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
3835         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
3836         echo "Smallest OST: $SMALLESTOST"
3837         [ $SMALLESTOST -lt 10240 ] && \
3838                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
3839
3840         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 5)) ] && \
3841                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 5))
3842         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
3843         echo "File size: $F78SIZE"
3844         $SETSTRIPE $DIR/$tfile -c -1 || error "setstripe failed"
3845         for i in `seq 1 $NSEQ`
3846         do
3847                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
3848                 echo directIO rdwr round $i of $NSEQ
3849                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
3850         done
3851
3852         rm -f $DIR/$tfile
3853 }
3854 run_test 78 "handle large O_DIRECT writes correctly ============"
3855
3856 test_79() { # bug 12743
3857         wait_delete_completed
3858
3859         BKTOTAL=$(calc_osc_kbytes kbytestotal)
3860         BKFREE=$(calc_osc_kbytes kbytesfree)
3861         BKAVAIL=$(calc_osc_kbytes kbytesavail)
3862         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
3863         DFTOTAL=`echo $STRING | cut -d, -f1`
3864         DFUSED=`echo $STRING  | cut -d, -f2`
3865         DFAVAIL=`echo $STRING | cut -d, -f3`
3866         DFFREE=$(($DFTOTAL - $DFUSED))
3867
3868         ALLOWANCE=$((64 * $OSTCOUNT))
3869
3870         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
3871            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
3872                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
3873         fi
3874         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
3875            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
3876                 error "df free($DFFREE) mismatch OST free($BKFREE)"
3877         fi
3878         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
3879            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
3880                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
3881         fi
3882 }
3883 run_test 79 "df report consistency check ======================="
3884
3885 test_80() { # bug 10718
3886         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
3887         sync; sleep 1; sync
3888         local BEFORE=`date +%s`
3889         cancel_lru_locks osc
3890         local AFTER=`date +%s`
3891         local DIFF=$((AFTER-BEFORE))
3892         if [ $DIFF -gt 1 ] ; then
3893                 error "elapsed for 1M@1T = $DIFF"
3894         fi
3895         true
3896 }
3897 run_test 80 "Page eviction is equally fast at high offsets too  ===="
3898
3899 test_99a() {
3900         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3901         mkdir -p $DIR/d99cvsroot || error "mkdir $DIR/d99cvsroot failed"
3902         chown $RUNAS_ID $DIR/d99cvsroot || error "chown $DIR/d99cvsroot failed"
3903         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
3904         cd $TMP
3905
3906         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
3907         cd $oldPWD
3908 }
3909 run_test 99a "cvs init ========================================="
3910
3911 test_99b() {
3912         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3913         [ ! -d $DIR/d99cvsroot ] && test_99a
3914         $RUNAS [ ! -w /tmp ] && skip "/tmp has wrong w permission -- skipping" && return
3915         cd /etc/init.d || error "cd /etc/init.d failed"
3916         # some versions of cvs import exit(1) when asked to import links or
3917         # files they can't read.  ignore those files.
3918         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
3919                         ! -perm +4 -printf '-I %f\n')
3920         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
3921                 d99reposname vtag rtag > /dev/null || error "cvs import failed"
3922 }
3923 run_test 99b "cvs import ======================================="
3924
3925 test_99c() {
3926         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3927         [ ! -d $DIR/d99cvsroot ] && test_99b
3928         cd $DIR || error "cd $DIR failed"
3929         mkdir -p $DIR/d99reposname || error "mkdir $DIR/d99reposname failed"
3930         chown $RUNAS_ID $DIR/d99reposname || \
3931                 error "chown $DIR/d99reposname failed"
3932         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname > /dev/null || \
3933                 error "cvs co d99reposname failed"
3934 }
3935 run_test 99c "cvs checkout ====================================="
3936
3937 test_99d() {
3938         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3939         [ ! -d $DIR/d99cvsroot ] && test_99c
3940         cd $DIR/d99reposname
3941         $RUNAS touch foo99
3942         $RUNAS cvs add -m 'addmsg' foo99
3943 }
3944 run_test 99d "cvs add =========================================="
3945
3946 test_99e() {
3947         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3948         [ ! -d $DIR/d99cvsroot ] && test_99c
3949         cd $DIR/d99reposname
3950         $RUNAS cvs update
3951 }
3952 run_test 99e "cvs update ======================================="
3953
3954 test_99f() {
3955         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
3956         [ ! -d $DIR/d99cvsroot ] && test_99d
3957         cd $DIR/d99reposname
3958         $RUNAS cvs commit -m 'nomsg' foo99
3959 }
3960 run_test 99f "cvs commit ======================================="
3961
3962 test_100() {
3963         [ "$NETTYPE" = tcp ] || \
3964                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
3965                         return ; }
3966
3967         remote_ost_nodsh && skip "remote OST with nodsh" && return
3968         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3969         remote_servers || \
3970                 { skip "useless for local single node setup" && return; }
3971
3972         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
3973                 [ "$PROT" != "tcp" ] && continue
3974                 RPORT=$(echo $REMOTE | cut -d: -f2)
3975                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
3976
3977                 rc=0
3978                 LPORT=`echo $LOCAL | cut -d: -f2`
3979                 if [ $LPORT -ge 1024 ]; then
3980                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
3981                         netstat -tna
3982                         error_exit "local: $LPORT > 1024, remote: $RPORT"
3983                 fi
3984         done
3985         [ "$rc" = 0 ] || error_exit "privileged port not found" )
3986 }
3987 run_test 100 "check local port using privileged port ==========="
3988
3989 function get_named_value()
3990 {
3991     local tag
3992
3993     tag=$1
3994     while read ;do
3995         line=$REPLY
3996         case $line in
3997         $tag*)
3998             echo $line | sed "s/^$tag//"
3999             break
4000             ;;
4001         esac
4002     done
4003 }
4004
4005 export CACHE_MAX=`lctl get_param -n llite/*/max_cached_mb | head -n 1`
4006 cleanup_101() {
4007         lctl set_param -n llite.*.max_cached_mb $CACHE_MAX
4008         trap 0
4009 }
4010
4011 test_101() {
4012         local s
4013         local discard
4014         local nreads=10000
4015         [ "$CPU" = "UML" ] && nreads=1000
4016         local cache_limit=32
4017
4018         lctl set_param -n osc.*.rpc_stats 0
4019         trap cleanup_101 EXIT
4020
4021         lctl set_param -n llite.*.read_ahead_stats 0
4022         lctl set_param -n llite.*.max_cached_mb $cache_limit
4023
4024         #
4025         # randomly read 10000 of 64K chunks from file 3x 32MB in size
4026         #
4027         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
4028         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
4029
4030         discard=0
4031         for s in `lctl get_param -n llite.*.read_ahead_stats | \
4032                 get_named_value 'read but discarded' | cut -d" " -f1`; do
4033                         discard=$(($discard + $s))
4034         done
4035         cleanup_101
4036
4037         if [ $(($discard * 10)) -gt $nreads ] ;then
4038                 lctl get_param osc.*.rpc_stats
4039                 lctl get_param llite.*.read_ahead_stats
4040                 error "too many ($discard) discarded pages"
4041         fi
4042         rm -f $DIR/$tfile || true
4043 }
4044 run_test 101 "check read-ahead for random reads ================"
4045
4046 export SETUP_TEST101b=no
4047 setup_101b() {
4048         [ "$SETUP_TEST101b" = "yes" ] && return
4049         mkdir -p $DIR/$tdir
4050         STRIPE_SIZE=1048576
4051         STRIPE_COUNT=$OSTCOUNT
4052         STRIPE_OFFSET=0
4053
4054         trap cleanup_101 EXIT
4055         # prepare the read-ahead file
4056         $SETSTRIPE $DIR/$tfile -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT
4057
4058         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
4059         SETUP_TEST101b=yes
4060 }
4061
4062 cleanup_101() {
4063         trap 0
4064         rm -rf $DIR/$tdir $DIR/$tfile
4065         SETUP_TEST101b=no
4066 }
4067
4068 calc_total() {
4069         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
4070 }
4071
4072 ra_check_101b() {
4073         local READ_SIZE=$1
4074         local STRIPE_SIZE=1048576
4075         local RA_INC=1048576
4076         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
4077         local FILE_LENGTH=$((64*100))
4078         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
4079                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
4080         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
4081                         get_named_value 'read but discarded' | \
4082                         cut -d" " -f1 | calc_total`
4083
4084         if [ $DISCARD -gt $discard_limit ]; then
4085                 lctl get_param llite.*.read_ahead_stats
4086                 error "Too many ($DISCARD) discarded pages (size ${READ_SIZE})"
4087         else
4088                 echo "Read-ahead success for size ${READ_SIZE}"
4089         fi
4090 }
4091
4092 test_101b() {
4093         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs for stride-read" && return
4094         local STRIPE_SIZE=1048576
4095         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
4096         local FILE_LENGTH=$((STRIPE_SIZE*100))
4097         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
4098         # prepare the read-ahead file
4099         setup_101b
4100         cancel_lru_locks osc
4101         for BIDX in 2 4 8 16 32 64 128 256; do
4102                 local BSIZE=$((BIDX*4096))
4103                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
4104                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
4105                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
4106                 $LCTL set_param -n llite.*.read_ahead_stats 0
4107                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
4108                         -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
4109                 cancel_lru_locks osc
4110                 ra_check_101b $BSIZE
4111         done
4112         true
4113 }
4114 run_test 101b "check stride-io mode read-ahead ================="
4115
4116 test_101c() {
4117         local STRIPE_SIZE=1048576
4118         local FILE_LENGTH=$((STRIPE_SIZE*100))
4119         local nreads=10000
4120
4121         setup_101b
4122
4123         cancel_lru_locks osc
4124         $LCTL set_param osc.*.rpc_stats 0
4125         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
4126         for OSC in `$LCTL  get_param -N osc.*`
4127         do
4128                 if [ "$OSC" == "osc.num_refs" ]; then
4129                         continue
4130                 fi
4131                 lines=`$LCTL get_param -n ${OSC}.rpc_stats | wc | awk '{print $1}'`
4132                 if [ $lines -le 20 ]; then
4133                         continue
4134                 fi
4135
4136                 rpc4k=$($LCTL get_param -n $OSC | awk '$1 == "1:" { print $2; exit; }')
4137                 rpc8k=$($LCTL get_param -n $OSC | awk '$1 == "2:" { print $2; exit; }')
4138                 rpc16k=$($LCTL get_param -n $OSC | awk '$1 == "4:" { print $2; exit; }')
4139                 rpc32k=$($LCTL get_param -n $OSC | awk '$1 == "8:" { print $2; exit; }')
4140
4141                 [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
4142                 [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
4143                 [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
4144                 [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
4145
4146                 echo "Small rpc check passed!"
4147                 rpc64k=$($LCTL get_param -n $OSC | awk '$1 == "16:" { print $2; exit; }')
4148                 rpc128k=$($LCTL get_param -n $OSC | awk '$1 == "32:" { print $2; exit; }')
4149                 rpc256k=$($LCTL get_param -n $OSC | awk '$1 == "64:" { print $2; exit; }')
4150                 rpc512k=$($LCTL get_param -n $OSC | awk '$1 == "128:" { print $2; exit; }')
4151                 rpc1024k=$($LCTL get_param -n $OSC | awk '$1 == "256:" { print $2; exit; }')
4152
4153                 [ $rpc64k == 0 ]   && error "No 64k readahead IO ${rpc64k}"
4154                 [ $rpc128k == 0 ]  && error "No 128k readahead IO ${rpc128k}"
4155                 [ $rpc256k == 0 ]  && error "No 256k readahead IO ${rpc256k}"
4156                 [ $rpc512k == 0 ]  && error "No 512k readahead IO ${rpc256k}"
4157                 [ $rpc1024k == 0 ] && error "No 1024k readahead IO ${rpc1024k}"
4158                 echo "Big rpc check passed!"
4159         done
4160         cleanup_101
4161         true
4162 }
4163 run_test 101c "check stripe_size aligned read-ahead ================="
4164
4165 set_read_ahead() {
4166    lctl get_param -n llite.*.max_read_ahead_mb | head -n 1
4167    lctl set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
4168 }
4169
4170 test_101d() {
4171     local file=$DIR/$tfile
4172     local size=${FILESIZE_101c:-500}
4173     local ra_MB=${READAHEAD_MB:-40}
4174
4175     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
4176     [ $space -gt $((size / 1024)) ] ||
4177         { skip "Need free space ${size}M, have $space" && return; }
4178
4179     echo Creating ${size}M test file $file
4180     dd if=/dev/zero of=$file bs=1M count=$size
4181     echo Cancel LRU locks on lustre client to flush the client cache
4182     cancel_lru_locks osc
4183
4184     echo Disable read-ahead
4185     local old_READAHEAD=$(set_read_ahead 0)
4186
4187     echo Reading the test file $file with read-ahead disabled
4188     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
4189
4190     echo Cancel LRU locks on lustre client to flush the client cache
4191     cancel_lru_locks osc
4192     echo Enable read-ahead with ${ra_MB}MB
4193     set_read_ahead $ra_MB
4194
4195     echo Reading the test file $file with read-ahead enabled
4196     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
4197
4198     echo read-ahead disabled time read $time_ra_OFF
4199     echo read-ahead enabled  time read $time_ra_ON
4200
4201     set_read_ahead $old_READAHEAD
4202     rm -f $file
4203
4204     [ $time_ra_ON -lt $time_ra_OFF ] ||
4205         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
4206                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
4207 }
4208 run_test 101d "file read with and without read-ahead enabled  ================="
4209
4210 export SETUP_TEST102=no
4211 setup_test102() {
4212         [ "$SETUP_TEST102" = "yes" ] && return
4213         mkdir -p $DIR/$tdir
4214         chown $RUNAS_ID $DIR/$tdir
4215         STRIPE_SIZE=65536
4216         STRIPE_OFFSET=1
4217         STRIPE_COUNT=$OSTCOUNT
4218         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
4219
4220         trap cleanup_test102 EXIT
4221         cd $DIR
4222         $1 $SETSTRIPE $tdir -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT
4223         cd $DIR/$tdir
4224         for num in 1 2 3 4
4225         do
4226                 for count in `seq 1 $STRIPE_COUNT`
4227                 do
4228                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4229                         do
4230                                 local stripe_size=`expr $STRIPE_SIZE \* $num`
4231                                 local file=file"$num-$offset-$count"
4232                                 $1 $SETSTRIPE $file -s $stripe_size -i $offset -c $count
4233                         done
4234                 done
4235         done
4236
4237         cd $DIR
4238         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
4239         SETUP_TEST102=yes
4240 }
4241
4242 cleanup_test102() {
4243         trap 0
4244         [ "$SETUP_TEST102" = "yes" ] || return 0
4245         rm -f $TMP/f102.tar
4246         SETUP_TEST102=no
4247 }
4248
4249 test_102a() {
4250         local testfile=$DIR/xattr_testfile
4251
4252         rm -f $testfile
4253         touch $testfile
4254
4255         [ "$UID" != 0 ] && skip_env "must run as root" && return
4256         [ -z "`lctl get_param -n mdc.*.connect_flags | grep xattr`" ] &&
4257                 skip_env "must have user_xattr" && return
4258         [ -z "$(which setfattr 2>/dev/null)" ] && skip_env "could not find setfattr" && return
4259
4260         echo "set/get xattr..."
4261         setfattr -n trusted.name1 -v value1 $testfile || error
4262         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
4263         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
4264
4265         setfattr -n user.author1 -v author1 $testfile || error
4266         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
4267         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
4268
4269         echo "listxattr..."
4270         setfattr -n trusted.name2 -v value2 $testfile || error
4271         setfattr -n trusted.name3 -v value3 $testfile || error
4272         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4273         grep "trusted.name" | wc -l` -eq 3 ] || error
4274
4275
4276         setfattr -n user.author2 -v author2 $testfile || error
4277         setfattr -n user.author3 -v author3 $testfile || error
4278         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
4279         grep "user" | wc -l` -eq 3 ] || error
4280
4281         echo "remove xattr..."
4282         setfattr -x trusted.name1 $testfile || error
4283         getfattr -d -m trusted $testfile 2> /dev/null | \
4284         grep "trusted.name1" && error || true
4285
4286         setfattr -x user.author1 $testfile || error
4287         getfattr -d -m user $testfile 2> /dev/null | \
4288         grep "user.author1" && error || true
4289
4290         # b10667: setting lustre special xattr be silently discarded
4291         echo "set lustre special xattr ..."
4292         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
4293
4294         rm -f $testfile
4295 }
4296 run_test 102a "user xattr test =================================="
4297
4298 test_102b() {
4299         # b10930: get/set/list trusted.lov xattr
4300         echo "get/set/list trusted.lov xattr ..."
4301         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
4302         local testfile=$DIR/$tfile
4303         $SETSTRIPE -s 65536 -i 1 -c 2 $testfile || error "setstripe failed"
4304         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4305         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
4306
4307         local testfile2=${testfile}2
4308         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
4309                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
4310
4311         $MCREATE $testfile2
4312         setfattr -n trusted.lov -v $value $testfile2
4313         local tmp_file=${testfile}3
4314         $GETSTRIPE -v $testfile2 > $tmp_file
4315         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4316         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4317         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
4318         [ $stripe_count -eq 2 ] || error "stripe count $stripe_count != 2"
4319 }
4320 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
4321
4322 test_102c() {
4323         # b10930: get/set/list lustre.lov xattr
4324         echo "get/set/list lustre.lov xattr ..."
4325         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
4326         mkdir -p $DIR/$tdir
4327         chown $RUNAS_ID $DIR/$tdir
4328         local testfile=$DIR/$tdir/$tfile
4329         $RUNAS $SETSTRIPE -s 65536 -i 1 -c 2 $testfile||error "setstripe failed"
4330         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
4331         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
4332
4333         local testfile2=${testfile}2
4334         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
4335                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
4336
4337         $RUNAS $MCREATE $testfile2
4338         $RUNAS setfattr -n lustre.lov -v $value $testfile2
4339         local tmp_file=${testfile}3
4340         $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
4341         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4342         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4343         [ "$stripe_size" -eq 65536 ] || error "stripe size $stripe_size != 65536"
4344         [ "$stripe_count" -eq 2 ] || error "stripe count $stripe_count != 2"
4345 }
4346 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
4347
4348 compare_stripe_info1() {
4349         local stripe_index_all_zero=1
4350
4351         for num in 1 2 3 4
4352         do
4353                 for count in `seq 1 $STRIPE_COUNT`
4354                 do
4355                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4356                         do
4357                                 local size=`expr $STRIPE_SIZE \* $num`
4358                                 local file=file"$num-$offset-$count"
4359                                 get_stripe_info client $PWD/$file "$1"
4360                                 if [ $stripe_size -ne $size ]; then
4361                                         error "$file: different stripe size $stripe_size, expected $size" && return
4362                                 fi
4363                                 if [ $stripe_count -ne $count ]; then
4364                                         error "$file: different stripe count $stripe_count, expected $count" && return
4365                                 fi
4366                                 if [ $stripe_index -ne 0 ]; then
4367                                        stripe_index_all_zero=0
4368                                 fi
4369                         done
4370                 done
4371         done
4372         [ $stripe_index_all_zero -eq 1 ] && error "all files are being extracted starting from OST index 0"
4373         return 0
4374 }
4375
4376 find_lustre_tar() {
4377         [ -n "$(which tar 2>/dev/null)" ] && strings $(which tar) | grep -q lustre && echo tar
4378 }
4379
4380 test_102d() {
4381         # b10930: tar test for trusted.lov xattr
4382         TAR=$(find_lustre_tar)
4383         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4384         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4385         setup_test102
4386         mkdir -p $DIR/d102d
4387         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
4388         cd $DIR/d102d/$tdir
4389         compare_stripe_info1
4390 }
4391 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
4392
4393 test_102f() {
4394         # b10930: tar test for trusted.lov xattr
4395         TAR=$(find_lustre_tar)
4396         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4397         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4398         setup_test102
4399         mkdir -p $DIR/d102f
4400         cd $DIR
4401         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
4402         cd $DIR/d102f/$tdir
4403         compare_stripe_info1
4404 }
4405 run_test 102f "tar copy files, not keep osts ==========="
4406
4407 test_102h() { # bug 15777
4408         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
4409                 skip "must have user_xattr" && return
4410         [ -z "$(which setfattr 2>/dev/null)" ] &&
4411                 skip_env "could not find setfattr" && return
4412
4413         XBIG=trusted.big
4414         XSIZE=1024
4415         touch $DIR/$tfile
4416         VALUE=datadatadatadatadatadatadatadata
4417         while [ $(echo $VALUE | wc -c) -lt $XSIZE ]; do
4418                 VALUE="$VALUE$VALUE"
4419         done
4420         log "save $XBIG on $DIR/$tfile"
4421         setfattr -n $XBIG -v "$VALUE" $DIR/$tfile ||
4422                 error "saving $XBIG on $DIR/$tfile failed"
4423         ORIG=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4424         OSIZE=$(echo $ORIG | wc -c)
4425         [ $OSIZE -lt $XSIZE ] && error "set $XBIG too small ($OSIZE < $XSIZE)"
4426
4427         XSML=trusted.sml
4428         log "save $XSML on $DIR/$tfile"
4429         setfattr -n $XSML -v val $DIR/$tfile ||
4430                 error "saving $XSML on $DIR/$tfile failed"
4431         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4432         if [ "$NEW" != "$ORIG" ]; then
4433                 log "orig: $ORIG"
4434                 log "new: $NEW"
4435                 error "$XBIG different after saving $XSML"
4436         fi
4437
4438         log "grow $XSML on $DIR/$tfile"
4439         setfattr -n $XSML -v "$VALUE" $DIR/$tfile ||
4440                 error "growing $XSML on $DIR/$tfile failed"
4441         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4442         if [ "$NEW" != "$ORIG" ]; then
4443                 log "orig: $ORIG"
4444                 log "new: $NEW"
4445                 error "$XBIG different after growing $XSML"
4446         fi
4447         log "$XBIG still valid after growing $XSML"
4448 }
4449 run_test 102h "grow xattr from inside inode to external block"
4450
4451 test_102i() { # bug 17038
4452         touch $DIR/$tfile
4453         ln -s $DIR/$tfile $DIR/${tfile}link
4454         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
4455         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"
4456         rm -f $DIR/$tfile $DIR/${tfile}link
4457 }
4458 run_test 102i "lgetxattr test on symbolic link ============"
4459
4460 test_102j() {
4461         TAR=$(find_lustre_tar)
4462         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
4463         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
4464         setup_test102 "$RUNAS"
4465         mkdir -p $DIR/d102j
4466         chown $RUNAS_ID $DIR/d102j
4467         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
4468         cd $DIR/d102j/$tdir
4469         compare_stripe_info1 "$RUNAS"
4470 }
4471 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
4472
4473 test_102k() {
4474         touch $DIR/$tfile
4475         # b22187 just check that does not crash for regular file.
4476         setfattr -n trusted.lov $DIR/$tfile
4477         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
4478         local test_kdir=$DIR/d102k
4479         mkdir $test_kdir
4480         local default_size=`$GETSTRIPE -s $test_kdir`
4481         local default_count=`$GETSTRIPE -c $test_kdir`
4482         local default_offset=`$GETSTRIPE -o $test_kdir`
4483         $SETSTRIPE -s 65536 -i 1 -c $OSTCOUNT $test_kdir || error 'dir setstripe failed'
4484         setfattr -n trusted.lov $test_kdir
4485         local stripe_size=`$GETSTRIPE -s $test_kdir`
4486         local stripe_count=`$GETSTRIPE -c $test_kdir`
4487         local stripe_offset=`$GETSTRIPE -o $test_kdir`
4488         [ $stripe_size -eq $default_size ] || error "stripe size $stripe_size != $default_size"
4489         [ $stripe_count -eq $default_count ] || error "stripe count $stripe_count != $default_count"
4490         [ $stripe_offset -eq $default_offset ] || error "stripe offset $stripe_offset != $default_offset"
4491         rm -rf $DIR/$tfile $test_kdir
4492 }
4493 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
4494
4495 cleanup_test102
4496
4497 run_acl_subtest()
4498 {
4499     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
4500     return $?
4501 }
4502
4503 test_103 () {
4504     [ "$UID" != 0 ] && skip_env "must run as root" && return
4505     [ -z "$(lctl get_param mdc.*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
4506     [ -z "$(which setfacl 2>/dev/null)" ] && skip_env "could not find setfacl" && return
4507
4508     SAVE_UMASK=`umask`
4509     umask 0022
4510     cd $DIR
4511
4512     echo "performing cp ..."
4513     run_acl_subtest cp || error
4514     echo "performing getfacl-noacl..."
4515     run_acl_subtest getfacl-noacl > /dev/null || error "getfacl-noacl test failed"
4516     echo "performing misc..."
4517     run_acl_subtest misc > /dev/null || error "misc test failed"
4518 #    XXX add back permission test when we support supplementary groups.
4519 #    echo "performing permissions..."
4520 #    run_acl_subtest permissions || error
4521     echo "performing setfacl..."
4522     run_acl_subtest setfacl > /dev/null || error "setfacl test failed"
4523
4524     # inheritance test got from HP
4525     echo "performing inheritance..."
4526     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
4527     chmod +x make-tree || error "chmod +x failed"
4528     run_acl_subtest inheritance > /dev/null || error "inheritance test failed"
4529     rm -f make-tree
4530
4531     cd $SAVE_PWD
4532     umask $SAVE_UMASK
4533 }
4534 run_test 103 "acl test ========================================="
4535
4536 test_104a() {
4537         touch $DIR/$tfile
4538         lfs df || error "lfs df failed"
4539         lfs df -ih || error "lfs df -ih failed"
4540         lfs df -h $DIR || error "lfs df -h $DIR failed"
4541         lfs df -i $DIR || error "lfs df -i $DIR failed"
4542         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
4543         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
4544
4545         OSC=`lctl get_param -n devices | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
4546         lctl --device %$OSC deactivate
4547         lfs df || error "lfs df with deactivated OSC failed"
4548         lctl --device %$OSC recover
4549         lfs df || error "lfs df with reactivated OSC failed"
4550 }
4551 run_test 104a "lfs df [-ih] [path] test ========================="
4552
4553 test_104b() {
4554         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4555         chmod 666 /dev/obd
4556         denied_cnt=$((`$RUNAS $LFS check servers 2>&1 | grep "Permission denied" | wc -l`))
4557         if [ $denied_cnt -ne 0 ];
4558         then
4559                     error "lfs check servers test failed"
4560         fi
4561 }
4562 run_test 104b "$RUNAS lfs check servers test ===================="
4563
4564 test_105a() {
4565         # doesn't work on 2.4 kernels
4566         touch $DIR/$tfile
4567         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4568         then
4569                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
4570         else
4571                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
4572         fi
4573 }
4574 run_test 105a "flock when mounted without -o flock test ========"
4575
4576 test_105b() {
4577         touch $DIR/$tfile
4578         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4579         then
4580                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
4581         else
4582                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
4583         fi
4584 }
4585 run_test 105b "fcntl when mounted without -o flock test ========"
4586
4587 test_105c() {
4588         touch $DIR/$tfile
4589         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4590         then
4591                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
4592         else
4593                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
4594         fi
4595 }
4596 run_test 105c "lockf when mounted without -o flock test ========"
4597
4598 test_105d() { # bug 15924
4599         mkdir -p $DIR/$tdir
4600         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
4601                 skip "mount w/o flock enabled" && return
4602         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
4603         $LCTL set_param fail_loc=0x80000315
4604         flocks_test 2 $DIR/$tdir
4605 }
4606 run_test 105d "flock race (should not freeze) ========"
4607
4608 test_105e() { # bug 22660
4609         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
4610                 skip "mount w/o flock enabled" && return
4611         touch $DIR/$tfile
4612         flocks_test 3 $DIR/$tfile
4613 }
4614 run_test 105e "Two conflicting flocks from same process ======="
4615
4616 test_106() { #bug 10921
4617         mkdir -p $DIR/$tdir
4618         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
4619         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
4620 }
4621 run_test 106 "attempt exec of dir followed by chown of that dir"
4622
4623 test_107() {
4624         CDIR=`pwd`
4625         cd $DIR
4626
4627         local file=core
4628         rm -f $file
4629
4630         local save_pattern=$(sysctl -n kernel.core_pattern)
4631         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
4632         sysctl -w kernel.core_pattern=$file
4633         sysctl -w kernel.core_uses_pid=0
4634
4635         ulimit -c unlimited
4636         sleep 60 &
4637         SLEEPPID=$!
4638
4639         sleep 1
4640
4641         kill -s 11 $SLEEPPID
4642         wait $SLEEPPID
4643         if [ -e $file ]; then
4644                 size=`stat -c%s $file`
4645                 [ $size -eq 0 ] && error "Zero length core file $file"
4646         else
4647                 error "Fail to create core file $file"
4648         fi
4649         rm -f $file
4650         sysctl -w kernel.core_pattern=$save_pattern
4651         sysctl -w kernel.core_uses_pid=$save_uses_pid
4652         cd $CDIR
4653 }
4654 run_test 107 "Coredump on SIG"
4655
4656 test_115() {
4657         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4658             cut -c11-20)
4659         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
4660             return
4661         echo "Starting with $OSTIO_pre threads"
4662
4663         NUMTEST=20000
4664         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
4665         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
4666         echo "$NUMTEST creates/unlinks"
4667         mkdir -p $DIR/$tdir
4668         createmany -o $DIR/$tdir/$tfile $NUMTEST
4669         unlinkmany $DIR/$tdir/$tfile $NUMTEST
4670
4671         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4672             cut -c11-20)
4673
4674         # don't return an error
4675         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
4676             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&\
4677             echo "This may be fine, depending on what ran before this test" &&\
4678             echo "and how fast this system is." && return
4679
4680         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
4681 }
4682 run_test 115 "verify dynamic thread creation===================="
4683
4684 free_min_max () {
4685         wait_delete_completed
4686         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail))
4687         echo OST kbytes available: ${AVAIL[@]}
4688         MAXI=0; MAXV=${AVAIL[0]}
4689         MINI=0; MINV=${AVAIL[0]}
4690         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
4691             #echo OST $i: ${AVAIL[i]}kb
4692             if [ ${AVAIL[i]} -gt $MAXV ]; then
4693                 MAXV=${AVAIL[i]}; MAXI=$i
4694             fi
4695             if [ ${AVAIL[i]} -lt $MINV ]; then
4696                 MINV=${AVAIL[i]}; MINI=$i
4697             fi
4698         done
4699         echo Min free space: OST $MINI: $MINV
4700         echo Max free space: OST $MAXI: $MAXV
4701 }
4702
4703 test_116() {
4704         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
4705
4706         echo -n "Free space priority "
4707         lctl get_param -n lov.*.qos_prio_free
4708         declare -a AVAIL
4709         free_min_max
4710         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI" &&\
4711                 return
4712
4713         # generate uneven OSTs
4714         mkdir -p $DIR/$tdir/OST${MINI}
4715         declare -i FILL
4716         FILL=$(($MINV / 4))
4717         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
4718         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
4719         i=1
4720         while [ $FILL -gt 0 ]; do
4721             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
4722             FILL=$(($FILL - 2048))
4723             echo -n .
4724             i=$(($i + 1))
4725         done
4726         FILL=$(($MINV / 4))
4727         sync
4728         sleep_maxage
4729
4730         free_min_max
4731         DIFF=$(($MAXV - $MINV))
4732         DIFF2=$(($DIFF * 100 / $MINV))
4733         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
4734         if [ $DIFF2 -gt 20 ]; then
4735             echo "ok"
4736         else
4737             echo "failed - QOS mode won't be used"
4738             error_ignore "QOS imbalance criteria not met"
4739             return
4740         fi
4741
4742         MINI1=$MINI; MINV1=$MINV
4743         MAXI1=$MAXI; MAXV1=$MAXV
4744
4745         # now fill using QOS
4746         echo writing a bunch of files to QOS-assigned OSTs
4747         $SETSTRIPE $DIR/$tdir -c 1
4748         i=1
4749         while [ $FILL -gt 0 ]; do
4750             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
4751             FILL=$(($FILL - 200))
4752             echo -n .
4753             i=$(($i + 1))
4754         done
4755         echo "wrote $i 200k files"
4756         sync
4757         sleep_maxage
4758
4759         echo "Note: free space may not be updated, so measurements might be off"
4760         free_min_max
4761         DIFF2=$(($MAXV - $MINV))
4762         echo "free space delta: orig $DIFF final $DIFF2"
4763         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
4764         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
4765         echo "Wrote $DIFF to smaller OST $MINI1"
4766         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
4767         echo "Wrote $DIFF2 to larger OST $MAXI1"
4768         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
4769
4770         # Figure out which files were written where
4771         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd | awk '/'$MINI1': / {print $2; exit}')
4772         echo $UUID
4773         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4774         echo "$MINC files created on smaller OST $MINI1"
4775         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd | (awk '/'$MAXI1': / {print $2; exit}'))
4776         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4777         echo "$MAXC files created on larger OST $MAXI1"
4778         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
4779         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
4780
4781         rm -rf $DIR/$tdir
4782 }
4783 run_test 116 "stripe QOS: free space balance ==================="
4784
4785 test_117() # bug 10891
4786 {
4787         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
4788         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
4789         lctl set_param fail_loc=0x21e
4790         > $DIR/$tfile || error "truncate failed"
4791         lctl set_param fail_loc=0
4792         echo "Truncate succeeded."
4793 }
4794 run_test 117 "verify fsfilt_extend ============================="
4795
4796 export OLD_RESENDCOUNT=""
4797 set_resend_count () {
4798         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
4799         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
4800         lctl set_param -n $PROC_RESENDCOUNT $1
4801         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
4802 }
4803
4804 [ "$SLOW" = "no" ] && set_resend_count 4 # for reduce test_118* time (bug 14842)
4805
4806 # Reset async IO behavior after error case
4807 reset_async() {
4808         FILE=$DIR/reset_async
4809
4810         # Ensure all OSCs are cleared
4811         $SETSTRIPE -c -1 $FILE
4812         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
4813         sync
4814         rm $FILE
4815 }
4816
4817 test_118a() #bug 11710
4818 {
4819         reset_async
4820
4821         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4822         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
4823         WRITEBACK=$(lctl get_param "llite.*.dump_page_cache" | grep -c writeback)
4824
4825         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4826                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4827                 return 1;
4828         fi
4829 }
4830 run_test 118a "verify O_SYNC works =========="
4831
4832 test_118b()
4833 {
4834         remote_ost_nodsh && skip "remote OST with nodsh" && return
4835
4836         reset_async
4837
4838         #define OBD_FAIL_OST_ENOENT 0x217
4839         set_nodes_failloc "$(osts_nodes)" 0x217
4840         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4841         RC=$?
4842         set_nodes_failloc "$(osts_nodes)" 0
4843         DIRTY=$(lctl get_param llite.*.dump_page_cache | grep -c dirty)
4844         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4845
4846         if [[ $RC -eq 0 ]]; then
4847                 error "Must return error due to dropped pages, rc=$RC"
4848                 return 1;
4849         fi
4850
4851         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4852                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4853                 return 1;
4854         fi
4855
4856         echo "Dirty pages not leaked on ENOENT"
4857
4858         # Due to the above error the OSC will issue all RPCs syncronously
4859         # until a subsequent RPC completes successfully without error.
4860         multiop $DIR/$tfile Ow4096yc
4861         rm -f $DIR/$tfile
4862
4863         return 0
4864 }
4865 run_test 118b "Reclaim dirty pages on fatal error =========="
4866
4867 test_118c()
4868 {
4869         remote_ost_nodsh && skip "remote OST with nodsh" && return
4870
4871         reset_async
4872
4873         #define OBD_FAIL_OST_EROFS               0x216
4874         set_nodes_failloc "$(osts_nodes)" 0x216
4875
4876         # multiop should block due to fsync until pages are written
4877         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4878         MULTIPID=$!
4879         sleep 1
4880
4881         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4882                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4883         fi
4884
4885         WRITEBACK=$(lctl get_param -n llite/*/dump_page_cache | grep -c writeback)
4886         if [[ $WRITEBACK -eq 0 ]]; then
4887                 error "No page in writeback, writeback=$WRITEBACK"
4888         fi
4889
4890         set_nodes_failloc "$(osts_nodes)" 0
4891         wait $MULTIPID
4892         RC=$?
4893         if [[ $RC -ne 0 ]]; then
4894                 error "Multiop fsync failed, rc=$RC"
4895         fi
4896
4897         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4898         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4899         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4900                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4901         fi
4902
4903         rm -f $DIR/$tfile
4904         echo "Dirty pages flushed via fsync on EROFS"
4905         return 0
4906 }
4907 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
4908
4909 test_118d()
4910 {
4911         remote_ost_nodsh && skip "remote OST with nodsh" && return
4912
4913         reset_async
4914
4915         #define OBD_FAIL_OST_BRW_PAUSE_BULK
4916         set_nodes_failloc "$(osts_nodes)" 0x214
4917         # multiop should block due to fsync until pages are written
4918         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4919         MULTIPID=$!
4920         sleep 1
4921
4922         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4923                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4924         fi
4925
4926         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4927         if [[ $WRITEBACK -eq 0 ]]; then
4928                 error "No page in writeback, writeback=$WRITEBACK"
4929         fi
4930
4931         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
4932         set_nodes_failloc "$(osts_nodes)" 0
4933
4934         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4935         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4936         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4937                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4938         fi
4939
4940         rm -f $DIR/$tfile
4941         echo "Dirty pages gaurenteed flushed via fsync"
4942         return 0
4943 }
4944 run_test 118d "Fsync validation inject a delay of the bulk =========="
4945
4946 test_118f() {
4947         reset_async
4948
4949         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
4950         lctl set_param fail_loc=0x8000040a
4951
4952         # Should simulate EINVAL error which is fatal
4953         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4954         RC=$?
4955         if [[ $RC -eq 0 ]]; then
4956                 error "Must return error due to dropped pages, rc=$RC"
4957         fi
4958
4959         lctl set_param fail_loc=0x0
4960
4961         LOCKED=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c locked)
4962         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
4963         WRITEBACK=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c writeback)
4964         if [[ $LOCKED -ne 0 ]]; then
4965                 error "Locked pages remain in cache, locked=$LOCKED"
4966         fi
4967
4968         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4969                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4970         fi
4971
4972         rm -f $DIR/$tfile
4973         echo "No pages locked after fsync"
4974
4975         reset_async
4976         return 0
4977 }
4978 run_test 118f "Simulate unrecoverable OSC side error =========="
4979
4980 test_118g() {
4981         reset_async
4982
4983         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4984         lctl set_param fail_loc=0x406
4985
4986         # simulate local -ENOMEM
4987         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4988         RC=$?
4989
4990         lctl set_param fail_loc=0
4991         if [[ $RC -eq 0 ]]; then
4992                 error "Must return error due to dropped pages, rc=$RC"
4993         fi
4994
4995         LOCKED=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c locked)
4996         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
4997         WRITEBACK=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c writeback)
4998         if [[ $LOCKED -ne 0 ]]; then
4999                 error "Locked pages remain in cache, locked=$LOCKED"
5000         fi
5001
5002         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5003                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5004         fi
5005
5006         rm -f $DIR/$tfile
5007         echo "No pages locked after fsync"
5008
5009         reset_async
5010         return 0
5011 }
5012 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
5013
5014 test_118h() {
5015         remote_ost_nodsh && skip "remote OST with nodsh" && return
5016
5017         reset_async
5018
5019         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
5020         set_nodes_failloc "$(osts_nodes)" 0x20e
5021         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
5022         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5023         RC=$?
5024
5025         set_nodes_failloc "$(osts_nodes)" 0
5026         if [[ $RC -eq 0 ]]; then
5027                 error "Must return error due to dropped pages, rc=$RC"
5028         fi
5029
5030         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
5031         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
5032         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writebac)
5033         if [[ $LOCKED -ne 0 ]]; then
5034                 error "Locked pages remain in cache, locked=$LOCKED"
5035         fi
5036
5037         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5038                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5039         fi
5040
5041         rm -f $DIR/$tfile
5042         echo "No pages locked after fsync"
5043
5044         return 0
5045 }
5046 run_test 118h "Verify timeout in handling recoverables errors  =========="
5047
5048 test_118i() {
5049         remote_ost_nodsh && skip "remote OST with nodsh" && return
5050
5051         reset_async
5052
5053         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
5054         set_nodes_failloc "$(osts_nodes)" 0x20e
5055
5056         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
5057         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
5058         PID=$!
5059         sleep 5
5060         set_nodes_failloc "$(osts_nodes)" 0
5061
5062         wait $PID
5063         RC=$?
5064         if [[ $RC -ne 0 ]]; then
5065                 error "got error, but should be not, rc=$RC"
5066         fi
5067
5068         LOCKED=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c locked)
5069         DIRTY=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c dirty)
5070         WRITEBACK=$(lctl get_param -n "llite.*.dump_page_cache" | grep -c writeback)
5071         if [[ $LOCKED -ne 0 ]]; then
5072                 error "Locked pages remain in cache, locked=$LOCKED"
5073         fi
5074
5075         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5076                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5077         fi
5078
5079         rm -f $DIR/$tfile
5080         echo "No pages locked after fsync"
5081
5082         return 0
5083 }
5084 run_test 118i "Fix error before timeout in recoverable error  =========="
5085
5086 test_118j() {
5087         remote_ost_nodsh && skip "remote OST with nodsh" && return
5088
5089         reset_async
5090
5091         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
5092         set_nodes_failloc "$(osts_nodes)" 0x220
5093
5094         # return -EIO from OST
5095         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5096         RC=$?
5097         set_nodes_failloc "$(osts_nodes)" 0x0
5098         if [[ $RC -eq 0 ]]; then
5099                 error "Must return error due to dropped pages, rc=$RC"
5100         fi
5101
5102         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
5103         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
5104         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
5105         if [[ $LOCKED -ne 0 ]]; then
5106                 error "Locked pages remain in cache, locked=$LOCKED"
5107         fi
5108
5109         # in recoverable error on OST we want resend and stay until it finished
5110         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5111                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5112         fi
5113
5114         rm -f $DIR/$tfile
5115         echo "No pages locked after fsync"
5116
5117         return 0
5118 }
5119 run_test 118j "Simulate unrecoverable OST side error =========="
5120
5121 test_118k()
5122 {
5123         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
5124
5125         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
5126         set_nodes_failloc "$(osts_nodes)" 0x20e
5127         mkdir -p $DIR/$tdir
5128
5129         for ((i=0;i<10;i++)); do
5130                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
5131                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
5132                 SLEEPPID=$!
5133                 sleep 0.500s
5134                 kill $SLEEPPID
5135                 wait $SLEEPPID
5136         done
5137
5138         set_nodes_failloc "$(osts_nodes)" 0
5139         rm -rf $DIR/$tdir
5140 }
5141 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
5142
5143 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
5144
5145 test_119a() # bug 11737
5146 {
5147         BSIZE=$((512 * 1024))
5148         directio write $DIR/$tfile 0 1 $BSIZE
5149         # We ask to read two blocks, which is more than a file size.
5150         # directio will indicate an error when requested and actual
5151         # sizes aren't equeal (a normal situation in this case) and
5152         # print actual read amount.
5153         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
5154         if [ "$NOB" != "$BSIZE" ]; then
5155                 error "read $NOB bytes instead of $BSIZE"
5156         fi
5157         rm -f $DIR/$tfile
5158 }
5159 run_test 119a "Short directIO read must return actual read amount"
5160
5161 test_119b() # bug 11737
5162 {
5163         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5164
5165         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
5166         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
5167         sync
5168         multiop $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
5169                 error "direct read failed"
5170         rm -f $DIR/$tfile
5171 }
5172 run_test 119b "Sparse directIO read must return actual read amount"
5173
5174 test_119c() # bug 13099
5175 {
5176         BSIZE=1048576
5177         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
5178         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
5179         rm -f $DIR/$tfile
5180 }
5181 run_test 119c "Testing for direct read hitting hole"
5182
5183 test_119d() # bug 15950
5184 {
5185         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
5186         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
5187         BSIZE=1048576
5188         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
5189         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
5190         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
5191         lctl set_param fail_loc=0x40d
5192         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
5193         pid_dio=$!
5194         sleep 1
5195         cat $DIR/$tfile > /dev/null &
5196         lctl set_param fail_loc=0
5197         pid_reads=$!
5198         wait $pid_dio
5199         log "the DIO writes have completed, now wait for the reads (should not block very long)"
5200         sleep 2
5201         [ -n "`ps h -p $pid_reads -o comm`" ] && \
5202                 error "the read rpcs have not completed in 2s"
5203         rm -f $DIR/$tfile
5204         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
5205 }
5206 run_test 119d "The DIO path should try to send a new rpc once one is completed"
5207
5208 test_120a() {
5209         mkdir -p $DIR/$tdir
5210         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5211                skip "no early lock cancel on server" && return 0
5212         lru_resize_disable mdc
5213         lru_resize_disable osc
5214         cancel_lru_locks mdc
5215         stat $DIR/$tdir > /dev/null
5216         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5217         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5218         mkdir $DIR/$tdir/d1
5219         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5220         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5221         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5222         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5223         lru_resize_enable mdc
5224         lru_resize_enable osc
5225 }
5226 run_test 120a "Early Lock Cancel: mkdir test ==================="
5227
5228 test_120b() {
5229         mkdir -p $DIR/$tdir
5230         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5231                skip "no early lock cancel on server" && return 0
5232         lru_resize_disable mdc
5233         lru_resize_disable osc
5234         cancel_lru_locks mdc
5235         stat $DIR/$tdir > /dev/null
5236         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5237         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5238         touch $DIR/$tdir/f1
5239         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5240         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5241         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5242         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5243         lru_resize_enable mdc
5244         lru_resize_enable osc
5245 }
5246 run_test 120b "Early Lock Cancel: create test =================="
5247
5248 test_120c() {
5249         mkdir -p $DIR/$tdir
5250         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5251                skip "no early lock cancel on server" && return 0
5252         lru_resize_disable mdc
5253         lru_resize_disable osc
5254         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
5255         touch $DIR/$tdir/d1/f1
5256         cancel_lru_locks mdc
5257         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
5258         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5259         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5260         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
5261         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5262         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5263         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5264         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5265         lru_resize_enable mdc
5266         lru_resize_enable osc
5267 }
5268 run_test 120c "Early Lock Cancel: link test ===================="
5269
5270 test_120d() {
5271         mkdir -p $DIR/$tdir
5272         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5273                skip "no early lock cancel on server" && return 0
5274         lru_resize_disable mdc
5275         lru_resize_disable osc
5276         touch $DIR/$tdir
5277         cancel_lru_locks mdc
5278         stat $DIR/$tdir > /dev/null
5279         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5280         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5281         chmod a+x $DIR/$tdir
5282         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5283         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5284         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5285         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5286         lru_resize_enable mdc
5287         lru_resize_enable osc
5288 }
5289 run_test 120d "Early Lock Cancel: setattr test ================="
5290
5291 test_120e() {
5292         mkdir -p $DIR/$tdir
5293         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5294                skip "no early lock cancel on server" && return 0
5295         lru_resize_disable mdc
5296         lru_resize_disable osc
5297         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
5298         cancel_lru_locks mdc
5299         cancel_lru_locks osc
5300         dd if=$DIR/$tdir/f1 of=/dev/null
5301         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
5302         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5303         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5304         unlink $DIR/$tdir/f1
5305         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5306         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5307         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5308         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5309         lru_resize_enable mdc
5310         lru_resize_enable osc
5311 }
5312 run_test 120e "Early Lock Cancel: unlink test =================="
5313
5314 test_120f() {
5315         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5316                skip "no early lock cancel on server" && return 0
5317         mkdir -p $DIR/$tdir
5318         lru_resize_disable mdc
5319         lru_resize_disable osc
5320         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
5321         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
5322         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
5323         cancel_lru_locks mdc
5324         cancel_lru_locks osc
5325         dd if=$DIR/$tdir/d1/f1 of=/dev/null
5326         dd if=$DIR/$tdir/d2/f2 of=/dev/null
5327         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
5328         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5329         blk1=`lctl get_param -n ldlm/services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5330         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
5331         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5332         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5333         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5334         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5335         lru_resize_enable mdc
5336         lru_resize_enable osc
5337 }
5338 run_test 120f "Early Lock Cancel: rename test =================="
5339
5340 test_120g() {
5341         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5342                skip "no early lock cancel on server" && return 0
5343         lru_resize_disable mdc
5344         lru_resize_disable osc
5345         count=10000
5346         echo create $count files
5347         mkdir -p $DIR/$tdir
5348         cancel_lru_locks mdc
5349         cancel_lru_locks osc
5350         t0=`date +%s`
5351
5352         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5353         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5354         createmany -o $DIR/$tdir/f $count
5355         sync
5356         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5357         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5358         t1=`date +%s`
5359         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
5360         echo rm $count files
5361         rm -r $DIR/$tdir
5362         sync
5363         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5364         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5365         t2=`date +%s`
5366         echo total: $count removes in $((t2-t1))
5367         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
5368         sleep 2
5369         # wait for commitment of removal
5370         lru_resize_enable mdc
5371         lru_resize_enable osc
5372 }
5373 run_test 120g "Early Lock Cancel: performance test ============="
5374
5375 test_121() { #bug 10589
5376         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
5377         lctl set_param fail_loc=0x310
5378         cancel_lru_locks osc > /dev/null
5379         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
5380         lctl set_param fail_loc=0
5381         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
5382 }
5383 run_test 121 "read cancel race ================================="
5384
5385 test_122() { #bug 11544
5386         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
5387         lctl set_param fail_loc=0x508
5388         dd if=/dev/zero of=$DIR/$tfile count=1
5389         sync
5390         lctl set_param fail_loc=0
5391 }
5392 run_test 122 "fail client bulk callback (shouldn't LBUG) ======="
5393
5394 test_123a() { # was test 123, statahead(bug 11401)
5395         # interop 18 <-> 2x
5396         local lustre_version=$(get_lustre_version mds)
5397         if [[ $lustre_version != 1.8* ]]; then
5398                 skip mds running $lustre_version, statahead is disabled
5399                 return 0
5400         fi
5401
5402         statahead_max_old=`lctl get_param -n llite.*.statahead_max | head -n 1`
5403
5404         SLOWOK=0
5405         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
5406                 log "testing on UP system. Performance may be not as good as expected."
5407                 SLOWOK=1
5408         fi
5409
5410         rm -rf $DIR/$tdir
5411         mkdir -p $DIR/$tdir
5412         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
5413         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
5414         MULT=10
5415         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
5416                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
5417
5418                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
5419                 [ $max -eq 0 ] && max=32
5420                 lctl set_param -n llite.*.statahead_max 0
5421                 lctl get_param llite.*.statahead_max
5422                 cancel_lru_locks mdc
5423                 cancel_lru_locks osc
5424                 stime=`date +%s`
5425                 time ls -l $DIR/$tdir | wc -l
5426                 etime=`date +%s`
5427                 delta=$((etime - stime))
5428                 log "ls $i files without statahead: $delta sec"
5429                 lctl set_param llite.*.statahead_max=$max
5430
5431                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
5432                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
5433                 cancel_lru_locks mdc
5434                 cancel_lru_locks osc
5435                 stime=`date +%s`
5436                 time ls -l $DIR/$tdir | wc -l
5437                 etime=`date +%s`
5438                 delta_sa=$((etime - stime))
5439                 log "ls $i files with statahead: $delta_sa sec"
5440                 lctl get_param -n llite.*.statahead_stats
5441                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
5442
5443                 if [ $swrong -lt $ewrong ]; then
5444                         log "statahead was stopped, maybe too many locks held!"
5445                 fi
5446
5447                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
5448
5449                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
5450                         if [  $SLOWOK -eq 0 ]; then
5451                                 error "ls $i files is slower with statahead!"
5452                                 debugsave
5453
5454                                 lctl set_param debug=-1
5455                                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
5456                                 [ $max -eq 0 ] && max=32
5457                                 lctl set_param -n llite.*.statahead_max 0
5458                                 lctl get_param llite.*.statahead_max
5459                                 cancel_lru_locks mdc
5460                                 cancel_lru_locks osc
5461                                 $LCTL clear
5462                                 stime=`date +%s`
5463                                 time ls -l $DIR/$tdir | wc -l
5464                                 etime=`date +%s`
5465                                 error "ls $i files (again) without statahead: $((etime - stime)) sec"
5466
5467                                 lctl set_param debug=-1
5468                                 lctl set_param llite.*.statahead_max=$max
5469                                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
5470                                 cancel_lru_locks mdc
5471                                 cancel_lru_locks osc
5472                                 $LCTL clear
5473                                 stime=`date +%s`
5474                                 time ls -l $DIR/$tdir | wc -l
5475                                 etime=`date +%s`
5476                                 error "ls $i files (again) with statahead: $((etime - stime)) sec"
5477                                 lctl get_param -n llite.*.statahead_stats
5478
5479                                 debugrestore
5480                         else
5481                                 log "ls $i files is slower with statahead!"
5482                         fi
5483                         break
5484                 fi
5485
5486                 [ $delta -gt 20 ] && break
5487                 [ $delta -gt 8 ] && MULT=$((50 / delta))
5488                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
5489         done
5490         log "ls done"
5491
5492         stime=`date +%s`
5493         rm -r $DIR/$tdir
5494         sync
5495         etime=`date +%s`
5496         delta=$((etime - stime))
5497         log "rm -r $DIR/$tdir/: $delta seconds"
5498         log "rm done"
5499         # restore default value
5500         $LCTL set_param llite.*.statahead_max=$statahead_max_old
5501         $LCTL get_param -n llite.*.statahead_stats
5502 }
5503 run_test 123a "verify statahead work"
5504
5505 test_123b () { # statahead(bug 15027)
5506         # interop 18 <-> 2x
5507         local lustre_version=$(get_lustre_version mds)
5508         if [[ $lustre_version != 1.8* ]]; then
5509                 skip mds running $lustre_version, statahead is disabled
5510                 return 0
5511         fi
5512
5513         mkdir -p $DIR/$tdir
5514         createmany -o $DIR/$tdir/$tfile-%d 1000
5515
5516         cancel_lru_locks mdc
5517         cancel_lru_locks osc
5518
5519 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
5520         lctl set_param fail_loc=0x80000803
5521         ls -lR $DIR/$tdir > /dev/null
5522         log "ls done"
5523         lctl set_param fail_loc=0x0
5524         lctl get_param -n llite.*.statahead_stats
5525         rm -r $DIR/$tdir
5526         sync
5527
5528 }
5529 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
5530
5531 test_124a() {
5532         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
5533                skip "no lru resize on server" && return 0
5534         local NR=2000
5535         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
5536
5537         log "create $NR files at $DIR/$tdir"
5538         createmany -o $DIR/$tdir/f $NR ||
5539                 error "failed to create $NR files in $DIR/$tdir"
5540
5541         cancel_lru_locks mdc
5542         ls -l $DIR/$tdir > /dev/null
5543
5544         local NSDIR=""
5545         local LRU_SIZE=0
5546         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
5547                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5548                 LRU_SIZE=$(lctl get_param -n $PARAM)
5549                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
5550                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
5551                         log "NS=$(basename $NSDIR)"
5552                         break
5553                 fi
5554         done
5555
5556         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
5557                 skip "Not enough cached locks created!"
5558                 return 0
5559         fi
5560         log "LRU=$LRU_SIZE"
5561
5562         local SLEEP=30
5563
5564         # We know that lru resize allows one client to hold $LIMIT locks
5565         # for 10h. After that locks begin to be killed by client.
5566         local MAX_HRS=10
5567         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
5568
5569         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
5570         # killing locks. Some time was spent for creating locks. This means
5571         # that up to the moment of sleep finish we must have killed some of
5572         # them (10-100 locks). This depends on how fast ther were created.
5573         # Many of them were touched in almost the same moment and thus will
5574         # be killed in groups.
5575         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
5576
5577         # Use $LRU_SIZE_B here to take into account real number of locks
5578         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
5579         local LRU_SIZE_B=$LRU_SIZE
5580         log "LVF=$LVF"
5581         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
5582         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
5583
5584         # Let's make sure that we really have some margin. Client checks
5585         # cached locks every 10 sec.
5586         SLEEP=$((SLEEP+20))
5587         log "Sleep ${SLEEP} sec"
5588         local SEC=0
5589         while ((SEC<$SLEEP)); do
5590                 echo -n "..."
5591                 sleep 5
5592                 SEC=$((SEC+5))
5593                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
5594                 echo -n "$LRU_SIZE"
5595         done
5596         echo ""
5597         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
5598         local LRU_SIZE_A=`lctl get_param -n $NSDIR/lru_size`
5599
5600         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
5601                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
5602                 unlinkmany $DIR/$tdir/f $NR
5603                 return
5604         }
5605
5606         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
5607         log "unlink $NR files at $DIR/$tdir"
5608         unlinkmany $DIR/$tdir/f $NR
5609 }
5610 run_test 124a "lru resize ======================================="
5611
5612 test_124b() {
5613         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
5614                skip "no lru resize on server" && return 0
5615
5616         # even for cmd no matter what metadata namespace to use for getting
5617         # the limit, we use appropriate.
5618         LIMIT=`lctl get_param -n ldlm.namespaces.*mdc*.pool.limit`
5619
5620         NR=$(($(default_lru_size)*20))
5621         if [ $NR -gt $LIMIT ]; then
5622                 NR=$LIMIT
5623         fi
5624         lru_resize_disable mdc
5625         mkdir -p $DIR/$tdir/disable_lru_resize ||
5626                 error "failed to create $DIR/$tdir/disable_lru_resize"
5627
5628         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
5629         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
5630         cancel_lru_locks mdc
5631         stime=`date +%s`
5632         PID=""
5633         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5634         PID="$PID $!"
5635         sleep 2
5636         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5637         PID="$PID $!"
5638         sleep 2
5639         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5640         PID="$PID $!"
5641         wait $PID
5642         etime=`date +%s`
5643         nolruresize_delta=$((etime-stime))
5644         log "ls -la time: $nolruresize_delta seconds"
5645         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
5646         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
5647
5648         lru_resize_enable mdc
5649         mkdir -p $DIR/$tdir/enable_lru_resize ||
5650                 error "failed to create $DIR/$tdir/enable_lru_resize"
5651
5652         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
5653         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
5654         cancel_lru_locks mdc
5655         stime=`date +%s`
5656         PID=""
5657         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5658         PID="$PID $!"
5659         sleep 2
5660         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5661         PID="$PID $!"
5662         sleep 2
5663         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5664         PID="$PID $!"
5665         wait $PID
5666         etime=`date +%s`
5667         lruresize_delta=$((etime-stime))
5668         log "ls -la time: $lruresize_delta seconds"
5669         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
5670
5671         if [ $lruresize_delta -gt $nolruresize_delta ]; then
5672                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
5673         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
5674                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
5675         else
5676                 log "lru resize performs the same with no lru resize"
5677         fi
5678         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
5679 }
5680 run_test 124b "lru resize (performance test) ======================="
5681
5682 test_125() { # 13358
5683         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
5684         mkdir -p $DIR/d125 || error "mkdir failed"
5685         $SETSTRIPE $DIR/d125 -s 65536 -c -1 || error "setstripe failed"
5686         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failes"
5687         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
5688 }
5689 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
5690
5691 test_126() { # bug 12829/13455
5692         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
5693         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
5694         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
5695         rm -f $DIR/$tfile
5696         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
5697 }
5698 run_test 126 "check that the fsgid provided by the client is taken into account"
5699
5700 test_127() { # bug 15521
5701         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
5702         $LCTL set_param osc.*.stats=0
5703         FSIZE=$((2048 * 1024))
5704         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
5705         cancel_lru_locks osc
5706         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
5707
5708         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
5709         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
5710                 echo "got $COUNT $NAME"
5711                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
5712                 eval $NAME=$COUNT || error "Wrong proc format"
5713
5714                 case $NAME in
5715                         read_bytes|write_bytes)
5716                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
5717                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
5718                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
5719                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
5720                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
5721                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
5722                                 error "sumsquare is too small: $SUMSQ"
5723                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
5724                                 error "sumsquare is too big: $SUMSQ"
5725                         ;;
5726                         *) ;;
5727                 esac
5728         done < $DIR/${tfile}.tmp
5729
5730         #check that we actually got some stats
5731         [ "$read_bytes" ] || error "Missing read_bytes stats"
5732         [ "$write_bytes" ] || error "Missing write_bytes stats"
5733         [ "$read_bytes" != 0 ] || error "no read done"
5734         [ "$write_bytes" != 0 ] || error "no write done"
5735 }
5736 run_test 127 "verify the client stats are sane"
5737
5738 test_128() { # bug 15212
5739         touch $DIR/$tfile
5740         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
5741                 find $DIR/$tfile
5742                 find $DIR/$tfile
5743         EOF
5744
5745         result=$(grep error $TMP/$tfile.log)
5746         rm -f $DIR/$tfile
5747         [ -z "$result" ] || error "consecutive find with interactive lfs failed"
5748 }
5749 run_test 128 "interactive lfs for 2 consecutive finds"
5750
5751 test_129() {
5752         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return 0
5753         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5754
5755         local MNTDEV=$(get_mds_mntdev_proc_path)
5756         DEV=$(ldiskfs_canon "$MNTDEV" mds)
5757         [ -z "$DEV" ] && error "can't access mds mntdev"
5758         EFBIG=27
5759         LDPROC=/proc/fs/ldiskfs/$DEV/max_dir_size
5760         do_facet mds "test -e /sys/fs/ldiskfs/$DEV/max_dir_size" && LDPROC=/sys/fs/ldiskfs/$DEV/max_dir_size
5761         MAX=16384
5762
5763         do_facet mds "echo $MAX > $LDPROC"
5764
5765         mkdir -p $DIR/$tdir
5766
5767         I=0
5768         J=0
5769         while [ ! $I -gt $MAX ]; do
5770                 multiop $DIR/$tdir/$J Oc
5771                 rc=$?
5772                 if [ $rc -eq $EFBIG ]; then
5773                         do_facet mds "echo 0 >$LDPROC"
5774                         echo "return code $rc received as expected"
5775                         return 0
5776                 elif [ $rc -ne 0 ]; then
5777                         do_facet mds "echo 0 >$LDPROC"
5778                         error_exit "error $rc instead of expected $EFBIG"
5779                 fi
5780                 J=$((J+1))
5781                 I=$(stat -c%s "$DIR/$tdir")
5782         done
5783
5784         error "exceeded dir size limit: $I bytes"
5785         do_facet mds "echo 0 >$LDPROC"
5786 }
5787 run_test 129 "test directory size limit ========================"
5788
5789 OLDIFS="$IFS"
5790 cleanup_130() {
5791         trap 0
5792         IFS="$OLDIFS"
5793 }
5794
5795 test_130a() {
5796         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5797         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5798
5799         trap cleanup_130 EXIT RETURN
5800
5801         local fm_file=$DIR/$tfile
5802         lfs setstripe -s 65536 -c 1 $fm_file ||
5803                 error "setstripe failed on $fm_file"
5804         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
5805                 error "dd failed for $fm_file"
5806
5807         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5808         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5809
5810         lun=`$GETSTRIPE $fm_file  | grep -A 10 obdidx | awk '{print $1}' | grep -v "obdidx"`
5811
5812         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
5813         IFS=$'\n'
5814         tot_len=0
5815         for line in $filefrag_op
5816         do
5817                 frag_lun=`echo $line | cut -d: -f5`
5818                 ext_len=`echo $line | cut -d: -f4`
5819                 if (( $frag_lun != $lun )); then
5820                         cleanup_130
5821                         error "FIEMAP on 1-stripe file($fm_file) failed"
5822                         return
5823                 fi
5824                 (( tot_len += ext_len ))
5825         done
5826
5827         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
5828                 cleanup_130
5829                 error "FIEMAP on 1-stripe file($fm_file) failed;"
5830                 return
5831         fi
5832
5833         cleanup_130
5834
5835         echo "FIEMAP on single striped file succeeded"
5836 }
5837 run_test 130a "FIEMAP (1-stripe file)"
5838
5839 test_130b() {
5840         [ "$OSTCOUNT" -lt "2" ] && skip_env "FIEMAP on 2-stripe file test" && return
5841
5842         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5843         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5844
5845         trap cleanup_130 EXIT RETURN
5846
5847         local fm_file=$DIR/$tfile
5848         lfs setstripe -s 65536 -c 2 $fm_file ||
5849                 error "setstripe failed on $fm_file"
5850         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
5851                 error "dd failed on $fm_file"
5852
5853         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5854         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5855
5856         last_lun=`echo $filefrag_op | cut -d: -f5`
5857
5858         IFS=$'\n'
5859         tot_len=0
5860         num_luns=1
5861         for line in $filefrag_op; do
5862                 frag_lun=`echo $line | cut -d: -f5`
5863                 ext_len=`echo $line | cut -d: -f4`
5864                 if (( $frag_lun != $last_lun )); then
5865                         if (( tot_len != 1024 )); then
5866                                 cleanup_130
5867                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of 256"
5868                                 return
5869                         else
5870                                 (( num_luns += 1 ))
5871                                 tot_len=0
5872                         fi
5873                 fi
5874                 (( tot_len += ext_len ))
5875                 last_lun=$frag_lun
5876         done
5877         if (( num_luns != 2 || tot_len != 1024 )); then
5878                 cleanup_130
5879                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
5880                 return
5881         fi
5882
5883         cleanup_130
5884
5885         echo "FIEMAP on 2-stripe file succeeded"
5886 }
5887 run_test 130b "FIEMAP (2-stripe file)"
5888
5889 test_130c() {
5890         [ "$OSTCOUNT" -lt "2" ] && skip_env "FIEMAP on 2-stripe hole test" && return
5891
5892         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5893         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5894
5895         trap cleanup_130 EXIT RETURN
5896
5897         local fm_file=$DIR/$tfile
5898         lfs setstripe -s 65536 -c 2 $fm_file ||
5899                 error "setstripe failed on $fm_file"
5900         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
5901                 error "dd failed on $fm_file"
5902
5903         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5904         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5905
5906         last_lun=`echo $filefrag_op | cut -d: -f5`
5907
5908         IFS=$'\n'
5909         tot_len=0
5910         num_luns=1
5911         for line in $filefrag_op
5912         do
5913                 frag_lun=`echo $line | cut -d: -f5`
5914                 ext_len=`echo $line | cut -d: -f4`
5915                 if (( $frag_lun != $last_lun )); then
5916                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
5917                         if (( logical != 512 )); then
5918                                 cleanup_130
5919                                 error "FIEMAP $fm_file: logical start for LUN $logical instead of 512"
5920                                 return
5921                         fi
5922                         if (( tot_len != 512 )); then
5923                                 cleanup_130
5924                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of 1024"
5925                                 return
5926                         else
5927                                 (( num_luns += 1 ))
5928                                 tot_len=0
5929                         fi
5930                 fi
5931                 (( tot_len += ext_len ))
5932                 last_lun=$frag_lun
5933         done
5934         if (( num_luns != 2 || tot_len != 512 )); then
5935                 cleanup_130
5936                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
5937                 return
5938         fi
5939
5940         cleanup_130
5941
5942         echo "FIEMAP on 2-stripe file with hole succeeded"
5943 }
5944 run_test 130c "FIEMAP (2-stripe file with hole)"
5945
5946 test_130d() {
5947         [ "$OSTCOUNT" -lt "3" ] && skip_env "FIEMAP on N-stripe file test" && return
5948
5949         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5950         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
5951
5952         trap cleanup_130 EXIT RETURN
5953
5954         local fm_file=$DIR/$tfile
5955         lfs setstripe -s 65536 -c $OSTCOUNT $fm_file ||
5956                 error "setstripe failed on $fm_file"
5957         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
5958                 error "dd failed on $fm_file"
5959
5960         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5961         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5962
5963         last_lun=`echo $filefrag_op | cut -d: -f5`
5964
5965         IFS=$'\n'
5966         tot_len=0
5967         num_luns=1
5968         for line in $filefrag_op
5969         do
5970                 frag_lun=`echo $line | cut -d: -f5`
5971                 ext_len=`echo $line | cut -d: -f4`
5972                 if (( $frag_lun != $last_lun )); then
5973                         if (( tot_len != 1024 )); then
5974                                 cleanup_130
5975                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of 1024"
5976                                 return
5977                         else
5978                                 (( num_luns += 1 ))
5979                                 tot_len=0
5980                         fi
5981                 fi
5982                 (( tot_len += ext_len ))
5983                 last_lun=$frag_lun
5984         done
5985         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
5986                 cleanup_130
5987                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
5988                 return
5989         fi
5990
5991         cleanup_130
5992
5993         echo "FIEMAP on N-stripe file succeeded"
5994 }
5995 run_test 130d "FIEMAP (N-stripe file)"
5996
5997 test_130e() {
5998         [ "$OSTCOUNT" -lt "2" ] && skip "continuation FIEMAP test" && return
5999
6000         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
6001         [ -n "$filefrag_op" ] && skip "filefrag has no FIEMAP support" && return
6002
6003         trap cleanup_130 EXIT RETURN
6004
6005         local fm_file=$DIR/$tfile
6006         lfs setstripe -s 131072 -c 2 $fm_file ||
6007                 error "setstripe failed on $fm_file"
6008         NUM_BLKS=512
6009         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
6010         for ((i = 0; i < $NUM_BLKS; i++)); do
6011                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
6012         done
6013
6014         filefrag -ves $fm_file || error "filefrag $fm_file failed"
6015         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
6016
6017         last_lun=`echo $filefrag_op | cut -d: -f5`
6018
6019         IFS=$'\n'
6020         tot_len=0
6021         num_luns=1
6022         for line in $filefrag_op
6023         do
6024                 frag_lun=`echo $line | cut -d: -f5`
6025                 ext_len=`echo $line | cut -d: -f4`
6026                 if (( $frag_lun != $last_lun )); then
6027                         if (( tot_len != $EXPECTED_LEN )); then
6028                                 cleanup_130
6029                                 error "FIEMAP $fm_file: len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
6030                                 return
6031                         else
6032                                 (( num_luns += 1 ))
6033                                 tot_len=0
6034                         fi
6035                 fi
6036                 (( tot_len += ext_len ))
6037                 last_lun=$frag_lun
6038         done
6039         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
6040                 cleanup_130
6041                 error "FIEMAP $fm_file: wrong number of LUNs or wrong len for OST $last_lun"
6042                 return
6043         fi
6044
6045         cleanup_130
6046
6047         echo "FIEMAP with continuation calls succeeded"
6048 }
6049 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
6050
6051 check_stats() {
6052         local res
6053         local count
6054         case $1 in
6055         mds) local dev=$(get_mds_mdt_device_proc_path)
6056              res=`do_facet mds $LCTL get_param $dev.$FSNAME-MDT0000.stats | grep "$2"`
6057                  ;;
6058         ost) res=`do_facet ost0 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
6059                  ;;
6060         *) error "Wrong argument $1" ;;
6061         esac
6062         echo $res
6063         count=`echo $res | awk '{print $2}'`
6064         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
6065         # if the argument $3 is zero, it means any stat increment is ok.
6066         if [ $3 -gt 0 ] ; then
6067                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
6068         fi
6069 }
6070
6071 test_133a() {
6072         # interop 18 <-> 20
6073         local lustre_version=$(get_lustre_version mds)
6074         if [[ $lustre_version != 1.8* ]]; then
6075                 skip mds running $lustre_version, no stats, bz22378
6076                 return 0
6077         fi
6078
6079         local testdir=$DIR/${tdir}/stats_testdir
6080         mkdir -p $DIR/${tdir}
6081
6082         # clear stats.
6083         local dev=$(get_mds_mdt_device_proc_path)
6084         do_facet mds $LCTL set_param $dev.*.stats=clear
6085         do_facet ost $LCTL set_param obdfilter.*.stats=clear
6086
6087         # verify mdt stats first.
6088         mkdir ${testdir} || error "mkdir failed"
6089         check_stats mds "mkdir" 1
6090         touch ${testdir}/${tfile} || "touch failed"
6091         # LPROC_MDS_OPEN is incremented by 2 - in mds_open() and mds_intent_policy()
6092         check_stats mds "open" 2
6093         check_stats mds "close" 1
6094         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
6095         check_stats mds "mknod" 1
6096         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
6097         check_stats mds "unlink" 1
6098         rm -f ${testdir}/${tfile} || error "file remove failed"
6099         check_stats mds "unlink" 2
6100
6101         # remove working dir and check mdt stats again.
6102         rmdir ${testdir} || error "rmdir failed"
6103         check_stats mds "rmdir" 1
6104
6105         rm -rf $DIR/${tdir}
6106 }
6107 run_test 133a "Verifying MDT stats ========================================"
6108
6109 test_133b() {
6110         # interop 18 <-> 20
6111         local lustre_version=$(get_lustre_version mds)
6112         if [[ $lustre_version != 1.8* ]]; then
6113                 skip mds running $lustre_version, no stats, bz22378
6114                 return 0
6115         fi
6116
6117         local testdir=$DIR/${tdir}/stats_testdir
6118         mkdir -p ${testdir} || error "mkdir failed"
6119         touch ${testdir}/${tfile} || "touch failed"
6120         cancel_lru_locks mdc
6121
6122         # clear stats.
6123         local dev=$(get_mds_mdt_device_proc_path)
6124         do_facet mds $LCTL set_param $dev.*.stats=clear
6125         do_facet ost $LCTL set_param obdfilter.*.stats=clear
6126
6127         # extra mdt stats verification.
6128         stat ${testdir}/${tfile} || error "stat failed"
6129         check_stats mds "getattr" 0
6130         chmod 444 ${testdir}/${tfile} || error "chmod failed"
6131         check_stats mds "setattr" 1
6132         $LFS df || error "lfs failed"
6133         check_stats mds "statfs" 1
6134
6135         rm -rf $DIR/${tdir}
6136 }
6137 run_test 133b "Verifying extra MDT stats =================================="
6138
6139 test_133c() {
6140         # interop 18 <-> 20
6141         local lustre_version=$(get_lustre_version mds)
6142         if [[ $lustre_version != 1.8* ]]; then
6143                 skip mds running $lustre_version, no stats, bz22378
6144                 return 0
6145         fi
6146
6147         local testdir=$DIR/${tdir}/stats_testdir
6148         mkdir -p ${testdir} || error "mkdir failed"
6149
6150         # verify obdfilter stats.
6151         $LFS setstripe -c 1 -o 0 ${testdir}/${tfile}
6152         sync
6153         cancel_lru_locks osc
6154
6155         # clear stats.
6156         local dev=$(get_mds_mdt_device_proc_path)
6157         do_facet mds $LCTL set_param $dev.*.stats=clear
6158         do_facet ost $LCTL set_param obdfilter.*.stats=clear
6159
6160         dd if=/dev/zero of=${testdir}/${tfile} bs=1024k count=1 || error "dd failed"
6161         sync
6162         cancel_lru_locks osc
6163         check_stats ost "write" 1
6164
6165         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
6166         check_stats ost "read" 1
6167
6168         > ${testdir}/${tfile} || error "truncate failed"
6169         check_stats ost "punch" 1
6170
6171         rm -f ${testdir}/${tfile} || error "file remove failed"
6172         check_stats ost "destroy" 1
6173
6174         rm -rf $DIR/${tdir}
6175 }
6176 run_test 133c "Verifying OST stats ========================================"
6177
6178 test_140() { #bug-17379
6179         mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
6180         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
6181         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
6182
6183         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
6184         local i=0
6185         while i=`expr $i + 1`; do
6186                 mkdir -p $i || error "Creating dir $i"
6187                 cd $i || error "Changing to $i"
6188                 ln -s ../stat stat || error "Creating stat symlink"
6189                 # Read the symlink until ELOOP present,
6190                 # not LBUGing the system is considered success,
6191                 # we didn't overrun the stack.
6192                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
6193                 [ $ret -ne 0 ] && {
6194                         if [ $ret -eq 40 ]; then
6195                                 break  # -ELOOP
6196                         else
6197                                 error "Open stat symlink"
6198                                 return
6199                         fi
6200                 }
6201         done
6202         i=`expr $i - 1`
6203         echo "The symlink depth = $i"
6204         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 ] || error "Invalid symlink depth"
6205 }
6206 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
6207
6208 test_150() {
6209         local TF="$TMP/$tfile"
6210
6211         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
6212         cp $TF $DIR/$tfile
6213         cancel_lru_locks osc
6214         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
6215         remount_client $MOUNT
6216         df -P $MOUNT
6217         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
6218
6219         $TRUNCATE $TF 6000
6220         $TRUNCATE $DIR/$tfile 6000
6221         cancel_lru_locks osc
6222         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
6223
6224         echo "12345" >>$TF
6225         echo "12345" >>$DIR/$tfile
6226         cancel_lru_locks osc
6227         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
6228
6229         echo "12345" >>$TF
6230         echo "12345" >>$DIR/$tfile
6231         cancel_lru_locks osc
6232         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
6233
6234         rm -f $TF
6235         true
6236 }
6237 run_test 150 "truncate/append tests"
6238
6239 function roc_hit() {
6240     local list=$(comma_list $(osts_nodes))
6241
6242     ACCNUM=$(do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
6243         awk '/'cache_hit'/ {sum+=$2} END {print sum}')
6244     echo $ACCNUM
6245 }
6246
6247 function set_cache() {
6248     local on=1
6249
6250     if [ "$2" == "off" ]; then
6251         on=0;
6252     fi
6253     local list=$(comma_list $(osts_nodes))
6254     do_nodes $list lctl set_param obdfilter.*.${1}_cache_enable $on
6255
6256     cancel_lru_locks osc
6257 }
6258
6259 test_151() {
6260         remote_ost_nodsh && skip "remote OST with nodsh" && return
6261
6262         local list=$(comma_list $(osts_nodes))
6263         if ! do_nodes $list grep -q truncate_inode_pages_range /proc/kallsyms; then  #b=18718
6264                 skip "old RHEL4/SLES9 kernel" && return
6265         fi
6266
6267         local CPAGES=3
6268
6269         # check whether obdfilter is cache capable at all
6270         if ! do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable > /dev/null; then
6271                 echo "not cache-capable obdfilter"
6272                 return 0
6273         fi
6274
6275         # make sure cache is enabled on all obdfilters
6276         do_nodes $list $LCTL set_param obdfilter.*.read_cache_enable=1
6277         do_nodes $list $LCTL set_param obdfilter.*.writethrough_cache_enable=1
6278
6279         # pages should be in the case right after write
6280         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
6281         local BEFORE=`roc_hit`
6282         cancel_lru_locks osc
6283         cat $DIR/$tfile >/dev/null
6284         local AFTER=`roc_hit`
6285         if let "AFTER - BEFORE != CPAGES"; then
6286                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6287         fi
6288
6289         # the following read invalidates the cache
6290         cancel_lru_locks osc
6291         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 0
6292         cat $DIR/$tfile >/dev/null
6293
6294         # now data shouldn't be found in the cache
6295         BEFORE=`roc_hit`
6296         cancel_lru_locks osc
6297         cat $DIR/$tfile >/dev/null
6298         AFTER=`roc_hit`
6299         if let "AFTER - BEFORE != 0"; then
6300                 error "IN CACHE: before: $BEFORE, after: $AFTER"
6301         fi
6302
6303         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=1
6304         do_nodes $list $LCTL set_param obdfilter.*.writethrough_cache_enable=1
6305         rm -f $DIR/$tfile
6306 }
6307 run_test 151 "test cache on oss and controls ==============================="
6308
6309 test_152() {
6310         local TF="$TMP/$tfile"
6311
6312         # simulate ENOMEM during write
6313 #define OBD_FAIL_OST_NOMEM      0x226
6314         lctl set_param fail_loc=0x80000226
6315         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
6316         cp $TF $DIR/$tfile
6317         sync || error "sync failed"
6318         lctl set_param fail_loc=0
6319
6320         # discard client's cache
6321         cancel_lru_locks osc
6322
6323         # simulate ENOMEM during read
6324         lctl set_param fail_loc=0x80000226
6325         cmp $TF $DIR/$tfile || error "cmp failed"
6326         lctl set_param fail_loc=0
6327
6328         rm -f $TF
6329 }
6330 run_test 152 "test read/write with enomem ============================"
6331
6332 test_153() {
6333         multiop $DIR/$tfile Ow4096Ycu || error "multiop failed"
6334 }
6335 run_test 153 "test if fdatasync does not crash ======================="
6336
6337 test_154() {
6338         # do directio so as not to populate the page cache
6339         log "creating a 10 Mb file"
6340         multiop $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
6341         log "starting reads"
6342         dd if=$DIR/$tfile of=/dev/null bs=4096 &
6343         log "truncating the file"
6344         multiop $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
6345         log "killing dd"
6346         kill %+ || true # reads might have finished
6347         echo "wait until dd is finished"
6348         wait
6349         log "removing the temporary file"
6350         rm -rf $DIR/$tfile || error "tmp file removal failed"
6351 }
6352 run_test 154 "parallel read and truncate should not deadlock ==="
6353
6354 test_155_load() {
6355     local temp=$TMP/$tfile
6356     local file=$DIR/$tfile
6357     local list=$(comma_list $(osts_nodes))
6358     local big=$(do_nodes $list grep "cache" /proc/cpuinfo | \
6359         awk '{sum+=$4} END{print sum}')
6360
6361     log big is $big K
6362
6363     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
6364         error "dd of=$temp bs=6096 count=1 failed"
6365     cp $temp $file
6366     cancel_lru_locks osc
6367     cmp $temp $file || error "$temp $file differ"
6368
6369     $TRUNCATE $temp 6000
6370     $TRUNCATE $file 6000
6371     cmp $temp $file || error "$temp $file differ (truncate1)"
6372
6373     echo "12345" >>$temp
6374     echo "12345" >>$file
6375     cmp $temp $file || error "$temp $file differ (append1)"
6376
6377     echo "12345" >>$temp
6378     echo "12345" >>$file
6379     cmp $temp $file || error "$temp $file differ (append2)"
6380
6381     dd if=/dev/urandom of=$temp bs=$((big*2)) count=1k || \
6382         error "dd of=$temp bs=$((big*2)) count=1k failed"
6383     cp $temp $file
6384     ls -lh $temp $file
6385     cancel_lru_locks osc
6386     cmp $temp $file || error "$temp $file differ"
6387
6388     rm -f $temp
6389     true
6390 }
6391
6392 test_155a() {
6393     set_cache read on
6394     set_cache writethrough on
6395     test_155_load
6396 }
6397 run_test 155a "Verification of correctness: read cache:on write_cache:on"
6398
6399 test_155b() {
6400     set_cache read on
6401     set_cache writethrough off
6402     test_155_load
6403 }
6404 run_test 155b "Verification of correctness: read cache:on write_cache:off"
6405
6406 test_155c() {
6407     set_cache read off
6408     set_cache writethrough on
6409     test_155_load
6410 }
6411 run_test 155c "Verification of correctness: read cache:off write_cache:on"
6412
6413 test_155d() {
6414     set_cache read off
6415     set_cache writethrough off
6416     test_155_load
6417 }
6418 run_test 155d "Verification of correctness: read cache:off write_cache:off "
6419
6420 test_156() {
6421     local CPAGES=3
6422     local BEFORE
6423     local AFTER
6424     local file="$DIR/$tfile"
6425
6426     log "Turn on read and write cache"
6427     set_cache read on
6428     set_cache writethrough on
6429
6430     log "Write data and read it back."
6431     log "Read should be satisfied from the cache."
6432     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6433     BEFORE=`roc_hit`
6434     cancel_lru_locks osc
6435     cat $file >/dev/null
6436     AFTER=`roc_hit`
6437     if ! let "AFTER - BEFORE == CPAGES"; then
6438         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6439     else
6440         log "cache hits:: before: $BEFORE, after: $AFTER"
6441     fi
6442
6443     log "Read again; it should be satisfied from the cache."
6444     BEFORE=$AFTER
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
6455     log "Turn off the read cache and turn on the write cache"
6456     set_cache read off
6457     set_cache writethrough on
6458
6459     log "Read again; it should be satisfied from the cache."
6460     BEFORE=`roc_hit`
6461     cancel_lru_locks osc
6462     cat $file >/dev/null
6463     AFTER=`roc_hit`
6464     if ! let "AFTER - BEFORE == CPAGES"; then
6465         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6466     else
6467         log "cache hits:: before: $BEFORE, after: $AFTER"
6468     fi
6469
6470     log "Read again; it should not be satisfied from the cache."
6471     BEFORE=$AFTER
6472     cancel_lru_locks osc
6473     cat $file >/dev/null
6474     AFTER=`roc_hit`
6475     if ! let "AFTER - BEFORE == 0"; then
6476         error "IN CACHE: before: $BEFORE, after: $AFTER"
6477     else
6478         log "cache hits:: before: $BEFORE, after: $AFTER"
6479     fi
6480
6481     log "Write data and read it back."
6482     log "Read should be satisfied from the cache."
6483     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6484     BEFORE=`roc_hit`
6485     cancel_lru_locks osc
6486     cat $file >/dev/null
6487     AFTER=`roc_hit`
6488     if ! let "AFTER - BEFORE == CPAGES"; then
6489         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6490     else
6491         log "cache hits:: before: $BEFORE, after: $AFTER"
6492     fi
6493
6494     log "Read again; it should not be satisfied from the cache."
6495     BEFORE=$AFTER
6496     cancel_lru_locks osc
6497     cat $file >/dev/null
6498     AFTER=`roc_hit`
6499     if ! let "AFTER - BEFORE == 0"; then
6500         error "IN CACHE: before: $BEFORE, after: $AFTER"
6501     else
6502         log "cache hits:: before: $BEFORE, after: $AFTER"
6503     fi
6504
6505
6506     log "Turn off read and write cache"
6507     set_cache read off
6508     set_cache writethrough off
6509
6510     log "Write data and read it back"
6511     log "It should not be satisfied from the cache."
6512     rm -f $file
6513     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6514     cancel_lru_locks osc
6515     BEFORE=`roc_hit`
6516     cat $file >/dev/null
6517     AFTER=`roc_hit`
6518     if ! let "AFTER - BEFORE == 0"; then
6519         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
6520     else
6521         log "cache hits:: before: $BEFORE, after: $AFTER"
6522     fi
6523
6524
6525     log "Turn on the read cache and turn off the write cache"
6526     set_cache read on
6527     set_cache writethrough off
6528
6529     log "Write data and read it back"
6530     log "It should not be satisfied from the cache."
6531     rm -f $file
6532     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
6533     BEFORE=`roc_hit`
6534     cancel_lru_locks osc
6535     cat $file >/dev/null
6536     AFTER=`roc_hit`
6537     if ! let "AFTER - BEFORE == 0"; then
6538         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
6539     else
6540         log "cache hits:: before: $BEFORE, after: $AFTER"
6541     fi
6542
6543     log "Read again; it should be satisfied from the cache."
6544     BEFORE=`roc_hit`
6545     cancel_lru_locks osc
6546     cat $file >/dev/null
6547     AFTER=`roc_hit`
6548     if ! let "AFTER - BEFORE == CPAGES"; then
6549         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6550     else
6551         log "cache hits:: before: $BEFORE, after: $AFTER"
6552     fi
6553
6554     rm -f $file
6555 }
6556 run_test 156 "Verification of ROC tunables ========================"
6557
6558 test_170() {
6559         $LCTL clear     # bug 18514
6560         $LCTL debug_daemon start $TMP/${tfile}_log_good
6561         touch $DIR/$tfile
6562         $LCTL debug_daemon stop
6563         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
6564                error "sed failed to read log_good"
6565
6566         $LCTL debug_daemon start $TMP/${tfile}_log_good
6567         rm -rf $DIR/$tfile
6568         $LCTL debug_daemon stop
6569
6570         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
6571                error "lctl df log_bad failed"
6572
6573         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
6574         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
6575
6576         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
6577         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
6578
6579         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
6580                 error "bad_line good_line1 good_line2 are empty"
6581
6582         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
6583         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
6584         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
6585
6586         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
6587         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
6588         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
6589
6590         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
6591                 error "bad_line_new good_line_new are empty"
6592
6593         local expected_good=$((good_line1 + good_line2*2))
6594
6595         rm -f $TMP/${tfile}*
6596         if [ $bad_line -ne $bad_line_new ]; then
6597                 error "expected $bad_line bad lines, but got $bad_line_new"
6598                 return 1
6599         fi
6600
6601         if [ $expected_good -ne $good_line_new ]; then
6602                 error "expected $expected_good good lines, but got $good_line_new"
6603                 return 2
6604         fi
6605         true
6606 }
6607 run_test 170 "test lctl df to handle corrupted log ====================="
6608
6609 test_171() { # bug20592
6610 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
6611         $LCTL set_param fail_loc=0x50e
6612         $LCTL set_param fail_val=3000
6613         multiop_bg_pause $DIR/$tfile Os || true
6614         # cause log dump
6615         sleep 3
6616         if dmesg | grep "recursive fault"; then
6617                 error "caught a recursive fault"
6618         fi
6619         $LCTL set_param fail_loc=0
6620         true
6621 }
6622 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
6623
6624 obdecho_create_test() {
6625         local OBD=$1
6626         local node=$2
6627         local rc=0
6628         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
6629         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" || rc=2; }
6630         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec create 1" || rc=3; }
6631         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec test_brw 0 w 1" || rc=4; }
6632         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec cleanup" || rc=5; }
6633         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec detach" || rc=6; }
6634         return $rc
6635 }
6636
6637 test_180() {
6638         local lustre_version=$(get_lustre_version mds)
6639         if [[ $lustre_version != 1.8* ]]; then
6640                skip bug22316 mds running $lustre_version
6641                return
6642         fi
6643         local rc=0
6644         local rmmod_local=0
6645         local rmmod_remote=0
6646
6647         lsmod | grep -q obdecho || { load_module obdecho/obdecho && rmmod_local=1; }
6648
6649         OBD=`$LCTL  dl | awk ' /-osc-/ { print $4; exit; }'`
6650         [ "x$OBD" != "x" ] && { obdecho_create_test $OBD client || rc=2; }
6651         [ $rmmod_local -eq 1 ] && rmmod obdecho
6652         [ $rc -ne 0 ] && return $rc
6653
6654         do_facet ost "lsmod | grep -q obdecho || { insmod ${LUSTRE}/obdecho/obdecho.ko || modprobe obdecho; }" && rmmod_remote=1
6655
6656         OBD=$(do_facet ost "$LCTL  dl | awk '/obdfilter/ { print; exit; }'" | awk '{print $4;}')
6657         [ "x$OBD" != "x" ] && { obdecho_create_test $OBD ost || rc=3; }
6658         [ $rmmod_remote -eq 1 ] && do_facet ost "rmmod obdecho"
6659         [ $rc -ne 0 ] && return $rc
6660
6661         true
6662 }
6663 run_test 180 "test obdecho ============================================"
6664
6665 test_181() { # bug 22177
6666         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
6667         # create enough files to index the directory
6668         createmany -o $DIR/$tdir/foobar 4000
6669         # print attributes for debug purpose
6670         lsattr -d .
6671         # open dir
6672         multiop_bg_pause $DIR/$tdir D_Sc || return 1
6673         MULTIPID=$!
6674         # remove the files & current working dir
6675         unlinkmany $DIR/$tdir/foobar 4000
6676         rmdir $DIR/$tdir
6677         kill -USR1 $MULTIPID
6678         wait $MULTIPID
6679         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
6680         return 0
6681 }
6682 run_test 181 "Test open-unlinked dir ========================"
6683
6684 POOL=${POOL:-cea1}
6685 TGT_COUNT=$OSTCOUNT
6686 TGTPOOL_FIRST=1
6687 TGTPOOL_MAX=$(($TGT_COUNT - 1))
6688 TGTPOOL_STEP=2
6689 TGTPOOL_LIST=`seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`
6690 POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
6691 POOL_DIR_NAME=dir_tst
6692 POOL_DIR=$POOL_ROOT/$POOL_DIR_NAME
6693 POOL_FILE=$POOL_ROOT/file_tst
6694
6695 test_pools()
6696 {
6697         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep pools)" ] &&
6698                 skip "missing pools support on server" && return 1
6699         remote_mgs_nodsh && skip "remote MGS with nodsh" && return 1
6700         [ -z "$mdtlov" ] && mdtlov=$(get_mdtlov_proc_path $FSNAME)
6701         return 0
6702 }
6703
6704 check_file_in_pool()
6705 {
6706         file=$1
6707         res=$($GETSTRIPE $file | grep 0x | cut -f2)
6708         for i in $res
6709         do
6710                 found=$(echo :$TGTPOOL_LIST: | tr " " ":"  | grep :$i:)
6711                 if [[ "$found" == "" ]]
6712                 then
6713                         echo "pool list: $TGTPOOL_LIST"
6714                         echo "striping: $res"
6715                         error "$file not allocated in $POOL"
6716                         return 1
6717                 fi
6718         done
6719         return 0
6720 }
6721
6722 export mdtlov=
6723
6724 trap "cleanup_pools $FSNAME" EXIT
6725
6726 test_200a() {
6727         test_pools || return 0
6728
6729         create_pool $FSNAME.$POOL || return $?
6730         [ $($LFS pool_list $FSNAME | grep -c $POOL) -eq 1 ] ||
6731                 error "$POOL not in lfs pool_list"
6732 }
6733 run_test 200a "Create new pool =========================================="
6734
6735 test_200b() {
6736         test_pools || return 0
6737         TGT=$(for i in $TGTPOOL_LIST; do printf "$FSNAME-OST%04x_UUID " $i; done)
6738         do_facet mgs $LCTL pool_add $FSNAME.$POOL \
6739                 $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]
6740
6741         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | sort -u | tr '\n' ' ' " "$TGT" ||
6742                         error "Add to pool failed"
6743 }
6744 run_test 200b "Add targets to a pool ===================================="
6745
6746 test_200c() {
6747         test_pools || return 0
6748         mkdir -p $POOL_DIR
6749         $SETSTRIPE -c 2 -p $POOL $POOL_DIR
6750         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
6751         # b-19919 test relative path works well
6752         mkdir -p $POOL_DIR/$POOL_DIR_NAME
6753         cd $POOL_DIR
6754         $SETSTRIPE -c 2 -p $POOL $POOL_DIR_NAME
6755         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/$POOL_DIR_NAME"
6756         $SETSTRIPE -c 2 -p $POOL ./$POOL_DIR_NAME
6757         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/./$POOL_DIR_NAME"
6758         $SETSTRIPE -c 2 -p $POOL ../$POOL_DIR_NAME
6759         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/../$POOL_DIR_NAME"
6760         $SETSTRIPE -c 2 -p $POOL ../$POOL_DIR_NAME/$POOL_DIR_NAME
6761         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/../$POOL_DIR_NAME/$POOL_DIR_NAME"
6762          rm -rf $POOL_DIR_NAME; cd -
6763 }
6764 run_test 200c "Set pool on a directory ================================="
6765
6766 test_200d() {
6767         test_pools || return 0
6768         res=$($GETSTRIPE --pool $POOL_DIR | awk '/^pool:/ {print $2}')
6769         [ "$res" = $POOL ] || error "Pool on $POOL_DIR is $res, not $POOL"
6770 }
6771 run_test 200d "Check pool on a directory ==============================="
6772
6773 test_200e() {
6774         test_pools || return 0
6775         failed=0
6776         for i in $(seq -w 1 $(($TGT_COUNT * 3))); do
6777                 file=$POOL_DIR/file-$i
6778                 touch $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 200e "Check files allocation from directory pool =============="
6787
6788 test_200f() {
6789         test_pools || return 0
6790         mkdir -p $POOL_FILE
6791         failed=0
6792         for i in $(seq -w 1 $(($TGT_COUNT * 3))); do
6793                 file=$POOL_FILE/spoo-$i
6794                 $SETSTRIPE -p $POOL $file
6795                 check_file_in_pool $file
6796                 if [[ $? != 0 ]]; then
6797                         failed=$(($failed + 1))
6798                 fi
6799         done
6800         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
6801 }
6802 run_test 200f "Create files in a pool ==================================="
6803
6804 test_200g() {
6805         test_pools || return 0
6806
6807         TGT=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$POOL | tr '\n' ' ')
6808         res=$($LFS df --pool $FSNAME.$POOL | awk '{print $1}' | grep "$FSNAME-OST" | tr '\n' ' ')
6809         [ "$res" = "$TGT" ] || error "Pools OSTs '$TGT' is not '$res' that lfs df reports"
6810 }
6811 run_test 200g "lfs df a pool ============================================"
6812
6813 test_200h() { # b=24039
6814         test_pools || return 0
6815         mkdir -p $POOL_DIR || error "unable to create $POOL_DIR"
6816
6817         local file="/..$POOL_DIR/$tfile-1"
6818         $SETSTRIPE -p $POOL $file || error "unable to create $file"
6819
6820         cd $POOL_DIR
6821         $SETSTRIPE -p $POOL $tfile-2 || \
6822                 error "unable to create $tfile-2 in $POOL_DIR"
6823 }
6824 run_test 200h "Create files in a pool with relative pathname ============"
6825
6826 test_201a() {
6827         test_pools || return 0
6828
6829         TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
6830         do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
6831         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | grep $TGT" "" ||
6832                 error "$TGT not removed from $FSNAME.$POOL"
6833 }
6834 run_test 201a "Remove a target from a pool ============================="
6835
6836 test_201b() {
6837         test_pools || return 0
6838
6839         for TGT in $($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | sort -u)
6840         do
6841                 do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
6842         done
6843         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL" "" ||
6844                 error "Pool $FSNAME.$POOL cannot be drained"
6845         # striping on an empty/nonexistant pool should fall back to "pool of everything"
6846         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for empty pool"
6847         # setstripe on an empty pool should fail
6848         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
6849                 error "expected failure when creating file with empty pool"
6850         return 0
6851 }
6852 run_test 201b "Remove all targets from a pool =========================="
6853
6854 test_201c() {
6855         test_pools || return 0
6856
6857         do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
6858         
6859         sleep 2
6860     # striping on an empty/nonexistant pool should fall back to "pool of everything"
6861         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for missing pool"
6862         # setstripe on an empty pool should fail
6863         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
6864                 error "expected failure when creating file with missing pool"
6865
6866         # get param should return err once pool is gone
6867         if wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null ||
6868                 echo foo" "foo"; then
6869                 remove_pool_from_list $FSNAME.$POOL
6870                 return 0
6871         fi
6872         error "Pool $FSNAME.$POOL is not destroyed"
6873 }
6874 run_test 201c "Remove a pool ============================================"
6875
6876 cleanup_pools $FSNAME
6877
6878 test_202() {
6879         if [ "$NETTYPE" = "o2ib" ]; then
6880                 skip "unaligned direct I/O is not supported by o2iblnd"
6881                 return
6882         fi
6883         $LFS setstripe -c 2 -s 1048576 $DIR/$tfile
6884         multiop $DIR/$tfile oO_WRONLY:O_APPEND:O_DIRECT:b1048548b130c || \
6885                 error "direct write failed"
6886         multiop $DIR/${tfile}2 oO_WRONLY:O_CREAT:w1048548w130c || \
6887                 error "cached write failed"
6888         cmp $DIR/$tfile $DIR/${tfile}2 || error "cmp failed"
6889         rm -f $DIR/${tfile}2
6890 }
6891 run_test 202 "O_APPEND+O_DIRECT multistripe write ========================"
6892
6893 test_203() {
6894         local lustre_version=$(get_lustre_version mds)
6895         if [[ $lustre_version != 1.8* ]]; then
6896                skip bug23766 mds running $lustre_version
6897                return
6898         fi
6899
6900         local ATIME=`do_facet mds lctl get_param -n mds.*.atime_diff`
6901         echo "atime should be updated on the MDS when closing file" > $DIR/$tfile
6902         sync
6903         # reads should update atime on the client and close should update it on the MDS
6904         multiop_bg_pause $DIR/$tfile o_r20c || return 1
6905         MULTIPID=$!
6906         sleep $((ATIME+1))
6907         time1=`date +%s`
6908         log "now is $time1"
6909         kill -USR1 $MULTIPID || return 2
6910         echo "starting reads"
6911         wait
6912         cancel_lru_locks osc
6913         cancel_lru_locks mdc
6914         time2=`stat -c "%X" $DIR/$tfile`
6915         log "new atime is $time2"
6916         [ "$time2" -ge "$time1" ] || error "atime was not updated"
6917 }
6918 run_test 203 " atime should be updated on the MDS when closing file ===="
6919
6920
6921 #
6922 # tests that do cleanup/setup should be run at the end
6923 #
6924
6925 test_900() {
6926         local ls
6927         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
6928         $LCTL set_param fail_loc=0x903
6929         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
6930         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
6931                 echo "clear" > $ls
6932         done
6933         FAIL_ON_ERROR=true cleanup
6934         FAIL_ON_ERROR=true setup
6935 }
6936 run_test 900 "umount should not race with any mgc requeue thread"
6937
6938 complete $(basename $0) $SECONDS
6939 check_and_cleanup_lustre
6940 if [ "$I_MOUNTED" != "yes" ]; then
6941         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
6942 fi
6943 exit_status