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