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