Whamcloud - gitweb
LU-988 ost: add debugging for inode timestamps
[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         start_full_debug_logging
2430         touch $DIR1/$tfile
2431         sleep 1
2432
2433         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
2434         local multipid=$!
2435         local mtime1=`stat -c %Y $DIR1/$tfile`
2436
2437         mv $DIR1/$tfile $DIR1/$tfile-1
2438
2439         kill -USR1 $multipid
2440         wait $multipid || error "multiop close failed"
2441
2442         for (( i=0; i < 2; i++ )) ; do
2443                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2444                 [ "$mtime1" = "$mtime2" ] || \
2445                         error "mtime is lost on close: $mtime2, should be $mtime1"
2446
2447                 cancel_lru_locks osc
2448                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2449         done
2450         stop_full_debug_logging
2451 }
2452 run_test 39j "write, rename, close, stat ======================="
2453
2454 test_39k() {
2455         touch $DIR1/$tfile
2456         sleep 1
2457
2458         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
2459         local multipid=$!
2460         local mtime1=`stat -c %Y $DIR1/$tfile`
2461
2462         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2463
2464         kill -USR1 $multipid
2465         wait $multipid || error "multiop close failed"
2466
2467         for (( i=0; i < 2; i++ )) ; do
2468                 local mtime2=`stat -c %Y $DIR1/$tfile`
2469
2470                 [ "$mtime2" = $TEST_39_MTIME ] || \
2471                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
2472
2473                 cancel_lru_locks osc
2474                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2475         done
2476 }
2477 run_test 39k "write, utime, close, stat ========================"
2478
2479 # this should be set to future
2480 TEST_39_ATIME=`date -d "1 year" +%s`
2481
2482 test_39l() {
2483         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2484         local atime_diff=$(do_facet $SINGLEMDS lctl get_param -n mdd.*.atime_diff)
2485
2486         mkdir -p $DIR/$tdir
2487
2488         # test setting directory atime to future
2489         touch -a -d @$TEST_39_ATIME $DIR/$tdir
2490         local atime=$(stat -c %X $DIR/$tdir)
2491         [ "$atime" = $TEST_39_ATIME ] || \
2492                 error "atime is not set to future: $atime, should be $TEST_39_ATIME"
2493
2494         # test setting directory atime from future to now
2495         local d1=$(date +%s)
2496         ls $DIR/$tdir
2497         local d2=$(date +%s)
2498
2499         cancel_lru_locks mdc
2500         atime=$(stat -c %X $DIR/$tdir)
2501         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2502                 error "atime is not updated from future: $atime, should be $d1<atime<$d2"
2503
2504         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=2
2505         sleep 3
2506
2507         # test setting directory atime when now > dir atime + atime_diff
2508         d1=$(date +%s)
2509         ls $DIR/$tdir
2510         d2=$(date +%s)
2511         cancel_lru_locks mdc
2512         atime=$(stat -c %X $DIR/$tdir)
2513         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2514                 error "atime is not updated  : $atime, should be $d2"
2515
2516         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=60
2517         sleep 3
2518
2519         # test not setting directory atime when now < dir atime + atime_diff
2520         ls $DIR/$tdir
2521         cancel_lru_locks mdc
2522         atime=$(stat -c %X $DIR/$tdir)
2523         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2524                 error "atime is updated to $atime, should remain $d1<atime<$d2"
2525
2526         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=$atime_diff
2527 }
2528 run_test 39l "directory atime update ==========================="
2529
2530 test_39m() {
2531         touch $DIR1/$tfile
2532         sleep 2
2533         local far_past_mtime=$(date -d "May 29 1953" +%s)
2534         local far_past_atime=$(date -d "Dec 17 1903" +%s)
2535
2536         touch -m -d @$far_past_mtime $DIR1/$tfile
2537         touch -a -d @$far_past_atime $DIR1/$tfile
2538
2539         for (( i=0; i < 2; i++ )) ; do
2540                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
2541                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
2542                         error "atime or mtime set incorrectly"
2543
2544                 cancel_lru_locks osc
2545                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2546         done
2547 }
2548 run_test 39m "test atime and mtime before 1970"
2549
2550 test_40() {
2551         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
2552         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
2553         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
2554 }
2555 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
2556
2557 test_41() {
2558         # bug 1553
2559         small_write $DIR/f41 18
2560 }
2561 run_test 41 "test small file write + fstat ====================="
2562
2563 count_ost_writes() {
2564         lctl get_param -n osc.*.stats |
2565             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
2566 }
2567
2568 # decent default
2569 WRITEBACK_SAVE=500
2570 DIRTY_RATIO_SAVE=40
2571 MAX_DIRTY_RATIO=50
2572 BG_DIRTY_RATIO_SAVE=10
2573 MAX_BG_DIRTY_RATIO=25
2574
2575 start_writeback() {
2576         trap 0
2577         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
2578         # dirty_ratio, dirty_background_ratio
2579         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
2580                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
2581                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
2582                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
2583         else
2584                 # if file not here, we are a 2.4 kernel
2585                 kill -CONT `pidof kupdated`
2586         fi
2587 }
2588
2589 stop_writeback() {
2590         # setup the trap first, so someone cannot exit the test at the
2591         # exact wrong time and mess up a machine
2592         trap start_writeback EXIT
2593         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
2594         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
2595                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
2596                 sysctl -w vm.dirty_writeback_centisecs=0
2597                 sysctl -w vm.dirty_writeback_centisecs=0
2598                 # save and increase /proc/sys/vm/dirty_ratio
2599                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
2600                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
2601                 # save and increase /proc/sys/vm/dirty_background_ratio
2602                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
2603                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
2604         else
2605                 # if file not here, we are a 2.4 kernel
2606                 kill -STOP `pidof kupdated`
2607         fi
2608 }
2609
2610 # ensure that all stripes have some grant before we test client-side cache
2611 setup_test42() {
2612         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
2613                 dd if=/dev/zero of=$i bs=4k count=1
2614                 rm $i
2615         done
2616 }
2617
2618 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
2619 # file truncation, and file removal.
2620 test_42a() {
2621         setup_test42
2622         cancel_lru_locks osc
2623         stop_writeback
2624         sync; sleep 1; sync # just to be safe
2625         BEFOREWRITES=`count_ost_writes`
2626         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
2627         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
2628         AFTERWRITES=`count_ost_writes`
2629         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
2630                 error "$BEFOREWRITES < $AFTERWRITES"
2631         start_writeback
2632 }
2633 run_test 42a "ensure that we don't flush on close =============="
2634
2635 test_42b() {
2636         setup_test42
2637         cancel_lru_locks osc
2638         stop_writeback
2639         sync
2640         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
2641         BEFOREWRITES=`count_ost_writes`
2642         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
2643         AFTERWRITES=`count_ost_writes`
2644         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
2645                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
2646         fi
2647         BEFOREWRITES=`count_ost_writes`
2648         sync || error "sync: $?"
2649         AFTERWRITES=`count_ost_writes`
2650         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
2651                 error "$BEFOREWRITES < $AFTERWRITES on sync"
2652         fi
2653         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
2654         start_writeback
2655         return 0
2656 }
2657 run_test 42b "test destroy of file with cached dirty data ======"
2658
2659 # if these tests just want to test the effect of truncation,
2660 # they have to be very careful.  consider:
2661 # - the first open gets a {0,EOF}PR lock
2662 # - the first write conflicts and gets a {0, count-1}PW
2663 # - the rest of the writes are under {count,EOF}PW
2664 # - the open for truncate tries to match a {0,EOF}PR
2665 #   for the filesize and cancels the PWs.
2666 # any number of fixes (don't get {0,EOF} on open, match
2667 # composite locks, do smarter file size management) fix
2668 # this, but for now we want these tests to verify that
2669 # the cancellation with truncate intent works, so we
2670 # start the file with a full-file pw lock to match against
2671 # until the truncate.
2672 trunc_test() {
2673         test=$1
2674         file=$DIR/$test
2675         offset=$2
2676         cancel_lru_locks osc
2677         stop_writeback
2678         # prime the file with 0,EOF PW to match
2679         touch $file
2680         $TRUNCATE $file 0
2681         sync; sync
2682         # now the real test..
2683         dd if=/dev/zero of=$file bs=1024 count=100
2684         BEFOREWRITES=`count_ost_writes`
2685         $TRUNCATE $file $offset
2686         cancel_lru_locks osc
2687         AFTERWRITES=`count_ost_writes`
2688         start_writeback
2689 }
2690
2691 test_42c() {
2692         trunc_test 42c 1024
2693         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
2694             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
2695         rm $file
2696 }
2697 run_test 42c "test partial truncate of file with cached dirty data"
2698
2699 test_42d() {
2700         trunc_test 42d 0
2701         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
2702             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
2703         rm $file
2704 }
2705 run_test 42d "test complete truncate of file with cached dirty data"
2706
2707 test_42e() { # bug22074
2708         local TDIR=$DIR/${tdir}e
2709         local pagesz=$(page_size)
2710         local pages=16 # hardcoded 16 pages, don't change it.
2711         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
2712         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
2713         local max_dirty_mb
2714         local warmup_files
2715
2716         mkdir -p $TDIR
2717         $SETSTRIPE -c 1 $TDIR
2718         createmany -o $TDIR/f $files
2719
2720         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
2721
2722         # we assume that with $OSTCOUNT files, at least one of them will
2723         # be allocated on OST0.
2724         warmup_files=$((OSTCOUNT * max_dirty_mb))
2725         createmany -o $TDIR/w $warmup_files
2726
2727         # write a large amount of data into one file and sync, to get good
2728         # avail_grant number from OST.
2729         for ((i=0; i<$warmup_files; i++)); do
2730                 idx=$($GETSTRIPE -i $TDIR/w$i)
2731                 [ $idx -ne 0 ] && continue
2732                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
2733                 break
2734         done
2735         [ $i -gt $warmup_files ] && error "OST0 is still cold"
2736         sync
2737         $LCTL get_param $proc_osc0/cur_dirty_bytes
2738         $LCTL get_param $proc_osc0/cur_grant_bytes
2739
2740         # create as much dirty pages as we can while not to trigger the actual
2741         # RPCs directly. but depends on the env, VFS may trigger flush during this
2742         # period, hopefully we are good.
2743         for ((i=0; i<$warmup_files; i++)); do
2744                 idx=$($GETSTRIPE -i $TDIR/w$i)
2745                 [ $idx -ne 0 ] && continue
2746                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
2747         done
2748         $LCTL get_param $proc_osc0/cur_dirty_bytes
2749         $LCTL get_param $proc_osc0/cur_grant_bytes
2750
2751         # perform the real test
2752         $LCTL set_param $proc_osc0/rpc_stats 0
2753         for ((;i<$files; i++)); do
2754                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
2755                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
2756         done
2757         sync
2758         $LCTL get_param $proc_osc0/rpc_stats
2759
2760         local percent=0
2761         local have_ppr=false
2762         $LCTL get_param $proc_osc0/rpc_stats |
2763                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
2764                         # skip lines until we are at the RPC histogram data
2765                         [ "$PPR" == "pages" ] && have_ppr=true && continue
2766                         $have_ppr || continue
2767
2768                         # we only want the percent stat for < 16 pages
2769                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
2770
2771                         percent=$((percent + WPCT))
2772                         if [ $percent -gt 15 ]; then
2773                                 error "less than 16-pages write RPCs" \
2774                                       "$percent% > 15%"
2775                                 break
2776                         fi
2777                 done
2778         rm -rf $TDIR
2779 }
2780 run_test 42e "verify sub-RPC writes are not done synchronously"
2781
2782 test_43() {
2783         mkdir -p $DIR/$tdir
2784         cp -p /bin/ls $DIR/$tdir/$tfile
2785         $MULTIOP $DIR/$tdir/$tfile Ow_c &
2786         pid=$!
2787         # give multiop a chance to open
2788         sleep 1
2789
2790         $DIR/$tdir/$tfile && error || true
2791         kill -USR1 $pid
2792 }
2793 run_test 43 "execution of file opened for write should return -ETXTBSY"
2794
2795 test_43a() {
2796         mkdir -p $DIR/d43
2797         cp -p `which $MULTIOP` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2798         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2799         MULTIOP_PID=$!
2800         $MULTIOP $DIR/d43/multiop Oc && error "expected error, got success"
2801         kill -USR1 $MULTIOP_PID || return 2
2802         wait $MULTIOP_PID || return 3
2803         rm $TMP/test43.junk
2804 }
2805 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
2806
2807 test_43b() {
2808         mkdir -p $DIR/d43
2809         cp -p `which $MULTIOP` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2810         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2811         MULTIOP_PID=$!
2812         $TRUNCATE $DIR/d43/multiop 0 && error "expected error, got success"
2813         kill -USR1 $MULTIOP_PID || return 2
2814         wait $MULTIOP_PID || return 3
2815         rm $TMP/test43.junk
2816 }
2817 run_test 43b "truncate of file being executed should return -ETXTBSY"
2818
2819 test_43c() {
2820         local testdir="$DIR/d43c"
2821         mkdir -p $testdir
2822         cp $SHELL $testdir/
2823         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
2824                 ( cd $testdir && md5sum -c)
2825 }
2826 run_test 43c "md5sum of copy into lustre========================"
2827
2828 test_44() {
2829         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
2830         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
2831         dd if=$DIR/f1 bs=4k count=1 > /dev/null
2832 }
2833 run_test 44 "zero length read from a sparse stripe ============="
2834
2835 test_44a() {
2836     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
2837                          awk '{print $2}'`
2838     [ -z "$nstripe" ] && skip "can't get stripe info" && return
2839     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
2840     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
2841                       awk '{print $2}'`
2842     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
2843         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
2844     fi
2845
2846     OFFSETS="0 $((stride/2)) $((stride-1))"
2847     for offset in $OFFSETS ; do
2848       for i in `seq 0 $((nstripe-1))`; do
2849         local GLOBALOFFSETS=""
2850         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
2851         local myfn=$DIR/d44a-$size
2852         echo "--------writing $myfn at $size"
2853         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
2854         GLOBALOFFSETS="$GLOBALOFFSETS $size"
2855         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2856                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2857
2858         for j in `seq 0 $((nstripe-1))`; do
2859             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
2860             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
2861             GLOBALOFFSETS="$GLOBALOFFSETS $size"
2862         done
2863         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2864                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2865         rm -f $myfn
2866       done
2867     done
2868 }
2869 run_test 44a "test sparse pwrite ==============================="
2870
2871 dirty_osc_total() {
2872         tot=0
2873         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
2874                 tot=$(($tot + $d))
2875         done
2876         echo $tot
2877 }
2878 do_dirty_record() {
2879         before=`dirty_osc_total`
2880         echo executing "\"$*\""
2881         eval $*
2882         after=`dirty_osc_total`
2883         echo before $before, after $after
2884 }
2885 test_45() {
2886         f="$DIR/f45"
2887         # Obtain grants from OST if it supports it
2888         echo blah > ${f}_grant
2889         stop_writeback
2890         sync
2891         do_dirty_record "echo blah > $f"
2892         [ $before -eq $after ] && error "write wasn't cached"
2893         do_dirty_record "> $f"
2894         [ $before -gt $after ] || error "truncate didn't lower dirty count"
2895         do_dirty_record "echo blah > $f"
2896         [ $before -eq $after ] && error "write wasn't cached"
2897         do_dirty_record "sync"
2898         [ $before -gt $after ] || error "writeback didn't lower dirty count"
2899         do_dirty_record "echo blah > $f"
2900         [ $before -eq $after ] && error "write wasn't cached"
2901         do_dirty_record "cancel_lru_locks osc"
2902         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
2903         start_writeback
2904 }
2905 run_test 45 "osc io page accounting ============================"
2906
2907 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
2908 # test tickles a bug where re-dirtying a page was failing to be mapped to the
2909 # objects offset and an assert hit when an rpc was built with 1023's mapped
2910 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
2911 test_46() {
2912         f="$DIR/f46"
2913         stop_writeback
2914         sync
2915         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2916         sync
2917         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
2918         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2919         sync
2920         start_writeback
2921 }
2922 run_test 46 "dirtying a previously written page ================"
2923
2924 # test_47 is removed "Device nodes check" is moved to test_28
2925
2926 test_48a() { # bug 2399
2927         check_kernel_version 34 || return 0
2928         mkdir -p $DIR/d48a
2929         cd $DIR/d48a
2930         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
2931         mkdir $DIR/d48a || error "recreate directory failed"
2932         touch foo || error "'touch foo' failed after recreating cwd"
2933         mkdir bar || error "'mkdir foo' failed after recreating cwd"
2934         if check_kernel_version 44; then
2935                 touch .foo || error "'touch .foo' failed after recreating cwd"
2936                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
2937         fi
2938         ls . > /dev/null || error "'ls .' failed after recreating cwd"
2939         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2940         cd . || error "'cd .' failed after recreating cwd"
2941         mkdir . && error "'mkdir .' worked after recreating cwd"
2942         rmdir . && error "'rmdir .' worked after recreating cwd"
2943         ln -s . baz || error "'ln -s .' failed after recreating cwd"
2944         cd .. || error "'cd ..' failed after recreating cwd"
2945 }
2946 run_test 48a "Access renamed working dir (should return errors)="
2947
2948 test_48b() { # bug 2399
2949         check_kernel_version 34 || return 0
2950         mkdir -p $DIR/d48b
2951         cd $DIR/d48b
2952         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
2953         touch foo && error "'touch foo' worked after removing cwd"
2954         mkdir foo && error "'mkdir foo' worked after removing cwd"
2955         if check_kernel_version 44; then
2956                 touch .foo && error "'touch .foo' worked after removing cwd"
2957                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2958         fi
2959         ls . > /dev/null && error "'ls .' worked after removing cwd"
2960         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2961         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
2962         mkdir . && error "'mkdir .' worked after removing cwd"
2963         rmdir . && error "'rmdir .' worked after removing cwd"
2964         ln -s . foo && error "'ln -s .' worked after removing cwd"
2965         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
2966 }
2967 run_test 48b "Access removed working dir (should return errors)="
2968
2969 test_48c() { # bug 2350
2970         check_kernel_version 36 || return 0
2971         #lctl set_param debug=-1
2972         #set -vx
2973         mkdir -p $DIR/d48c/dir
2974         cd $DIR/d48c/dir
2975         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
2976         $TRACE touch foo && error "'touch foo' worked after removing cwd"
2977         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
2978         if check_kernel_version 44; then
2979                 touch .foo && error "'touch .foo' worked after removing cwd"
2980                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2981         fi
2982         $TRACE ls . && error "'ls .' worked after removing cwd"
2983         $TRACE ls .. || error "'ls ..' failed after removing cwd"
2984         is_patchless || ( $TRACE cd . && error "'cd .' worked after removing cwd" )
2985         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
2986         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
2987         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
2988         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2989 }
2990 run_test 48c "Access removed working subdir (should return errors)"
2991
2992 test_48d() { # bug 2350
2993         check_kernel_version 36 || return 0
2994         #lctl set_param debug=-1
2995         #set -vx
2996         mkdir -p $DIR/d48d/dir
2997         cd $DIR/d48d/dir
2998         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2999         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
3000         $TRACE touch foo && error "'touch foo' worked after removing parent"
3001         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
3002         if check_kernel_version 44; then
3003                 touch .foo && error "'touch .foo' worked after removing parent"
3004                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
3005         fi
3006         $TRACE ls . && error "'ls .' worked after removing parent"
3007         $TRACE ls .. && error "'ls ..' worked after removing parent"
3008         is_patchless || ( $TRACE cd . && error "'cd .' worked after recreate parent" )
3009         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
3010         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3011         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3012         is_patchless || ( $TRACE cd .. && error "'cd ..' worked after removing parent" || true )
3013 }
3014 run_test 48d "Access removed parent subdir (should return errors)"
3015
3016 test_48e() { # bug 4134
3017         check_kernel_version 41 || return 0
3018         #lctl set_param debug=-1
3019         #set -vx
3020         mkdir -p $DIR/d48e/dir
3021         cd $DIR/d48e/dir
3022         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
3023         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
3024         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
3025         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
3026         # On a buggy kernel addition of "touch foo" after cd .. will
3027         # produce kernel oops in lookup_hash_it
3028         touch ../foo && error "'cd ..' worked after recreate parent"
3029         cd $DIR
3030         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
3031 }
3032 run_test 48e "Access to recreated parent subdir (should return errors)"
3033
3034 test_49() { # LU-1030
3035         # get ost1 size - lustre-OST0000
3036         ost1_size=$(do_facet ost1 lfs df |grep ${ost1_svc} |awk '{print $4}')
3037         # write 800M at maximum
3038         [ $ost1_size -gt 819200 ] && ost1_size=819200
3039
3040         lfs setstripe -c 1 -i 0 $DIR/$tfile
3041         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3042         local dd_pid=$!
3043
3044         # change max_pages_per_rpc while writing the file
3045         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3046         local orig_mppc=`$LCTL get_param -n $osc1_mppc`
3047         # loop until dd process exits
3048         while ps ax -opid | grep -q $dd_pid; do
3049                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3050                 sleep $((RANDOM % 5 + 1))
3051         done
3052         # restore original max_pages_per_rpc
3053         $LCTL set_param $osc1_mppc=$orig_mppc
3054 }
3055 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3056
3057 test_50() {
3058         # bug 1485
3059         mkdir $DIR/d50
3060         cd $DIR/d50
3061         ls /proc/$$/cwd || error
3062 }
3063 run_test 50 "special situations: /proc symlinks  ==============="
3064
3065 test_51a() {    # was test_51
3066         # bug 1516 - create an empty entry right after ".." then split dir
3067         mkdir $DIR/d51
3068         touch $DIR/d51/foo
3069         $MCREATE $DIR/d51/bar
3070         rm $DIR/d51/foo
3071         createmany -m $DIR/d51/longfile 201
3072         FNUM=202
3073         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
3074                 $MCREATE $DIR/d51/longfile$FNUM
3075                 FNUM=$(($FNUM + 1))
3076                 echo -n "+"
3077         done
3078         echo
3079         ls -l $DIR/d51 > /dev/null || error
3080 }
3081 run_test 51a "special situations: split htree with empty entry =="
3082
3083 export NUMTEST=70000
3084 test_51b() {
3085         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3086         [ $NUMFREE -lt 21000 ] && \
3087                 skip "not enough free inodes ($NUMFREE)" && \
3088                 return
3089
3090         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
3091
3092         mkdir -p $DIR/d51b
3093         createmany -d $DIR/d51b/t- $NUMTEST
3094 }
3095 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
3096
3097 test_51ba() { # LU-993
3098         local BASE=$DIR/d51b
3099         # unlink all but 100 subdirectories, then check it still works
3100         local LEFT=100
3101         local DELETE=$((NUMTEST - LEFT))
3102
3103         ! [ -d "${BASE}/t-$DELETE" ] && skip "test_51b() not run" && return 0
3104
3105         # for ldiskfs the nlink count should be 1, but this is OSD specific
3106         # and so this is listed for informational purposes only
3107         log "nlink before: $(stat -c %h $BASE)"
3108         unlinkmany -d $BASE/t- $DELETE ||
3109                 error "unlink of first $DELETE subdirs failed"
3110
3111         log "nlink between: $(stat -c %h $BASE)"
3112         local FOUND=$(ls -l ${BASE} | wc -l)
3113         FOUND=$((FOUND - 1))  # trim the first line of ls output
3114         [ $FOUND -ne $LEFT ] &&
3115                 error "can't find subdirs: found only $FOUND/$LEFT"
3116
3117         unlinkmany -d $BASE/t- $DELETE $LEFT ||
3118                 error "unlink of second $LEFT subdirs failed"
3119         log "nlink after: $(stat -c %h $BASE)"
3120 }
3121 run_test 51ba "rmdir .../t-0 --- .../t-$NUMTEST"
3122
3123 test_51bb() {
3124         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3125
3126         local ndirs=${TEST51BB_NDIRS:-10}
3127         local nfiles=${TEST51BB_NFILES:-100}
3128
3129         local numfree=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3130
3131         [ $numfree -lt $(( ndirs * nfiles)) ] && \
3132                 nfiles=$(( numfree / ndirs - 10 ))
3133
3134         local dir=$DIR/d51bb
3135         mkdir -p $dir
3136         local savePOLICY=$(lctl get_param -n lmv.*.placement)
3137         lctl set_param -n lmv.*.placement=CHAR
3138
3139         lfs df -i $dir
3140         local IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3141         OLDUSED=($IUSED)
3142
3143         declare -a dirs
3144         for ((i=0; i < $ndirs; i++)); do
3145                 dirs[i]=$dir/$RANDOM
3146                 echo Creating directory ${dirs[i]}
3147                 mkdir -p ${dirs[i]}
3148                 ls $dir
3149                 echo Creating $nfiles in dir ${dirs[i]} ...
3150                 echo "createmany -o ${dirs[i]}/$tfile- $nfiles"
3151                 createmany -o ${dirs[i]}/$tfile- $nfiles
3152         done
3153         ls $dir
3154
3155         sleep 1
3156
3157         IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3158         NEWUSED=($IUSED)
3159
3160         local rc=0
3161         for ((i=0; i<${#NEWUSED[@]}; i++)); do
3162                 echo "mds $i: inodes count OLD ${OLDUSED[$i]} NEW ${NEWUSED[$i]}"
3163                 [ ${OLDUSED[$i]} -lt ${NEWUSED[$i]} ] || rc=$((rc + 1))
3164         done
3165
3166         lctl set_param -n lmv.*.placement=$savePOLICY
3167
3168         [ $rc -ne $MDSCOUNT ] || \
3169                 error "Objects/inodes are not distributed over all mds servers"
3170 }
3171 run_test 51bb "mkdir createmany CMD $MDSCOUNT  ===================="
3172
3173 test_51d() {
3174         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3175         mkdir -p $DIR/d51d
3176         createmany -o $DIR/d51d/t- 1000
3177         $GETSTRIPE $DIR/d51d > $TMP/files
3178         for N in `seq 0 $((OSTCOUNT - 1))`; do
3179             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3180             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3181             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3182         done
3183         unlinkmany $DIR/d51d/t- 1000
3184
3185         NLAST=0
3186         for N in `seq 1 $((OSTCOUNT - 1))`; do
3187             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3188                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3189             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3190                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3191
3192             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3193                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3194             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3195                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3196             NLAST=$N
3197         done
3198 }
3199 run_test 51d "check object distribution ===================="
3200
3201 test_52a() {
3202         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
3203         mkdir -p $DIR/d52a
3204         touch $DIR/d52a/foo
3205         chattr +a $DIR/d52a/foo || error "chattr +a failed"
3206         echo bar >> $DIR/d52a/foo || error "append bar failed"
3207         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
3208         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
3209         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
3210         echo foo >> $DIR/d52a/foo || error "append foo failed"
3211         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
3212         lsattr $DIR/d52a/foo | egrep -q "^-+a[-e]+ $DIR/d52a/foo" || error "lsattr"
3213         chattr -a $DIR/d52a/foo || error "chattr -a failed"
3214         cp -r $DIR/d52a /tmp/
3215         rm -fr $DIR/d52a || error "cleanup rm failed"
3216 }
3217 run_test 52a "append-only flag test (should return errors) ====="
3218
3219 test_52b() {
3220         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
3221         mkdir -p $DIR/d52b
3222         touch $DIR/d52b/foo
3223         chattr +i $DIR/d52b/foo || error "chattr +i failed"
3224         cat test > $DIR/d52b/foo && error "cat test worked"
3225         cp /etc/hosts $DIR/d52b/foo && error "cp worked"
3226         rm -f $DIR/d52b/foo 2>/dev/null && error "rm worked"
3227         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error  "link worked"
3228         echo foo >> $DIR/d52b/foo && error "echo worked"
3229         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error "rename worked"
3230         [ -f $DIR/d52b/foo ] || error
3231         [ -f $DIR/d52b/foo_ren ] && error
3232         lsattr $DIR/d52b/foo | egrep -q "^-+i[-e]+ $DIR/d52b/foo" || error "lsattr"
3233         chattr -i $DIR/d52b/foo || error "chattr failed"
3234
3235         rm -fr $DIR/d52b || error
3236 }
3237 run_test 52b "immutable flag test (should return errors) ======="
3238
3239 test_53() {
3240         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3241         remote_ost_nodsh && skip "remote OST with nodsh" && return
3242
3243         local param
3244         local ostname
3245         local mds_last
3246         local ost_last
3247         local ostnum
3248
3249         # only test MDT0000
3250         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3251         for value in $(do_facet $SINGLEMDS lctl get_param osc.$mdtosc.prealloc_last_id) ; do
3252                 param=`echo ${value[0]} | cut -d "=" -f1`
3253                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
3254                 mds_last=$(do_facet $SINGLEMDS lctl get_param -n $param)
3255                 ostnum=$(echo $ostname | sed "s/${FSNAME}-OST//g" | awk '{print ($1+1)}' )
3256                 ost_last=$(do_facet ost$ostnum lctl get_param -n obdfilter.$ostname.last_id | head -n 1)
3257                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3258                 if [ $ost_last != $mds_last ]; then
3259                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3260                 fi
3261         done
3262 }
3263 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
3264
3265 test_54a() {
3266         [ ! -f "$SOCKETSERVER" ] && skip_env "no socketserver, skipping" && return
3267         [ ! -f "$SOCKETCLIENT" ] && skip_env "no socketclient, skipping" && return
3268         $SOCKETSERVER $DIR/socket
3269         $SOCKETCLIENT $DIR/socket || error
3270         $MUNLINK $DIR/socket
3271 }
3272 run_test 54a "unix domain socket test =========================="
3273
3274 test_54b() {
3275         f="$DIR/f54b"
3276         mknod $f c 1 3
3277         chmod 0666 $f
3278         dd if=/dev/zero of=$f bs=`page_size` count=1
3279 }
3280 run_test 54b "char device works in lustre ======================"
3281
3282 find_loop_dev() {
3283         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
3284         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
3285         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
3286
3287         for i in `seq 3 7`; do
3288                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
3289                 LOOPDEV=$LOOPBASE$i
3290                 LOOPNUM=$i
3291                 break
3292         done
3293 }
3294
3295 test_54c() {
3296         tfile="$DIR/f54c"
3297         tdir="$DIR/d54c"
3298         loopdev="$DIR/loop54c"
3299
3300         find_loop_dev
3301         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
3302         mknod $loopdev b 7 $LOOPNUM
3303         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
3304         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
3305         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
3306         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
3307         mkdir -p $tdir
3308         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
3309         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
3310         df $tdir
3311         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
3312         $UMOUNT $tdir
3313         losetup -d $loopdev
3314         rm $loopdev
3315 }
3316 run_test 54c "block device works in lustre ====================="
3317
3318 test_54d() {
3319         f="$DIR/f54d"
3320         string="aaaaaa"
3321         mknod $f p
3322         [ "$string" = `echo $string > $f | cat $f` ] || error
3323 }
3324 run_test 54d "fifo device works in lustre ======================"
3325
3326 test_54e() {
3327         check_kernel_version 46 || return 0
3328         f="$DIR/f54e"
3329         string="aaaaaa"
3330         cp -aL /dev/console $f
3331         echo $string > $f || error
3332 }
3333 run_test 54e "console/tty device works in lustre ======================"
3334
3335 #The test_55 used to be iopen test and it was removed by bz#24037.
3336 #run_test 55 "check iopen_connect_dentry() ======================"
3337
3338 test_56a() {    # was test_56
3339         rm -rf $DIR/d56
3340         $SETSTRIPE -d $DIR
3341         mkdir $DIR/d56
3342         mkdir $DIR/d56/dir
3343         NUMFILES=3
3344         NUMFILESx2=$(($NUMFILES * 2))
3345         for i in `seq 1 $NUMFILES` ; do
3346                 touch $DIR/d56/file$i
3347                 touch $DIR/d56/dir/file$i
3348         done
3349
3350         # test lfs getstripe with --recursive
3351         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
3352         [ $FILENUM -eq $NUMFILESx2 ] ||
3353                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
3354         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
3355         [ $FILENUM -eq $NUMFILES ] ||
3356                 error "$GETSTRIPE $DIR/d56: found $FILENUM, not $NUMFILES"
3357         echo "$GETSTRIPE --recursive passed."
3358
3359         # test lfs getstripe with file instead of dir
3360         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
3361         [ $FILENUM  -eq 1 ] || error \
3362                  "$GETSTRIPE $DIR/d56/file1: found $FILENUM, not 1"
3363         echo "$GETSTRIPE file1 passed."
3364
3365         #test lfs getstripe with --verbose
3366         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||
3367                 error "$GETSTRIPE --verbose $DIR/d56: want $NUMFILES lmm_magic"
3368         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] ||
3369             error "$GETSTRIPE $DIR/d56: showed lmm_magic"
3370         echo "$GETSTRIPE --verbose passed."
3371
3372         #test lfs getstripe with --obd
3373         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" ||
3374                 error "$GETSTRIPE --obd wrong_uuid should return error message"
3375
3376         [  "$OSTCOUNT" -lt 2 ] &&
3377                 skip_env "skipping other $GETSTRIPE --obd test" && return
3378
3379         OSTIDX=1
3380         OBDUUID=$(ostuuid_from_index $OSTIDX)
3381         FILENUM=`$GETSTRIPE -ir $DIR/d56 | grep -x $OSTIDX | wc -l`
3382         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | grep obdidx | wc -l`
3383         [ $FOUND -eq $FILENUM ] ||
3384                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
3385         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 |
3386                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
3387                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
3388                 error "$GETSTRIPE --obd: should not show file on other obd"
3389         echo "$GETSTRIPE --obd passed"
3390 }
3391 run_test 56a "check $GETSTRIPE"
3392
3393 NUMFILES=3
3394 NUMDIRS=3
3395 setup_56() {
3396         local LOCAL_NUMFILES="$1"
3397         local LOCAL_NUMDIRS="$2"
3398         local MKDIR_PARAMS="$3"
3399
3400         if [ ! -d "$TDIR" ] ; then
3401                 mkdir -p $TDIR
3402                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
3403                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3404                         touch $TDIR/file$i
3405                 done
3406                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3407                         mkdir $TDIR/dir$i
3408                         for j in `seq 1 $LOCAL_NUMFILES` ; do
3409                                 touch $TDIR/dir$i/file$j
3410                         done
3411                 done
3412         fi
3413 }
3414
3415 setup_56_special() {
3416         LOCAL_NUMFILES=$1
3417         LOCAL_NUMDIRS=$2
3418         setup_56 $1 $2
3419         if [ ! -e "$TDIR/loop1b" ] ; then
3420                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3421                         mknod $TDIR/loop${i}b b 7 $i
3422                         mknod $TDIR/null${i}c c 1 3
3423                         ln -s $TDIR/file1 $TDIR/link${i}l
3424                 done
3425                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3426                         mknod $TDIR/dir$i/loop${i}b b 7 $i
3427                         mknod $TDIR/dir$i/null${i}c c 1 3
3428                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
3429                 done
3430         fi
3431 }
3432
3433 test_56g() {
3434         $SETSTRIPE -d $DIR
3435
3436         TDIR=$DIR/${tdir}g
3437         setup_56 $NUMFILES $NUMDIRS
3438
3439         EXPECTED=$(($NUMDIRS + 2))
3440         # test lfs find with -name
3441         for i in $(seq 1 $NUMFILES) ; do
3442                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
3443                 [ $NUMS -eq $EXPECTED ] ||
3444                         error "lfs find -name \"*$i\" $TDIR wrong: "\
3445                               "found $NUMS, expected $EXPECTED"
3446         done
3447 }
3448 run_test 56g "check lfs find -name ============================="
3449
3450 test_56h() {
3451         $SETSTRIPE -d $DIR
3452
3453         TDIR=$DIR/${tdir}g
3454         setup_56 $NUMFILES $NUMDIRS
3455
3456         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
3457         # test lfs find with ! -name
3458         for i in $(seq 1 $NUMFILES) ; do
3459                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
3460                 [ $NUMS -eq $EXPECTED ] ||
3461                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
3462                               "found $NUMS, expected $EXPECTED"
3463         done
3464 }
3465 run_test 56h "check lfs find ! -name ============================="
3466
3467 test_56i() {
3468        tdir=${tdir}i
3469        mkdir -p $DIR/$tdir
3470        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
3471        CMD="$LFIND -ost $UUID $DIR/$tdir"
3472        OUT=$($CMD)
3473        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
3474 }
3475 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
3476
3477 test_56j() {
3478         TDIR=$DIR/${tdir}g
3479         setup_56_special $NUMFILES $NUMDIRS
3480
3481         EXPECTED=$((NUMDIRS + 1))
3482         CMD="$LFIND -type d $TDIR"
3483         NUMS=$($CMD | wc -l)
3484         [ $NUMS -eq $EXPECTED ] ||
3485                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3486 }
3487 run_test 56j "check lfs find -type d ============================="
3488
3489 test_56k() {
3490         TDIR=$DIR/${tdir}g
3491         setup_56_special $NUMFILES $NUMDIRS
3492
3493         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3494         CMD="$LFIND -type f $TDIR"
3495         NUMS=$($CMD | wc -l)
3496         [ $NUMS -eq $EXPECTED ] ||
3497                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3498 }
3499 run_test 56k "check lfs find -type f ============================="
3500
3501 test_56l() {
3502         TDIR=$DIR/${tdir}g
3503         setup_56_special $NUMFILES $NUMDIRS
3504
3505         EXPECTED=$((NUMDIRS + NUMFILES))
3506         CMD="$LFIND -type b $TDIR"
3507         NUMS=$($CMD | wc -l)
3508         [ $NUMS -eq $EXPECTED ] ||
3509                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3510 }
3511 run_test 56l "check lfs find -type b ============================="
3512
3513 test_56m() {
3514         TDIR=$DIR/${tdir}g
3515         setup_56_special $NUMFILES $NUMDIRS
3516
3517         EXPECTED=$((NUMDIRS + NUMFILES))
3518         CMD="$LFIND -type c $TDIR"
3519         NUMS=$($CMD | wc -l)
3520         [ $NUMS -eq $EXPECTED ] ||
3521                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3522 }
3523 run_test 56m "check lfs find -type c ============================="
3524
3525 test_56n() {
3526         TDIR=$DIR/${tdir}g
3527         setup_56_special $NUMFILES $NUMDIRS
3528
3529         EXPECTED=$((NUMDIRS + NUMFILES))
3530         CMD="$LFIND -type l $TDIR"
3531         NUMS=$($CMD | wc -l)
3532         [ $NUMS -eq $EXPECTED ] ||
3533                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3534 }
3535 run_test 56n "check lfs find -type l ============================="
3536
3537 test_56o() {
3538         TDIR=$DIR/${tdir}o
3539         setup_56 $NUMFILES $NUMDIRS
3540
3541         utime $TDIR/file1 > /dev/null || error "utime (1)"
3542         utime $TDIR/file2 > /dev/null || error "utime (2)"
3543         utime $TDIR/dir1 > /dev/null || error "utime (3)"
3544         utime $TDIR/dir2 > /dev/null || error "utime (4)"
3545         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
3546         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
3547
3548         EXPECTED=4
3549         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
3550         [ $NUMS -eq $EXPECTED ] || \
3551                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
3552
3553         EXPECTED=12
3554         CMD="$LFIND -mtime 0 $TDIR"
3555         NUMS=$($CMD | wc -l)
3556         [ $NUMS -eq $EXPECTED ] ||
3557                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3558 }
3559 run_test 56o "check lfs find -mtime for old files =========================="
3560
3561 test_56p() {
3562         [ $RUNAS_ID -eq $UID ] &&
3563                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3564
3565         TDIR=$DIR/${tdir}p
3566         setup_56 $NUMFILES $NUMDIRS
3567
3568         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
3569         EXPECTED=$NUMFILES
3570         CMD="$LFIND -uid $RUNAS_ID $TDIR"
3571         NUMS=$($CMD | wc -l)
3572         [ $NUMS -eq $EXPECTED ] || \
3573                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3574
3575         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
3576         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
3577         NUMS=$($CMD | wc -l)
3578         [ $NUMS -eq $EXPECTED ] || \
3579                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3580 }
3581 run_test 56p "check lfs find -uid and ! -uid ==============================="
3582
3583 test_56q() {
3584         [ $RUNAS_ID -eq $UID ] &&
3585                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3586
3587         TDIR=$DIR/${tdir}q
3588         setup_56 $NUMFILES $NUMDIRS
3589
3590         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
3591
3592         EXPECTED=$NUMFILES
3593         CMD="$LFIND -gid $RUNAS_GID $TDIR"
3594         NUMS=$($CMD | wc -l)
3595         [ $NUMS -eq $EXPECTED ] ||
3596                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3597
3598         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
3599         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
3600         NUMS=$($CMD | wc -l)
3601         [ $NUMS -eq $EXPECTED ] ||
3602                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3603 }
3604 run_test 56q "check lfs find -gid and ! -gid ==============================="
3605
3606 test_56r() {
3607         TDIR=$DIR/${tdir}r
3608         setup_56 $NUMFILES $NUMDIRS
3609
3610         EXPECTED=12
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=0
3616         CMD="$LFIND ! -size 0 -type f $TDIR"
3617         NUMS=$($CMD | wc -l)
3618         [ $NUMS -eq $EXPECTED ] ||
3619                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3620         echo "test" > $TDIR/$tfile
3621         echo "test2" > $TDIR/$tfile.2 && sync
3622         EXPECTED=1
3623         CMD="$LFIND -size 5 -type f $TDIR"
3624         NUMS=$($CMD | wc -l)
3625         [ $NUMS -eq $EXPECTED ] ||
3626                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3627         EXPECTED=1
3628         CMD="$LFIND -size +5 -type f $TDIR"
3629         NUMS=$($CMD | wc -l)
3630         [ $NUMS -eq $EXPECTED ] ||
3631                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3632         EXPECTED=2
3633         CMD="$LFIND -size +0 -type f $TDIR"
3634         NUMS=$($CMD | wc -l)
3635         [ $NUMS -eq $EXPECTED ] ||
3636                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3637         EXPECTED=2
3638         CMD="$LFIND ! -size -5 -type f $TDIR"
3639         NUMS=$($CMD | wc -l)
3640         [ $NUMS -eq $EXPECTED ] ||
3641                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3642         EXPECTED=12
3643         CMD="$LFIND -size -5 -type f $TDIR"
3644         NUMS=$($CMD | wc -l)
3645         [ $NUMS -eq $EXPECTED ] ||
3646                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3647 }
3648 run_test 56r "check lfs find -size works =========================="
3649
3650 test_56s() { # LU-611
3651         TDIR=$DIR/${tdir}s
3652         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
3653
3654         if [ $OSTCOUNT -gt 1 ]; then
3655                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
3656                 ONESTRIPE=4
3657                 EXTRA=4
3658         else
3659                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
3660                 EXTRA=0
3661         fi
3662
3663         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3664         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
3665         NUMS=$($CMD | wc -l)
3666         [ $NUMS -eq $EXPECTED ] ||
3667                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3668
3669         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
3670         CMD="$LFIND -stripe-count +0 -type f $TDIR"
3671         NUMS=$($CMD | wc -l)
3672         [ $NUMS -eq $EXPECTED ] ||
3673                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3674
3675         EXPECTED=$ONESTRIPE
3676         CMD="$LFIND -stripe-count 1 -type f $TDIR"
3677         NUMS=$($CMD | wc -l)
3678         [ $NUMS -eq $EXPECTED ] ||
3679                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3680
3681         CMD="$LFIND -stripe-count -2 -type f $TDIR"
3682         NUMS=$($CMD | wc -l)
3683         [ $NUMS -eq $EXPECTED ] ||
3684                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3685
3686         EXPECTED=0
3687         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
3688         NUMS=$($CMD | wc -l)
3689         [ $NUMS -eq $EXPECTED ] ||
3690                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3691 }
3692 run_test 56s "check lfs find -stripe-count works"
3693
3694 test_56t() { # LU-611
3695         TDIR=$DIR/${tdir}t
3696         setup_56 $NUMFILES $NUMDIRS "-s 512k"
3697
3698         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
3699
3700         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3701         CMD="$LFIND -stripe-size 512k -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=$(((NUMDIRS + 1) * NUMFILES + 4))
3712         CMD="$LFIND -stripe-size +200k -type f $TDIR"
3713         NUMS=$($CMD | wc -l)
3714         [ $NUMS -eq $EXPECTED ] ||
3715                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3716
3717         CMD="$LFIND -stripe-size -640k -type f $TDIR"
3718         NUMS=$($CMD | wc -l)
3719         [ $NUMS -eq $EXPECTED ] ||
3720                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3721
3722         EXPECTED=4
3723         CMD="$LFIND -stripe-size 256k -type f $TDIR"
3724         NUMS=$($CMD | wc -l)
3725         [ $NUMS -eq $EXPECTED ] ||
3726                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3727
3728         CMD="$LFIND -stripe-size -320k -type f $TDIR"
3729         NUMS=$($CMD | wc -l)
3730         [ $NUMS -eq $EXPECTED ] ||
3731                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3732
3733         EXPECTED=0
3734         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
3735         NUMS=$($CMD | wc -l)
3736         [ $NUMS -eq $EXPECTED ] ||
3737                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3738 }
3739 run_test 56t "check lfs find -stripe-size works"
3740
3741 test_56u() { # LU-611
3742         TDIR=$DIR/${tdir}u
3743         setup_56 $NUMFILES $NUMDIRS "-i 0"
3744
3745         if [ $OSTCOUNT -gt 1 ]; then
3746                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
3747                 ONESTRIPE=4
3748         else
3749                 ONESTRIPE=0
3750         fi
3751
3752         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3753         CMD="$LFIND -stripe-index 0 -type f $TDIR"
3754         NUMS=$($CMD | wc -l)
3755         [ $NUMS -eq $EXPECTED ] ||
3756                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3757
3758         EXPECTED=$ONESTRIPE
3759         CMD="$LFIND -stripe-index 1 -type f $TDIR"
3760         NUMS=$($CMD | wc -l)
3761         [ $NUMS -eq $EXPECTED ] ||
3762                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3763
3764         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
3765         NUMS=$($CMD | wc -l)
3766         [ $NUMS -eq $EXPECTED ] ||
3767                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3768
3769         EXPECTED=0
3770         # This should produce an error and not return any files
3771         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
3772         NUMS=$($CMD 2>/dev/null | wc -l)
3773         [ $NUMS -eq $EXPECTED ] ||
3774                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3775
3776         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
3777         CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
3778         NUMS=$($CMD | wc -l)
3779         [ $NUMS -eq $EXPECTED ] ||
3780                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3781 }
3782 run_test 56u "check lfs find -stripe-index works"
3783
3784 test_56v() {
3785     local MDT_IDX=0
3786
3787     TDIR=$DIR/${tdir}v
3788     rm -rf $TDIR
3789     setup_56 $NUMFILES $NUMDIRS
3790
3791     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
3792     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
3793
3794     for file in $($LFIND -mdt $UUID $TDIR); do
3795         file_mdt_idx=$($GETSTRIPE -M $file)
3796         [ $file_mdt_idx -eq $MDT_IDX ] ||
3797             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
3798     done
3799 }
3800 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
3801
3802 # Get and check the actual stripe count of one file.
3803 # Usage: check_stripe_count <file> <expected_stripe_count>
3804 check_stripe_count() {
3805     local file=$1
3806     local expected=$2
3807     local actual
3808
3809     [[ -z "$file" || -z "$expected" ]] &&
3810         error "check_stripe_count: invalid argument!"
3811
3812     local cmd="$GETSTRIPE -c $file"
3813     actual=$($cmd) || error "$cmd failed"
3814     actual=${actual%% *}
3815
3816     if [[ $actual -ne $expected ]]; then
3817         [[ $expected -eq -1 ]] ||
3818             error "$cmd wrong: found $actual, expected $expected"
3819         [[ $actual -eq $OSTCOUNT ]] ||
3820             error "$cmd wrong: found $actual, expected $OSTCOUNT"
3821     fi
3822 }
3823
3824 test_56w() {
3825     TDIR=$DIR/${tdir}w
3826
3827     rm -rf $TDIR || error "remove $TDIR failed"
3828     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
3829
3830     local stripe_size
3831     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
3832         error "$GETSTRIPE -S -d $TDIR failed"
3833     stripe_size=${stripe_size%% *}
3834
3835     local file_size=$((stripe_size * OSTCOUNT))
3836     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
3837     local required_space=$((file_num * file_size))
3838     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
3839     [[ $free_space -le $((required_space / 1024)) ]] &&
3840         skip_env "need at least $required_space bytes free space," \
3841                  "have $free_space kbytes" && return
3842
3843     local dd_bs=65536
3844     local dd_count=$((file_size / dd_bs))
3845
3846     # write data into the files
3847     local i
3848     local j
3849     local file
3850     for i in $(seq 1 $NUMFILES); do
3851         file=$TDIR/file$i
3852         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
3853             error "write data into $file failed"
3854     done
3855     for i in $(seq 1 $NUMDIRS); do
3856         for j in $(seq 1 $NUMFILES); do
3857             file=$TDIR/dir$i/file$j
3858             yes | dd bs=$dd_bs count=$dd_count of=$file \
3859                 >/dev/null 2>&1 ||
3860                 error "write data into $file failed"
3861         done
3862     done
3863
3864     local expected=-1
3865     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
3866
3867     # lfs_migrate file
3868     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
3869     echo "$cmd"
3870     eval $cmd || error "$cmd failed"
3871
3872     check_stripe_count $TDIR/file1 $expected
3873
3874     # lfs_migrate dir
3875     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
3876     echo "$cmd"
3877     eval $cmd || error "$cmd failed"
3878
3879     for j in $(seq 1 $NUMFILES); do
3880         check_stripe_count $TDIR/dir1/file$j $expected
3881     done
3882
3883     # lfs_migrate works with lfs find
3884     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
3885          $LFS_MIGRATE -y -c $expected"
3886     echo "$cmd"
3887     eval $cmd || error "$cmd failed"
3888
3889     for i in $(seq 2 $NUMFILES); do
3890         check_stripe_count $TDIR/file$i $expected
3891     done
3892     for i in $(seq 2 $NUMDIRS); do
3893         for j in $(seq 1 $NUMFILES); do
3894             check_stripe_count $TDIR/dir$i/file$j $expected
3895         done
3896     done
3897 }
3898 run_test 56w "check lfs_migrate -c stripe_count works"
3899
3900 test_57a() {
3901         # note test will not do anything if MDS is not local
3902         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3903         local MNTDEV="osd*.*MDT*.mntdev"
3904         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
3905         [ -z "$DEV" ] && error "can't access $MNTDEV"
3906         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
3907                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
3908                         error "can't access $DEV"
3909                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
3910                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
3911                 rm $TMP/t57a.dump
3912         done
3913 }
3914 run_test 57a "verify MDS filesystem created with large inodes =="
3915
3916 test_57b() {
3917         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3918         local dir=$DIR/d57b
3919
3920         local FILECOUNT=100
3921         local FILE1=$dir/f1
3922         local FILEN=$dir/f$FILECOUNT
3923
3924         rm -rf $dir || error "removing $dir"
3925         mkdir -p $dir || error "creating $dir"
3926         local num=$(get_mds_dir $dir)
3927         local mymds=mds$num
3928
3929         echo "mcreating $FILECOUNT files"
3930         createmany -m $dir/f 1 $FILECOUNT || \
3931                 error "creating files in $dir"
3932
3933         # verify that files do not have EAs yet
3934         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
3935         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
3936
3937         sync
3938         sleep 1
3939         df $dir  #make sure we get new statfs data
3940         local MDSFREE=$(do_facet $mymds \
3941                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
3942         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
3943         echo "opening files to create objects/EAs"
3944         local FILE
3945         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
3946                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
3947         done
3948
3949         # verify that files have EAs now
3950         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
3951         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
3952
3953         sleep 1  #make sure we get new statfs data
3954         df $dir
3955         local MDSFREE2=$(do_facet $mymds \
3956                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
3957         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
3958         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
3959                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
3960                         error "MDC before $MDCFREE != after $MDCFREE2"
3961                 else
3962                         echo "MDC before $MDCFREE != after $MDCFREE2"
3963                         echo "unable to confirm if MDS has large inodes"
3964                 fi
3965         fi
3966         rm -rf $dir
3967 }
3968 run_test 57b "default LOV EAs are stored inside large inodes ==="
3969
3970 test_58() {
3971     [ -z "$(which wiretest 2>/dev/null)" ] && skip_env "could not find wiretest" && return
3972     wiretest
3973 }
3974 run_test 58 "verify cross-platform wire constants =============="
3975
3976 test_59() {
3977         echo "touch 130 files"
3978         createmany -o $DIR/f59- 130
3979         echo "rm 130 files"
3980         unlinkmany $DIR/f59- 130
3981         sync
3982         sleep 2
3983         # wait for commitment of removal
3984 }
3985 run_test 59 "verify cancellation of llog records async ========="
3986
3987 TEST60_HEAD="test_60 run $RANDOM"
3988 test_60a() {
3989         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
3990         [ ! -f run-llog.sh ] && skip_env "missing subtest run-llog.sh" && return
3991         log "$TEST60_HEAD - from kernel mode"
3992         do_facet mgs sh run-llog.sh
3993 }
3994 run_test 60a "llog sanity tests run from kernel module =========="
3995
3996 test_60b() { # bug 6411
3997         dmesg > $DIR/$tfile
3998         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
3999                                  /llog.test/ {
4000                                          if (marker)
4001                                                  from_marker++
4002                                          from_begin++
4003                                  }
4004                                  END {
4005                                          if (marker)
4006                                                  print from_marker
4007                                          else
4008                                                  print from_begin
4009                                  }"`
4010         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
4011 }
4012 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4013
4014 test_60c() {
4015         echo "create 5000 files"
4016         createmany -o $DIR/f60c- 5000
4017 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4018         lctl set_param fail_loc=0x80000137
4019         unlinkmany $DIR/f60c- 5000
4020         lctl set_param fail_loc=0
4021 }
4022 run_test 60c "unlink file when mds full"
4023
4024 test_60d() {
4025         SAVEPRINTK=$(lctl get_param -n printk)
4026
4027         # verify "lctl mark" is even working"
4028         MESSAGE="test message ID $RANDOM $$"
4029         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4030         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4031
4032         lctl set_param printk=0 || error "set lnet.printk failed"
4033         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4034         MESSAGE="new test message ID $RANDOM $$"
4035         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4036         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4037         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4038
4039         lctl set_param -n printk="$SAVEPRINTK"
4040 }
4041 run_test 60d "test printk console message masking"
4042
4043 test_61() {
4044         f="$DIR/f61"
4045         dd if=/dev/zero of=$f bs=`page_size` count=1
4046         cancel_lru_locks osc
4047         $MULTIOP $f OSMWUc || error
4048         sync
4049 }
4050 run_test 61 "mmap() writes don't make sync hang ================"
4051
4052 # bug 2330 - insufficient obd_match error checking causes LBUG
4053 test_62() {
4054         f="$DIR/f62"
4055         echo foo > $f
4056         cancel_lru_locks osc
4057         lctl set_param fail_loc=0x405
4058         cat $f && error "cat succeeded, expect -EIO"
4059         lctl set_param fail_loc=0
4060 }
4061 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4062 # match every page all of the time.
4063 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4064
4065 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4066 test_63a() {    # was test_63
4067         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4068         lctl set_param -n osc.*.max_dirty_mb 0
4069         for i in `seq 10` ; do
4070                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4071                 sleep 5
4072                 kill $!
4073                 sleep 1
4074         done
4075
4076         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
4077         rm -f $DIR/f63 || true
4078 }
4079 run_test 63a "Verify oig_wait interruption does not crash ======="
4080
4081 # bug 2248 - async write errors didn't return to application on sync
4082 # bug 3677 - async write errors left page locked
4083 test_63b() {
4084         debugsave
4085         lctl set_param debug=-1
4086
4087         # ensure we have a grant to do async writes
4088         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4089         rm $DIR/$tfile
4090
4091         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4092         lctl set_param fail_loc=0x80000406
4093         $MULTIOP $DIR/$tfile Owy && \
4094                 error "sync didn't return ENOMEM"
4095         sync; sleep 2; sync     # do a real sync this time to flush page
4096         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4097                 error "locked page left in cache after async error" || true
4098         debugrestore
4099 }
4100 run_test 63b "async write errors should be returned to fsync ==="
4101
4102 test_64a () {
4103         df $DIR
4104         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4105 }
4106 run_test 64a "verify filter grant calculations (in kernel) ====="
4107
4108 test_64b () {
4109         [ ! -f oos.sh ] && skip_env "missing subtest oos.sh" && return
4110         sh oos.sh $MOUNT
4111 }
4112 run_test 64b "check out-of-space detection on client ==========="
4113
4114 # bug 1414 - set/get directories' stripe info
4115 test_65a() {
4116         mkdir -p $DIR/d65
4117         touch $DIR/d65/f1
4118         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
4119 }
4120 run_test 65a "directory with no stripe info ===================="
4121
4122 test_65b() {
4123         mkdir -p $DIR/d65
4124         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65||error "setstripe"
4125         touch $DIR/d65/f2
4126         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
4127 }
4128 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4129
4130 test_65c() {
4131         if [ $OSTCOUNT -gt 1 ]; then
4132                 mkdir -p $DIR/d65
4133                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4134                         -c $(($OSTCOUNT - 1)) $DIR/d65 || error "setstripe"
4135                 touch $DIR/d65/f3
4136                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
4137         fi
4138 }
4139 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4140
4141 test_65d() {
4142         mkdir -p $DIR/d65
4143         if [ $STRIPECOUNT -le 0 ]; then
4144                 sc=1
4145         elif [ $STRIPECOUNT -gt 2000 ]; then
4146 #LOV_MAX_STRIPE_COUNT is 2000
4147                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
4148         else
4149                 sc=$(($STRIPECOUNT - 1))
4150         fi
4151         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/d65 || error "setstripe"
4152         touch $DIR/d65/f4 $DIR/d65/f5
4153         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
4154 }
4155 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
4156
4157 test_65e() {
4158         mkdir -p $DIR/d65
4159
4160         $SETSTRIPE $DIR/d65 || error "setstripe"
4161         $GETSTRIPE -v $DIR/d65 | grep "Default" || error "no stripe info failed"
4162         touch $DIR/d65/f6
4163         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
4164 }
4165 run_test 65e "directory setstripe defaults ======================="
4166
4167 test_65f() {
4168         mkdir -p $DIR/d65f
4169         $RUNAS $SETSTRIPE $DIR/d65f && error "setstripe succeeded" || true
4170 }
4171 run_test 65f "dir setstripe permission (should return error) ==="
4172
4173 test_65g() {
4174         mkdir -p $DIR/d65
4175         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65 ||error "setstripe"
4176         $SETSTRIPE -d $DIR/d65 || error "setstripe"
4177         $GETSTRIPE -v $DIR/d65 | grep "Default" || \
4178                 error "delete default stripe failed"
4179 }
4180 run_test 65g "directory setstripe -d ==========================="
4181
4182 test_65h() {
4183         mkdir -p $DIR/d65
4184         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65 ||error "setstripe"
4185         mkdir -p $DIR/d65/dd1
4186         [ $($GETSTRIPE -c $DIR/d65) == $($GETSTRIPE -c $DIR/d65/dd1) ] ||
4187                 error "stripe info inherit failed"
4188 }
4189 run_test 65h "directory stripe info inherit ===================="
4190
4191 test_65i() { # bug6367
4192         $SETSTRIPE -S 65536 -c -1 $MOUNT
4193 }
4194 run_test 65i "set non-default striping on root directory (bug 6367)="
4195
4196 test_65ia() { # bug12836
4197         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
4198 }
4199 run_test 65ia "getstripe on -1 default directory striping"
4200
4201 test_65ib() { # bug12836
4202         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
4203 }
4204 run_test 65ib "getstripe -v on -1 default directory striping"
4205
4206 test_65ic() { # bug12836
4207         $LFS find -mtime -1 $MOUNT || error "find $MOUNT failed"
4208 }
4209 run_test 65ic "new find on -1 default directory striping"
4210
4211 test_65j() { # bug6367
4212         sync; sleep 1
4213         # if we aren't already remounting for each test, do so for this test
4214         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
4215                 cleanup || error "failed to unmount"
4216                 setup
4217         fi
4218         $SETSTRIPE -d $MOUNT || error "setstripe failed"
4219 }
4220 run_test 65j "set default striping on root directory (bug 6367)="
4221
4222 test_65k() { # bug11679
4223     [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
4224     remote_mds_nodsh && skip "remote MDS with nodsh" && return
4225
4226     echo "Check OST status: "
4227     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
4228               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
4229
4230     for OSC in $MDS_OSCS; do
4231         echo $OSC "is activate"
4232         do_facet $SINGLEMDS lctl --device %$OSC activate
4233     done
4234
4235     do_facet client mkdir -p $DIR/$tdir
4236     for INACTIVE_OSC in $MDS_OSCS; do
4237         echo "Deactivate: " $INACTIVE_OSC
4238         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
4239         for STRIPE_OSC in $MDS_OSCS; do
4240             OST=`osc_to_ost $STRIPE_OSC`
4241             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
4242                  awk -F: /$OST/'{ print $1 }' | head -n 1`
4243
4244             [ -f $DIR/$tdir/$IDX ] && continue
4245             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
4246             do_facet client $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
4247             RC=$?
4248             [ $RC -ne 0 ] && error "setstripe should have succeeded"
4249         done
4250         do_facet client rm -f $DIR/$tdir/*
4251         echo $INACTIVE_OSC "is Activate."
4252         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
4253     done
4254 }
4255 run_test 65k "validate manual striping works properly with deactivated OSCs"
4256
4257 test_65l() { # bug 12836
4258         mkdir -p $DIR/$tdir/test_dir
4259         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
4260         $LFS find -mtime -1 $DIR/$tdir >/dev/null
4261 }
4262 run_test 65l "lfs find on -1 stripe dir ========================"
4263
4264 # bug 2543 - update blocks count on client
4265 test_66() {
4266         COUNT=${COUNT:-8}
4267         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
4268         sync; sleep 1; sync
4269         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
4270         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
4271 }
4272 run_test 66 "update inode blocks count on client ==============="
4273
4274 LLOOP=
4275 LLITELOOPLOAD=
4276 cleanup_68() {
4277         trap 0
4278         if [ ! -z "$LLOOP" ]; then
4279                 if swapon -s | grep -q $LLOOP; then
4280                         swapoff $LLOOP || error "swapoff failed"
4281                 fi
4282
4283                 $LCTL blockdev_detach $LLOOP || error "detach failed"
4284                 rm -f $LLOOP
4285                 unset LLOOP
4286         fi
4287         if [ ! -z "$LLITELOOPLOAD" ]; then
4288                 rmmod llite_lloop
4289                 unset LLITELOOPLOAD
4290         fi
4291         rm -f $DIR/f68*
4292 }
4293
4294 meminfo() {
4295         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
4296 }
4297
4298 swap_used() {
4299         swapon -s | awk '($1 == "'$1'") { print $4 }'
4300 }
4301
4302 # test case for lloop driver, basic function
4303 test_68a() {
4304         [ "$UID" != 0 ] && skip_env "must run as root" && return
4305         llite_lloop_enabled || \
4306                 { skip_env "llite_lloop module disabled" && return; }
4307
4308         trap cleanup_68 EXIT
4309
4310         if ! module_loaded llite_lloop; then
4311                 if load_module llite/llite_lloop; then
4312                         LLITELOOPLOAD=yes
4313                 else
4314                         skip_env "can't find module llite_lloop"
4315                         return
4316                 fi
4317         fi
4318
4319         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4320         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
4321         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
4322
4323         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
4324         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
4325
4326         cleanup_68
4327 }
4328 run_test 68a "lloop driver - basic test ========================"
4329
4330 # excercise swapping to lustre by adding a high priority swapfile entry
4331 # and then consuming memory until it is used.
4332 test_68b() {  # was test_68
4333         [ "$UID" != 0 ] && skip_env "must run as root" && return
4334         lctl get_param -n devices | grep -q obdfilter && \
4335                 skip "local OST" && return
4336
4337         grep -q llite_lloop /proc/modules
4338         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
4339
4340         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
4341                 skip "can't reliably test swap with TCP" && return
4342
4343         MEMTOTAL=`meminfo MemTotal`
4344         NR_BLOCKS=$((MEMTOTAL>>8))
4345         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
4346
4347         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4348         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
4349         mkswap $DIR/f68b
4350
4351         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
4352
4353         trap cleanup_68 EXIT
4354
4355         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
4356
4357         echo "before: `swapon -s | grep $LLOOP`"
4358         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
4359         echo "after: `swapon -s | grep $LLOOP`"
4360         SWAPUSED=`swap_used $LLOOP`
4361
4362         cleanup_68
4363
4364         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
4365 }
4366 run_test 68b "support swapping to Lustre ========================"
4367
4368 # bug5265, obdfilter oa2dentry return -ENOENT
4369 # #define OBD_FAIL_OST_ENOENT 0x217
4370 test_69() {
4371         remote_ost_nodsh && skip "remote OST with nodsh" && return
4372
4373         f="$DIR/$tfile"
4374         $SETSTRIPE -c 1 -i 0 $f
4375
4376         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
4377
4378         do_facet ost1 lctl set_param fail_loc=0x217
4379         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
4380         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
4381
4382         do_facet ost1 lctl set_param fail_loc=0
4383         $DIRECTIO write $f 0 2 || error "write error"
4384
4385         cancel_lru_locks osc
4386         $DIRECTIO read $f 0 1 || error "read error"
4387
4388         do_facet ost1 lctl set_param fail_loc=0x217
4389         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
4390
4391         do_facet ost1 lctl set_param fail_loc=0
4392         rm -f $f
4393 }
4394 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
4395
4396 test_71() {
4397     mkdir -p $DIR/$tdir
4398     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
4399 }
4400 run_test 71 "Running dbench on lustre (don't segment fault) ===="
4401
4402 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
4403         check_kernel_version 43 || return 0
4404         [ "$RUNAS_ID" = "$UID" ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4405
4406         # Check that testing environment is properly set up. Skip if not
4407         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
4408                 skip_env "User $RUNAS_ID does not exist - skipping"
4409                 return 0
4410         }
4411         # We had better clear the $DIR to get enough space for dd
4412         rm -rf $DIR/*
4413         touch $DIR/f72
4414         chmod 777 $DIR/f72
4415         chmod ug+s $DIR/f72
4416         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
4417         # See if we are still setuid/sgid
4418         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
4419         # Now test that MDS is updated too
4420         cancel_lru_locks mdc
4421         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
4422         true
4423         rm -f $DIR/f72
4424 }
4425 run_test 72a "Test that remove suid works properly (bug5695) ===="
4426
4427 test_72b() { # bug 24226 -- keep mode setting when size is not changing
4428         local perm
4429
4430         [ "$RUNAS_ID" = "$UID" ] && \
4431                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4432         [ "$RUNAS_ID" -eq 0 ] && \
4433                 skip_env "RUNAS_ID = 0 -- skipping" && return
4434
4435         # Check that testing environment is properly set up. Skip if not
4436         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
4437                 skip_env "User $RUNAS_ID does not exist - skipping"
4438                 return 0
4439         }
4440         touch $DIR/${tfile}-f{g,u}
4441         mkdir $DIR/${tfile}-d{g,u}
4442         chmod 770 $DIR/${tfile}-{f,d}{g,u}
4443         chmod g+s $DIR/${tfile}-{f,d}g
4444         chmod u+s $DIR/${tfile}-{f,d}u
4445         for perm in 777 2777 4777; do
4446                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
4447                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
4448                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
4449                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
4450         done
4451         true
4452 }
4453 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
4454
4455 # bug 3462 - multiple simultaneous MDC requests
4456 test_73() {
4457         mkdir $DIR/d73-1
4458         mkdir $DIR/d73-2
4459         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
4460         pid1=$!
4461
4462         lctl set_param fail_loc=0x80000129
4463         $MULTIOP $DIR/d73-1/f73-2 Oc &
4464         sleep 1
4465         lctl set_param fail_loc=0
4466
4467         $MULTIOP $DIR/d73-2/f73-3 Oc &
4468         pid3=$!
4469
4470         kill -USR1 $pid1
4471         wait $pid1 || return 1
4472
4473         sleep 25
4474
4475         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
4476         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
4477         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
4478
4479         rm -rf $DIR/d73-*
4480 }
4481 run_test 73 "multiple MDC requests (should not deadlock)"
4482
4483 test_74a() { # bug 6149, 6184
4484         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
4485         #
4486         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
4487         # will spin in a tight reconnection loop
4488         touch $DIR/f74a
4489         lctl set_param fail_loc=0x8000030e
4490         # get any lock that won't be difficult - lookup works.
4491         ls $DIR/f74a
4492         lctl set_param fail_loc=0
4493         true
4494         rm -f $DIR/f74a
4495 }
4496 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
4497
4498 test_74b() { # bug 13310
4499         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
4500         #
4501         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
4502         # will spin in a tight reconnection loop
4503         lctl set_param fail_loc=0x8000030e
4504         # get a "difficult" lock
4505         touch $DIR/f74b
4506         lctl set_param fail_loc=0
4507         true
4508         rm -f $DIR/f74b
4509 }
4510 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
4511
4512 test_74c() {
4513 #define OBD_FAIL_LDLM_NEW_LOCK
4514         lctl set_param fail_loc=0x80000319
4515         touch $DIR/$tfile && error "Touch successful"
4516         true
4517 }
4518 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
4519
4520 num_inodes() {
4521         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
4522 }
4523
4524 get_inode_slab_tunables() {
4525         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
4526 }
4527
4528 set_inode_slab_tunables() {
4529         echo "lustre_inode_cache $1" > /proc/slabinfo
4530 }
4531
4532 test_76() { # Now for bug 20433, added originally in bug 1443
4533         local SLAB_SETTINGS=`get_inode_slab_tunables`
4534         local CPUS=`getconf _NPROCESSORS_ONLN`
4535         # we cannot set limit below 1 which means 1 inode in each
4536         # per-cpu cache is still allowed
4537         set_inode_slab_tunables "1 1 0"
4538         cancel_lru_locks osc
4539         BEFORE_INODES=`num_inodes`
4540         echo "before inodes: $BEFORE_INODES"
4541         local COUNT=1000
4542         [ "$SLOW" = "no" ] && COUNT=100
4543         for i in `seq $COUNT`; do
4544                 touch $DIR/$tfile
4545                 rm -f $DIR/$tfile
4546         done
4547         cancel_lru_locks osc
4548         AFTER_INODES=`num_inodes`
4549         echo "after inodes: $AFTER_INODES"
4550         local wait=0
4551         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
4552                 sleep 2
4553                 AFTER_INODES=`num_inodes`
4554                 wait=$((wait+2))
4555                 echo "wait $wait seconds inodes: $AFTER_INODES"
4556                 if [ $wait -gt 30 ]; then
4557                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
4558                 fi
4559         done
4560         set_inode_slab_tunables "$SLAB_SETTINGS"
4561 }
4562 run_test 76 "confirm clients recycle inodes properly ===="
4563
4564
4565 export ORIG_CSUM=""
4566 set_checksums()
4567 {
4568         # Note: in sptlrpc modes which enable its own bulk checksum, the
4569         # original crc32_le bulk checksum will be automatically disabled,
4570         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
4571         # will be checked by sptlrpc code against sptlrpc bulk checksum.
4572         # In this case set_checksums() will not be no-op, because sptlrpc
4573         # bulk checksum will be enabled all through the test.
4574
4575         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
4576         lctl set_param -n osc.*.checksums $1
4577         return 0
4578 }
4579
4580 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
4581                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
4582 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
4583 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
4584 set_checksum_type()
4585 {
4586         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
4587         log "set checksum type to $1"
4588         return 0
4589 }
4590 F77_TMP=$TMP/f77-temp
4591 F77SZ=8
4592 setup_f77() {
4593         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
4594                 error "error writing to $F77_TMP"
4595 }
4596
4597 test_77a() { # bug 10889
4598         $GSS && skip "could not run with gss" && return
4599         [ ! -f $F77_TMP ] && setup_f77
4600         set_checksums 1
4601         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
4602         set_checksums 0
4603         rm -f $DIR/$tfile
4604 }
4605 run_test 77a "normal checksum read/write operation ============="
4606
4607 test_77b() { # bug 10889
4608         $GSS && skip "could not run with gss" && return
4609         [ ! -f $F77_TMP ] && setup_f77
4610         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4611         lctl set_param fail_loc=0x80000409
4612         set_checksums 1
4613         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
4614                 error "dd error: $?"
4615         lctl set_param fail_loc=0
4616         set_checksums 0
4617 }
4618 run_test 77b "checksum error on client write ===================="
4619
4620 test_77c() { # bug 10889
4621         $GSS && skip "could not run with gss" && return
4622         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
4623         set_checksums 1
4624         for algo in $CKSUM_TYPES; do
4625                 cancel_lru_locks osc
4626                 set_checksum_type $algo
4627                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
4628                 lctl set_param fail_loc=0x80000408
4629                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
4630                 lctl set_param fail_loc=0
4631         done
4632         set_checksums 0
4633         set_checksum_type $ORIG_CSUM_TYPE
4634         rm -f $DIR/f77b
4635 }
4636 run_test 77c "checksum error on client read ==================="
4637
4638 test_77d() { # bug 10889
4639         $GSS && skip "could not run with gss" && return
4640         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4641         lctl set_param fail_loc=0x80000409
4642         set_checksums 1
4643         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
4644                 error "direct write: rc=$?"
4645         lctl set_param fail_loc=0
4646         set_checksums 0
4647 }
4648 run_test 77d "checksum error on OST direct write ==============="
4649
4650 test_77e() { # bug 10889
4651         $GSS && skip "could not run with gss" && return
4652         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
4653         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
4654         lctl set_param fail_loc=0x80000408
4655         set_checksums 1
4656         cancel_lru_locks osc
4657         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
4658                 error "direct read: rc=$?"
4659         lctl set_param fail_loc=0
4660         set_checksums 0
4661 }
4662 run_test 77e "checksum error on OST direct read ================"
4663
4664 test_77f() { # bug 10889
4665         $GSS && skip "could not run with gss" && return
4666         set_checksums 1
4667         for algo in $CKSUM_TYPES; do
4668                 cancel_lru_locks osc
4669                 set_checksum_type $algo
4670                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4671                 lctl set_param fail_loc=0x409
4672                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
4673                         error "direct write succeeded"
4674                 lctl set_param fail_loc=0
4675         done
4676         set_checksum_type $ORIG_CSUM_TYPE
4677         set_checksums 0
4678 }
4679 run_test 77f "repeat checksum error on write (expect error) ===="
4680
4681 test_77g() { # bug 10889
4682         $GSS && skip "could not run with gss" && return
4683         remote_ost_nodsh && skip "remote OST with nodsh" && return
4684
4685         [ ! -f $F77_TMP ] && setup_f77
4686
4687         $SETSTRIPE -c 1 -i 0 $DIR/f77g
4688         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
4689         do_facet ost1 lctl set_param fail_loc=0x8000021a
4690         set_checksums 1
4691         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
4692                 error "write error: rc=$?"
4693         do_facet ost1 lctl set_param fail_loc=0
4694         set_checksums 0
4695 }
4696 run_test 77g "checksum error on OST write ======================"
4697
4698 test_77h() { # bug 10889
4699         $GSS && skip "could not run with gss" && return
4700         remote_ost_nodsh && skip "remote OST with nodsh" && return
4701
4702         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
4703         cancel_lru_locks osc
4704         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
4705         do_facet ost1 lctl set_param fail_loc=0x8000021b
4706         set_checksums 1
4707         cmp $F77_TMP $DIR/f77g || error "file compare failed"
4708         do_facet ost1 lctl set_param fail_loc=0
4709         set_checksums 0
4710 }
4711 run_test 77h "checksum error on OST read ======================="
4712
4713 test_77i() { # bug 13805
4714         $GSS && skip "could not run with gss" && return
4715         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
4716         lctl set_param fail_loc=0x40b
4717         remount_client $MOUNT
4718         lctl set_param fail_loc=0
4719         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
4720                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
4721                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
4722                 [ "$algo" = "crc32" ] || error "algo set to $algo instead of crc32"
4723         done
4724         remount_client $MOUNT
4725 }
4726 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
4727
4728 test_77j() { # bug 13805
4729         $GSS && skip "could not run with gss" && return
4730         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
4731         lctl set_param fail_loc=0x40c
4732         remount_client $MOUNT
4733         lctl set_param fail_loc=0
4734         sleep 2 # wait async osc connect to finish
4735         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
4736                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
4737                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
4738                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
4739         done
4740         remount_client $MOUNT
4741 }
4742 run_test 77j "client only supporting ADLER32 ===================="
4743
4744 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
4745 rm -f $F77_TMP
4746 unset F77_TMP
4747
4748 test_78() { # bug 10901
4749         remote_ost || { skip_env "local OST" && return; }
4750
4751         NSEQ=5
4752         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
4753         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
4754         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
4755         echo "MemTotal: $MEMTOTAL"
4756 # reserve 256MB of memory for the kernel and other running processes,
4757 # and then take 1/2 of the remaining memory for the read/write buffers.
4758     if [ $MEMTOTAL -gt 512 ] ;then
4759         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
4760     else
4761         # for those poor memory-starved high-end clusters...
4762         MEMTOTAL=$((MEMTOTAL / 2))
4763     fi
4764         echo "Mem to use for directio: $MEMTOTAL"
4765         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
4766         [ $F78SIZE -gt 512 ] && F78SIZE=512
4767         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
4768         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
4769         echo "Smallest OST: $SMALLESTOST"
4770         [ $SMALLESTOST -lt 10240 ] && \
4771                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
4772
4773         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
4774                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
4775
4776         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
4777         echo "File size: $F78SIZE"
4778         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
4779         for i in `seq 1 $NSEQ`
4780         do
4781                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
4782                 echo directIO rdwr round $i of $NSEQ
4783                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
4784         done
4785
4786         rm -f $DIR/$tfile
4787 }
4788 run_test 78 "handle large O_DIRECT writes correctly ============"
4789
4790 test_79() { # bug 12743
4791         wait_delete_completed
4792
4793         BKTOTAL=$(calc_osc_kbytes kbytestotal)
4794         BKFREE=$(calc_osc_kbytes kbytesfree)
4795         BKAVAIL=$(calc_osc_kbytes kbytesavail)
4796
4797         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
4798         DFTOTAL=`echo $STRING | cut -d, -f1`
4799         DFUSED=`echo $STRING  | cut -d, -f2`
4800         DFAVAIL=`echo $STRING | cut -d, -f3`
4801         DFFREE=$(($DFTOTAL - $DFUSED))
4802
4803         ALLOWANCE=$((64 * $OSTCOUNT))
4804
4805         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
4806            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
4807                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
4808         fi
4809         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
4810            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
4811                 error "df free($DFFREE) mismatch OST free($BKFREE)"
4812         fi
4813         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
4814            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
4815                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
4816         fi
4817 }
4818 run_test 79 "df report consistency check ======================="
4819
4820 test_80() { # bug 10718
4821         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
4822         sync; sleep 1; sync
4823         local BEFORE=`date +%s`
4824         cancel_lru_locks osc
4825         local AFTER=`date +%s`
4826         local DIFF=$((AFTER-BEFORE))
4827         if [ $DIFF -gt 1 ] ; then
4828                 error "elapsed for 1M@1T = $DIFF"
4829         fi
4830         true
4831         rm -f $DIR/$tfile
4832 }
4833 run_test 80 "Page eviction is equally fast at high offsets too  ===="
4834
4835 test_81a() { # LU-456
4836         remote_ost_nodsh && skip "remote OST with nodsh" && return
4837         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
4838         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
4839         do_facet ost0 lctl set_param fail_loc=0x80000228
4840
4841         # write should trigger a retry and success
4842         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
4843         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4844         RC=$?
4845         if [ $RC -ne 0 ] ; then
4846                 error "write should success, but failed for $RC"
4847         fi
4848 }
4849 run_test 81a "OST should retry write when get -ENOSPC ==============="
4850
4851 test_81b() { # LU-456
4852         remote_ost_nodsh && skip "remote OST with nodsh" && return
4853         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
4854         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
4855         do_facet ost0 lctl set_param fail_loc=0x228
4856
4857         # write should retry several times and return -ENOSPC finally
4858         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
4859         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4860         RC=$?
4861         ENOSPC=28
4862         if [ $RC -ne $ENOSPC ] ; then
4863                 error "dd should fail for -ENOSPC, but succeed."
4864         fi
4865 }
4866 run_test 81b "OST should return -ENOSPC when retry still fails ======="
4867
4868 test_82() { # LU-1031
4869         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
4870         local gid1=14091995
4871         local gid2=16022000
4872
4873         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
4874         local MULTIPID1=$!
4875         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
4876         local MULTIPID2=$!
4877         kill -USR1 $MULTIPID2
4878         sleep 2
4879         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
4880                 error "First grouplock does not block second one"
4881         else
4882                 echo "Second grouplock blocks first one"
4883         fi
4884         kill -USR1 $MULTIPID1
4885         wait $MULTIPID1
4886         wait $MULTIPID2
4887 }
4888 run_test 82 "Basic grouplock test ==============================="
4889
4890 test_99a() {
4891         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && \
4892             return
4893         mkdir -p $DIR/d99cvsroot
4894         chown $RUNAS_ID $DIR/d99cvsroot
4895         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
4896         cd $TMP
4897
4898         $RUNAS cvs -d $DIR/d99cvsroot init || error
4899         cd $oldPWD
4900 }
4901 run_test 99a "cvs init ========================================="
4902
4903 test_99b() {
4904         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4905         [ ! -d $DIR/d99cvsroot ] && test_99a
4906         cd /etc/init.d
4907         # some versions of cvs import exit(1) when asked to import links or
4908         # files they can't read.  ignore those files.
4909         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
4910                         ! -perm +4 -printf '-I %f\n')
4911         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
4912                 d99reposname vtag rtag
4913 }
4914 run_test 99b "cvs import ======================================="
4915
4916 test_99c() {
4917         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4918         [ ! -d $DIR/d99cvsroot ] && test_99b
4919         cd $DIR
4920         mkdir -p $DIR/d99reposname
4921         chown $RUNAS_ID $DIR/d99reposname
4922         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
4923 }
4924 run_test 99c "cvs checkout ====================================="
4925
4926 test_99d() {
4927         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4928         [ ! -d $DIR/d99cvsroot ] && test_99c
4929         cd $DIR/d99reposname
4930         $RUNAS touch foo99
4931         $RUNAS cvs add -m 'addmsg' foo99
4932 }
4933 run_test 99d "cvs add =========================================="
4934
4935 test_99e() {
4936         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4937         [ ! -d $DIR/d99cvsroot ] && test_99c
4938         cd $DIR/d99reposname
4939         $RUNAS cvs update
4940 }
4941 run_test 99e "cvs update ======================================="
4942
4943 test_99f() {
4944         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
4945         [ ! -d $DIR/d99cvsroot ] && test_99d
4946         cd $DIR/d99reposname
4947         $RUNAS cvs commit -m 'nomsg' foo99
4948     rm -fr $DIR/d99cvsroot
4949 }
4950 run_test 99f "cvs commit ======================================="
4951
4952 test_100() {
4953         [ "$NETTYPE" = tcp ] || \
4954                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
4955                         return ; }
4956
4957         remote_ost_nodsh && skip "remote OST with nodsh" && return
4958         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4959         remote_servers || \
4960                 { skip "useless for local single node setup" && return; }
4961
4962         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
4963                 [ "$PROT" != "tcp" ] && continue
4964                 RPORT=$(echo $REMOTE | cut -d: -f2)
4965                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
4966
4967                 rc=0
4968                 LPORT=`echo $LOCAL | cut -d: -f2`
4969                 if [ $LPORT -ge 1024 ]; then
4970                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
4971                         netstat -tna
4972                         error_exit "local: $LPORT > 1024, remote: $RPORT"
4973                 fi
4974         done
4975         [ "$rc" = 0 ] || error_exit "privileged port not found" )
4976 }
4977 run_test 100 "check local port using privileged port ==========="
4978
4979 function get_named_value()
4980 {
4981     local tag
4982
4983     tag=$1
4984     while read ;do
4985         line=$REPLY
4986         case $line in
4987         $tag*)
4988             echo $line | sed "s/^$tag[ ]*//"
4989             break
4990             ;;
4991         esac
4992     done
4993 }
4994
4995 export CACHE_MAX=`$LCTL get_param -n llite.*.max_cached_mb | head -n 1`
4996 cleanup_101a() {
4997         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
4998         trap 0
4999 }
5000
5001 test_101a() {
5002         local s
5003         local discard
5004         local nreads=10000
5005         [ "$CPU" = "UML" ] && nreads=1000
5006         local cache_limit=32
5007
5008         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5009         trap cleanup_101a EXIT
5010         $LCTL set_param -n llite.*.read_ahead_stats 0
5011         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5012
5013         #
5014         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5015         #
5016         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5017         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5018
5019         discard=0
5020         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
5021                 get_named_value 'read but discarded' | cut -d" " -f1`; do
5022                         discard=$(($discard + $s))
5023         done
5024         cleanup_101a
5025
5026         if [ $(($discard * 10)) -gt $nreads ] ;then
5027                 $LCTL get_param osc.*-osc*.rpc_stats
5028                 $LCTL get_param llite.*.read_ahead_stats
5029                 error "too many ($discard) discarded pages"
5030         fi
5031         rm -f $DIR/$tfile || true
5032 }
5033 run_test 101a "check read-ahead for random reads ================"
5034
5035 setup_test101bc() {
5036         mkdir -p $DIR/$tdir
5037         STRIPE_SIZE=1048576
5038         STRIPE_COUNT=$OSTCOUNT
5039         STRIPE_OFFSET=0
5040
5041         local list=$(comma_list $(osts_nodes))
5042         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=0
5043         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable=0
5044
5045         trap cleanup_test101bc EXIT
5046         # prepare the read-ahead file
5047         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5048
5049         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
5050 }
5051
5052 cleanup_test101bc() {
5053         trap 0
5054         rm -rf $DIR/$tdir
5055         rm -f $DIR/$tfile
5056
5057         local list=$(comma_list $(osts_nodes))
5058         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=1
5059         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable=1
5060 }
5061
5062 calc_total() {
5063         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5064 }
5065
5066 ra_check_101() {
5067         local READ_SIZE=$1
5068         local STRIPE_SIZE=1048576
5069         local RA_INC=1048576
5070         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5071         local FILE_LENGTH=$((64*100))
5072         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5073                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5074         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5075                         get_named_value 'read but discarded' | \
5076                         cut -d" " -f1 | calc_total`
5077         if [ $DISCARD -gt $discard_limit ]; then
5078                 $LCTL get_param llite.*.read_ahead_stats
5079                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5080         else
5081                 echo "Read-ahead success for size ${READ_SIZE}"
5082         fi
5083 }
5084
5085 test_101b() {
5086         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5087         local STRIPE_SIZE=1048576
5088         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5089         local FILE_LENGTH=$((STRIPE_SIZE*100))
5090         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
5091         # prepare the read-ahead file
5092         setup_test101bc
5093         cancel_lru_locks osc
5094         for BIDX in 2 4 8 16 32 64 128 256
5095         do
5096                 local BSIZE=$((BIDX*4096))
5097                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5098                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5099                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5100                 $LCTL set_param -n llite.*.read_ahead_stats 0
5101                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5102                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5103                 cancel_lru_locks osc
5104                 ra_check_101 $BSIZE
5105         done
5106         cleanup_test101bc
5107         true
5108 }
5109 run_test 101b "check stride-io mode read-ahead ================="
5110
5111 test_101c() {
5112     local STRIPE_SIZE=1048576
5113     local FILE_LENGTH=$((STRIPE_SIZE*100))
5114     local nreads=10000
5115     local osc
5116
5117     setup_test101bc
5118
5119     cancel_lru_locks osc
5120     $LCTL set_param osc.*.rpc_stats 0
5121     $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
5122     for osc in $($LCTL get_param -N osc.*); do
5123         if [ "$osc" == "osc.num_refs" ]; then
5124             continue
5125         fi
5126
5127         local lines=$($LCTL get_param -n ${osc}.rpc_stats | wc | awk '{print $1}')
5128         if [ $lines -le 20 ]; then
5129             continue
5130         fi
5131
5132         local rpc4k=$($LCTL get_param -n ${osc}.rpc_stats |
5133                                      awk '$1 == "1:" { print $2; exit; }')
5134         local rpc8k=$($LCTL get_param -n ${osc}.rpc_stats |
5135                                      awk '$1 == "2:" { print $2; exit; }')
5136         local rpc16k=$($LCTL get_param -n ${osc}.rpc_stats |
5137                                      awk '$1 == "4:" { print $2; exit; }')
5138         local rpc32k=$($LCTL get_param -n ${osc}.rpc_stats |
5139                                      awk '$1 == "8:" { print $2; exit; }')
5140
5141         [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
5142         [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
5143         [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
5144         [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
5145         echo "${osc} rpc check passed!"
5146     done
5147     cleanup_test101bc
5148     true
5149 }
5150 run_test 101c "check stripe_size aligned read-ahead ================="
5151
5152 set_read_ahead() {
5153    $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
5154    $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
5155 }
5156
5157 test_101d() {
5158     local file=$DIR/$tfile
5159     local size=${FILESIZE_101c:-500}
5160     local ra_MB=${READAHEAD_MB:-40}
5161
5162     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5163     [ $space -gt $((size / 1024)) ] ||
5164         { skip "Need free space ${size}M, have $space" && return; }
5165
5166     echo Creating ${size}M test file $file
5167     dd if=/dev/zero of=$file bs=1M count=$size
5168     echo Cancel LRU locks on lustre client to flush the client cache
5169     cancel_lru_locks osc
5170
5171     echo Disable read-ahead
5172     local old_READAHEAD=$(set_read_ahead 0)
5173
5174     echo Reading the test file $file with read-ahead disabled
5175     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5176
5177     echo Cancel LRU locks on lustre client to flush the client cache
5178     cancel_lru_locks osc
5179     echo Enable read-ahead with ${ra_MB}MB
5180     set_read_ahead $ra_MB
5181
5182     echo Reading the test file $file with read-ahead enabled
5183     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5184
5185     echo read-ahead disabled time read $time_ra_OFF
5186     echo read-ahead enabled  time read $time_ra_ON
5187
5188     set_read_ahead $old_READAHEAD
5189     rm -f $file
5190
5191     [ $time_ra_ON -lt $time_ra_OFF ] ||
5192         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
5193                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
5194 }
5195 run_test 101d "file read with and without read-ahead enabled  ================="
5196
5197 test_101e() {
5198     local file=$DIR/$tfile
5199     local size=500  #KB
5200     local count=100
5201     local blksize=1024
5202
5203     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5204     local need_space=$((count * size))
5205     [ $space -gt $need_space ] ||
5206         { skip_env "Need free space $need_space, have $space" && return; }
5207
5208     echo Creating $count ${size}K test files
5209     for ((i = 0; i < $count; i++)); do
5210         dd if=/dev/zero of=${file}_${i} bs=$blksize count=$size 2>/dev/null
5211     done
5212
5213     echo Cancel LRU locks on lustre client to flush the client cache
5214     cancel_lru_locks osc
5215
5216     echo Reset readahead stats
5217     $LCTL set_param -n llite.*.read_ahead_stats 0
5218
5219     for ((i = 0; i < $count; i++)); do
5220         dd if=${file}_${i} of=/dev/null bs=$blksize count=$size 2>/dev/null
5221     done
5222
5223     local miss=$($LCTL get_param -n llite.*.read_ahead_stats | \
5224           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5225
5226     for ((i = 0; i < $count; i++)); do
5227         rm -rf ${file}_${i} 2>/dev/null
5228     done
5229
5230     #10000 means 20% reads are missing in readahead
5231     [ $miss -lt 10000 ] ||  error "misses too much for small reads"
5232 }
5233 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
5234
5235 cleanup_test101f() {
5236     trap 0
5237     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
5238     rm -rf $DIR/$tfile 2>/dev/null
5239 }
5240
5241 test_101f() {
5242     local file=$DIR/$tfile
5243     local nreads=1000
5244
5245     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
5246     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
5247     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
5248     trap cleanup_test101f EXIT
5249
5250     echo Cancel LRU locks on lustre client to flush the client cache
5251     cancel_lru_locks osc
5252
5253     echo Reset readahead stats
5254     $LCTL set_param -n llite.*.read_ahead_stats 0
5255     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
5256     # readahead should read in 2M file on second read, so only miss
5257     # 2 pages.
5258     echo Random 4K reads on 2M file for 1000 times
5259     $READS -f $file -s 2097152 -b 4096 -n $nreads
5260
5261     echo checking missing pages
5262     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
5263           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5264
5265     [ $miss -lt 3 ] || error "misses too much pages!"
5266     cleanup_test101f
5267 }
5268 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
5269
5270 setup_test102() {
5271         mkdir -p $DIR/$tdir
5272         chown $RUNAS_ID $DIR/$tdir
5273         STRIPE_SIZE=65536
5274         STRIPE_OFFSET=1
5275         STRIPE_COUNT=$OSTCOUNT
5276         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
5277
5278         trap cleanup_test102 EXIT
5279         cd $DIR
5280         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
5281         cd $DIR/$tdir
5282         for num in 1 2 3 4; do
5283                 for count in $(seq 1 $STRIPE_COUNT); do
5284                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
5285                                 local size=`expr $STRIPE_SIZE \* $num`
5286                                 local file=file"$num-$idx-$count"
5287                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
5288                         done
5289                 done
5290         done
5291
5292         cd $DIR
5293         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
5294 }
5295
5296 cleanup_test102() {
5297         trap 0
5298         rm -f $TMP/f102.tar
5299         rm -rf $DIR/d0.sanity/d102
5300 }
5301
5302 test_102a() {
5303         local testfile=$DIR/xattr_testfile
5304
5305         touch $testfile
5306
5307         [ "$UID" != 0 ] && skip_env "must run as root" && return
5308         [ -z "`lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr`" ] &&
5309                 skip_env "must have user_xattr" && return
5310
5311         [ -z "$(which setfattr 2>/dev/null)" ] &&
5312                 skip_env "could not find setfattr" && return
5313
5314         echo "set/get xattr..."
5315         setfattr -n trusted.name1 -v value1 $testfile || error
5316         getfattr -n trusted.name1 $testfile 2> /dev/null |
5317           grep "trusted.name1=.value1" ||
5318                 error "$testfile missing trusted.name1=value1"
5319
5320         setfattr -n user.author1 -v author1 $testfile || error
5321         getfattr -n user.author1 $testfile 2> /dev/null |
5322           grep "user.author1=.author1" ||
5323                 error "$testfile missing trusted.author1=author1"
5324
5325         echo "listxattr..."
5326         setfattr -n trusted.name2 -v value2 $testfile ||
5327                 error "$testfile unable to set trusted.name2"
5328         setfattr -n trusted.name3 -v value3 $testfile ||
5329                 error "$testfile unable to set trusted.name3"
5330         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
5331             grep "trusted.name" | wc -l) -eq 3 ] ||
5332                 error "$testfile missing 3 trusted.name xattrs"
5333
5334         setfattr -n user.author2 -v author2 $testfile ||
5335                 error "$testfile unable to set user.author2"
5336         setfattr -n user.author3 -v author3 $testfile ||
5337                 error "$testfile unable to set user.author3"
5338         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
5339             grep "user.author" | wc -l) -eq 3 ] ||
5340                 error "$testfile missing 3 user.author xattrs"
5341
5342         echo "remove xattr..."
5343         setfattr -x trusted.name1 $testfile ||
5344                 error "$testfile error deleting trusted.name1"
5345         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
5346                 error "$testfile did not delete trusted.name1 xattr"
5347
5348         setfattr -x user.author1 $testfile ||
5349                 error "$testfile error deleting user.author1"
5350         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
5351                 error "$testfile did not delete trusted.name1 xattr"
5352
5353         # b10667: setting lustre special xattr be silently discarded
5354         echo "set lustre special xattr ..."
5355         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
5356                 error "$testfile allowed setting trusted.lov"
5357 }
5358 run_test 102a "user xattr test =================================="
5359
5360 test_102b() {
5361         # b10930: get/set/list trusted.lov xattr
5362         echo "get/set/list trusted.lov xattr ..."
5363         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5364         local testfile=$DIR/$tfile
5365         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
5366                 error "setstripe failed"
5367         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
5368                 error "getstripe failed"
5369         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
5370         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
5371
5372         local testfile2=${testfile}2
5373         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
5374                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
5375
5376         $MCREATE $testfile2
5377         setfattr -n trusted.lov -v $value $testfile2
5378         local stripe_size=$($GETSTRIPE -S $testfile2)
5379         local stripe_count=$($GETSTRIPE -c $testfile2)
5380         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
5381         [ $stripe_count -eq $STRIPECOUNT ] ||
5382                 error "stripe count $stripe_count != $STRIPECOUNT"
5383         rm -f $DIR/$tfile
5384 }
5385 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
5386
5387 test_102c() {
5388         # b10930: get/set/list lustre.lov xattr
5389         echo "get/set/list lustre.lov xattr ..."
5390         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5391         mkdir -p $DIR/$tdir
5392         chown $RUNAS_ID $DIR/$tdir
5393         local testfile=$DIR/$tdir/$tfile
5394         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
5395                 error "setstripe failed"
5396         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
5397                 error "getstripe failed"
5398         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
5399         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
5400
5401         local testfile2=${testfile}2
5402         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
5403                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
5404
5405         $RUNAS $MCREATE $testfile2
5406         $RUNAS setfattr -n lustre.lov -v $value $testfile2
5407         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
5408         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
5409         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
5410         [ $stripe_count -eq $STRIPECOUNT ] ||
5411                 error "stripe count $stripe_count != $STRIPECOUNT"
5412 }
5413 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
5414
5415 compare_stripe_info1() {
5416         local stripe_index_all_zero=true
5417
5418         for num in 1 2 3 4; do
5419                 for count in $(seq 1 $STRIPE_COUNT); do
5420                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
5421                                 local size=$((STRIPE_SIZE * num))
5422                                 local file=file"$num-$offset-$count"
5423                                 stripe_size=$(lfs getstripe -S $PWD/$file)
5424                                 [ $stripe_size -ne $size ] &&
5425                                     error "$file: size $stripe_size != $size"
5426                                 stripe_count=$(lfs getstripe -c $PWD/$file)
5427                                 # allow fewer stripes to be created, ORI-601
5428                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
5429                                     error "$file: count $stripe_count != $count"
5430                                 stripe_index=$(lfs getstripe -i $PWD/$file)
5431                                 [ $stripe_index -ne 0 ] &&
5432                                         stripe_index_all_zero=false
5433                         done
5434                 done
5435         done
5436         $stripe_index_all_zero &&
5437                 error "all files are being extracted starting from OST index 0"
5438         return 0
5439 }
5440
5441 find_lustre_tar() {
5442         [ -n "$(which tar 2>/dev/null)" ] &&
5443                 strings $(which tar) | grep -q "lustre" && echo tar
5444 }
5445
5446 test_102d() {
5447         # b10930: tar test for trusted.lov xattr
5448         TAR=$(find_lustre_tar)
5449         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5450         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5451         setup_test102
5452         mkdir -p $DIR/d102d
5453         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
5454         cd $DIR/d102d/$tdir
5455         compare_stripe_info1
5456 }
5457 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
5458
5459 test_102f() {
5460         # b10930: tar test for trusted.lov xattr
5461         TAR=$(find_lustre_tar)
5462         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5463         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5464         setup_test102
5465         mkdir -p $DIR/d102f
5466         cd $DIR
5467         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
5468         cd $DIR/d102f/$tdir
5469         compare_stripe_info1
5470 }
5471 run_test 102f "tar copy files, not keep osts ==========="
5472
5473 grow_xattr() {
5474         local xsize=${1:-1024}  # in bytes
5475         local file=$DIR/$tfile
5476
5477         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
5478                 skip "must have user_xattr" && return 0
5479         [ -z "$(which setfattr 2>/dev/null)" ] &&
5480                 skip_env "could not find setfattr" && return 0
5481         [ -z "$(which getfattr 2>/dev/null)" ] &&
5482                 skip_env "could not find getfattr" && return 0
5483
5484         touch $file
5485
5486         local value="$(generate_string $xsize)"
5487
5488         local xbig=trusted.big
5489         log "save $xbig on $file"
5490         setfattr -n $xbig -v $value $file ||
5491                 error "saving $xbig on $file failed"
5492
5493         local orig=$(get_xattr_value $xbig $file)
5494         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
5495
5496         local xsml=trusted.sml
5497         log "save $xsml on $file"
5498         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
5499
5500         local new=$(get_xattr_value $xbig $file)
5501         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
5502
5503         log "grow $xsml on $file"
5504         setfattr -n $xsml -v "$value" $file ||
5505                 error "growing $xsml on $file failed"
5506
5507         new=$(get_xattr_value $xbig $file)
5508         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
5509         log "$xbig still valid after growing $xsml"
5510
5511         rm -f $file
5512 }
5513
5514 test_102h() { # bug 15777
5515         grow_xattr 1024
5516 }
5517 run_test 102h "grow xattr from inside inode to external block"
5518
5519 test_102ha() {
5520         large_xattr_enabled || { skip "large_xattr disabled" && return; }
5521         grow_xattr $(max_xattr_size)
5522 }
5523 run_test 102ha "grow xattr from inside inode to external inode"
5524
5525 test_102i() { # bug 17038
5526         touch $DIR/$tfile
5527         ln -s $DIR/$tfile $DIR/${tfile}link
5528         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
5529         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"
5530         rm -f $DIR/$tfile $DIR/${tfile}link
5531 }
5532 run_test 102i "lgetxattr test on symbolic link ============"
5533
5534 test_102j() {
5535         TAR=$(find_lustre_tar)
5536         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5537         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5538         setup_test102 "$RUNAS"
5539         mkdir -p $DIR/d102j
5540         chown $RUNAS_ID $DIR/d102j
5541         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
5542         cd $DIR/d102j/$tdir
5543         compare_stripe_info1 "$RUNAS"
5544 }
5545 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
5546
5547 test_102k() {
5548         touch $DIR/$tfile
5549         # b22187 just check that does not crash for regular file.
5550         setfattr -n trusted.lov $DIR/$tfile
5551         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
5552         local test_kdir=$DIR/d102k
5553         mkdir $test_kdir
5554         local default_size=`$GETSTRIPE -S $test_kdir`
5555         local default_count=`$GETSTRIPE -c $test_kdir`
5556         local default_offset=`$GETSTRIPE -i $test_kdir`
5557         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $test_kdir ||
5558                 error 'dir setstripe failed'
5559         setfattr -n trusted.lov $test_kdir
5560         local stripe_size=`$GETSTRIPE -S $test_kdir`
5561         local stripe_count=`$GETSTRIPE -c $test_kdir`
5562         local stripe_offset=`$GETSTRIPE -i $test_kdir`
5563         [ $stripe_size -eq $default_size ] ||
5564                 error "stripe size $stripe_size != $default_size"
5565         [ $stripe_count -eq $default_count ] ||
5566                 error "stripe count $stripe_count != $default_count"
5567         [ $stripe_offset -eq $default_offset ] ||
5568                 error "stripe offset $stripe_offset != $default_offset"
5569         rm -rf $DIR/$tfile $test_kdir
5570 }
5571 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
5572
5573 test_102l() {
5574         # LU-532 trusted. xattr is invisible to non-root
5575         local testfile=$DIR/$tfile
5576
5577         touch $testfile
5578
5579         echo "listxattr as user..."
5580         chown $RUNAS_ID $testfile
5581         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
5582             grep -q "trusted" &&
5583                 error "$testfile trusted xattrs are user visible"
5584
5585         return 0;
5586 }
5587 run_test 102l "listxattr filter test =================================="
5588
5589 cleanup_test102
5590
5591 run_acl_subtest()
5592 {
5593     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
5594     return $?
5595 }
5596
5597 test_103 () {
5598     [ "$UID" != 0 ] && skip_env "must run as root" && return
5599     [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
5600     [ -z "$(which setfacl 2>/dev/null)" ] && skip_env "could not find setfacl" && return
5601     $GSS && skip "could not run under gss" && return
5602
5603     declare -a identity_old
5604
5605     for num in `seq $MDSCOUNT`; do
5606         switch_identity $num true || identity_old[$num]=$?
5607     done
5608
5609     SAVE_UMASK=`umask`
5610     umask 0022
5611     cd $DIR
5612
5613     echo "performing cp ..."
5614     run_acl_subtest cp || error
5615     echo "performing getfacl-noacl..."
5616     run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
5617     echo "performing misc..."
5618     run_acl_subtest misc || error  "misc test failed"
5619     echo "performing permissions..."
5620     run_acl_subtest permissions || error "permissions failed"
5621     echo "performing setfacl..."
5622     run_acl_subtest setfacl || error  "setfacl test failed"
5623
5624     # inheritance test got from HP
5625     echo "performing inheritance..."
5626     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
5627     chmod +x make-tree || error "chmod +x failed"
5628     run_acl_subtest inheritance || error "inheritance test failed"
5629     rm -f make-tree
5630
5631     cd $SAVE_PWD
5632     umask $SAVE_UMASK
5633
5634     for num in `seq $MDSCOUNT`; do
5635         if [ "${identity_old[$num]}" = 1 ]; then
5636             switch_identity $num false || identity_old[$num]=$?
5637         fi
5638     done
5639 }
5640 run_test 103 "acl test ========================================="
5641
5642 test_104a() {
5643         touch $DIR/$tfile
5644         lfs df || error "lfs df failed"
5645         lfs df -ih || error "lfs df -ih failed"
5646         lfs df -h $DIR || error "lfs df -h $DIR failed"
5647         lfs df -i $DIR || error "lfs df -i $DIR failed"
5648         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
5649         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
5650
5651         OSC=`lctl dl |grep OST0000-osc-[^M] |awk '{print $4}'`
5652         lctl --device %$OSC deactivate
5653         lfs df || error "lfs df with deactivated OSC failed"
5654         lctl --device %$OSC activate
5655         # wait the osc back to normal
5656         wait_osc_import_state client ost FULL
5657
5658         lfs df || error "lfs df with reactivated OSC failed"
5659         rm -f $DIR/$tfile
5660 }
5661 run_test 104a "lfs df [-ih] [path] test ========================="
5662
5663 test_104b() {
5664         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5665         chmod 666 /dev/obd
5666         denied_cnt=$((`$RUNAS $LFS check servers 2>&1 | grep "Permission denied" | wc -l`))
5667         if [ $denied_cnt -ne 0 ];
5668         then
5669                     error "lfs check servers test failed"
5670         fi
5671 }
5672 run_test 104b "$RUNAS lfs check servers test ===================="
5673
5674 test_105a() {
5675         # doesn't work on 2.4 kernels
5676         touch $DIR/$tfile
5677         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5678         then
5679                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
5680         else
5681                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
5682         fi
5683         rm -f $DIR/$tfile
5684 }
5685 run_test 105a "flock when mounted without -o flock test ========"
5686
5687 test_105b() {
5688         touch $DIR/$tfile
5689         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5690         then
5691                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
5692         else
5693                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
5694         fi
5695         rm -f $DIR/$tfile
5696 }
5697 run_test 105b "fcntl when mounted without -o flock test ========"
5698
5699 test_105c() {
5700         touch $DIR/$tfile
5701         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5702         then
5703                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
5704         else
5705                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
5706         fi
5707         rm -f $DIR/$tfile
5708 }
5709 run_test 105c "lockf when mounted without -o flock test ========"
5710
5711 test_105d() { # bug 15924
5712         mkdir -p $DIR/$tdir
5713         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
5714                 skip "mount w/o flock enabled" && return
5715         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
5716         $LCTL set_param fail_loc=0x80000315
5717         flocks_test 2 $DIR/$tdir
5718 }
5719 run_test 105d "flock race (should not freeze) ========"
5720
5721 test_105e() { # bug 22660 && 22040
5722         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
5723                 skip "mount w/o flock enabled" && return
5724         touch $DIR/$tfile
5725         flocks_test 3 $DIR/$tfile
5726 }
5727 run_test 105e "Two conflicting flocks from same process ======="
5728
5729 test_106() { #bug 10921
5730         mkdir -p $DIR/$tdir
5731         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
5732         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
5733 }
5734 run_test 106 "attempt exec of dir followed by chown of that dir"
5735
5736 test_107() {
5737         CDIR=`pwd`
5738         cd $DIR
5739
5740         local file=core
5741         rm -f $file
5742
5743         local save_pattern=$(sysctl -n kernel.core_pattern)
5744         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
5745         sysctl -w kernel.core_pattern=$file
5746         sysctl -w kernel.core_uses_pid=0
5747
5748         ulimit -c unlimited
5749         sleep 60 &
5750         SLEEPPID=$!
5751
5752         sleep 1
5753
5754         kill -s 11 $SLEEPPID
5755         wait $SLEEPPID
5756         if [ -e $file ]; then
5757                 size=`stat -c%s $file`
5758                 [ $size -eq 0 ] && error "Fail to create core file $file"
5759         else
5760                 error "Fail to create core file $file"
5761         fi
5762         rm -f $file
5763         sysctl -w kernel.core_pattern=$save_pattern
5764         sysctl -w kernel.core_uses_pid=$save_uses_pid
5765         cd $CDIR
5766 }
5767 run_test 107 "Coredump on SIG"
5768
5769 test_110() {
5770         mkdir -p $DIR/d110
5771         mkdir $DIR/d110/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || error "mkdir with 255 char fail"
5772         mkdir $DIR/d110/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && error "mkdir with 256 char should fail, but not"
5773         touch $DIR/d110/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx || error "create with 255 char fail"
5774         touch $DIR/d110/yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy && error ""create with 256 char should fail, but not
5775
5776         ls -l $DIR/d110
5777     rm -fr $DIR/d110
5778 }
5779 run_test 110 "filename length checking"
5780
5781 test_115() {
5782         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
5783             cut -c11-20)
5784         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
5785             return
5786         echo "Starting with $OSTIO_pre threads"
5787
5788         NUMTEST=20000
5789         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
5790         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
5791         echo "$NUMTEST creates/unlinks"
5792         mkdir -p $DIR/$tdir
5793         createmany -o $DIR/$tdir/$tfile $NUMTEST
5794         unlinkmany $DIR/$tdir/$tfile $NUMTEST
5795
5796         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
5797             cut -c11-20)
5798
5799         # don't return an error
5800         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
5801             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&\
5802             echo "This may be fine, depending on what ran before this test" &&\
5803             echo "and how fast this system is." && return
5804
5805         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
5806 }
5807 run_test 115 "verify dynamic thread creation===================="
5808
5809 free_min_max () {
5810         wait_delete_completed
5811         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
5812         echo OST kbytes available: ${AVAIL[@]}
5813         MAXI=0; MAXV=${AVAIL[0]}
5814         MINI=0; MINV=${AVAIL[0]}
5815         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
5816             #echo OST $i: ${AVAIL[i]}kb
5817             if [ ${AVAIL[i]} -gt $MAXV ]; then
5818                 MAXV=${AVAIL[i]}; MAXI=$i
5819             fi
5820             if [ ${AVAIL[i]} -lt $MINV ]; then
5821                 MINV=${AVAIL[i]}; MINI=$i
5822             fi
5823         done
5824         echo Min free space: OST $MINI: $MINV
5825         echo Max free space: OST $MAXI: $MAXV
5826 }
5827
5828 test_116() {
5829         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
5830
5831         echo -n "Free space priority "
5832         lctl get_param -n lov.*-clilov-*.qos_prio_free
5833         declare -a AVAIL
5834         free_min_max
5835         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI, skip" &&\
5836                 return
5837
5838         # generate uneven OSTs
5839         mkdir -p $DIR/$tdir/OST${MINI}
5840         declare -i FILL
5841         FILL=$(($MINV / 4))
5842         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
5843         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
5844         i=0
5845         while [ $FILL -gt 0 ]; do
5846             i=$(($i + 1))
5847             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
5848             FILL=$(($FILL - 2048))
5849             echo -n .
5850         done
5851         FILL=$(($MINV / 4))
5852         sync
5853         sleep_maxage
5854
5855         free_min_max
5856         DIFF=$(($MAXV - $MINV))
5857         DIFF2=$(($DIFF * 100 / $MINV))
5858         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
5859         if [ $DIFF2 -gt 20 ]; then
5860             echo "ok"
5861         else
5862             echo "failed - QOS mode won't be used"
5863             error_ignore "QOS imbalance criteria not met"
5864             return
5865         fi
5866
5867         MINI1=$MINI; MINV1=$MINV
5868         MAXI1=$MAXI; MAXV1=$MAXV
5869
5870         # now fill using QOS
5871         echo writing a bunch of files to QOS-assigned OSTs
5872         $SETSTRIPE -c 1 $DIR/$tdir
5873         i=0
5874         while [ $FILL -gt 0 ]; do
5875             i=$(($i + 1))
5876             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
5877             FILL=$(($FILL - 200))
5878             echo -n .
5879         done
5880         echo "wrote $i 200k files"
5881         sync
5882         sleep_maxage
5883
5884         echo "Note: free space may not be updated, so measurements might be off"
5885         free_min_max
5886         DIFF2=$(($MAXV - $MINV))
5887         echo "free space delta: orig $DIFF final $DIFF2"
5888         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
5889         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
5890         echo "Wrote $DIFF to smaller OST $MINI1"
5891         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
5892         echo "Wrote $DIFF2 to larger OST $MAXI1"
5893         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
5894
5895         # Figure out which files were written where
5896         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
5897                awk '/'$MINI1': / {print $2; exit}')
5898         echo $UUID
5899         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
5900         echo "$MINC files created on smaller OST $MINI1"
5901         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
5902                awk '/'$MAXI1': / {print $2; exit}')
5903         echo $UUID
5904         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
5905         echo "$MAXC files created on larger OST $MAXI1"
5906         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
5907         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
5908
5909         rm -rf $DIR/$tdir
5910 }
5911 run_test 116 "stripe QOS: free space balance ==================="
5912
5913 test_117() # bug 10891
5914 {
5915         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
5916         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
5917         lctl set_param fail_loc=0x21e
5918         > $DIR/$tfile || error "truncate failed"
5919         lctl set_param fail_loc=0
5920         echo "Truncate succeeded."
5921         rm -f $DIR/$tfile
5922 }
5923 run_test 117 "verify fsfilt_extend =========="
5924
5925 export OLD_RESENDCOUNT=""
5926 set_resend_count () {
5927         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
5928         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
5929         lctl set_param -n $PROC_RESENDCOUNT $1
5930         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
5931 }
5932
5933 [ "$SLOW" = "no" ] && set_resend_count 4 # for reduce test_118* time (bug 14842)
5934
5935 # Reset async IO behavior after error case
5936 reset_async() {
5937         FILE=$DIR/reset_async
5938
5939         # Ensure all OSCs are cleared
5940         $SETSTRIPE -c -1 $FILE
5941         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
5942         sync
5943         rm $FILE
5944 }
5945
5946 test_118a() #bug 11710
5947 {
5948         reset_async
5949
5950         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5951         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
5952         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
5953
5954         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5955                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5956                 return 1;
5957         fi
5958         rm -f $DIR/$tfile
5959 }
5960 run_test 118a "verify O_SYNC works =========="
5961
5962 test_118b()
5963 {
5964         remote_ost_nodsh && skip "remote OST with nodsh" && return
5965
5966         reset_async
5967
5968         #define OBD_FAIL_OST_ENOENT 0x217
5969         set_nodes_failloc "$(osts_nodes)" 0x217
5970         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5971         RC=$?
5972         set_nodes_failloc "$(osts_nodes)" 0
5973         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
5974         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
5975                     grep -c writeback)
5976
5977         if [[ $RC -eq 0 ]]; then
5978                 error "Must return error due to dropped pages, rc=$RC"
5979                 return 1;
5980         fi
5981
5982         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
5983                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
5984                 return 1;
5985         fi
5986
5987         echo "Dirty pages not leaked on ENOENT"
5988
5989         # Due to the above error the OSC will issue all RPCs syncronously
5990         # until a subsequent RPC completes successfully without error.
5991         $MULTIOP $DIR/$tfile Ow4096yc
5992         rm -f $DIR/$tfile
5993
5994         return 0
5995 }
5996 run_test 118b "Reclaim dirty pages on fatal error =========="
5997
5998 test_118c()
5999 {
6000         remote_ost_nodsh && skip "remote OST with nodsh" && return
6001
6002         reset_async
6003
6004         #define OBD_FAIL_OST_EROFS               0x216
6005         set_nodes_failloc "$(osts_nodes)" 0x216
6006
6007         # multiop should block due to fsync until pages are written
6008         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6009         MULTIPID=$!
6010         sleep 1
6011
6012         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6013                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6014         fi
6015
6016         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6017                     grep -c writeback)
6018         if [[ $WRITEBACK -eq 0 ]]; then
6019                 error "No page in writeback, writeback=$WRITEBACK"
6020         fi
6021
6022         set_nodes_failloc "$(osts_nodes)" 0
6023         wait $MULTIPID
6024         RC=$?
6025         if [[ $RC -ne 0 ]]; then
6026                 error "Multiop fsync failed, rc=$RC"
6027         fi
6028
6029         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6030         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6031                     grep -c writeback)
6032         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6033                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6034         fi
6035
6036         rm -f $DIR/$tfile
6037         echo "Dirty pages flushed via fsync on EROFS"
6038         return 0
6039 }
6040 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
6041
6042 test_118d()
6043 {
6044         remote_ost_nodsh && skip "remote OST with nodsh" && return
6045
6046         reset_async
6047
6048         #define OBD_FAIL_OST_BRW_PAUSE_BULK
6049         set_nodes_failloc "$(osts_nodes)" 0x214
6050         # multiop should block due to fsync until pages are written
6051         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6052         MULTIPID=$!
6053         sleep 1
6054
6055         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6056                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6057         fi
6058
6059         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6060                     grep -c writeback)
6061         if [[ $WRITEBACK -eq 0 ]]; then
6062                 error "No page in writeback, writeback=$WRITEBACK"
6063         fi
6064
6065         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
6066         set_nodes_failloc "$(osts_nodes)" 0
6067
6068         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6069         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6070                     grep -c writeback)
6071         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6072                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6073         fi
6074
6075         rm -f $DIR/$tfile
6076         echo "Dirty pages gaurenteed flushed via fsync"
6077         return 0
6078 }
6079 run_test 118d "Fsync validation inject a delay of the bulk =========="
6080
6081 test_118f() {
6082         reset_async
6083
6084         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
6085         lctl set_param fail_loc=0x8000040a
6086
6087         # Should simulate EINVAL error which is fatal
6088         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6089         RC=$?
6090         if [[ $RC -eq 0 ]]; then
6091                 error "Must return error due to dropped pages, rc=$RC"
6092         fi
6093
6094         lctl set_param fail_loc=0x0
6095
6096         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6097         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6098         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6099                     grep -c writeback)
6100         if [[ $LOCKED -ne 0 ]]; then
6101                 error "Locked pages remain in cache, locked=$LOCKED"
6102         fi
6103
6104         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6105                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6106         fi
6107
6108         rm -f $DIR/$tfile
6109         echo "No pages locked after fsync"
6110
6111         reset_async
6112         return 0
6113 }
6114 run_test 118f "Simulate unrecoverable OSC side error =========="
6115
6116 test_118g() {
6117         reset_async
6118
6119         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
6120         lctl set_param fail_loc=0x406
6121
6122         # simulate local -ENOMEM
6123         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6124         RC=$?
6125
6126         lctl set_param fail_loc=0
6127         if [[ $RC -eq 0 ]]; then
6128                 error "Must return error due to dropped pages, rc=$RC"
6129         fi
6130
6131         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6132         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6133         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6134                         grep -c writeback)
6135         if [[ $LOCKED -ne 0 ]]; then
6136                 error "Locked pages remain in cache, locked=$LOCKED"
6137         fi
6138
6139         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6140                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6141         fi
6142
6143         rm -f $DIR/$tfile
6144         echo "No pages locked after fsync"
6145
6146         reset_async
6147         return 0
6148 }
6149 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
6150
6151 test_118h() {
6152         remote_ost_nodsh && skip "remote OST with nodsh" && return
6153
6154         reset_async
6155
6156         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6157         set_nodes_failloc "$(osts_nodes)" 0x20e
6158         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6159         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6160         RC=$?
6161
6162         set_nodes_failloc "$(osts_nodes)" 0
6163         if [[ $RC -eq 0 ]]; then
6164                 error "Must return error due to dropped pages, rc=$RC"
6165         fi
6166
6167         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6168         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6169         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6170                     grep -c writeback)
6171         if [[ $LOCKED -ne 0 ]]; then
6172                 error "Locked pages remain in cache, locked=$LOCKED"
6173         fi
6174
6175         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6176                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6177         fi
6178
6179         rm -f $DIR/$tfile
6180         echo "No pages locked after fsync"
6181
6182         return 0
6183 }
6184 run_test 118h "Verify timeout in handling recoverables errors  =========="
6185
6186 test_118i() {
6187         remote_ost_nodsh && skip "remote OST with nodsh" && return
6188
6189         reset_async
6190
6191         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6192         set_nodes_failloc "$(osts_nodes)" 0x20e
6193
6194         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6195         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6196         PID=$!
6197         sleep 5
6198         set_nodes_failloc "$(osts_nodes)" 0
6199
6200         wait $PID
6201         RC=$?
6202         if [[ $RC -ne 0 ]]; then
6203                 error "got error, but should be not, rc=$RC"
6204         fi
6205
6206         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6207         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6208         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6209         if [[ $LOCKED -ne 0 ]]; then
6210                 error "Locked pages remain in cache, locked=$LOCKED"
6211         fi
6212
6213         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6214                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6215         fi
6216
6217         rm -f $DIR/$tfile
6218         echo "No pages locked after fsync"
6219
6220         return 0
6221 }
6222 run_test 118i "Fix error before timeout in recoverable error  =========="
6223
6224 test_118j() {
6225         remote_ost_nodsh && skip "remote OST with nodsh" && return
6226
6227         reset_async
6228
6229         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
6230         set_nodes_failloc "$(osts_nodes)" 0x220
6231
6232         # return -EIO from OST
6233         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6234         RC=$?
6235         set_nodes_failloc "$(osts_nodes)" 0x0
6236         if [[ $RC -eq 0 ]]; then
6237                 error "Must return error due to dropped pages, rc=$RC"
6238         fi
6239
6240         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6241         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6242         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6243         if [[ $LOCKED -ne 0 ]]; then
6244                 error "Locked pages remain in cache, locked=$LOCKED"
6245         fi
6246
6247         # in recoverable error on OST we want resend and stay until it finished
6248         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6249                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6250         fi
6251
6252         rm -f $DIR/$tfile
6253         echo "No pages locked after fsync"
6254
6255         return 0
6256 }
6257 run_test 118j "Simulate unrecoverable OST side error =========="
6258
6259 test_118k()
6260 {
6261         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
6262
6263         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6264         set_nodes_failloc "$(osts_nodes)" 0x20e
6265         mkdir -p $DIR/$tdir
6266
6267         for ((i=0;i<10;i++)); do
6268                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
6269                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
6270                 SLEEPPID=$!
6271                 sleep 0.500s
6272                 kill $SLEEPPID
6273                 wait $SLEEPPID
6274         done
6275
6276         set_nodes_failloc "$(osts_nodes)" 0
6277         rm -rf $DIR/$tdir
6278 }
6279 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
6280
6281 test_118l()
6282 {
6283         # LU-646
6284         mkdir -p $DIR/$tdir
6285         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
6286         rm -rf $DIR/$tdir
6287 }
6288 run_test 118l "fsync dir ========="
6289
6290 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
6291
6292 test_119a() # bug 11737
6293 {
6294         BSIZE=$((512 * 1024))
6295         directio write $DIR/$tfile 0 1 $BSIZE
6296         # We ask to read two blocks, which is more than a file size.
6297         # directio will indicate an error when requested and actual
6298         # sizes aren't equeal (a normal situation in this case) and
6299         # print actual read amount.
6300         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
6301         if [ "$NOB" != "$BSIZE" ]; then
6302                 error "read $NOB bytes instead of $BSIZE"
6303         fi
6304         rm -f $DIR/$tfile
6305 }
6306 run_test 119a "Short directIO read must return actual read amount"
6307
6308 test_119b() # bug 11737
6309 {
6310         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6311
6312         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
6313         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
6314         sync
6315         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
6316                 error "direct read failed"
6317         rm -f $DIR/$tfile
6318 }
6319 run_test 119b "Sparse directIO read must return actual read amount"
6320
6321 test_119c() # bug 13099
6322 {
6323         BSIZE=1048576
6324         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
6325         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
6326         rm -f $DIR/$tfile
6327 }
6328 run_test 119c "Testing for direct read hitting hole"
6329
6330 test_119d() # bug 15950
6331 {
6332         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
6333         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
6334         BSIZE=1048576
6335         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
6336         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
6337         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
6338         lctl set_param fail_loc=0x40d
6339         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
6340         pid_dio=$!
6341         sleep 1
6342         cat $DIR/$tfile > /dev/null &
6343         lctl set_param fail_loc=0
6344         pid_reads=$!
6345         wait $pid_dio
6346         log "the DIO writes have completed, now wait for the reads (should not block very long)"
6347         sleep 2
6348         [ -n "`ps h -p $pid_reads -o comm`" ] && \
6349         error "the read rpcs have not completed in 2s"
6350         rm -f $DIR/$tfile
6351         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
6352 }
6353 run_test 119d "The DIO path should try to send a new rpc once one is completed"
6354
6355 test_120a() {
6356         mkdir -p $DIR/$tdir
6357         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6358                skip "no early lock cancel on server" && return 0
6359         lru_resize_disable mdc
6360         lru_resize_disable osc
6361         cancel_lru_locks mdc
6362         stat $DIR/$tdir > /dev/null
6363         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6364         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6365         mkdir $DIR/$tdir/d1
6366         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6367         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6368         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6369         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6370         lru_resize_enable mdc
6371         lru_resize_enable osc
6372 }
6373 run_test 120a "Early Lock Cancel: mkdir test"
6374
6375 test_120b() {
6376         mkdir -p $DIR/$tdir
6377         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6378                skip "no early lock cancel on server" && return 0
6379         lru_resize_disable mdc
6380         lru_resize_disable osc
6381         cancel_lru_locks mdc
6382         stat $DIR/$tdir > /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         touch $DIR/$tdir/f1
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 120b "Early Lock Cancel: create test"
6394
6395 test_120c() {
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         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
6402         touch $DIR/$tdir/d1/f1
6403         cancel_lru_locks mdc
6404         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
6405         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6406         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6407         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
6408         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6409         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6410         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6411         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6412         lru_resize_enable mdc
6413         lru_resize_enable osc
6414 }
6415 run_test 120c "Early Lock Cancel: link test"
6416
6417 test_120d() {
6418         mkdir -p $DIR/$tdir
6419         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6420                skip "no early lock cancel on server" && return 0
6421         lru_resize_disable mdc
6422         lru_resize_disable osc
6423         touch $DIR/$tdir
6424         cancel_lru_locks mdc
6425         stat $DIR/$tdir > /dev/null
6426         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6427         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6428         chmod a+x $DIR/$tdir
6429         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6430         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6431         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6432         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6433         lru_resize_enable mdc
6434         lru_resize_enable osc
6435 }
6436 run_test 120d "Early Lock Cancel: setattr test"
6437
6438 test_120e() {
6439         mkdir -p $DIR/$tdir
6440         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6441                skip "no early lock cancel on server" && return 0
6442         lru_resize_disable mdc
6443         lru_resize_disable osc
6444         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
6445         cancel_lru_locks mdc
6446         cancel_lru_locks osc
6447         dd if=$DIR/$tdir/f1 of=/dev/null
6448         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
6449         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6450               awk '/ldlm_cancel/ {print $2}'`
6451         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6452               awk '/ldlm_bl_callback/ {print $2}'`
6453         unlink $DIR/$tdir/f1
6454         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6455               awk '/ldlm_cancel/ {print $2}'`
6456         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6457               awk '/ldlm_bl_callback/ {print $2}'`
6458         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6459         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6460         lru_resize_enable mdc
6461         lru_resize_enable osc
6462 }
6463 run_test 120e "Early Lock Cancel: unlink test"
6464
6465 test_120f() {
6466         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6467                skip "no early lock cancel on server" && return 0
6468         mkdir -p $DIR/$tdir
6469         lru_resize_disable mdc
6470         lru_resize_disable osc
6471         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
6472         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
6473         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
6474         cancel_lru_locks mdc
6475         cancel_lru_locks osc
6476         dd if=$DIR/$tdir/d1/f1 of=/dev/null
6477         dd if=$DIR/$tdir/d2/f2 of=/dev/null
6478         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
6479         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6480               awk '/ldlm_cancel/ {print $2}'`
6481         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6482               awk '/ldlm_bl_callback/ {print $2}'`
6483         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
6484         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6485               awk '/ldlm_cancel/ {print $2}'`
6486         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6487               awk '/ldlm_bl_callback/ {print $2}'`
6488         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6489         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6490         lru_resize_enable mdc
6491         lru_resize_enable osc
6492 }
6493 run_test 120f "Early Lock Cancel: rename test"
6494
6495 test_120g() {
6496         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6497                skip "no early lock cancel on server" && return 0
6498         lru_resize_disable mdc
6499         lru_resize_disable osc
6500         count=10000
6501         echo create $count files
6502         mkdir -p $DIR/$tdir
6503         cancel_lru_locks mdc
6504         cancel_lru_locks osc
6505         t0=`date +%s`
6506
6507         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6508               awk '/ldlm_cancel/ {print $2}'`
6509         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6510               awk '/ldlm_bl_callback/ {print $2}'`
6511         createmany -o $DIR/$tdir/f $count
6512         sync
6513         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6514               awk '/ldlm_cancel/ {print $2}'`
6515         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6516               awk '/ldlm_bl_callback/ {print $2}'`
6517         t1=`date +%s`
6518         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
6519         echo rm $count files
6520         rm -r $DIR/$tdir
6521         sync
6522         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6523               awk '/ldlm_cancel/ {print $2}'`
6524         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6525               awk '/ldlm_bl_callback/ {print $2}'`
6526         t2=`date +%s`
6527         echo total: $count removes in $((t2-t1))
6528         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
6529         sleep 2
6530         # wait for commitment of removal
6531         lru_resize_enable mdc
6532         lru_resize_enable osc
6533 }
6534 run_test 120g "Early Lock Cancel: performance test"
6535
6536 test_121() { #bug #10589
6537         rm -rf $DIR/$tfile
6538         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
6539 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
6540         lctl set_param fail_loc=0x310
6541         cancel_lru_locks osc > /dev/null
6542         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
6543         lctl set_param fail_loc=0
6544         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
6545 }
6546 run_test 121 "read cancel race ========="
6547
6548 test_123a() { # was test 123, statahead(bug 11401)
6549         SLOWOK=0
6550         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
6551             log "testing on UP system. Performance may be not as good as expected."
6552                         SLOWOK=1
6553         fi
6554
6555         rm -rf $DIR/$tdir
6556         mkdir -p $DIR/$tdir
6557         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6558         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
6559         MULT=10
6560         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
6561                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
6562
6563                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
6564                 lctl set_param -n llite.*.statahead_max 0
6565                 lctl get_param llite.*.statahead_max
6566                 cancel_lru_locks mdc
6567                 cancel_lru_locks osc
6568                 stime=`date +%s`
6569                 time ls -l $DIR/$tdir | wc -l
6570                 etime=`date +%s`
6571                 delta=$((etime - stime))
6572                 log "ls $i files without statahead: $delta sec"
6573                 lctl set_param llite.*.statahead_max=$max
6574
6575                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
6576                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
6577                 cancel_lru_locks mdc
6578                 cancel_lru_locks osc
6579                 stime=`date +%s`
6580                 time ls -l $DIR/$tdir | wc -l
6581                 etime=`date +%s`
6582                 delta_sa=$((etime - stime))
6583                 log "ls $i files with statahead: $delta_sa sec"
6584                 lctl get_param -n llite.*.statahead_stats
6585                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
6586
6587                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
6588                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
6589
6590                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
6591                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
6592                     lctl set_param -n llite.*.statahead_max 0
6593                     lctl get_param llite.*.statahead_max
6594                     cancel_lru_locks mdc
6595                     cancel_lru_locks osc
6596                     stime=`date +%s`
6597                     time ls -l $DIR/$tdir | wc -l
6598                     etime=`date +%s`
6599                     delta=$((etime - stime))
6600                     log "ls $i files again without statahead: $delta sec"
6601                     lctl set_param llite.*.statahead_max=$max
6602                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
6603                         if [  $SLOWOK -eq 0 ]; then
6604                                 error "ls $i files is slower with statahead!"
6605                         else
6606                                 log "ls $i files is slower with statahead!"
6607                         fi
6608                         break
6609                     fi
6610                 fi
6611
6612                 [ $delta -gt 20 ] && break
6613                 [ $delta -gt 8 ] && MULT=$((50 / delta))
6614                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
6615         done
6616         log "ls done"
6617
6618         stime=`date +%s`
6619         rm -r $DIR/$tdir
6620         sync
6621         etime=`date +%s`
6622         delta=$((etime - stime))
6623         log "rm -r $DIR/$tdir/: $delta seconds"
6624         log "rm done"
6625         lctl get_param -n llite.*.statahead_stats
6626 }
6627 run_test 123a "verify statahead work"
6628
6629 test_123b () { # statahead(bug 15027)
6630         mkdir -p $DIR/$tdir
6631         createmany -o $DIR/$tdir/$tfile-%d 1000
6632
6633         cancel_lru_locks mdc
6634         cancel_lru_locks osc
6635
6636 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
6637         lctl set_param fail_loc=0x80000803
6638         ls -lR $DIR/$tdir > /dev/null
6639         log "ls done"
6640         lctl set_param fail_loc=0x0
6641         lctl get_param -n llite.*.statahead_stats
6642         rm -r $DIR/$tdir
6643         sync
6644
6645 }
6646 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
6647
6648 test_124a() {
6649         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
6650                skip "no lru resize on server" && return 0
6651         local NR=2000
6652         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
6653
6654         log "create $NR files at $DIR/$tdir"
6655         createmany -o $DIR/$tdir/f $NR ||
6656                 error "failed to create $NR files in $DIR/$tdir"
6657
6658         cancel_lru_locks mdc
6659         ls -l $DIR/$tdir > /dev/null
6660
6661         local NSDIR=""
6662         local LRU_SIZE=0
6663         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
6664                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6665                 LRU_SIZE=$(lctl get_param -n $PARAM)
6666                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
6667                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
6668                                                 log "NSDIR=$NSDIR"
6669                         log "NS=$(basename $NSDIR)"
6670                         break
6671                 fi
6672         done
6673
6674         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
6675                 skip "Not enough cached locks created!"
6676                 return 0
6677         fi
6678         log "LRU=$LRU_SIZE"
6679
6680         local SLEEP=30
6681
6682         # We know that lru resize allows one client to hold $LIMIT locks
6683         # for 10h. After that locks begin to be killed by client.
6684         local MAX_HRS=10
6685         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
6686                 log "LIMIT=$LIMIT"
6687
6688         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
6689         # killing locks. Some time was spent for creating locks. This means
6690         # that up to the moment of sleep finish we must have killed some of
6691         # them (10-100 locks). This depends on how fast ther were created.
6692         # Many of them were touched in almost the same moment and thus will
6693         # be killed in groups.
6694         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
6695
6696         # Use $LRU_SIZE_B here to take into account real number of locks
6697         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
6698         local LRU_SIZE_B=$LRU_SIZE
6699         log "LVF=$LVF"
6700         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
6701                 log "OLD_LVF=$OLD_LVF"
6702         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
6703
6704         # Let's make sure that we really have some margin. Client checks
6705         # cached locks every 10 sec.
6706         SLEEP=$((SLEEP+20))
6707         log "Sleep ${SLEEP} sec"
6708         local SEC=0
6709         while ((SEC<$SLEEP)); do
6710                 echo -n "..."
6711                 sleep 5
6712                 SEC=$((SEC+5))
6713                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
6714                 echo -n "$LRU_SIZE"
6715         done
6716         echo ""
6717         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
6718         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
6719
6720         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
6721                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
6722                 unlinkmany $DIR/$tdir/f $NR
6723                 return
6724         }
6725
6726         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
6727         log "unlink $NR files at $DIR/$tdir"
6728         unlinkmany $DIR/$tdir/f $NR
6729 }
6730 run_test 124a "lru resize ======================================="
6731
6732 get_max_pool_limit()
6733 {
6734         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
6735         local max=0
6736         for l in $limit; do
6737                 if test $l -gt $max; then
6738                         max=$l
6739                 fi
6740         done
6741         echo $max
6742 }
6743
6744 test_124b() {
6745         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
6746                skip "no lru resize on server" && return 0
6747
6748         LIMIT=`get_max_pool_limit`
6749
6750         NR=$(($(default_lru_size)*20))
6751         if [ $NR -gt $LIMIT ]; then
6752                 log "Limit lock number by $LIMIT locks"
6753                 NR=$LIMIT
6754         fi
6755         lru_resize_disable mdc
6756         mkdir -p $DIR/$tdir/disable_lru_resize ||
6757                 error "failed to create $DIR/$tdir/disable_lru_resize"
6758
6759         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
6760         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
6761         cancel_lru_locks mdc
6762         stime=`date +%s`
6763         PID=""
6764         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6765         PID="$PID $!"
6766         sleep 2
6767         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6768         PID="$PID $!"
6769         sleep 2
6770         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6771         PID="$PID $!"
6772         wait $PID
6773         etime=`date +%s`
6774         nolruresize_delta=$((etime-stime))
6775         log "ls -la time: $nolruresize_delta seconds"
6776         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
6777         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
6778
6779         lru_resize_enable mdc
6780         mkdir -p $DIR/$tdir/enable_lru_resize ||
6781                 error "failed to create $DIR/$tdir/enable_lru_resize"
6782
6783         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
6784         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
6785         cancel_lru_locks mdc
6786         stime=`date +%s`
6787         PID=""
6788         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6789         PID="$PID $!"
6790         sleep 2
6791         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6792         PID="$PID $!"
6793         sleep 2
6794         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6795         PID="$PID $!"
6796         wait $PID
6797         etime=`date +%s`
6798         lruresize_delta=$((etime-stime))
6799         log "ls -la time: $lruresize_delta seconds"
6800         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
6801
6802         if [ $lruresize_delta -gt $nolruresize_delta ]; then
6803                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
6804         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
6805                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
6806         else
6807                 log "lru resize performs the same with no lru resize"
6808         fi
6809         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
6810 }
6811 run_test 124b "lru resize (performance test) ======================="
6812
6813 test_125() { # 13358
6814         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
6815         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
6816         mkdir -p $DIR/d125 || error "mkdir failed"
6817         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
6818         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
6819         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
6820 }
6821 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
6822
6823 test_126() { # bug 12829/13455
6824         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
6825         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
6826         $GSS && skip "must run as gss disabled" && return
6827
6828         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
6829         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
6830         rm -f $DIR/$tfile
6831         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
6832 }
6833 run_test 126 "check that the fsgid provided by the client is taken into account"
6834
6835 test_127a() { # bug 15521
6836         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
6837         $LCTL set_param osc.*.stats=0
6838         FSIZE=$((2048 * 1024))
6839         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
6840         cancel_lru_locks osc
6841         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
6842
6843         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
6844         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
6845                 echo "got $COUNT $NAME"
6846                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
6847                 eval $NAME=$COUNT || error "Wrong proc format"
6848
6849                 case $NAME in
6850                         read_bytes|write_bytes)
6851                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
6852                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
6853                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
6854                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
6855                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
6856                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
6857                                 error "sumsquare is too small: $SUMSQ"
6858                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
6859                                 error "sumsquare is too big: $SUMSQ"
6860                         ;;
6861                         *) ;;
6862                 esac
6863         done < $DIR/${tfile}.tmp
6864
6865         #check that we actually got some stats
6866         [ "$read_bytes" ] || error "Missing read_bytes stats"
6867         [ "$write_bytes" ] || error "Missing write_bytes stats"
6868         [ "$read_bytes" != 0 ] || error "no read done"
6869         [ "$write_bytes" != 0 ] || error "no write done"
6870 }
6871 run_test 127a "verify the client stats are sane"
6872
6873 test_127b() { # bug LU-333
6874         $LCTL set_param llite.*.stats=0
6875         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
6876         # perform 2 reads and writes so MAX is different from SUM.
6877         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
6878         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
6879         cancel_lru_locks osc
6880         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
6881         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
6882
6883         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
6884         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
6885                 echo "got $COUNT $NAME"
6886                 eval $NAME=$COUNT || error "Wrong proc format"
6887
6888         case $NAME in
6889                 read_bytes)
6890                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
6891                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
6892                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
6893                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
6894                         ;;
6895                 write_bytes)
6896                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
6897                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
6898                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
6899                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
6900                         ;;
6901                         *) ;;
6902                 esac
6903         done < $TMP/${tfile}.tmp
6904
6905         #check that we actually got some stats
6906         [ "$read_bytes" ] || error "Missing read_bytes stats"
6907         [ "$write_bytes" ] || error "Missing write_bytes stats"
6908         [ "$read_bytes" != 0 ] || error "no read done"
6909         [ "$write_bytes" != 0 ] || error "no write done"
6910 }
6911 run_test 127b "verify the llite client stats are sane"
6912
6913 test_128() { # bug 15212
6914         touch $DIR/$tfile
6915         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
6916                 find $DIR/$tfile
6917                 find $DIR/$tfile
6918         EOF
6919
6920         result=$(grep error $TMP/$tfile.log)
6921         rm -f $DIR/$tfile
6922         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
6923 }
6924 run_test 128 "interactive lfs for 2 consecutive find's"
6925
6926 set_dir_limits () {
6927         local mntdev
6928         local canondev
6929         local node
6930
6931         local LDPROC=/proc/fs/ldiskfs
6932
6933         for facet in $(get_facets MDS); do
6934                 canondev=$(ldiskfs_canon *.$(convert_facet2label $facet).mntdev $facet)
6935                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" || LDPROC=/sys/fs/ldiskfs
6936                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
6937         done
6938 }
6939 test_129() {
6940         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return 0
6941         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6942
6943         EFBIG=27
6944         MAX=16384
6945
6946         set_dir_limits $MAX
6947
6948         mkdir -p $DIR/$tdir
6949
6950         I=0
6951         J=0
6952         while [ ! $I -gt $((MAX * MDSCOUNT)) ]; do
6953                 $MULTIOP $DIR/$tdir/$J Oc
6954                 rc=$?
6955                 if [ $rc -eq $EFBIG ]; then
6956                         set_dir_limits 0
6957                         echo "return code $rc received as expected"
6958                         return 0
6959                 elif [ $rc -ne 0 ]; then
6960                         set_dir_limits 0
6961                         error_exit "return code $rc received instead of expected $EFBIG"
6962                 fi
6963                 J=$((J+1))
6964                 I=$(stat -c%s "$DIR/$tdir")
6965         done
6966
6967         set_dir_limits 0
6968         error "exceeded dir size limit $MAX x $MDSCOUNT $((MAX * MDSCOUNT)) : $I bytes"
6969 }
6970 run_test 129 "test directory size limit ========================"
6971
6972 OLDIFS="$IFS"
6973 cleanup_130() {
6974         trap 0
6975         IFS="$OLDIFS"
6976 }
6977
6978 test_130a() {
6979         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
6980         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
6981
6982         trap cleanup_130 EXIT RETURN
6983
6984         local fm_file=$DIR/$tfile
6985         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
6986         dd if=/dev/zero of=$fm_file bs=65536 count=1 || error "dd failed for $fm_file"
6987
6988         filefrag -ves $fm_file || error "filefrag $fm_file failed"
6989         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
6990
6991         lun=$($GETSTRIPE -i $fm_file)
6992
6993         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
6994         IFS=$'\n'
6995         tot_len=0
6996         for line in $filefrag_op
6997         do
6998                 frag_lun=`echo $line | cut -d: -f5`
6999                 ext_len=`echo $line | cut -d: -f4`
7000                 if (( $frag_lun != $lun )); then
7001                         cleanup_130
7002                         error "FIEMAP on 1-stripe file($fm_file) failed"
7003                         return
7004                 fi
7005                 (( tot_len += ext_len ))
7006         done
7007
7008         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
7009                 cleanup_130
7010                 error "FIEMAP on 1-stripe file($fm_file) failed;"
7011                 return
7012         fi
7013
7014         cleanup_130
7015
7016         echo "FIEMAP on single striped file succeeded"
7017 }
7018 run_test 130a "FIEMAP (1-stripe file)"
7019
7020 test_130b() {
7021         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping FIEMAP on 2-stripe file test" && return
7022
7023         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7024         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7025
7026         trap cleanup_130 EXIT RETURN
7027
7028         local fm_file=$DIR/$tfile
7029         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7030         dd if=/dev/zero of=$fm_file bs=1M count=2 || error "dd failed on $fm_file"
7031
7032         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7033         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7034
7035         last_lun=`echo $filefrag_op | cut -d: -f5`
7036
7037         IFS=$'\n'
7038         tot_len=0
7039         num_luns=1
7040         for line in $filefrag_op
7041         do
7042                 frag_lun=`echo $line | cut -d: -f5`
7043                 ext_len=`echo $line | cut -d: -f4`
7044                 if (( $frag_lun != $last_lun )); then
7045                         if (( tot_len != 1024 )); then
7046                                 cleanup_130
7047                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
7048                                 return
7049                         else
7050                                 (( num_luns += 1 ))
7051                                 tot_len=0
7052                         fi
7053                 fi
7054                 (( tot_len += ext_len ))
7055                 last_lun=$frag_lun
7056         done
7057         if (( num_luns != 2 || tot_len != 1024 )); then
7058                 cleanup_130
7059                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7060                 return
7061         fi
7062
7063         cleanup_130
7064
7065         echo "FIEMAP on 2-stripe file succeeded"
7066 }
7067 run_test 130b "FIEMAP (2-stripe file)"
7068
7069 test_130c() {
7070         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping FIEMAP on 2-stripe file with hole test" && return
7071
7072         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7073         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7074
7075         trap cleanup_130 EXIT RETURN
7076
7077         local fm_file=$DIR/$tfile
7078         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7079         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
7080
7081         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7082         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7083
7084         last_lun=`echo $filefrag_op | cut -d: -f5`
7085
7086         IFS=$'\n'
7087         tot_len=0
7088         num_luns=1
7089         for line in $filefrag_op
7090         do
7091                 frag_lun=`echo $line | cut -d: -f5`
7092                 ext_len=`echo $line | cut -d: -f4`
7093                 if (( $frag_lun != $last_lun )); then
7094                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
7095                         if (( logical != 512 )); then
7096                                 cleanup_130
7097                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
7098                                 return
7099                         fi
7100                         if (( tot_len != 512 )); then
7101                                 cleanup_130
7102                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7103                                 return
7104                         else
7105                                 (( num_luns += 1 ))
7106                                 tot_len=0
7107                         fi
7108                 fi
7109                 (( tot_len += ext_len ))
7110                 last_lun=$frag_lun
7111         done
7112         if (( num_luns != 2 || tot_len != 512 )); then
7113                 cleanup_130
7114                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7115                 return
7116         fi
7117
7118         cleanup_130
7119
7120         echo "FIEMAP on 2-stripe file with hole succeeded"
7121 }
7122 run_test 130c "FIEMAP (2-stripe file with hole)"
7123
7124 test_130d() {
7125         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
7126
7127         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7128         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7129
7130         trap cleanup_130 EXIT RETURN
7131
7132         local fm_file=$DIR/$tfile
7133         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
7134         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
7135
7136         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7137         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7138
7139         last_lun=`echo $filefrag_op | cut -d: -f5`
7140
7141         IFS=$'\n'
7142         tot_len=0
7143         num_luns=1
7144         for line in $filefrag_op
7145         do
7146                 frag_lun=`echo $line | cut -d: -f5`
7147                 ext_len=`echo $line | cut -d: -f4`
7148                 if (( $frag_lun != $last_lun )); then
7149                         if (( tot_len != 1024 )); then
7150                                 cleanup_130
7151                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7152                                 return
7153                         else
7154                                 (( num_luns += 1 ))
7155                                 tot_len=0
7156                         fi
7157                 fi
7158                 (( tot_len += ext_len ))
7159                 last_lun=$frag_lun
7160         done
7161         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
7162                 cleanup_130
7163                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7164                 return
7165         fi
7166
7167         cleanup_130
7168
7169         echo "FIEMAP on N-stripe file succeeded"
7170 }
7171 run_test 130d "FIEMAP (N-stripe file)"
7172
7173 test_130e() {
7174         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
7175
7176         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7177         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7178
7179         trap cleanup_130 EXIT RETURN
7180
7181         local fm_file=$DIR/$tfile
7182         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
7183         NUM_BLKS=512
7184         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
7185         for ((i = 0; i < $NUM_BLKS; i++))
7186         do
7187                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
7188         done
7189
7190         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7191         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
7192
7193         last_lun=`echo $filefrag_op | cut -d: -f5`
7194
7195         IFS=$'\n'
7196         tot_len=0
7197         num_luns=1
7198         for line in $filefrag_op
7199         do
7200                 frag_lun=`echo $line | cut -d: -f5`
7201                 ext_len=`echo $line | cut -d: -f4`
7202                 if (( $frag_lun != $last_lun )); then
7203                         if (( tot_len != $EXPECTED_LEN )); then
7204                                 cleanup_130
7205                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
7206                                 return
7207                         else
7208                                 (( num_luns += 1 ))
7209                                 tot_len=0
7210                         fi
7211                 fi
7212                 (( tot_len += ext_len ))
7213                 last_lun=$frag_lun
7214         done
7215         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
7216                 cleanup_130
7217                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7218                 return
7219         fi
7220
7221         cleanup_130
7222
7223         echo "FIEMAP with continuation calls succeeded"
7224 }
7225 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
7226
7227 # Test for writev/readv
7228 test_131a() {
7229         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
7230         error "writev test failed"
7231         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
7232         error "readv failed"
7233         rm -f $DIR/$tfile
7234 }
7235 run_test 131a "test iov's crossing stripe boundary for writev/readv"
7236
7237 test_131b() {
7238         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
7239         error "append writev test failed"
7240         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
7241         error "append writev test failed"
7242         rm -f $DIR/$tfile
7243 }
7244 run_test 131b "test append writev"
7245
7246 test_131c() {
7247         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
7248         error "NOT PASS"
7249 }
7250 run_test 131c "test read/write on file w/o objects"
7251
7252 test_131d() {
7253         rwv -f $DIR/$tfile -w -n 1 1572864
7254         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
7255         if [ "$NOB" != 1572864 ]; then
7256                 error "Short read filed: read $NOB bytes instead of 1572864"
7257         fi
7258         rm -f $DIR/$tfile
7259 }
7260 run_test 131d "test short read"
7261
7262 test_131e() {
7263         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
7264         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
7265         error "read hitting hole failed"
7266         rm -f $DIR/$tfile
7267 }
7268 run_test 131e "test read hitting hole"
7269
7270 get_ost_param() {
7271         local token=$1
7272         local gl_sum=0
7273         for node in $(osts_nodes); do
7274                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
7275                 [ x$gl = x"" ] && gl=0
7276                 gl_sum=$((gl_sum + gl))
7277         done
7278         echo $gl
7279 }
7280
7281 som_mode_switch() {
7282         local som=$1
7283         local gl1=$2
7284         local gl2=$3
7285
7286         if [ x$som = x"enabled" ]; then
7287                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
7288                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
7289                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
7290         else
7291                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
7292                 MOUNTOPT="$MOUNTOPT,som_preview"
7293                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
7294         fi
7295
7296         # do remount to make new mount-conf parameters actual
7297         echo remounting...
7298         sync
7299         stopall
7300         setupall
7301 }
7302
7303 test_132() { #1028, SOM
7304         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7305         local num=$(get_mds_dir $DIR)
7306         local mymds=mds${num}
7307         local MOUNTOPT_SAVE=$MOUNTOPT
7308
7309         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
7310         cancel_lru_locks osc
7311
7312         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
7313
7314         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
7315         stat $DIR/$tfile >/dev/null
7316         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
7317         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
7318         rm $DIR/$tfile
7319         som_mode_switch $som1 $gl1 $gl2
7320
7321         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
7322         cancel_lru_locks osc
7323
7324         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
7325         if [ $som1 == $som2 ]; then
7326             error "som is still "$som2
7327             if [ x$som2 = x"enabled" ]; then
7328                 som2="disabled"
7329             else
7330                 som2="enabled"
7331             fi
7332         fi
7333
7334         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
7335         stat $DIR/$tfile >/dev/null
7336         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
7337         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
7338         som_mode_switch $som2 $gl1 $gl2
7339         MOUNTOPT=$MOUNTOPT_SAVE
7340 }
7341 run_test 132 "som avoids glimpse rpc"
7342
7343 check_stats() {
7344         local res
7345         local count
7346         case $1 in
7347         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
7348                  ;;
7349         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
7350                  ;;
7351         *) error "Wrong argument $1" ;;
7352         esac
7353         echo $res
7354         count=`echo $res | awk '{print $2}'`
7355         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
7356         # if the argument $3 is zero, it means any stat increment is ok.
7357         if [ $3 -gt 0 ] ; then
7358                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
7359         fi
7360 }
7361
7362 test_133a() {
7363         remote_ost_nodsh && skip "remote OST with nodsh" && return
7364         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7365
7366         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
7367                 { skip "MDS doesn't support rename stats"; return; }
7368         local testdir=$DIR/${tdir}/stats_testdir
7369         mkdir -p $DIR/${tdir}
7370
7371         # clear stats.
7372         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7373         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7374
7375         # verify mdt stats first.
7376         mkdir ${testdir} || error "mkdir failed"
7377         check_stats $SINGLEMDS "mkdir" 1
7378         touch ${testdir}/${tfile} || "touch failed"
7379         check_stats $SINGLEMDS "open" 1
7380         check_stats $SINGLEMDS "close" 1
7381         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
7382         check_stats $SINGLEMDS "mknod" 1
7383         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
7384         check_stats $SINGLEMDS "unlink" 1
7385         rm -f ${testdir}/${tfile} || error "file remove failed"
7386         check_stats $SINGLEMDS "unlink" 2
7387
7388         # remove working dir and check mdt stats again.
7389         rmdir ${testdir} || error "rmdir failed"
7390         check_stats $SINGLEMDS "rmdir" 1
7391
7392         local testdir1=$DIR/${tdir}/stats_testdir1
7393         mkdir -p ${testdir}
7394         mkdir -p ${testdir1}
7395         touch ${testdir1}/test1
7396         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
7397         check_stats $SINGLEMDS "crossdir_rename" 1
7398
7399         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
7400         check_stats $SINGLEMDS "samedir_rename" 1
7401
7402         rm -rf $DIR/${tdir}
7403 }
7404 run_test 133a "Verifying MDT stats ========================================"
7405
7406 test_133b() {
7407         remote_ost_nodsh && skip "remote OST with nodsh" && return
7408         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7409         local testdir=$DIR/${tdir}/stats_testdir
7410         mkdir -p ${testdir} || error "mkdir failed"
7411         touch ${testdir}/${tfile} || "touch failed"
7412         cancel_lru_locks mdc
7413
7414         # clear stats.
7415         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7416         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7417
7418         # extra mdt stats verification.
7419         chmod 444 ${testdir}/${tfile} || error "chmod failed"
7420         check_stats $SINGLEMDS "setattr" 1
7421         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7422         ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
7423         check_stats $SINGLEMDS "getattr" 1
7424         $LFS df || error "lfs failed"
7425         check_stats $SINGLEMDS "statfs" 1
7426
7427         rm -rf $DIR/${tdir}
7428 }
7429 run_test 133b "Verifying extra MDT stats =================================="
7430
7431 test_133c() {
7432         remote_ost_nodsh && skip "remote OST with nodsh" && return
7433         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7434         local testdir=$DIR/${tdir}/stats_testdir
7435         mkdir -p ${testdir} || error "mkdir failed"
7436
7437         # verify obdfilter stats.
7438         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
7439         sync
7440         cancel_lru_locks osc
7441
7442         # clear stats.
7443         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7444         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7445
7446         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
7447         sync
7448         cancel_lru_locks osc
7449         check_stats ost "write" 1
7450
7451         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
7452         check_stats ost "read" 1
7453
7454         > ${testdir}/${tfile} || error "truncate failed"
7455         check_stats ost "punch" 1
7456
7457         rm -f ${testdir}/${tfile} || error "file remove failed"
7458         check_stats ost "destroy" 1
7459
7460         rm -rf $DIR/${tdir}
7461 }
7462 run_test 133c "Verifying OST stats ========================================"
7463
7464 order_2() {
7465     local value=$1
7466     local orig=$value
7467     local order=1
7468
7469     while [ $value -ge 2 ]; do
7470         order=$((order*2))
7471         value=$((value/2))
7472     done
7473
7474     if [ $orig -gt $order ]; then
7475         order=$((order*2))
7476     fi
7477     echo $order
7478 }
7479
7480 size_in_KMGT() {
7481     local value=$1
7482     local size=('K' 'M' 'G' 'T');
7483     local i=0
7484     local size_string=$value
7485
7486     while [ $value -ge 1024 ]; do
7487         if [ $i -gt 3 ]; then
7488             #T is the biggest unit we get here, if that is bigger,
7489             #just return XXXT
7490             size_string=${value}T
7491             break
7492         fi
7493         value=$((value >> 10))
7494         if [ $value -lt 1024 ]; then
7495             size_string=${value}${size[$i]}
7496             break
7497         fi
7498         i=$((i + 1))
7499     done
7500
7501     echo $size_string
7502 }
7503
7504 get_rename_size() {
7505     local size=$1
7506     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
7507                    awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
7508     echo $sample
7509 }
7510
7511 test_133d() {
7512     remote_ost_nodsh && skip "remote OST with nodsh" && return
7513     remote_mds_nodsh && skip "remote MDS with nodsh" && return
7514     do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
7515         { skip "MDS doesn't support rename stats"; return; }
7516
7517     local testdir1=$DIR/${tdir}/stats_testdir1
7518     local testdir2=$DIR/${tdir}/stats_testdir2
7519
7520     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
7521
7522     mkdir -p ${testdir1} || error "mkdir failed"
7523     mkdir -p ${testdir2} || error "mkdir failed"
7524
7525     createmany -o $testdir1/test 512 || error "createmany failed"
7526     local testdir1_size=$(ls -l $DIR/${tdir} |
7527                           awk '/stats_testdir1/ {print $5}')
7528     local testdir2_size=$(ls -l $DIR/${tdir} |
7529                           awk '/stats_testdir2/ {print $5}')
7530
7531     testdir1_size=$(order_2 $testdir1_size)
7532     testdir2_size=$(order_2 $testdir2_size)
7533
7534     testdir1_size=$(size_in_KMGT $testdir1_size)
7535     testdir2_size=$(size_in_KMGT $testdir2_size)
7536
7537     echo "source rename dir size: ${testdir1_size}"
7538     echo "target rename dir size: ${testdir2_size}"
7539
7540     # check samedir rename size
7541     mv ${testdir1}/test0 ${testdir1}/test_0
7542     local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
7543     eval $cmd || error "$cmd failed"
7544     local samedir=$($cmd | grep 'same_dir')
7545     local same_sample=$(get_rename_size $testdir1_size)
7546     [ -z "$samedir" ] && error "samedir_rename_size count error"
7547     [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
7548     echo "Check same dir rename stats success"
7549
7550     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
7551
7552     # check crossdir rename size
7553     mv ${testdir1}/test_0 ${testdir2}/test_0
7554     eval $cmd || error "$cmd failed"
7555     local crossdir=$($cmd | grep 'crossdir')
7556     local src_sample=$(get_rename_size $testdir1_size)
7557     local tgt_sample=$(get_rename_size $testdir2_size)
7558     [ -z "$crossdir" ] && error "crossdir_rename_size count error"
7559     [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
7560     [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
7561     echo "Check cross dir rename stats success"
7562     rm -rf $DIR/${tdir}
7563 }
7564 run_test 133d "Verifying rename_stats ========================================"
7565
7566 test_140() { #bug-17379
7567         mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
7568         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
7569         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
7570
7571         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
7572         local i=0
7573         while i=`expr $i + 1`; do
7574                 mkdir -p $i || error "Creating dir $i"
7575                 cd $i || error "Changing to $i"
7576                 ln -s ../stat stat || error "Creating stat symlink"
7577                 # Read the symlink until ELOOP present,
7578                 # not LBUGing the system is considered success,
7579                 # we didn't overrun the stack.
7580                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
7581                 [ $ret -ne 0 ] && {
7582                         if [ $ret -eq 40 ]; then
7583                                 break  # -ELOOP
7584                         else
7585                                 error "Open stat symlink"
7586                                 return
7587                         fi
7588                 }
7589         done
7590         i=`expr $i - 1`
7591         echo "The symlink depth = $i"
7592         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 ] || error "Invalid symlink depth"
7593 }
7594 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
7595
7596 test_150() {
7597         local TF="$TMP/$tfile"
7598
7599         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
7600         cp $TF $DIR/$tfile
7601         cancel_lru_locks osc
7602         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
7603         remount_client $MOUNT
7604         df -P $MOUNT
7605         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
7606
7607         $TRUNCATE $TF 6000
7608         $TRUNCATE $DIR/$tfile 6000
7609         cancel_lru_locks osc
7610         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
7611
7612         echo "12345" >>$TF
7613         echo "12345" >>$DIR/$tfile
7614         cancel_lru_locks osc
7615         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
7616
7617         echo "12345" >>$TF
7618         echo "12345" >>$DIR/$tfile
7619         cancel_lru_locks osc
7620         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
7621
7622         rm -f $TF
7623         true
7624 }
7625 run_test 150 "truncate/append tests"
7626
7627 function roc_hit() {
7628     local list=$(comma_list $(osts_nodes))
7629
7630     ACCNUM=$(do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
7631         awk '/'cache_hit'/ {sum+=$2} END {print sum}')
7632     echo $ACCNUM
7633 }
7634
7635 function set_cache() {
7636     local on=1
7637
7638     if [ "$2" == "off" ]; then
7639         on=0;
7640     fi
7641     local list=$(comma_list $(osts_nodes))
7642     do_nodes $list lctl set_param obdfilter.*.${1}_cache_enable $on
7643
7644     cancel_lru_locks osc
7645 }
7646
7647 test_151() {
7648         remote_ost_nodsh && skip "remote OST with nodsh" && return
7649
7650         local CPAGES=3
7651         local list=$(comma_list $(osts_nodes))
7652
7653         # check whether obdfilter is cache capable at all
7654         if ! do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable > /dev/null; then
7655                 echo "not cache-capable obdfilter"
7656                 return 0
7657         fi
7658
7659         # check cache is enabled on all obdfilters
7660         if do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable | grep 0 >&/dev/null; then
7661                 echo "oss cache is disabled"
7662                 return 0
7663         fi
7664
7665         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable 1
7666
7667         # pages should be in the case right after write
7668         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
7669         local BEFORE=`roc_hit`
7670         cancel_lru_locks osc
7671         cat $DIR/$tfile >/dev/null
7672         local AFTER=`roc_hit`
7673         if ! let "AFTER - BEFORE == CPAGES"; then
7674                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7675         fi
7676
7677         # the following read invalidates the cache
7678         cancel_lru_locks osc
7679         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 0
7680         cat $DIR/$tfile >/dev/null
7681
7682         # now data shouldn't be found in the cache
7683         BEFORE=`roc_hit`
7684         cancel_lru_locks osc
7685         cat $DIR/$tfile >/dev/null
7686         AFTER=`roc_hit`
7687         if let "AFTER - BEFORE != 0"; then
7688                 error "IN CACHE: before: $BEFORE, after: $AFTER"
7689         fi
7690
7691         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 1
7692         rm -f $DIR/$tfile
7693 }
7694 run_test 151 "test cache on oss and controls ==============================="
7695
7696 test_152() {
7697         local TF="$TMP/$tfile"
7698
7699         # simulate ENOMEM during write
7700 #define OBD_FAIL_OST_NOMEM      0x226
7701         lctl set_param fail_loc=0x80000226
7702         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
7703         cp $TF $DIR/$tfile
7704         sync || error "sync failed"
7705         lctl set_param fail_loc=0
7706
7707         # discard client's cache
7708         cancel_lru_locks osc
7709
7710         # simulate ENOMEM during read
7711         lctl set_param fail_loc=0x80000226
7712         cmp $TF $DIR/$tfile || error "cmp failed"
7713         lctl set_param fail_loc=0
7714
7715         rm -f $TF
7716 }
7717 run_test 152 "test read/write with enomem ============================"
7718
7719 test_153() {
7720         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
7721 }
7722 run_test 153 "test if fdatasync does not crash ======================="
7723
7724 test_154() {
7725         cp /etc/hosts $DIR/$tfile
7726
7727         fid=$($LFS path2fid $DIR/$tfile)
7728         rc=$?
7729         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
7730
7731         ffid=$DIR/.lustre/fid/$fid
7732
7733         echo "stat fid $fid"
7734         stat $ffid > /dev/null || error "stat $ffid failed."
7735         echo "touch fid $fid"
7736         touch $ffid || error "touch $ffid failed."
7737         echo "write to fid $fid"
7738         cat /etc/hosts > $ffid || error "write $ffid failed."
7739         echo "read fid $fid"
7740         diff /etc/hosts $ffid || error "read $ffid failed."
7741         echo "append write to fid $fid"
7742         cat /etc/hosts >> $ffid || error "append write $ffid failed."
7743         echo "rename fid $fid"
7744         mv $ffid $DIR/$tfile.1 && error "rename $ffid to $tfile.1 should fail."
7745         touch $DIR/$tfile.1
7746         mv $DIR/$tfile.1 $ffid && error "rename $tfile.1 to $ffid should fail."
7747         rm -f $DIR/$tfile.1
7748         echo "truncate fid $fid"
7749         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
7750         echo "link fid $fid"
7751         ln -f $ffid $DIR/tfile.lnk || error "link $ffid failed."
7752         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
7753                 echo "setfacl fid $fid"
7754                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
7755                 echo "getfacl fid $fid"
7756                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
7757         fi
7758         echo "unlink fid $fid"
7759         unlink $DIR/.lustre/fid/$fid && error "unlink $ffid should fail."
7760         echo "mknod fid $fid"
7761         mknod $ffid c 1 3 && error "mknod $ffid should fail."
7762
7763         fid=[0xf00000400:0x1:0x0]
7764         ffid=$DIR/.lustre/fid/$fid
7765
7766         echo "stat non-exist fid $fid"
7767         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
7768         echo "write to non-exist fid $fid"
7769         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
7770         echo "link new fid $fid"
7771         ln $DIR/$tfile $ffid && error "link $ffid should fail."
7772
7773         mkdir -p $DIR/$tdir
7774         touch $DIR/$tdir/$tfile
7775         fid=$($LFS path2fid $DIR/$tdir)
7776         rc=$?
7777         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
7778
7779         ffid=$DIR/.lustre/fid/$fid
7780
7781         echo "ls $fid"
7782         ls $ffid > /dev/null || error "ls $ffid failed."
7783         echo "touch $fid/$tfile.1"
7784         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
7785
7786         echo "touch $DIR/.lustre/fid/$tfile"
7787         touch $DIR/.lustre/fid/$tfile && \
7788                 error "touch $DIR/.lustre/fid/$tfile should fail."
7789
7790         echo "Open-by-FID succeeded"
7791 }
7792 run_test 154 "Open-by-FID"
7793
7794 test_155_small_load() {
7795     local temp=$TMP/$tfile
7796     local file=$DIR/$tfile
7797
7798     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
7799         error "dd of=$temp bs=6096 count=1 failed"
7800     cp $temp $file
7801     cancel_lru_locks osc
7802     cmp $temp $file || error "$temp $file differ"
7803
7804     $TRUNCATE $temp 6000
7805     $TRUNCATE $file 6000
7806     cmp $temp $file || error "$temp $file differ (truncate1)"
7807
7808     echo "12345" >>$temp
7809     echo "12345" >>$file
7810     cmp $temp $file || error "$temp $file differ (append1)"
7811
7812     echo "12345" >>$temp
7813     echo "12345" >>$file
7814     cmp $temp $file || error "$temp $file differ (append2)"
7815
7816     rm -f $temp $file
7817     true
7818 }
7819
7820 test_155_big_load() {
7821     remote_ost_nodsh && skip "remote OST with nodsh" && return
7822     local temp=$TMP/$tfile
7823     local file=$DIR/$tfile
7824
7825     free_min_max
7826     local cache_size=$(do_facet ost$((MAXI+1)) \
7827         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
7828     local large_file_size=$((cache_size * 2))
7829
7830     echo "OSS cache size: $cache_size KB"
7831     echo "Large file size: $large_file_size KB"
7832
7833     [ $MAXV -le $large_file_size ] && \
7834         skip_env "max available OST size needs > $large_file_size KB" && \
7835         return 0
7836
7837     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
7838
7839     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
7840         error "dd of=$temp bs=$large_file_size count=1k failed"
7841     cp $temp $file
7842     ls -lh $temp $file
7843     cancel_lru_locks osc
7844     cmp $temp $file || error "$temp $file differ"
7845
7846     rm -f $temp $file
7847     true
7848 }
7849
7850 test_155a() {
7851     set_cache read on
7852     set_cache writethrough on
7853     test_155_small_load
7854 }
7855 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
7856
7857 test_155b() {
7858     set_cache read on
7859     set_cache writethrough off
7860     test_155_small_load
7861 }
7862 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
7863
7864 test_155c() {
7865     set_cache read off
7866     set_cache writethrough on
7867     test_155_small_load
7868 }
7869 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
7870
7871 test_155d() {
7872     set_cache read off
7873     set_cache writethrough off
7874     test_155_small_load
7875 }
7876 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
7877
7878 test_155e() {
7879     set_cache read on
7880     set_cache writethrough on
7881     test_155_big_load
7882 }
7883 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
7884
7885 test_155f() {
7886     set_cache read on
7887     set_cache writethrough off
7888     test_155_big_load
7889 }
7890 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
7891
7892 test_155g() {
7893     set_cache read off
7894     set_cache writethrough on
7895     test_155_big_load
7896 }
7897 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
7898
7899 test_155h() {
7900     set_cache read off
7901     set_cache writethrough off
7902     test_155_big_load
7903 }
7904 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
7905
7906 test_156() {
7907     local CPAGES=3
7908     local BEFORE
7909     local AFTER
7910     local file="$DIR/$tfile"
7911
7912     log "Turn on read and write cache"
7913     set_cache read on
7914     set_cache writethrough on
7915
7916     log "Write data and read it back."
7917     log "Read should be satisfied from the cache."
7918     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
7919     BEFORE=`roc_hit`
7920     cancel_lru_locks osc
7921     cat $file >/dev/null
7922     AFTER=`roc_hit`
7923     if ! let "AFTER - BEFORE == CPAGES"; then
7924         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7925     else
7926         log "cache hits:: before: $BEFORE, after: $AFTER"
7927     fi
7928
7929     log "Read again; it should be satisfied from the cache."
7930     BEFORE=$AFTER
7931     cancel_lru_locks osc
7932     cat $file >/dev/null
7933     AFTER=`roc_hit`
7934     if ! let "AFTER - BEFORE == CPAGES"; then
7935         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7936     else
7937         log "cache hits:: before: $BEFORE, after: $AFTER"
7938     fi
7939
7940
7941     log "Turn off the read cache and turn on the write cache"
7942     set_cache read off
7943     set_cache writethrough on
7944
7945     log "Read again; it should be satisfied from the cache."
7946     BEFORE=`roc_hit`
7947     cancel_lru_locks osc
7948     cat $file >/dev/null
7949     AFTER=`roc_hit`
7950     if ! let "AFTER - BEFORE == CPAGES"; then
7951         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7952     else
7953         log "cache hits:: before: $BEFORE, after: $AFTER"
7954     fi
7955
7956     log "Read again; it should not be satisfied from the cache."
7957     BEFORE=$AFTER
7958     cancel_lru_locks osc
7959     cat $file >/dev/null
7960     AFTER=`roc_hit`
7961     if ! let "AFTER - BEFORE == 0"; then
7962         error "IN CACHE: before: $BEFORE, after: $AFTER"
7963     else
7964         log "cache hits:: before: $BEFORE, after: $AFTER"
7965     fi
7966
7967     log "Write data and read it back."
7968     log "Read should be satisfied from the cache."
7969     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
7970     BEFORE=`roc_hit`
7971     cancel_lru_locks osc
7972     cat $file >/dev/null
7973     AFTER=`roc_hit`
7974     if ! let "AFTER - BEFORE == CPAGES"; then
7975         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7976     else
7977         log "cache hits:: before: $BEFORE, after: $AFTER"
7978     fi
7979
7980     log "Read again; it should not be satisfied from the cache."
7981     BEFORE=$AFTER
7982     cancel_lru_locks osc
7983     cat $file >/dev/null
7984     AFTER=`roc_hit`
7985     if ! let "AFTER - BEFORE == 0"; then
7986         error "IN CACHE: before: $BEFORE, after: $AFTER"
7987     else
7988         log "cache hits:: before: $BEFORE, after: $AFTER"
7989     fi
7990
7991
7992     log "Turn off read and write cache"
7993     set_cache read off
7994     set_cache writethrough off
7995
7996     log "Write data and read it back"
7997     log "It should not be satisfied from the cache."
7998     rm -f $file
7999     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8000     cancel_lru_locks osc
8001     BEFORE=`roc_hit`
8002     cat $file >/dev/null
8003     AFTER=`roc_hit`
8004     if ! let "AFTER - BEFORE == 0"; then
8005         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
8006     else
8007         log "cache hits:: before: $BEFORE, after: $AFTER"
8008     fi
8009
8010
8011     log "Turn on the read cache and turn off the write cache"
8012     set_cache read on
8013     set_cache writethrough off
8014
8015     log "Write data and read it back"
8016     log "It should not be satisfied from the cache."
8017     rm -f $file
8018     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8019     BEFORE=`roc_hit`
8020     cancel_lru_locks osc
8021     cat $file >/dev/null
8022     AFTER=`roc_hit`
8023     if ! let "AFTER - BEFORE == 0"; then
8024         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
8025     else
8026         log "cache hits:: before: $BEFORE, after: $AFTER"
8027     fi
8028
8029     log "Read again; it should be satisfied from the cache."
8030     BEFORE=`roc_hit`
8031     cancel_lru_locks osc
8032     cat $file >/dev/null
8033     AFTER=`roc_hit`
8034     if ! let "AFTER - BEFORE == CPAGES"; then
8035         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8036     else
8037         log "cache hits:: before: $BEFORE, after: $AFTER"
8038     fi
8039
8040     rm -f $file
8041 }
8042 run_test 156 "Verification of tunables ============================"
8043
8044 #Changelogs
8045 err17935 () {
8046     if [ $MDSCOUNT -gt 1 ]; then
8047         error_ignore 17935 $*
8048     else
8049         error $*
8050     fi
8051 }
8052
8053 changelog_chmask()
8054 {
8055     MASK=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_mask |\
8056            grep -c $1)
8057
8058     if [ $MASK -eq 1 ]; then
8059         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="-$1"
8060     else
8061         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="+$1"
8062     fi
8063 }
8064
8065 test_160() {
8066     remote_mds_nodsh && skip "remote MDS with nodsh" && return
8067     [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
8068         { skip "Need MDS version at least 2.2.0"; return; }
8069     USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
8070     echo "Registered as changelog user $USER"
8071     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
8072         grep -q $USER || error "User $USER not found in changelog_users"
8073
8074     # change something
8075     mkdir -p $DIR/$tdir/pics/2008/zachy
8076     touch $DIR/$tdir/pics/2008/zachy/timestamp
8077     cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
8078     mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
8079     ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
8080     ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
8081     rm $DIR/$tdir/pics/desktop.jpg
8082
8083     $LFS changelog $MDT0 | tail -5
8084
8085     echo "verifying changelog mask"
8086     changelog_chmask "MKDIR"
8087     changelog_chmask "CLOSE"
8088
8089     mkdir -p $DIR/$tdir/pics/zach/sofia
8090     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
8091
8092     changelog_chmask "MKDIR"
8093     changelog_chmask "CLOSE"
8094
8095     mkdir -p $DIR/$tdir/pics/2008/sofia
8096     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
8097
8098     $LFS changelog $MDT0
8099     MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
8100     CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
8101     [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
8102     [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
8103
8104     # verify contents
8105     echo "verifying target fid"
8106     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
8107         tail -1 | awk '{print $6}')
8108     fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
8109     [ "$fidc" == "t=$fidf" ] || \
8110         err17935 "fid in changelog $fidc != file fid $fidf"
8111     echo "verifying parent fid"
8112     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
8113         tail -1 | awk '{print $7}')
8114     fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
8115     [ "$fidc" == "p=$fidf" ] || \
8116         err17935 "pfid in changelog $fidc != dir fid $fidf"
8117
8118     USER_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
8119         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
8120     $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
8121     USER_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
8122         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
8123     echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
8124     [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \
8125         err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2"
8126
8127     MIN_REC=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_users | \
8128         awk 'min == "" || $2 < min {min = $2}; END {print min}')
8129     FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
8130     echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
8131     [ $FIRST_REC == $(($MIN_REC + 1)) ] || \
8132         err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC"
8133
8134     echo "verifying user deregister"
8135     do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
8136     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
8137         grep -q $USER && error "User $USER still found in changelog_users"
8138
8139     USERS=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
8140         mdd.$MDT0.changelog_users | wc -l) - 2 ))
8141     if [ $USERS -eq 0 ]; then
8142         LAST_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
8143             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
8144         touch $DIR/$tdir/chloe
8145         LAST_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
8146             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
8147         echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2"
8148         [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
8149     else
8150         echo "$USERS other changelog users; can't verify off"
8151     fi
8152 }
8153 run_test 160 "changelog sanity"
8154
8155 test_161() {
8156     mkdir -p $DIR/$tdir
8157     cp /etc/hosts $DIR/$tdir/$tfile
8158     mkdir $DIR/$tdir/foo1
8159     mkdir $DIR/$tdir/foo2
8160     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
8161     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
8162     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
8163     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
8164     local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[')
8165     if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
8166         $LFS fid2path $DIR $FID
8167         err17935 "bad link ea"
8168     fi
8169     # middle
8170     rm $DIR/$tdir/foo2/zachary
8171     # last
8172     rm $DIR/$tdir/foo2/thor
8173     # first
8174     rm $DIR/$tdir/$tfile
8175     # rename
8176     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
8177     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
8178         then
8179         $LFS fid2path $DIR $FID
8180         err17935 "bad link rename"
8181     fi
8182     rm $DIR/$tdir/foo2/maggie
8183
8184     # overflow the EA
8185     local longname=filename_avg_len_is_thirty_two_
8186     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
8187         error "failed to hardlink many files"
8188     links=$($LFS fid2path $DIR $FID | wc -l)
8189     echo -n "${links}/1000 links in link EA"
8190     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
8191     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
8192         error "failed to unlink many hardlinks"
8193 }
8194 run_test 161 "link ea sanity"
8195
8196 check_path() {
8197     local expected=$1
8198     shift
8199     local fid=$2
8200
8201     local path=$(${LFS} fid2path $*)
8202     RC=$?
8203
8204     if [ $RC -ne 0 ]; then
8205         err17935 "path looked up of $expected failed. Error $RC"
8206         return $RC
8207     elif [ "${path}" != "${expected}" ]; then
8208         err17935 "path looked up \"${path}\" instead of \"${expected}\""
8209         return 2
8210     fi
8211     echo "fid $fid resolves to path $path (expected $expected)"
8212 }
8213
8214 test_162() {
8215         # Make changes to filesystem
8216         mkdir -p $DIR/$tdir/d2
8217         touch $DIR/$tdir/d2/$tfile
8218         touch $DIR/$tdir/d2/x1
8219         touch $DIR/$tdir/d2/x2
8220         mkdir -p $DIR/$tdir/d2/a/b/c
8221         mkdir -p $DIR/$tdir/d2/p/q/r
8222         # regular file
8223         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
8224         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
8225
8226         # softlink
8227         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
8228         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
8229         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
8230
8231         # softlink to wrong file
8232         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
8233         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
8234         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
8235
8236         # hardlink
8237         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
8238         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
8239         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
8240         # fid2path dir/fsname should both work
8241         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
8242         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
8243
8244         # hardlink count: check that there are 2 links
8245         # Doesnt work with CMD yet: 17935
8246         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
8247                 err17935 "expected 2 links"
8248
8249         # hardlink indexing: remove the first link
8250         rm $DIR/$tdir/d2/p/q/r/hlink
8251         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
8252
8253         return 0
8254 }
8255 run_test 162 "path lookup sanity"
8256
8257 test_163() {
8258         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8259         copytool --test $FSNAME || { skip "copytool not runnable: $?" && return; }
8260         copytool $FSNAME &
8261         sleep 1
8262         local uuid=$($LCTL get_param -n mdc.${FSNAME}-MDT0000-mdc-*.uuid)
8263         # this proc file is temporary and linux-only
8264         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT0000.mdccomm=$uuid ||\
8265          error "kernel->userspace send failed"
8266         kill -INT $!
8267 }
8268 run_test 163 "kernel <-> userspace comms"
8269
8270 test_169() {
8271         # do directio so as not to populate the page cache
8272         log "creating a 10 Mb file"
8273         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
8274         log "starting reads"
8275         dd if=$DIR/$tfile of=/dev/null bs=4096 &
8276         log "truncating the file"
8277         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
8278         log "killing dd"
8279         kill %+ || true # reads might have finished
8280         echo "wait until dd is finished"
8281         wait
8282         log "removing the temporary file"
8283         rm -rf $DIR/$tfile || error "tmp file removal failed"
8284 }
8285 run_test 169 "parallel read and truncate should not deadlock"
8286
8287 test_170() {
8288         $LCTL clear     # bug 18514
8289         $LCTL debug_daemon start $TMP/${tfile}_log_good
8290         touch $DIR/$tfile
8291         $LCTL debug_daemon stop
8292         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
8293                error "sed failed to read log_good"
8294
8295         $LCTL debug_daemon start $TMP/${tfile}_log_good
8296         rm -rf $DIR/$tfile
8297         $LCTL debug_daemon stop
8298
8299         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
8300                error "lctl df log_bad failed"
8301
8302         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
8303         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
8304
8305         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
8306         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
8307
8308         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
8309                 error "bad_line good_line1 good_line2 are empty"
8310
8311         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
8312         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
8313         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
8314
8315         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
8316         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
8317         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
8318
8319         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
8320                 error "bad_line_new good_line_new are empty"
8321
8322         local expected_good=$((good_line1 + good_line2*2))
8323
8324         rm -f $TMP/${tfile}*
8325         # LU-231, short malformed line may not be counted into bad lines
8326         if [ $bad_line -ne $bad_line_new ] &&
8327                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
8328                 error "expected $bad_line bad lines, but got $bad_line_new"
8329                 return 1
8330         fi
8331
8332         if [ $expected_good -ne $good_line_new ]; then
8333                 error "expected $expected_good good lines, but got $good_line_new"
8334                 return 2
8335         fi
8336         true
8337 }
8338 run_test 170 "test lctl df to handle corrupted log ====================="
8339
8340 test_171() { # bug20592
8341 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
8342         $LCTL set_param fail_loc=0x50e
8343         $LCTL set_param fail_val=3000
8344         multiop_bg_pause $DIR/$tfile O_s || true
8345         local MULTIPID=$!
8346         kill -USR1 $MULTIPID
8347         # cause log dump
8348         sleep 3
8349         wait $MULTIPID
8350         if dmesg | grep "recursive fault"; then
8351                 error "caught a recursive fault"
8352         fi
8353         $LCTL set_param fail_loc=0
8354         true
8355 }
8356 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
8357
8358 # it would be good to share it with obdfilter-survey/libecho code
8359 setup_obdecho_osc () {
8360         local rc=0
8361         local ost_nid=$1
8362         local obdfilter_name=$2
8363         echo "Creating new osc for $obdfilter_name on $ost_nid"
8364         # make sure we can find loopback nid
8365         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
8366
8367         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
8368                            ${obdfilter_name}_osc_UUID || rc=2; }
8369         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
8370                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
8371         return $rc
8372 }
8373
8374 cleanup_obdecho_osc () {
8375         local obdfilter_name=$1
8376         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
8377         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
8378         return 0
8379 }
8380
8381 obdecho_create_test() {
8382         local OBD=$1
8383         local node=$2
8384         local rc=0
8385         local id
8386         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
8387         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
8388                            rc=2; }
8389         if [ $rc -eq 0 ]; then
8390             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
8391             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
8392         fi
8393         echo "New object id is $id"
8394         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec test_brw 10 w v 64 $id" ||
8395                            rc=4; }
8396         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
8397                                         "cleanup" || rc=5; }
8398         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
8399                                         "detach" || rc=6; }
8400         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
8401         return $rc
8402 }
8403
8404 test_180a() {
8405         remote_ost_nodsh && skip "remote OST with nodsh" && return
8406         local rc=0
8407         local rmmod_local=0
8408
8409         if ! module_loaded obdecho; then
8410             load_module obdecho/obdecho
8411             rmmod_local=1
8412         fi
8413
8414         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
8415         local host=$(lctl get_param -n osc.$osc.import |
8416                              awk '/current_connection:/ {print $2}' )
8417         local target=$(lctl get_param -n osc.$osc.import |
8418                              awk '/target:/ {print $2}' )
8419         target=${target%_UUID}
8420
8421         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
8422         [ $rc -eq 0 ] && { obdecho_create_test ${target}_osc client || rc=2; }
8423         [[ -n $target ]] && cleanup_obdecho_osc $target
8424         [ $rmmod_local -eq 1 ] && rmmod obdecho
8425         return $rc
8426 }
8427 run_test 180a "test obdecho on osc"
8428
8429 test_180b() {
8430         remote_ost_nodsh && skip "remote OST with nodsh" && return
8431         local rc=0
8432         local rmmod_remote=0
8433
8434         do_facet ost1 "lsmod | grep -q obdecho || "                      \
8435                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
8436                       "modprobe obdecho; }" && rmmod_remote=1
8437         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
8438         [[ -n $target ]] && { obdecho_create_test $target ost1 || rc=1; }
8439         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
8440         return $rc
8441 }
8442 run_test 180b "test obdecho directly on obdfilter"
8443
8444 test_181() { # bug 22177
8445         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
8446         # create enough files to index the directory
8447         createmany -o $DIR/$tdir/foobar 4000
8448         # print attributes for debug purpose
8449         lsattr -d .
8450         # open dir
8451         multiop_bg_pause $DIR/$tdir D_Sc || return 1
8452         MULTIPID=$!
8453         # remove the files & current working dir
8454         unlinkmany $DIR/$tdir/foobar 4000
8455         rmdir $DIR/$tdir
8456         kill -USR1 $MULTIPID
8457         wait $MULTIPID
8458         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
8459         return 0
8460 }
8461 run_test 181 "Test open-unlinked dir ========================"
8462
8463 test_182() {
8464         # disable MDC RPC lock wouldn't crash client
8465         local fcount=1000
8466         local tcount=4
8467
8468         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
8469 #define OBD_FAIL_MDC_RPCS_SEM           0x804
8470         $LCTL set_param fail_loc=0x804
8471
8472         for (( i=0; i < $tcount; i++ )) ; do
8473                 mkdir $DIR/$tdir/$i
8474                 createmany -o $DIR/$tdir/$i/f- $fcount &
8475         done
8476         wait
8477
8478         for (( i=0; i < $tcount; i++ )) ; do
8479                 unlinkmany $DIR/$tdir/$i/f- $fcount &
8480         done
8481         wait
8482
8483         rm -rf $DIR/$tdir
8484
8485         $LCTL set_param fail_loc=0
8486 }
8487 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
8488
8489 # OST pools tests
8490 POOL=${POOL:-cea1}
8491 TGT_COUNT=$OSTCOUNT
8492 TGTPOOL_FIRST=1
8493 TGTPOOL_MAX=$(($TGT_COUNT - 1))
8494 TGTPOOL_STEP=2
8495 TGTPOOL_LIST=`seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`
8496 POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
8497 POOL_DIR_NAME=dir_tst
8498 POOL_DIR=$POOL_ROOT/$POOL_DIR_NAME
8499 POOL_FILE=$POOL_ROOT/file_tst
8500
8501 check_file_in_pool()
8502 {
8503         file=$1
8504         res=$($GETSTRIPE $file | grep 0x | cut -f2)
8505         for i in $res
8506         do
8507                 found=$(echo :$TGTPOOL_LIST: | tr " " ":"  | grep :$i:)
8508                 if [[ "$found" == "" ]]
8509                 then
8510                         echo "pool list: $TGTPOOL_LIST"
8511                         echo "striping: $res"
8512                         error "$file not allocated in $POOL"
8513                         return 1
8514                 fi
8515         done
8516         return 0
8517 }
8518
8519 trap "cleanup_pools $FSNAME" EXIT
8520
8521 test_200a() {
8522         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8523     create_pool $FSNAME.$POOL || return $?
8524         [ $($LFS pool_list $FSNAME | grep -c $POOL) -eq 1 ] ||
8525                 error "$POOL not in lfs pool_list"
8526 }
8527 run_test 200a "Create new pool =========================================="
8528
8529 test_200b() {
8530         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8531         TGT=$(for i in $TGTPOOL_LIST; do printf "$FSNAME-OST%04x_UUID " $i; done)
8532         do_facet mgs $LCTL pool_add $FSNAME.$POOL \
8533                 $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]
8534         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | sort -u | tr '\n' ' ' " "$TGT" ||
8535                 error "Add to pool failed"
8536         local lfscount=$($LFS pool_list $FSNAME.$POOL | grep -c "\-OST")
8537         local addcount=$((($TGTPOOL_MAX - $TGTPOOL_FIRST) / $TGTPOOL_STEP + 1))
8538         [ $lfscount -eq $addcount ] ||
8539                 error "lfs pool_list bad ost count $lfscount != $addcount"
8540 }
8541 run_test 200b "Add targets to a pool ===================================="
8542
8543 test_200c() {
8544         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8545         mkdir -p $POOL_DIR
8546         $SETSTRIPE -c 2 -p $POOL $POOL_DIR
8547         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
8548         # b-19919 test relative path works well
8549         mkdir -p $POOL_DIR/$POOL_DIR_NAME
8550         cd $POOL_DIR
8551         $SETSTRIPE -c 2 -p $POOL $POOL_DIR_NAME
8552         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/$POOL_DIR_NAME"
8553         $SETSTRIPE -c 2 -p $POOL ./$POOL_DIR_NAME
8554         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/./$POOL_DIR_NAME"
8555         $SETSTRIPE -c 2 -p $POOL ../$POOL_DIR_NAME
8556         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/../$POOL_DIR_NAME"
8557         $SETSTRIPE -c 2 -p $POOL ../$POOL_DIR_NAME/$POOL_DIR_NAME
8558         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR/../$POOL_DIR_NAME/$POOL_DIR_NAME"
8559         rm -rf $POOL_DIR_NAME; cd -
8560 }
8561 run_test 200c "Set pool on a directory ================================="
8562
8563 test_200d() {
8564         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8565         res=$($GETSTRIPE --pool $POOL_DIR)
8566         [ $res = $POOL ] || error "Pool on $POOL_DIR is $res, not $POOL"
8567 }
8568 run_test 200d "Check pool on a directory ==============================="
8569
8570 test_200e() {
8571         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8572         failed=0
8573         for i in $(seq -w 1 $(($TGT_COUNT * 3)))
8574         do
8575                 file=$POOL_DIR/file-$i
8576                 touch $file
8577                 check_file_in_pool $file
8578                 if [[ $? != 0 ]]
8579                 then
8580                         failed=$(($failed + 1))
8581                 fi
8582         done
8583         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
8584 }
8585 run_test 200e "Check files allocation from directory pool =============="
8586
8587 test_200f() {
8588         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8589         mkdir -p $POOL_FILE
8590         failed=0
8591         for i in $(seq -w 1 $(($TGT_COUNT * 3)))
8592         do
8593                 file=$POOL_FILE/spoo-$i
8594                 $SETSTRIPE -p $POOL $file
8595                 check_file_in_pool $file
8596                 if [[ $? != 0 ]]
8597                 then
8598                         failed=$(($failed + 1))
8599                 fi
8600         done
8601         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
8602 }
8603 run_test 200f "Create files in a pool ==================================="
8604
8605 test_200g() {
8606         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8607         TGT=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$POOL | tr '\n' ' ')
8608         res=$($LFS df --pool $FSNAME.$POOL | awk '{print $1}' | grep "$FSNAME-OST" | tr '\n' ' ')
8609         [ "$res" = "$TGT" ] || error "Pools OSTs '$TGT' is not '$res' that lfs df reports"
8610 }
8611 run_test 200g "lfs df a pool ============================================"
8612
8613 test_200h() { # b=24039
8614         mkdir -p $POOL_DIR || error "unable to create $POOL_DIR"
8615
8616         local file="/..$POOL_DIR/$tfile-1"
8617         $SETSTRIPE -p $POOL $file || error "unable to create $file"
8618
8619         cd $POOL_DIR
8620         $SETSTRIPE -p $POOL $tfile-2 || \
8621                 error "unable to create $tfile-2 in $POOL_DIR"
8622 }
8623 run_test 200h "Create files in a pool with relative pathname ============"
8624
8625 test_201a() {
8626         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8627         TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
8628         do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
8629         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | grep $TGT" "" ||
8630                 error "$TGT not removed from $FSNAME.$POOL"
8631 }
8632 run_test 201a "Remove a target from a pool ============================="
8633
8634 test_201b() {
8635         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8636         for TGT in $($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | sort -u)
8637         do
8638                 do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
8639         done
8640         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL" "" ||
8641                 error "Pool $FSNAME.$POOL cannot be drained"
8642         # striping on an empty/nonexistant pool should fall back to "pool of everything"
8643         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for empty pool"
8644         # setstripe on an empty pool should fail
8645         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
8646                 error "expected failure when creating file with empty pool"
8647         return 0
8648 }
8649 run_test 201b "Remove all targets from a pool =========================="
8650
8651 test_201c() {
8652         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8653         do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
8654
8655         sleep 2
8656     # striping on an empty/nonexistant pool should fall back to "pool of everything"
8657         touch ${POOL_DIR}/$tfile || error "failed to use fallback striping for missing pool"
8658         # setstripe on an empty pool should fail
8659         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile 2>/dev/null && \
8660                 error "expected failure when creating file with missing pool"
8661
8662         # get param should return err once pool is gone
8663         if wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null ||
8664                         echo foo" "foo"; then
8665                 remove_pool_from_list $FSNAME.$POOL
8666                 return 0
8667         fi
8668         error "Pool $FSNAME.$POOL is not destroyed"
8669 }
8670 run_test 201c "Remove a pool ============================================"
8671
8672 cleanup_pools $FSNAME
8673
8674 # usage: default_attr <count | size | offset>
8675 default_attr() {
8676         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
8677 }
8678
8679 # usage: check_default_stripe_attr
8680 check_default_stripe_attr() {
8681         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
8682         case $1 in
8683         --stripe-count|--count)
8684                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
8685         --stripe-size|--size)
8686                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
8687         --stripe-index|--index)
8688                 EXPECTED=-1;;
8689         *)
8690                 error "unknown getstripe attr '$1'"
8691         esac
8692
8693         [ $ACTUAL != $EXPECTED ] &&
8694                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
8695 }
8696
8697 test_204a() {
8698         mkdir -p $DIR/$tdir
8699         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
8700
8701         check_default_stripe_attr --stripe-count
8702         check_default_stripe_attr --stripe-size
8703         check_default_stripe_attr --stripe-index
8704
8705         return 0
8706 }
8707 run_test 204a "Print default stripe attributes ================="
8708
8709 test_204b() {
8710         mkdir -p $DIR/$tdir
8711         $SETSTRIPE --stripe-count 1 $DIR/$tdir
8712
8713         check_default_stripe_attr --stripe-size
8714         check_default_stripe_attr --stripe-index
8715
8716         return 0
8717 }
8718 run_test 204b "Print default stripe size and offset  ==========="
8719
8720 test_204c() {
8721         mkdir -p $DIR/$tdir
8722         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
8723
8724         check_default_stripe_attr --stripe-count
8725         check_default_stripe_attr --stripe-index
8726
8727         return 0
8728 }
8729 run_test 204c "Print default stripe count and offset ==========="
8730
8731 test_204d() {
8732         mkdir -p $DIR/$tdir
8733         $SETSTRIPE --stripe-index 0 $DIR/$tdir
8734
8735         check_default_stripe_attr --stripe-count
8736         check_default_stripe_attr --stripe-size
8737
8738         return 0
8739 }
8740 run_test 204d "Print default stripe count and size ============="
8741
8742 test_204e() {
8743         mkdir -p $DIR/$tdir
8744         $SETSTRIPE -d $DIR/$tdir
8745
8746         check_default_stripe_attr --stripe-count --raw
8747         check_default_stripe_attr --stripe-size --raw
8748         check_default_stripe_attr --stripe-index --raw
8749
8750         return 0
8751 }
8752 run_test 204e "Print raw stripe attributes ================="
8753
8754 test_204f() {
8755         mkdir -p $DIR/$tdir
8756         $SETSTRIPE --stripe-count 1 $DIR/$tdir
8757
8758         check_default_stripe_attr --stripe-size --raw
8759         check_default_stripe_attr --stripe-index --raw
8760
8761         return 0
8762 }
8763 run_test 204f "Print raw stripe size and offset  ==========="
8764
8765 test_204g() {
8766         mkdir -p $DIR/$tdir
8767         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
8768
8769         check_default_stripe_attr --stripe-count --raw
8770         check_default_stripe_attr --stripe-index --raw
8771
8772         return 0
8773 }
8774 run_test 204g "Print raw stripe count and offset ==========="
8775
8776 test_204h() {
8777         mkdir -p $DIR/$tdir
8778         $SETSTRIPE --stripe-index 0 $DIR/$tdir
8779
8780         check_default_stripe_attr --stripe-count --raw
8781         check_default_stripe_attr --stripe-size --raw
8782
8783         return 0
8784 }
8785 run_test 204h "Print raw stripe count and size ============="
8786
8787 # Figure out which job scheduler is being used, if any,
8788 # or use a fake one
8789 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
8790         JOBENV=SLURM_JOB_ID
8791 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
8792         JOBENV=LSB_JOBID
8793 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
8794         JOBENV=PBS_JOBID
8795 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
8796         JOBENV=LOADL_STEP_ID
8797 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
8798         JOBENV=JOB_ID
8799 else
8800         JOBENV=FAKE_JOBID
8801 fi
8802
8803 verify_jobstats() {
8804         local cmd=$1
8805         local target=$2
8806
8807         # clear old jobstats
8808         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
8809         do_facet ost0 lctl set_param obdfilter.*.job_stats="clear"
8810
8811         # use a new JobID for this test, or we might see an old one
8812         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
8813
8814         JOBVAL=${!JOBENV}
8815         log "Test: $cmd"
8816         log "Using JobID environment variable $JOBENV=$JOBVAL"
8817
8818         if [ $JOBENV = "FAKE_JOBID" ]; then
8819                 FAKE_JOBID=$JOBVAL $cmd
8820         else
8821                 $cmd
8822         fi
8823
8824         if [ "$target" = "mdt" -o "$target" = "both" ]; then
8825                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
8826                 do_facet $FACET lctl get_param mdt.*.job_stats |
8827                         grep $JOBVAL || error "No job stats found on MDT $FACET"
8828         fi
8829         if [ "$target" = "ost" -o "$target" = "both" ]; then
8830                 FACET=ost0
8831                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
8832                         grep $JOBVAL || error "No job stats found on OST $FACET"
8833         fi
8834 }
8835
8836 test_205() { # Job stats
8837         local cmd
8838         OLD_JOBENV=`$LCTL get_param -n jobid_var`
8839         if [ $OLD_JOBENV != $JOBENV ]; then
8840                 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$JOBENV
8841                 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
8842                         $JOBENV || return 1
8843         fi
8844
8845         # mkdir
8846         cmd="mkdir $DIR/$tfile"
8847         verify_jobstats "$cmd" "mdt"
8848         # rmdir
8849         cmd="rm -fr $DIR/$tfile"
8850         verify_jobstats "$cmd" "mdt"
8851         # mknod
8852         cmd="mknod $DIR/$tfile c 1 3"
8853         verify_jobstats "$cmd" "mdt"
8854         # unlink
8855         cmd="rm -f $DIR/$tfile"
8856         verify_jobstats "$cmd" "mdt"
8857         # open & close
8858         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
8859         verify_jobstats "$cmd" "mdt"
8860         # setattr
8861         cmd="touch $DIR/$tfile"
8862         verify_jobstats "$cmd" "both"
8863         # write
8864         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
8865         verify_jobstats "$cmd" "ost"
8866         # read
8867         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
8868         verify_jobstats "$cmd" "ost"
8869         # truncate
8870         cmd="$TRUNCATE $DIR/$tfile 0"
8871         verify_jobstats "$cmd" "both"
8872         # rename
8873         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
8874         verify_jobstats "$cmd" "mdt"
8875
8876         # cleanup
8877         rm -f $DIR/jobstats_test_rename
8878
8879         if [ $OLD_JOBENV != $JOBENV ]; then
8880                 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$OLD_JOBENV
8881                 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
8882                         $OLD_JOBENV || return 1
8883         fi
8884 }
8885 run_test 205 "Verify job stats"
8886
8887 test_212() {
8888         size=`date +%s`
8889         size=$((size % 8192 + 1))
8890         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
8891         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
8892         rm -f $DIR/f212 $DIR/f212.xyz
8893 }
8894 run_test 212 "Sendfile test ============================================"
8895
8896 test_213() {
8897         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
8898         cancel_lru_locks osc
8899         lctl set_param fail_loc=0x8000040f
8900         # generate a read lock
8901         cat $DIR/$tfile > /dev/null
8902         # write to the file, it will try to cancel the above read lock.
8903         cat /etc/hosts >> $DIR/$tfile
8904 }
8905 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
8906
8907 test_214() { # for bug 20133
8908         mkdir -p $DIR/d214p/d214c
8909         for (( i=0; i < 340; i++ )) ; do
8910                 touch $DIR/d214p/d214c/a$i
8911         done
8912
8913         ls -l $DIR/d214p || error "ls -l $DIR/d214p failed"
8914         mv $DIR/d214p/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
8915         ls $DIR/d214c || error "ls $DIR/d214c failed"
8916         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
8917 }
8918 run_test 214 "hash-indexed directory test - bug 20133"
8919
8920 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
8921 create_lnet_proc_files() {
8922         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
8923         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
8924
8925         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
8926         rm -f "$TMP/lnet_$1.sys_tmp"
8927 }
8928
8929 # counterpart of create_lnet_proc_files
8930 remove_lnet_proc_files() {
8931         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
8932 }
8933
8934 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
8935 # 3rd arg as regexp for body
8936 check_lnet_proc_stats() {
8937         local l=$(cat "$TMP/lnet_$1" |wc -l)
8938         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
8939
8940         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
8941 }
8942
8943 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
8944 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
8945 # optional and can be regexp for 2nd line (lnet.routes case)
8946 check_lnet_proc_entry() {
8947         local blp=2            # blp stands for 'position of 1st line of body'
8948         [ "$5" = "" ] || blp=3 # lnet.routes case
8949
8950         local l=$(cat "$TMP/lnet_$1" |wc -l)
8951         # subtracting one from $blp because the body can be empty
8952         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
8953
8954         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
8955                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
8956
8957         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
8958                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
8959
8960         # bail out if any unexpected line happened
8961         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
8962         [ "$?" != 0 ] || error "$2 misformatted"
8963 }
8964
8965 test_215() { # for bugs 18102, 21079, 21517
8966         local N='(0|[1-9][0-9]*)'       # non-negative numeric
8967         local P='[1-9][0-9]*'           # positive numeric
8968         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
8969         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
8970         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
8971         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
8972
8973         local L1 # regexp for 1st line
8974         local L2 # regexp for 2nd line (optional)
8975         local BR # regexp for the rest (body)
8976
8977         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
8978         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
8979         create_lnet_proc_files "stats"
8980         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
8981         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
8982         remove_lnet_proc_files "stats"
8983
8984         # /proc/sys/lnet/routes should look like this:
8985         # Routing disabled/enabled
8986         # net hops state router
8987         # where net is a string like tcp0, hops >= 0, state is up/down,
8988         # router is a string like 192.168.1.1@tcp2
8989         L1="^Routing (disabled|enabled)$"
8990         L2="^net +hops +state +router$"
8991         BR="^$NET +$N +(up|down) +$NID$"
8992         create_lnet_proc_files "routes"
8993         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
8994         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
8995         remove_lnet_proc_files "routes"
8996
8997         # /proc/sys/lnet/routers should look like this:
8998         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
8999         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
9000         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
9001         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
9002         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
9003         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
9004         create_lnet_proc_files "routers"
9005         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
9006         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
9007         remove_lnet_proc_files "routers"
9008
9009         # /proc/sys/lnet/peers should look like this:
9010         # nid refs state last max rtr min tx min queue
9011         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
9012         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
9013         # numeric (0 or >0 or <0), queue >= 0.
9014         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
9015         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
9016         create_lnet_proc_files "peers"
9017         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
9018         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
9019         remove_lnet_proc_files "peers"
9020
9021         # /proc/sys/lnet/buffers  should look like this:
9022         # pages count credits min
9023         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
9024         L1="^pages +count +credits +min$"
9025         BR="^ +$N +$N +$I +$I$"
9026         create_lnet_proc_files "buffers"
9027         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
9028         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
9029         remove_lnet_proc_files "buffers"
9030
9031         # /proc/sys/lnet/nis should look like this:
9032         # nid status alive refs peer rtr max tx min
9033         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
9034         # alive is numeric (0 or >0 or <0), refs > 0, peer >= 0,
9035         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
9036         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
9037         BR="^$NID +(up|down) +$I +$P +$N +$N +$N +$I +$I$"
9038         create_lnet_proc_files "nis"
9039         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
9040         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
9041         remove_lnet_proc_files "nis"
9042
9043         # can we successfully write to /proc/sys/lnet/stats?
9044         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
9045         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
9046 }
9047 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
9048
9049 test_216() { # bug 20317
9050         remote_ost_nodsh && skip "remote OST with nodsh" && return
9051         local node
9052         local p="$TMP/sanityN-$TESTNAME.parameters"
9053         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
9054         for node in $(osts_nodes); do
9055                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
9056                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
9057                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
9058         done
9059         clear_osc_stats
9060
9061         # agressive lockless i/o settings
9062         for node in $(osts_nodes); do
9063                 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'
9064         done
9065         lctl set_param -n osc.*.contention_seconds 60
9066
9067         $DIRECTIO write $DIR/$tfile 0 10 4096
9068         $CHECKSTAT -s 40960 $DIR/$tfile
9069
9070         # disable lockless i/o
9071         for node in $(osts_nodes); do
9072                 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'
9073         done
9074         lctl set_param -n osc.*.contention_seconds 0
9075         clear_osc_stats
9076
9077         dd if=/dev/zero of=$DIR/$tfile count=0
9078         $CHECKSTAT -s 0 $DIR/$tfile
9079
9080         restore_lustre_params <$p
9081         rm -f $p
9082         rm $DIR/$tfile
9083 }
9084 run_test 216 "check lockless direct write works and updates file size and kms correctly"
9085
9086 test_217() { # bug 22430
9087         local node
9088         local nid
9089
9090         for node in $(nodes_list); do
9091                 nid=$(host_nids_address $node $NETTYPE)
9092                 if [[ $nid = *-* ]] ; then
9093                         echo "lctl ping $nid@$NETTYPE"
9094                         lctl ping $nid@$NETTYPE
9095                 else
9096                         echo "skipping $node (no hyphen detected)"
9097                 fi
9098         done
9099 }
9100 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
9101
9102 test_218() {
9103        # do directio so as not to populate the page cache
9104        log "creating a 10 Mb file"
9105        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
9106        log "starting reads"
9107        dd if=$DIR/$tfile of=/dev/null bs=4096 &
9108        log "truncating the file"
9109        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
9110        log "killing dd"
9111        kill %+ || true # reads might have finished
9112        echo "wait until dd is finished"
9113        wait
9114        log "removing the temporary file"
9115        rm -rf $DIR/$tfile || error "tmp file removal failed"
9116 }
9117 run_test 218 "parallel read and truncate should not deadlock ======================="
9118
9119 test_219() {
9120         # write one partial page
9121         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
9122         # set no grant so vvp_io_commit_write will do sync write
9123         $LCTL set_param fail_loc=0x411
9124         # write a full page at the end of file
9125         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
9126
9127         $LCTL set_param fail_loc=0
9128         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
9129         $LCTL set_param fail_loc=0x411
9130         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
9131 }
9132 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
9133
9134 test_220() { #LU-325
9135         remote_ost_nodsh && skip "remote OST with nodsh" && return
9136         local OSTIDX=0
9137
9138         mkdir -p $DIR/$tdir
9139         local OST=$(lfs osts | grep ${OSTIDX}": " | \
9140                 awk '{print $2}' | sed -e 's/_UUID$//')
9141
9142         # on the mdt's osc
9143         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
9144         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
9145                         osc.$mdtosc_proc1.prealloc_last_id)
9146         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
9147                         osc.$mdtosc_proc1.prealloc_next_id)
9148
9149         $LFS df -i
9150
9151         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
9152         #define OBD_FAIL_OST_ENOINO              0x229
9153         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
9154         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
9155         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
9156
9157         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
9158
9159         MDSOBJS=$((last_id - next_id))
9160         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
9161
9162         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
9163         echo "OST still has $count kbytes free"
9164
9165         echo "create $MDSOBJS files @next_id..."
9166         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
9167
9168         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
9169                         osc.$mdtosc_proc1.prealloc_last_id)
9170         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
9171                         osc.$mdtosc_proc1.prealloc_next_id)
9172
9173         echo "after creation, last_id=$last_id2, next_id=$next_id2"
9174         $LFS df -i
9175
9176         echo "cleanup..."
9177
9178         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
9179         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
9180
9181         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
9182         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
9183         echo "unlink $MDSOBJS files @$next_id..."
9184         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
9185 }
9186 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
9187
9188 test_221() {
9189         dd if=`which date` of=$MOUNT/date oflag=sync
9190         chmod +x $MOUNT/date
9191
9192         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
9193         $LCTL set_param fail_loc=0x80001401
9194
9195         $MOUNT/date > /dev/null
9196         rm -f $MOUNT/date
9197 }
9198 run_test 221 "make sure fault and truncate race to not cause OOM"
9199
9200 test_222a () {
9201        rm -rf $DIR/$tdir
9202        mkdir -p $DIR/$tdir
9203        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9204        createmany -o $DIR/$tdir/$tfile 10
9205        cancel_lru_locks mdc
9206        cancel_lru_locks osc
9207        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
9208        $LCTL set_param fail_loc=0x31a
9209        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
9210        $LCTL set_param fail_loc=0
9211        rm -r $DIR/$tdir
9212 }
9213 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
9214
9215 test_222b () {
9216        rm -rf $DIR/$tdir
9217        mkdir -p $DIR/$tdir
9218        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9219        createmany -o $DIR/$tdir/$tfile 10
9220        cancel_lru_locks mdc
9221        cancel_lru_locks osc
9222        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
9223        $LCTL set_param fail_loc=0x31a
9224        rm -r $DIR/$tdir || "AGL for rmdir failed"
9225        $LCTL set_param fail_loc=0
9226 }
9227 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
9228
9229 test_223 () {
9230        rm -rf $DIR/$tdir
9231        mkdir -p $DIR/$tdir
9232        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9233        createmany -o $DIR/$tdir/$tfile 10
9234        cancel_lru_locks mdc
9235        cancel_lru_locks osc
9236        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
9237        $LCTL set_param fail_loc=0x31b
9238        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
9239        $LCTL set_param fail_loc=0
9240        rm -r $DIR/$tdir
9241 }
9242 run_test 223 "osc reenqueue if without AGL lock granted ======================="
9243
9244 test_224a() { # LU-1039, MRP-303
9245         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
9246         $LCTL set_param fail_loc=0x508
9247         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
9248         $LCTL set_param fail_loc=0
9249         df $DIR
9250 }
9251 run_test 224a "Don't panic on bulk IO failure"
9252
9253 test_224b() { # LU-1039, MRP-303
9254         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
9255         cancel_lru_locks osc
9256         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
9257         $LCTL set_param fail_loc=0x515
9258         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
9259         $LCTL set_param fail_loc=0
9260         df $DIR
9261 }
9262 run_test 224b "Don't panic on bulk IO failure"
9263
9264 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
9265 test_225a () {
9266        if [ -z ${MDSSURVEY} ]; then
9267               skip_env "mds-survey not found" && return
9268        fi
9269        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
9270             { skip "Need MDS version at least 2.2.51"; return; }
9271
9272        local mds=$(facet_host $SINGLEMDS)
9273        local target=$(do_nodes $mds 'lctl dl' | \
9274                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
9275
9276        local cmd1="file_count=1000 thrhi=4"
9277        local cmd2="dir_count=2 layer=mdd stripe_count=0"
9278        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
9279        local cmd="$cmd1 $cmd2 $cmd3"
9280
9281        rm -f ${TMP}/mds_survey*
9282        echo + $cmd
9283        eval $cmd || error "mds-survey with zero-stripe failed"
9284        cat ${TMP}/mds_survey*
9285        rm -f ${TMP}/mds_survey*
9286 }
9287 run_test 225a "Metadata survey sanity with zero-stripe"
9288
9289 test_225b () {
9290        if [ -z ${MDSSURVEY} ]; then
9291               skip_env "mds-survey not found" && return
9292        fi
9293        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
9294             { skip "Need MDS version at least 2.2.51"; return; }
9295
9296        if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
9297               skip_env "Need to mount OST to test" && return
9298        fi
9299
9300        local mds=$(facet_host $SINGLEMDS)
9301        local target=$(do_nodes $mds 'lctl dl' | \
9302                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
9303
9304        local cmd1="file_count=1000 thrhi=4"
9305        local cmd2="dir_count=2 layer=mdd stripe_count=1"
9306        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
9307        local cmd="$cmd1 $cmd2 $cmd3"
9308
9309        rm -f ${TMP}/mds_survey*
9310        echo + $cmd
9311        eval $cmd || error "mds-survey with stripe_count failed"
9312        cat ${TMP}/mds_survey*
9313        rm -f ${TMP}/mds_survey*
9314 }
9315 run_test 225b "Metadata survey sanity with stripe_count = 1"
9316
9317 mcreate_path2fid () {
9318         local mode=$1
9319         local major=$2
9320         local minor=$3
9321         local name=$4
9322         local desc=$5
9323         local path=$DIR/$tdir/$name
9324         local fid
9325         local rc
9326         local fid_path
9327
9328         $MCREATE --mode=$1 --major=$2 --minor=$3 $path || \
9329                 error "error: cannot create $desc"
9330
9331         fid=$($LFS path2fid $path)
9332         rc=$?
9333         [ $rc -ne 0 ] && error "error: cannot get fid of a $desc"
9334
9335         fid_path=$($LFS fid2path $DIR $fid)
9336         rc=$?
9337         [ $rc -ne 0 ] && error "error: cannot get path of a $desc by fid"
9338
9339         [ "$path" == "$fid_path" ] || \
9340                 error "error: fid2path returned \`$fid_path', expected \`$path'"
9341 }
9342
9343 test_226 () {
9344         rm -rf $DIR/$tdir
9345         mkdir -p $DIR/$tdir
9346
9347         mcreate_path2fid 0010666 0 0 fifo "FIFO"
9348         mcreate_path2fid 0020666 1 3 null "character special file (null)"
9349         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
9350         mcreate_path2fid 0040666 0 0 dir "directory"
9351         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
9352         mcreate_path2fid 0100666 0 0 file "regular file"
9353         mcreate_path2fid 0120666 0 0 link "symbolic link"
9354         mcreate_path2fid 0140666 0 0 sock "socket"
9355 }
9356 run_test 226 "call path2fid and fid2path on files of all type"
9357
9358 # LU-1299 Executing or running ldd on a truncated executable does not
9359 # cause an out-of-memory condition.
9360 test_227() {
9361         dd if=`which date` of=$MOUNT/date bs=1k count=1
9362         chmod +x $MOUNT/date
9363
9364         $MOUNT/date > /dev/null
9365         ldd $MOUNT/date > /dev/null
9366         rm -f $MOUNT/date
9367 }
9368 run_test 227 "running truncated executable does not cause OOM"
9369
9370 #
9371 # tests that do cleanup/setup should be run at the end
9372 #
9373
9374 test_900() {
9375         local ls
9376         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
9377         $LCTL set_param fail_loc=0x903
9378         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
9379         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
9380                 echo "clear" > $ls
9381         done
9382         FAIL_ON_ERROR=true cleanup
9383         FAIL_ON_ERROR=true setup
9384 }
9385 run_test 900 "umount should not race with any mgc requeue thread"
9386
9387 complete $(basename $0) $SECONDS
9388 check_and_cleanup_lustre
9389 if [ "$I_MOUNTED" != "yes" ]; then
9390         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
9391 fi
9392 exit_status