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