Whamcloud - gitweb
62143638d1409303756798b704557f702fedb342
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
11 ALWAYS_EXCEPT="                27u   42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 # Tests that fail on uml
15 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
16 #                                    buffer i/o errs             sock spc runas
17 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 27m 27n 27o 27p 27q 27r 31d 54a  64b 99a 99b 99c 99d 99e 99f 101a"
18
19 case `uname -r` in
20 2.4*) FSTYPE=${FSTYPE:-ext3} ;;
21 2.6*) FSTYPE=${FSTYPE:-ldiskfs} ;;
22 *) error "unsupported kernel" ;;
23 esac
24
25 SRCDIR=$(cd $(dirname $0); echo $PWD)
26 export PATH=$PATH:/sbin
27
28 TMP=${TMP:-/tmp}
29
30 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
31 CREATETEST=${CREATETEST:-createtest}
32 LFS=${LFS:-lfs}
33 LFIND=${LFIND:-"$LFS find"}
34 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
35 LCTL=${LCTL:-lctl}
36 MCREATE=${MCREATE:-mcreate}
37 OPENFILE=${OPENFILE:-openfile}
38 OPENUNLINK=${OPENUNLINK:-openunlink}
39 READS=${READS:-"reads"}
40 MUNLINK=${MUNLINK:-munlink}
41 SOCKETSERVER=${SOCKETSERVER:-socketserver}
42 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
43 MEMHOG=${MEMHOG:-memhog}
44 DIRECTIO=${DIRECTIO:-directio}
45 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
46 UMOUNT=${UMOUNT:-"umount -d"}
47 STRIPES_PER_OBJ=-1
48 CHECK_GRANT=${CHECK_GRANT:-"yes"}
49 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
50
51 export NAME=${NAME:-local}
52
53 SAVE_PWD=$PWD
54
55 CLEANUP=${CLEANUP:-:}
56 SETUP=${SETUP:-:}
57 TRACE=${TRACE:-""}
58 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
59 . $LUSTRE/tests/test-framework.sh
60 init_test_env $@
61 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
62 init_logging
63
64 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24v 27m 36f 36g 36h 51b 60c 63 64b 68 71 73 77f 78 101a 103 115 120g 124b"
65
66 FAIL_ON_ERROR=false
67
68 cleanup() {
69         echo -n "cln.."
70         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
71         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
72 }
73 setup() {
74         echo -n "mnt.."
75         load_modules
76         setupall || exit 10
77         echo "done"
78 }
79
80 check_kernel_version() {
81         WANT_VER=$1
82         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
83         case $GOT_VER in
84         patchless|patchless_client) return 0;;
85         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
86         esac
87         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
88         return 1
89 }
90
91 if [ "$ONLY" == "cleanup" ]; then
92        sh llmountcleanup.sh
93        exit 0
94 fi
95
96 check_and_setup_lustre
97
98 DIR=${DIR:-$MOUNT}
99 assert_DIR
100
101 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
102     awk '{gsub(/_UUID/,""); print $1}' | head -1)
103 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
104 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
105 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
106 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
107 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
108 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
109
110 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
111 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
112 rm -rf $DIR/[Rdfs][0-9]*
113
114 # $RUNAS_ID may get set incorrectly somewhere else
115 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
116
117 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
118
119 build_test_filter
120
121 if [ "${ONLY}" = "MOUNT" ] ; then
122         echo "Lustre is up, please go on"
123         exit
124 fi
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         mkdir $DIR/d1/d2 && error "we expect EEXIST, but not returned"
160         $CHECKSTAT -t dir $DIR/d1/d2 || error
161 }
162 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
163
164 test_1b() {
165         rmdir $DIR/d1/d2
166         rmdir $DIR/d1
167         $CHECKSTAT -a $DIR/d1 || error
168 }
169 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
170
171 test_2a() {
172         mkdir $DIR/d2
173         touch $DIR/d2/f
174         $CHECKSTAT -t file $DIR/d2/f || error
175 }
176 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
177
178 test_2b() {
179         rm -r $DIR/d2
180         $CHECKSTAT -a $DIR/d2 || error
181 }
182 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
183
184 test_3a() {
185         mkdir $DIR/d3
186         $CHECKSTAT -t dir $DIR/d3 || error
187 }
188 run_test 3a "mkdir .../d3 ======================================"
189
190 test_3b() {
191         if [ ! -d $DIR/d3 ]; then
192                 mkdir $DIR/d3
193         fi
194         touch $DIR/d3/f
195         $CHECKSTAT -t file $DIR/d3/f || error
196 }
197 run_test 3b "touch .../d3/f ===================================="
198
199 test_3c() {
200         rm -r $DIR/d3
201         $CHECKSTAT -a $DIR/d3 || error
202 }
203 run_test 3c "rm -r .../d3 ======================================"
204
205 test_4a() {
206         mkdir $DIR/d4
207         $CHECKSTAT -t dir $DIR/d4 || error
208 }
209 run_test 4a "mkdir .../d4 ======================================"
210
211 test_4b() {
212         if [ ! -d $DIR/d4 ]; then
213                 mkdir $DIR/d4
214         fi
215         mkdir $DIR/d4/d2
216         $CHECKSTAT -t dir $DIR/d4/d2 || error
217 }
218 run_test 4b "mkdir .../d4/d2 ==================================="
219
220 test_5() {
221         mkdir $DIR/d5
222         mkdir $DIR/d5/d2
223         chmod 0707 $DIR/d5/d2
224         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
225 }
226 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
227
228 test_6a() {
229         touch $DIR/f6a
230         chmod 0666 $DIR/f6a || error
231         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
232 }
233 run_test 6a "touch .../f6a; chmod .../f6a ======================"
234
235 test_6b() {
236         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
237         if [ ! -f $DIR/f6a ]; then
238                 touch $DIR/f6a
239                 chmod 0666 $DIR/f6a
240         fi
241         $RUNAS chmod 0444 $DIR/f6a && error
242         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
243 }
244 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
245
246 test_6c() {
247         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
248         touch $DIR/f6c
249         chown $RUNAS_ID $DIR/f6c || error
250         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
251 }
252 run_test 6c "touch .../f6c; chown .../f6c ======================"
253
254 test_6d() {
255         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
256         if [ ! -f $DIR/f6c ]; then
257                 touch $DIR/f6c
258                 chown $RUNAS_ID $DIR/f6c
259         fi
260         $RUNAS chown $UID $DIR/f6c && error
261         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
262 }
263 run_test 6d "$RUNAS chown .../f6c (should return error) =="
264
265 test_6e() {
266         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
267         touch $DIR/f6e
268         chgrp $RUNAS_ID $DIR/f6e || error
269         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
270 }
271 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
272
273 test_6f() {
274         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
275         if [ ! -f $DIR/f6e ]; then
276                 touch $DIR/f6e
277                 chgrp $RUNAS_ID $DIR/f6e
278         fi
279         $RUNAS chgrp $UID $DIR/f6e && error
280         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
281 }
282 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
283
284 test_6g() {
285         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
286         mkdir $DIR/d6g || error
287         chmod 777 $DIR/d6g || error
288         $RUNAS mkdir $DIR/d6g/d || error
289         chmod g+s $DIR/d6g/d || error
290         mkdir $DIR/d6g/d/subdir
291         $CHECKSTAT -g \#$RUNAS_GID $DIR/d6g/d/subdir || error
292 }
293 run_test 6g "Is new dir in sgid dir inheriting group?"
294
295 test_6h() { # bug 7331
296         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
297         touch $DIR/f6h || error "touch failed"
298         chown $RUNAS_ID:$RUNAS_GID $DIR/f6h || error "initial chown failed"
299         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
300         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/f6h || error
301 }
302 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
303
304 test_7a() {
305         mkdir $DIR/d7
306         $MCREATE $DIR/d7/f
307         chmod 0666 $DIR/d7/f
308         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
309 }
310 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
311
312 test_7b() {
313         if [ ! -d $DIR/d7 ]; then
314                 mkdir $DIR/d7
315         fi
316         $MCREATE $DIR/d7/f2
317         echo -n foo > $DIR/d7/f2
318         [ "`cat $DIR/d7/f2`" = "foo" ] || error
319         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
320 }
321 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
322
323 test_8() {
324         mkdir $DIR/d8
325         touch $DIR/d8/f
326         chmod 0666 $DIR/d8/f
327         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
328 }
329 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
330
331 test_9() {
332         mkdir $DIR/d9
333         mkdir $DIR/d9/d2
334         mkdir $DIR/d9/d2/d3
335         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
336 }
337 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
338
339 test_10() {
340         mkdir $DIR/d10
341         mkdir $DIR/d10/d2
342         touch $DIR/d10/d2/f
343         $CHECKSTAT -t file $DIR/d10/d2/f || error
344 }
345 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
346
347 test_11() {
348         mkdir $DIR/d11
349         mkdir $DIR/d11/d2
350         chmod 0666 $DIR/d11/d2
351         chmod 0705 $DIR/d11/d2
352         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
353 }
354 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
355
356 test_12() {
357         mkdir $DIR/d12
358         touch $DIR/d12/f
359         chmod 0666 $DIR/d12/f
360         chmod 0654 $DIR/d12/f
361         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
362 }
363 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
364
365 test_13() {
366         mkdir $DIR/d13
367         dd if=/dev/zero of=$DIR/d13/f count=10
368         >  $DIR/d13/f
369         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
370 }
371 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
372
373 test_14() {
374         mkdir $DIR/d14
375         touch $DIR/d14/f
376         rm $DIR/d14/f
377         $CHECKSTAT -a $DIR/d14/f || error
378 }
379 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
380
381 test_15() {
382         mkdir $DIR/d15
383         touch $DIR/d15/f
384         mv $DIR/d15/f $DIR/d15/f2
385         $CHECKSTAT -t file $DIR/d15/f2 || error
386 }
387 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
388
389 test_16() {
390         mkdir $DIR/d16
391         touch $DIR/d16/f
392         rm -rf $DIR/d16/f
393         $CHECKSTAT -a $DIR/d16/f || error
394 }
395 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
396
397 test_17a() {
398         mkdir -p $DIR/d17
399         touch $DIR/d17/f
400         ln -s $DIR/d17/f $DIR/d17/l-exist
401         ls -l $DIR/d17
402         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
403         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
404         rm -f $DIR/d17/l-exist
405         $CHECKSTAT -a $DIR/d17/l-exist || error
406 }
407 run_test 17a "symlinks: create, remove (real) =================="
408
409 test_17b() {
410         mkdir -p $DIR/d17
411         ln -s no-such-file $DIR/d17/l-dangle
412         ls -l $DIR/d17
413         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
414         $CHECKSTAT -fa $DIR/d17/l-dangle || error
415         rm -f $DIR/d17/l-dangle
416         $CHECKSTAT -a $DIR/d17/l-dangle || error
417 }
418 run_test 17b "symlinks: create, remove (dangling) =============="
419
420 test_17c() { # bug 3440 - don't save failed open RPC for replay
421         mkdir -p $DIR/d17
422         ln -s foo $DIR/d17/f17c
423         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
424 }
425 run_test 17c "symlinks: open dangling (should return error) ===="
426
427 test_17d() {
428         mkdir -p $DIR/d17
429         ln -s foo $DIR/d17/f17d
430         touch $DIR/d17/f17d || error "creating to new symlink"
431 }
432 run_test 17d "symlinks: create dangling ========================"
433
434 test_17e() {
435         mkdir -p $DIR/$tdir
436         local foo=$DIR/$tdir/$tfile
437         ln -s $foo $foo || error "create symlink failed"
438         ls -l $foo || error "ls -l failed"
439         ls $foo && error "ls not failed" || true
440 }
441 run_test 17e "symlinks: create recursive symlink (should return error) ===="
442
443 test_17f() {
444         mkdir -p $DIR/d17f
445         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
446         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
447         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
448         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
449         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
450         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/d17f/666
451         ls -l  $DIR/d17f
452 }
453 run_test 17f "symlinks: long and very long symlink name ========================"
454
455 test_17g() {
456         mkdir -p $DIR/$tdir
457         LONGSYMLINK="$(dd if=/dev/zero bs=4095 count=1 | tr '\0' 'x')"
458         ln -s $LONGSYMLINK $DIR/$tdir/$tfile
459         ls -l $DIR/$tdir
460 }
461 run_test 17g "symlinks: really long symlink name ==============================="
462
463 test_17h() { #bug 17378
464         remote_mds_nodsh && skip "remote MDS with nodsh" && return
465         mkdir -p $DIR/$tdir
466         $SETSTRIPE -c -1 $DIR/$tdir
467 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
468         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000141
469         touch $DIR/$tdir/$tfile || true
470 }
471 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
472
473 test_17i() { #bug 20018
474         remote_mds_nodsh && skip "remote MDS with nodsh" && return
475         mkdir -p $DIR/$tdir
476         local foo=$DIR/$tdir/$tfile
477         ln -s $foo $foo || error "create symlink failed"
478 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
479         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000143
480         ls -l $foo && error "error not detected"
481         return 0
482 }
483 run_test 17i "don't panic on short symlink"
484
485 test_17k() { #bug 22301
486         rsync --help | grep -q xattr ||
487                 skip_env "$(rsync --version| head -1) does not support xattrs"
488         mkdir -p $DIR/{$tdir,$tdir.new}
489         touch $DIR/$tdir/$tfile
490         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
491         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
492                 error "rsync failed with xattrs enabled"
493 }
494 run_test 17k "symlinks: rsync with xattrs enabled ========================="
495
496 test_18() {
497         touch $DIR/f
498         ls $DIR || error
499 }
500 run_test 18 "touch .../f ; ls ... =============================="
501
502 test_19a() {
503         touch $DIR/f19
504         ls -l $DIR
505         rm $DIR/f19
506         $CHECKSTAT -a $DIR/f19 || error
507 }
508 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
509
510 test_19b() {
511         ls -l $DIR/f19 && error || true
512 }
513 run_test 19b "ls -l .../f19 (should return error) =============="
514
515 test_19c() {
516         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
517         $RUNAS touch $DIR/f19 && error || true
518 }
519 run_test 19c "$RUNAS touch .../f19 (should return error) =="
520
521 test_19d() {
522         cat $DIR/f19 && error || true
523 }
524 run_test 19d "cat .../f19 (should return error) =============="
525
526 test_20() {
527         touch $DIR/f
528         rm $DIR/f
529         log "1 done"
530         touch $DIR/f
531         rm $DIR/f
532         log "2 done"
533         touch $DIR/f
534         rm $DIR/f
535         log "3 done"
536         $CHECKSTAT -a $DIR/f || error
537 }
538 run_test 20 "touch .../f ; ls -l ... ==========================="
539
540 test_21() {
541         mkdir $DIR/d21
542         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
543         ln -s dangle $DIR/d21/link
544         echo foo >> $DIR/d21/link
545         cat $DIR/d21/dangle
546         $CHECKSTAT -t link $DIR/d21/link || error
547         $CHECKSTAT -f -t file $DIR/d21/link || error
548 }
549 run_test 21 "write to dangling link ============================"
550
551 test_22() {
552         WDIR=$DIR/$tdir
553         mkdir -p $WDIR
554         chown $RUNAS_ID:$RUNAS_GID $WDIR
555         (cd $WDIR || error "cd $WDIR failed";
556         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
557         $RUNAS tar xf -)
558         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
559         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
560         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
561 }
562 run_test 22 "unpack tar archive as non-root user ==============="
563
564 # was test_23
565 test_23a() {
566         mkdir -p $DIR/$tdir
567         local file=$DIR/$tdir/$tfile
568
569         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
570         openfile -f O_CREAT:O_EXCL $file &&
571                 error "$file recreate succeeded" || true
572 }
573 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
574
575 test_23b() { # bug 18988
576         mkdir -p $DIR/$tdir
577         local file=$DIR/$tdir/$tfile
578
579         rm -f $file
580         echo foo > $file || error "write filed"
581         echo bar >> $file || error "append filed"
582         $CHECKSTAT -s 8 $file || error "wrong size"
583         rm $file
584 }
585 run_test 23b "O_APPEND check =========================="
586
587 test_24a() {
588         echo '== rename sanity =============================================='
589         echo '-- same directory rename'
590         mkdir $DIR/R1
591         touch $DIR/R1/f
592         mv $DIR/R1/f $DIR/R1/g
593         $CHECKSTAT -t file $DIR/R1/g || error
594 }
595 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
596
597 test_24b() {
598         mkdir $DIR/R2
599         touch $DIR/R2/{f,g}
600         mv $DIR/R2/f $DIR/R2/g
601         $CHECKSTAT -a $DIR/R2/f || error
602         $CHECKSTAT -t file $DIR/R2/g || error
603 }
604 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
605
606 test_24c() {
607         mkdir $DIR/R3
608         mkdir $DIR/R3/f
609         mv $DIR/R3/f $DIR/R3/g
610         $CHECKSTAT -a $DIR/R3/f || error
611         $CHECKSTAT -t dir $DIR/R3/g || error
612 }
613 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
614
615 test_24d() {
616         mkdir $DIR/R4
617         mkdir $DIR/R4/{f,g}
618         mrename $DIR/R4/f $DIR/R4/g
619         $CHECKSTAT -a $DIR/R4/f || error
620         $CHECKSTAT -t dir $DIR/R4/g || error
621 }
622 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
623
624 test_24e() {
625         echo '-- cross directory renames --'
626         mkdir $DIR/R5{a,b}
627         touch $DIR/R5a/f
628         mv $DIR/R5a/f $DIR/R5b/g
629         $CHECKSTAT -a $DIR/R5a/f || error
630         $CHECKSTAT -t file $DIR/R5b/g || error
631 }
632 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
633
634 test_24f() {
635         mkdir $DIR/R6{a,b}
636         touch $DIR/R6a/f $DIR/R6b/g
637         mv $DIR/R6a/f $DIR/R6b/g
638         $CHECKSTAT -a $DIR/R6a/f || error
639         $CHECKSTAT -t file $DIR/R6b/g || error
640 }
641 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
642
643 test_24g() {
644         mkdir $DIR/R7{a,b}
645         mkdir $DIR/R7a/d
646         mv $DIR/R7a/d $DIR/R7b/e
647         $CHECKSTAT -a $DIR/R7a/d || error
648         $CHECKSTAT -t dir $DIR/R7b/e || error
649 }
650 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
651
652 test_24h() {
653         mkdir $DIR/R8{a,b}
654         mkdir $DIR/R8a/d $DIR/R8b/e
655         mrename $DIR/R8a/d $DIR/R8b/e
656         $CHECKSTAT -a $DIR/R8a/d || error
657         $CHECKSTAT -t dir $DIR/R8b/e || error
658 }
659 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
660
661 test_24i() {
662         echo "-- rename error cases"
663         mkdir $DIR/R9
664         mkdir $DIR/R9/a
665         touch $DIR/R9/f
666         mrename $DIR/R9/f $DIR/R9/a
667         $CHECKSTAT -t file $DIR/R9/f || error
668         $CHECKSTAT -t dir  $DIR/R9/a || error
669         $CHECKSTAT -a $DIR/R9/a/f || error
670 }
671 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
672
673 test_24j() {
674         mkdir $DIR/R10
675         mrename $DIR/R10/f $DIR/R10/g
676         $CHECKSTAT -t dir $DIR/R10 || error
677         $CHECKSTAT -a $DIR/R10/f || error
678         $CHECKSTAT -a $DIR/R10/g || error
679 }
680 run_test 24j "source does not exist ============================"
681
682 test_24k() {
683         mkdir $DIR/R11a $DIR/R11a/d
684         touch $DIR/R11a/f
685         mv $DIR/R11a/f $DIR/R11a/d
686         $CHECKSTAT -a $DIR/R11a/f || error
687         $CHECKSTAT -t file $DIR/R11a/d/f || error
688 }
689 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
690
691 # bug 2429 - rename foo foo foo creates invalid file
692 test_24l() {
693         f="$DIR/f24l"
694         multiop $f OcNs || error
695 }
696 run_test 24l "Renaming a file to itself ========================"
697
698 test_24m() {
699         f="$DIR/f24m"
700         multiop $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
701         # on ext3 this does not remove either the source or target files
702         # though the "expected" operation would be to remove the source
703         $CHECKSTAT -t file ${f} || error "${f} missing"
704         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
705 }
706 run_test 24m "Renaming a file to a hard link to itself ========="
707
708 test_24n() {
709     f="$DIR/f24n"
710     # this stats the old file after it was renamed, so it should fail
711     touch ${f}
712     $CHECKSTAT ${f}
713     mv ${f} ${f}.rename
714     $CHECKSTAT ${f}.rename
715     $CHECKSTAT -a ${f}
716 }
717 run_test 24n "Statting the old file after renaming (Posix rename 2)"
718
719 test_24o() {
720         check_kernel_version 37 || return 0
721         mkdir -p $DIR/d24o
722         rename_many -s random -v -n 10 $DIR/d24o
723 }
724 run_test 24o "rename of files during htree split ==============="
725
726 test_24p() {
727         mkdir $DIR/R12{a,b}
728         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
729         mrename $DIR/R12a $DIR/R12b
730         $CHECKSTAT -a $DIR/R12a || error
731         $CHECKSTAT -t dir $DIR/R12b || error
732         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
733         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
734 }
735 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
736
737 test_24q() {
738         mkdir $DIR/R13{a,b}
739         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
740         multiop_bg_pause $DIR/R13b D_c || return 1
741         MULTIPID=$!
742
743         mrename $DIR/R13a $DIR/R13b
744         $CHECKSTAT -a $DIR/R13a || error
745         $CHECKSTAT -t dir $DIR/R13b || error
746         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
747         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
748         kill -USR1 $MULTIPID
749         wait $MULTIPID || error "multiop close failed"
750 }
751 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
752
753 test_24r() { #bug 3789
754         mkdir $DIR/R14a $DIR/R14a/b
755         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
756         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
757         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
758 }
759 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
760
761 test_24s() {
762         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
763         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
764         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
765         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
766 }
767 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
768 test_24t() {
769         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
770         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
771         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
772         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
773 }
774 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
775
776 test_24u() { # bug12192
777         multiop $DIR/$tfile C2w$((2048 * 1024))c || error
778         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
779 }
780 run_test 24u "create stripe file"
781
782 page_size() {
783         getconf PAGE_SIZE
784 }
785
786 test_24v() {
787         local NRFILES=100000
788         local FREE_INODES=`lfs df -i|grep "filesystem summary" | awk '{print $5}'`
789         [ $FREE_INODES -lt $NRFILES ] && \
790                 skip "not enough free inodes $FREE_INODES required $NRFILES" && \
791                 return
792
793         mkdir -p $DIR/d24v
794         createmany -m $DIR/d24v/$tfile $NRFILES
795
796         cancel_lru_locks mdc
797         lctl set_param mdc.*.stats clear
798
799         ls $DIR/d24v >/dev/null || error "error in listing large dir"
800
801         # LU-5 large readdir
802         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
803         #               8 bytes for name(filename is mostly 5 in this test) +
804         #               8 bytes for luda_type
805         # take into account of overhead in lu_dirpage header and end mark in
806         # each page, plus one in RPC_NUM calculation.
807         DIRENT_SIZE=48
808         RPC_SIZE=$(($(lctl get_param -n mdc.*.max_pages_per_rpc)*$(page_size)))
809         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
810         mds_readpage=`lctl get_param mdc.*.stats | \
811                                 awk '/^mds_readpage/ {print $2}'`
812         [ $mds_readpage -gt $RPC_NUM ] && \
813                 error "large readdir doesn't take effect"
814
815         rm $DIR/d24v -rf
816 }
817 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
818
819 test_24w() { # bug21506
820         SZ1=234852
821         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
822         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
823         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
824         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
825         [ "$SZ1" = "$SZ2" ] || \
826                 error "Error reading at the end of the file $tfile"
827 }
828 run_test 24w "Reading a file larger than 4Gb"
829
830 test_25a() {
831         echo '== symlink sanity ============================================='
832
833         mkdir $DIR/d25
834         ln -s d25 $DIR/s25
835         touch $DIR/s25/foo || error
836 }
837 run_test 25a "create file in symlinked directory ==============="
838
839 test_25b() {
840         [ ! -d $DIR/d25 ] && test_25a
841         $CHECKSTAT -t file $DIR/s25/foo || error
842 }
843 run_test 25b "lookup file in symlinked directory ==============="
844
845 test_26a() {
846         mkdir $DIR/d26
847         mkdir $DIR/d26/d26-2
848         ln -s d26/d26-2 $DIR/s26
849         touch $DIR/s26/foo || error
850 }
851 run_test 26a "multiple component symlink ======================="
852
853 test_26b() {
854         mkdir -p $DIR/d26b/d26-2
855         ln -s d26b/d26-2/foo $DIR/s26-2
856         touch $DIR/s26-2 || error
857 }
858 run_test 26b "multiple component symlink at end of lookup ======"
859
860 test_26c() {
861         mkdir $DIR/d26.2
862         touch $DIR/d26.2/foo
863         ln -s d26.2 $DIR/s26.2-1
864         ln -s s26.2-1 $DIR/s26.2-2
865         ln -s s26.2-2 $DIR/s26.2-3
866         chmod 0666 $DIR/s26.2-3/foo
867 }
868 run_test 26c "chain of symlinks ================================"
869
870 # recursive symlinks (bug 439)
871 test_26d() {
872         ln -s d26-3/foo $DIR/d26-3
873 }
874 run_test 26d "create multiple component recursive symlink ======"
875
876 test_26e() {
877         [ ! -h $DIR/d26-3 ] && test_26d
878         rm $DIR/d26-3
879 }
880 run_test 26e "unlink multiple component recursive symlink ======"
881
882 # recursive symlinks (bug 7022)
883 test_26f() {
884         mkdir -p $DIR/$tdir
885         mkdir $DIR/$tdir/$tfile        || error "mkdir $DIR/$tdir/$tfile failed"
886         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
887         mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
888         mkdir $tfile             || error "mkdir $tfile failed"
889         cd $tfile                || error "cd $tfile failed"
890         ln -s .. dotdot          || error "ln dotdot failed"
891         ln -s dotdot/lndir lndir || error "ln lndir failed"
892         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
893         output=`ls $tfile/$tfile/lndir/bar1`
894         [ "$output" = bar1 ] && error "unexpected output"
895         rm -r $tfile             || error "rm $tfile failed"
896         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
897 }
898 run_test 26f "rm -r of a directory which has recursive symlink ="
899
900 test_27a() {
901         echo '== stripe sanity =============================================='
902         mkdir -p $DIR/d27 || error "mkdir failed"
903         $GETSTRIPE $DIR/d27
904         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
905         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
906         pass
907         log "== test_27a: write to one stripe file ========================="
908         cp /etc/hosts $DIR/d27/f0 || error
909 }
910 run_test 27a "one stripe file =================================="
911
912 test_27b() {
913         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
914         mkdir -p $DIR/d27
915         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
916         $GETSTRIPE -c $DIR/d27/f01
917         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
918                 error "two-stripe file doesn't have two stripes"
919 }
920 run_test 27b "create two stripe file"
921
922 test_27c() {
923         [ -f $DIR/d27/f01 ] || skip "test_27b not run" && return
924
925         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
926 }
927 run_test 27c "write to two stripe file"
928
929 test_27d() {
930         mkdir -p $DIR/d27
931         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
932         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
933         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
934 }
935 run_test 27d "create file with default settings ================"
936
937 test_27e() {
938         mkdir -p $DIR/d27
939         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
940         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
941         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
942 }
943 run_test 27e "setstripe existing file (should return error) ======"
944
945 test_27f() {
946         mkdir -p $DIR/d27
947         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
948         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
949         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
950 }
951 run_test 27f "setstripe with bad stripe size (should return error)"
952
953 test_27g() {
954         mkdir -p $DIR/d27
955         $MCREATE $DIR/d27/fnone || error "mcreate failed"
956         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
957                 error "$DIR/d27/fnone has object"
958 }
959 run_test 27g "$GETSTRIPE with no objects"
960
961 test_27i() {
962         touch $DIR/d27/fsome || error "touch failed"
963         [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
964 }
965 run_test 27i "$GETSTRIPE with some objects"
966
967 test_27j() {
968         mkdir -p $DIR/d27
969         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
970 }
971 run_test 27j "setstripe with bad stripe offset (should return error)"
972
973 test_27k() { # bug 2844
974         mkdir -p $DIR/d27
975         FILE=$DIR/d27/f27k
976         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
977         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
978         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
979         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
980         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
981         dd if=/dev/zero of=$FILE bs=4k count=1
982         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
983         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
984 }
985 run_test 27k "limit i_blksize for broken user apps ============="
986
987 test_27l() {
988         mkdir -p $DIR/d27
989         mcreate $DIR/f27l || error "creating file"
990         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
991                 error "setstripe should have failed" || true
992 }
993 run_test 27l "check setstripe permissions (should return error)"
994
995 test_27m() {
996         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
997         if [ $ORIGFREE -gt $MAXFREE ]; then
998                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
999                 return
1000         fi
1001         mkdir -p $DIR/d27
1002         $SETSTRIPE -i 0 -c 1 $DIR/d27/f27m_1
1003         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE &&
1004                 error "dd should fill OST0"
1005         i=2
1006         while $SETSTRIPE -i 0 -c 1 $DIR/d27/f27m_$i; do
1007                 i=`expr $i + 1`
1008                 [ $i -gt 256 ] && break
1009         done
1010         i=`expr $i + 1`
1011         touch $DIR/d27/f27m_$i
1012         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
1013                 error "OST0 was full but new created file still use it"
1014         i=`expr $i + 1`
1015         touch $DIR/d27/f27m_$i
1016         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
1017                 error "OST0 was full but new created file still use it"
1018         rm -r $DIR/d27
1019         sleep 15
1020 }
1021 run_test 27m "create file while OST0 was full =================="
1022
1023 sleep_maxage() {
1024         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1025         sleep $DELAY
1026 }
1027
1028 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1029 # if the OST isn't full anymore.
1030 reset_enospc() {
1031         local OSTIDX=${1:-""}
1032
1033         local list=$(comma_list $(osts_nodes))
1034         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1035
1036         do_nodes $list lctl set_param fail_loc=0
1037         sleep_maxage
1038 }
1039
1040 exhaust_precreations() {
1041         local OSTIDX=$1
1042         local FAILLOC=$2
1043         local FAILIDX=${3:-$OSTIDX}
1044
1045         mkdir -p $DIR/$tdir
1046         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1047         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1048
1049         local OST=$(ostname_from_index $OSTIDX)
1050         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1051                           sed -e 's/_UUID$//;s/^.*-//')
1052
1053         # on the mdt's osc
1054         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1055         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1056         osc.$mdtosc_proc1.prealloc_last_id)
1057         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1058         osc.$mdtosc_proc1.prealloc_next_id)
1059
1060         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1061         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1062
1063         mkdir -p $DIR/$tdir/${OST}
1064         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1065 #define OBD_FAIL_OST_ENOSPC              0x215
1066         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1067         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1068         echo "Creating to objid $last_id on ost $OST..."
1069         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1070         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1071         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1072         sleep_maxage
1073 }
1074
1075 exhaust_all_precreations() {
1076         local i
1077         for (( i=0; i < OSTCOUNT; i++ )) ; do
1078                 exhaust_precreations $i $1 -1
1079         done
1080 }
1081
1082 test_27n() {
1083         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1084         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1085         remote_ost_nodsh && skip "remote OST with nodsh" && return
1086
1087         reset_enospc
1088         rm -f $DIR/$tdir/$tfile
1089         exhaust_precreations 0 0x80000215
1090         $SETSTRIPE -c -1 $DIR/$tdir
1091         touch $DIR/$tdir/$tfile || error
1092         $GETSTRIPE $DIR/$tdir/$tfile
1093         reset_enospc
1094 }
1095 run_test 27n "create file with some full OSTs =================="
1096
1097 test_27o() {
1098         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1099         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1100         remote_ost_nodsh && skip "remote OST with nodsh" && return
1101
1102         reset_enospc
1103         rm -f $DIR/$tdir/$tfile
1104         exhaust_all_precreations 0x215
1105
1106         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1107
1108         reset_enospc
1109         rm -rf $DIR/$tdir/*
1110 }
1111 run_test 27o "create file with all full OSTs (should error) ===="
1112
1113 test_27p() {
1114         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1115         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1116         remote_ost_nodsh && skip "remote OST with nodsh" && return
1117
1118         reset_enospc
1119         rm -f $DIR/$tdir/$tfile
1120         mkdir -p $DIR/$tdir
1121
1122         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1123         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1124         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1125
1126         exhaust_precreations 0 0x80000215
1127         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1128         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1129         $GETSTRIPE $DIR/$tdir/$tfile
1130
1131         reset_enospc
1132 }
1133 run_test 27p "append to a truncated file with some full OSTs ==="
1134
1135 test_27q() {
1136         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1137         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1138         remote_ost_nodsh && skip "remote OST with nodsh" && return
1139
1140         reset_enospc
1141         rm -f $DIR/$tdir/$tfile
1142
1143         mkdir -p $DIR/$tdir
1144         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1145         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1146         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1147
1148         exhaust_all_precreations 0x215
1149
1150         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1151         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1152
1153         reset_enospc
1154 }
1155 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1156
1157 test_27r() {
1158         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1159         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1160         remote_ost_nodsh && skip "remote OST with nodsh" && return
1161
1162         reset_enospc
1163         rm -f $DIR/$tdir/$tfile
1164         exhaust_precreations 0 0x80000215
1165
1166         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1167
1168         reset_enospc
1169 }
1170 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1171
1172 test_27s() { # bug 10725
1173         mkdir -p $DIR/$tdir
1174         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1175         local stripe_count=0
1176         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1177         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1178                 error "stripe width >= 2^32 succeeded" || true
1179
1180 }
1181 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1182
1183 test_27t() { # bug 10864
1184         WDIR=`pwd`
1185         WLFS=`which lfs`
1186         cd $DIR
1187         touch $tfile
1188         $WLFS getstripe $tfile
1189         cd $WDIR
1190 }
1191 run_test 27t "check that utils parse path correctly"
1192
1193 test_27u() { # bug 4900
1194         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1195         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1196
1197 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1198         do_facet $SINGLEMDS lctl set_param fail_loc=0x139
1199         mkdir -p $DIR/$tdir
1200         createmany -o $DIR/$tdir/t- 1000
1201         do_facet $SINGLEMDS lctl set_param fail_loc=0
1202
1203         TLOG=$DIR/$tfile.getstripe
1204         $GETSTRIPE $DIR/$tdir > $TLOG
1205         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1206         unlinkmany $DIR/$tdir/t- 1000
1207         [ $OBJS -gt 0 ] && \
1208                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1209 }
1210 run_test 27u "skip object creation on OSC w/o objects =========="
1211
1212 test_27v() { # bug 4900
1213         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1214         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1215         remote_ost_nodsh && skip "remote OST with nodsh" && return
1216
1217         exhaust_all_precreations 0x215
1218         reset_enospc
1219
1220         mkdir -p $DIR/$tdir
1221         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1222
1223         touch $DIR/$tdir/$tfile
1224         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1225         # all except ost1
1226         for (( i=1; i < OSTCOUNT; i++ )); do
1227                 do_facet ost$i lctl set_param fail_loc=0x705
1228         done
1229         local START=`date +%s`
1230         createmany -o $DIR/$tdir/$tfile 32
1231
1232         local FINISH=`date +%s`
1233         local TIMEOUT=`lctl get_param -n timeout`
1234         local PROCESS=$((FINISH - START))
1235         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1236                error "$FINISH - $START >= $TIMEOUT / 2"
1237         sleep $((TIMEOUT / 2 - PROCESS))
1238         reset_enospc
1239 }
1240 run_test 27v "skip object creation on slow OST ================="
1241
1242 test_27w() { # bug 10997
1243         mkdir -p $DIR/$tdir || error "mkdir failed"
1244         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1245         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1246                 error "stripe size $size != 65536" || true
1247         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1248                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1249 }
1250 run_test 27w "check $SETSTRIPE -S option"
1251
1252 test_27wa() {
1253         [ "$OSTCOUNT" -lt "2" ] &&
1254                 skip_env "skipping multiple stripe count/offset test" && return
1255
1256         mkdir -p $DIR/$tdir || error "mkdir failed"
1257         for i in $(seq 1 $OSTCOUNT); do
1258                 offset=$((i - 1))
1259                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1260                         error "setstripe -c $i -i $offset failed"
1261                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1262                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1263                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1264                 [ $index -ne $offset ] &&
1265                         error "stripe offset $index != $offset" || true
1266         done
1267 }
1268 run_test 27wa "check $SETSTRIPE -c -i options"
1269
1270 test_27x() {
1271         remote_ost_nodsh && skip "remote OST with nodsh" && return
1272         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1273         OFFSET=$(($OSTCOUNT - 1))
1274         OSTIDX=0
1275         local OST=$(ostname_from_index $OSTIDX)
1276
1277         mkdir -p $DIR/$tdir
1278         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1279         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1280         sleep_maxage
1281         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1282         for i in `seq 0 $OFFSET`; do
1283                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1284                 error "OST0 was degraded but new created file still use it"
1285         done
1286         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1287 }
1288 run_test 27x "create files while OST0 is degraded"
1289
1290 test_27y() {
1291         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1292         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1293         remote_ost_nodsh && skip "remote OST with nodsh" && return
1294
1295         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1296         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1297             osc.$mdtosc.prealloc_last_id)
1298         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1299             osc.$mdtosc.prealloc_next_id)
1300         local fcount=$((last_id - next_id))
1301         [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1302         [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1303
1304         MDS_OSCS=`do_facet $SINGLEMDS lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
1305         OFFSET=$(($OSTCOUNT-1))
1306         OST=-1
1307         for OSC in $MDS_OSCS; do
1308                 if [ $OST == -1 ]; then {
1309                         OST=`osc_to_ost $OSC`
1310                 } else {
1311                         echo $OSC "is Deactivate:"
1312                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1313                 } fi
1314         done
1315
1316         OSTIDX=$(index_from_ostuuid $OST)
1317         mkdir -p $DIR/$tdir
1318         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1319
1320         do_facet ost$((OSTIDX+1)) lctl set_param -n obdfilter.$OST.degraded 1
1321         sleep_maxage
1322         createmany -o $DIR/$tdir/$tfile $fcount
1323         do_facet ost$((OSTIDX+1)) lctl set_param -n obdfilter.$OST.degraded 0
1324
1325         for i in `seq 0 $OFFSET`; do
1326                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "$OSTIDX"` ] || \
1327                       error "files created on deactivated OSTs instead of degraded OST"
1328         done
1329         for OSC in $MDS_OSCS; do
1330                 [ `osc_to_ost $OSC` != $OST  ] && {
1331                         echo $OSC "is activate"
1332                         do_facet $SINGLEMDS lctl --device %$OSC activate
1333                 }
1334         done
1335 }
1336 run_test 27y "create files while OST0 is degraded and the rest inactive"
1337
1338 check_seq_oid()
1339 {
1340         log "check file $1"
1341
1342         lmm_count=$($GETSTRIPE -c $1)
1343         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1344         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1345
1346         local old_ifs="$IFS"
1347         IFS=$'[:]'
1348         fid=($($LFS path2fid $1))
1349         IFS="$old_ifs"
1350
1351         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1352         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1353
1354         # compare lmm_seq and lu_fid->f_seq
1355         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1356         # compare lmm_object_id and lu_fid->oid
1357         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1358
1359         [ "$FSTYPE" != "ldiskfs" ] &&
1360                 skip "cannot check filter fid FSTYPE=$FSTYPE" && return 0
1361
1362         # check the trusted.fid attribute of the OST objects of the file
1363         local have_obdidx=false
1364         local stripe_nr=0
1365         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1366                 # skip lines up to and including "obdidx"
1367                 [ -z "$obdidx" ] && break
1368                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1369                 $have_obdidx || continue
1370
1371                 local ost=$((obdidx + 1))
1372                 local dev=$(ostdevname $ost)
1373
1374                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1375
1376                 #don't unmount/remount the OSTs if we don't need to do that
1377                 #local dir=$(facet_mntpt ost$ost)
1378                 #stop ost$dev
1379                 #do_facet ost$dev mount -t $FSTYPE $dev $dir $OST_MOUNT_OPTS ||
1380                 #       { error "mounting $dev as $FSTYPE failed"; return 3; }
1381                 #local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid)
1382                 #local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
1383
1384                 local obj_file="O/$seq/d$((oid %32))/$oid"
1385                 local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1386                            $dev 2>/dev/null" | grep "parent=")
1387
1388                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1389
1390                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1391
1392                 #do_facet ost$ost umount -d $dir
1393                 #start ost$ost $dev $OST_MOUNT_OPTS
1394
1395                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1396                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1397                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1398                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1399                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1400                 local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1401
1402                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1403                 [ $ff_pseq = $lmm_seq ] ||
1404                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1405                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1406                 [ $ff_poid = $lmm_oid ] ||
1407                         error "FF parent OID $ff_poid != $lmm_oid"
1408                 [ $ff_pstripe = $stripe_nr ] ||
1409                         error "FF stripe $ff_pstripe != $stripe_nr"
1410
1411                 stripe_nr=$((stripe_nr + 1))
1412         done
1413 }
1414
1415 test_27z() {
1416         remote_ost_nodsh && skip "remote OST with nodsh" && return
1417         mkdir -p $DIR/$tdir
1418
1419         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1420                 { error "setstripe -c -1 failed"; return 1; }
1421         # We need to send a write to every object to get parent FID info set.
1422         # This _should_ also work for setattr, but does not currently.
1423         # touch $DIR/$tdir/$tfile-1 ||
1424         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1425                 { error "dd $tfile-1 failed"; return 2; }
1426         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1427                 { error "setstripe -c -1 failed"; return 3; }
1428         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1429                 { error "dd $tfile-2 failed"; return 4; }
1430
1431         # make sure write RPCs have been sent to OSTs
1432         sync; sleep 5; sync
1433
1434         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1435         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1436 }
1437 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1438
1439 test_27A() { # b=19102
1440         local restore_size=$($GETSTRIPE -S $MOUNT)
1441         local restore_count=$($GETSTRIPE -c $MOUNT)
1442         local restore_offset=$($GETSTRIPE -i $MOUNT)
1443         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1444         local default_size=$($GETSTRIPE -S $MOUNT)
1445         local default_count=$($GETSTRIPE -c $MOUNT)
1446         local default_offset=$($GETSTRIPE -i $MOUNT)
1447         local dsize=$((1024 * 1024))
1448         [ $default_size -eq $dsize ] ||
1449                 error "stripe size $default_size != $dsize"
1450         [ $default_count -eq 1 ] || error "stripe count $default_count != 1"
1451         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1452         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1453 }
1454 run_test 27A "check filesystem-wide default LOV EA values"
1455
1456 # createtest also checks that device nodes are created and
1457 # then visible correctly (#2091)
1458 test_28() { # bug 2091
1459         mkdir $DIR/d28
1460         $CREATETEST $DIR/d28/ct || error
1461 }
1462 run_test 28 "create/mknod/mkdir with bad file types ============"
1463
1464 test_29() {
1465         cancel_lru_locks mdc
1466         mkdir $DIR/d29
1467         touch $DIR/d29/foo
1468         log 'first d29'
1469         ls -l $DIR/d29
1470
1471         declare -i LOCKCOUNTORIG=0
1472         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1473                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1474         done
1475         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1476
1477         declare -i LOCKUNUSEDCOUNTORIG=0
1478         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1479                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1480         done
1481
1482         log 'second d29'
1483         ls -l $DIR/d29
1484         log 'done'
1485
1486         declare -i LOCKCOUNTCURRENT=0
1487         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1488                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1489         done
1490
1491         declare -i LOCKUNUSEDCOUNTCURRENT=0
1492         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1493                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1494         done
1495
1496         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1497                 lctl set_param -n ldlm.dump_namespaces ""
1498                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1499                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1500                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1501                 return 2
1502         fi
1503         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1504                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1505                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1506                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1507                 return 3
1508         fi
1509 }
1510 run_test 29 "IT_GETATTR regression  ============================"
1511
1512 test_30a() { # was test_30
1513         cp `which ls` $DIR || cp /bin/ls $DIR
1514         $DIR/ls / || error
1515         rm $DIR/ls
1516 }
1517 run_test 30a "execute binary from Lustre (execve) =============="
1518
1519 test_30b() {
1520         cp `which ls` $DIR || cp /bin/ls $DIR
1521         chmod go+rx $DIR/ls
1522         $RUNAS $DIR/ls / || error
1523         rm $DIR/ls
1524 }
1525 run_test 30b "execute binary from Lustre as non-root ==========="
1526
1527 test_30c() { # b=22376
1528         cp `which ls` $DIR || cp /bin/ls $DIR
1529         chmod a-rw $DIR/ls
1530         cancel_lru_locks mdc
1531         cancel_lru_locks osc
1532         $RUNAS $DIR/ls / || error
1533         rm -f $DIR/ls
1534 }
1535 run_test 30c "execute binary from Lustre without read perms ===="
1536
1537 test_31a() {
1538         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1539         $CHECKSTAT -a $DIR/f31 || error
1540 }
1541 run_test 31a "open-unlink file =================================="
1542
1543 test_31b() {
1544         touch $DIR/f31 || error
1545         ln $DIR/f31 $DIR/f31b || error
1546         multiop $DIR/f31b Ouc || error
1547         $CHECKSTAT -t file $DIR/f31 || error
1548 }
1549 run_test 31b "unlink file with multiple links while open ======="
1550
1551 test_31c() {
1552         touch $DIR/f31 || error
1553         ln $DIR/f31 $DIR/f31c || error
1554         multiop_bg_pause $DIR/f31 O_uc || return 1
1555         MULTIPID=$!
1556         multiop $DIR/f31c Ouc
1557         kill -USR1 $MULTIPID
1558         wait $MULTIPID
1559 }
1560 run_test 31c "open-unlink file with multiple links ============="
1561
1562 test_31d() {
1563         opendirunlink $DIR/d31d $DIR/d31d || error
1564         $CHECKSTAT -a $DIR/d31d || error
1565 }
1566 run_test 31d "remove of open directory ========================="
1567
1568 test_31e() { # bug 2904
1569         check_kernel_version 34 || return 0
1570         openfilleddirunlink $DIR/d31e || error
1571 }
1572 run_test 31e "remove of open non-empty directory ==============="
1573
1574 test_31f() { # bug 4554
1575         set -vx
1576         mkdir $DIR/d31f
1577         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1578         cp /etc/hosts $DIR/d31f
1579         ls -l $DIR/d31f
1580         $GETSTRIPE $DIR/d31f/hosts
1581         multiop_bg_pause $DIR/d31f D_c || return 1
1582         MULTIPID=$!
1583
1584         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1585         mkdir $DIR/d31f
1586         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1587         cp /etc/hosts $DIR/d31f
1588         ls -l $DIR/d31f
1589         $GETSTRIPE $DIR/d31f/hosts
1590         multiop_bg_pause $DIR/d31f D_c || return 1
1591         MULTIPID2=$!
1592
1593         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1594         wait $MULTIPID || error "first opendir $MULTIPID failed"
1595
1596         sleep 6
1597
1598         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1599         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1600         set +vx
1601 }
1602 run_test 31f "remove of open directory with open-unlink file ==="
1603
1604 test_31g() {
1605         echo "-- cross directory link --"
1606         mkdir $DIR/d31g{a,b}
1607         touch $DIR/d31ga/f
1608         ln $DIR/d31ga/f $DIR/d31gb/g
1609         $CHECKSTAT -t file $DIR/d31ga/f || error "source"
1610         [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
1611         $CHECKSTAT -t file $DIR/d31gb/g || error "target"
1612         [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
1613 }
1614 run_test 31g "cross directory link==============="
1615
1616 test_31h() {
1617         echo "-- cross directory link --"
1618         mkdir $DIR/d31h
1619         mkdir $DIR/d31h/dir
1620         touch $DIR/d31h/f
1621         ln $DIR/d31h/f $DIR/d31h/dir/g
1622         $CHECKSTAT -t file $DIR/d31h/f || error "source"
1623         [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
1624         $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
1625         [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
1626 }
1627 run_test 31h "cross directory link under child==============="
1628
1629 test_31i() {
1630         echo "-- cross directory link --"
1631         mkdir $DIR/d31i
1632         mkdir $DIR/d31i/dir
1633         touch $DIR/d31i/dir/f
1634         ln $DIR/d31i/dir/f $DIR/d31i/g
1635         $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
1636         [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
1637         $CHECKSTAT -t file $DIR/d31i/g || error "target"
1638         [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
1639 }
1640 run_test 31i "cross directory link under parent==============="
1641
1642
1643 test_31j() {
1644         mkdir $DIR/d31j
1645         mkdir $DIR/d31j/dir1
1646         ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
1647         link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
1648         mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
1649         mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
1650         return 0
1651 }
1652 run_test 31j "link for directory==============="
1653
1654
1655 test_31k() {
1656         mkdir $DIR/d31k
1657         touch $DIR/d31k/s
1658         touch $DIR/d31k/exist
1659         mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
1660         mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
1661         mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
1662         mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
1663         mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
1664         mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
1665         mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
1666         return 0
1667 }
1668 run_test 31k "link to file: the same, non-existing, dir==============="
1669
1670 test_31m() {
1671         mkdir $DIR/d31m
1672         touch $DIR/d31m/s
1673         mkdir $DIR/d31m2
1674         touch $DIR/d31m2/exist
1675         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
1676         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
1677         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
1678         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
1679         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
1680         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
1681         return 0
1682 }
1683 run_test 31m "link to file: the same, non-existing, dir==============="
1684
1685 test_32a() {
1686         echo "== more mountpoints and symlinks ================="
1687         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1688         mkdir -p $DIR/d32a/ext2-mountpoint
1689         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1690         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error
1691         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1692 }
1693 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1694
1695 test_32b() {
1696         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1697         mkdir -p $DIR/d32b/ext2-mountpoint
1698         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1699         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1700         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1701 }
1702 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1703
1704 test_32c() {
1705         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1706         mkdir -p $DIR/d32c/ext2-mountpoint
1707         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1708         mkdir -p $DIR/d32c/d2/test_dir
1709         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1710         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1711 }
1712 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1713
1714 test_32d() {
1715         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1716         mkdir -p $DIR/d32d/ext2-mountpoint
1717         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1718         mkdir -p $DIR/d32d/d2/test_dir
1719         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1720         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1721 }
1722 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1723
1724 test_32e() {
1725         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1726         mkdir -p $DIR/d32e/tmp
1727         TMP_DIR=$DIR/d32e/tmp
1728         ln -s $DIR/d32e $TMP_DIR/symlink11
1729         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1730         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1731         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1732 }
1733 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1734
1735 test_32f() {
1736         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1737         mkdir -p $DIR/d32f/tmp
1738         TMP_DIR=$DIR/d32f/tmp
1739         ln -s $DIR/d32f $TMP_DIR/symlink11
1740         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1741         ls $DIR/d32f/tmp/symlink11  || error
1742         ls $DIR/d32f/symlink01 || error
1743 }
1744 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1745
1746 test_32g() {
1747         TMP_DIR=$DIR/$tdir/tmp
1748         mkdir -p $TMP_DIR $DIR/${tdir}2
1749         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1750         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1751         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1752         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1753         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1754         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1755 }
1756 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1757
1758 test_32h() {
1759         rm -fr $DIR/$tdir $DIR/${tdir}2
1760         TMP_DIR=$DIR/$tdir/tmp
1761         mkdir -p $TMP_DIR $DIR/${tdir}2
1762         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1763         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1764         ls $TMP_DIR/symlink12 || error
1765         ls $DIR/$tdir/symlink02  || error
1766 }
1767 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1768
1769 test_32i() {
1770         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1771         mkdir -p $DIR/d32i/ext2-mountpoint
1772         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1773         touch $DIR/d32i/test_file
1774         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error
1775         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1776 }
1777 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1778
1779 test_32j() {
1780         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1781         mkdir -p $DIR/d32j/ext2-mountpoint
1782         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1783         touch $DIR/d32j/test_file
1784         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1785         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1786 }
1787 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1788
1789 test_32k() {
1790         rm -fr $DIR/d32k
1791         mkdir -p $DIR/d32k/ext2-mountpoint
1792         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint
1793         mkdir -p $DIR/d32k/d2
1794         touch $DIR/d32k/d2/test_file || error
1795         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1796         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1797 }
1798 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1799
1800 test_32l() {
1801         rm -fr $DIR/d32l
1802         mkdir -p $DIR/d32l/ext2-mountpoint
1803         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1804         mkdir -p $DIR/d32l/d2
1805         touch $DIR/d32l/d2/test_file
1806         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1807         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1808 }
1809 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1810
1811 test_32m() {
1812         rm -fr $DIR/d32m
1813         mkdir -p $DIR/d32m/tmp
1814         TMP_DIR=$DIR/d32m/tmp
1815         ln -s $DIR $TMP_DIR/symlink11
1816         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1817         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1818         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1819 }
1820 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1821
1822 test_32n() {
1823         rm -fr $DIR/d32n
1824         mkdir -p $DIR/d32n/tmp
1825         TMP_DIR=$DIR/d32n/tmp
1826         ln -s $DIR $TMP_DIR/symlink11
1827         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1828         ls -l $DIR/d32n/tmp/symlink11  || error
1829         ls -l $DIR/d32n/symlink01 || error
1830 }
1831 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1832
1833 test_32o() {
1834         rm -fr $DIR/d32o $DIR/$tfile
1835         touch $DIR/$tfile
1836         mkdir -p $DIR/d32o/tmp
1837         TMP_DIR=$DIR/d32o/tmp
1838         ln -s $DIR/$tfile $TMP_DIR/symlink12
1839         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1840         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1841         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1842         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1843         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1844 }
1845 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1846
1847 test_32p() {
1848     log 32p_1
1849         rm -fr $DIR/d32p
1850     log 32p_2
1851         rm -f $DIR/$tfile
1852     log 32p_3
1853         touch $DIR/$tfile
1854     log 32p_4
1855         mkdir -p $DIR/d32p/tmp
1856     log 32p_5
1857         TMP_DIR=$DIR/d32p/tmp
1858     log 32p_6
1859         ln -s $DIR/$tfile $TMP_DIR/symlink12
1860     log 32p_7
1861         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1862     log 32p_8
1863         cat $DIR/d32p/tmp/symlink12 || error
1864     log 32p_9
1865         cat $DIR/d32p/symlink02 || error
1866     log 32p_10
1867 }
1868 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1869
1870 test_32q() {
1871         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1872         mkdir -p $DIR/d32q
1873         touch $DIR/d32q/under_the_mount
1874         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1875         ls $DIR/d32q/under_the_mount && error || true
1876         $UMOUNT $DIR/d32q || error
1877 }
1878 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1879
1880 test_32r() {
1881         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1882         mkdir -p $DIR/d32r
1883         touch $DIR/d32r/under_the_mount
1884         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1885         ls $DIR/d32r | grep -q under_the_mount && error || true
1886         $UMOUNT $DIR/d32r || error
1887 }
1888 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1889
1890 test_33() {
1891         rm -f $DIR/$tfile
1892         touch $DIR/$tfile
1893         chmod 444 $DIR/$tfile
1894         chown $RUNAS_ID $DIR/$tfile
1895         log 33_1
1896         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1897         log 33_2
1898 }
1899 run_test 33 "write file with mode 444 (should return error) ===="
1900
1901 test_33a() {
1902         rm -fr $DIR/d33
1903         mkdir -p $DIR/d33
1904         chown $RUNAS_ID $DIR/d33
1905         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1906         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1907                 error "open RDWR" || true
1908 }
1909 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1910
1911 test_33b() {
1912         rm -fr $DIR/d33
1913         mkdir -p $DIR/d33
1914         chown $RUNAS_ID $DIR/d33
1915         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
1916 }
1917 run_test 33b "test open file with malformed flags (No panic and return error)"
1918
1919 test_33c() {
1920         local ostnum
1921         local ostname
1922         local write_bytes
1923         local all_zeros
1924
1925         remote_ost_nodsh && skip "remote OST with nodsh" && return
1926         all_zeros=:
1927         rm -fr $DIR/d33
1928         mkdir -p $DIR/d33
1929         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
1930
1931         sync
1932         for ostnum in $(seq $OSTCOUNT); do
1933                 # test-framework's OST numbering is one-based, while Lustre's
1934                 # is zero-based
1935                 ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
1936                 # Parsing llobdstat's output sucks; we could grep the /proc
1937                 # path, but that's likely to not be as portable as using the
1938                 # llobdstat utility.  So we parse lctl output instead.
1939                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
1940                         obdfilter/$ostname/stats |
1941                         awk '/^write_bytes/ {print $7}' )
1942                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
1943                 if (( ${write_bytes:-0} > 0 ))
1944                 then
1945                         all_zeros=false
1946                         break;
1947                 fi
1948         done
1949
1950         $all_zeros || return 0
1951
1952         # Write four bytes
1953         echo foo > $DIR/d33/bar
1954         # Really write them
1955         sync
1956
1957         # Total up write_bytes after writing.  We'd better find non-zeros.
1958         for ostnum in $(seq $OSTCOUNT); do
1959                 ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
1960                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
1961                         obdfilter/$ostname/stats |
1962                         awk '/^write_bytes/ {print $7}' )
1963                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
1964                 if (( ${write_bytes:-0} > 0 ))
1965                 then
1966                         all_zeros=false
1967                         break;
1968                 fi
1969         done
1970
1971         if $all_zeros
1972         then
1973                 for ostnum in $(seq $OSTCOUNT); do
1974                         ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
1975                         echo "Check that write_bytes is present in obdfilter/*/stats:"
1976                         do_facet ost$ostnum lctl get_param -n \
1977                                 obdfilter/$ostname/stats
1978                 done
1979                 error "OST not keeping write_bytes stats (b22312)"
1980         fi
1981 }
1982 run_test 33c "test llobdstat and write_bytes"
1983
1984 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1985 test_34a() {
1986         rm -f $DIR/f34
1987         $MCREATE $DIR/f34 || error
1988         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1989         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1990         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1991         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1992 }
1993 run_test 34a "truncate file that has not been opened ==========="
1994
1995 test_34b() {
1996         [ ! -f $DIR/f34 ] && test_34a
1997         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1998         $OPENFILE -f O_RDONLY $DIR/f34
1999         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2000         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2001 }
2002 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2003
2004 test_34c() {
2005         [ ! -f $DIR/f34 ] && test_34a
2006         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2007         $OPENFILE -f O_RDWR $DIR/f34
2008         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2009         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2010 }
2011 run_test 34c "O_RDWR opening file-with-size works =============="
2012
2013 test_34d() {
2014         [ ! -f $DIR/f34 ] && test_34a
2015         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2016         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2017         rm $DIR/f34
2018 }
2019 run_test 34d "write to sparse file ============================="
2020
2021 test_34e() {
2022         rm -f $DIR/f34e
2023         $MCREATE $DIR/f34e || error
2024         $TRUNCATE $DIR/f34e 1000 || error
2025         $CHECKSTAT -s 1000 $DIR/f34e || error
2026         $OPENFILE -f O_RDWR $DIR/f34e
2027         $CHECKSTAT -s 1000 $DIR/f34e || error
2028 }
2029 run_test 34e "create objects, some with size and some without =="
2030
2031 test_34f() { # bug 6242, 6243
2032         SIZE34F=48000
2033         rm -f $DIR/f34f
2034         $MCREATE $DIR/f34f || error
2035         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2036         dd if=$DIR/f34f of=$TMP/f34f
2037         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2038         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2039         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2040         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2041         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2042 }
2043 run_test 34f "read from a file with no objects until EOF ======="
2044
2045 test_34g() {
2046         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2047         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2048         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2049         cancel_lru_locks osc
2050         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2051                 error "wrong size after lock cancel"
2052
2053         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2054         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2055                 error "expanding truncate failed"
2056         cancel_lru_locks osc
2057         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2058                 error "wrong expanded size after lock cancel"
2059 }
2060 run_test 34g "truncate long file ==============================="
2061
2062 test_34h() {
2063         local gid=10
2064         local sz=1000
2065
2066         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2067         multiop $DIR/$tfile OG${gid}T${sz}g${gid}c &
2068         MULTIPID=$!
2069         sleep 2
2070
2071         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2072                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2073                 kill -9 $MULTIPID
2074         fi
2075         wait $MULTIPID
2076         local nsz=`stat -c %s $DIR/$tfile`
2077         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2078 }
2079 run_test 34h "ftruncate file under grouplock should not block"
2080
2081 test_35a() {
2082         cp /bin/sh $DIR/f35a
2083         chmod 444 $DIR/f35a
2084         chown $RUNAS_ID $DIR/f35a
2085         $RUNAS $DIR/f35a && error || true
2086         rm $DIR/f35a
2087 }
2088 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2089
2090 test_36a() {
2091         rm -f $DIR/f36
2092         utime $DIR/f36 || error
2093 }
2094 run_test 36a "MDS utime check (mknod, utime) ==================="
2095
2096 test_36b() {
2097         echo "" > $DIR/f36
2098         utime $DIR/f36 || error
2099 }
2100 run_test 36b "OST utime check (open, utime) ===================="
2101
2102 test_36c() {
2103         rm -f $DIR/d36/f36
2104         mkdir $DIR/d36
2105         chown $RUNAS_ID $DIR/d36
2106         $RUNAS utime $DIR/d36/f36 || error
2107 }
2108 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2109
2110 test_36d() {
2111         [ ! -d $DIR/d36 ] && test_36c
2112         echo "" > $DIR/d36/f36
2113         $RUNAS utime $DIR/d36/f36 || error
2114 }
2115 run_test 36d "non-root OST utime check (open, utime) ==========="
2116
2117 test_36e() {
2118         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2119         mkdir -p $DIR/$tdir
2120         touch $DIR/$tdir/$tfile
2121         $RUNAS utime $DIR/$tdir/$tfile && \
2122                 error "utime worked, expected failure" || true
2123 }
2124 run_test 36e "utime on non-owned file (should return error) ===="
2125
2126 subr_36fh() {
2127         local fl="$1"
2128         local LANG_SAVE=$LANG
2129         local LC_LANG_SAVE=$LC_LANG
2130         export LANG=C LC_LANG=C # for date language
2131
2132         DATESTR="Dec 20  2000"
2133         mkdir -p $DIR/$tdir
2134         lctl set_param fail_loc=$fl
2135         date; date +%s
2136         cp /etc/hosts $DIR/$tdir/$tfile
2137         sync & # write RPC generated with "current" inode timestamp, but delayed
2138         sleep 1
2139         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2140         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2141         cancel_lru_locks osc
2142         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2143         date; date +%s
2144         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2145                 echo "BEFORE: $LS_BEFORE" && \
2146                 echo "AFTER : $LS_AFTER" && \
2147                 echo "WANT  : $DATESTR" && \
2148                 error "$DIR/$tdir/$tfile timestamps changed" || true
2149
2150         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2151 }
2152
2153 test_36f() {
2154         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2155         subr_36fh "0x80000214"
2156 }
2157 run_test 36f "utime on file racing with OST BRW write =========="
2158
2159 test_36g() {
2160         remote_ost_nodsh && skip "remote OST with nodsh" && return
2161         local fmd_max_age
2162         local fmd_before
2163         local fmd_after
2164
2165         mkdir -p $DIR/$tdir
2166         fmd_max_age=$(do_facet ost1 \
2167                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2168                 head -n 1")
2169
2170         fmd_before=$(do_facet ost1 \
2171                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2172         touch $DIR/$tdir/$tfile
2173         sleep $((fmd_max_age + 12))
2174         fmd_after=$(do_facet ost1 \
2175                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2176
2177         echo "fmd_before: $fmd_before"
2178         echo "fmd_after: $fmd_after"
2179         [ "$fmd_after" -gt "$fmd_before" ] && \
2180                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2181                 error "fmd didn't expire after ping" || true
2182 }
2183 run_test 36g "filter mod data cache expiry ====================="
2184
2185 test_36h() {
2186         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2187         subr_36fh "0x80000227"
2188 }
2189 run_test 36h "utime on file racing with OST BRW write =========="
2190
2191 test_37() {
2192         mkdir -p $DIR/$tdir
2193         echo f > $DIR/$tdir/fbugfile
2194         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2195         ls $DIR/$tdir | grep "\<fbugfile\>" && error
2196         $UMOUNT $DIR/$tdir || error
2197         rm -f $DIR/$tdir/fbugfile || error
2198 }
2199 run_test 37 "ls a mounted file system to check old content ====="
2200
2201 test_38() {
2202         local file=$DIR/$tfile
2203         touch $file
2204         openfile -f O_DIRECTORY $file
2205         local RC=$?
2206         local ENOTDIR=20
2207         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2208         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2209 }
2210 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2211
2212 test_39() {
2213         touch $DIR/$tfile
2214         touch $DIR/${tfile}2
2215 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2216 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2217 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2218         sleep 2
2219         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2220         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2221                 echo "mtime"
2222                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2223                 echo "atime"
2224                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2225                 echo "ctime"
2226                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2227                 error "O_TRUNC didn't change timestamps"
2228         fi
2229 }
2230 run_test 39 "mtime changed on create ==========================="
2231
2232 test_39b() {
2233         mkdir -p $DIR/$tdir
2234         cp -p /etc/passwd $DIR/$tdir/fopen
2235         cp -p /etc/passwd $DIR/$tdir/flink
2236         cp -p /etc/passwd $DIR/$tdir/funlink
2237         cp -p /etc/passwd $DIR/$tdir/frename
2238         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2239
2240         sleep 1
2241         echo "aaaaaa" >> $DIR/$tdir/fopen
2242         echo "aaaaaa" >> $DIR/$tdir/flink
2243         echo "aaaaaa" >> $DIR/$tdir/funlink
2244         echo "aaaaaa" >> $DIR/$tdir/frename
2245
2246         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2247         local link_new=`stat -c %Y $DIR/$tdir/flink`
2248         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2249         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2250
2251         cat $DIR/$tdir/fopen > /dev/null
2252         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2253         rm -f $DIR/$tdir/funlink2
2254         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2255
2256         for (( i=0; i < 2; i++ )) ; do
2257                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2258                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2259                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2260                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2261
2262                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2263                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2264                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2265                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2266
2267                 cancel_lru_locks osc
2268                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2269         done
2270 }
2271 run_test 39b "mtime change on open, link, unlink, rename  ======"
2272
2273 # this should be set to past
2274 TEST_39_MTIME=`date -d "1 year ago" +%s`
2275
2276 # bug 11063
2277 test_39c() {
2278         touch $DIR1/$tfile
2279         sleep 2
2280         local mtime0=`stat -c %Y $DIR1/$tfile`
2281
2282         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2283         local mtime1=`stat -c %Y $DIR1/$tfile`
2284         [ "$mtime1" = $TEST_39_MTIME ] || \
2285                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2286
2287         local d1=`date +%s`
2288         echo hello >> $DIR1/$tfile
2289         local d2=`date +%s`
2290         local mtime2=`stat -c %Y $DIR1/$tfile`
2291         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2292                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2293
2294         mv $DIR1/$tfile $DIR1/$tfile-1
2295
2296         for (( i=0; i < 2; i++ )) ; do
2297                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2298                 [ "$mtime2" = "$mtime3" ] || \
2299                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2300
2301                 cancel_lru_locks osc
2302                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2303         done
2304 }
2305 run_test 39c "mtime change on rename ==========================="
2306
2307 # bug 21114
2308 test_39d() {
2309         touch $DIR1/$tfile
2310
2311         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2312
2313         for (( i=0; i < 2; i++ )) ; do
2314                 local mtime=`stat -c %Y $DIR1/$tfile`
2315                 [ $mtime = $TEST_39_MTIME ] || \
2316                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2317
2318                 cancel_lru_locks osc
2319                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2320         done
2321 }
2322 run_test 39d "create, utime, stat =============================="
2323
2324 # bug 21114
2325 test_39e() {
2326         touch $DIR1/$tfile
2327         local mtime1=`stat -c %Y $DIR1/$tfile`
2328
2329         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2330
2331         for (( i=0; i < 2; i++ )) ; do
2332                 local mtime2=`stat -c %Y $DIR1/$tfile`
2333                 [ $mtime2 = $TEST_39_MTIME ] || \
2334                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2335
2336                 cancel_lru_locks osc
2337                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2338         done
2339 }
2340 run_test 39e "create, stat, utime, stat ========================"
2341
2342 # bug 21114
2343 test_39f() {
2344         touch $DIR1/$tfile
2345         mtime1=`stat -c %Y $DIR1/$tfile`
2346
2347         sleep 2
2348         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2349
2350         for (( i=0; i < 2; i++ )) ; do
2351                 local mtime2=`stat -c %Y $DIR1/$tfile`
2352                 [ $mtime2 = $TEST_39_MTIME ] || \
2353                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2354
2355                 cancel_lru_locks osc
2356                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2357         done
2358 }
2359 run_test 39f "create, stat, sleep, utime, stat ================="
2360
2361 # bug 11063
2362 test_39g() {
2363         echo hello >> $DIR1/$tfile
2364         local mtime1=`stat -c %Y $DIR1/$tfile`
2365
2366         sleep 2
2367         chmod o+r $DIR1/$tfile
2368
2369         for (( i=0; i < 2; i++ )) ; do
2370                 local mtime2=`stat -c %Y $DIR1/$tfile`
2371                 [ "$mtime1" = "$mtime2" ] || \
2372                         error "lost mtime: $mtime2, should be $mtime1"
2373
2374                 cancel_lru_locks osc
2375                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2376         done
2377 }
2378 run_test 39g "write, chmod, stat ==============================="
2379
2380 # bug 11063
2381 test_39h() {
2382         touch $DIR1/$tfile
2383         sleep 1
2384
2385         local d1=`date`
2386         echo hello >> $DIR1/$tfile
2387         local mtime1=`stat -c %Y $DIR1/$tfile`
2388
2389         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2390         local d2=`date`
2391         if [ "$d1" != "$d2" ]; then
2392                 echo "write and touch not within one second"
2393         else
2394                 for (( i=0; i < 2; i++ )) ; do
2395                         local mtime2=`stat -c %Y $DIR1/$tfile`
2396                         [ "$mtime2" = $TEST_39_MTIME ] || \
2397                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2398
2399                         cancel_lru_locks osc
2400                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2401                 done
2402         fi
2403 }
2404 run_test 39h "write, utime within one second, stat ============="
2405
2406 test_39i() {
2407         touch $DIR1/$tfile
2408         sleep 1
2409
2410         echo hello >> $DIR1/$tfile
2411         local mtime1=`stat -c %Y $DIR1/$tfile`
2412
2413         mv $DIR1/$tfile $DIR1/$tfile-1
2414
2415         for (( i=0; i < 2; i++ )) ; do
2416                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2417
2418                 [ "$mtime1" = "$mtime2" ] || \
2419                         error "lost mtime: $mtime2, should be $mtime1"
2420
2421                 cancel_lru_locks osc
2422                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2423         done
2424 }
2425 run_test 39i "write, rename, stat =============================="
2426
2427 test_39j() {
2428         debugsave
2429         lctl set_param debug=-1
2430         touch $DIR1/$tfile
2431         sleep 1
2432
2433         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
2434         local multipid=$!
2435         local mtime1=`stat -c %Y $DIR1/$tfile`
2436
2437         mv $DIR1/$tfile $DIR1/$tfile-1
2438
2439         kill -USR1 $multipid
2440         wait $multipid || error "multiop close failed"
2441
2442         for (( i=0; i < 2; i++ )) ; do
2443                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2444                 [ "$mtime1" = "$mtime2" ] || \
2445                         error "mtime is lost on close: $mtime2, should be $mtime1"
2446
2447                 cancel_lru_locks osc
2448                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2449         done
2450         debugrestore
2451 }
2452 run_test 39j "write, rename, close, stat ======================="
2453
2454 test_39k() {
2455         touch $DIR1/$tfile
2456         sleep 1
2457
2458         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
2459         local multipid=$!
2460         local mtime1=`stat -c %Y $DIR1/$tfile`
2461
2462         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2463
2464         kill -USR1 $multipid
2465         wait $multipid || error "multiop close failed"
2466
2467         for (( i=0; i < 2; i++ )) ; do
2468                 local mtime2=`stat -c %Y $DIR1/$tfile`
2469
2470                 [ "$mtime2" = $TEST_39_MTIME ] || \
2471                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
2472
2473                 cancel_lru_locks osc
2474                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2475         done
2476 }
2477 run_test 39k "write, utime, close, stat ========================"
2478
2479 # this should be set to future
2480 TEST_39_ATIME=`date -d "1 year" +%s`
2481
2482 test_39l() {
2483         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2484         local atime_diff=$(do_facet $SINGLEMDS lctl get_param -n mdd.*.atime_diff)
2485
2486         mkdir -p $DIR/$tdir
2487
2488         # test setting directory atime to future
2489         touch -a -d @$TEST_39_ATIME $DIR/$tdir
2490         local atime=$(stat -c %X $DIR/$tdir)
2491         [ "$atime" = $TEST_39_ATIME ] || \
2492                 error "atime is not set to future: $atime, should be $TEST_39_ATIME"
2493
2494         # test setting directory atime from future to now
2495         local d1=$(date +%s)
2496         ls $DIR/$tdir
2497         local d2=$(date +%s)
2498
2499         cancel_lru_locks mdc
2500         atime=$(stat -c %X $DIR/$tdir)
2501         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2502                 error "atime is not updated from future: $atime, should be $d1<atime<$d2"
2503
2504         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=2
2505         sleep 3
2506
2507         # test setting directory atime when now > dir atime + atime_diff
2508         d1=$(date +%s)
2509         ls $DIR/$tdir
2510         d2=$(date +%s)
2511         cancel_lru_locks mdc
2512         atime=$(stat -c %X $DIR/$tdir)
2513         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2514                 error "atime is not updated  : $atime, should be $d2"
2515
2516         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=60
2517         sleep 3
2518
2519         # test not setting directory atime when now < dir atime + atime_diff
2520         ls $DIR/$tdir
2521         cancel_lru_locks mdc
2522         atime=$(stat -c %X $DIR/$tdir)
2523         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2524                 error "atime is updated to $atime, should remain $d1<atime<$d2"
2525
2526         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=$atime_diff
2527 }
2528 run_test 39l "directory atime update ==========================="
2529
2530 test_39m() {
2531         touch $DIR1/$tfile
2532         sleep 2
2533         local far_past_mtime=$(date -d "May 29 1953" +%s)
2534         local far_past_atime=$(date -d "Dec 17 1903" +%s)
2535
2536         touch -m -d @$far_past_mtime $DIR1/$tfile
2537         touch -a -d @$far_past_atime $DIR1/$tfile
2538
2539         for (( i=0; i < 2; i++ )) ; do
2540                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
2541                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
2542                         error "atime or mtime set incorrectly"
2543
2544                 cancel_lru_locks osc
2545                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2546         done
2547 }
2548 run_test 39m "test atime and mtime before 1970"
2549
2550 test_40() {
2551         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
2552         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
2553         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
2554 }
2555 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
2556
2557 test_41() {
2558         # bug 1553
2559         small_write $DIR/f41 18
2560 }
2561 run_test 41 "test small file write + fstat ====================="
2562
2563 count_ost_writes() {
2564         lctl get_param -n osc.*.stats |
2565             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
2566 }
2567
2568 # decent default
2569 WRITEBACK_SAVE=500
2570 DIRTY_RATIO_SAVE=40
2571 MAX_DIRTY_RATIO=50
2572 BG_DIRTY_RATIO_SAVE=10
2573 MAX_BG_DIRTY_RATIO=25
2574
2575 start_writeback() {
2576         trap 0
2577         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
2578         # dirty_ratio, dirty_background_ratio
2579         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
2580                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
2581                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
2582                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
2583         else
2584                 # if file not here, we are a 2.4 kernel
2585                 kill -CONT `pidof kupdated`
2586         fi
2587 }
2588
2589 stop_writeback() {
2590         # setup the trap first, so someone cannot exit the test at the
2591         # exact wrong time and mess up a machine
2592         trap start_writeback EXIT
2593         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
2594         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
2595                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
2596                 sysctl -w vm.dirty_writeback_centisecs=0
2597                 sysctl -w vm.dirty_writeback_centisecs=0
2598                 # save and increase /proc/sys/vm/dirty_ratio
2599                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
2600                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
2601                 # save and increase /proc/sys/vm/dirty_background_ratio
2602                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
2603                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
2604         else
2605                 # if file not here, we are a 2.4 kernel
2606                 kill -STOP `pidof kupdated`
2607         fi
2608 }
2609
2610 # ensure that all stripes have some grant before we test client-side cache
2611 setup_test42() {
2612         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
2613                 dd if=/dev/zero of=$i bs=4k count=1
2614                 rm $i
2615         done
2616 }
2617
2618 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
2619 # file truncation, and file removal.
2620 test_42a() {
2621         setup_test42
2622         cancel_lru_locks osc
2623         stop_writeback
2624         sync; sleep 1; sync # just to be safe
2625         BEFOREWRITES=`count_ost_writes`
2626         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
2627         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
2628         AFTERWRITES=`count_ost_writes`
2629         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
2630                 error "$BEFOREWRITES < $AFTERWRITES"
2631         start_writeback
2632 }
2633 run_test 42a "ensure that we don't flush on close =============="
2634
2635 test_42b() {
2636         setup_test42
2637         cancel_lru_locks osc
2638         stop_writeback
2639         sync
2640         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
2641         BEFOREWRITES=`count_ost_writes`
2642         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
2643         AFTERWRITES=`count_ost_writes`
2644         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
2645                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
2646         fi
2647         BEFOREWRITES=`count_ost_writes`
2648         sync || error "sync: $?"
2649         AFTERWRITES=`count_ost_writes`
2650         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
2651                 error "$BEFOREWRITES < $AFTERWRITES on sync"
2652         fi
2653         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
2654         start_writeback
2655         return 0
2656 }
2657 run_test 42b "test destroy of file with cached dirty data ======"
2658
2659 # if these tests just want to test the effect of truncation,
2660 # they have to be very careful.  consider:
2661 # - the first open gets a {0,EOF}PR lock
2662 # - the first write conflicts and gets a {0, count-1}PW
2663 # - the rest of the writes are under {count,EOF}PW
2664 # - the open for truncate tries to match a {0,EOF}PR
2665 #   for the filesize and cancels the PWs.
2666 # any number of fixes (don't get {0,EOF} on open, match
2667 # composite locks, do smarter file size management) fix
2668 # this, but for now we want these tests to verify that
2669 # the cancellation with truncate intent works, so we
2670 # start the file with a full-file pw lock to match against
2671 # until the truncate.
2672 trunc_test() {
2673         test=$1
2674         file=$DIR/$test
2675         offset=$2
2676         cancel_lru_locks osc
2677         stop_writeback
2678         # prime the file with 0,EOF PW to match
2679         touch $file
2680         $TRUNCATE $file 0
2681         sync; sync
2682         # now the real test..
2683         dd if=/dev/zero of=$file bs=1024 count=100
2684         BEFOREWRITES=`count_ost_writes`
2685         $TRUNCATE $file $offset
2686         cancel_lru_locks osc
2687         AFTERWRITES=`count_ost_writes`
2688         start_writeback
2689 }
2690
2691 test_42c() {
2692         trunc_test 42c 1024
2693         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
2694             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
2695         rm $file
2696 }
2697 run_test 42c "test partial truncate of file with cached dirty data"
2698
2699 test_42d() {
2700         trunc_test 42d 0
2701         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
2702             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
2703         rm $file
2704 }
2705 run_test 42d "test complete truncate of file with cached dirty data"
2706
2707 test_42e() { # bug22074
2708         local TDIR=$DIR/${tdir}e
2709         local pagesz=$(page_size)
2710         local pages=16 # hardcoded 16 pages, don't change it.
2711         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
2712         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
2713         local max_dirty_mb
2714         local warmup_files
2715
2716         mkdir -p $TDIR
2717         $SETSTRIPE -c 1 $TDIR
2718         createmany -o $TDIR/f $files
2719
2720         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
2721
2722         # we assume that with $OSTCOUNT files, at least one of them will
2723         # be allocated on OST0.
2724         warmup_files=$((OSTCOUNT * max_dirty_mb))
2725         createmany -o $TDIR/w $warmup_files
2726
2727         # write a large amount of data into one file and sync, to get good
2728         # avail_grant number from OST.
2729         for ((i=0; i<$warmup_files; i++)); do
2730                 idx=$($GETSTRIPE -i $TDIR/w$i)
2731                 [ $idx -ne 0 ] && continue
2732                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
2733                 break
2734         done
2735         [ $i -gt $warmup_files ] && error "OST0 is still cold"
2736         sync
2737         $LCTL get_param $proc_osc0/cur_dirty_bytes
2738         $LCTL get_param $proc_osc0/cur_grant_bytes
2739
2740         # create as much dirty pages as we can while not to trigger the actual
2741         # RPCs directly. but depends on the env, VFS may trigger flush during this
2742         # period, hopefully we are good.
2743         for ((i=0; i<$warmup_files; i++)); do
2744                 idx=$($GETSTRIPE -i $TDIR/w$i)
2745                 [ $idx -ne 0 ] && continue
2746                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
2747         done
2748         $LCTL get_param $proc_osc0/cur_dirty_bytes
2749         $LCTL get_param $proc_osc0/cur_grant_bytes
2750
2751         # perform the real test
2752         $LCTL set_param $proc_osc0/rpc_stats 0
2753         for ((;i<$files; i++)); do
2754                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
2755                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
2756         done
2757         sync
2758         $LCTL get_param $proc_osc0/rpc_stats
2759
2760         local percent=0
2761         local have_ppr=false
2762         $LCTL get_param $proc_osc0/rpc_stats |
2763                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
2764                         # skip lines until we are at the RPC histogram data
2765                         [ "$PPR" == "pages" ] && have_ppr=true && continue
2766                         $have_ppr || continue
2767
2768                         # we only want the percent stat for < 16 pages
2769                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
2770
2771                         percent=$((percent + WPCT))
2772                         if [ $percent -gt 15 ]; then
2773                                 error "less than 16-pages write RPCs" \
2774                                       "$percent% > 15%"
2775                                 break
2776                         fi
2777                 done
2778         rm -rf $TDIR
2779 }
2780 run_test 42e "verify sub-RPC writes are not done synchronously"
2781
2782 test_43() {
2783         mkdir -p $DIR/$tdir
2784         cp -p /bin/ls $DIR/$tdir/$tfile
2785         multiop $DIR/$tdir/$tfile Ow_c &
2786         pid=$!
2787         # give multiop a chance to open
2788         sleep 1
2789
2790         $DIR/$tdir/$tfile && error || true
2791         kill -USR1 $pid
2792 }
2793 run_test 43 "execution of file opened for write should return -ETXTBSY"
2794
2795 test_43a() {
2796         mkdir -p $DIR/d43
2797         cp -p `which multiop` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2798         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2799         MULTIOP_PID=$!
2800         multiop $DIR/d43/multiop Oc && error "expected error, got success"
2801         kill -USR1 $MULTIOP_PID || return 2
2802         wait $MULTIOP_PID || return 3
2803         rm $TMP/test43.junk
2804 }
2805 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
2806
2807 test_43b() {
2808         mkdir -p $DIR/d43
2809         cp -p `which multiop` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2810         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2811         MULTIOP_PID=$!
2812         $TRUNCATE $DIR/d43/multiop 0 && error "expected error, got success"
2813         kill -USR1 $MULTIOP_PID || return 2
2814         wait $MULTIOP_PID || return 3
2815         rm $TMP/test43.junk
2816 }
2817 run_test 43b "truncate of file being executed should return -ETXTBSY"
2818
2819 test_43c() {
2820         local testdir="$DIR/d43c"
2821         mkdir -p $testdir
2822         cp $SHELL $testdir/
2823         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
2824                 ( cd $testdir && md5sum -c)
2825 }
2826 run_test 43c "md5sum of copy into lustre========================"
2827
2828 test_44() {
2829         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
2830         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
2831         dd if=$DIR/f1 bs=4k count=1 > /dev/null
2832 }
2833 run_test 44 "zero length read from a sparse stripe ============="
2834
2835 test_44a() {
2836     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
2837                          awk '{print $2}'`
2838     [ -z "$nstripe" ] && skip "can't get stripe info" && return
2839     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
2840     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
2841                       awk '{print $2}'`
2842     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
2843         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
2844     fi
2845
2846     OFFSETS="0 $((stride/2)) $((stride-1))"
2847     for offset in $OFFSETS ; do
2848       for i in `seq 0 $((nstripe-1))`; do
2849         local GLOBALOFFSETS=""
2850         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
2851         local myfn=$DIR/d44a-$size
2852         echo "--------writing $myfn at $size"
2853         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
2854         GLOBALOFFSETS="$GLOBALOFFSETS $size"
2855         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2856                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2857
2858         for j in `seq 0 $((nstripe-1))`; do
2859             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
2860             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
2861             GLOBALOFFSETS="$GLOBALOFFSETS $size"
2862         done
2863         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2864                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2865         rm -f $myfn
2866       done
2867     done
2868 }
2869 run_test 44a "test sparse pwrite ==============================="
2870
2871 dirty_osc_total() {
2872         tot=0
2873         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
2874                 tot=$(($tot + $d))
2875         done
2876         echo $tot
2877 }
2878 do_dirty_record() {
2879         before=`dirty_osc_total`
2880         echo executing "\"$*\""
2881         eval $*
2882         after=`dirty_osc_total`
2883         echo before $before, after $after
2884 }
2885 test_45() {
2886         f="$DIR/f45"
2887         # Obtain grants from OST if it supports it
2888         echo blah > ${f}_grant
2889         stop_writeback
2890         sync
2891         do_dirty_record "echo blah > $f"
2892         [ $before -eq $after ] && error "write wasn't cached"
2893         do_dirty_record "> $f"
2894         [ $before -gt $after ] || error "truncate didn't lower dirty count"
2895         do_dirty_record "echo blah > $f"
2896         [ $before -eq $after ] && error "write wasn't cached"
2897         do_dirty_record "sync"
2898         [ $before -gt $after ] || error "writeback didn't lower dirty count"
2899         do_dirty_record "echo blah > $f"
2900         [ $before -eq $after ] && error "write wasn't cached"
2901         do_dirty_record "cancel_lru_locks osc"
2902         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
2903         start_writeback
2904 }
2905 run_test 45 "osc io page accounting ============================"
2906
2907 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
2908 # test tickles a bug where re-dirtying a page was failing to be mapped to the
2909 # objects offset and an assert hit when an rpc was built with 1023's mapped
2910 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
2911 test_46() {
2912         f="$DIR/f46"
2913         stop_writeback
2914         sync
2915         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2916         sync
2917         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
2918         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2919         sync
2920         start_writeback
2921 }
2922 run_test 46 "dirtying a previously written page ================"
2923
2924 # test_47 is removed "Device nodes check" is moved to test_28
2925
2926 test_48a() { # bug 2399
2927         check_kernel_version 34 || return 0
2928         mkdir -p $DIR/d48a
2929         cd $DIR/d48a
2930         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
2931         mkdir $DIR/d48a || error "recreate directory failed"
2932         touch foo || error "'touch foo' failed after recreating cwd"
2933         mkdir bar || error "'mkdir foo' failed after recreating cwd"
2934         if check_kernel_version 44; then
2935                 touch .foo || error "'touch .foo' failed after recreating cwd"
2936                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
2937         fi
2938         ls . > /dev/null || error "'ls .' failed after recreating cwd"
2939         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2940         cd . || error "'cd .' failed after recreating cwd"
2941         mkdir . && error "'mkdir .' worked after recreating cwd"
2942         rmdir . && error "'rmdir .' worked after recreating cwd"
2943         ln -s . baz || error "'ln -s .' failed after recreating cwd"
2944         cd .. || error "'cd ..' failed after recreating cwd"
2945 }
2946 run_test 48a "Access renamed working dir (should return errors)="
2947
2948 test_48b() { # bug 2399
2949         check_kernel_version 34 || return 0
2950         mkdir -p $DIR/d48b
2951         cd $DIR/d48b
2952         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
2953         touch foo && error "'touch foo' worked after removing cwd"
2954         mkdir foo && error "'mkdir foo' worked after removing cwd"
2955         if check_kernel_version 44; then
2956                 touch .foo && error "'touch .foo' worked after removing cwd"
2957                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2958         fi
2959         ls . > /dev/null && error "'ls .' worked after removing cwd"
2960         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2961         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
2962         mkdir . && error "'mkdir .' worked after removing cwd"
2963         rmdir . && error "'rmdir .' worked after removing cwd"
2964         ln -s . foo && error "'ln -s .' worked after removing cwd"
2965         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
2966 }
2967 run_test 48b "Access removed working dir (should return errors)="
2968
2969 test_48c() { # bug 2350
2970         check_kernel_version 36 || return 0
2971         #lctl set_param debug=-1
2972         #set -vx
2973         mkdir -p $DIR/d48c/dir
2974         cd $DIR/d48c/dir
2975         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
2976         $TRACE touch foo && error "'touch foo' worked after removing cwd"
2977         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
2978         if check_kernel_version 44; then
2979                 touch .foo && error "'touch .foo' worked after removing cwd"
2980                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2981         fi
2982         $TRACE ls . && error "'ls .' worked after removing cwd"
2983         $TRACE ls .. || error "'ls ..' failed after removing cwd"
2984         is_patchless || ( $TRACE cd . && error "'cd .' worked after removing cwd" )
2985         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
2986         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
2987         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
2988         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2989 }
2990 run_test 48c "Access removed working subdir (should return errors)"
2991
2992 test_48d() { # bug 2350
2993         check_kernel_version 36 || return 0
2994         #lctl set_param debug=-1
2995         #set -vx
2996         mkdir -p $DIR/d48d/dir
2997         cd $DIR/d48d/dir
2998         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2999         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
3000         $TRACE touch foo && error "'touch foo' worked after removing parent"
3001         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
3002         if check_kernel_version 44; then
3003                 touch .foo && error "'touch .foo' worked after removing parent"
3004                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
3005         fi
3006         $TRACE ls . && error "'ls .' worked after removing parent"
3007         $TRACE ls .. && error "'ls ..' worked after removing parent"
3008         is_patchless || ( $TRACE cd . && error "'cd .' worked after recreate parent" )
3009         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
3010         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3011         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3012         is_patchless || ( $TRACE cd .. && error "'cd ..' worked after removing parent" || true )
3013 }
3014 run_test 48d "Access removed parent subdir (should return errors)"
3015
3016 test_48e() { # bug 4134
3017         check_kernel_version 41 || return 0
3018         #lctl set_param debug=-1
3019         #set -vx
3020         mkdir -p $DIR/d48e/dir
3021         cd $DIR/d48e/dir
3022         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
3023         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
3024         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
3025         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
3026         # On a buggy kernel addition of "touch foo" after cd .. will
3027         # produce kernel oops in lookup_hash_it
3028         touch ../foo && error "'cd ..' worked after recreate parent"
3029         cd $DIR
3030         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
3031 }
3032 run_test 48e "Access to recreated parent subdir (should return errors)"
3033
3034 test_50() {
3035         # bug 1485
3036         mkdir $DIR/d50
3037         cd $DIR/d50
3038         ls /proc/$$/cwd || error
3039 }
3040 run_test 50 "special situations: /proc symlinks  ==============="
3041
3042 test_51a() {    # was test_51
3043         # bug 1516 - create an empty entry right after ".." then split dir
3044         mkdir $DIR/d51
3045         touch $DIR/d51/foo
3046         $MCREATE $DIR/d51/bar
3047         rm $DIR/d51/foo
3048         createmany -m $DIR/d51/longfile 201
3049         FNUM=202
3050         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
3051                 $MCREATE $DIR/d51/longfile$FNUM
3052                 FNUM=$(($FNUM + 1))
3053                 echo -n "+"
3054         done
3055         echo
3056         ls -l $DIR/d51 > /dev/null || error
3057 }
3058 run_test 51a "special situations: split htree with empty entry =="
3059
3060 export NUMTEST=70000
3061 test_51b() {
3062         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3063         [ $NUMFREE -lt 21000 ] && \
3064                 skip "not enough free inodes ($NUMFREE)" && \
3065                 return
3066
3067         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
3068
3069         mkdir -p $DIR/d51b
3070         createmany -d $DIR/d51b/t- $NUMTEST
3071 }
3072 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
3073
3074 test_51ba() { # LU-993
3075         local BASE=$DIR/d51b
3076         # unlink all but 100 subdirectories, then check it still works
3077         local LEFT=100
3078         local DELETE=$((NUMTEST - LEFT))
3079
3080         ! [ -d "${BASE}/t-$DELETE" ] && skip "test_51b() not run" && return 0
3081
3082         # for ldiskfs the nlink count should be 1, but this is OSD specific
3083         # and so this is listed for informational purposes only
3084         log "nlink before: $(stat -c %h $BASE)"
3085         unlinkmany -d $BASE/t- $DELETE ||
3086                 error "unlink of first $DELETE subdirs failed"
3087
3088         log "nlink between: $(stat -c %h $BASE)"
3089         local FOUND=$(ls -l ${BASE} | wc -l)
3090         FOUND=$((FOUND - 1))  # trim the first line of ls output
3091         [ $FOUND -ne $LEFT ] &&
3092                 error "can't find subdirs: found only $FOUND/$LEFT"
3093
3094         unlinkmany -d $BASE/t- $DELETE $LEFT ||
3095                 error "unlink of second $LEFT subdirs failed"
3096         log "nlink after: $(stat -c %h $BASE)"
3097 }
3098 run_test 51ba "rmdir .../t-0 --- .../t-$NUMTEST"
3099
3100 test_51bb() {
3101         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3102
3103         local ndirs=${TEST51BB_NDIRS:-10}
3104         local nfiles=${TEST51BB_NFILES:-100}
3105
3106         local numfree=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3107
3108         [ $numfree -lt $(( ndirs * nfiles)) ] && \
3109                 nfiles=$(( numfree / ndirs - 10 ))
3110
3111         local dir=$DIR/d51bb
3112         mkdir -p $dir
3113         local savePOLICY=$(lctl get_param -n lmv.*.placement)
3114         lctl set_param -n lmv.*.placement=CHAR
3115
3116         lfs df -i $dir
3117         local IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3118         OLDUSED=($IUSED)
3119
3120         declare -a dirs
3121         for ((i=0; i < $ndirs; i++)); do
3122                 dirs[i]=$dir/$RANDOM
3123                 echo Creating directory ${dirs[i]}
3124                 mkdir -p ${dirs[i]}
3125                 ls $dir
3126                 echo Creating $nfiles in dir ${dirs[i]} ...
3127                 echo "createmany -o ${dirs[i]}/$tfile- $nfiles"
3128                 createmany -o ${dirs[i]}/$tfile- $nfiles
3129         done
3130         ls $dir
3131
3132         sleep 1
3133
3134         IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3135         NEWUSED=($IUSED)
3136
3137         local rc=0
3138         for ((i=0; i<${#NEWUSED[@]}; i++)); do
3139                 echo "mds $i: inodes count OLD ${OLDUSED[$i]} NEW ${NEWUSED[$i]}"
3140                 [ ${OLDUSED[$i]} -lt ${NEWUSED[$i]} ] || rc=$((rc + 1))
3141         done
3142
3143         lctl set_param -n lmv.*.placement=$savePOLICY
3144
3145         [ $rc -ne $MDSCOUNT ] || \
3146                 error "Objects/inodes are not distributed over all mds servers"
3147 }
3148 run_test 51bb "mkdir createmany CMD $MDSCOUNT  ===================="
3149
3150 test_51d() {
3151         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3152         mkdir -p $DIR/d51d
3153         createmany -o $DIR/d51d/t- 1000
3154         $GETSTRIPE $DIR/d51d > $TMP/files
3155         for N in `seq 0 $((OSTCOUNT - 1))`; do
3156             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3157             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3158             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3159         done
3160         unlinkmany $DIR/d51d/t- 1000
3161
3162         NLAST=0
3163         for N in `seq 1 $((OSTCOUNT - 1))`; do
3164             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3165                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3166             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3167                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3168
3169             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3170                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3171             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3172                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3173             NLAST=$N
3174         done
3175 }
3176 run_test 51d "check object distribution ===================="
3177
3178 test_52a() {
3179         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
3180         mkdir -p $DIR/d52a
3181         touch $DIR/d52a/foo
3182         chattr +a $DIR/d52a/foo || error "chattr +a failed"
3183         echo bar >> $DIR/d52a/foo || error "append bar failed"
3184         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
3185         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
3186         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
3187         echo foo >> $DIR/d52a/foo || error "append foo failed"
3188         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
3189         lsattr $DIR/d52a/foo | egrep -q "^-+a[-e]+ $DIR/d52a/foo" || error "lsattr"
3190         chattr -a $DIR/d52a/foo || error "chattr -a failed"
3191         cp -r $DIR/d52a /tmp/
3192         rm -fr $DIR/d52a || error "cleanup rm failed"
3193 }
3194 run_test 52a "append-only flag test (should return errors) ====="
3195
3196 test_52b() {
3197         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
3198         mkdir -p $DIR/d52b
3199         touch $DIR/d52b/foo
3200         chattr +i $DIR/d52b/foo || error "chattr +i failed"
3201         cat test > $DIR/d52b/foo && error "cat test worked"
3202         cp /etc/hosts $DIR/d52b/foo && error "cp worked"
3203         rm -f $DIR/d52b/foo 2>/dev/null && error "rm worked"
3204         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error  "link worked"
3205         echo foo >> $DIR/d52b/foo && error "echo worked"
3206         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error "rename worked"
3207         [ -f $DIR/d52b/foo ] || error
3208         [ -f $DIR/d52b/foo_ren ] && error
3209         lsattr $DIR/d52b/foo | egrep -q "^-+i[-e]+ $DIR/d52b/foo" || error "lsattr"
3210         chattr -i $DIR/d52b/foo || error "chattr failed"
3211
3212         rm -fr $DIR/d52b || error
3213 }
3214 run_test 52b "immutable flag test (should return errors) ======="
3215
3216 test_53() {
3217         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3218         remote_ost_nodsh && skip "remote OST with nodsh" && return
3219
3220         local param
3221         local ostname
3222         local mds_last
3223         local ost_last
3224         local ostnum
3225
3226         # only test MDT0000
3227         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3228         for value in $(do_facet $SINGLEMDS lctl get_param osc.$mdtosc.prealloc_last_id) ; do
3229                 param=`echo ${value[0]} | cut -d "=" -f1`
3230                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
3231                 mds_last=$(do_facet $SINGLEMDS lctl get_param -n $param)
3232                 ostnum=$(echo $ostname | sed "s/${FSNAME}-OST//g" | awk '{print ($1+1)}' )
3233                 ost_last=$(do_facet ost$ostnum lctl get_param -n obdfilter.$ostname.last_id | head -n 1)
3234                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3235                 if [ $ost_last != $mds_last ]; then
3236                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3237                 fi
3238         done
3239 }
3240 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
3241
3242 test_54a() {
3243         [ ! -f "$SOCKETSERVER" ] && skip_env "no socketserver, skipping" && return
3244         [ ! -f "$SOCKETCLIENT" ] && skip_env "no socketclient, skipping" && return
3245         $SOCKETSERVER $DIR/socket
3246         $SOCKETCLIENT $DIR/socket || error
3247         $MUNLINK $DIR/socket
3248 }
3249 run_test 54a "unix domain socket test =========================="
3250
3251 test_54b() {
3252         f="$DIR/f54b"
3253         mknod $f c 1 3
3254         chmod 0666 $f
3255         dd if=/dev/zero of=$f bs=`page_size` count=1
3256 }
3257 run_test 54b "char device works in lustre ======================"
3258
3259 find_loop_dev() {
3260         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
3261         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
3262         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
3263
3264         for i in `seq 3 7`; do
3265                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
3266                 LOOPDEV=$LOOPBASE$i
3267                 LOOPNUM=$i
3268                 break
3269         done
3270 }
3271
3272 test_54c() {
3273         tfile="$DIR/f54c"
3274         tdir="$DIR/d54c"
3275         loopdev="$DIR/loop54c"
3276
3277         find_loop_dev
3278         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
3279         mknod $loopdev b 7 $LOOPNUM
3280         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
3281         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
3282         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
3283         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
3284         mkdir -p $tdir
3285         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
3286         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
3287         df $tdir
3288         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
3289         $UMOUNT $tdir
3290         losetup -d $loopdev
3291         rm $loopdev
3292 }
3293 run_test 54c "block device works in lustre ====================="
3294
3295 test_54d() {
3296         f="$DIR/f54d"
3297         string="aaaaaa"
3298         mknod $f p
3299         [ "$string" = `echo $string > $f | cat $f` ] || error
3300 }
3301 run_test 54d "fifo device works in lustre ======================"
3302
3303 test_54e() {
3304         check_kernel_version 46 || return 0
3305         f="$DIR/f54e"
3306         string="aaaaaa"
3307         cp -aL /dev/console $f
3308         echo $string > $f || error
3309 }
3310 run_test 54e "console/tty device works in lustre ======================"
3311
3312 #The test_55 used to be iopen test and it was removed by bz#24037.
3313 #run_test 55 "check iopen_connect_dentry() ======================"
3314
3315 test_56a() {    # was test_56
3316         rm -rf $DIR/d56
3317         $SETSTRIPE -d $DIR
3318         mkdir $DIR/d56
3319         mkdir $DIR/d56/dir
3320         NUMFILES=3
3321         NUMFILESx2=$(($NUMFILES * 2))
3322         for i in `seq 1 $NUMFILES` ; do
3323                 touch $DIR/d56/file$i
3324                 touch $DIR/d56/dir/file$i
3325         done
3326
3327         # test lfs getstripe with --recursive
3328         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
3329         [ $FILENUM -eq $NUMFILESx2 ] ||
3330                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
3331         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
3332         [ $FILENUM -eq $NUMFILES ] ||
3333                 error "$GETSTRIPE $DIR/d56: found $FILENUM, not $NUMFILES"
3334         echo "$GETSTRIPE --recursive passed."
3335
3336         # test lfs getstripe with file instead of dir
3337         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
3338         [ $FILENUM  -eq 1 ] || error \
3339                  "$GETSTRIPE $DIR/d56/file1: found $FILENUM, not 1"
3340         echo "$GETSTRIPE file1 passed."
3341
3342         #test lfs getstripe with --verbose
3343         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||
3344                 error "$GETSTRIPE --verbose $DIR/d56: want $NUMFILES lmm_magic"
3345         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] ||
3346             error "$GETSTRIPE $DIR/d56: showed lmm_magic"
3347         echo "$GETSTRIPE --verbose passed."
3348
3349         #test lfs getstripe with --obd
3350         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" ||
3351                 error "$GETSTRIPE --obd wrong_uuid should return error message"
3352
3353         [  "$OSTCOUNT" -lt 2 ] &&
3354                 skip_env "skipping other $GETSTRIPE --obd test" && return
3355
3356         OSTIDX=1
3357         OBDUUID=$(ostuuid_from_index $OSTIDX)
3358         FILENUM=`$GETSTRIPE -ir $DIR/d56 | grep -x $OSTIDX | wc -l`
3359         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | grep obdidx | wc -l`
3360         [ $FOUND -eq $FILENUM ] ||
3361                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
3362         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 |
3363                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
3364                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
3365                 error "$GETSTRIPE --obd: should not show file on other obd"
3366         echo "$GETSTRIPE --obd passed"
3367 }
3368 run_test 56a "check $GETSTRIPE"
3369
3370 NUMFILES=3
3371 NUMDIRS=3
3372 setup_56() {
3373         local LOCAL_NUMFILES="$1"
3374         local LOCAL_NUMDIRS="$2"
3375         local MKDIR_PARAMS="$3"
3376
3377         if [ ! -d "$TDIR" ] ; then
3378                 mkdir -p $TDIR
3379                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
3380                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3381                         touch $TDIR/file$i
3382                 done
3383                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3384                         mkdir $TDIR/dir$i
3385                         for j in `seq 1 $LOCAL_NUMFILES` ; do
3386                                 touch $TDIR/dir$i/file$j
3387                         done
3388                 done
3389         fi
3390 }
3391
3392 setup_56_special() {
3393         LOCAL_NUMFILES=$1
3394         LOCAL_NUMDIRS=$2
3395         setup_56 $1 $2
3396         if [ ! -e "$TDIR/loop1b" ] ; then
3397                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3398                         mknod $TDIR/loop${i}b b 7 $i
3399                         mknod $TDIR/null${i}c c 1 3
3400                         ln -s $TDIR/file1 $TDIR/link${i}l
3401                 done
3402                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3403                         mknod $TDIR/dir$i/loop${i}b b 7 $i
3404                         mknod $TDIR/dir$i/null${i}c c 1 3
3405                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
3406                 done
3407         fi
3408 }
3409
3410 test_56g() {
3411         $SETSTRIPE -d $DIR
3412
3413         TDIR=$DIR/${tdir}g
3414         setup_56 $NUMFILES $NUMDIRS
3415
3416         EXPECTED=$(($NUMDIRS + 2))
3417         # test lfs find with -name
3418         for i in $(seq 1 $NUMFILES) ; do
3419                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
3420                 [ $NUMS -eq $EXPECTED ] ||
3421                         error "lfs find -name \"*$i\" $TDIR wrong: "\
3422                               "found $NUMS, expected $EXPECTED"
3423         done
3424 }
3425 run_test 56g "check lfs find -name ============================="
3426
3427 test_56h() {
3428         $SETSTRIPE -d $DIR
3429
3430         TDIR=$DIR/${tdir}g
3431         setup_56 $NUMFILES $NUMDIRS
3432
3433         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
3434         # test lfs find with ! -name
3435         for i in $(seq 1 $NUMFILES) ; do
3436                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
3437                 [ $NUMS -eq $EXPECTED ] ||
3438                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
3439                               "found $NUMS, expected $EXPECTED"
3440         done
3441 }
3442 run_test 56h "check lfs find ! -name ============================="
3443
3444 test_56i() {
3445        tdir=${tdir}i
3446        mkdir -p $DIR/$tdir
3447        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
3448        CMD="$LFIND -ost $UUID $DIR/$tdir"
3449        OUT=$($CMD)
3450        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
3451 }
3452 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
3453
3454 test_56j() {
3455         TDIR=$DIR/${tdir}g
3456         setup_56_special $NUMFILES $NUMDIRS
3457
3458         EXPECTED=$((NUMDIRS + 1))
3459         CMD="$LFIND -type d $TDIR"
3460         NUMS=$($CMD | wc -l)
3461         [ $NUMS -eq $EXPECTED ] ||
3462                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3463 }
3464 run_test 56j "check lfs find -type d ============================="
3465
3466 test_56k() {
3467         TDIR=$DIR/${tdir}g
3468         setup_56_special $NUMFILES $NUMDIRS
3469
3470         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3471         CMD="$LFIND -type f $TDIR"
3472         NUMS=$($CMD | wc -l)
3473         [ $NUMS -eq $EXPECTED ] ||
3474                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3475 }
3476 run_test 56k "check lfs find -type f ============================="
3477
3478 test_56l() {
3479         TDIR=$DIR/${tdir}g
3480         setup_56_special $NUMFILES $NUMDIRS
3481
3482         EXPECTED=$((NUMDIRS + NUMFILES))
3483         CMD="$LFIND -type b $TDIR"
3484         NUMS=$($CMD | wc -l)
3485         [ $NUMS -eq $EXPECTED ] ||
3486                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3487 }
3488 run_test 56l "check lfs find -type b ============================="
3489
3490 test_56m() {
3491         TDIR=$DIR/${tdir}g
3492         setup_56_special $NUMFILES $NUMDIRS
3493
3494         EXPECTED=$((NUMDIRS + NUMFILES))
3495         CMD="$LFIND -type c $TDIR"
3496         NUMS=$($CMD | wc -l)
3497         [ $NUMS -eq $EXPECTED ] ||
3498                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3499 }
3500 run_test 56m "check lfs find -type c ============================="
3501
3502 test_56n() {
3503         TDIR=$DIR/${tdir}g
3504         setup_56_special $NUMFILES $NUMDIRS
3505
3506         EXPECTED=$((NUMDIRS + NUMFILES))
3507         CMD="$LFIND -type l $TDIR"
3508         NUMS=$($CMD | wc -l)
3509         [ $NUMS -eq $EXPECTED ] ||
3510                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3511 }
3512 run_test 56n "check lfs find -type l ============================="
3513
3514 test_56o() {
3515         TDIR=$DIR/${tdir}o
3516         setup_56 $NUMFILES $NUMDIRS
3517
3518         utime $TDIR/file1 > /dev/null || error "utime (1)"
3519         utime $TDIR/file2 > /dev/null || error "utime (2)"
3520         utime $TDIR/dir1 > /dev/null || error "utime (3)"
3521         utime $TDIR/dir2 > /dev/null || error "utime (4)"
3522         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
3523         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
3524
3525         EXPECTED=4
3526         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
3527         [ $NUMS -eq $EXPECTED ] || \
3528                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
3529
3530         EXPECTED=12
3531         CMD="$LFIND -mtime 0 $TDIR"
3532         NUMS=$($CMD | wc -l)
3533         [ $NUMS -eq $EXPECTED ] ||
3534                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3535 }
3536 run_test 56o "check lfs find -mtime for old files =========================="
3537
3538 test_56p() {
3539         [ $RUNAS_ID -eq $UID ] &&
3540                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3541
3542         TDIR=$DIR/${tdir}p
3543         setup_56 $NUMFILES $NUMDIRS
3544
3545         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
3546         EXPECTED=$NUMFILES
3547         CMD="$LFIND -uid $RUNAS_ID $TDIR"
3548         NUMS=$($CMD | wc -l)
3549         [ $NUMS -eq $EXPECTED ] || \
3550                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3551
3552         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
3553         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
3554         NUMS=$($CMD | wc -l)
3555         [ $NUMS -eq $EXPECTED ] || \
3556                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3557 }
3558 run_test 56p "check lfs find -uid and ! -uid ==============================="
3559
3560 test_56q() {
3561         [ $RUNAS_ID -eq $UID ] &&
3562                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3563
3564         TDIR=$DIR/${tdir}q
3565         setup_56 $NUMFILES $NUMDIRS
3566
3567         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
3568
3569         EXPECTED=$NUMFILES
3570         CMD="$LFIND -gid $RUNAS_GID $TDIR"
3571         NUMS=$($CMD | wc -l)
3572         [ $NUMS -eq $EXPECTED ] ||
3573                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3574
3575         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
3576         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
3577         NUMS=$($CMD | wc -l)
3578         [ $NUMS -eq $EXPECTED ] ||
3579                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3580 }
3581 run_test 56q "check lfs find -gid and ! -gid ==============================="
3582
3583 test_56r() {
3584         TDIR=$DIR/${tdir}r
3585         setup_56 $NUMFILES $NUMDIRS
3586
3587         EXPECTED=12
3588         CMD="$LFIND -size 0 -type f $TDIR"
3589         NUMS=$($CMD | wc -l)
3590         [ $NUMS -eq $EXPECTED ] ||
3591                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3592         EXPECTED=0
3593         CMD="$LFIND ! -size 0 -type f $TDIR"
3594         NUMS=$($CMD | wc -l)
3595         [ $NUMS -eq $EXPECTED ] ||
3596                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3597         echo "test" > $TDIR/$tfile
3598         echo "test2" > $TDIR/$tfile.2 && sync
3599         EXPECTED=1
3600         CMD="$LFIND -size 5 -type f $TDIR"
3601         NUMS=$($CMD | wc -l)
3602         [ $NUMS -eq $EXPECTED ] ||
3603                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3604         EXPECTED=1
3605         CMD="$LFIND -size +5 -type f $TDIR"
3606         NUMS=$($CMD | wc -l)
3607         [ $NUMS -eq $EXPECTED ] ||
3608                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3609         EXPECTED=2
3610         CMD="$LFIND -size +0 -type f $TDIR"
3611         NUMS=$($CMD | wc -l)
3612         [ $NUMS -eq $EXPECTED ] ||
3613                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3614         EXPECTED=2
3615         CMD="$LFIND ! -size -5 -type f $TDIR"
3616         NUMS=$($CMD | wc -l)
3617         [ $NUMS -eq $EXPECTED ] ||
3618                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3619         EXPECTED=12
3620         CMD="$LFIND -size -5 -type f $TDIR"
3621         NUMS=$($CMD | wc -l)
3622         [ $NUMS -eq $EXPECTED ] ||
3623                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3624 }
3625 run_test 56r "check lfs find -size works =========================="
3626
3627 test_56s() { # LU-611
3628         TDIR=$DIR/${tdir}s
3629         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
3630
3631         if [ $OSTCOUNT -gt 1 ]; then
3632                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
3633                 ONESTRIPE=4
3634                 EXTRA=4
3635         else
3636                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
3637                 EXTRA=0
3638         fi
3639
3640         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3641         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
3642         NUMS=$($CMD | wc -l)
3643         [ $NUMS -eq $EXPECTED ] ||
3644                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3645
3646         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
3647         CMD="$LFIND -stripe-count +0 -type f $TDIR"
3648         NUMS=$($CMD | wc -l)
3649         [ $NUMS -eq $EXPECTED ] ||
3650                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3651
3652         EXPECTED=$ONESTRIPE
3653         CMD="$LFIND -stripe-count 1 -type f $TDIR"
3654         NUMS=$($CMD | wc -l)
3655         [ $NUMS -eq $EXPECTED ] ||
3656                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3657
3658         CMD="$LFIND -stripe-count -2 -type f $TDIR"
3659         NUMS=$($CMD | wc -l)
3660         [ $NUMS -eq $EXPECTED ] ||
3661                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3662
3663         EXPECTED=0
3664         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
3665         NUMS=$($CMD | wc -l)
3666         [ $NUMS -eq $EXPECTED ] ||
3667                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3668 }
3669 run_test 56s "check lfs find -stripe-count works"
3670
3671 test_56t() { # LU-611
3672         TDIR=$DIR/${tdir}t
3673         setup_56 $NUMFILES $NUMDIRS "-s 512k"
3674
3675         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
3676
3677         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3678         CMD="$LFIND -stripe-size 512k -type f $TDIR"
3679         NUMS=$($CMD | wc -l)
3680         [ $NUMS -eq $EXPECTED ] ||
3681                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3682
3683         CMD="$LFIND -stripe-size +320k -type f $TDIR"
3684         NUMS=$($CMD | wc -l)
3685         [ $NUMS -eq $EXPECTED ] ||
3686                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3687
3688         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
3689         CMD="$LFIND -stripe-size +200k -type f $TDIR"
3690         NUMS=$($CMD | wc -l)
3691         [ $NUMS -eq $EXPECTED ] ||
3692                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3693
3694         CMD="$LFIND -stripe-size -640k -type f $TDIR"
3695         NUMS=$($CMD | wc -l)
3696         [ $NUMS -eq $EXPECTED ] ||
3697                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3698
3699         EXPECTED=4
3700         CMD="$LFIND -stripe-size 256k -type f $TDIR"
3701         NUMS=$($CMD | wc -l)
3702         [ $NUMS -eq $EXPECTED ] ||
3703                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3704
3705         CMD="$LFIND -stripe-size -320k -type f $TDIR"
3706         NUMS=$($CMD | wc -l)
3707         [ $NUMS -eq $EXPECTED ] ||
3708                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3709
3710         EXPECTED=0
3711         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
3712         NUMS=$($CMD | wc -l)
3713         [ $NUMS -eq $EXPECTED ] ||
3714                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3715 }
3716 run_test 56t "check lfs find -stripe-size works"
3717
3718 test_56u() { # LU-611
3719         TDIR=$DIR/${tdir}u
3720         setup_56 $NUMFILES $NUMDIRS "-i 0"
3721
3722         if [ $OSTCOUNT -gt 1 ]; then
3723                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
3724                 ONESTRIPE=4
3725         else
3726                 ONESTRIPE=0
3727         fi
3728
3729         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3730         CMD="$LFIND -stripe-index 0 -type f $TDIR"
3731         NUMS=$($CMD | wc -l)
3732         [ $NUMS -eq $EXPECTED ] ||
3733                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3734
3735         EXPECTED=$ONESTRIPE
3736         CMD="$LFIND -stripe-index 1 -type f $TDIR"
3737         NUMS=$($CMD | wc -l)
3738         [ $NUMS -eq $EXPECTED ] ||
3739                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3740
3741         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
3742         NUMS=$($CMD | wc -l)
3743         [ $NUMS -eq $EXPECTED ] ||
3744                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3745
3746         EXPECTED=0
3747         # This should produce an error and not return any files
3748         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
3749         NUMS=$($CMD 2>/dev/null | wc -l)
3750         [ $NUMS -eq $EXPECTED ] ||
3751                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3752
3753         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
3754         CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
3755         NUMS=$($CMD | wc -l)
3756         [ $NUMS -eq $EXPECTED ] ||
3757                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3758 }
3759 run_test 56u "check lfs find -stripe-index works"
3760
3761 test_56v() {
3762     local MDT_IDX=0
3763
3764     TDIR=$DIR/${tdir}v
3765     rm -rf $TDIR
3766     setup_56 $NUMFILES $NUMDIRS
3767
3768     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
3769     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
3770
3771     for file in $($LFIND -mdt $UUID $TDIR); do
3772         file_mdt_idx=$($GETSTRIPE -M $file)
3773         [ $file_mdt_idx -eq $MDT_IDX ] ||
3774             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
3775     done
3776 }
3777 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
3778
3779 # Get and check the actual stripe count of one file.
3780 # Usage: check_stripe_count <file> <expected_stripe_count>
3781 check_stripe_count() {
3782     local file=$1
3783     local expected=$2
3784     local actual
3785
3786     [[ -z "$file" || -z "$expected" ]] &&
3787         error "check_stripe_count: invalid argument!"
3788
3789     local cmd="$GETSTRIPE -c $file"
3790     actual=$($cmd) || error "$cmd failed"
3791     actual=${actual%% *}
3792
3793     if [[ $actual -ne $expected ]]; then
3794         [[ $expected -eq -1 ]] ||
3795             error "$cmd wrong: found $actual, expected $expected"
3796         [[ $actual -eq $OSTCOUNT ]] ||
3797             error "$cmd wrong: found $actual, expected $OSTCOUNT"
3798     fi
3799 }
3800
3801 test_56w() {
3802     TDIR=$DIR/${tdir}w
3803
3804     rm -rf $TDIR || error "remove $TDIR failed"
3805     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
3806
3807     local stripe_size
3808     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
3809         error "$GETSTRIPE -S -d $TDIR failed"
3810     stripe_size=${stripe_size%% *}
3811
3812     local file_size=$((stripe_size * OSTCOUNT))
3813     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
3814     local required_space=$((file_num * file_size))
3815     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
3816     [[ $free_space -le $((required_space / 1024)) ]] &&
3817         skip_env "need at least $required_space bytes free space," \
3818                  "have $free_space kbytes" && return
3819
3820     local dd_bs=65536
3821     local dd_count=$((file_size / dd_bs))
3822
3823     # write data into the files
3824     local i
3825     local j
3826     local file
3827     for i in $(seq 1 $NUMFILES); do
3828         file=$TDIR/file$i
3829         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
3830             error "write data into $file failed"
3831     done
3832     for i in $(seq 1 $NUMDIRS); do
3833         for j in $(seq 1 $NUMFILES); do
3834             file=$TDIR/dir$i/file$j
3835             yes | dd bs=$dd_bs count=$dd_count of=$file \
3836                 >/dev/null 2>&1 ||
3837                 error "write data into $file failed"
3838         done
3839     done
3840
3841     local expected=-1
3842     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
3843
3844     # lfs_migrate file
3845     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
3846     echo "$cmd"
3847     eval $cmd || error "$cmd failed"
3848
3849     check_stripe_count $TDIR/file1 $expected
3850
3851     # lfs_migrate dir
3852     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
3853     echo "$cmd"
3854     eval $cmd || error "$cmd failed"
3855
3856     for j in $(seq 1 $NUMFILES); do
3857         check_stripe_count $TDIR/dir1/file$j $expected
3858     done
3859
3860     # lfs_migrate works with lfs find
3861     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
3862          $LFS_MIGRATE -y -c $expected"
3863     echo "$cmd"
3864     eval $cmd || error "$cmd failed"
3865
3866     for i in $(seq 2 $NUMFILES); do
3867         check_stripe_count $TDIR/file$i $expected
3868     done
3869     for i in $(seq 2 $NUMDIRS); do
3870         for j in $(seq 1 $NUMFILES); do
3871             check_stripe_count $TDIR/dir$i/file$j $expected
3872         done
3873     done
3874 }
3875 run_test 56w "check lfs_migrate -c stripe_count works"
3876
3877 test_57a() {
3878         # note test will not do anything if MDS is not local
3879         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3880         local MNTDEV="osd*.*MDT*.mntdev"
3881         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
3882         [ -z "$DEV" ] && error "can't access $MNTDEV"
3883         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
3884                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
3885                         error "can't access $DEV"
3886                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
3887                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
3888                 rm $TMP/t57a.dump
3889         done
3890 }
3891 run_test 57a "verify MDS filesystem created with large inodes =="
3892
3893 test_57b() {
3894         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3895         local dir=$DIR/d57b
3896
3897         local FILECOUNT=100
3898         local FILE1=$dir/f1
3899         local FILEN=$dir/f$FILECOUNT
3900
3901         rm -rf $dir || error "removing $dir"
3902         mkdir -p $dir || error "creating $dir"
3903         local num=$(get_mds_dir $dir)
3904         local mymds=mds$num
3905
3906         echo "mcreating $FILECOUNT files"
3907         createmany -m $dir/f 1 $FILECOUNT || \
3908                 error "creating files in $dir"
3909
3910         # verify that files do not have EAs yet
3911         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
3912         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
3913
3914         sync
3915         sleep 1
3916         df $dir  #make sure we get new statfs data
3917         local MDSFREE=$(do_facet $mymds \
3918                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
3919         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
3920         echo "opening files to create objects/EAs"
3921         local FILE
3922         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
3923                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
3924         done
3925
3926         # verify that files have EAs now
3927         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
3928         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
3929
3930         sleep 1  #make sure we get new statfs data
3931         df $dir
3932         local MDSFREE2=$(do_facet $mymds \
3933                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
3934         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
3935         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
3936                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
3937                         error "MDC before $MDCFREE != after $MDCFREE2"
3938                 else
3939                         echo "MDC before $MDCFREE != after $MDCFREE2"
3940                         echo "unable to confirm if MDS has large inodes"
3941                 fi
3942         fi
3943         rm -rf $dir
3944 }
3945 run_test 57b "default LOV EAs are stored inside large inodes ==="
3946
3947 test_58() {
3948     [ -z "$(which wiretest 2>/dev/null)" ] && skip_env "could not find wiretest" && return
3949     wiretest
3950 }
3951 run_test 58 "verify cross-platform wire constants =============="
3952
3953 test_59() {
3954         echo "touch 130 files"
3955         createmany -o $DIR/f59- 130
3956         echo "rm 130 files"
3957         unlinkmany $DIR/f59- 130
3958         sync
3959         sleep 2
3960         # wait for commitment of removal
3961 }
3962 run_test 59 "verify cancellation of llog records async ========="
3963
3964 TEST60_HEAD="test_60 run $RANDOM"
3965 test_60a() {
3966         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
3967         [ ! -f run-llog.sh ] && skip_env "missing subtest run-llog.sh" && return
3968         log "$TEST60_HEAD - from kernel mode"
3969         do_facet mgs sh run-llog.sh
3970 }
3971 run_test 60a "llog sanity tests run from kernel module =========="
3972
3973 test_60b() { # bug 6411
3974         dmesg > $DIR/$tfile
3975         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
3976                                  /llog.test/ {
3977                                          if (marker)
3978                                                  from_marker++
3979                                          from_begin++
3980                                  }
3981                                  END {
3982                                          if (marker)
3983                                                  print from_marker
3984                                          else
3985                                                  print from_begin
3986                                  }"`
3987         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
3988 }
3989 run_test 60b "limit repeated messages from CERROR/CWARN ========"
3990
3991 test_60c() {
3992         echo "create 5000 files"
3993         createmany -o $DIR/f60c- 5000
3994 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
3995         lctl set_param fail_loc=0x80000137
3996         unlinkmany $DIR/f60c- 5000
3997         lctl set_param fail_loc=0
3998 }
3999 run_test 60c "unlink file when mds full"
4000
4001 test_60d() {
4002         SAVEPRINTK=$(lctl get_param -n printk)
4003
4004         # verify "lctl mark" is even working"
4005         MESSAGE="test message ID $RANDOM $$"
4006         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4007         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4008
4009         lctl set_param printk=0 || error "set lnet.printk failed"
4010         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4011         MESSAGE="new test message ID $RANDOM $$"
4012         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4013         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4014         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4015
4016         lctl set_param -n printk="$SAVEPRINTK"
4017 }
4018 run_test 60d "test printk console message masking"
4019
4020 test_61() {
4021         f="$DIR/f61"
4022         dd if=/dev/zero of=$f bs=`page_size` count=1
4023         cancel_lru_locks osc
4024         multiop $f OSMWUc || error
4025         sync
4026 }
4027 run_test 61 "mmap() writes don't make sync hang ================"
4028
4029 # bug 2330 - insufficient obd_match error checking causes LBUG
4030 test_62() {
4031         f="$DIR/f62"
4032         echo foo > $f
4033         cancel_lru_locks osc
4034         lctl set_param fail_loc=0x405
4035         cat $f && error "cat succeeded, expect -EIO"
4036         lctl set_param fail_loc=0
4037 }
4038 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4039 # match every page all of the time.
4040 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4041
4042 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4043 test_63a() {    # was test_63
4044         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4045         lctl set_param -n osc.*.max_dirty_mb 0
4046         for i in `seq 10` ; do
4047                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4048                 sleep 5
4049                 kill $!
4050                 sleep 1
4051         done
4052
4053         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
4054         rm -f $DIR/f63 || true
4055 }
4056 run_test 63a "Verify oig_wait interruption does not crash ======="
4057
4058 # bug 2248 - async write errors didn't return to application on sync
4059 # bug 3677 - async write errors left page locked
4060 test_63b() {
4061         debugsave
4062         lctl set_param debug=-1
4063
4064         # ensure we have a grant to do async writes
4065         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4066         rm $DIR/$tfile
4067
4068         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4069         lctl set_param fail_loc=0x80000406
4070         multiop $DIR/$tfile Owy && \
4071                 error "sync didn't return ENOMEM"
4072         sync; sleep 2; sync     # do a real sync this time to flush page
4073         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4074                 error "locked page left in cache after async error" || true
4075         debugrestore
4076 }
4077 run_test 63b "async write errors should be returned to fsync ==="
4078
4079 test_64a () {
4080         df $DIR
4081         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4082 }
4083 run_test 64a "verify filter grant calculations (in kernel) ====="
4084
4085 test_64b () {
4086         [ ! -f oos.sh ] && skip_env "missing subtest oos.sh" && return
4087         sh oos.sh $MOUNT
4088 }
4089 run_test 64b "check out-of-space detection on client ==========="
4090
4091 # bug 1414 - set/get directories' stripe info
4092 test_65a() {
4093         mkdir -p $DIR/d65
4094         touch $DIR/d65/f1
4095         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
4096 }
4097 run_test 65a "directory with no stripe info ===================="
4098
4099 test_65b() {
4100         mkdir -p $DIR/d65
4101         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65||error "setstripe"
4102         touch $DIR/d65/f2
4103         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
4104 }
4105 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4106
4107 test_65c() {
4108         if [ $OSTCOUNT -gt 1 ]; then
4109                 mkdir -p $DIR/d65
4110                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4111                         -c $(($OSTCOUNT - 1)) $DIR/d65 || error "setstripe"
4112                 touch $DIR/d65/f3
4113                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
4114         fi
4115 }
4116 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4117
4118 test_65d() {
4119         mkdir -p $DIR/d65
4120         if [ $STRIPECOUNT -le 0 ]; then
4121                 sc=1
4122         elif [ $STRIPECOUNT -gt 2000 ]; then
4123 #LOV_MAX_STRIPE_COUNT is 2000
4124                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
4125         else
4126                 sc=$(($STRIPECOUNT - 1))
4127         fi
4128         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/d65 || error "setstripe"
4129         touch $DIR/d65/f4 $DIR/d65/f5
4130         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
4131 }
4132 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
4133
4134 test_65e() {
4135         mkdir -p $DIR/d65
4136
4137         $SETSTRIPE $DIR/d65 || error "setstripe"
4138         $GETSTRIPE -v $DIR/d65 | grep "Default" || error "no stripe info failed"
4139         touch $DIR/d65/f6
4140         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
4141 }
4142 run_test 65e "directory setstripe defaults ======================="
4143
4144 test_65f() {
4145         mkdir -p $DIR/d65f
4146         $RUNAS $SETSTRIPE $DIR/d65f && error "setstripe succeeded" || true
4147 }
4148 run_test 65f "dir setstripe permission (should return error) ==="
4149
4150 test_65g() {
4151         mkdir -p $DIR/d65
4152         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65 ||error "setstripe"
4153         $SETSTRIPE -d $DIR/d65 || error "setstripe"
4154         $GETSTRIPE -v $DIR/d65 | grep "Default" || \
4155                 error "delete default stripe failed"
4156 }
4157 run_test 65g "directory setstripe -d ==========================="
4158
4159 test_65h() {
4160         mkdir -p $DIR/d65
4161         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65 ||error "setstripe"
4162         mkdir -p $DIR/d65/dd1
4163         [ $($GETSTRIPE -c $DIR/d65) == $($GETSTRIPE -c $DIR/d65/dd1) ] ||
4164                 error "stripe info inherit failed"
4165 }
4166 run_test 65h "directory stripe info inherit ===================="
4167
4168 test_65i() { # bug6367
4169         $SETSTRIPE -S 65536 -c -1 $MOUNT
4170 }
4171 run_test 65i "set non-default striping on root directory (bug 6367)="
4172
4173 test_65ia() { # bug12836
4174         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
4175 }
4176 run_test 65ia "getstripe on -1 default directory striping"
4177
4178 test_65ib() { # bug12836
4179         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
4180 }
4181 run_test 65ib "getstripe -v on -1 default directory striping"
4182
4183 test_65ic() { # bug12836
4184         $LFS find -mtime -1 $MOUNT || error "find $MOUNT failed"
4185 }
4186 run_test 65ic "new find on -1 default directory striping"
4187
4188 test_65j() { # bug6367
4189         sync; sleep 1
4190         # if we aren't already remounting for each test, do so for this test
4191         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
4192                 cleanup || error "failed to unmount"
4193                 setup
4194         fi
4195         $SETSTRIPE -d $MOUNT || error "setstripe failed"
4196 }
4197 run_test 65j "set default striping on root directory (bug 6367)="
4198
4199 test_65k() { # bug11679
4200     [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
4201     remote_mds_nodsh && skip "remote MDS with nodsh" && return
4202
4203     echo "Check OST status: "
4204     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
4205               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
4206
4207     for OSC in $MDS_OSCS; do
4208         echo $OSC "is activate"
4209         do_facet $SINGLEMDS lctl --device %$OSC activate
4210     done
4211
4212     do_facet client mkdir -p $DIR/$tdir
4213     for INACTIVE_OSC in $MDS_OSCS; do
4214         echo "Deactivate: " $INACTIVE_OSC
4215         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
4216         for STRIPE_OSC in $MDS_OSCS; do
4217             OST=`osc_to_ost $STRIPE_OSC`
4218             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
4219                  awk -F: /$OST/'{ print $1 }' | head -n 1`
4220
4221             [ -f $DIR/$tdir/$IDX ] && continue
4222             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
4223             do_facet client $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
4224             RC=$?
4225             [ $RC -ne 0 ] && error "setstripe should have succeeded"
4226         done
4227         do_facet client rm -f $DIR/$tdir/*
4228         echo $INACTIVE_OSC "is Activate."
4229         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
4230     done
4231 }
4232 run_test 65k "validate manual striping works properly with deactivated OSCs"
4233
4234 test_65l() { # bug 12836
4235         mkdir -p $DIR/$tdir/test_dir
4236         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
4237         $LFS find -mtime -1 $DIR/$tdir >/dev/null
4238 }
4239 run_test 65l "lfs find on -1 stripe dir ========================"
4240
4241 # bug 2543 - update blocks count on client
4242 test_66() {
4243         COUNT=${COUNT:-8}
4244         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
4245         sync; sleep 1; sync
4246         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
4247         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
4248 }
4249 run_test 66 "update inode blocks count on client ==============="
4250
4251 LLOOP=
4252 LLITELOOPLOAD=
4253 cleanup_68() {
4254         trap 0
4255         if [ ! -z "$LLOOP" ]; then
4256                 if swapon -s | grep -q $LLOOP; then
4257                         swapoff $LLOOP || error "swapoff failed"
4258                 fi
4259
4260                 $LCTL blockdev_detach $LLOOP || error "detach failed"
4261                 rm -f $LLOOP
4262                 unset LLOOP
4263         fi
4264         if [ ! -z "$LLITELOOPLOAD" ]; then
4265                 rmmod llite_lloop
4266                 unset LLITELOOPLOAD
4267         fi
4268         rm -f $DIR/f68*
4269 }
4270
4271 meminfo() {
4272         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
4273 }
4274
4275 swap_used() {
4276         swapon -s | awk '($1 == "'$1'") { print $4 }'
4277 }
4278
4279 # test case for lloop driver, basic function
4280 test_68a() {
4281         [ "$UID" != 0 ] && skip_env "must run as root" && return
4282         llite_lloop_enabled || \
4283                 { skip_env "llite_lloop module disabled" && return; }
4284
4285         trap cleanup_68 EXIT
4286
4287         if ! module_loaded llite_lloop; then
4288                 if load_module llite/llite_lloop; then
4289                         LLITELOOPLOAD=yes
4290                 else
4291                         skip_env "can't find module llite_lloop"
4292                         return
4293                 fi
4294         fi
4295
4296         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4297         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
4298         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
4299
4300         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
4301         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
4302
4303         cleanup_68
4304 }
4305 run_test 68a "lloop driver - basic test ========================"
4306
4307 # excercise swapping to lustre by adding a high priority swapfile entry
4308 # and then consuming memory until it is used.
4309 test_68b() {  # was test_68
4310         [ "$UID" != 0 ] && skip_env "must run as root" && return
4311         lctl get_param -n devices | grep -q obdfilter && \
4312                 skip "local OST" && return
4313
4314         grep -q llite_lloop /proc/modules
4315         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
4316
4317         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
4318                 skip "can't reliably test swap with TCP" && return
4319
4320         MEMTOTAL=`meminfo MemTotal`
4321         NR_BLOCKS=$((MEMTOTAL>>8))
4322         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
4323
4324         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4325         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
4326         mkswap $DIR/f68b
4327
4328         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
4329
4330         trap cleanup_68 EXIT
4331
4332         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
4333
4334         echo "before: `swapon -s | grep $LLOOP`"
4335         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
4336         echo "after: `swapon -s | grep $LLOOP`"
4337         SWAPUSED=`swap_used $LLOOP`
4338
4339         cleanup_68
4340
4341         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
4342 }
4343 run_test 68b "support swapping to Lustre ========================"
4344
4345 # bug5265, obdfilter oa2dentry return -ENOENT
4346 # #define OBD_FAIL_OST_ENOENT 0x217
4347 test_69() {
4348         remote_ost_nodsh && skip "remote OST with nodsh" && return
4349
4350         f="$DIR/$tfile"
4351         $SETSTRIPE -c 1 -i 0 $f
4352
4353         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
4354
4355         do_facet ost1 lctl set_param fail_loc=0x217
4356         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
4357         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
4358
4359         do_facet ost1 lctl set_param fail_loc=0
4360         $DIRECTIO write $f 0 2 || error "write error"
4361
4362         cancel_lru_locks osc
4363         $DIRECTIO read $f 0 1 || error "read error"
4364
4365         do_facet ost1 lctl set_param fail_loc=0x217
4366         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
4367
4368         do_facet ost1 lctl set_param fail_loc=0
4369         rm -f $f
4370 }
4371 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
4372
4373 test_71() {
4374     mkdir -p $DIR/$tdir
4375     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
4376 }
4377 run_test 71 "Running dbench on lustre (don't segment fault) ===="
4378
4379 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
4380         check_kernel_version 43 || return 0
4381         [ "$RUNAS_ID" = "$UID" ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4382
4383         # Check that testing environment is properly set up. Skip if not
4384         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
4385                 skip_env "User $RUNAS_ID does not exist - skipping"
4386                 return 0
4387         }
4388         # We had better clear the $DIR to get enough space for dd
4389         rm -rf $DIR/*
4390         touch $DIR/f72
4391         chmod 777 $DIR/f72
4392         chmod ug+s $DIR/f72
4393         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
4394         # See if we are still setuid/sgid
4395         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
4396         # Now test that MDS is updated too
4397         cancel_lru_locks mdc
4398         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
4399         true
4400         rm -f $DIR/f72
4401 }
4402 run_test 72a "Test that remove suid works properly (bug5695) ===="
4403
4404 test_72b() { # bug 24226 -- keep mode setting when size is not changing
4405         local perm
4406
4407         [ "$RUNAS_ID" = "$UID" ] && \
4408                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4409         [ "$RUNAS_ID" -eq 0 ] && \
4410                 skip_env "RUNAS_ID = 0 -- skipping" && return
4411
4412         # Check that testing environment is properly set up. Skip if not
4413         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
4414                 skip_env "User $RUNAS_ID does not exist - skipping"
4415                 return 0
4416         }
4417         touch $DIR/${tfile}-f{g,u}
4418         mkdir $DIR/${tfile}-d{g,u}
4419         chmod 770 $DIR/${tfile}-{f,d}{g,u}
4420         chmod g+s $DIR/${tfile}-{f,d}g
4421         chmod u+s $DIR/${tfile}-{f,d}u
4422         for perm in 777 2777 4777; do
4423                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
4424                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
4425                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
4426                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
4427         done
4428         true
4429 }
4430 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
4431
4432 # bug 3462 - multiple simultaneous MDC requests
4433 test_73() {
4434         mkdir $DIR/d73-1
4435         mkdir $DIR/d73-2
4436         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
4437         pid1=$!
4438
4439         lctl set_param fail_loc=0x80000129
4440         multiop $DIR/d73-1/f73-2 Oc &
4441         sleep 1
4442         lctl set_param fail_loc=0
4443
4444         multiop $DIR/d73-2/f73-3 Oc &
4445         pid3=$!
4446
4447         kill -USR1 $pid1
4448         wait $pid1 || return 1
4449
4450         sleep 25
4451
4452         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
4453         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
4454         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
4455
4456         rm -rf $DIR/d73-*
4457 }
4458 run_test 73 "multiple MDC requests (should not deadlock)"
4459
4460 test_74a() { # bug 6149, 6184
4461         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
4462         #
4463         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
4464         # will spin in a tight reconnection loop
4465         touch $DIR/f74a
4466         lctl set_param fail_loc=0x8000030e
4467         # get any lock that won't be difficult - lookup works.
4468         ls $DIR/f74a
4469         lctl set_param fail_loc=0
4470         true
4471         rm -f $DIR/f74a
4472 }
4473 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
4474
4475 test_74b() { # bug 13310
4476         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
4477         #
4478         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
4479         # will spin in a tight reconnection loop
4480         lctl set_param fail_loc=0x8000030e
4481         # get a "difficult" lock
4482         touch $DIR/f74b
4483         lctl set_param fail_loc=0
4484         true
4485         rm -f $DIR/f74b
4486 }
4487 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
4488
4489 test_74c() {
4490 #define OBD_FAIL_LDLM_NEW_LOCK
4491         lctl set_param fail_loc=0x80000319
4492         touch $DIR/$tfile && error "Touch successful"
4493         true
4494 }
4495 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
4496
4497 num_inodes() {
4498         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
4499 }
4500
4501 get_inode_slab_tunables() {
4502         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
4503 }
4504
4505 set_inode_slab_tunables() {
4506         echo "lustre_inode_cache $1" > /proc/slabinfo
4507 }
4508
4509 test_76() { # Now for bug 20433, added originally in bug 1443
4510         local SLAB_SETTINGS=`get_inode_slab_tunables`
4511         local CPUS=`getconf _NPROCESSORS_ONLN`
4512         # we cannot set limit below 1 which means 1 inode in each
4513         # per-cpu cache is still allowed
4514         set_inode_slab_tunables "1 1 0"
4515         cancel_lru_locks osc
4516         BEFORE_INODES=`num_inodes`
4517         echo "before inodes: $BEFORE_INODES"
4518         local COUNT=1000
4519         [ "$SLOW" = "no" ] && COUNT=100
4520         for i in `seq $COUNT`; do
4521                 touch $DIR/$tfile
4522                 rm -f $DIR/$tfile
4523         done
4524         cancel_lru_locks osc
4525         AFTER_INODES=`num_inodes`
4526         echo "after inodes: $AFTER_INODES"
4527         local wait=0
4528         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
4529                 sleep 2
4530                 AFTER_INODES=`num_inodes`
4531                 wait=$((wait+2))
4532                 echo "wait $wait seconds inodes: $AFTER_INODES"
4533                 if [ $wait -gt 30 ]; then
4534                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
4535                 fi
4536         done
4537         set_inode_slab_tunables "$SLAB_SETTINGS"
4538 }
4539 run_test 76 "confirm clients recycle inodes properly ===="
4540
4541
4542 export ORIG_CSUM=""
4543 set_checksums()
4544 {
4545         # Note: in sptlrpc modes which enable its own bulk checksum, the
4546         # original crc32_le bulk checksum will be automatically disabled,
4547         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
4548         # will be checked by sptlrpc code against sptlrpc bulk checksum.
4549         # In this case set_checksums() will not be no-op, because sptlrpc
4550         # bulk checksum will be enabled all through the test.
4551
4552         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
4553         lctl set_param -n osc.*.checksums $1
4554         return 0
4555 }
4556
4557 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
4558                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
4559 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
4560 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
4561 set_checksum_type()
4562 {
4563         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
4564         log "set checksum type to $1"
4565         return 0
4566 }
4567 F77_TMP=$TMP/f77-temp
4568 F77SZ=8
4569 setup_f77() {
4570         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
4571                 error "error writing to $F77_TMP"
4572 }
4573
4574 test_77a() { # bug 10889
4575         $GSS && skip "could not run with gss" && return
4576         [ ! -f $F77_TMP ] && setup_f77
4577         set_checksums 1
4578         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
4579         set_checksums 0
4580         rm -f $DIR/$tfile
4581 }
4582 run_test 77a "normal checksum read/write operation ============="
4583
4584 test_77b() { # bug 10889
4585         $GSS && skip "could not run with gss" && return
4586         [ ! -f $F77_TMP ] && setup_f77
4587         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4588         lctl set_param fail_loc=0x80000409
4589         set_checksums 1
4590         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
4591                 error "dd error: $?"
4592         lctl set_param fail_loc=0
4593         set_checksums 0
4594 }
4595 run_test 77b "checksum error on client write ===================="
4596
4597 test_77c() { # bug 10889
4598         $GSS && skip "could not run with gss" && return
4599         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
4600         set_checksums 1
4601         for algo in $CKSUM_TYPES; do
4602                 cancel_lru_locks osc
4603                 set_checksum_type $algo
4604                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
4605                 lctl set_param fail_loc=0x80000408
4606                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
4607                 lctl set_param fail_loc=0
4608         done
4609         set_checksums 0
4610         set_checksum_type $ORIG_CSUM_TYPE
4611         rm -f $DIR/f77b
4612 }
4613 run_test 77c "checksum error on client read ==================="
4614
4615 test_77d() { # bug 10889
4616         $GSS && skip "could not run with gss" && return
4617         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4618         lctl set_param fail_loc=0x80000409
4619         set_checksums 1
4620         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
4621                 error "direct write: rc=$?"
4622         lctl set_param fail_loc=0
4623         set_checksums 0
4624 }
4625 run_test 77d "checksum error on OST direct write ==============="
4626
4627 test_77e() { # bug 10889
4628         $GSS && skip "could not run with gss" && return
4629         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
4630         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
4631         lctl set_param fail_loc=0x80000408
4632         set_checksums 1
4633         cancel_lru_locks osc
4634         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
4635                 error "direct read: rc=$?"
4636         lctl set_param fail_loc=0
4637         set_checksums 0
4638 }
4639 run_test 77e "checksum error on OST direct read ================"
4640
4641 test_77f() { # bug 10889
4642         $GSS && skip "could not run with gss" && return
4643         set_checksums 1
4644         for algo in $CKSUM_TYPES; do
4645                 cancel_lru_locks osc
4646                 set_checksum_type $algo
4647                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4648                 lctl set_param fail_loc=0x409
4649                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
4650                         error "direct write succeeded"
4651                 lctl set_param fail_loc=0
4652         done
4653         set_checksum_type $ORIG_CSUM_TYPE
4654         set_checksums 0
4655 }
4656 run_test 77f "repeat checksum error on write (expect error) ===="
4657
4658 test_77g() { # bug 10889
4659         $GSS && skip "could not run with gss" && return
4660         remote_ost_nodsh && skip "remote OST with nodsh" && return
4661
4662         [ ! -f $F77_TMP ] && setup_f77
4663
4664         $SETSTRIPE -c 1 -i 0 $DIR/f77g
4665         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
4666         do_facet ost1 lctl set_param fail_loc=0x8000021a
4667         set_checksums 1
4668         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
4669                 error "write error: rc=$?"
4670         do_facet ost1 lctl set_param fail_loc=0
4671         set_checksums 0
4672 }
4673 run_test 77g "checksum error on OST write ======================"
4674
4675 test_77h() { # bug 10889
4676         $GSS && skip "could not run with gss" && return
4677         remote_ost_nodsh && skip "remote OST with nodsh" && return
4678
4679         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
4680         cancel_lru_locks osc
4681         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
4682         do_facet ost1 lctl set_param fail_loc=0x8000021b
4683         set_checksums 1
4684         cmp $F77_TMP $DIR/f77g || error "file compare failed"
4685         do_facet ost1 lctl set_param fail_loc=0
4686         set_checksums 0
4687 }
4688 run_test 77h "checksum error on OST read ======================="
4689
4690 test_77i() { # bug 13805
4691         $GSS && skip "could not run with gss" && return
4692         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
4693         lctl set_param fail_loc=0x40b
4694         remount_client $MOUNT
4695         lctl set_param fail_loc=0
4696         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
4697                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
4698                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
4699                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
4700         done
4701         remount_client $MOUNT
4702 }
4703 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
4704
4705 test_77j() { # bug 13805
4706         $GSS && skip "could not run with gss" && return
4707         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
4708         lctl set_param fail_loc=0x40c
4709         remount_client $MOUNT
4710         lctl set_param fail_loc=0
4711         sleep 2 # wait async osc connect to finish
4712         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
4713                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
4714                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
4715                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
4716         done
4717         remount_client $MOUNT
4718 }
4719 run_test 77j "client only supporting ADLER32 ===================="
4720
4721 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
4722 rm -f $F77_TMP
4723 unset F77_TMP
4724
4725 test_78() { # bug 10901
4726         remote_ost || { skip_env "local OST" && return; }
4727
4728         NSEQ=5
4729         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
4730         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
4731         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
4732         echo "MemTotal: $MEMTOTAL"
4733 # reserve 256MB of memory for the kernel and other running processes,
4734 # and then take 1/2 of the remaining memory for the read/write buffers.
4735     if [ $MEMTOTAL -gt 512 ] ;then
4736         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
4737     else
4738         # for those poor memory-starved high-end clusters...
4739         MEMTOTAL=$((MEMTOTAL / 2))
4740     fi
4741         echo "Mem to use for directio: $MEMTOTAL"
4742         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
4743         [ $F78SIZE -gt 512 ] && F78SIZE=512
4744         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
4745         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
4746         echo "Smallest OST: $SMALLESTOST"
4747         [ $SMALLESTOST -lt 10240 ] && \
4748                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
4749
4750         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
4751                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
4752
4753         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
4754         echo "File size: $F78SIZE"
4755         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
4756         for i in `seq 1 $NSEQ`
4757         do
4758                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
4759                 echo directIO rdwr round $i of $NSEQ
4760                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
4761         done
4762
4763         rm -f $DIR/$tfile
4764 }
4765 run_test 78 "handle large O_DIRECT writes correctly ============"
4766
4767 test_79() { # bug 12743
4768         wait_delete_completed
4769
4770         BKTOTAL=$(calc_osc_kbytes kbytestotal)
4771         BKFREE=$(calc_osc_kbytes kbytesfree)
4772         BKAVAIL=$(calc_osc_kbytes kbytesavail)
4773
4774         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
4775         DFTOTAL=`echo $STRING | cut -d, -f1`
4776         DFUSED=`echo $STRING  | cut -d, -f2`
4777         DFAVAIL=`echo $STRING | cut -d, -f3`
4778         DFFREE=$(($DFTOTAL - $DFUSED))
4779
4780         ALLOWANCE=$((64 * $OSTCOUNT))
4781
4782         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
4783            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
4784                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
4785         fi
4786         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
4787            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
4788                 error "df free($DFFREE) mismatch OST free($BKFREE)"
4789         fi
4790         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
4791            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
4792                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
4793         fi
4794 }
4795 run_test 79 "df report consistency check ======================="
4796
4797 test_80() { # bug 10718
4798         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
4799         sync; sleep 1; sync
4800         local BEFORE=`date +%s`
4801         cancel_lru_locks osc
4802         local AFTER=`date +%s`
4803         local DIFF=$((AFTER-BEFORE))
4804         if [ $DIFF -gt 1 ] ; then
4805                 error "elapsed for 1M@1T = $DIFF"
4806         fi
4807         true
4808         rm -f $DIR/$tfile
4809 }
4810 run_test 80 "Page eviction is equally fast at high offsets too  ===="
4811
4812 test_81a() { # LU-456
4813         remote_ost_nodsh && skip "remote OST with nodsh" && return
4814         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
4815         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
4816         do_facet ost0 lctl set_param fail_loc=0x80000228
4817
4818         # write should trigger a retry and success
4819         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
4820         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4821         RC=$?
4822         if [ $RC -ne 0 ] ; then
4823                 error "write should success, but failed for $RC"
4824         fi
4825 }
4826 run_test 81a "OST should retry write when get -ENOSPC ==============="
4827
4828 test_81b() { # LU-456
4829         remote_ost_nodsh && skip "remote OST with nodsh" && return
4830         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
4831         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
4832         do_facet ost0 lctl set_param fail_loc=0x228
4833
4834         # write should retry several times and return -ENOSPC finally
4835         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
4836         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4837         RC=$?
4838         ENOSPC=28
4839         if [ $RC -ne $ENOSPC ] ; then
4840                 error "dd should fail for -ENOSPC, but succeed."
4841         fi
4842 }
4843 run_test 81b "OST should return -ENOSPC when retry still fails ======="
4844
4845
4846 test_99a() {
4847         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && \
4848             return
4849         mkdir -p $DIR/d99cvsroot
4850         chown $RUNAS_ID $DIR/d99cvsroot
4851         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
4852         cd $TMP
4853
4854         $RUNAS cvs -d $DIR/d99cvsroot init || error
4855         cd $oldPWD
4856 }
4857 run_test 99a "cvs init ========================================="
4858
4859 test_99b() {
4860         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4861         [ ! -d $DIR/d99cvsroot ] && test_99a
4862         cd /etc/init.d
4863         # some versions of cvs import exit(1) when asked to import links or
4864         # files they can't read.  ignore those files.
4865         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
4866                         ! -perm +4 -printf '-I %f\n')
4867         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
4868                 d99reposname vtag rtag
4869 }
4870 run_test 99b "cvs import ======================================="
4871
4872 test_99c() {
4873         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4874         [ ! -d $DIR/d99cvsroot ] && test_99b
4875         cd $DIR
4876         mkdir -p $DIR/d99reposname
4877         chown $RUNAS_ID $DIR/d99reposname
4878         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
4879 }
4880 run_test 99c "cvs checkout ====================================="
4881
4882 test_99d() {
4883         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4884         [ ! -d $DIR/d99cvsroot ] && test_99c
4885         cd $DIR/d99reposname
4886         $RUNAS touch foo99
4887         $RUNAS cvs add -m 'addmsg' foo99
4888 }
4889 run_test 99d "cvs add =========================================="
4890
4891 test_99e() {
4892         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4893         [ ! -d $DIR/d99cvsroot ] && test_99c
4894         cd $DIR/d99reposname
4895         $RUNAS cvs update
4896 }
4897 run_test 99e "cvs update ======================================="
4898
4899 test_99f() {
4900         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4901         [ ! -d $DIR/d99cvsroot ] && test_99d
4902         cd $DIR/d99reposname
4903         $RUNAS cvs commit -m 'nomsg' foo99
4904     rm -fr $DIR/d99cvsroot
4905 }
4906 run_test 99f "cvs commit ======================================="
4907
4908 test_100() {
4909         [ "$NETTYPE" = tcp ] || \
4910                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
4911                         return ; }
4912
4913         remote_ost_nodsh && skip "remote OST with nodsh" && return
4914         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4915         remote_servers || \
4916                 { skip "useless for local single node setup" && return; }
4917
4918         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
4919                 [ "$PROT" != "tcp" ] && continue
4920                 RPORT=$(echo $REMOTE | cut -d: -f2)
4921                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
4922
4923                 rc=0
4924                 LPORT=`echo $LOCAL | cut -d: -f2`
4925                 if [ $LPORT -ge 1024 ]; then
4926                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
4927                         netstat -tna
4928                         error_exit "local: $LPORT > 1024, remote: $RPORT"
4929                 fi
4930         done
4931         [ "$rc" = 0 ] || error_exit "privileged port not found" )
4932 }
4933 run_test 100 "check local port using privileged port ==========="
4934
4935 function get_named_value()
4936 {
4937     local tag
4938
4939     tag=$1
4940     while read ;do
4941         line=$REPLY
4942         case $line in
4943         $tag*)
4944             echo $line | sed "s/^$tag[ ]*//"
4945             break
4946             ;;
4947         esac
4948     done
4949 }
4950
4951 export CACHE_MAX=`$LCTL get_param -n llite.*.max_cached_mb | head -n 1`
4952 cleanup_101a() {
4953         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
4954         trap 0
4955 }
4956
4957 test_101a() {
4958         local s
4959         local discard
4960         local nreads=10000
4961         [ "$CPU" = "UML" ] && nreads=1000
4962         local cache_limit=32
4963
4964         $LCTL set_param -n osc.*-osc*.rpc_stats 0
4965         trap cleanup_101a EXIT
4966         $LCTL set_param -n llite.*.read_ahead_stats 0
4967         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
4968
4969         #
4970         # randomly read 10000 of 64K chunks from file 3x 32MB in size
4971         #
4972         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
4973         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
4974
4975         discard=0
4976         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
4977                 get_named_value 'read but discarded' | cut -d" " -f1`; do
4978                         discard=$(($discard + $s))
4979         done
4980         cleanup_101a
4981
4982         if [ $(($discard * 10)) -gt $nreads ] ;then
4983                 $LCTL get_param osc.*-osc*.rpc_stats
4984                 $LCTL get_param llite.*.read_ahead_stats
4985                 error "too many ($discard) discarded pages"
4986         fi
4987         rm -f $DIR/$tfile || true
4988 }
4989 run_test 101a "check read-ahead for random reads ================"
4990
4991 setup_test101bc() {
4992         mkdir -p $DIR/$tdir
4993         STRIPE_SIZE=1048576
4994         STRIPE_COUNT=$OSTCOUNT
4995         STRIPE_OFFSET=0
4996
4997         local list=$(comma_list $(osts_nodes))
4998         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=0
4999         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable=0
5000
5001         trap cleanup_test101bc EXIT
5002         # prepare the read-ahead file
5003         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5004
5005         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
5006 }
5007
5008 cleanup_test101bc() {
5009         trap 0
5010         rm -rf $DIR/$tdir
5011         rm -f $DIR/$tfile
5012
5013         local list=$(comma_list $(osts_nodes))
5014         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=1
5015         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable=1
5016 }
5017
5018 calc_total() {
5019         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5020 }
5021
5022 ra_check_101() {
5023         local READ_SIZE=$1
5024         local STRIPE_SIZE=1048576
5025         local RA_INC=1048576
5026         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5027         local FILE_LENGTH=$((64*100))
5028         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5029                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5030         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5031                         get_named_value 'read but discarded' | \
5032                         cut -d" " -f1 | calc_total`
5033         if [ $DISCARD -gt $discard_limit ]; then
5034                 $LCTL get_param llite.*.read_ahead_stats
5035                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5036         else
5037                 echo "Read-ahead success for size ${READ_SIZE}"
5038         fi
5039 }
5040
5041 test_101b() {
5042         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5043         local STRIPE_SIZE=1048576
5044         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5045         local FILE_LENGTH=$((STRIPE_SIZE*100))
5046         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
5047         # prepare the read-ahead file
5048         setup_test101bc
5049         cancel_lru_locks osc
5050         for BIDX in 2 4 8 16 32 64 128 256
5051         do
5052                 local BSIZE=$((BIDX*4096))
5053                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5054                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5055                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5056                 $LCTL set_param -n llite.*.read_ahead_stats 0
5057                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5058                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5059                 cancel_lru_locks osc
5060                 ra_check_101 $BSIZE
5061         done
5062         cleanup_test101bc
5063         true
5064 }
5065 run_test 101b "check stride-io mode read-ahead ================="
5066
5067 test_101c() {
5068     local STRIPE_SIZE=1048576
5069     local FILE_LENGTH=$((STRIPE_SIZE*100))
5070     local nreads=10000
5071     local osc
5072
5073     setup_test101bc
5074
5075     cancel_lru_locks osc
5076     $LCTL set_param osc.*.rpc_stats 0
5077     $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
5078     for osc in $($LCTL get_param -N osc.*); do
5079         if [ "$osc" == "osc.num_refs" ]; then
5080             continue
5081         fi
5082
5083         local lines=$($LCTL get_param -n ${osc}.rpc_stats | wc | awk '{print $1}')
5084         if [ $lines -le 20 ]; then
5085             continue
5086         fi
5087
5088         local rpc4k=$($LCTL get_param -n ${osc}.rpc_stats |
5089                                      awk '$1 == "1:" { print $2; exit; }')
5090         local rpc8k=$($LCTL get_param -n ${osc}.rpc_stats |
5091                                      awk '$1 == "2:" { print $2; exit; }')
5092         local rpc16k=$($LCTL get_param -n ${osc}.rpc_stats |
5093                                      awk '$1 == "4:" { print $2; exit; }')
5094         local rpc32k=$($LCTL get_param -n ${osc}.rpc_stats |
5095                                      awk '$1 == "8:" { print $2; exit; }')
5096
5097         [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
5098         [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
5099         [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
5100         [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
5101         echo "${osc} rpc check passed!"
5102     done
5103     cleanup_test101bc
5104     true
5105 }
5106 run_test 101c "check stripe_size aligned read-ahead ================="
5107
5108 set_read_ahead() {
5109    $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
5110    $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
5111 }
5112
5113 test_101d() {
5114     local file=$DIR/$tfile
5115     local size=${FILESIZE_101c:-500}
5116     local ra_MB=${READAHEAD_MB:-40}
5117
5118     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5119     [ $space -gt $((size / 1024)) ] ||
5120         { skip "Need free space ${size}M, have $space" && return; }
5121
5122     echo Creating ${size}M test file $file
5123     dd if=/dev/zero of=$file bs=1M count=$size
5124     echo Cancel LRU locks on lustre client to flush the client cache
5125     cancel_lru_locks osc
5126
5127     echo Disable read-ahead
5128     local old_READAHEAD=$(set_read_ahead 0)
5129
5130     echo Reading the test file $file with read-ahead disabled
5131     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5132
5133     echo Cancel LRU locks on lustre client to flush the client cache
5134     cancel_lru_locks osc
5135     echo Enable read-ahead with ${ra_MB}MB
5136     set_read_ahead $ra_MB
5137
5138     echo Reading the test file $file with read-ahead enabled
5139     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5140
5141     echo read-ahead disabled time read $time_ra_OFF
5142     echo read-ahead enabled  time read $time_ra_ON
5143
5144     set_read_ahead $old_READAHEAD
5145     rm -f $file
5146
5147     [ $time_ra_ON -lt $time_ra_OFF ] ||
5148         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
5149                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
5150 }
5151 run_test 101d "file read with and without read-ahead enabled  ================="
5152
5153 test_101e() {
5154     local file=$DIR/$tfile
5155     local size=500  #KB
5156     local count=100
5157     local blksize=1024
5158
5159     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5160     local need_space=$((count * size))
5161     [ $space -gt $need_space ] ||
5162         { skip_env "Need free space $need_space, have $space" && return; }
5163
5164     echo Creating $count ${size}K test files
5165     for ((i = 0; i < $count; i++)); do
5166         dd if=/dev/zero of=${file}_${i} bs=$blksize count=$size 2>/dev/null
5167     done
5168
5169     echo Cancel LRU locks on lustre client to flush the client cache
5170     cancel_lru_locks osc
5171
5172     echo Reset readahead stats
5173     $LCTL set_param -n llite.*.read_ahead_stats 0
5174
5175     for ((i = 0; i < $count; i++)); do
5176         dd if=${file}_${i} of=/dev/null bs=$blksize count=$size 2>/dev/null
5177     done
5178
5179     local miss=$($LCTL get_param -n llite.*.read_ahead_stats | \
5180           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5181
5182     for ((i = 0; i < $count; i++)); do
5183         rm -rf ${file}_${i} 2>/dev/null
5184     done
5185
5186     #10000 means 20% reads are missing in readahead
5187     [ $miss -lt 10000 ] ||  error "misses too much for small reads"
5188 }
5189 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
5190
5191 cleanup_test101f() {
5192     trap 0
5193     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
5194     rm -rf $DIR/$tfile 2>/dev/null
5195 }
5196
5197 test_101f() {
5198     local file=$DIR/$tfile
5199     local nreads=1000
5200
5201     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
5202     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
5203     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
5204     trap cleanup_test101f EXIT
5205
5206     echo Cancel LRU locks on lustre client to flush the client cache
5207     cancel_lru_locks osc
5208
5209     echo Reset readahead stats
5210     $LCTL set_param -n llite.*.read_ahead_stats 0
5211     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
5212     # readahead should read in 2M file on second read, so only miss
5213     # 2 pages.
5214     echo Random 4K reads on 2M file for 1000 times
5215     $READS -f $file -s 2097152 -b 4096 -n $nreads
5216
5217     echo checking missing pages
5218     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
5219           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5220
5221     [ $miss -lt 3 ] || error "misses too much pages!"
5222     cleanup_test101f
5223 }
5224 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
5225
5226 setup_test102() {
5227         mkdir -p $DIR/$tdir
5228         chown $RUNAS_ID $DIR/$tdir
5229         STRIPE_SIZE=65536
5230         STRIPE_OFFSET=1
5231         STRIPE_COUNT=$OSTCOUNT
5232         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
5233
5234         trap cleanup_test102 EXIT
5235         cd $DIR
5236         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
5237         cd $DIR/$tdir
5238         for num in 1 2 3 4; do
5239                 for count in $(seq 1 $STRIPE_COUNT); do
5240                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
5241                                 local size=`expr $STRIPE_SIZE \* $num`
5242                                 local file=file"$num-$idx-$count"
5243                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
5244                         done
5245                 done
5246         done
5247
5248         cd $DIR
5249         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
5250 }
5251
5252 cleanup_test102() {
5253         trap 0
5254         rm -f $TMP/f102.tar
5255         rm -rf $DIR/d0.sanity/d102
5256 }
5257
5258 test_102a() {
5259         local testfile=$DIR/xattr_testfile
5260
5261         touch $testfile
5262
5263         [ "$UID" != 0 ] && skip_env "must run as root" && return
5264         [ -z "`lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr`" ] &&
5265                 skip_env "must have user_xattr" && return
5266
5267         [ -z "$(which setfattr 2>/dev/null)" ] &&
5268                 skip_env "could not find setfattr" && return
5269
5270         echo "set/get xattr..."
5271         setfattr -n trusted.name1 -v value1 $testfile || error
5272         getfattr -n trusted.name1 $testfile 2> /dev/null |
5273           grep "trusted.name1=.value1" ||
5274                 error "$testfile missing trusted.name1=value1"
5275
5276         setfattr -n user.author1 -v author1 $testfile || error
5277         getfattr -n user.author1 $testfile 2> /dev/null |
5278           grep "user.author1=.author1" ||
5279                 error "$testfile missing trusted.author1=author1"
5280
5281         echo "listxattr..."
5282         setfattr -n trusted.name2 -v value2 $testfile ||
5283                 error "$testfile unable to set trusted.name2"
5284         setfattr -n trusted.name3 -v value3 $testfile ||
5285                 error "$testfile unable to set trusted.name3"
5286         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
5287             grep "trusted.name" | wc -l) -eq 3 ] ||
5288                 error "$testfile missing 3 trusted.name xattrs"
5289
5290         setfattr -n user.author2 -v author2 $testfile ||
5291                 error "$testfile unable to set user.author2"
5292         setfattr -n user.author3 -v author3 $testfile ||
5293                 error "$testfile unable to set user.author3"
5294         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
5295             grep "user.author" | wc -l) -eq 3 ] ||
5296                 error "$testfile missing 3 user.author xattrs"
5297
5298         echo "remove xattr..."
5299         setfattr -x trusted.name1 $testfile ||
5300                 error "$testfile error deleting trusted.name1"
5301         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
5302                 error "$testfile did not delete trusted.name1 xattr"
5303
5304         setfattr -x user.author1 $testfile ||
5305                 error "$testfile error deleting user.author1"
5306         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
5307                 error "$testfile did not delete trusted.name1 xattr"
5308
5309         # b10667: setting lustre special xattr be silently discarded
5310         echo "set lustre special xattr ..."
5311         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
5312                 error "$testfile allowed setting trusted.lov"
5313 }
5314 run_test 102a "user xattr test =================================="
5315
5316 test_102b() {
5317         # b10930: get/set/list trusted.lov xattr
5318         echo "get/set/list trusted.lov xattr ..."
5319         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5320         local testfile=$DIR/$tfile
5321         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
5322                 error "setstripe failed"
5323         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
5324                 error "getstripe failed"
5325         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
5326         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
5327
5328         local testfile2=${testfile}2
5329         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
5330                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
5331
5332         $MCREATE $testfile2
5333         setfattr -n trusted.lov -v $value $testfile2
5334         local stripe_size=$($GETSTRIPE -S $testfile2)
5335         local stripe_count=$($GETSTRIPE -c $testfile2)
5336         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
5337         [ $stripe_count -eq $STRIPECOUNT ] ||
5338                 error "stripe count $stripe_count != $STRIPECOUNT"
5339         rm -f $DIR/$tfile
5340 }
5341 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
5342
5343 test_102c() {
5344         # b10930: get/set/list lustre.lov xattr
5345         echo "get/set/list lustre.lov xattr ..."
5346         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5347         mkdir -p $DIR/$tdir
5348         chown $RUNAS_ID $DIR/$tdir
5349         local testfile=$DIR/$tdir/$tfile
5350         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
5351                 error "setstripe failed"
5352         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
5353                 error "getstripe failed"
5354         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
5355         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
5356
5357         local testfile2=${testfile}2
5358         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
5359                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
5360
5361         $RUNAS $MCREATE $testfile2
5362         $RUNAS setfattr -n lustre.lov -v $value $testfile2
5363         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
5364         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
5365         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
5366         [ $stripe_count -eq $STRIPECOUNT ] ||
5367                 error "stripe count $stripe_count != $STRIPECOUNT"
5368 }
5369 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
5370
5371 compare_stripe_info1() {
5372         local stripe_index_all_zero=true
5373
5374         for num in 1 2 3 4; do
5375                 for count in $(seq 1 $STRIPE_COUNT); do
5376                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
5377                                 local size=$((STRIPE_SIZE * num))
5378                                 local file=file"$num-$offset-$count"
5379                                 stripe_size=$(lfs getstripe -S $PWD/$file)
5380                                 [ $stripe_size -ne $size ] &&
5381                                     error "$file: size $stripe_size != $size"
5382                                 stripe_count=$(lfs getstripe -c $PWD/$file)
5383                                 # allow fewer stripes to be created, ORI-601
5384                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
5385                                     error "$file: count $stripe_count != $count"
5386                                 stripe_index=$(lfs getstripe -i $PWD/$file)
5387                                 [ $stripe_index -ne 0 ] &&
5388                                         stripe_index_all_zero=false
5389                         done
5390                 done
5391         done
5392         $stripe_index_all_zero &&
5393                 error "all files are being extracted starting from OST index 0"
5394         return 0
5395 }
5396
5397 find_lustre_tar() {
5398         [ -n "$(which tar 2>/dev/null)" ] &&
5399                 strings $(which tar) | grep -q "lustre" && echo tar
5400 }
5401
5402 test_102d() {
5403         # b10930: tar test for trusted.lov xattr
5404         TAR=$(find_lustre_tar)
5405         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5406         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5407         setup_test102
5408         mkdir -p $DIR/d102d
5409         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
5410         cd $DIR/d102d/$tdir
5411         compare_stripe_info1
5412 }
5413 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
5414
5415 test_102f() {
5416         # b10930: tar test for trusted.lov xattr
5417         TAR=$(find_lustre_tar)
5418         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5419         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5420         setup_test102
5421         mkdir -p $DIR/d102f
5422         cd $DIR
5423         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
5424         cd $DIR/d102f/$tdir
5425         compare_stripe_info1
5426 }
5427 run_test 102f "tar copy files, not keep osts ==========="
5428
5429 grow_xattr() {
5430         local xsize=${1:-1024}  # in bytes
5431         local file=$DIR/$tfile
5432
5433         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
5434                 skip "must have user_xattr" && return 0
5435         [ -z "$(which setfattr 2>/dev/null)" ] &&
5436                 skip_env "could not find setfattr" && return 0
5437         [ -z "$(which getfattr 2>/dev/null)" ] &&
5438                 skip_env "could not find getfattr" && return 0
5439
5440         touch $file
5441
5442         local value="$(generate_string $xsize)"
5443
5444         local xbig=trusted.big
5445         log "save $xbig on $file"
5446         setfattr -n $xbig -v $value $file ||
5447                 error "saving $xbig on $file failed"
5448
5449         local orig=$(get_xattr_value $xbig $file)
5450         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
5451
5452         local xsml=trusted.sml
5453         log "save $xsml on $file"
5454         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
5455
5456         local new=$(get_xattr_value $xbig $file)
5457         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
5458
5459         log "grow $xsml on $file"
5460         setfattr -n $xsml -v "$value" $file ||
5461                 error "growing $xsml on $file failed"
5462
5463         new=$(get_xattr_value $xbig $file)
5464         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
5465         log "$xbig still valid after growing $xsml"
5466
5467         rm -f $file
5468 }
5469
5470 test_102h() { # bug 15777
5471         grow_xattr 1024
5472 }
5473 run_test 102h "grow xattr from inside inode to external block"
5474
5475 test_102ha() {
5476         large_xattr_enabled || { skip "large_xattr disabled" && return; }
5477         grow_xattr $(max_xattr_size)
5478 }
5479 run_test 102ha "grow xattr from inside inode to external inode"
5480
5481 test_102i() { # bug 17038
5482         touch $DIR/$tfile
5483         ln -s $DIR/$tfile $DIR/${tfile}link
5484         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
5485         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"
5486         rm -f $DIR/$tfile $DIR/${tfile}link
5487 }
5488 run_test 102i "lgetxattr test on symbolic link ============"
5489
5490 test_102j() {
5491         TAR=$(find_lustre_tar)
5492         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5493         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5494         setup_test102 "$RUNAS"
5495         mkdir -p $DIR/d102j
5496         chown $RUNAS_ID $DIR/d102j
5497         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
5498         cd $DIR/d102j/$tdir
5499         compare_stripe_info1 "$RUNAS"
5500 }
5501 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
5502
5503 test_102k() {
5504         touch $DIR/$tfile
5505         # b22187 just check that does not crash for regular file.
5506         setfattr -n trusted.lov $DIR/$tfile
5507         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
5508         local test_kdir=$DIR/d102k
5509         mkdir $test_kdir
5510         local default_size=`$GETSTRIPE -S $test_kdir`
5511         local default_count=`$GETSTRIPE -c $test_kdir`
5512         local default_offset=`$GETSTRIPE -i $test_kdir`
5513         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $test_kdir ||
5514                 error 'dir setstripe failed'
5515         setfattr -n trusted.lov $test_kdir
5516         local stripe_size=`$GETSTRIPE -S $test_kdir`
5517         local stripe_count=`$GETSTRIPE -c $test_kdir`
5518         local stripe_offset=`$GETSTRIPE -i $test_kdir`
5519         [ $stripe_size -eq $default_size ] ||
5520                 error "stripe size $stripe_size != $default_size"
5521         [ $stripe_count -eq $default_count ] ||
5522                 error "stripe count $stripe_count != $default_count"
5523         [ $stripe_offset -eq $default_offset ] ||
5524                 error "stripe offset $stripe_offset != $default_offset"
5525         rm -rf $DIR/$tfile $test_kdir
5526 }
5527 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
5528
5529 test_102l() {
5530         # LU-532 trusted. xattr is invisible to non-root
5531         local testfile=$DIR/$tfile
5532
5533         touch $testfile
5534
5535         echo "listxattr as user..."
5536         chown $RUNAS_ID $testfile
5537         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
5538             grep -q "trusted" &&
5539                 error "$testfile trusted xattrs are user visible"
5540
5541         return 0;
5542 }
5543 run_test 102l "listxattr filter test =================================="
5544
5545 cleanup_test102
5546
5547 run_acl_subtest()
5548 {
5549     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
5550     return $?
5551 }
5552
5553 test_103 () {
5554     [ "$UID" != 0 ] && skip_env "must run as root" && return
5555     [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
5556     [ -z "$(which setfacl 2>/dev/null)" ] && skip_env "could not find setfacl" && return
5557     $GSS && skip "could not run under gss" && return
5558
5559     declare -a identity_old
5560
5561     for num in `seq $MDSCOUNT`; do
5562         switch_identity $num true || identity_old[$num]=$?
5563     done
5564
5565     SAVE_UMASK=`umask`
5566     umask 0022
5567     cd $DIR
5568
5569     echo "performing cp ..."
5570     run_acl_subtest cp || error
5571     echo "performing getfacl-noacl..."
5572     run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
5573     echo "performing misc..."
5574     run_acl_subtest misc || error  "misc test failed"
5575     echo "performing permissions..."
5576     run_acl_subtest permissions || error "permissions failed"
5577     echo "performing setfacl..."
5578     run_acl_subtest setfacl || error  "setfacl test failed"
5579
5580     # inheritance test got from HP
5581     echo "performing inheritance..."
5582     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
5583     chmod +x make-tree || error "chmod +x failed"
5584     run_acl_subtest inheritance || error "inheritance test failed"
5585     rm -f make-tree
5586
5587     cd $SAVE_PWD
5588     umask $SAVE_UMASK
5589
5590     for num in `seq $MDSCOUNT`; do
5591         if [ "${identity_old[$num]}" = 1 ]; then
5592             switch_identity $num false || identity_old[$num]=$?
5593         fi
5594     done
5595 }
5596 run_test 103 "acl test ========================================="
5597
5598 test_104a() {
5599         touch $DIR/$tfile
5600         lfs df || error "lfs df failed"
5601         lfs df -ih || error "lfs df -ih failed"
5602         lfs df -h $DIR || error "lfs df -h $DIR failed"
5603         lfs df -i $DIR || error "lfs df -i $DIR failed"
5604         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
5605         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
5606
5607         OSC=`lctl dl |grep OST0000-osc-[^M] |awk '{print $4}'`
5608         lctl --device %$OSC deactivate
5609         lfs df || error "lfs df with deactivated OSC failed"
5610         lctl --device %$OSC activate
5611         # wait the osc back to normal
5612         wait_osc_import_state client ost FULL
5613
5614         lfs df || error "lfs df with reactivated OSC failed"
5615         rm -f $DIR/$tfile
5616 }
5617 run_test 104a "lfs df [-ih] [path] test ========================="
5618
5619 test_104b() {
5620         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5621         chmod 666 /dev/obd
5622         denied_cnt=$((`$RUNAS $LFS check servers 2>&1 | grep "Permission denied" | wc -l`))
5623         if [ $denied_cnt -ne 0 ];
5624         then
5625                     error "lfs check servers test failed"
5626         fi
5627 }
5628 run_test 104b "$RUNAS lfs check servers test ===================="
5629
5630 test_105a() {
5631         # doesn't work on 2.4 kernels
5632         touch $DIR/$tfile
5633         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5634         then
5635                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
5636         else
5637                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
5638         fi
5639         rm -f $DIR/$tfile
5640 }
5641 run_test 105a "flock when mounted without -o flock test ========"
5642
5643 test_105b() {
5644         touch $DIR/$tfile
5645         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5646         then
5647                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
5648         else
5649                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
5650         fi
5651         rm -f $DIR/$tfile
5652 }
5653 run_test 105b "fcntl when mounted without -o flock test ========"
5654
5655 test_105c() {
5656         touch $DIR/$tfile
5657         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5658         then
5659                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
5660         else
5661                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
5662         fi
5663         rm -f $DIR/$tfile
5664 }
5665 run_test 105c "lockf when mounted without -o flock test ========"
5666
5667 test_105d() { # bug 15924
5668         mkdir -p $DIR/$tdir
5669         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
5670                 skip "mount w/o flock enabled" && return
5671         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
5672         $LCTL set_param fail_loc=0x80000315
5673         flocks_test 2 $DIR/$tdir
5674 }
5675 run_test 105d "flock race (should not freeze) ========"
5676
5677 test_105e() { # bug 22660 && 22040
5678         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
5679                 skip "mount w/o flock enabled" && return
5680         touch $DIR/$tfile
5681         flocks_test 3 $DIR/$tfile
5682 }
5683 run_test 105e "Two conflicting flocks from same process ======="
5684
5685 test_106() { #bug 10921
5686         mkdir -p $DIR/$tdir
5687         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
5688         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
5689 }
5690 run_test 106 "attempt exec of dir followed by chown of that dir"
5691
5692 test_107() {
5693         CDIR=`pwd`
5694         cd $DIR
5695
5696         local file=core
5697         rm -f $file
5698
5699         local save_pattern=$(sysctl -n kernel.core_pattern)
5700         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
5701         sysctl -w kernel.core_pattern=$file
5702         sysctl -w kernel.core_uses_pid=0
5703
5704         ulimit -c unlimited
5705         sleep 60 &
5706         SLEEPPID=$!
5707
5708         sleep 1
5709
5710         kill -s 11 $SLEEPPID
5711         wait $SLEEPPID
5712         if [ -e $file ]; then
5713                 size=`stat -c%s $file`
5714                 [ $size -eq 0 ] && error "Fail to create core file $file"
5715         else
5716                 error "Fail to create core file $file"
5717         fi
5718         rm -f $file
5719         sysctl -w kernel.core_pattern=$save_pattern
5720         sysctl -w kernel.core_uses_pid=$save_uses_pid
5721         cd $CDIR
5722 }
5723 run_test 107 "Coredump on SIG"
5724
5725 test_110() {
5726         mkdir -p $DIR/d110
5727         mkdir $DIR/d110/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || error "mkdir with 255 char fail"
5728         mkdir $DIR/d110/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && error "mkdir with 256 char should fail, but not"
5729         touch $DIR/d110/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx || error "create with 255 char fail"
5730         touch $DIR/d110/yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy && error ""create with 256 char should fail, but not
5731
5732         ls -l $DIR/d110
5733     rm -fr $DIR/d110
5734 }
5735 run_test 110 "filename length checking"
5736
5737 test_115() {
5738         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
5739             cut -c11-20)
5740         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
5741             return
5742         echo "Starting with $OSTIO_pre threads"
5743
5744         NUMTEST=20000
5745         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
5746         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
5747         echo "$NUMTEST creates/unlinks"
5748         mkdir -p $DIR/$tdir
5749         createmany -o $DIR/$tdir/$tfile $NUMTEST
5750         unlinkmany $DIR/$tdir/$tfile $NUMTEST
5751
5752         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
5753             cut -c11-20)
5754
5755         # don't return an error
5756         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
5757             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&\
5758             echo "This may be fine, depending on what ran before this test" &&\
5759             echo "and how fast this system is." && return
5760
5761         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
5762 }
5763 run_test 115 "verify dynamic thread creation===================="
5764
5765 free_min_max () {
5766         wait_delete_completed
5767         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
5768         echo OST kbytes available: ${AVAIL[@]}
5769         MAXI=0; MAXV=${AVAIL[0]}
5770         MINI=0; MINV=${AVAIL[0]}
5771         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
5772             #echo OST $i: ${AVAIL[i]}kb
5773             if [ ${AVAIL[i]} -gt $MAXV ]; then
5774                 MAXV=${AVAIL[i]}; MAXI=$i
5775             fi
5776             if [ ${AVAIL[i]} -lt $MINV ]; then
5777                 MINV=${AVAIL[i]}; MINI=$i
5778             fi
5779         done
5780         echo Min free space: OST $MINI: $MINV
5781         echo Max free space: OST $MAXI: $MAXV
5782 }
5783
5784 test_116() {
5785         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
5786
5787         echo -n "Free space priority "
5788         lctl get_param -n lov.*-clilov-*.qos_prio_free
5789         declare -a AVAIL
5790         free_min_max
5791         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI, skip" &&\
5792                 return
5793
5794         # generate uneven OSTs
5795         mkdir -p $DIR/$tdir/OST${MINI}
5796         declare -i FILL
5797         FILL=$(($MINV / 4))
5798         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
5799         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
5800         i=0
5801         while [ $FILL -gt 0 ]; do
5802             i=$(($i + 1))
5803             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
5804             FILL=$(($FILL - 2048))
5805             echo -n .
5806         done
5807         FILL=$(($MINV / 4))
5808         sync
5809         sleep_maxage
5810
5811         free_min_max
5812         DIFF=$(($MAXV - $MINV))
5813         DIFF2=$(($DIFF * 100 / $MINV))
5814         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
5815         if [ $DIFF2 -gt 20 ]; then
5816             echo "ok"
5817         else
5818             echo "failed - QOS mode won't be used"
5819             error_ignore "QOS imbalance criteria not met"
5820             return
5821         fi
5822
5823         MINI1=$MINI; MINV1=$MINV
5824         MAXI1=$MAXI; MAXV1=$MAXV
5825
5826         # now fill using QOS
5827         echo writing a bunch of files to QOS-assigned OSTs
5828         $SETSTRIPE -c 1 $DIR/$tdir
5829         i=0
5830         while [ $FILL -gt 0 ]; do
5831             i=$(($i + 1))
5832             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
5833             FILL=$(($FILL - 200))
5834             echo -n .
5835         done
5836         echo "wrote $i 200k files"
5837         sync
5838         sleep_maxage
5839
5840         echo "Note: free space may not be updated, so measurements might be off"
5841         free_min_max
5842         DIFF2=$(($MAXV - $MINV))
5843         echo "free space delta: orig $DIFF final $DIFF2"
5844         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
5845         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
5846         echo "Wrote $DIFF to smaller OST $MINI1"
5847         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
5848         echo "Wrote $DIFF2 to larger OST $MAXI1"
5849         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
5850
5851         # Figure out which files were written where
5852         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
5853                awk '/'$MINI1': / {print $2; exit}')
5854         echo $UUID
5855         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
5856         echo "$MINC files created on smaller OST $MINI1"
5857         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
5858                awk '/'$MAXI1': / {print $2; exit}')
5859         echo $UUID
5860         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
5861         echo "$MAXC files created on larger OST $MAXI1"
5862         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
5863         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
5864
5865         rm -rf $DIR/$tdir
5866 }
5867 run_test 116 "stripe QOS: free space balance ==================="
5868
5869 test_117() # bug 10891
5870 {
5871         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
5872         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
5873         lctl set_param fail_loc=0x21e
5874         > $DIR/$tfile || error "truncate failed"
5875         lctl set_param fail_loc=0
5876         echo "Truncate succeeded."
5877         rm -f $DIR/$tfile
5878 }
5879 run_test 117 "verify fsfilt_extend =========="
5880
5881 export OLD_RESENDCOUNT=""
5882 set_resend_count () {
5883         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
5884         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
5885         lctl set_param -n $PROC_RESENDCOUNT $1
5886         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
5887 }
5888
5889 [ "$SLOW" = "no" ] && set_resend_count 4 # for reduce test_118* time (bug 14842)
5890
5891 # Reset async IO behavior after error case
5892 reset_async() {
5893         FILE=$DIR/reset_async
5894
5895         # Ensure all OSCs are cleared
5896         $SETSTRIPE -c -1 $FILE
5897         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
5898         sync
5899         rm $FILE
5900 }
5901
5902 test_118a() #bug 11710
5903 {
5904         reset_async
5905
5906         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5907         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
5908         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
5909
5910         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5911                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5912                 return 1;
5913         fi
5914         rm -f $DIR/$tfile
5915 }
5916 run_test 118a "verify O_SYNC works =========="
5917
5918 test_118b()
5919 {
5920         remote_ost_nodsh && skip "remote OST with nodsh" && return
5921
5922         reset_async
5923
5924         #define OBD_FAIL_OST_ENOENT 0x217
5925         set_nodes_failloc "$(osts_nodes)" 0x217
5926         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5927         RC=$?
5928         set_nodes_failloc "$(osts_nodes)" 0
5929         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
5930         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
5931                     grep -c writeback)
5932
5933         if [[ $RC -eq 0 ]]; then
5934                 error "Must return error due to dropped pages, rc=$RC"
5935                 return 1;
5936         fi
5937
5938         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5939                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5940                 return 1;
5941         fi
5942
5943         echo "Dirty pages not leaked on ENOENT"
5944
5945         # Due to the above error the OSC will issue all RPCs syncronously
5946         # until a subsequent RPC completes successfully without error.
5947         multiop $DIR/$tfile Ow4096yc
5948         rm -f $DIR/$tfile
5949
5950         return 0
5951 }
5952 run_test 118b "Reclaim dirty pages on fatal error =========="
5953
5954 test_118c()
5955 {
5956         remote_ost_nodsh && skip "remote OST with nodsh" && return
5957
5958         reset_async
5959
5960         #define OBD_FAIL_OST_EROFS               0x216
5961         set_nodes_failloc "$(osts_nodes)" 0x216
5962
5963         # multiop should block due to fsync until pages are written
5964         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
5965         MULTIPID=$!
5966         sleep 1
5967
5968         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
5969                 error "Multiop failed to block on fsync, pid=$MULTIPID"
5970         fi
5971
5972         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
5973                     grep -c writeback)
5974         if [[ $WRITEBACK -eq 0 ]]; then
5975                 error "No page in writeback, writeback=$WRITEBACK"
5976         fi
5977
5978         set_nodes_failloc "$(osts_nodes)" 0
5979         wait $MULTIPID
5980         RC=$?
5981         if [[ $RC -ne 0 ]]; then
5982                 error "Multiop fsync failed, rc=$RC"
5983         fi
5984
5985         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
5986         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
5987                     grep -c writeback)
5988         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5989                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5990         fi
5991
5992         rm -f $DIR/$tfile
5993         echo "Dirty pages flushed via fsync on EROFS"
5994         return 0
5995 }
5996 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
5997
5998 test_118d()
5999 {
6000         remote_ost_nodsh && skip "remote OST with nodsh" && return
6001
6002         reset_async
6003
6004         #define OBD_FAIL_OST_BRW_PAUSE_BULK
6005         set_nodes_failloc "$(osts_nodes)" 0x214
6006         # multiop should block due to fsync until pages are written
6007         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6008         MULTIPID=$!
6009         sleep 1
6010
6011         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6012                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6013         fi
6014
6015         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6016                     grep -c writeback)
6017         if [[ $WRITEBACK -eq 0 ]]; then
6018                 error "No page in writeback, writeback=$WRITEBACK"
6019         fi
6020
6021         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
6022         set_nodes_failloc "$(osts_nodes)" 0
6023
6024         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6025         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6026                     grep -c writeback)
6027         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6028                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6029         fi
6030
6031         rm -f $DIR/$tfile
6032         echo "Dirty pages gaurenteed flushed via fsync"
6033         return 0
6034 }
6035 run_test 118d "Fsync validation inject a delay of the bulk =========="
6036
6037 test_118f() {
6038         reset_async
6039
6040         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
6041         lctl set_param fail_loc=0x8000040a
6042
6043         # Should simulate EINVAL error which is fatal
6044         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6045         RC=$?
6046         if [[ $RC -eq 0 ]]; then
6047                 error "Must return error due to dropped pages, rc=$RC"
6048         fi
6049
6050         lctl set_param fail_loc=0x0
6051
6052         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6053         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6054         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6055                     grep -c writeback)
6056         if [[ $LOCKED -ne 0 ]]; then
6057                 error "Locked pages remain in cache, locked=$LOCKED"
6058         fi
6059
6060         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6061                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6062         fi
6063
6064         rm -f $DIR/$tfile
6065         echo "No pages locked after fsync"
6066
6067         reset_async
6068         return 0
6069 }
6070 run_test 118f "Simulate unrecoverable OSC side error =========="
6071
6072 test_118g() {
6073         reset_async
6074
6075         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
6076         lctl set_param fail_loc=0x406
6077
6078         # simulate local -ENOMEM
6079         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6080         RC=$?
6081
6082         lctl set_param fail_loc=0
6083         if [[ $RC -eq 0 ]]; then
6084                 error "Must return error due to dropped pages, rc=$RC"
6085         fi
6086
6087         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6088         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6089         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6090                         grep -c writeback)
6091         if [[ $LOCKED -ne 0 ]]; then
6092                 error "Locked pages remain in cache, locked=$LOCKED"
6093         fi
6094
6095         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6096                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6097         fi
6098
6099         rm -f $DIR/$tfile
6100         echo "No pages locked after fsync"
6101
6102         reset_async
6103         return 0
6104 }
6105 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
6106
6107 test_118h() {
6108         remote_ost_nodsh && skip "remote OST with nodsh" && return
6109
6110         reset_async
6111
6112         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6113         set_nodes_failloc "$(osts_nodes)" 0x20e
6114         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6115         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6116         RC=$?
6117
6118         set_nodes_failloc "$(osts_nodes)" 0
6119         if [[ $RC -eq 0 ]]; then
6120                 error "Must return error due to dropped pages, rc=$RC"
6121         fi
6122
6123         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6124         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6125         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6126                     grep -c writeback)
6127         if [[ $LOCKED -ne 0 ]]; then
6128                 error "Locked pages remain in cache, locked=$LOCKED"
6129         fi
6130
6131         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6132                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6133         fi
6134
6135         rm -f $DIR/$tfile
6136         echo "No pages locked after fsync"
6137
6138         return 0
6139 }
6140 run_test 118h "Verify timeout in handling recoverables errors  =========="
6141
6142 test_118i() {
6143         remote_ost_nodsh && skip "remote OST with nodsh" && return
6144
6145         reset_async
6146
6147         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6148         set_nodes_failloc "$(osts_nodes)" 0x20e
6149
6150         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6151         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6152         PID=$!
6153         sleep 5
6154         set_nodes_failloc "$(osts_nodes)" 0
6155
6156         wait $PID
6157         RC=$?
6158         if [[ $RC -ne 0 ]]; then
6159                 error "got error, but should be not, rc=$RC"
6160         fi
6161
6162         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6163         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6164         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6165         if [[ $LOCKED -ne 0 ]]; then
6166                 error "Locked pages remain in cache, locked=$LOCKED"
6167         fi
6168
6169         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6170                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6171         fi
6172
6173         rm -f $DIR/$tfile
6174         echo "No pages locked after fsync"
6175
6176         return 0
6177 }
6178 run_test 118i "Fix error before timeout in recoverable error  =========="
6179
6180 test_118j() {
6181         remote_ost_nodsh && skip "remote OST with nodsh" && return
6182
6183         reset_async
6184
6185         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
6186         set_nodes_failloc "$(osts_nodes)" 0x220
6187
6188         # return -EIO from OST
6189         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6190         RC=$?
6191         set_nodes_failloc "$(osts_nodes)" 0x0
6192         if [[ $RC -eq 0 ]]; then
6193                 error "Must return error due to dropped pages, rc=$RC"
6194         fi
6195
6196         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6197         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6198         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6199         if [[ $LOCKED -ne 0 ]]; then
6200                 error "Locked pages remain in cache, locked=$LOCKED"
6201         fi
6202
6203         # in recoverable error on OST we want resend and stay until it finished
6204         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6205                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6206         fi
6207
6208         rm -f $DIR/$tfile
6209         echo "No pages locked after fsync"
6210
6211         return 0
6212 }
6213 run_test 118j "Simulate unrecoverable OST side error =========="
6214
6215 test_118k()
6216 {
6217         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
6218
6219         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6220         set_nodes_failloc "$(osts_nodes)" 0x20e
6221         mkdir -p $DIR/$tdir
6222
6223         for ((i=0;i<10;i++)); do
6224                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
6225                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
6226                 SLEEPPID=$!
6227                 sleep 0.500s
6228                 kill $SLEEPPID
6229                 wait $SLEEPPID
6230         done
6231
6232         set_nodes_failloc "$(osts_nodes)" 0
6233         rm -rf $DIR/$tdir
6234 }
6235 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
6236
6237 test_118l()
6238 {
6239         # LU-646
6240         mkdir -p $DIR/$tdir
6241         multiop $DIR/$tdir Dy || error "fsync dir failed"
6242         rm -rf $DIR/$tdir
6243 }
6244 run_test 118l "fsync dir ========="
6245
6246 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
6247
6248 test_119a() # bug 11737
6249 {
6250         BSIZE=$((512 * 1024))
6251         directio write $DIR/$tfile 0 1 $BSIZE
6252         # We ask to read two blocks, which is more than a file size.
6253         # directio will indicate an error when requested and actual
6254         # sizes aren't equeal (a normal situation in this case) and
6255         # print actual read amount.
6256         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
6257         if [ "$NOB" != "$BSIZE" ]; then
6258                 error "read $NOB bytes instead of $BSIZE"
6259         fi
6260         rm -f $DIR/$tfile
6261 }
6262 run_test 119a "Short directIO read must return actual read amount"
6263
6264 test_119b() # bug 11737
6265 {
6266         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6267
6268         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
6269         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
6270         sync
6271         multiop $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
6272                 error "direct read failed"
6273         rm -f $DIR/$tfile
6274 }
6275 run_test 119b "Sparse directIO read must return actual read amount"
6276
6277 test_119c() # bug 13099
6278 {
6279         BSIZE=1048576
6280         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
6281         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
6282         rm -f $DIR/$tfile
6283 }
6284 run_test 119c "Testing for direct read hitting hole"
6285
6286 test_119d() # bug 15950
6287 {
6288         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
6289         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
6290         BSIZE=1048576
6291         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
6292         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
6293         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
6294         lctl set_param fail_loc=0x40d
6295         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
6296         pid_dio=$!
6297         sleep 1
6298         cat $DIR/$tfile > /dev/null &
6299         lctl set_param fail_loc=0
6300         pid_reads=$!
6301         wait $pid_dio
6302         log "the DIO writes have completed, now wait for the reads (should not block very long)"
6303         sleep 2
6304         [ -n "`ps h -p $pid_reads -o comm`" ] && \
6305         error "the read rpcs have not completed in 2s"
6306         rm -f $DIR/$tfile
6307         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
6308 }
6309 run_test 119d "The DIO path should try to send a new rpc once one is completed"
6310
6311 test_120a() {
6312         mkdir -p $DIR/$tdir
6313         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6314                skip "no early lock cancel on server" && return 0
6315         lru_resize_disable mdc
6316         lru_resize_disable osc
6317         cancel_lru_locks mdc
6318         stat $DIR/$tdir > /dev/null
6319         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6320         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6321         mkdir $DIR/$tdir/d1
6322         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6323         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6324         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6325         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6326         lru_resize_enable mdc
6327         lru_resize_enable osc
6328 }
6329 run_test 120a "Early Lock Cancel: mkdir test"
6330
6331 test_120b() {
6332         mkdir -p $DIR/$tdir
6333         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6334                skip "no early lock cancel on server" && return 0
6335         lru_resize_disable mdc
6336         lru_resize_disable osc
6337         cancel_lru_locks mdc
6338         stat $DIR/$tdir > /dev/null
6339         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6340         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6341         touch $DIR/$tdir/f1
6342         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6343         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6344         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6345         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6346         lru_resize_enable mdc
6347         lru_resize_enable osc
6348 }
6349 run_test 120b "Early Lock Cancel: create test"
6350
6351 test_120c() {
6352         mkdir -p $DIR/$tdir
6353         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6354                skip "no early lock cancel on server" && return 0
6355         lru_resize_disable mdc
6356         lru_resize_disable osc
6357         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
6358         touch $DIR/$tdir/d1/f1
6359         cancel_lru_locks mdc
6360         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
6361         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6362         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6363         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
6364         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6365         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6366         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6367         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6368         lru_resize_enable mdc
6369         lru_resize_enable osc
6370 }
6371 run_test 120c "Early Lock Cancel: link test"
6372
6373 test_120d() {
6374         mkdir -p $DIR/$tdir
6375         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6376                skip "no early lock cancel on server" && return 0
6377         lru_resize_disable mdc
6378         lru_resize_disable osc
6379         touch $DIR/$tdir
6380         cancel_lru_locks mdc
6381         stat $DIR/$tdir > /dev/null
6382         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6383         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6384         chmod a+x $DIR/$tdir
6385         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6386         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6387         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6388         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6389         lru_resize_enable mdc
6390         lru_resize_enable osc
6391 }
6392 run_test 120d "Early Lock Cancel: setattr test"
6393
6394 test_120e() {
6395         mkdir -p $DIR/$tdir
6396         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6397                skip "no early lock cancel on server" && return 0
6398         lru_resize_disable mdc
6399         lru_resize_disable osc
6400         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
6401         cancel_lru_locks mdc
6402         cancel_lru_locks osc
6403         dd if=$DIR/$tdir/f1 of=/dev/null
6404         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
6405         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6406               awk '/ldlm_cancel/ {print $2}'`
6407         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6408               awk '/ldlm_bl_callback/ {print $2}'`
6409         unlink $DIR/$tdir/f1
6410         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6411               awk '/ldlm_cancel/ {print $2}'`
6412         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6413               awk '/ldlm_bl_callback/ {print $2}'`
6414         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6415         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6416         lru_resize_enable mdc
6417         lru_resize_enable osc
6418 }
6419 run_test 120e "Early Lock Cancel: unlink test"
6420
6421 test_120f() {
6422         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6423                skip "no early lock cancel on server" && return 0
6424         mkdir -p $DIR/$tdir
6425         lru_resize_disable mdc
6426         lru_resize_disable osc
6427         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
6428         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
6429         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
6430         cancel_lru_locks mdc
6431         cancel_lru_locks osc
6432         dd if=$DIR/$tdir/d1/f1 of=/dev/null
6433         dd if=$DIR/$tdir/d2/f2 of=/dev/null
6434         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
6435         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6436               awk '/ldlm_cancel/ {print $2}'`
6437         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6438               awk '/ldlm_bl_callback/ {print $2}'`
6439         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
6440         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6441               awk '/ldlm_cancel/ {print $2}'`
6442         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6443               awk '/ldlm_bl_callback/ {print $2}'`
6444         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6445         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6446         lru_resize_enable mdc
6447         lru_resize_enable osc
6448 }
6449 run_test 120f "Early Lock Cancel: rename test"
6450
6451 test_120g() {
6452         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6453                skip "no early lock cancel on server" && return 0
6454         lru_resize_disable mdc
6455         lru_resize_disable osc
6456         count=10000
6457         echo create $count files
6458         mkdir -p $DIR/$tdir
6459         cancel_lru_locks mdc
6460         cancel_lru_locks osc
6461         t0=`date +%s`
6462
6463         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6464               awk '/ldlm_cancel/ {print $2}'`
6465         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6466               awk '/ldlm_bl_callback/ {print $2}'`
6467         createmany -o $DIR/$tdir/f $count
6468         sync
6469         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6470               awk '/ldlm_cancel/ {print $2}'`
6471         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6472               awk '/ldlm_bl_callback/ {print $2}'`
6473         t1=`date +%s`
6474         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
6475         echo rm $count files
6476         rm -r $DIR/$tdir
6477         sync
6478         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6479               awk '/ldlm_cancel/ {print $2}'`
6480         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6481               awk '/ldlm_bl_callback/ {print $2}'`
6482         t2=`date +%s`
6483         echo total: $count removes in $((t2-t1))
6484         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
6485         sleep 2
6486         # wait for commitment of removal
6487         lru_resize_enable mdc
6488         lru_resize_enable osc
6489 }
6490 run_test 120g "Early Lock Cancel: performance test"
6491
6492 test_121() { #bug #10589
6493         rm -rf $DIR/$tfile
6494         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
6495 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
6496         lctl set_param fail_loc=0x310
6497         cancel_lru_locks osc > /dev/null
6498         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
6499         lctl set_param fail_loc=0
6500         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
6501 }
6502 run_test 121 "read cancel race ========="
6503
6504 test_123a() { # was test 123, statahead(bug 11401)
6505         SLOWOK=0
6506         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
6507             log "testing on UP system. Performance may be not as good as expected."
6508                         SLOWOK=1
6509         fi
6510
6511         rm -rf $DIR/$tdir
6512         mkdir -p $DIR/$tdir
6513         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6514         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
6515         MULT=10
6516         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
6517                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
6518
6519                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
6520                 lctl set_param -n llite.*.statahead_max 0
6521                 lctl get_param llite.*.statahead_max
6522                 cancel_lru_locks mdc
6523                 cancel_lru_locks osc
6524                 stime=`date +%s`
6525                 time ls -l $DIR/$tdir | wc -l
6526                 etime=`date +%s`
6527                 delta=$((etime - stime))
6528                 log "ls $i files without statahead: $delta sec"
6529                 lctl set_param llite.*.statahead_max=$max
6530
6531                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
6532                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
6533                 cancel_lru_locks mdc
6534                 cancel_lru_locks osc
6535                 stime=`date +%s`
6536                 time ls -l $DIR/$tdir | wc -l
6537                 etime=`date +%s`
6538                 delta_sa=$((etime - stime))
6539                 log "ls $i files with statahead: $delta_sa sec"
6540                 lctl get_param -n llite.*.statahead_stats
6541                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
6542
6543                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
6544                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
6545
6546                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
6547                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
6548                     lctl set_param -n llite.*.statahead_max 0
6549                     lctl get_param llite.*.statahead_max
6550                     cancel_lru_locks mdc
6551                     cancel_lru_locks osc
6552                     stime=`date +%s`
6553                     time ls -l $DIR/$tdir | wc -l
6554                     etime=`date +%s`
6555                     delta=$((etime - stime))
6556                     log "ls $i files again without statahead: $delta sec"
6557                     lctl set_param llite.*.statahead_max=$max
6558                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
6559                         if [  $SLOWOK -eq 0 ]; then
6560                                 error "ls $i files is slower with statahead!"
6561                         else
6562                                 log "ls $i files is slower with statahead!"
6563                         fi
6564                         break
6565                     fi
6566                 fi
6567
6568                 [ $delta -gt 20 ] && break
6569                 [ $delta -gt 8 ] && MULT=$((50 / delta))
6570                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
6571         done
6572         log "ls done"
6573
6574         stime=`date +%s`
6575         rm -r $DIR/$tdir
6576         sync
6577         etime=`date +%s`
6578         delta=$((etime - stime))
6579         log "rm -r $DIR/$tdir/: $delta seconds"
6580         log "rm done"
6581         lctl get_param -n llite.*.statahead_stats
6582 }
6583 run_test 123a "verify statahead work"
6584
6585 test_123b () { # statahead(bug 15027)
6586         mkdir -p $DIR/$tdir
6587         createmany -o $DIR/$tdir/$tfile-%d 1000
6588
6589         cancel_lru_locks mdc
6590         cancel_lru_locks osc
6591
6592 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
6593         lctl set_param fail_loc=0x80000803
6594         ls -lR $DIR/$tdir > /dev/null
6595         log "ls done"
6596         lctl set_param fail_loc=0x0
6597         lctl get_param -n llite.*.statahead_stats
6598         rm -r $DIR/$tdir
6599         sync
6600
6601 }
6602 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
6603
6604 test_124a() {
6605         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
6606                skip "no lru resize on server" && return 0
6607         local NR=2000
6608         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
6609
6610         log "create $NR files at $DIR/$tdir"
6611         createmany -o $DIR/$tdir/f $NR ||
6612                 error "failed to create $NR files in $DIR/$tdir"
6613
6614         cancel_lru_locks mdc
6615         ls -l $DIR/$tdir > /dev/null
6616
6617         local NSDIR=""
6618         local LRU_SIZE=0
6619         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
6620                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6621                 LRU_SIZE=$(lctl get_param -n $PARAM)
6622                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
6623                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
6624                                                 log "NSDIR=$NSDIR"
6625                         log "NS=$(basename $NSDIR)"
6626                         break
6627                 fi
6628         done
6629
6630         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
6631                 skip "Not enough cached locks created!"
6632                 return 0
6633         fi
6634         log "LRU=$LRU_SIZE"
6635
6636         local SLEEP=30
6637
6638         # We know that lru resize allows one client to hold $LIMIT locks
6639         # for 10h. After that locks begin to be killed by client.
6640         local MAX_HRS=10
6641         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
6642                 log "LIMIT=$LIMIT"
6643
6644         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
6645         # killing locks. Some time was spent for creating locks. This means
6646         # that up to the moment of sleep finish we must have killed some of
6647         # them (10-100 locks). This depends on how fast ther were created.
6648         # Many of them were touched in almost the same moment and thus will
6649         # be killed in groups.
6650         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
6651
6652         # Use $LRU_SIZE_B here to take into account real number of locks
6653         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
6654         local LRU_SIZE_B=$LRU_SIZE
6655         log "LVF=$LVF"
6656         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
6657                 log "OLD_LVF=$OLD_LVF"
6658         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
6659
6660         # Let's make sure that we really have some margin. Client checks
6661         # cached locks every 10 sec.
6662         SLEEP=$((SLEEP+20))
6663         log "Sleep ${SLEEP} sec"
6664         local SEC=0
6665         while ((SEC<$SLEEP)); do
6666                 echo -n "..."
6667                 sleep 5
6668                 SEC=$((SEC+5))
6669                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
6670                 echo -n "$LRU_SIZE"
6671         done
6672         echo ""
6673         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
6674         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
6675
6676         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
6677                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
6678                 unlinkmany $DIR/$tdir/f $NR
6679                 return
6680         }
6681
6682         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
6683         log "unlink $NR files at $DIR/$tdir"
6684         unlinkmany $DIR/$tdir/f $NR
6685 }
6686 run_test 124a "lru resize ======================================="
6687
6688 get_max_pool_limit()
6689 {
6690         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
6691         local max=0
6692         for l in $limit; do
6693                 if test $l -gt $max; then
6694                         max=$l
6695                 fi
6696         done
6697         echo $max
6698 }
6699
6700 test_124b() {
6701         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
6702                skip "no lru resize on server" && return 0
6703
6704         LIMIT=`get_max_pool_limit`
6705
6706         NR=$(($(default_lru_size)*20))
6707         if [ $NR -gt $LIMIT ]; then
6708                 log "Limit lock number by $LIMIT locks"
6709                 NR=$LIMIT
6710         fi
6711         lru_resize_disable mdc
6712         mkdir -p $DIR/$tdir/disable_lru_resize ||
6713                 error "failed to create $DIR/$tdir/disable_lru_resize"
6714
6715         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
6716         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
6717         cancel_lru_locks mdc
6718         stime=`date +%s`
6719         PID=""
6720         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6721         PID="$PID $!"
6722         sleep 2
6723         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6724         PID="$PID $!"
6725         sleep 2
6726         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6727         PID="$PID $!"
6728         wait $PID
6729         etime=`date +%s`
6730         nolruresize_delta=$((etime-stime))
6731         log "ls -la time: $nolruresize_delta seconds"
6732         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
6733         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
6734
6735         lru_resize_enable mdc
6736         mkdir -p $DIR/$tdir/enable_lru_resize ||
6737                 error "failed to create $DIR/$tdir/enable_lru_resize"
6738
6739         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
6740         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
6741         cancel_lru_locks mdc
6742         stime=`date +%s`
6743         PID=""
6744         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6745         PID="$PID $!"
6746         sleep 2
6747         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6748         PID="$PID $!"
6749         sleep 2
6750         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6751         PID="$PID $!"
6752         wait $PID
6753         etime=`date +%s`
6754         lruresize_delta=$((etime-stime))
6755         log "ls -la time: $lruresize_delta seconds"
6756         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
6757
6758         if [ $lruresize_delta -gt $nolruresize_delta ]; then
6759                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
6760         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
6761                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
6762         else
6763                 log "lru resize performs the same with no lru resize"
6764         fi
6765         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
6766 }
6767 run_test 124b "lru resize (performance test) ======================="
6768
6769 test_125() { # 13358
6770         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
6771         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
6772         mkdir -p $DIR/d125 || error "mkdir failed"
6773         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
6774         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
6775         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
6776 }
6777 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
6778
6779 test_126() { # bug 12829/13455
6780         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
6781         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
6782         $GSS && skip "must run as gss disabled" && return
6783
6784         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
6785         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
6786         rm -f $DIR/$tfile
6787         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
6788 }
6789 run_test 126 "check that the fsgid provided by the client is taken into account"
6790
6791 test_127a() { # bug 15521
6792         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
6793         $LCTL set_param osc.*.stats=0
6794         FSIZE=$((2048 * 1024))
6795         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
6796         cancel_lru_locks osc
6797         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
6798
6799         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
6800         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
6801                 echo "got $COUNT $NAME"
6802                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
6803                 eval $NAME=$COUNT || error "Wrong proc format"
6804
6805                 case $NAME in
6806                         read_bytes|write_bytes)
6807                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
6808                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
6809                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
6810                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
6811                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
6812                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
6813                                 error "sumsquare is too small: $SUMSQ"
6814                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
6815                                 error "sumsquare is too big: $SUMSQ"
6816                         ;;
6817                         *) ;;
6818                 esac
6819         done < $DIR/${tfile}.tmp
6820
6821         #check that we actually got some stats
6822         [ "$read_bytes" ] || error "Missing read_bytes stats"
6823         [ "$write_bytes" ] || error "Missing write_bytes stats"
6824         [ "$read_bytes" != 0 ] || error "no read done"
6825         [ "$write_bytes" != 0 ] || error "no write done"
6826 }
6827 run_test 127a "verify the client stats are sane"
6828
6829 test_127b() { # bug LU-333
6830         $LCTL set_param llite.*.stats=0
6831         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
6832         # perform 2 reads and writes so MAX is different from SUM.
6833         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
6834         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
6835         cancel_lru_locks osc
6836         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
6837         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
6838
6839         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
6840         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
6841                 echo "got $COUNT $NAME"
6842                 eval $NAME=$COUNT || error "Wrong proc format"
6843
6844         case $NAME in
6845                 read_bytes)
6846                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
6847                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
6848                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
6849                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
6850                         ;;
6851                 write_bytes)
6852                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
6853                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
6854                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
6855                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
6856                         ;;
6857                         *) ;;
6858                 esac
6859         done < $TMP/${tfile}.tmp
6860
6861         #check that we actually got some stats
6862         [ "$read_bytes" ] || error "Missing read_bytes stats"
6863         [ "$write_bytes" ] || error "Missing write_bytes stats"
6864         [ "$read_bytes" != 0 ] || error "no read done"
6865         [ "$write_bytes" != 0 ] || error "no write done"
6866 }
6867 run_test 127b "verify the llite client stats are sane"
6868
6869 test_128() { # bug 15212
6870         touch $DIR/$tfile
6871         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
6872                 find $DIR/$tfile
6873                 find $DIR/$tfile
6874         EOF
6875
6876         result=$(grep error $TMP/$tfile.log)
6877         rm -f $DIR/$tfile
6878         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
6879 }
6880 run_test 128 "interactive lfs for 2 consecutive find's"
6881
6882 set_dir_limits () {
6883         local mntdev
6884         local canondev
6885         local node
6886
6887         local LDPROC=/proc/fs/ldiskfs
6888
6889         for facet in $(get_facets MDS); do
6890                 canondev=$(ldiskfs_canon *.$(convert_facet2label $facet).mntdev $facet)
6891                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" || LDPROC=/sys/fs/ldiskfs
6892                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
6893         done
6894 }
6895 test_129() {
6896         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return 0
6897         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6898
6899         EFBIG=27
6900         MAX=16384
6901
6902         set_dir_limits $MAX
6903
6904         mkdir -p $DIR/$tdir
6905
6906         I=0
6907         J=0
6908         while [ ! $I -gt $((MAX * MDSCOUNT)) ]; do
6909                 multiop $DIR/$tdir/$J Oc
6910                 rc=$?
6911                 if [ $rc -eq $EFBIG ]; then
6912                         set_dir_limits 0
6913                         echo "return code $rc received as expected"
6914                         return 0
6915                 elif [ $rc -ne 0 ]; then
6916                         set_dir_limits 0
6917                         error_exit "return code $rc received instead of expected $EFBIG"
6918                 fi
6919                 J=$((J+1))
6920                 I=$(stat -c%s "$DIR/$tdir")
6921         done
6922
6923         set_dir_limits 0
6924         error "exceeded dir size limit $MAX x $MDSCOUNT $((MAX * MDSCOUNT)) : $I bytes"
6925 }
6926 run_test 129 "test directory size limit ========================"
6927
6928 OLDIFS="$IFS"
6929 cleanup_130() {
6930         trap 0
6931         IFS="$OLDIFS"
6932 }
6933
6934 test_130a() {
6935         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
6936         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
6937
6938         trap cleanup_130 EXIT RETURN
6939
6940         local fm_file=$DIR/$tfile
6941         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
6942         dd if=/dev/zero of=$fm_file bs=65536 count=1 || error "dd failed for $fm_file"
6943
6944         filefrag -ves $fm_file || error "filefrag $fm_file failed"
6945         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
6946
6947         lun=$($GETSTRIPE -i $fm_file)
6948
6949         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
6950         IFS=$'\n'
6951         tot_len=0
6952         for line in $filefrag_op
6953         do
6954                 frag_lun=`echo $line | cut -d: -f5`
6955                 ext_len=`echo $line | cut -d: -f4`
6956                 if (( $frag_lun != $lun )); then
6957                         cleanup_130
6958                         error "FIEMAP on 1-stripe file($fm_file) failed"
6959                         return
6960                 fi
6961                 (( tot_len += ext_len ))
6962         done
6963
6964         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
6965                 cleanup_130
6966                 error "FIEMAP on 1-stripe file($fm_file) failed;"
6967                 return
6968         fi
6969
6970         cleanup_130
6971
6972         echo "FIEMAP on single striped file succeeded"
6973 }
6974 run_test 130a "FIEMAP (1-stripe file)"
6975
6976 test_130b() {
6977         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping FIEMAP on 2-stripe file test" && return
6978
6979         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
6980         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
6981
6982         trap cleanup_130 EXIT RETURN
6983
6984         local fm_file=$DIR/$tfile
6985         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
6986         dd if=/dev/zero of=$fm_file bs=1M count=2 || error "dd failed on $fm_file"
6987
6988         filefrag -ves $fm_file || error "filefrag $fm_file failed"
6989         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
6990
6991         last_lun=`echo $filefrag_op | cut -d: -f5`
6992
6993         IFS=$'\n'
6994         tot_len=0
6995         num_luns=1
6996         for line in $filefrag_op
6997         do
6998                 frag_lun=`echo $line | cut -d: -f5`
6999                 ext_len=`echo $line | cut -d: -f4`
7000                 if (( $frag_lun != $last_lun )); then
7001                         if (( tot_len != 1024 )); then
7002                                 cleanup_130
7003                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
7004                                 return
7005                         else
7006                                 (( num_luns += 1 ))
7007                                 tot_len=0
7008                         fi
7009                 fi
7010                 (( tot_len += ext_len ))
7011                 last_lun=$frag_lun
7012         done
7013         if (( num_luns != 2 || tot_len != 1024 )); then
7014                 cleanup_130
7015                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7016                 return
7017         fi
7018
7019         cleanup_130
7020
7021         echo "FIEMAP on 2-stripe file succeeded"
7022 }
7023 run_test 130b "FIEMAP (2-stripe file)"
7024
7025 test_130c() {
7026         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping FIEMAP on 2-stripe file with hole test" && return
7027
7028         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7029         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7030
7031         trap cleanup_130 EXIT RETURN
7032
7033         local fm_file=$DIR/$tfile
7034         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7035         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
7036
7037         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7038         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7039
7040         last_lun=`echo $filefrag_op | cut -d: -f5`
7041
7042         IFS=$'\n'
7043         tot_len=0
7044         num_luns=1
7045         for line in $filefrag_op
7046         do
7047                 frag_lun=`echo $line | cut -d: -f5`
7048                 ext_len=`echo $line | cut -d: -f4`
7049                 if (( $frag_lun != $last_lun )); then
7050                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
7051                         if (( logical != 512 )); then
7052                                 cleanup_130
7053                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
7054                                 return
7055                         fi
7056                         if (( tot_len != 512 )); then
7057                                 cleanup_130
7058                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7059                                 return
7060                         else
7061                                 (( num_luns += 1 ))
7062                                 tot_len=0
7063                         fi
7064                 fi
7065                 (( tot_len += ext_len ))
7066                 last_lun=$frag_lun
7067         done
7068         if (( num_luns != 2 || tot_len != 512 )); then
7069                 cleanup_130
7070                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7071                 return
7072         fi
7073
7074         cleanup_130
7075
7076         echo "FIEMAP on 2-stripe file with hole succeeded"
7077 }
7078 run_test 130c "FIEMAP (2-stripe file with hole)"
7079
7080 test_130d() {
7081         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
7082
7083         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7084         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7085
7086         trap cleanup_130 EXIT RETURN
7087
7088         local fm_file=$DIR/$tfile
7089         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
7090         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
7091
7092         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7093         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7094
7095         last_lun=`echo $filefrag_op | cut -d: -f5`
7096
7097         IFS=$'\n'
7098         tot_len=0
7099         num_luns=1
7100         for line in $filefrag_op
7101         do
7102                 frag_lun=`echo $line | cut -d: -f5`
7103                 ext_len=`echo $line | cut -d: -f4`
7104                 if (( $frag_lun != $last_lun )); then
7105                         if (( tot_len != 1024 )); then
7106                                 cleanup_130
7107                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7108                                 return
7109                         else
7110                                 (( num_luns += 1 ))
7111                                 tot_len=0
7112                         fi
7113                 fi
7114                 (( tot_len += ext_len ))
7115                 last_lun=$frag_lun
7116         done
7117         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
7118                 cleanup_130
7119                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7120                 return
7121         fi
7122
7123         cleanup_130
7124
7125         echo "FIEMAP on N-stripe file succeeded"
7126 }
7127 run_test 130d "FIEMAP (N-stripe file)"
7128
7129 test_130e() {
7130         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
7131
7132         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7133         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7134
7135         trap cleanup_130 EXIT RETURN
7136
7137         local fm_file=$DIR/$tfile
7138         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
7139         NUM_BLKS=512
7140         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
7141         for ((i = 0; i < $NUM_BLKS; i++))
7142         do
7143                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
7144         done
7145
7146         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7147         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
7148
7149         last_lun=`echo $filefrag_op | cut -d: -f5`
7150
7151         IFS=$'\n'
7152         tot_len=0
7153         num_luns=1
7154         for line in $filefrag_op
7155         do
7156                 frag_lun=`echo $line | cut -d: -f5`
7157                 ext_len=`echo $line | cut -d: -f4`
7158                 if (( $frag_lun != $last_lun )); then
7159                         if (( tot_len != $EXPECTED_LEN )); then
7160                                 cleanup_130
7161                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
7162                                 return
7163                         else
7164                                 (( num_luns += 1 ))
7165                                 tot_len=0
7166                         fi
7167                 fi
7168                 (( tot_len += ext_len ))
7169                 last_lun=$frag_lun
7170         done
7171         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
7172                 cleanup_130
7173                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7174                 return
7175         fi
7176
7177         cleanup_130
7178
7179         echo "FIEMAP with continuation calls succeeded"
7180 }
7181 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
7182
7183 # Test for writev/readv
7184 test_131a() {
7185         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
7186         error "writev test failed"
7187         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
7188         error "readv failed"
7189         rm -f $DIR/$tfile
7190 }
7191 run_test 131a "test iov's crossing stripe boundary for writev/readv"
7192
7193 test_131b() {
7194         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
7195         error "append writev test failed"
7196         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
7197         error "append writev test failed"
7198         rm -f $DIR/$tfile
7199 }
7200 run_test 131b "test append writev"
7201
7202 test_131c() {
7203         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
7204         error "NOT PASS"
7205 }
7206 run_test 131c "test read/write on file w/o objects"
7207
7208 test_131d() {
7209         rwv -f $DIR/$tfile -w -n 1 1572864
7210         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
7211         if [ "$NOB" != 1572864 ]; then
7212                 error "Short read filed: read $NOB bytes instead of 1572864"
7213         fi
7214         rm -f $DIR/$tfile
7215 }
7216 run_test 131d "test short read"
7217
7218 test_131e() {
7219         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
7220         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
7221         error "read hitting hole failed"
7222         rm -f $DIR/$tfile
7223 }
7224 run_test 131e "test read hitting hole"
7225
7226 get_ost_param() {
7227         local token=$1
7228         local gl_sum=0
7229         for node in $(osts_nodes); do
7230                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
7231                 [ x$gl = x"" ] && gl=0
7232                 gl_sum=$((gl_sum + gl))
7233         done
7234         echo $gl
7235 }
7236
7237 som_mode_switch() {
7238         local som=$1
7239         local gl1=$2
7240         local gl2=$3
7241
7242         if [ x$som = x"enabled" ]; then
7243                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
7244                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
7245                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
7246         else
7247                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
7248                 MOUNTOPT="$MOUNTOPT,som_preview"
7249                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
7250         fi
7251
7252         # do remount to make new mount-conf parameters actual
7253         echo remounting...
7254         sync
7255         stopall
7256         setupall
7257 }
7258
7259 test_132() { #1028, SOM
7260         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7261         local num=$(get_mds_dir $DIR)
7262         local mymds=mds${num}
7263         local MOUNTOPT_SAVE=$MOUNTOPT
7264
7265         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
7266         cancel_lru_locks osc
7267
7268         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
7269
7270         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
7271         stat $DIR/$tfile >/dev/null
7272         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
7273         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
7274         rm $DIR/$tfile
7275         som_mode_switch $som1 $gl1 $gl2
7276
7277         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
7278         cancel_lru_locks osc
7279
7280         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
7281         if [ $som1 == $som2 ]; then
7282             error "som is still "$som2
7283             if [ x$som2 = x"enabled" ]; then
7284                 som2="disabled"
7285             else
7286                 som2="enabled"
7287             fi
7288         fi
7289
7290         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
7291         stat $DIR/$tfile >/dev/null
7292         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
7293         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
7294         som_mode_switch $som2 $gl1 $gl2
7295         MOUNTOPT=$MOUNTOPT_SAVE
7296 }
7297 run_test 132 "som avoids glimpse rpc"
7298
7299 check_stats() {
7300         local res
7301         local count
7302         case $1 in
7303         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
7304                  ;;
7305         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
7306                  ;;
7307         *) error "Wrong argument $1" ;;
7308         esac
7309         echo $res
7310         count=`echo $res | awk '{print $2}'`
7311         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
7312         # if the argument $3 is zero, it means any stat increment is ok.
7313         if [ $3 -gt 0 ] ; then
7314                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
7315         fi
7316 }
7317
7318 test_133a() {
7319         remote_ost_nodsh && skip "remote OST with nodsh" && return
7320         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7321
7322         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
7323                 { skip "MDS doesn't support rename stats"; return; }
7324         local testdir=$DIR/${tdir}/stats_testdir
7325         mkdir -p $DIR/${tdir}
7326
7327         # clear stats.
7328         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7329         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7330
7331         # verify mdt stats first.
7332         mkdir ${testdir} || error "mkdir failed"
7333         check_stats $SINGLEMDS "mkdir" 1
7334         touch ${testdir}/${tfile} || "touch failed"
7335         check_stats $SINGLEMDS "open" 1
7336         check_stats $SINGLEMDS "close" 1
7337         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
7338         check_stats $SINGLEMDS "mknod" 1
7339         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
7340         check_stats $SINGLEMDS "unlink" 1
7341         rm -f ${testdir}/${tfile} || error "file remove failed"
7342         check_stats $SINGLEMDS "unlink" 2
7343
7344         # remove working dir and check mdt stats again.
7345         rmdir ${testdir} || error "rmdir failed"
7346         check_stats $SINGLEMDS "rmdir" 1
7347
7348         local testdir1=$DIR/${tdir}/stats_testdir1
7349         mkdir -p ${testdir}
7350         mkdir -p ${testdir1}
7351         touch ${testdir1}/test1
7352         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
7353         check_stats $SINGLEMDS "crossdir_rename" 1
7354
7355         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
7356         check_stats $SINGLEMDS "samedir_rename" 1
7357
7358         rm -rf $DIR/${tdir}
7359 }
7360 run_test 133a "Verifying MDT stats ========================================"
7361
7362 test_133b() {
7363         remote_ost_nodsh && skip "remote OST with nodsh" && return
7364         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7365         local testdir=$DIR/${tdir}/stats_testdir
7366         mkdir -p ${testdir} || error "mkdir failed"
7367         touch ${testdir}/${tfile} || "touch failed"
7368         cancel_lru_locks mdc
7369
7370         # clear stats.
7371         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7372         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7373
7374         # extra mdt stats verification.
7375         chmod 444 ${testdir}/${tfile} || error "chmod failed"
7376         check_stats $SINGLEMDS "setattr" 1
7377         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7378         ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
7379         check_stats $SINGLEMDS "getattr" 1
7380         $LFS df || error "lfs failed"
7381         check_stats $SINGLEMDS "statfs" 1
7382
7383         rm -rf $DIR/${tdir}
7384 }
7385 run_test 133b "Verifying extra MDT stats =================================="
7386
7387 test_133c() {
7388         remote_ost_nodsh && skip "remote OST with nodsh" && return
7389         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7390         local testdir=$DIR/${tdir}/stats_testdir
7391         mkdir -p ${testdir} || error "mkdir failed"
7392
7393         # verify obdfilter stats.
7394         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
7395         sync
7396         cancel_lru_locks osc
7397
7398         # clear stats.
7399         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7400         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7401
7402         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
7403         sync
7404         cancel_lru_locks osc
7405         check_stats ost "write" 1
7406
7407         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
7408         check_stats ost "read" 1
7409
7410         > ${testdir}/${tfile} || error "truncate failed"
7411         check_stats ost "punch" 1
7412
7413         rm -f ${testdir}/${tfile} || error "file remove failed"
7414         check_stats ost "destroy" 1
7415
7416         rm -rf $DIR/${tdir}
7417 }
7418 run_test 133c "Verifying OST stats ========================================"
7419
7420 order_2() {
7421     local value=$1
7422     local orig=$value
7423     local order=1
7424
7425     while [ $value -ge 2 ]; do
7426         order=$((order*2))
7427         value=$((value/2))
7428     done
7429
7430     if [ $orig -gt $order ]; then
7431         order=$((order*2))
7432     fi
7433     echo $order
7434 }
7435
7436 size_in_KMGT() {
7437     local value=$1
7438     local size=('K' 'M' 'G' 'T');
7439     local i=0
7440     local size_string=$value
7441
7442     while [ $value -ge 1024 ]; do
7443         if [ $i -gt 3 ]; then
7444             #T is the biggest unit we get here, if that is bigger,
7445             #just return XXXT
7446             size_string=${value}T
7447             break
7448         fi
7449         value=$((value >> 10))
7450         if [ $value -lt 1024 ]; then
7451             size_string=${value}${size[$i]}
7452             break
7453         fi
7454         i=$((i + 1))
7455     done
7456
7457     echo $size_string
7458 }
7459
7460 get_rename_size() {
7461     local size=$1
7462     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
7463                    awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
7464     echo $sample
7465 }
7466
7467 test_133d() {
7468     remote_ost_nodsh && skip "remote OST with nodsh" && return
7469     remote_mds_nodsh && skip "remote MDS with nodsh" && return
7470     do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
7471         { skip "MDS doesn't support rename stats"; return; }
7472
7473     local testdir1=$DIR/${tdir}/stats_testdir1
7474     local testdir2=$DIR/${tdir}/stats_testdir2
7475
7476     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
7477
7478     mkdir -p ${testdir1} || error "mkdir failed"
7479     mkdir -p ${testdir2} || error "mkdir failed"
7480
7481     createmany -o $testdir1/test 512 || error "createmany failed"
7482     local testdir1_size=$(ls -l $DIR/${tdir} |
7483                           awk '/stats_testdir1/ {print $5}')
7484     local testdir2_size=$(ls -l $DIR/${tdir} |
7485                           awk '/stats_testdir2/ {print $5}')
7486
7487     testdir1_size=$(order_2 $testdir1_size)
7488     testdir2_size=$(order_2 $testdir2_size)
7489
7490     testdir1_size=$(size_in_KMGT $testdir1_size)
7491     testdir2_size=$(size_in_KMGT $testdir2_size)
7492
7493     echo "source rename dir size: ${testdir1_size}"
7494     echo "target rename dir size: ${testdir2_size}"
7495
7496     # check samedir rename size
7497     mv ${testdir1}/test0 ${testdir1}/test_0
7498     local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
7499     eval $cmd || error "$cmd failed"
7500     local samedir=$($cmd | grep 'same_dir')
7501     local same_sample=$(get_rename_size $testdir1_size)
7502     [ -z "$samedir" ] && error "samedir_rename_size count error"
7503     [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
7504     echo "Check same dir rename stats success"
7505
7506     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
7507
7508     # check crossdir rename size
7509     mv ${testdir1}/test_0 ${testdir2}/test_0
7510     eval $cmd || error "$cmd failed"
7511     local crossdir=$($cmd | grep 'crossdir')
7512     local src_sample=$(get_rename_size $testdir1_size)
7513     local tgt_sample=$(get_rename_size $testdir2_size)
7514     [ -z "$crossdir" ] && error "crossdir_rename_size count error"
7515     [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
7516     [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
7517     echo "Check cross dir rename stats success"
7518     rm -rf $DIR/${tdir}
7519 }
7520 run_test 133d "Verifying rename_stats ========================================"
7521
7522 test_140() { #bug-17379
7523         mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
7524         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
7525         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
7526
7527         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
7528         local i=0
7529         while i=`expr $i + 1`; do
7530                 mkdir -p $i || error "Creating dir $i"
7531                 cd $i || error "Changing to $i"
7532                 ln -s ../stat stat || error "Creating stat symlink"
7533                 # Read the symlink until ELOOP present,
7534                 # not LBUGing the system is considered success,
7535                 # we didn't overrun the stack.
7536                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
7537                 [ $ret -ne 0 ] && {
7538                         if [ $ret -eq 40 ]; then
7539                                 break  # -ELOOP
7540                         else
7541                                 error "Open stat symlink"
7542                                 return
7543                         fi
7544                 }
7545         done
7546         i=`expr $i - 1`
7547         echo "The symlink depth = $i"
7548         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 ] || error "Invalid symlink depth"
7549 }
7550 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
7551
7552 test_150() {
7553         local TF="$TMP/$tfile"
7554
7555         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
7556         cp $TF $DIR/$tfile
7557         cancel_lru_locks osc
7558         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
7559         remount_client $MOUNT
7560         df -P $MOUNT
7561         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
7562
7563         $TRUNCATE $TF 6000
7564         $TRUNCATE $DIR/$tfile 6000
7565         cancel_lru_locks osc
7566         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
7567
7568         echo "12345" >>$TF
7569         echo "12345" >>$DIR/$tfile
7570         cancel_lru_locks osc
7571         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
7572
7573         echo "12345" >>$TF
7574         echo "12345" >>$DIR/$tfile
7575         cancel_lru_locks osc
7576         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
7577
7578         rm -f $TF
7579         true
7580 }
7581 run_test 150 "truncate/append tests"
7582
7583 function roc_hit() {
7584     local list=$(comma_list $(osts_nodes))
7585
7586     ACCNUM=$(do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
7587         awk '/'cache_hit'/ {sum+=$2} END {print sum}')
7588     echo $ACCNUM
7589 }
7590
7591 function set_cache() {
7592     local on=1
7593
7594     if [ "$2" == "off" ]; then
7595         on=0;
7596     fi
7597     local list=$(comma_list $(osts_nodes))
7598     do_nodes $list lctl set_param obdfilter.*.${1}_cache_enable $on
7599
7600     cancel_lru_locks osc
7601 }
7602
7603 test_151() {
7604         remote_ost_nodsh && skip "remote OST with nodsh" && return
7605
7606         local CPAGES=3
7607         local list=$(comma_list $(osts_nodes))
7608
7609         # check whether obdfilter is cache capable at all
7610         if ! do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable > /dev/null; then
7611                 echo "not cache-capable obdfilter"
7612                 return 0
7613         fi
7614
7615         # check cache is enabled on all obdfilters
7616         if do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable | grep 0 >&/dev/null; then
7617                 echo "oss cache is disabled"
7618                 return 0
7619         fi
7620
7621         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable 1
7622
7623         # pages should be in the case right after write
7624         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
7625         local BEFORE=`roc_hit`
7626         cancel_lru_locks osc
7627         cat $DIR/$tfile >/dev/null
7628         local AFTER=`roc_hit`
7629         if ! let "AFTER - BEFORE == CPAGES"; then
7630                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7631         fi
7632
7633         # the following read invalidates the cache
7634         cancel_lru_locks osc
7635         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 0
7636         cat $DIR/$tfile >/dev/null
7637
7638         # now data shouldn't be found in the cache
7639         BEFORE=`roc_hit`
7640         cancel_lru_locks osc
7641         cat $DIR/$tfile >/dev/null
7642         AFTER=`roc_hit`
7643         if let "AFTER - BEFORE != 0"; then
7644                 error "IN CACHE: before: $BEFORE, after: $AFTER"
7645         fi
7646
7647         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 1
7648         rm -f $DIR/$tfile
7649 }
7650 run_test 151 "test cache on oss and controls ==============================="
7651
7652 test_152() {
7653         local TF="$TMP/$tfile"
7654
7655         # simulate ENOMEM during write
7656 #define OBD_FAIL_OST_NOMEM      0x226
7657         lctl set_param fail_loc=0x80000226
7658         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
7659         cp $TF $DIR/$tfile
7660         sync || error "sync failed"
7661         lctl set_param fail_loc=0
7662
7663         # discard client's cache
7664         cancel_lru_locks osc
7665
7666         # simulate ENOMEM during read
7667         lctl set_param fail_loc=0x80000226
7668         cmp $TF $DIR/$tfile || error "cmp failed"
7669         lctl set_param fail_loc=0
7670
7671         rm -f $TF
7672 }
7673 run_test 152 "test read/write with enomem ============================"
7674
7675 test_153() {
7676         multiop $DIR/$tfile Ow4096Ycu || error "multiop failed"
7677 }
7678 run_test 153 "test if fdatasync does not crash ======================="
7679
7680 test_154() {
7681         cp /etc/hosts $DIR/$tfile
7682
7683         fid=$($LFS path2fid $DIR/$tfile)
7684         rc=$?
7685         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
7686
7687         ffid=$DIR/.lustre/fid/$fid
7688
7689         echo "stat fid $fid"
7690         stat $ffid > /dev/null || error "stat $ffid failed."
7691         echo "touch fid $fid"
7692         touch $ffid || error "touch $ffid failed."
7693         echo "write to fid $fid"
7694         cat /etc/hosts > $ffid || error "write $ffid failed."
7695         echo "read fid $fid"
7696         diff /etc/hosts $ffid || error "read $ffid failed."
7697         echo "append write to fid $fid"
7698         cat /etc/hosts >> $ffid || error "append write $ffid failed."
7699         echo "rename fid $fid"
7700         mv $ffid $DIR/$tfile.1 && error "rename $ffid to $tfile.1 should fail."
7701         touch $DIR/$tfile.1
7702         mv $DIR/$tfile.1 $ffid && error "rename $tfile.1 to $ffid should fail."
7703         rm -f $DIR/$tfile.1
7704         echo "truncate fid $fid"
7705         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
7706         echo "link fid $fid"
7707         ln -f $ffid $DIR/tfile.lnk || error "link $ffid failed."
7708         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
7709                 echo "setfacl fid $fid"
7710                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
7711                 echo "getfacl fid $fid"
7712                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
7713         fi
7714         echo "unlink fid $fid"
7715         unlink $DIR/.lustre/fid/$fid && error "unlink $ffid should fail."
7716         echo "mknod fid $fid"
7717         mknod $ffid c 1 3 && error "mknod $ffid should fail."
7718
7719         fid=[0xf00000400:0x1:0x0]
7720         ffid=$DIR/.lustre/fid/$fid
7721
7722         echo "stat non-exist fid $fid"
7723         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
7724         echo "write to non-exist fid $fid"
7725         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
7726         echo "link new fid $fid"
7727         ln $DIR/$tfile $ffid && error "link $ffid should fail."
7728
7729         mkdir -p $DIR/$tdir
7730         touch $DIR/$tdir/$tfile
7731         fid=$($LFS path2fid $DIR/$tdir)
7732         rc=$?
7733         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
7734
7735         ffid=$DIR/.lustre/fid/$fid
7736
7737         echo "ls $fid"
7738         ls $ffid > /dev/null || error "ls $ffid failed."
7739         echo "touch $fid/$tfile.1"
7740         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
7741
7742         echo "touch $DIR/.lustre/fid/$tfile"
7743         touch $DIR/.lustre/fid/$tfile && \
7744                 error "touch $DIR/.lustre/fid/$tfile should fail."
7745
7746         echo "Open-by-FID succeeded"
7747 }
7748 run_test 154 "Open-by-FID"
7749
7750 test_155_small_load() {
7751     local temp=$TMP/$tfile
7752     local file=$DIR/$tfile
7753
7754     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
7755         error "dd of=$temp bs=6096 count=1 failed"
7756     cp $temp $file
7757     cancel_lru_locks osc
7758     cmp $temp $file || error "$temp $file differ"
7759
7760     $TRUNCATE $temp 6000
7761     $TRUNCATE $file 6000
7762     cmp $temp $file || error "$temp $file differ (truncate1)"
7763
7764     echo "12345" >>$temp
7765     echo "12345" >>$file
7766     cmp $temp $file || error "$temp $file differ (append1)"
7767
7768     echo "12345" >>$temp
7769     echo "12345" >>$file
7770     cmp $temp $file || error "$temp $file differ (append2)"
7771
7772     rm -f $temp $file
7773     true
7774 }
7775
7776 test_155_big_load() {
7777     remote_ost_nodsh && skip "remote OST with nodsh" && return
7778     local temp=$TMP/$tfile
7779     local file=$DIR/$tfile
7780
7781     free_min_max
7782     local cache_size=$(do_facet ost$((MAXI+1)) \
7783         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
7784     local large_file_size=$((cache_size * 2))
7785
7786     echo "OSS cache size: $cache_size KB"
7787     echo "Large file size: $large_file_size KB"
7788
7789     [ $MAXV -le $large_file_size ] && \
7790         skip_env "max available OST size needs > $large_file_size KB" && \
7791         return 0
7792
7793     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
7794
7795     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
7796         error "dd of=$temp bs=$large_file_size count=1k failed"
7797     cp $temp $file
7798     ls -lh $temp $file
7799     cancel_lru_locks osc
7800     cmp $temp $file || error "$temp $file differ"
7801
7802     rm -f $temp $file
7803     true
7804 }
7805
7806 test_155a() {
7807     set_cache read on
7808     set_cache writethrough on
7809     test_155_small_load
7810 }
7811 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
7812
7813 test_155b() {
7814     set_cache read on
7815     set_cache writethrough off
7816     test_155_small_load
7817 }
7818 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
7819
7820 test_155c() {
7821     set_cache read off
7822     set_cache writethrough on
7823     test_155_small_load
7824 }
7825 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
7826
7827 test_155d() {
7828     set_cache read off
7829     set_cache writethrough off
7830     test_155_small_load
7831 }
7832 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
7833
7834 test_155e() {
7835     set_cache read on
7836     set_cache writethrough on
7837     test_155_big_load
7838 }
7839 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
7840
7841 test_155f() {
7842     set_cache read on
7843     set_cache writethrough off
7844     test_155_big_load
7845 }
7846 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
7847
7848 test_155g() {
7849     set_cache read off
7850     set_cache writethrough on
7851     test_155_big_load
7852 }
7853 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
7854
7855 test_155h() {
7856     set_cache read off
7857     set_cache writethrough off
7858     test_155_big_load
7859 }
7860 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
7861
7862 test_156() {
7863     local CPAGES=3
7864     local BEFORE
7865     local AFTER
7866     local file="$DIR/$tfile"
7867
7868     log "Turn on read and write cache"
7869     set_cache read on
7870     set_cache writethrough on
7871
7872     log "Write data and read it back."
7873     log "Read should be satisfied from the cache."
7874     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
7875     BEFORE=`roc_hit`
7876     cancel_lru_locks osc
7877     cat $file >/dev/null
7878     AFTER=`roc_hit`
7879     if ! let "AFTER - BEFORE == CPAGES"; then
7880         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7881     else
7882         log "cache hits:: before: $BEFORE, after: $AFTER"
7883     fi
7884
7885     log "Read again; it should be satisfied from the cache."
7886     BEFORE=$AFTER
7887     cancel_lru_locks osc
7888     cat $file >/dev/null
7889     AFTER=`roc_hit`
7890     if ! let "AFTER - BEFORE == CPAGES"; then
7891         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7892     else
7893         log "cache hits:: before: $BEFORE, after: $AFTER"
7894     fi
7895
7896
7897     log "Turn off the read cache and turn on the write cache"
7898     set_cache read off
7899     set_cache writethrough on
7900
7901     log "Read again; it should be satisfied from the cache."
7902     BEFORE=`roc_hit`
7903     cancel_lru_locks osc
7904     cat $file >/dev/null
7905     AFTER=`roc_hit`
7906     if ! let "AFTER - BEFORE == CPAGES"; then
7907         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7908     else
7909         log "cache hits:: before: $BEFORE, after: $AFTER"
7910     fi
7911
7912     log "Read again; it should not be satisfied from the cache."
7913     BEFORE=$AFTER
7914     cancel_lru_locks osc
7915     cat $file >/dev/null
7916     AFTER=`roc_hit`
7917     if ! let "AFTER - BEFORE == 0"; then
7918         error "IN CACHE: before: $BEFORE, after: $AFTER"
7919     else
7920         log "cache hits:: before: $BEFORE, after: $AFTER"
7921     fi
7922
7923     log "Write data and read it back."
7924     log "Read should be satisfied from the cache."
7925     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
7926     BEFORE=`roc_hit`
7927     cancel_lru_locks osc
7928     cat $file >/dev/null
7929     AFTER=`roc_hit`
7930     if ! let "AFTER - BEFORE == CPAGES"; then
7931         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7932     else
7933         log "cache hits:: before: $BEFORE, after: $AFTER"
7934     fi
7935
7936     log "Read again; it should not be satisfied from the cache."
7937     BEFORE=$AFTER
7938     cancel_lru_locks osc
7939     cat $file >/dev/null
7940     AFTER=`roc_hit`
7941     if ! let "AFTER - BEFORE == 0"; then
7942         error "IN CACHE: before: $BEFORE, after: $AFTER"
7943     else
7944         log "cache hits:: before: $BEFORE, after: $AFTER"
7945     fi
7946
7947
7948     log "Turn off read and write cache"
7949     set_cache read off
7950     set_cache writethrough off
7951
7952     log "Write data and read it back"
7953     log "It should not be satisfied from the cache."
7954     rm -f $file
7955     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
7956     cancel_lru_locks osc
7957     BEFORE=`roc_hit`
7958     cat $file >/dev/null
7959     AFTER=`roc_hit`
7960     if ! let "AFTER - BEFORE == 0"; then
7961         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
7962     else
7963         log "cache hits:: before: $BEFORE, after: $AFTER"
7964     fi
7965
7966
7967     log "Turn on the read cache and turn off the write cache"
7968     set_cache read on
7969     set_cache writethrough off
7970
7971     log "Write data and read it back"
7972     log "It should not be satisfied from the cache."
7973     rm -f $file
7974     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
7975     BEFORE=`roc_hit`
7976     cancel_lru_locks osc
7977     cat $file >/dev/null
7978     AFTER=`roc_hit`
7979     if ! let "AFTER - BEFORE == 0"; then
7980         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
7981     else
7982         log "cache hits:: before: $BEFORE, after: $AFTER"
7983     fi
7984
7985     log "Read again; it should be satisfied from the cache."
7986     BEFORE=`roc_hit`
7987     cancel_lru_locks osc
7988     cat $file >/dev/null
7989     AFTER=`roc_hit`
7990     if ! let "AFTER - BEFORE == CPAGES"; then
7991         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7992     else
7993         log "cache hits:: before: $BEFORE, after: $AFTER"
7994     fi
7995
7996     rm -f $file
7997 }
7998 run_test 156 "Verification of tunables ============================"
7999
8000 #Changelogs
8001 err17935 () {
8002     if [ $MDSCOUNT -gt 1 ]; then
8003         error_ignore 17935 $*
8004     else
8005         error $*
8006     fi
8007 }
8008
8009 changelog_chmask()
8010 {
8011     MASK=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_mask |\
8012            grep -c $1)
8013
8014     if [ $MASK -eq 1 ]; then
8015         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="-$1"
8016     else
8017         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="+$1"
8018     fi
8019 }
8020
8021 test_160() {
8022     remote_mds_nodsh && skip "remote MDS with nodsh" && return
8023     [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
8024         { skip "Need MDS version at least 2.2.0"; return; }
8025     USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
8026     echo "Registered as changelog user $USER"
8027     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
8028         grep -q $USER || error "User $USER not found in changelog_users"
8029
8030     # change something
8031     mkdir -p $DIR/$tdir/pics/2008/zachy
8032     touch $DIR/$tdir/pics/2008/zachy/timestamp
8033     cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
8034     mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
8035     ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
8036     ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
8037     rm $DIR/$tdir/pics/desktop.jpg
8038
8039     $LFS changelog $MDT0 | tail -5
8040
8041     echo "verifying changelog mask"
8042     changelog_chmask "MKDIR"
8043     changelog_chmask "CLOSE"
8044
8045     mkdir -p $DIR/$tdir/pics/zach/sofia
8046     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
8047
8048     changelog_chmask "MKDIR"
8049     changelog_chmask "CLOSE"
8050
8051     mkdir -p $DIR/$tdir/pics/2008/sofia
8052     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
8053
8054     $LFS changelog $MDT0
8055     MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
8056     CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
8057     [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
8058     [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
8059
8060     # verify contents
8061     echo "verifying target fid"
8062     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
8063         tail -1 | awk '{print $6}')
8064     fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
8065     [ "$fidc" == "t=$fidf" ] || \
8066         err17935 "fid in changelog $fidc != file fid $fidf"
8067     echo "verifying parent fid"
8068     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
8069         tail -1 | awk '{print $7}')
8070     fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
8071     [ "$fidc" == "p=$fidf" ] || \
8072         err17935 "pfid in changelog $fidc != dir fid $fidf"
8073
8074     USER_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
8075         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
8076     $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
8077     USER_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
8078         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
8079     echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
8080     [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \
8081         err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2"
8082
8083     MIN_REC=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_users | \
8084         awk 'min == "" || $2 < min {min = $2}; END {print min}')
8085     FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
8086     echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
8087     [ $FIRST_REC == $(($MIN_REC + 1)) ] || \
8088         err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC"
8089
8090     echo "verifying user deregister"
8091     do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
8092     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
8093         grep -q $USER && error "User $USER still found in changelog_users"
8094
8095     USERS=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
8096         mdd.$MDT0.changelog_users | wc -l) - 2 ))
8097     if [ $USERS -eq 0 ]; then
8098         LAST_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
8099             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
8100         touch $DIR/$tdir/chloe
8101         LAST_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
8102             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
8103         echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2"
8104         [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
8105     else
8106         echo "$USERS other changelog users; can't verify off"
8107     fi
8108 }
8109 run_test 160 "changelog sanity"
8110
8111 test_161() {
8112     mkdir -p $DIR/$tdir
8113     cp /etc/hosts $DIR/$tdir/$tfile
8114     mkdir $DIR/$tdir/foo1
8115     mkdir $DIR/$tdir/foo2
8116     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
8117     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
8118     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
8119     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
8120     local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[')
8121     if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
8122         $LFS fid2path $DIR $FID
8123         err17935 "bad link ea"
8124     fi
8125     # middle
8126     rm $DIR/$tdir/foo2/zachary
8127     # last
8128     rm $DIR/$tdir/foo2/thor
8129     # first
8130     rm $DIR/$tdir/$tfile
8131     # rename
8132     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
8133     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
8134         then
8135         $LFS fid2path $DIR $FID
8136         err17935 "bad link rename"
8137     fi
8138     rm $DIR/$tdir/foo2/maggie
8139
8140     # overflow the EA
8141     local longname=filename_avg_len_is_thirty_two_
8142     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
8143         error "failed to hardlink many files"
8144     links=$($LFS fid2path $DIR $FID | wc -l)
8145     echo -n "${links}/1000 links in link EA"
8146     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
8147     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
8148         error "failed to unlink many hardlinks"
8149 }
8150 run_test 161 "link ea sanity"
8151
8152 check_path() {
8153     local expected=$1
8154     shift
8155     local fid=$2
8156
8157     local path=$(${LFS} fid2path $*)
8158     RC=$?
8159
8160     if [ $RC -ne 0 ]; then
8161         err17935 "path looked up of $expected failed. Error $RC"
8162         return $RC
8163     elif [ "${path}" != "${expected}" ]; then
8164         err17935 "path looked up \"${path}\" instead of \"${expected}\""
8165         return 2
8166     fi
8167     echo "fid $fid resolves to path $path (expected $expected)"
8168 }
8169
8170 test_162() {
8171         # Make changes to filesystem
8172         mkdir -p $DIR/$tdir/d2
8173         touch $DIR/$tdir/d2/$tfile
8174         touch $DIR/$tdir/d2/x1
8175         touch $DIR/$tdir/d2/x2
8176         mkdir -p $DIR/$tdir/d2/a/b/c
8177         mkdir -p $DIR/$tdir/d2/p/q/r
8178         # regular file
8179         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
8180         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
8181
8182         # softlink
8183         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
8184         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
8185         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
8186
8187         # softlink to wrong file
8188         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
8189         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
8190         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
8191
8192         # hardlink
8193         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
8194         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
8195         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
8196         # fid2path dir/fsname should both work
8197         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
8198         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
8199
8200         # hardlink count: check that there are 2 links
8201         # Doesnt work with CMD yet: 17935
8202         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
8203                 err17935 "expected 2 links"
8204
8205         # hardlink indexing: remove the first link
8206         rm $DIR/$tdir/d2/p/q/r/hlink
8207         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
8208
8209         return 0
8210 }
8211 run_test 162 "path lookup sanity"
8212
8213 test_163() {
8214         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8215         copytool --test $FSNAME || { skip "copytool not runnable: $?" && return; }
8216         copytool $FSNAME &
8217         sleep 1
8218         local uuid=$($LCTL get_param -n mdc.${FSNAME}-MDT0000-mdc-*.uuid)
8219         # this proc file is temporary and linux-only
8220         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT0000.mdccomm=$uuid ||\
8221          error "kernel->userspace send failed"
8222         kill -INT $!
8223 }
8224 run_test 163 "kernel <-> userspace comms"
8225
8226 test_169() {
8227         # do directio so as not to populate the page cache
8228         log "creating a 10 Mb file"
8229         multiop $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
8230         log "starting reads"
8231         dd if=$DIR/$tfile of=/dev/null bs=4096 &
8232         log "truncating the file"
8233         multiop $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
8234         log "killing dd"
8235         kill %+ || true # reads might have finished
8236         echo "wait until dd is finished"
8237         wait
8238         log "removing the temporary file"
8239         rm -rf $DIR/$tfile || error "tmp file removal failed"
8240 }
8241 run_test 169 "parallel read and truncate should not deadlock"
8242
8243 test_170() {
8244         $LCTL clear     # bug 18514
8245         $LCTL debug_daemon start $TMP/${tfile}_log_good
8246         touch $DIR/$tfile
8247         $LCTL debug_daemon stop
8248         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
8249                error "sed failed to read log_good"
8250
8251         $LCTL debug_daemon start $TMP/${tfile}_log_good
8252         rm -rf $DIR/$tfile
8253         $LCTL debug_daemon stop
8254
8255         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
8256                error "lctl df log_bad failed"
8257
8258         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
8259         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
8260
8261         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
8262         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
8263
8264         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
8265                 error "bad_line good_line1 good_line2 are empty"
8266
8267         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
8268         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
8269         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
8270
8271         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
8272         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
8273         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
8274
8275         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
8276                 error "bad_line_new good_line_new are empty"
8277
8278         local expected_good=$((good_line1 + good_line2*2))
8279
8280         rm -f $TMP/${tfile}*
8281         # LU-231, short malformed line may not be counted into bad lines
8282         if [ $bad_line -ne $bad_line_new ] &&
8283                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
8284                 error "expected $bad_line bad lines, but got $bad_line_new"
8285                 return 1
8286         fi
8287
8288         if [ $expected_good -ne $good_line_new ]; then
8289                 error "expected $expected_good good lines, but got $good_line_new"
8290                 return 2
8291         fi
8292         true
8293 }
8294 run_test 170 "test lctl df to handle corrupted log ====================="
8295
8296 test_171() { # bug20592
8297 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
8298         $LCTL set_param fail_loc=0x50e
8299         $LCTL set_param fail_val=3000
8300         multiop_bg_pause $DIR/$tfile O_s || true
8301         local MULTIPID=$!
8302         kill -USR1 $MULTIPID
8303         # cause log dump
8304         sleep 3
8305         wait $MULTIPID
8306         if dmesg | grep "recursive fault"; then
8307                 error "caught a recursive fault"
8308         fi
8309         $LCTL set_param fail_loc=0
8310         true
8311 }
8312 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
8313
8314 # it would be good to share it with obdfilter-survey/libecho code
8315 setup_obdecho_osc () {
8316         local rc=0
8317         local ost_nid=$1
8318         local obdfilter_name=$2
8319         echo "Creating new osc for $obdfilter_name on $ost_nid"
8320         # make sure we can find loopback nid
8321         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
8322
8323         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
8324                            ${obdfilter_name}_osc_UUID || rc=2; }
8325         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
8326                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
8327         return $rc
8328 }
8329
8330 cleanup_obdecho_osc () {
8331         local obdfilter_name=$1
8332         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
8333         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
8334         return 0
8335 }
8336
8337 obdecho_create_test() {
8338         local OBD=$1
8339         local node=$2
8340         local rc=0
8341         local id
8342         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
8343         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
8344                            rc=2; }
8345         if [ $rc -eq 0 ]; then
8346             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
8347             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
8348         fi
8349         echo "New object id is $id"
8350         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec test_brw 10 w v 64 $id" ||
8351                            rc=4; }
8352         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
8353                                         "cleanup" || rc=5; }
8354         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
8355                                         "detach" || rc=6; }
8356         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
8357         return $rc
8358 }
8359
8360 test_180a() {
8361         remote_ost_nodsh && skip "remote OST with nodsh" && return
8362         local rc=0
8363         local rmmod_local=0
8364
8365         if ! module_loaded obdecho; then
8366             load_module obdecho/obdecho
8367             rmmod_local=1
8368         fi
8369
8370         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
8371         local host=$(lctl get_param -n osc.$osc.import |
8372                              awk '/current_connection:/ {print $2}' )
8373         local target=$(lctl get_param -n osc.$osc.import |
8374                              awk '/target:/ {print $2}' )
8375         target=${target%_UUID}
8376
8377         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
8378         [ $rc -eq 0 ] && { obdecho_create_test ${target}_osc client || rc=2; }
8379         [[ -n $target ]] && cleanup_obdecho_osc $target
8380         [ $rmmod_local -eq 1 ] && rmmod obdecho
8381         return $rc
8382 }
8383 run_test 180a "test obdecho on osc"
8384
8385 test_180b() {
8386         remote_ost_nodsh && skip "remote OST with nodsh" && return
8387         local rc=0
8388         local rmmod_remote=0
8389
8390         do_facet ost1 "lsmod | grep -q obdecho || "                      \
8391                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
8392                       "modprobe obdecho; }" && rmmod_remote=1
8393         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
8394         [[ -n $target ]] && { obdecho_create_test $target ost1 || rc=1; }
8395         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
8396         return $rc
8397 }
8398 run_test 180b "test obdecho directly on obdfilter"
8399
8400 test_181() { # bug 22177
8401         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
8402         # create enough files to index the directory
8403         createmany -o $DIR/$tdir/foobar 4000
8404         # print attributes for debug purpose
8405         lsattr -d .
8406         # open dir
8407         multiop_bg_pause $DIR/$tdir D_Sc || return 1
8408         MULTIPID=$!
8409         # remove the files & current working dir
8410         unlinkmany $DIR/$tdir/foobar 4000
8411         rmdir $DIR/$tdir
8412         kill -USR1 $MULTIPID
8413         wait $MULTIPID
8414         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
8415         return 0
8416 }
8417 run_test 181 "Test open-unlinked dir ========================"
8418
8419 # OST pools tests
8420 POOL=${POOL:-cea1}
8421 TGT_COUNT=$OSTCOUNT
8422 TGTPOOL_FIRST=1
8423 TGTPOOL_MAX=$(($TGT_COUNT - 1))
8424 TGTPOOL_STEP=2
8425 TGTPOOL_LIST=`seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`
8426 POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
8427 POOL_DIR_NAME=dir_tst
8428 POOL_DIR=$POOL_ROOT/$POOL_DIR_NAME
8429 POOL_FILE=$POOL_ROOT/file_tst
8430
8431 check_file_in_pool()
8432 {
8433         file=$1
8434         res=$($GETSTRIPE $file | grep 0x | cut -f2)
8435         for i in $res
8436         do
8437                 found=$(echo :$TGTPOOL_LIST: | tr " " ":"  | grep :$i:)
8438                 if [[ "$found" == "" ]]
8439                 then
8440                         echo "pool list: $TGTPOOL_LIST"
8441                         echo "striping: $res"
8442                         error "$file not allocated in $POOL"
8443                         return 1
8444                 fi
8445         done
8446         return 0
8447 }
8448
8449 trap "cleanup_pools $FSNAME" EXIT
8450
8451 test_200a() {
8452         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8453     create_pool $FSNAME.$POOL || return $?
8454         [ $($LFS pool_list $FSNAME | grep -c $POOL) -eq 1 ] ||
8455                 error "$POOL not in lfs pool_list"
8456 }
8457 run_test 200a "Create new pool =========================================="
8458
8459 test_200b() {
8460         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8461         TGT=$(for i in $TGTPOOL_LIST; do printf "$FSNAME-OST%04x_UUID " $i; done)
8462         do_facet mgs $LCTL pool_add $FSNAME.$POOL \
8463                 $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]
8464         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | sort -u | tr '\n' ' ' " "$TGT" ||
8465                 error "Add to pool failed"
8466         local lfscount=$($LFS pool_list $FSNAME.$POOL | grep -c "\-OST")
8467         local addcount=$((($TGTPOOL_MAX - $TGTPOOL_FIRST) / $TGTPOOL_STEP + 1))
8468         [ $lfscount -eq $addcount ] ||
8469                 error "lfs pool_list bad ost count $lfscount != $addcount"
8470 }
8471 run_test 200b "Add targets to a pool ===================================="
8472
8473 test_200c() {
8474         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8475         mkdir -p $POOL_DIR
8476         $SETSTRIPE -c 2 -p $POOL $POOL_DIR
8477         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
8478         # b-19919 test relative path works well
8479         mkdir -p $POOL_DIR/$POOL_DIR_NAME
8480         cd $POOL_DIR
8481         $SETSTRIPE -c 2 -p $POOL $POOL_DIR_NAME
8482         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/$POOL_DIR_NAME"
8483         $SETSTRIPE -c 2 -p $POOL ./$POOL_DIR_NAME
8484         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/./$POOL_DIR_NAME"
8485         $SETSTRIPE -c 2 -p $POOL ../$POOL_DIR_NAME
8486         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/../$POOL_DIR_NAME"
8487         $SETSTRIPE -c 2 -p $POOL ../$POOL_DIR_NAME/$POOL_DIR_NAME
8488         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/../$POOL_DIR_NAME/$POOL_DIR_NAME"
8489         rm -rf $POOL_DIR_NAME; cd -
8490 }
8491 run_test 200c "Set pool on a directory ================================="
8492
8493 test_200d() {
8494         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8495         res=$($GETSTRIPE --pool $POOL_DIR)
8496         [ $res = $POOL ] || error "Pool on $POOL_DIR is $res, not $POOL"
8497 }
8498 run_test 200d "Check pool on a directory ==============================="
8499
8500 test_200e() {
8501         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8502         failed=0
8503         for i in $(seq -w 1 $(($TGT_COUNT * 3)))
8504         do
8505                 file=$POOL_DIR/file-$i
8506                 touch $file
8507                 check_file_in_pool $file
8508                 if [[ $? != 0 ]]
8509                 then
8510                         failed=$(($failed + 1))
8511                 fi
8512         done
8513         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
8514 }
8515 run_test 200e "Check files allocation from directory pool =============="
8516
8517 test_200f() {
8518         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8519         mkdir -p $POOL_FILE
8520         failed=0
8521         for i in $(seq -w 1 $(($TGT_COUNT * 3)))
8522         do
8523                 file=$POOL_FILE/spoo-$i
8524                 $SETSTRIPE -p $POOL $file
8525                 check_file_in_pool $file
8526                 if [[ $? != 0 ]]
8527                 then
8528                         failed=$(($failed + 1))
8529                 fi
8530         done
8531         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
8532 }
8533 run_test 200f "Create files in a pool ==================================="
8534
8535 test_200g() {
8536         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8537         TGT=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$POOL | tr '\n' ' ')
8538         res=$($LFS df --pool $FSNAME.$POOL | awk '{print $1}' | grep "$FSNAME-OST" | tr '\n' ' ')
8539         [ "$res" = "$TGT" ] || error "Pools OSTs '$TGT' is not '$res' that lfs df reports"
8540 }
8541 run_test 200g "lfs df a pool ============================================"
8542
8543 test_200h() { # b=24039
8544         mkdir -p $POOL_DIR || error "unable to create $POOL_DIR"
8545
8546         local file="/..$POOL_DIR/$tfile-1"
8547         $SETSTRIPE -p $POOL $file || error "unable to create $file"
8548
8549         cd $POOL_DIR
8550         $SETSTRIPE -p $POOL $tfile-2 || \
8551                 error "unable to create $tfile-2 in $POOL_DIR"
8552 }
8553 run_test 200h "Create files in a pool with relative pathname ============"
8554
8555 test_201a() {
8556         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8557         TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
8558         do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
8559         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | grep $TGT" "" ||
8560                 error "$TGT not removed from $FSNAME.$POOL"
8561 }
8562 run_test 201a "Remove a target from a pool ============================="
8563
8564 test_201b() {
8565         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8566         for TGT in $($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | sort -u)
8567         do
8568                 do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
8569         done
8570         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL" "" ||
8571                 error "Pool $FSNAME.$POOL cannot be drained"
8572         # striping on an empty/nonexistant pool should fall back to "pool of everything"
8573         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for empty pool"
8574         # setstripe on an empty pool should fail
8575         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
8576                 error "expected failure when creating file with empty pool"
8577         return 0
8578 }
8579 run_test 201b "Remove all targets from a pool =========================="
8580
8581 test_201c() {
8582         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8583         do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
8584
8585         sleep 2
8586     # striping on an empty/nonexistant pool should fall back to "pool of everything"
8587         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for missing pool"
8588         # setstripe on an empty pool should fail
8589         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
8590                 error "expected failure when creating file with missing pool"
8591
8592         # get param should return err once pool is gone
8593         if wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null ||
8594                         echo foo" "foo"; then
8595                 remove_pool_from_list $FSNAME.$POOL
8596                 return 0
8597         fi
8598         error "Pool $FSNAME.$POOL is not destroyed"
8599 }
8600 run_test 201c "Remove a pool ============================================"
8601
8602 cleanup_pools $FSNAME
8603
8604 # usage: default_attr <count | size | offset>
8605 default_attr() {
8606         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
8607 }
8608
8609 # usage: check_default_stripe_attr
8610 check_default_stripe_attr() {
8611         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
8612         case $1 in
8613         --stripe-count|--count)
8614                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
8615         --stripe-size|--size)
8616                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
8617         --stripe-index|--index)
8618                 EXPECTED=-1;;
8619         *)
8620                 error "unknown getstripe attr '$1'"
8621         esac
8622
8623         [ $ACTUAL != $EXPECTED ] &&
8624                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
8625 }
8626
8627 test_204a() {
8628         mkdir -p $DIR/$tdir
8629         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
8630
8631         check_default_stripe_attr --stripe-count
8632         check_default_stripe_attr --stripe-size
8633         check_default_stripe_attr --stripe-index
8634
8635         return 0
8636 }
8637 run_test 204a "Print default stripe attributes ================="
8638
8639 test_204b() {
8640         mkdir -p $DIR/$tdir
8641         $SETSTRIPE --stripe-count 1 $DIR/$tdir
8642
8643         check_default_stripe_attr --stripe-size
8644         check_default_stripe_attr --stripe-index
8645
8646         return 0
8647 }
8648 run_test 204b "Print default stripe size and offset  ==========="
8649
8650 test_204c() {
8651         mkdir -p $DIR/$tdir
8652         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
8653
8654         check_default_stripe_attr --stripe-count
8655         check_default_stripe_attr --stripe-index
8656
8657         return 0
8658 }
8659 run_test 204c "Print default stripe count and offset ==========="
8660
8661 test_204d() {
8662         mkdir -p $DIR/$tdir
8663         $SETSTRIPE --stripe-index 0 $DIR/$tdir
8664
8665         check_default_stripe_attr --stripe-count
8666         check_default_stripe_attr --stripe-size
8667
8668         return 0
8669 }
8670 run_test 204d "Print default stripe count and size ============="
8671
8672 test_204e() {
8673         mkdir -p $DIR/$tdir
8674         $SETSTRIPE -d $DIR/$tdir
8675
8676         check_default_stripe_attr --stripe-count --raw
8677         check_default_stripe_attr --stripe-size --raw
8678         check_default_stripe_attr --stripe-index --raw
8679
8680         return 0
8681 }
8682 run_test 204e "Print raw stripe attributes ================="
8683
8684 test_204f() {
8685         mkdir -p $DIR/$tdir
8686         $SETSTRIPE --stripe-count 1 $DIR/$tdir
8687
8688         check_default_stripe_attr --stripe-size --raw
8689         check_default_stripe_attr --stripe-index --raw
8690
8691         return 0
8692 }
8693 run_test 204f "Print raw stripe size and offset  ==========="
8694
8695 test_204g() {
8696         mkdir -p $DIR/$tdir
8697         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
8698
8699         check_default_stripe_attr --stripe-count --raw
8700         check_default_stripe_attr --stripe-index --raw
8701
8702         return 0
8703 }
8704 run_test 204g "Print raw stripe count and offset ==========="
8705
8706 test_204h() {
8707         mkdir -p $DIR/$tdir
8708         $SETSTRIPE --stripe-index 0 $DIR/$tdir
8709
8710         check_default_stripe_attr --stripe-count --raw
8711         check_default_stripe_attr --stripe-size --raw
8712
8713         return 0
8714 }
8715 run_test 204h "Print raw stripe count and size ============="
8716
8717 # Figure out which job scheduler is being used, if any,
8718 # or use a fake one
8719 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
8720         JOBENV=SLURM_JOB_ID
8721 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
8722         JOBENV=LSB_JOBID
8723 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
8724         JOBENV=PBS_JOBID
8725 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
8726         JOBENV=LOADL_STEP_ID
8727 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
8728         JOBENV=JOB_ID
8729 else
8730         JOBENV=FAKE_JOBID
8731 fi
8732
8733 verify_jobstats() {
8734         local cmd=$1
8735         local target=$2
8736
8737         # clear old jobstats
8738         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
8739         do_facet ost0 lctl set_param obdfilter.*.job_stats="clear"
8740
8741         # use a new JobID for this test, or we might see an old one
8742         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
8743
8744         JOBVAL=${!JOBENV}
8745         log "Test: $cmd"
8746         log "Using JobID environment variable $JOBENV=$JOBVAL"
8747
8748         if [ $JOBENV = "FAKE_JOBID" ]; then
8749                 FAKE_JOBID=$JOBVAL $cmd
8750         else
8751                 $cmd
8752         fi
8753
8754         if [ "$target" = "mdt" -o "$target" = "both" ]; then
8755                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
8756                 do_facet $FACET lctl get_param mdt.*.job_stats |
8757                         grep $JOBVAL || error "No job stats found on MDT $FACET"
8758         fi
8759         if [ "$target" = "ost" -o "$target" = "both" ]; then
8760                 FACET=ost0
8761                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
8762                         grep $JOBVAL || error "No job stats found on OST $FACET"
8763         fi
8764 }
8765
8766 test_205() { # Job stats
8767         local cmd
8768         OLD_JOBENV=`$LCTL get_param -n jobid_var`
8769         if [ $OLD_JOBENV != $JOBENV ]; then
8770                 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$JOBENV
8771                 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
8772                         $JOBENV || return 1
8773         fi
8774
8775         # mkdir
8776         cmd="mkdir $DIR/$tfile"
8777         verify_jobstats "$cmd" "mdt"
8778         # rmdir
8779         cmd="rm -fr $DIR/$tfile"
8780         verify_jobstats "$cmd" "mdt"
8781         # mknod
8782         cmd="mknod $DIR/$tfile c 1 3"
8783         verify_jobstats "$cmd" "mdt"
8784         # unlink
8785         cmd="rm -f $DIR/$tfile"
8786         verify_jobstats "$cmd" "mdt"
8787         # open & close
8788         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
8789         verify_jobstats "$cmd" "mdt"
8790         # setattr
8791         cmd="touch $DIR/$tfile"
8792         verify_jobstats "$cmd" "both"
8793         # write
8794         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
8795         verify_jobstats "$cmd" "ost"
8796         # read
8797         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
8798         verify_jobstats "$cmd" "ost"
8799         # truncate
8800         cmd="$TRUNCATE $DIR/$tfile 0"
8801         verify_jobstats "$cmd" "both"
8802         # rename
8803         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
8804         verify_jobstats "$cmd" "mdt"
8805
8806         # cleanup
8807         rm -f $DIR/jobstats_test_rename
8808
8809         if [ $OLD_JOBENV != $JOBENV ]; then
8810                 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$OLD_JOBENV
8811                 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
8812                         $OLD_JOBENV || return 1
8813         fi
8814 }
8815 run_test 205 "Verify job stats"
8816
8817 test_212() {
8818         size=`date +%s`
8819         size=$((size % 8192 + 1))
8820         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
8821         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
8822         rm -f $DIR/f212 $DIR/f212.xyz
8823 }
8824 run_test 212 "Sendfile test ============================================"
8825
8826 test_213() {
8827         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
8828         cancel_lru_locks osc
8829         lctl set_param fail_loc=0x8000040f
8830         # generate a read lock
8831         cat $DIR/$tfile > /dev/null
8832         # write to the file, it will try to cancel the above read lock.
8833         cat /etc/hosts >> $DIR/$tfile
8834 }
8835 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
8836
8837 test_214() { # for bug 20133
8838         mkdir -p $DIR/d214p/d214c
8839         for (( i=0; i < 340; i++ )) ; do
8840                 touch $DIR/d214p/d214c/a$i
8841         done
8842
8843         ls -l $DIR/d214p || error "ls -l $DIR/d214p failed"
8844         mv $DIR/d214p/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
8845         ls $DIR/d214c || error "ls $DIR/d214c failed"
8846         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
8847 }
8848 run_test 214 "hash-indexed directory test - bug 20133"
8849
8850 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
8851 create_lnet_proc_files() {
8852         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
8853         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
8854
8855         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
8856         rm -f "$TMP/lnet_$1.sys_tmp"
8857 }
8858
8859 # counterpart of create_lnet_proc_files
8860 remove_lnet_proc_files() {
8861         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
8862 }
8863
8864 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
8865 # 3rd arg as regexp for body
8866 check_lnet_proc_stats() {
8867         local l=$(cat "$TMP/lnet_$1" |wc -l)
8868         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
8869
8870         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
8871 }
8872
8873 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
8874 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
8875 # optional and can be regexp for 2nd line (lnet.routes case)
8876 check_lnet_proc_entry() {
8877         local blp=2            # blp stands for 'position of 1st line of body'
8878         [ "$5" = "" ] || blp=3 # lnet.routes case
8879
8880         local l=$(cat "$TMP/lnet_$1" |wc -l)
8881         # subtracting one from $blp because the body can be empty
8882         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
8883
8884         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
8885                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
8886
8887         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
8888                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
8889
8890         # bail out if any unexpected line happened
8891         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
8892         [ "$?" != 0 ] || error "$2 misformatted"
8893 }
8894
8895 test_215() { # for bugs 18102, 21079, 21517
8896         local N='(0|[1-9][0-9]*)'       # non-negative numeric
8897         local P='[1-9][0-9]*'           # positive numeric
8898         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
8899         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
8900         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
8901         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
8902
8903         local L1 # regexp for 1st line
8904         local L2 # regexp for 2nd line (optional)
8905         local BR # regexp for the rest (body)
8906
8907         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
8908         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
8909         create_lnet_proc_files "stats"
8910         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
8911         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
8912         remove_lnet_proc_files "stats"
8913
8914         # /proc/sys/lnet/routes should look like this:
8915         # Routing disabled/enabled
8916         # net hops state router
8917         # where net is a string like tcp0, hops >= 0, state is up/down,
8918         # router is a string like 192.168.1.1@tcp2
8919         L1="^Routing (disabled|enabled)$"
8920         L2="^net +hops +state +router$"
8921         BR="^$NET +$N +(up|down) +$NID$"
8922         create_lnet_proc_files "routes"
8923         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
8924         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
8925         remove_lnet_proc_files "routes"
8926
8927         # /proc/sys/lnet/routers should look like this:
8928         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
8929         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
8930         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
8931         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
8932         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
8933         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
8934         create_lnet_proc_files "routers"
8935         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
8936         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
8937         remove_lnet_proc_files "routers"
8938
8939         # /proc/sys/lnet/peers should look like this:
8940         # nid refs state last max rtr min tx min queue
8941         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
8942         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
8943         # numeric (0 or >0 or <0), queue >= 0.
8944         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
8945         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
8946         create_lnet_proc_files "peers"
8947         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
8948         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
8949         remove_lnet_proc_files "peers"
8950
8951         # /proc/sys/lnet/buffers  should look like this:
8952         # pages count credits min
8953         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
8954         L1="^pages +count +credits +min$"
8955         BR="^ +$N +$N +$I +$I$"
8956         create_lnet_proc_files "buffers"
8957         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
8958         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
8959         remove_lnet_proc_files "buffers"
8960
8961         # /proc/sys/lnet/nis should look like this:
8962         # nid status alive refs peer rtr max tx min
8963         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
8964         # alive is numeric (0 or >0 or <0), refs > 0, peer >= 0,
8965         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
8966         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
8967         BR="^$NID +(up|down) +$I +$P +$N +$N +$N +$I +$I$"
8968         create_lnet_proc_files "nis"
8969         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
8970         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
8971         remove_lnet_proc_files "nis"
8972
8973         # can we successfully write to /proc/sys/lnet/stats?
8974         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
8975         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
8976 }
8977 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
8978
8979 test_216() { # bug 20317
8980         remote_ost_nodsh && skip "remote OST with nodsh" && return
8981         local node
8982         local p="$TMP/sanityN-$TESTNAME.parameters"
8983         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
8984         for node in $(osts_nodes); do
8985                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
8986                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
8987                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
8988         done
8989         clear_osc_stats
8990
8991         # agressive lockless i/o settings
8992         for node in $(osts_nodes); do
8993                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
8994         done
8995         lctl set_param -n osc.*.contention_seconds 60
8996
8997         $DIRECTIO write $DIR/$tfile 0 10 4096
8998         $CHECKSTAT -s 40960 $DIR/$tfile
8999
9000         # disable lockless i/o
9001         for node in $(osts_nodes); do
9002                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
9003         done
9004         lctl set_param -n osc.*.contention_seconds 0
9005         clear_osc_stats
9006
9007         dd if=/dev/zero of=$DIR/$tfile count=0
9008         $CHECKSTAT -s 0 $DIR/$tfile
9009
9010         restore_lustre_params <$p
9011         rm -f $p
9012         rm $DIR/$tfile
9013 }
9014 run_test 216 "check lockless direct write works and updates file size and kms correctly"
9015
9016 test_217() { # bug 22430
9017         local node
9018         local nid
9019
9020         for node in $(nodes_list); do
9021                 nid=$(host_nids_address $node $NETTYPE)
9022                 if [[ $nid = *-* ]] ; then
9023                         echo "lctl ping $nid@$NETTYPE"
9024                         lctl ping $nid@$NETTYPE
9025                 else
9026                         echo "skipping $node (no hyphen detected)"
9027                 fi
9028         done
9029 }
9030 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
9031
9032 test_218() {
9033        # do directio so as not to populate the page cache
9034        log "creating a 10 Mb file"
9035        multiop $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
9036        log "starting reads"
9037        dd if=$DIR/$tfile of=/dev/null bs=4096 &
9038        log "truncating the file"
9039        multiop $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
9040        log "killing dd"
9041        kill %+ || true # reads might have finished
9042        echo "wait until dd is finished"
9043        wait
9044        log "removing the temporary file"
9045        rm -rf $DIR/$tfile || error "tmp file removal failed"
9046 }
9047 run_test 218 "parallel read and truncate should not deadlock ======================="
9048
9049 test_219() {
9050         # write one partial page
9051         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
9052         # set no grant so vvp_io_commit_write will do sync write
9053         $LCTL set_param fail_loc=0x411
9054         # write a full page at the end of file
9055         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
9056
9057         $LCTL set_param fail_loc=0
9058         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
9059         $LCTL set_param fail_loc=0x411
9060         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
9061 }
9062 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
9063
9064 test_220() { #LU-325
9065         remote_ost_nodsh && skip "remote OST with nodsh" && return
9066         local OSTIDX=0
9067
9068         mkdir -p $DIR/$tdir
9069         local OST=$(lfs osts | grep ${OSTIDX}": " | \
9070                 awk '{print $2}' | sed -e 's/_UUID$//')
9071
9072         # on the mdt's osc
9073         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
9074         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
9075                         osc.$mdtosc_proc1.prealloc_last_id)
9076         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
9077                         osc.$mdtosc_proc1.prealloc_next_id)
9078
9079         $LFS df -i
9080
9081         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
9082         #define OBD_FAIL_OST_ENOINO              0x229
9083         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
9084         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
9085         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
9086
9087         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
9088
9089         MDSOBJS=$((last_id - next_id))
9090         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
9091
9092         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
9093         echo "OST still has $count kbytes free"
9094
9095         echo "create $MDSOBJS files @next_id..."
9096         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
9097
9098         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
9099                         osc.$mdtosc_proc1.prealloc_last_id)
9100         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
9101                         osc.$mdtosc_proc1.prealloc_next_id)
9102
9103         echo "after creation, last_id=$last_id2, next_id=$next_id2"
9104         $LFS df -i
9105
9106         echo "cleanup..."
9107
9108         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
9109         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
9110
9111         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
9112         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
9113         echo "unlink $MDSOBJS files @$next_id..."
9114         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
9115 }
9116 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
9117
9118 test_221() {
9119         dd if=`which date` of=$MOUNT/date oflag=sync
9120         chmod +x $MOUNT/date
9121
9122         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
9123         $LCTL set_param fail_loc=0x80001401
9124
9125         $MOUNT/date > /dev/null
9126         rm -f $MOUNT/date
9127 }
9128 run_test 221 "make sure fault and truncate race to not cause OOM"
9129
9130 test_222a () {
9131        rm -rf $DIR/$tdir
9132        mkdir -p $DIR/$tdir
9133        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9134        createmany -o $DIR/$tdir/$tfile 10
9135        cancel_lru_locks mdc
9136        cancel_lru_locks osc
9137        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
9138        $LCTL set_param fail_loc=0x31a
9139        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
9140        $LCTL set_param fail_loc=0
9141        rm -r $DIR/$tdir
9142 }
9143 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
9144
9145 test_222b () {
9146        rm -rf $DIR/$tdir
9147        mkdir -p $DIR/$tdir
9148        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9149        createmany -o $DIR/$tdir/$tfile 10
9150        cancel_lru_locks mdc
9151        cancel_lru_locks osc
9152        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
9153        $LCTL set_param fail_loc=0x31a
9154        rm -r $DIR/$tdir || "AGL for rmdir failed"
9155        $LCTL set_param fail_loc=0
9156 }
9157 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
9158
9159 test_223 () {
9160        rm -rf $DIR/$tdir
9161        mkdir -p $DIR/$tdir
9162        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9163        createmany -o $DIR/$tdir/$tfile 10
9164        cancel_lru_locks mdc
9165        cancel_lru_locks osc
9166        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
9167        $LCTL set_param fail_loc=0x31b
9168        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
9169        $LCTL set_param fail_loc=0
9170        rm -r $DIR/$tdir
9171 }
9172 run_test 223 "osc reenqueue if without AGL lock granted ======================="
9173
9174 test_224a() { # LU-1039, MRP-303
9175         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
9176         $LCTL set_param fail_loc=0x508
9177         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
9178         $LCTL set_param fail_loc=0
9179         df $DIR
9180 }
9181 run_test 224a "Don't panic on bulk IO failure"
9182
9183 test_224b() { # LU-1039, MRP-303
9184         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
9185         cancel_lru_locks osc
9186         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
9187         $LCTL set_param fail_loc=0x515
9188         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
9189         $LCTL set_param fail_loc=0
9190         df $DIR
9191 }
9192 run_test 224b "Don't panic on bulk IO failure"
9193
9194 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
9195 test_225a () {
9196        if [ -z ${MDSSURVEY} ]; then
9197               skip_env "mds-survey not found" && return
9198        fi
9199        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
9200             { skip "Need MDS version at least 2.2.51"; return; }
9201
9202        local mds=$(facet_host $SINGLEMDS)
9203        local target=$(do_nodes $mds 'lctl dl' | \
9204                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
9205
9206        local cmd1="file_count=1000 thrhi=4"
9207        local cmd2="dir_count=2 layer=mdd stripe_count=0"
9208        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
9209        local cmd="$cmd1 $cmd2 $cmd3"
9210
9211        rm -f ${TMP}/mds_survey*
9212        echo + $cmd
9213        eval $cmd || error "mds-survey with zero-stripe failed"
9214        cat ${TMP}/mds_survey*
9215        rm -f ${TMP}/mds_survey*
9216 }
9217 run_test 225a "Metadata survey sanity with zero-stripe"
9218
9219 test_225b () {
9220        if [ -z ${MDSSURVEY} ]; then
9221               skip_env "mds-survey not found" && return
9222        fi
9223        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
9224             { skip "Need MDS version at least 2.2.51"; return; }
9225
9226        if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
9227               skip_env "Need to mount OST to test" && return
9228        fi
9229
9230        local mds=$(facet_host $SINGLEMDS)
9231        local target=$(do_nodes $mds 'lctl dl' | \
9232                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
9233
9234        local cmd1="file_count=1000 thrhi=4"
9235        local cmd2="dir_count=2 layer=mdd stripe_count=1"
9236        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
9237        local cmd="$cmd1 $cmd2 $cmd3"
9238
9239        rm -f ${TMP}/mds_survey*
9240        echo + $cmd
9241        eval $cmd || error "mds-survey with stripe_count failed"
9242        cat ${TMP}/mds_survey*
9243        rm -f ${TMP}/mds_survey*
9244 }
9245 run_test 225b "Metadata survey sanity with stripe_count = 1"
9246
9247 mcreate_path2fid () {
9248         local mode=$1
9249         local major=$2
9250         local minor=$3
9251         local name=$4
9252         local desc=$5
9253         local path=$DIR/$tdir/$name
9254         local fid
9255         local rc
9256         local fid_path
9257
9258         $MCREATE --mode=$1 --major=$2 --minor=$3 $path || \
9259                 error "error: cannot create $desc"
9260
9261         fid=$($LFS path2fid $path)
9262         rc=$?
9263         [ $rc -ne 0 ] && error "error: cannot get fid of a $desc"
9264
9265         fid_path=$($LFS fid2path $DIR $fid)
9266         rc=$?
9267         [ $rc -ne 0 ] && error "error: cannot get path of a $desc by fid"
9268
9269         [ "$path" == "$fid_path" ] || \
9270                 error "error: fid2path returned \`$fid_path', expected \`$path'"
9271 }
9272
9273 test_226 () {
9274         rm -rf $DIR/$tdir
9275         mkdir -p $DIR/$tdir
9276
9277         mcreate_path2fid 0010666 0 0 fifo "FIFO"
9278         mcreate_path2fid 0020666 1 3 null "character special file (null)"
9279         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
9280         mcreate_path2fid 0040666 0 0 dir "directory"
9281         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
9282         mcreate_path2fid 0100666 0 0 file "regular file"
9283         mcreate_path2fid 0120666 0 0 link "symbolic link"
9284         mcreate_path2fid 0140666 0 0 sock "socket"
9285 }
9286 run_test 226 "call path2fid and fid2path on files of all type"
9287
9288 # LU-1299 Executing or running ldd on a truncated executable does not
9289 # cause an out-of-memory condition.
9290 test_227() {
9291         dd if=`which date` of=$MOUNT/date bs=1k count=1
9292         chmod +x $MOUNT/date
9293
9294         $MOUNT/date > /dev/null
9295         ldd $MOUNT/date > /dev/null
9296         rm -f $MOUNT/date
9297 }
9298 run_test 227 "running truncated executable does not cause OOM"
9299
9300 #
9301 # tests that do cleanup/setup should be run at the end
9302 #
9303
9304 test_900() {
9305         local ls
9306         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
9307         $LCTL set_param fail_loc=0x903
9308         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
9309         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
9310                 echo "clear" > $ls
9311         done
9312         FAIL_ON_ERROR=true cleanup
9313         FAIL_ON_ERROR=true setup
9314 }
9315 run_test 900 "umount should not race with any mgc requeue thread"
9316
9317 complete $(basename $0) $SECONDS
9318 check_and_cleanup_lustre
9319 if [ "$I_MOUNTED" != "yes" ]; then
9320         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
9321 fi
9322 exit_status