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