Whamcloud - gitweb
b=16893,18503
[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 12653 12653 5188 10764 16260
11 ALWAYS_EXCEPT="                27u   42a  42b  42c  42d  45   51d   65a   65e   68b   75    119d  $SANITY_EXCEPT"
12 # bug number for skipped test: 2108 9789 3637 9789 3561 5188/5749 1443
13 #ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"27m 42a 42b 42c 42d 45 68 76"}
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 # Tests that fail on uml
17 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
18 #                                    buffer i/o errs             sock spc runas
19 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 27m 27n 27o 27p 27q 27r 31d 54a  64b 99a 99b 99c 99d 99e 99f 101"
20
21 # test76 is not valid with FIDs because inode numbers are not reused
22 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 76"
23
24 case `uname -r` in
25 2.4*) FSTYPE=${FSTYPE:-ext3} ;;
26 2.6*) FSTYPE=${FSTYPE:-ldiskfs} ;;
27 *) error "unsupported kernel" ;;
28 esac
29
30 SRCDIR=$(cd $(dirname $0); echo $PWD)
31 export PATH=$PATH:/sbin
32
33 TMP=${TMP:-/tmp}
34
35 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
36 CREATETEST=${CREATETEST:-createtest}
37 LFS=${LFS:-lfs}
38 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
39 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
40 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
41 LFIND=${LFIND:-"$LFS find"}
42 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
43 LCTL=${LCTL:-lctl}
44 MCREATE=${MCREATE:-mcreate}
45 OPENFILE=${OPENFILE:-openfile}
46 OPENUNLINK=${OPENUNLINK:-openunlink}
47 READS=${READS:-"reads"}
48 TRUNCATE=${TRUNCATE:-truncate}
49 MUNLINK=${MUNLINK:-munlink}
50 SOCKETSERVER=${SOCKETSERVER:-socketserver}
51 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
52 IOPENTEST1=${IOPENTEST1:-iopentest1}
53 IOPENTEST2=${IOPENTEST2:-iopentest2}
54 MEMHOG=${MEMHOG:-memhog}
55 DIRECTIO=${DIRECTIO:-directio}
56 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
57 UMOUNT=${UMOUNT:-"umount -d"}
58 STRIPES_PER_OBJ=-1
59 CHECK_GRANT=${CHECK_GRANT:-"yes"}
60 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
61
62 export NAME=${NAME:-local}
63
64 SAVE_PWD=$PWD
65
66 CLEANUP=${CLEANUP:-:}
67 SETUP=${SETUP:-:}
68 TRACE=${TRACE:-""}
69 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
70 . $LUSTRE/tests/test-framework.sh
71 init_test_env $@
72 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
73
74 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24v 27m 36f 36g 51b 51c 60c 63 64b 68 71 73 77f 78 101 103 115 120g 124b"
75
76 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
77 FAIL_ON_ERROR=false
78
79 cleanup() {
80         echo -n "cln.."
81         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
82         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
83 }
84 setup() {
85         echo -n "mnt.."
86         load_modules
87         setupall || exit 10
88         echo "done"
89 }
90
91 check_kernel_version() {
92         WANT_VER=$1
93         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
94         case $GOT_VER in
95         patchless|patchless_client) return 0;;
96         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
97         esac
98         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
99         return 1
100 }
101
102 if [ "$ONLY" == "cleanup" ]; then
103        sh llmountcleanup.sh
104        exit 0
105 fi
106
107 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
108
109 check_and_setup_lustre
110
111 DIR=${DIR:-$MOUNT}
112 assert_DIR
113
114 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
115     awk '{gsub(/_UUID/,""); print $1}' | head -1)
116 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
117 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
118 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
119 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
120 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
121 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
122
123 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
124 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
125 rm -rf $DIR/[Rdfs][0-9]*
126
127 # $RUNAS_ID may get set incorrectly somewhere else
128 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
129
130 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
131
132 build_test_filter
133
134 if [ "${ONLY}" = "MOUNT" ] ; then
135         echo "Lustre is up, please go on"
136         exit
137 fi
138
139 echo "preparing for tests involving mounts"
140 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
141 touch $EXT2_DEV
142 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
143 echo # add a newline after mke2fs.
144
145 umask 077
146
147 OLDDEBUG="`lctl get_param -n debug 2> /dev/null`"
148 lctl set_param debug=-1 2> /dev/null || true
149 test_0() {
150         touch $DIR/$tfile
151         $CHECKSTAT -t file $DIR/$tfile || error
152         rm $DIR/$tfile
153         $CHECKSTAT -a $DIR/$tfile || error
154 }
155 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
156
157 test_0b() {
158         chmod 0755 $DIR || error
159         $CHECKSTAT -p 0755 $DIR || error
160 }
161 run_test 0b "chmod 0755 $DIR ============================="
162
163 test_0c() {
164     $LCTL get_param mdc.*.import | grep  "state: FULL" || error "import not FULL"
165     $LCTL get_param mdc.*.import | grep  "target: $FSNAME-MDT" || error "bad target"
166 }
167 run_test 0c "check import proc ============================="
168
169 test_1a() {
170         mkdir $DIR/d1
171         mkdir $DIR/d1/d2
172         mkdir $DIR/d1/d2 && error "we expect EEXIST, but not returned"
173         $CHECKSTAT -t dir $DIR/d1/d2 || error
174 }
175 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
176
177 test_1b() {
178         rmdir $DIR/d1/d2
179         rmdir $DIR/d1
180         $CHECKSTAT -a $DIR/d1 || error
181 }
182 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
183
184 test_2a() {
185         mkdir $DIR/d2
186         touch $DIR/d2/f
187         $CHECKSTAT -t file $DIR/d2/f || error
188 }
189 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
190
191 test_2b() {
192         rm -r $DIR/d2
193         $CHECKSTAT -a $DIR/d2 || error
194 }
195 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
196
197 test_3a() {
198         mkdir $DIR/d3
199         $CHECKSTAT -t dir $DIR/d3 || error
200 }
201 run_test 3a "mkdir .../d3 ======================================"
202
203 test_3b() {
204         if [ ! -d $DIR/d3 ]; then
205                 mkdir $DIR/d3
206         fi
207         touch $DIR/d3/f
208         $CHECKSTAT -t file $DIR/d3/f || error
209 }
210 run_test 3b "touch .../d3/f ===================================="
211
212 test_3c() {
213         rm -r $DIR/d3
214         $CHECKSTAT -a $DIR/d3 || error
215 }
216 run_test 3c "rm -r .../d3 ======================================"
217
218 test_4a() {
219         mkdir $DIR/d4
220         $CHECKSTAT -t dir $DIR/d4 || error
221 }
222 run_test 4a "mkdir .../d4 ======================================"
223
224 test_4b() {
225         if [ ! -d $DIR/d4 ]; then
226                 mkdir $DIR/d4
227         fi
228         mkdir $DIR/d4/d2
229         $CHECKSTAT -t dir $DIR/d4/d2 || error
230 }
231 run_test 4b "mkdir .../d4/d2 ==================================="
232
233 test_5() {
234         mkdir $DIR/d5
235         mkdir $DIR/d5/d2
236         chmod 0707 $DIR/d5/d2
237         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
238 }
239 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
240
241 test_6a() {
242         touch $DIR/f6a
243         chmod 0666 $DIR/f6a || error
244         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
245 }
246 run_test 6a "touch .../f6a; chmod .../f6a ======================"
247
248 test_6b() {
249         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
250         if [ ! -f $DIR/f6a ]; then
251                 touch $DIR/f6a
252                 chmod 0666 $DIR/f6a
253         fi
254         $RUNAS chmod 0444 $DIR/f6a && error
255         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
256 }
257 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
258
259 test_6c() {
260         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
261         touch $DIR/f6c
262         chown $RUNAS_ID $DIR/f6c || error
263         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
264 }
265 run_test 6c "touch .../f6c; chown .../f6c ======================"
266
267 test_6d() {
268         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
269         if [ ! -f $DIR/f6c ]; then
270                 touch $DIR/f6c
271                 chown $RUNAS_ID $DIR/f6c
272         fi
273         $RUNAS chown $UID $DIR/f6c && error
274         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
275 }
276 run_test 6d "$RUNAS chown .../f6c (should return error) =="
277
278 test_6e() {
279         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
280         touch $DIR/f6e
281         chgrp $RUNAS_ID $DIR/f6e || error
282         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
283 }
284 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
285
286 test_6f() {
287         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
288         if [ ! -f $DIR/f6e ]; then
289                 touch $DIR/f6e
290                 chgrp $RUNAS_ID $DIR/f6e
291         fi
292         $RUNAS chgrp $UID $DIR/f6e && error
293         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
294 }
295 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
296
297 test_6g() {
298         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
299         mkdir $DIR/d6g || error
300         chmod 777 $DIR/d6g || error
301         $RUNAS mkdir $DIR/d6g/d || error
302         chmod g+s $DIR/d6g/d || error
303         mkdir $DIR/d6g/d/subdir
304         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
305 }
306 run_test 6g "Is new dir in sgid dir inheriting group?"
307
308 test_6h() { # bug 7331
309         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
310         touch $DIR/f6h || error "touch failed"
311         chown $RUNAS_ID:$RUNAS_ID $DIR/f6h || error "initial chown failed"
312         $RUNAS -G$RUNAS_ID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
313         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_ID $DIR/f6h || error
314 }
315 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
316
317 test_7a() {
318         mkdir $DIR/d7
319         $MCREATE $DIR/d7/f
320         chmod 0666 $DIR/d7/f
321         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
322 }
323 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
324
325 test_7b() {
326         if [ ! -d $DIR/d7 ]; then
327                 mkdir $DIR/d7
328         fi
329         $MCREATE $DIR/d7/f2
330         echo -n foo > $DIR/d7/f2
331         [ "`cat $DIR/d7/f2`" = "foo" ] || error
332         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
333 }
334 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
335
336 test_8() {
337         mkdir $DIR/d8
338         touch $DIR/d8/f
339         chmod 0666 $DIR/d8/f
340         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
341 }
342 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
343
344 test_9() {
345         mkdir $DIR/d9
346         mkdir $DIR/d9/d2
347         mkdir $DIR/d9/d2/d3
348         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
349 }
350 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
351
352 test_10() {
353         mkdir $DIR/d10
354         mkdir $DIR/d10/d2
355         touch $DIR/d10/d2/f
356         $CHECKSTAT -t file $DIR/d10/d2/f || error
357 }
358 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
359
360 test_11() {
361         mkdir $DIR/d11
362         mkdir $DIR/d11/d2
363         chmod 0666 $DIR/d11/d2
364         chmod 0705 $DIR/d11/d2
365         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
366 }
367 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
368
369 test_12() {
370         mkdir $DIR/d12
371         touch $DIR/d12/f
372         chmod 0666 $DIR/d12/f
373         chmod 0654 $DIR/d12/f
374         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
375 }
376 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
377
378 test_13() {
379         mkdir $DIR/d13
380         dd if=/dev/zero of=$DIR/d13/f count=10
381         >  $DIR/d13/f
382         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
383 }
384 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
385
386 test_14() {
387         mkdir $DIR/d14
388         touch $DIR/d14/f
389         rm $DIR/d14/f
390         $CHECKSTAT -a $DIR/d14/f || error
391 }
392 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
393
394 test_15() {
395         mkdir $DIR/d15
396         touch $DIR/d15/f
397         mv $DIR/d15/f $DIR/d15/f2
398         $CHECKSTAT -t file $DIR/d15/f2 || error
399 }
400 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
401
402 test_16() {
403         mkdir $DIR/d16
404         touch $DIR/d16/f
405         rm -rf $DIR/d16/f
406         $CHECKSTAT -a $DIR/d16/f || error
407 }
408 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
409
410 test_17a() {
411         mkdir -p $DIR/d17
412         touch $DIR/d17/f
413         ln -s $DIR/d17/f $DIR/d17/l-exist
414         ls -l $DIR/d17
415         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
416         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
417         rm -f $DIR/d17/l-exist
418         $CHECKSTAT -a $DIR/d17/l-exist || error
419 }
420 run_test 17a "symlinks: create, remove (real) =================="
421
422 test_17b() {
423         mkdir -p $DIR/d17
424         ln -s no-such-file $DIR/d17/l-dangle
425         ls -l $DIR/d17
426         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
427         $CHECKSTAT -fa $DIR/d17/l-dangle || error
428         rm -f $DIR/d17/l-dangle
429         $CHECKSTAT -a $DIR/d17/l-dangle || error
430 }
431 run_test 17b "symlinks: create, remove (dangling) =============="
432
433 test_17c() { # bug 3440 - don't save failed open RPC for replay
434         mkdir -p $DIR/d17
435         ln -s foo $DIR/d17/f17c
436         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
437 }
438 run_test 17c "symlinks: open dangling (should return error) ===="
439
440 test_17d() {
441         mkdir -p $DIR/d17
442         ln -s foo $DIR/d17/f17d
443         touch $DIR/d17/f17d || error "creating to new symlink"
444 }
445 run_test 17d "symlinks: create dangling ========================"
446
447 test_17e() {
448         mkdir -p $DIR/$tdir
449         local foo=$DIR/$tdir/$tfile
450         ln -s $foo $foo || error "create symlink failed"
451         ls -l $foo || error "ls -l failed"
452         ls $foo && error "ls not failed" || true
453 }
454 run_test 17e "symlinks: create recursive symlink (should return error) ===="
455
456 test_17f() {
457         mkdir -p $DIR/d17f
458         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
459         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
460         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
461         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
462         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
463         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
464         ls -l  $DIR/d17f
465 }
466 run_test 17f "symlinks: long and very long symlink name ========================"
467
468 test_17g() {
469         mkdir -p $DIR/$tdir
470         LONGSYMLINK="$(dd if=/dev/zero bs=4095 count=1 | tr '\0' 'x')"
471         ln -s $LONGSYMLINK $DIR/$tdir/$tfile
472         ls -l $DIR/$tdir
473 }
474 run_test 17g "symlinks: really long symlink name ==============================="
475
476 test_17h() { #bug 17378
477         mkdir -p $DIR/$tdir
478         $SETSTRIPE $DIR/$tdir -c -1
479 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
480         do_facet mds lctl set_param fail_loc=0x80000141
481         touch $DIR/$tdir/$tfile || true
482 }
483 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
484
485 test_18() {
486         touch $DIR/f
487         ls $DIR || error
488 }
489 run_test 18 "touch .../f ; ls ... =============================="
490
491 test_19a() {
492         touch $DIR/f19
493         ls -l $DIR
494         rm $DIR/f19
495         $CHECKSTAT -a $DIR/f19 || error
496 }
497 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
498
499 test_19b() {
500         ls -l $DIR/f19 && error || true
501 }
502 run_test 19b "ls -l .../f19 (should return error) =============="
503
504 test_19c() {
505         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
506         $RUNAS touch $DIR/f19 && error || true
507 }
508 run_test 19c "$RUNAS touch .../f19 (should return error) =="
509
510 test_19d() {
511         cat $DIR/f19 && error || true
512 }
513 run_test 19d "cat .../f19 (should return error) =============="
514
515 test_20() {
516         touch $DIR/f
517         rm $DIR/f
518         log "1 done"
519         touch $DIR/f
520         rm $DIR/f
521         log "2 done"
522         touch $DIR/f
523         rm $DIR/f
524         log "3 done"
525         $CHECKSTAT -a $DIR/f || error
526 }
527 run_test 20 "touch .../f ; ls -l ... ==========================="
528
529 test_21() {
530         mkdir $DIR/d21
531         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
532         ln -s dangle $DIR/d21/link
533         echo foo >> $DIR/d21/link
534         cat $DIR/d21/dangle
535         $CHECKSTAT -t link $DIR/d21/link || error
536         $CHECKSTAT -f -t file $DIR/d21/link || error
537 }
538 run_test 21 "write to dangling link ============================"
539
540 test_22() {
541         WDIR=$DIR/$tdir
542         mkdir -p $WDIR
543         chown $RUNAS_ID $WDIR
544         (cd $WDIR || error "cd $WDIR failed";
545         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
546         $RUNAS tar xf -)
547         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
548         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
549         $CHECKSTAT -u \#$RUNAS_ID $WDIR/etc || error "checkstat -u failed"
550 }
551 run_test 22 "unpack tar archive as non-root user ==============="
552
553 # was test_23
554 test_23a() {
555         mkdir -p $DIR/$tdir
556         local file=$DIR/$tdir/$tfile
557
558         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
559         openfile -f O_CREAT:O_EXCL $file &&
560                 error "$file recreate succeeded" || true
561 }
562 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
563
564 test_23b() { # bug 18988
565         mkdir -p $DIR/$tdir
566         local file=$DIR/$tdir/$tfile
567
568         rm -f $file
569         echo foo > $file || error "write filed"
570         echo bar >> $file || error "append filed"
571         $CHECKSTAT -s 8 $file || error "wrong size"
572         rm $file
573 }
574 run_test 23b "O_APPEND check =========================="
575
576 test_24a() {
577         echo '== rename sanity =============================================='
578         echo '-- same directory rename'
579         mkdir $DIR/R1
580         touch $DIR/R1/f
581         mv $DIR/R1/f $DIR/R1/g
582         $CHECKSTAT -t file $DIR/R1/g || error
583 }
584 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
585
586 test_24b() {
587         mkdir $DIR/R2
588         touch $DIR/R2/{f,g}
589         mv $DIR/R2/f $DIR/R2/g
590         $CHECKSTAT -a $DIR/R2/f || error
591         $CHECKSTAT -t file $DIR/R2/g || error
592 }
593 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
594
595 test_24c() {
596         mkdir $DIR/R3
597         mkdir $DIR/R3/f
598         mv $DIR/R3/f $DIR/R3/g
599         $CHECKSTAT -a $DIR/R3/f || error
600         $CHECKSTAT -t dir $DIR/R3/g || error
601 }
602 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
603
604 test_24d() {
605         mkdir $DIR/R4
606         mkdir $DIR/R4/{f,g}
607         mrename $DIR/R4/f $DIR/R4/g
608         $CHECKSTAT -a $DIR/R4/f || error
609         $CHECKSTAT -t dir $DIR/R4/g || error
610 }
611 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
612
613 test_24e() {
614         echo '-- cross directory renames --'
615         mkdir $DIR/R5{a,b}
616         touch $DIR/R5a/f
617         mv $DIR/R5a/f $DIR/R5b/g
618         $CHECKSTAT -a $DIR/R5a/f || error
619         $CHECKSTAT -t file $DIR/R5b/g || error
620 }
621 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
622
623 test_24f() {
624         mkdir $DIR/R6{a,b}
625         touch $DIR/R6a/f $DIR/R6b/g
626         mv $DIR/R6a/f $DIR/R6b/g
627         $CHECKSTAT -a $DIR/R6a/f || error
628         $CHECKSTAT -t file $DIR/R6b/g || error
629 }
630 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
631
632 test_24g() {
633         mkdir $DIR/R7{a,b}
634         mkdir $DIR/R7a/d
635         mv $DIR/R7a/d $DIR/R7b/e
636         $CHECKSTAT -a $DIR/R7a/d || error
637         $CHECKSTAT -t dir $DIR/R7b/e || error
638 }
639 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
640
641 test_24h() {
642         mkdir $DIR/R8{a,b}
643         mkdir $DIR/R8a/d $DIR/R8b/e
644         mrename $DIR/R8a/d $DIR/R8b/e
645         $CHECKSTAT -a $DIR/R8a/d || error
646         $CHECKSTAT -t dir $DIR/R8b/e || error
647 }
648 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
649
650 test_24i() {
651         echo "-- rename error cases"
652         mkdir $DIR/R9
653         mkdir $DIR/R9/a
654         touch $DIR/R9/f
655         mrename $DIR/R9/f $DIR/R9/a
656         $CHECKSTAT -t file $DIR/R9/f || error
657         $CHECKSTAT -t dir  $DIR/R9/a || error
658         $CHECKSTAT -a $DIR/R9/a/f || error
659 }
660 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
661
662 test_24j() {
663         mkdir $DIR/R10
664         mrename $DIR/R10/f $DIR/R10/g
665         $CHECKSTAT -t dir $DIR/R10 || error
666         $CHECKSTAT -a $DIR/R10/f || error
667         $CHECKSTAT -a $DIR/R10/g || error
668 }
669 run_test 24j "source does not exist ============================"
670
671 test_24k() {
672         mkdir $DIR/R11a $DIR/R11a/d
673         touch $DIR/R11a/f
674         mv $DIR/R11a/f $DIR/R11a/d
675         $CHECKSTAT -a $DIR/R11a/f || error
676         $CHECKSTAT -t file $DIR/R11a/d/f || error
677 }
678 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
679
680 # bug 2429 - rename foo foo foo creates invalid file
681 test_24l() {
682         f="$DIR/f24l"
683         multiop $f OcNs || error
684 }
685 run_test 24l "Renaming a file to itself ========================"
686
687 test_24m() {
688         f="$DIR/f24m"
689         multiop $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
690         # on ext3 this does not remove either the source or target files
691         # though the "expected" operation would be to remove the source
692         $CHECKSTAT -t file ${f} || error "${f} missing"
693         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
694 }
695 run_test 24m "Renaming a file to a hard link to itself ========="
696
697 test_24n() {
698     f="$DIR/f24n"
699     # this stats the old file after it was renamed, so it should fail
700     touch ${f}
701     $CHECKSTAT ${f}
702     mv ${f} ${f}.rename
703     $CHECKSTAT ${f}.rename
704     $CHECKSTAT -a ${f}
705 }
706 run_test 24n "Statting the old file after renaming (Posix rename 2)"
707
708 test_24o() {
709         check_kernel_version 37 || return 0
710         mkdir -p $DIR/d24o
711         rename_many -s random -v -n 10 $DIR/d24o
712 }
713 run_test 24o "rename of files during htree split ==============="
714
715 test_24p() {
716         mkdir $DIR/R12{a,b}
717         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
718         mrename $DIR/R12a $DIR/R12b
719         $CHECKSTAT -a $DIR/R12a || error
720         $CHECKSTAT -t dir $DIR/R12b || error
721         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
722         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
723 }
724 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
725
726 test_24q() {
727         mkdir $DIR/R13{a,b}
728         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
729         multiop_bg_pause $DIR/R13b D_c || return 1
730         MULTIPID=$!
731
732         mrename $DIR/R13a $DIR/R13b
733         $CHECKSTAT -a $DIR/R13a || error
734         $CHECKSTAT -t dir $DIR/R13b || error
735         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
736         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
737         kill -USR1 $MULTIPID
738         wait $MULTIPID || error "multiop close failed"
739 }
740 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
741
742 test_24r() { #bug 3789
743         mkdir $DIR/R14a $DIR/R14a/b
744         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
745         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
746         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
747 }
748 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
749
750 test_24s() {
751         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
752         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
753         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
754         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
755 }
756 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
757 test_24t() {
758         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
759         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
760         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
761         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
762 }
763 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
764
765 test_24u() { # bug12192
766         multiop $DIR/$tfile C2w$((2048 * 1024))c || error
767         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
768 }
769 run_test 24u "create stripe file"
770
771 test_24v() {
772         local NRFILES=100000
773         local FREE_INODES=`lfs df -i|grep "filesystem summary" | awk '{print $5}'`
774         [ $FREE_INODES -lt $NRFILES ] && \
775                 skip "not enough free inodes $FREE_INODES required $NRFILES" && \
776                 return
777
778         mkdir -p $DIR/d24v
779         createmany -m $DIR/d24v/$tfile $NRFILES
780         ls $DIR/d24v >/dev/null || error "error in listing large dir"
781
782         rm $DIR/d24v -rf
783 }
784 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
785
786 test_25a() {
787         echo '== symlink sanity ============================================='
788
789         mkdir $DIR/d25
790         ln -s d25 $DIR/s25
791         touch $DIR/s25/foo || error
792 }
793 run_test 25a "create file in symlinked directory ==============="
794
795 test_25b() {
796         [ ! -d $DIR/d25 ] && test_25a
797         $CHECKSTAT -t file $DIR/s25/foo || error
798 }
799 run_test 25b "lookup file in symlinked directory ==============="
800
801 test_26a() {
802         mkdir $DIR/d26
803         mkdir $DIR/d26/d26-2
804         ln -s d26/d26-2 $DIR/s26
805         touch $DIR/s26/foo || error
806 }
807 run_test 26a "multiple component symlink ======================="
808
809 test_26b() {
810         mkdir -p $DIR/d26b/d26-2
811         ln -s d26b/d26-2/foo $DIR/s26-2
812         touch $DIR/s26-2 || error
813 }
814 run_test 26b "multiple component symlink at end of lookup ======"
815
816 test_26c() {
817         mkdir $DIR/d26.2
818         touch $DIR/d26.2/foo
819         ln -s d26.2 $DIR/s26.2-1
820         ln -s s26.2-1 $DIR/s26.2-2
821         ln -s s26.2-2 $DIR/s26.2-3
822         chmod 0666 $DIR/s26.2-3/foo
823 }
824 run_test 26c "chain of symlinks ================================"
825
826 # recursive symlinks (bug 439)
827 test_26d() {
828         ln -s d26-3/foo $DIR/d26-3
829 }
830 run_test 26d "create multiple component recursive symlink ======"
831
832 test_26e() {
833         [ ! -h $DIR/d26-3 ] && test_26d
834         rm $DIR/d26-3
835 }
836 run_test 26e "unlink multiple component recursive symlink ======"
837
838 # recursive symlinks (bug 7022)
839 test_26f() {
840         mkdir -p $DIR/$tdir
841         mkdir $DIR/$tdir/$tfile        || error "mkdir $DIR/$tdir/$tfile failed"
842         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
843         mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
844         mkdir $tfile             || error "mkdir $tfile failed"
845         cd $tfile                || error "cd $tfile failed"
846         ln -s .. dotdot          || error "ln dotdot failed"
847         ln -s dotdot/lndir lndir || error "ln lndir failed"
848         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
849         output=`ls $tfile/$tfile/lndir/bar1`
850         [ "$output" = bar1 ] && error "unexpected output"
851         rm -r $tfile             || error "rm $tfile failed"
852         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
853 }
854 run_test 26f "rm -r of a directory which has recursive symlink ="
855
856 test_27a() {
857         echo '== stripe sanity =============================================='
858         mkdir -p $DIR/d27 || error "mkdir failed"
859         $GETSTRIPE $DIR/d27
860         $SETSTRIPE $DIR/d27/f0 -c 1 || error "lstripe failed"
861         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
862         pass
863         log "== test_27a: write to one stripe file ========================="
864         cp /etc/hosts $DIR/d27/f0 || error
865 }
866 run_test 27a "one stripe file =================================="
867
868 test_27c() {
869         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
870         mkdir -p $DIR/d27
871         $SETSTRIPE $DIR/d27/f01 -c 2 || error "lstripe failed"
872         [ `$GETSTRIPE $DIR/d27/f01 | grep -A 10 obdidx | wc -l` -eq 4 ] ||
873                 error "two-stripe file doesn't have two stripes"
874         pass
875         log "== test_27c: write to two stripe file file f01 ================"
876         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
877 }
878 run_test 27c "create two stripe file f01 ======================="
879
880 test_27d() {
881         mkdir -p $DIR/d27
882         $SETSTRIPE -c0 -i-1 -s0 $DIR/d27/fdef || error "lstripe failed"
883         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
884         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
885 }
886 run_test 27d "create file with default settings ================"
887
888 test_27e() {
889         mkdir -p $DIR/d27
890         $SETSTRIPE $DIR/d27/f12 -c 2 || error "lstripe failed"
891         $SETSTRIPE $DIR/d27/f12 -c 2 && error "lstripe succeeded twice"
892         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
893 }
894 run_test 27e "setstripe existing file (should return error) ======"
895
896 test_27f() {
897         mkdir -p $DIR/d27
898         $SETSTRIPE $DIR/d27/fbad -s 100 -i 0 -c 1 && error "lstripe failed"
899         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
900         $GETSTRIPE $DIR/d27/fbad || error "lfs getstripe failed"
901 }
902 run_test 27f "setstripe with bad stripe size (should return error)"
903
904 test_27g() {
905         mkdir -p $DIR/d27
906         $MCREATE $DIR/d27/fnone || error "mcreate failed"
907         pass
908         log "== test 27h: lfs getstripe with no objects ===================="
909         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" || error "has object"
910         pass
911         log "== test 27i: lfs getstripe with some objects =================="
912         touch $DIR/d27/fsome || error "touch failed"
913         $GETSTRIPE $DIR/d27/fsome | grep obdidx || error "missing objects"
914 }
915 run_test 27g "test lfs getstripe ==========================================="
916
917 test_27j() {
918         mkdir -p $DIR/d27
919         $SETSTRIPE $DIR/d27/f27j -i $OSTCOUNT && error "lstripe failed"||true
920 }
921 run_test 27j "setstripe with bad stripe offset (should return error)"
922
923 test_27k() { # bug 2844
924         mkdir -p $DIR/d27
925         FILE=$DIR/d27/f27k
926         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
927         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
928         $SETSTRIPE $FILE -s 67108864 || error "lstripe failed"
929         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
930         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
931         dd if=/dev/zero of=$FILE bs=4k count=1
932         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
933         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
934 }
935 run_test 27k "limit i_blksize for broken user apps ============="
936
937 test_27l() {
938         mkdir -p $DIR/d27
939         mcreate $DIR/f27l || error "creating file"
940         $RUNAS $SETSTRIPE $DIR/f27l -c 1 && \
941                 error "lstripe should have failed" || true
942 }
943 run_test 27l "check setstripe permissions (should return error)"
944
945 test_27m() {
946         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2 OSTs -- skipping" && return
947         if [ $ORIGFREE -gt $MAXFREE ]; then
948                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
949                 return
950         fi
951         mkdir -p $DIR/d27
952         $SETSTRIPE $DIR/d27/f27m_1 -i 0 -c 1
953         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE && \
954                 error "dd should fill OST0"
955         i=2
956         while $SETSTRIPE $DIR/d27/f27m_$i -i 0 -c 1 ; do
957                 i=`expr $i + 1`
958                 [ $i -gt 256 ] && break
959         done
960         i=`expr $i + 1`
961         touch $DIR/d27/f27m_$i
962         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
963                 error "OST0 was full but new created file still use it"
964         i=`expr $i + 1`
965         touch $DIR/d27/f27m_$i
966         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
967                 error "OST0 was full but new created file still use it"
968         rm -r $DIR/d27
969         sleep 15
970 }
971 run_test 27m "create file while OST0 was full =================="
972
973 # osc's keep a NOSPC stick flag that gets unset with rmdir
974 reset_enospc() {
975         local FAIL_LOC=${1:-0}
976         local OSTIDX=${2:-""}
977
978         mkdir -p $DIR/d27/nospc
979         rmdir $DIR/d27/nospc
980         local list=$(comma_list $(osts_nodes))
981         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
982
983         do_nodes $list lctl set_param fail_loc=$FAIL_LOC
984 }
985
986 exhaust_precreations() {
987         local OSTIDX=$1
988         local MDSIDX=$(get_mds_dir "$DIR/d27")
989         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
990
991         local OST=$(lfs osts | grep ${OSTIDX}": " | \
992                 awk '{print $2}' | sed -e 's/_UUID$//')
993         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
994                           sed -e 's/_UUID$//;s/^.*-//')
995
996         # on the mdt's osc
997         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n osc.*${OST}-osc-${MDT_INDEX}.prealloc_last_id)
998         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n osc.*${OST}-osc-${MDT_INDEX}.prealloc_next_id)
999
1000         echo ${OST}-osc-${MDT_INDEX}.prealloc_last_id=$last_id
1001         echo ${OST}-osc-${MDT_INDEX}.prealloc_next_id=$next_id
1002
1003         mkdir -p $DIR/d27
1004         $SETSTRIPE $DIR/d27 -i $OSTIDX -c 1
1005 #define OBD_FAIL_OST_ENOSPC              0x215
1006         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1007         echo "Creating to objid $last_id on ost $OST..."
1008         createmany -o $DIR/d27/${OST}-f $next_id $((last_id - next_id + 2))
1009         do_facet mds${MDSIDX} lctl get_param osc.*${OST}-osc-${MDT_INDEX}.prealloc* | grep '[0-9]'
1010         reset_enospc $2 $OSTIDX
1011 }
1012
1013 exhaust_all_precreations() {
1014         local i
1015         for (( i=0; i < OSTCOUNT; i++ )) ; do
1016                 exhaust_precreations $i 0x215
1017         done
1018         reset_enospc $1
1019 }
1020
1021 test_27n() {
1022         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1023         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1024         remote_ost_nodsh && skip "remote OST with nodsh" && return
1025
1026         reset_enospc
1027         rm -f $DIR/d27/f27n
1028         exhaust_precreations 0 0x80000215
1029         $SETSTRIPE -c -1 $DIR/d27
1030         touch $DIR/d27/f27n || error
1031         $GETSTRIPE $DIR/d27/f27n
1032         reset_enospc
1033 }
1034 run_test 27n "create file with some full OSTs =================="
1035
1036 test_27o() {
1037         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1038         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1039         remote_ost_nodsh && skip "remote OST with nodsh" && return
1040
1041         reset_enospc
1042         rm -f $DIR/d27/f27o
1043         exhaust_all_precreations 0x215
1044         sleep 5
1045
1046         touch $DIR/d27/f27o && error "able to create $DIR/d27/f27o"
1047
1048         reset_enospc
1049         rm -rf $DIR/d27/*
1050 }
1051 run_test 27o "create file with all full OSTs (should error) ===="
1052
1053 test_27p() {
1054         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1055         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1056         remote_ost_nodsh && skip "remote OST with nodsh" && return
1057
1058         reset_enospc
1059         rm -f $DIR/d27/f27p
1060
1061         $MCREATE $DIR/d27/f27p || error "mcreate failed"
1062         $TRUNCATE $DIR/d27/f27p 80000000 || error "truncate failed"
1063         $CHECKSTAT -s 80000000 $DIR/d27/f27p || error "checkstat failed"
1064
1065         exhaust_precreations 0 0x80000215
1066         echo foo >> $DIR/d27/f27p || error "append failed"
1067         $CHECKSTAT -s 80000004 $DIR/d27/f27p || error "checkstat failed"
1068
1069         reset_enospc
1070 }
1071 run_test 27p "append to a truncated file with some full OSTs ==="
1072
1073 test_27q() {
1074         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1075         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1076         remote_ost_nodsh && skip "remote OST with nodsh" && return
1077
1078         reset_enospc
1079         rm -f $DIR/d27/f27q
1080
1081         $MCREATE $DIR/d27/f27q || error "mcreate $DIR/d27/f27q failed"
1082         $TRUNCATE $DIR/d27/f27q 80000000 ||error "truncate $DIR/d27/f27q failed"
1083         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat failed"
1084
1085         exhaust_all_precreations 0x215
1086
1087         echo foo >> $DIR/d27/f27q && error "append succeeded"
1088         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat 2 failed"
1089
1090         reset_enospc
1091 }
1092 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1093
1094 test_27r() {
1095         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1096         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1097         remote_ost_nodsh && skip "remote OST with nodsh" && return
1098
1099         reset_enospc
1100         rm -f $DIR/d27/f27r
1101         exhaust_precreations 0 0x80000215
1102
1103         $SETSTRIPE $DIR/d27/f27r -i 0 -c 2 # && error
1104
1105         reset_enospc
1106 }
1107 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1108
1109 test_27s() { # bug 10725
1110         mkdir -p $DIR/$tdir
1111         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1112         local stripe_count=0
1113         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1114         $SETSTRIPE $DIR/$tdir -s $stripe_size -c $stripe_count && \
1115                 error "stripe width >= 2^32 succeeded" || true
1116
1117 }
1118 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1119
1120 test_27t() { # bug 10864
1121         WDIR=`pwd`
1122         WLFS=`which lfs`
1123         cd $DIR
1124         touch $tfile
1125         $WLFS getstripe $tfile
1126         cd $WDIR
1127 }
1128 run_test 27t "check that utils parse path correctly"
1129
1130 test_27u() { # bug 4900
1131         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1132         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1133
1134 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1135         do_facet $SINGLEMDS lctl set_param fail_loc=0x139
1136         mkdir -p $DIR/d27u
1137         createmany -o $DIR/d27u/t- 1000
1138         do_facet $SINGLEMDS lctl set_param fail_loc=0
1139
1140         TLOG=$DIR/$tfile.getstripe
1141         $GETSTRIPE $DIR/d27u > $TLOG
1142         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1143         unlinkmany $DIR/d27u/t- 1000
1144         [ $OBJS -gt 0 ] && \
1145                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1146 }
1147 run_test 27u "skip object creation on OSC w/o objects =========="
1148
1149 test_27v() { # bug 4900
1150         [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
1151         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1152         remote_ost_nodsh && skip "remote OST with nodsh" && return
1153
1154         exhaust_all_precreations
1155
1156         mkdir -p $DIR/$tdir
1157         $SETSTRIPE $DIR/$tdir -c 1         # 1 stripe / file
1158
1159         touch $DIR/$tdir/$tfile
1160         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1161         # all except ost1
1162         for (( i=0; i < OSTCOUNT; i++ )) ; do
1163                 do_facet ost$i lctl set_param fail_loc=0x705
1164         done
1165         local START=`date +%s`
1166         createmany -o $DIR/$tdir/$tfile 32
1167
1168         reset_enospc
1169
1170         local FINISH=`date +%s`
1171         local TIMEOUT=`lctl get_param -n timeout`
1172         [ $((FINISH - START)) -ge $((TIMEOUT / 2)) ] && \
1173                error "$FINISH - $START >= $TIMEOUT / 2"
1174
1175         reset_enospc
1176 }
1177 run_test 27v "skip object creation on slow OST ================="
1178
1179 test_27w() { # bug 10997
1180         mkdir -p $DIR/d27w || error "mkdir failed"
1181         $LSTRIPE $DIR/d27w/f0 -s 65536 || error "lstripe failed"
1182         size=`$GETSTRIPE $DIR/d27w/f0 -qs`
1183         [ $size -ne 65536 ] && error "stripe size $size != 65536" || true
1184
1185         [ "$OSTCOUNT" -lt "2" ] && skip "skipping multiple stripe count/offset test" && return
1186         for i in `seq 1 $OSTCOUNT`; do
1187                 offset=$(($i-1))
1188                 $LSTRIPE $DIR/d27w/f$i -c $i -i $offset || error "lstripe -c $i -i $offset failed"
1189                 count=`$GETSTRIPE -qc $DIR/d27w/f$i`
1190                 index=`$GETSTRIPE -qo $DIR/d27w/f$i`
1191                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1192                 [ $index -ne $offset ] && error "stripe offset $index != $offset" || true
1193         done
1194 }
1195 run_test 27w "check lfs setstripe -c -s -i options ============="
1196
1197 test_27x() {
1198         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2 OSTs" && return
1199         DELAY=$(do_facet mds lctl get_param -n lov.*.qos_maxage | awk '{print $1 + 2}')
1200         OFFSET=$(($OSTCOUNTi - 1))
1201         OSTIDX=0
1202         local OST=$(lfs osts | awk '/'${OSTIDX}': / { print $2 }' | sed -e 's/_UUID$//')
1203         
1204         mkdir -p $DIR/$tdir
1205         $SETSTRIPE $DIR/$tdir -c 1      # 1 stripe per file
1206         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 1
1207         sleep $DELAY
1208         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1209         for i in `seq 0 $OFFSET`; do
1210                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] && 
1211                 error "OST0 was degraded but new created file still use it"
1212         done
1213         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 0
1214 }
1215 run_test 27x "create files while OST0 is degraded"
1216
1217 test_27y() {
1218         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2 OSTs -- skipping" && return
1219         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1220
1221         MDS_OSCS=`do_facet mds lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
1222         DELAY=$(do_facet mds lctl get_param -n lov.*.qos_maxage | awk '{print $1 + 2}')
1223         OFFSET=$(($OSTCOUNT-1))
1224         OST=-1
1225         for OSC in $MDS_OSCS; do
1226                 if [ $OST == -1 ]; then {
1227                         OST=`osc_to_ost $OSC`
1228                 } else {
1229                         echo $OSC "is Deactivate:"
1230                         do_facet mds lctl --device  %$OSC deactivate
1231                 } fi
1232         done
1233
1234         OSTIDX=$(lfs osts | grep ${OST} | awk '{print $1}' | sed -e 's/://')
1235         mkdir -p $DIR/$tdir
1236         $SETSTRIPE $DIR/$tdir -c 1      # 1 stripe / file
1237
1238         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 1 
1239         sleep $DELAY 
1240         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1241         do_facet ost$OSTIDX lctl set_param -n obdfilter.$OST.degraded 0 
1242
1243         for i in `seq 0 $OFFSET`; do
1244                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "$OSTIDX"` ] || \
1245                       error "files created on deactivated OSTs instead of degraded OST"
1246         done
1247         for OSC in $MDS_OSCS; do
1248                 [ `osc_to_ost $OSC` != $OST  ] && {
1249                         echo $OSC "is activate"
1250                         do_facet mds lctl --device %$OSC activate
1251                 }
1252         done
1253 }
1254 run_test 27y "create files while OST0 is degraded and the rest inactive"
1255
1256 # createtest also checks that device nodes are created and
1257 # then visible correctly (#2091)
1258 test_28() { # bug 2091
1259         mkdir $DIR/d28
1260         $CREATETEST $DIR/d28/ct || error
1261 }
1262 run_test 28 "create/mknod/mkdir with bad file types ============"
1263
1264 test_29() {
1265         cancel_lru_locks mdc
1266         mkdir $DIR/d29
1267         touch $DIR/d29/foo
1268         log 'first d29'
1269         ls -l $DIR/d29
1270
1271         declare -i LOCKCOUNTORIG=0
1272         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1273                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1274         done
1275         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1276
1277         declare -i LOCKUNUSEDCOUNTORIG=0
1278         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1279                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1280         done
1281
1282         log 'second d29'
1283         ls -l $DIR/d29
1284         log 'done'
1285
1286         declare -i LOCKCOUNTCURRENT=0
1287         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1288                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1289         done
1290
1291         declare -i LOCKUNUSEDCOUNTCURRENT=0
1292         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1293                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1294         done
1295
1296         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1297                 lctl set_param -n ldlm.dump_namespaces ""
1298                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1299                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1300                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1301                 return 2
1302         fi
1303         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1304                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1305                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1306                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1307                 return 3
1308         fi
1309 }
1310 run_test 29 "IT_GETATTR regression  ============================"
1311
1312 test_30() {
1313         cp `which ls` $DIR || cp /bin/ls $DIR
1314         $DIR/ls /
1315         rm $DIR/ls
1316 }
1317 run_test 30 "run binary from Lustre (execve) ==================="
1318
1319 test_31a() {
1320         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1321         $CHECKSTAT -a $DIR/f31 || error
1322 }
1323 run_test 31a "open-unlink file =================================="
1324
1325 test_31b() {
1326         touch $DIR/f31 || error
1327         ln $DIR/f31 $DIR/f31b || error
1328         multiop $DIR/f31b Ouc || error
1329         $CHECKSTAT -t file $DIR/f31 || error
1330 }
1331 run_test 31b "unlink file with multiple links while open ======="
1332
1333 test_31c() {
1334         touch $DIR/f31 || error
1335         ln $DIR/f31 $DIR/f31c || error
1336         multiop_bg_pause $DIR/f31 O_uc || return 1
1337         MULTIPID=$!
1338         multiop $DIR/f31c Ouc
1339         kill -USR1 $MULTIPID
1340         wait $MULTIPID
1341 }
1342 run_test 31c "open-unlink file with multiple links ============="
1343
1344 test_31d() {
1345         opendirunlink $DIR/d31d $DIR/d31d || error
1346         $CHECKSTAT -a $DIR/d31d || error
1347 }
1348 run_test 31d "remove of open directory ========================="
1349
1350 test_31e() { # bug 2904
1351         check_kernel_version 34 || return 0
1352         openfilleddirunlink $DIR/d31e || error
1353 }
1354 run_test 31e "remove of open non-empty directory ==============="
1355
1356 test_31f() { # bug 4554
1357         set -vx
1358         mkdir $DIR/d31f
1359         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1360         cp /etc/hosts $DIR/d31f
1361         ls -l $DIR/d31f
1362         $GETSTRIPE $DIR/d31f/hosts
1363         multiop_bg_pause $DIR/d31f D_c || return 1
1364         MULTIPID=$!
1365
1366         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1367         mkdir $DIR/d31f
1368         $SETSTRIPE $DIR/d31f -s 1048576 -c 1
1369         cp /etc/hosts $DIR/d31f
1370         ls -l $DIR/d31f
1371         $DIR/d31f/hosts
1372         multiop_bg_pause $DIR/d31f D_c || return 1
1373         MULTIPID2=$!
1374
1375         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1376         wait $MULTIPID || error "first opendir $MULTIPID failed"
1377
1378         sleep 6
1379
1380         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1381         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1382         set +vx
1383 }
1384 run_test 31f "remove of open directory with open-unlink file ==="
1385
1386 test_31g() {
1387         echo "-- cross directory link --"
1388         mkdir $DIR/d31g{a,b}
1389         touch $DIR/d31ga/f
1390         ln $DIR/d31ga/f $DIR/d31gb/g
1391         $CHECKSTAT -t file $DIR/d31ga/f || error "source"
1392         [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
1393         $CHECKSTAT -t file $DIR/d31gb/g || error "target"
1394         [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
1395 }
1396 run_test 31g "cross directory link==============="
1397
1398 test_31h() {
1399         echo "-- cross directory link --"
1400         mkdir $DIR/d31h
1401         mkdir $DIR/d31h/dir
1402         touch $DIR/d31h/f
1403         ln $DIR/d31h/f $DIR/d31h/dir/g
1404         $CHECKSTAT -t file $DIR/d31h/f || error "source"
1405         [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
1406         $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
1407         [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
1408 }
1409 run_test 31h "cross directory link under child==============="
1410
1411 test_31i() {
1412         echo "-- cross directory link --"
1413         mkdir $DIR/d31i
1414         mkdir $DIR/d31i/dir
1415         touch $DIR/d31i/dir/f
1416         ln $DIR/d31i/dir/f $DIR/d31i/g
1417         $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
1418         [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
1419         $CHECKSTAT -t file $DIR/d31i/g || error "target"
1420         [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
1421 }
1422 run_test 31i "cross directory link under parent==============="
1423
1424
1425 test_31j() {
1426         mkdir $DIR/d31j
1427         mkdir $DIR/d31j/dir1
1428         ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
1429         link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
1430         mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
1431         mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
1432         return 0
1433 }
1434 run_test 31j "link for directory==============="
1435
1436
1437 test_31k() {
1438         mkdir $DIR/d31k
1439         touch $DIR/d31k/s
1440         touch $DIR/d31k/exist
1441         mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
1442         mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
1443         mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
1444         mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
1445         mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
1446         mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
1447         mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
1448         return 0
1449 }
1450 run_test 31k "link to file: the same, non-existing, dir==============="
1451
1452 test_31m() {
1453         mkdir $DIR/d31m
1454         touch $DIR/d31m/s
1455         mkdir $DIR/d31m2
1456         touch $DIR/d31m2/exist
1457         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
1458         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
1459         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
1460         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
1461         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
1462         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
1463         return 0
1464 }
1465 run_test 31m "link to file: the same, non-existing, dir==============="
1466
1467 test_32a() {
1468         echo "== more mountpoints and symlinks ================="
1469         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1470         mkdir -p $DIR/d32a/ext2-mountpoint
1471         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1472         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error
1473         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1474 }
1475 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1476
1477 test_32b() {
1478         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1479         mkdir -p $DIR/d32b/ext2-mountpoint
1480         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1481         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1482         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1483 }
1484 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1485
1486 test_32c() {
1487         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1488         mkdir -p $DIR/d32c/ext2-mountpoint
1489         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1490         mkdir -p $DIR/d32c/d2/test_dir
1491         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1492         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1493 }
1494 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1495
1496 test_32d() {
1497         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1498         mkdir -p $DIR/d32d/ext2-mountpoint
1499         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1500         mkdir -p $DIR/d32d/d2/test_dir
1501         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1502         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1503 }
1504 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1505
1506 test_32e() {
1507         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1508         mkdir -p $DIR/d32e/tmp
1509         TMP_DIR=$DIR/d32e/tmp
1510         ln -s $DIR/d32e $TMP_DIR/symlink11
1511         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1512         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1513         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1514 }
1515 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1516
1517 test_32f() {
1518         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1519         mkdir -p $DIR/d32f/tmp
1520         TMP_DIR=$DIR/d32f/tmp
1521         ln -s $DIR/d32f $TMP_DIR/symlink11
1522         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1523         ls $DIR/d32f/tmp/symlink11  || error
1524         ls $DIR/d32f/symlink01 || error
1525 }
1526 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1527
1528 test_32g() {
1529         TMP_DIR=$DIR/$tdir/tmp
1530         mkdir -p $TMP_DIR $DIR/${tdir}2
1531         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1532         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1533         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1534         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1535         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1536         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1537 }
1538 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1539
1540 test_32h() {
1541         rm -fr $DIR/$tdir $DIR/${tdir}2
1542         TMP_DIR=$DIR/$tdir/tmp
1543         mkdir -p $TMP_DIR $DIR/${tdir}2
1544         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1545         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1546         ls $TMP_DIR/symlink12 || error
1547         ls $DIR/$tdir/symlink02  || error
1548 }
1549 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1550
1551 test_32i() {
1552         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1553         mkdir -p $DIR/d32i/ext2-mountpoint
1554         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1555         touch $DIR/d32i/test_file
1556         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error
1557         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1558 }
1559 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1560
1561 test_32j() {
1562         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1563         mkdir -p $DIR/d32j/ext2-mountpoint
1564         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1565         touch $DIR/d32j/test_file
1566         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1567         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1568 }
1569 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1570
1571 test_32k() {
1572         rm -fr $DIR/d32k
1573         mkdir -p $DIR/d32k/ext2-mountpoint
1574         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint
1575         mkdir -p $DIR/d32k/d2
1576         touch $DIR/d32k/d2/test_file || error
1577         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1578         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1579 }
1580 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1581
1582 test_32l() {
1583         rm -fr $DIR/d32l
1584         mkdir -p $DIR/d32l/ext2-mountpoint
1585         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1586         mkdir -p $DIR/d32l/d2
1587         touch $DIR/d32l/d2/test_file
1588         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1589         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1590 }
1591 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1592
1593 test_32m() {
1594         rm -fr $DIR/d32m
1595         mkdir -p $DIR/d32m/tmp
1596         TMP_DIR=$DIR/d32m/tmp
1597         ln -s $DIR $TMP_DIR/symlink11
1598         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1599         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1600         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1601 }
1602 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1603
1604 test_32n() {
1605         rm -fr $DIR/d32n
1606         mkdir -p $DIR/d32n/tmp
1607         TMP_DIR=$DIR/d32n/tmp
1608         ln -s $DIR $TMP_DIR/symlink11
1609         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1610         ls -l $DIR/d32n/tmp/symlink11  || error
1611         ls -l $DIR/d32n/symlink01 || error
1612 }
1613 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1614
1615 test_32o() {
1616         rm -fr $DIR/d32o $DIR/$tfile
1617         touch $DIR/$tfile
1618         mkdir -p $DIR/d32o/tmp
1619         TMP_DIR=$DIR/d32o/tmp
1620         ln -s $DIR/$tfile $TMP_DIR/symlink12
1621         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1622         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1623         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1624         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1625         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1626 }
1627 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1628
1629 test_32p() {
1630     log 32p_1
1631         rm -fr $DIR/d32p
1632     log 32p_2
1633         rm -f $DIR/$tfile
1634     log 32p_3
1635         touch $DIR/$tfile
1636     log 32p_4
1637         mkdir -p $DIR/d32p/tmp
1638     log 32p_5
1639         TMP_DIR=$DIR/d32p/tmp
1640     log 32p_6
1641         ln -s $DIR/$tfile $TMP_DIR/symlink12
1642     log 32p_7
1643         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1644     log 32p_8
1645         cat $DIR/d32p/tmp/symlink12 || error
1646     log 32p_9
1647         cat $DIR/d32p/symlink02 || error
1648     log 32p_10
1649 }
1650 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1651
1652 test_32q() {
1653         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1654         mkdir -p $DIR/d32q
1655         touch $DIR/d32q/under_the_mount
1656         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1657         ls $DIR/d32q/under_the_mount && error || true
1658         $UMOUNT $DIR/d32q || error
1659 }
1660 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1661
1662 test_32r() {
1663         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1664         mkdir -p $DIR/d32r
1665         touch $DIR/d32r/under_the_mount
1666         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1667         ls $DIR/d32r | grep -q under_the_mount && error || true
1668         $UMOUNT $DIR/d32r || error
1669 }
1670 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1671
1672 test_33() {
1673         rm -f $DIR/$tfile
1674         touch $DIR/$tfile
1675         chmod 444 $DIR/$tfile
1676         chown $RUNAS_ID $DIR/$tfile
1677         log 33_1
1678         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1679         log 33_2
1680 }
1681 run_test 33 "write file with mode 444 (should return error) ===="
1682
1683 test_33a() {
1684         rm -fr $DIR/d33
1685         mkdir -p $DIR/d33
1686         chown $RUNAS_ID $DIR/d33
1687         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1688         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1689                 error "open RDWR" || true
1690 }
1691 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1692
1693 test_33b() {
1694         rm -fr $DIR/d33
1695         mkdir -p $DIR/d33
1696         chown $RUNAS_ID $DIR/d33
1697         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
1698 }
1699 run_test 33b "test open file with malformed flags (No panic and return error)"
1700
1701 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1702 test_34a() {
1703         rm -f $DIR/f34
1704         $MCREATE $DIR/f34 || error
1705         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1706         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1707         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1708         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1709 }
1710 run_test 34a "truncate file that has not been opened ==========="
1711
1712 test_34b() {
1713         [ ! -f $DIR/f34 ] && test_34a
1714         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1715         $OPENFILE -f O_RDONLY $DIR/f34
1716         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1717         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1718 }
1719 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1720
1721 test_34c() {
1722         [ ! -f $DIR/f34 ] && test_34a
1723         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1724         $OPENFILE -f O_RDWR $DIR/f34
1725         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
1726         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1727 }
1728 run_test 34c "O_RDWR opening file-with-size works =============="
1729
1730 test_34d() {
1731         [ ! -f $DIR/f34 ] && test_34a
1732         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1733         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1734         rm $DIR/f34
1735 }
1736 run_test 34d "write to sparse file ============================="
1737
1738 test_34e() {
1739         rm -f $DIR/f34e
1740         $MCREATE $DIR/f34e || error
1741         $TRUNCATE $DIR/f34e 1000 || error
1742         $CHECKSTAT -s 1000 $DIR/f34e || error
1743         $OPENFILE -f O_RDWR $DIR/f34e
1744         $CHECKSTAT -s 1000 $DIR/f34e || error
1745 }
1746 run_test 34e "create objects, some with size and some without =="
1747
1748 test_34f() { # bug 6242, 6243
1749         SIZE34F=48000
1750         rm -f $DIR/f34f
1751         $MCREATE $DIR/f34f || error
1752         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
1753         dd if=$DIR/f34f of=$TMP/f34f
1754         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
1755         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
1756         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
1757         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
1758         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
1759 }
1760 run_test 34f "read from a file with no objects until EOF ======="
1761
1762 test_35a() {
1763         cp /bin/sh $DIR/f35a
1764         chmod 444 $DIR/f35a
1765         chown $RUNAS_ID $DIR/f35a
1766         $RUNAS $DIR/f35a && error || true
1767         rm $DIR/f35a
1768 }
1769 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1770
1771 test_36a() {
1772         rm -f $DIR/f36
1773         utime $DIR/f36 || error
1774 }
1775 run_test 36a "MDS utime check (mknod, utime) ==================="
1776
1777 test_36b() {
1778         echo "" > $DIR/f36
1779         utime $DIR/f36 || error
1780 }
1781 run_test 36b "OST utime check (open, utime) ===================="
1782
1783 test_36c() {
1784         rm -f $DIR/d36/f36
1785         mkdir $DIR/d36
1786         chown $RUNAS_ID $DIR/d36
1787         $RUNAS utime $DIR/d36/f36 || error
1788 }
1789 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1790
1791 test_36d() {
1792         [ ! -d $DIR/d36 ] && test_36c
1793         echo "" > $DIR/d36/f36
1794         $RUNAS utime $DIR/d36/f36 || error
1795 }
1796 run_test 36d "non-root OST utime check (open, utime) ==========="
1797
1798 test_36e() {
1799         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
1800         mkdir -p $DIR/$tdir
1801         touch $DIR/$tdir/$tfile
1802         $RUNAS utime $DIR/$tdir/$tfile && \
1803                 error "utime worked, expected failure" || true
1804 }
1805 run_test 36e "utime on non-owned file (should return error) ===="
1806
1807 test_36f() {
1808         export LANG=C LC_LANG=C # for date language
1809
1810         DATESTR="Dec 20  2000"
1811         mkdir -p $DIR/$tdir
1812         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1813         lctl set_param fail_loc=0x80000214
1814         date; date +%s
1815         cp /etc/hosts $DIR/$tdir/$tfile
1816         sync & # write RPC generated with "current" inode timestamp, but delayed
1817         sleep 1
1818         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
1819         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
1820         cancel_lru_locks osc
1821         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
1822         date; date +%s
1823         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
1824                 echo "BEFORE: $LS_BEFORE" && \
1825                 echo "AFTER : $LS_AFTER" && \
1826                 echo "WANT  : $DATESTR" && \
1827                 error "$DIR/$tdir/$tfile timestamps changed" || true
1828 }
1829 run_test 36f "utime on file racing with OST BRW write =========="
1830
1831 test_36g() {
1832         remote_ost_nodsh && skip "remote OST with nodsh" && return
1833
1834         mkdir -p $DIR/$tdir
1835         export FMD_MAX_AGE=`do_facet ost1 lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | head -n 1`
1836         FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1837         touch $DIR/$tdir/$tfile
1838         sleep $((FMD_MAX_AGE + 12))
1839         FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1840         [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
1841                 echo "AFTER : $FMD_AFTER > BEFORE $FMD_BEFORE" && \
1842                 error "fmd didn't expire after ping" || true
1843 }
1844 run_test 36g "filter mod data cache expiry ====================="
1845
1846 test_37() {
1847         mkdir -p $DIR/$tdir
1848         echo f > $DIR/$tdir/fbugfile
1849         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
1850         ls $DIR/$tdir | grep "\<fbugfile\>" && error
1851         $UMOUNT $DIR/$tdir || error
1852         rm -f $DIR/$tdir/fbugfile || error
1853 }
1854 run_test 37 "ls a mounted file system to check old content ====="
1855
1856 test_38() {
1857         local file=$DIR/$tfile
1858         touch $file
1859         openfile -f O_DIRECTORY $file
1860         local RC=$?
1861         local ENOTDIR=20
1862         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
1863         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
1864 }
1865 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
1866
1867 test_39() {
1868         touch $DIR/$tfile
1869         touch $DIR/${tfile}2
1870 #       ls -l  $DIR/$tfile $DIR/${tfile}2
1871 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
1872 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
1873         sleep 2
1874         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
1875         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
1876                 echo "mtime"
1877                 ls -l  $DIR/$tfile $DIR/${tfile}2
1878                 echo "atime"
1879                 ls -lu  $DIR/$tfile $DIR/${tfile}2
1880                 echo "ctime"
1881                 ls -lc  $DIR/$tfile $DIR/${tfile}2
1882                 error "O_TRUNC didn't change timestamps"
1883         fi
1884 }
1885 run_test 39 "mtime changed on create ==========================="
1886
1887 test_40() {
1888         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1889         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1890         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1891 }
1892 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1893
1894 test_41() {
1895         # bug 1553
1896         small_write $DIR/f41 18
1897 }
1898 run_test 41 "test small file write + fstat ====================="
1899
1900 count_ost_writes() {
1901         lctl get_param -n osc.*.stats |
1902             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1903 }
1904
1905 # decent default
1906 WRITEBACK_SAVE=500
1907 DIRTY_RATIO_SAVE=40
1908 MAX_DIRTY_RATIO=50
1909 BG_DIRTY_RATIO_SAVE=10
1910 MAX_BG_DIRTY_RATIO=25
1911
1912 start_writeback() {
1913         trap 0
1914         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
1915         # dirty_ratio, dirty_background_ratio
1916         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1917                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
1918                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
1919                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
1920         else
1921                 # if file not here, we are a 2.4 kernel
1922                 kill -CONT `pidof kupdated`
1923         fi
1924 }
1925
1926 stop_writeback() {
1927         # setup the trap first, so someone cannot exit the test at the
1928         # exact wrong time and mess up a machine
1929         trap start_writeback EXIT
1930         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1931         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1932                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
1933                 sysctl -w vm.dirty_writeback_centisecs=0
1934                 sysctl -w vm.dirty_writeback_centisecs=0
1935                 # save and increase /proc/sys/vm/dirty_ratio
1936                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
1937                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
1938                 # save and increase /proc/sys/vm/dirty_background_ratio
1939                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
1940                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
1941         else
1942                 # if file not here, we are a 2.4 kernel
1943                 kill -STOP `pidof kupdated`
1944         fi
1945 }
1946
1947 # ensure that all stripes have some grant before we test client-side cache
1948 setup_test42() {
1949         [ "$SETUP_TEST42" ] && return
1950         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1951                 dd if=/dev/zero of=$i bs=4k count=1
1952                 rm $i
1953         done
1954         SETUP_TEST42=DONE
1955 }
1956
1957 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1958 # file truncation, and file removal.
1959 test_42a() {
1960         setup_test42
1961         cancel_lru_locks osc
1962         stop_writeback
1963         sync; sleep 1; sync # just to be safe
1964         BEFOREWRITES=`count_ost_writes`
1965         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
1966         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1967         AFTERWRITES=`count_ost_writes`
1968         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1969                 error "$BEFOREWRITES < $AFTERWRITES"
1970         start_writeback
1971 }
1972 run_test 42a "ensure that we don't flush on close =============="
1973
1974 test_42b() {
1975         setup_test42
1976         cancel_lru_locks osc
1977         stop_writeback
1978         sync
1979         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1980         BEFOREWRITES=`count_ost_writes`
1981         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1982         AFTERWRITES=`count_ost_writes`
1983         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1984                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
1985         fi
1986         BEFOREWRITES=`count_ost_writes`
1987         sync || error "sync: $?"
1988         AFTERWRITES=`count_ost_writes`
1989         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1990                 error "$BEFOREWRITES < $AFTERWRITES on sync"
1991         fi
1992         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1993         start_writeback
1994         return 0
1995 }
1996 run_test 42b "test destroy of file with cached dirty data ======"
1997
1998 # if these tests just want to test the effect of truncation,
1999 # they have to be very careful.  consider:
2000 # - the first open gets a {0,EOF}PR lock
2001 # - the first write conflicts and gets a {0, count-1}PW
2002 # - the rest of the writes are under {count,EOF}PW
2003 # - the open for truncate tries to match a {0,EOF}PR
2004 #   for the filesize and cancels the PWs.
2005 # any number of fixes (don't get {0,EOF} on open, match
2006 # composite locks, do smarter file size management) fix
2007 # this, but for now we want these tests to verify that
2008 # the cancellation with truncate intent works, so we
2009 # start the file with a full-file pw lock to match against
2010 # until the truncate.
2011 trunc_test() {
2012         test=$1
2013         file=$DIR/$test
2014         offset=$2
2015         cancel_lru_locks osc
2016         stop_writeback
2017         # prime the file with 0,EOF PW to match
2018         touch $file
2019         $TRUNCATE $file 0
2020         sync; sync
2021         # now the real test..
2022         dd if=/dev/zero of=$file bs=1024 count=100
2023         BEFOREWRITES=`count_ost_writes`
2024         $TRUNCATE $file $offset
2025         cancel_lru_locks osc
2026         AFTERWRITES=`count_ost_writes`
2027         start_writeback
2028 }
2029
2030 test_42c() {
2031         trunc_test 42c 1024
2032         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
2033             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
2034         rm $file
2035 }
2036 run_test 42c "test partial truncate of file with cached dirty data"
2037
2038 test_42d() {
2039         trunc_test 42d 0
2040         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
2041             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
2042         rm $file
2043 }
2044 run_test 42d "test complete truncate of file with cached dirty data"
2045
2046 test_43() {
2047         mkdir -p $DIR/$tdir
2048         cp -p /bin/ls $DIR/$tdir/$tfile
2049         multiop $DIR/$tdir/$tfile Ow_c &
2050         pid=$!
2051         # give multiop a chance to open
2052         sleep 1
2053
2054         $DIR/$tdir/$tfile && error || true
2055         kill -USR1 $pid
2056 }
2057 run_test 43 "execution of file opened for write should return -ETXTBSY"
2058
2059 test_43a() {
2060         mkdir -p $DIR/d43
2061         cp -p `which multiop` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2062         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2063         MULTIOP_PID=$!
2064         multiop $DIR/d43/multiop Oc && error "expected error, got success"
2065         kill -USR1 $MULTIOP_PID || return 2
2066         wait $MULTIOP_PID || return 3
2067         rm $TMP/test43.junk
2068 }
2069 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
2070
2071 test_43b() {
2072         mkdir -p $DIR/d43
2073         cp -p `which multiop` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2074         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2075         MULTIOP_PID=$!
2076         truncate $DIR/d43/multiop 0 && error "expected error, got success"
2077         kill -USR1 $MULTIOP_PID || return 2
2078         wait $MULTIOP_PID || return 3
2079         rm $TMP/test43.junk
2080 }
2081 run_test 43b "truncate of file being executed should return -ETXTBSY"
2082
2083 test_43c() {
2084         local testdir="$DIR/d43c"
2085         mkdir -p $testdir
2086         cp $SHELL $testdir/
2087         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
2088                 ( cd $testdir && md5sum -c)
2089 }
2090 run_test 43c "md5sum of copy into lustre========================"
2091
2092 test_44() {
2093         [  "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
2094         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
2095         dd if=$DIR/f1 bs=4k count=1 > /dev/null
2096 }
2097 run_test 44 "zero length read from a sparse stripe ============="
2098
2099 test_44a() {
2100     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
2101                          awk '{print $2}'`
2102     [ -z "$nstripe" ] && skip "can't get stripe info" && return
2103     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
2104     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
2105                       awk '{print $2}'`
2106     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
2107         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
2108     fi
2109
2110     OFFSETS="0 $((stride/2)) $((stride-1))"
2111     for offset in $OFFSETS ; do
2112       for i in `seq 0 $((nstripe-1))`; do
2113         local GLOBALOFFSETS=""
2114         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
2115         local myfn=$DIR/d44a-$size
2116         echo "--------writing $myfn at $size"
2117         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
2118         GLOBALOFFSETS="$GLOBALOFFSETS $size"
2119         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2120                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2121
2122         for j in `seq 0 $((nstripe-1))`; do
2123             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
2124             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
2125             GLOBALOFFSETS="$GLOBALOFFSETS $size"
2126         done
2127         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2128                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2129         rm -f $myfn
2130       done
2131     done
2132 }
2133 run_test 44a "test sparse pwrite ==============================="
2134
2135 dirty_osc_total() {
2136         tot=0
2137         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
2138                 tot=$(($tot + $d))
2139         done
2140         echo $tot
2141 }
2142 do_dirty_record() {
2143         before=`dirty_osc_total`
2144         echo executing "\"$*\""
2145         eval $*
2146         after=`dirty_osc_total`
2147         echo before $before, after $after
2148 }
2149 test_45() {
2150         f="$DIR/f45"
2151         # Obtain grants from OST if it supports it
2152         echo blah > ${f}_grant
2153         stop_writeback
2154         sync
2155         do_dirty_record "echo blah > $f"
2156         [ $before -eq $after ] && error "write wasn't cached"
2157         do_dirty_record "> $f"
2158         [ $before -gt $after ] || error "truncate didn't lower dirty count"
2159         do_dirty_record "echo blah > $f"
2160         [ $before -eq $after ] && error "write wasn't cached"
2161         do_dirty_record "sync"
2162         [ $before -gt $after ] || error "writeback didn't lower dirty count"
2163         do_dirty_record "echo blah > $f"
2164         [ $before -eq $after ] && error "write wasn't cached"
2165         do_dirty_record "cancel_lru_locks osc"
2166         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
2167         start_writeback
2168 }
2169 run_test 45 "osc io page accounting ============================"
2170
2171 page_size() {
2172         getconf PAGE_SIZE
2173 }
2174
2175 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
2176 # test tickles a bug where re-dirtying a page was failing to be mapped to the
2177 # objects offset and an assert hit when an rpc was built with 1023's mapped
2178 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
2179 test_46() {
2180         f="$DIR/f46"
2181         stop_writeback
2182         sync
2183         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2184         sync
2185         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
2186         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2187         sync
2188         start_writeback
2189 }
2190 run_test 46 "dirtying a previously written page ================"
2191
2192 # test_47 is removed "Device nodes check" is moved to test_28
2193
2194 test_48a() { # bug 2399
2195         check_kernel_version 34 || return 0
2196         mkdir -p $DIR/d48a
2197         cd $DIR/d48a
2198         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
2199         mkdir $DIR/d48a || error "recreate directory failed"
2200         touch foo || error "'touch foo' failed after recreating cwd"
2201         mkdir bar || error "'mkdir foo' failed after recreating cwd"
2202         if check_kernel_version 44; then
2203                 touch .foo || error "'touch .foo' failed after recreating cwd"
2204                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
2205         fi
2206         ls . > /dev/null || error "'ls .' failed after recreating cwd"
2207         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2208         cd . || error "'cd .' failed after recreating cwd"
2209         mkdir . && error "'mkdir .' worked after recreating cwd"
2210         rmdir . && error "'rmdir .' worked after recreating cwd"
2211         ln -s . baz || error "'ln -s .' failed after recreating cwd"
2212         cd .. || error "'cd ..' failed after recreating cwd"
2213 }
2214 run_test 48a "Access renamed working dir (should return errors)="
2215
2216 test_48b() { # bug 2399
2217         check_kernel_version 34 || return 0
2218         mkdir -p $DIR/d48b
2219         cd $DIR/d48b
2220         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
2221         touch foo && error "'touch foo' worked after removing cwd"
2222         mkdir foo && error "'mkdir foo' worked after removing cwd"
2223         if check_kernel_version 44; then
2224                 touch .foo && error "'touch .foo' worked after removing cwd"
2225                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2226         fi
2227         ls . > /dev/null && error "'ls .' worked after removing cwd"
2228         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
2229         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
2230         mkdir . && error "'mkdir .' worked after removing cwd"
2231         rmdir . && error "'rmdir .' worked after removing cwd"
2232         ln -s . foo && error "'ln -s .' worked after removing cwd"
2233         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
2234 }
2235 run_test 48b "Access removed working dir (should return errors)="
2236
2237 test_48c() { # bug 2350
2238         check_kernel_version 36 || return 0
2239         #lctl set_param debug=-1
2240         #set -vx
2241         mkdir -p $DIR/d48c/dir
2242         cd $DIR/d48c/dir
2243         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
2244         $TRACE touch foo && error "'touch foo' worked after removing cwd"
2245         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
2246         if check_kernel_version 44; then
2247                 touch .foo && error "'touch .foo' worked after removing cwd"
2248                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2249         fi
2250         $TRACE ls . && error "'ls .' worked after removing cwd"
2251         $TRACE ls .. || error "'ls ..' failed after removing cwd"
2252         is_patchless || ( $TRACE cd . && error "'cd .' worked after removing cwd" )
2253         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
2254         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
2255         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
2256         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2257 }
2258 run_test 48c "Access removed working subdir (should return errors)"
2259
2260 test_48d() { # bug 2350
2261         check_kernel_version 36 || return 0
2262         #lctl set_param debug=-1
2263         #set -vx
2264         mkdir -p $DIR/d48d/dir
2265         cd $DIR/d48d/dir
2266         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2267         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
2268         $TRACE touch foo && error "'touch foo' worked after removing parent"
2269         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
2270         if check_kernel_version 44; then
2271                 touch .foo && error "'touch .foo' worked after removing parent"
2272                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
2273         fi
2274         $TRACE ls . && error "'ls .' worked after removing parent"
2275         $TRACE ls .. && error "'ls ..' worked after removing parent"
2276         is_patchless || ( $TRACE cd . && error "'cd .' worked after recreate parent" )
2277         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
2278         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
2279         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
2280         is_patchless || ( $TRACE cd .. && error "'cd ..' worked after removing parent" || true )
2281 }
2282 run_test 48d "Access removed parent subdir (should return errors)"
2283
2284 test_48e() { # bug 4134
2285         check_kernel_version 41 || return 0
2286         #lctl set_param debug=-1
2287         #set -vx
2288         mkdir -p $DIR/d48e/dir
2289         cd $DIR/d48e/dir
2290         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
2291         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
2292         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
2293         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
2294         # On a buggy kernel addition of "touch foo" after cd .. will
2295         # produce kernel oops in lookup_hash_it
2296         touch ../foo && error "'cd ..' worked after recreate parent"
2297         cd $DIR
2298         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
2299 }
2300 run_test 48e "Access to recreated parent subdir (should return errors)"
2301
2302 test_50() {
2303         # bug 1485
2304         mkdir $DIR/d50
2305         cd $DIR/d50
2306         ls /proc/$$/cwd || error
2307 }
2308 run_test 50 "special situations: /proc symlinks  ==============="
2309
2310 test_51a() {    # was test_51
2311         # bug 1516 - create an empty entry right after ".." then split dir
2312         mkdir $DIR/d51
2313         touch $DIR/d51/foo
2314         $MCREATE $DIR/d51/bar
2315         rm $DIR/d51/foo
2316         createmany -m $DIR/d51/longfile 201
2317         FNUM=202
2318         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
2319                 $MCREATE $DIR/d51/longfile$FNUM
2320                 FNUM=$(($FNUM + 1))
2321                 echo -n "+"
2322         done
2323         echo
2324         ls -l $DIR/d51 > /dev/null || error
2325 }
2326 run_test 51a "special situations: split htree with empty entry =="
2327
2328 #export NUMTEST=70000
2329 # FIXME: I select a relatively small number to do basic test.
2330 # large number may give panic(). debugging on this is going on.
2331 export NUMTEST=70
2332 test_51b() {
2333         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2334         [ $NUMFREE -lt 21000 ] && \
2335                 skip "not enough free inodes ($NUMFREE)" && \
2336                 return
2337
2338         check_kernel_version 40 || NUMTEST=31000
2339         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
2340
2341         mkdir -p $DIR/d51b
2342         createmany -d $DIR/d51b/t- $NUMTEST
2343 }
2344 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
2345
2346 test_51bb() {
2347         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2348
2349         local ndirs=${TEST51BB_NDIRS:-10}
2350         local nfiles=${TEST51BB_NFILES:-100}
2351
2352         local numfree=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2353
2354         [ $numfree -lt $(( ndirs * nfiles)) ] && \
2355                 nfiles=$(( numfree / ndirs - 10 ))
2356
2357         local dir=$DIR/d51bb
2358         mkdir -p $dir
2359         local savePOLICY=$(lctl get_param -n lmv.*.placement)
2360         lctl set_param -n lmv.*.placement=CHAR
2361
2362         lfs df -i $dir
2363         local IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
2364         OLDUSED=($IUSED)
2365
2366         declare -a dirs
2367         for ((i=0; i < $ndirs; i++)); do
2368                 dirs[i]=$dir/$RANDOM
2369                 echo Creating directory ${dirs[i]}
2370                 mkdir -p ${dirs[i]}
2371                 ls $dir
2372                 echo Creating $nfiles in dir ${dirs[i]} ...
2373                 echo "createmany -o ${dirs[i]}/$tfile- $nfiles"
2374                 createmany -o ${dirs[i]}/$tfile- $nfiles
2375         done
2376         ls $dir
2377
2378         sleep 1
2379
2380         IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
2381         NEWUSED=($IUSED)
2382
2383         local rc=0
2384         for ((i=0; i<${#NEWUSED[@]}; i++)); do
2385                 echo "mds $i: inodes count OLD ${OLDUSED[$i]} NEW ${NEWUSED[$i]}"
2386                 [ ${OLDUSED[$i]} -lt ${NEWUSED[$i]} ] || rc=$((rc + 1))
2387         done
2388
2389         lctl set_param -n lmv.*.placement=$savePOLICY
2390
2391         [ $rc -ne $MDSCOUNT ] || \
2392                 error "Objects/inodes are not distributed over all mds servers"
2393 }
2394 run_test 51bb "mkdir createmany CMD $MDSCOUNT  ===================="
2395
2396
2397 test_51c() {
2398         [ ! -d $DIR/d51b ] && skip "$DIR/51b missing" && \
2399                 return
2400
2401         unlinkmany -d $DIR/d51b/t- $NUMTEST
2402 }
2403 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
2404
2405 test_51d() {
2406         [  "$OSTCOUNT" -lt "3" ] && skip "skipping test with few OSTs" && return
2407         mkdir -p $DIR/d51d
2408         createmany -o $DIR/d51d/t- 1000
2409         $LFS getstripe $DIR/d51d > $TMP/files
2410         for N in `seq 0 $((OSTCOUNT - 1))`; do
2411             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
2412             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
2413             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
2414         done
2415         unlinkmany $DIR/d51d/t- 1000
2416
2417         NLAST=0
2418         for N in `seq 1 $((OSTCOUNT - 1))`; do
2419             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
2420                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2421             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
2422                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2423
2424             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
2425                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2426             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
2427                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2428             NLAST=$N
2429         done
2430 }
2431 run_test 51d "check object distribution ===================="
2432
2433 test_52a() {
2434         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
2435         mkdir -p $DIR/d52a
2436         touch $DIR/d52a/foo
2437         chattr +a $DIR/d52a/foo || error "chattr +a failed"
2438         echo bar >> $DIR/d52a/foo || error "append bar failed"
2439         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
2440         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
2441         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
2442         echo foo >> $DIR/d52a/foo || error "append foo failed"
2443         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
2444         lsattr $DIR/d52a/foo | egrep -q "^-+[ae]-+ $DIR/d52a/foo" || error "lsattr"
2445         chattr -a $DIR/d52a/foo || error "chattr -a failed"
2446         cp -r $DIR/d52a /tmp/
2447         rm -fr $DIR/d52a || error "cleanup rm failed"
2448 }
2449 run_test 52a "append-only flag test (should return errors) ====="
2450
2451 test_52b() {
2452         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
2453         mkdir -p $DIR/d52b
2454         touch $DIR/d52b/foo
2455         chattr +i $DIR/d52b/foo || error "chattr +i failed"
2456         cat test > $DIR/d52b/foo && error "cat test worked"
2457         cp /etc/hosts $DIR/d52b/foo && error "cp worked"
2458         rm -f $DIR/d52b/foo 2>/dev/null && error "rm worked"
2459         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error  "link worked"
2460         echo foo >> $DIR/d52b/foo && error "echo worked"
2461         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error "rename worked"
2462         [ -f $DIR/d52b/foo ] || error
2463         [ -f $DIR/d52b/foo_ren ] && error
2464         lsattr $DIR/d52b/foo | egrep -q "^-+[ie]-+ $DIR/d52b/foo" || error "lsattr"
2465         chattr -i $DIR/d52b/foo || error "chattr failed"
2466
2467         rm -fr $DIR/d52b || error
2468 }
2469 run_test 52b "immutable flag test (should return errors) ======="
2470
2471 test_53() {
2472         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2473         remote_ost_nodsh && skip "remote OST with nodsh" && return
2474
2475         local param
2476         local ostname
2477         local mds_last
2478         local ost_last
2479         local ostnum
2480
2481         # only test MDT0000
2482         for value in $(do_facet $SINGLEMDS lctl get_param osc.*-osc-MDT0000.prealloc_last_id) ; do
2483                 param=`echo ${value[0]} | cut -d "=" -f1`
2484                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
2485                 mds_last=$(do_facet $SINGLEMDS lctl get_param -n $param)
2486                 ostnum=$(echo $ostname | sed "s/${FSNAME}-OST//g" | awk '{print ($1+1)}' )
2487                 ost_last=$(do_facet ost$ostnum lctl get_param -n obdfilter.$ostname.last_id | head -n 1)
2488                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2489                 if [ $ost_last != $mds_last ]; then
2490                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2491                 fi
2492         done
2493 }
2494 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
2495
2496 test_54a() {
2497         [ ! -f "$SOCKETSERVER" ] && skip "no socketserver, skipping" && return
2498         [ ! -f "$SOCKETCLIENT" ] && skip "no socketclient, skipping" && return
2499         $SOCKETSERVER $DIR/socket
2500         $SOCKETCLIENT $DIR/socket || error
2501         $MUNLINK $DIR/socket
2502 }
2503 run_test 54a "unix domain socket test =========================="
2504
2505 test_54b() {
2506         f="$DIR/f54b"
2507         mknod $f c 1 3
2508         chmod 0666 $f
2509         dd if=/dev/zero of=$f bs=`page_size` count=1
2510 }
2511 run_test 54b "char device works in lustre ======================"
2512
2513 find_loop_dev() {
2514         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
2515         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
2516         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
2517
2518         for i in `seq 3 7`; do
2519                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
2520                 LOOPDEV=$LOOPBASE$i
2521                 LOOPNUM=$i
2522                 break
2523         done
2524 }
2525
2526 test_54c() {
2527         tfile="$DIR/f54c"
2528         tdir="$DIR/d54c"
2529         loopdev="$DIR/loop54c"
2530
2531         find_loop_dev
2532         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
2533         mknod $loopdev b 7 $LOOPNUM
2534         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
2535         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
2536         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
2537         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
2538         mkdir -p $tdir
2539         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
2540         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
2541         df $tdir
2542         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
2543         $UMOUNT $tdir
2544         losetup -d $loopdev
2545         rm $loopdev
2546 }
2547 run_test 54c "block device works in lustre ====================="
2548
2549 test_54d() {
2550         f="$DIR/f54d"
2551         string="aaaaaa"
2552         mknod $f p
2553         [ "$string" = `echo $string > $f | cat $f` ] || error
2554 }
2555 run_test 54d "fifo device works in lustre ======================"
2556
2557 test_54e() {
2558         check_kernel_version 46 || return 0
2559         f="$DIR/f54e"
2560         string="aaaaaa"
2561         cp -aL /dev/console $f
2562         echo $string > $f || error
2563 }
2564 run_test 54e "console/tty device works in lustre ======================"
2565
2566 check_fstype() {
2567         grep -q $FSTYPE /proc/filesystems && return 1
2568         modprobe $FSTYPE
2569         grep -q $FSTYPE /proc/filesystems && return 1
2570         insmod ../$FSTYPE/$FSTYPE.o
2571         grep -q $FSTYPE /proc/filesystems && return 1
2572         insmod ../$FSTYPE/$FSTYPE.ko
2573         grep -q $FSTYPE /proc/filesystems && return 1
2574         return 0
2575 }
2576
2577 test_55() {
2578         rm -rf $DIR/d55
2579         mkdir $DIR/d55
2580         check_fstype && skip "can't find fs $FSTYPE" && return
2581         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
2582         touch $DIR/d55/foo
2583         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
2584         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
2585         echo "check for $EXT2_DEV. Please wait..."
2586         rm -rf $DIR/d55/*
2587         $UMOUNT $DIR/d55 || error "unmounting"
2588 }
2589 run_test 55 "check iopen_connect_dentry() ======================"
2590
2591 test_56a() {    # was test_56
2592         rm -rf $DIR/d56
2593         $SETSTRIPE -d $DIR
2594         mkdir $DIR/d56
2595         mkdir $DIR/d56/dir
2596         NUMFILES=3
2597         NUMFILESx2=$(($NUMFILES * 2))
2598         for i in `seq 1 $NUMFILES` ; do
2599                 touch $DIR/d56/file$i
2600                 touch $DIR/d56/dir/file$i
2601         done
2602
2603         # test lfs getstripe with --recursive
2604         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
2605         [ $FILENUM -eq $NUMFILESx2 ] || error \
2606                 "lfs getstripe --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
2607         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
2608         [ $FILENUM -eq $NUMFILES ] || error \
2609                 "lfs getstripe $DIR/d56 without --recursive wrong: found $FILENUM, expected $NUMFILES"
2610         echo "lfs getstripe --recursive passed."
2611
2612         # test lfs getstripe with file instead of dir
2613         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
2614         [ $FILENUM  -eq 1 ] || error \
2615                  "lfs getstripe $DIR/d56/file1 wrong:found $FILENUM, expected 1"
2616         echo "lfs getstripe file passed."
2617
2618         #test lfs getstripe with --verbose
2619         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||\
2620                 error "lfs getstripe --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2621         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] || error \
2622                 "lfs getstripe $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2623         echo "lfs getstripe --verbose passed."
2624
2625         #test lfs getstripe with --obd
2626         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2627                 error "lfs getstripe --obd wrong_uuid should return error message"
2628
2629         [  "$OSTCOUNT" -lt 2 ] && \
2630                 skip "skipping other lfs getstripe --obd test" && return
2631         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1[    ]/p' | wc -l`
2632         OBDUUID=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1:/p' | awk '{print $2}'`
2633         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | wc -l`
2634         [ $FOUND -eq $FILENUM ] || \
2635                 error "lfs getstripe --obd wrong: found $FOUND, expected $FILENUM"
2636         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 | sed '/^[   ]*1[    ]/d' |\
2637                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] || \
2638                 error "lfs getstripe --obd wrong: should not show file on other obd"
2639         echo "lfs getstripe --obd passed."
2640 }
2641 run_test 56a "check lfs getstripe ===================================="
2642
2643 NUMFILES=3
2644 NUMDIRS=3
2645 setup_56() {
2646         LOCAL_NUMFILES=$1
2647         LOCAL_NUMDIRS=$2
2648         if [ ! -d "$DIR/${tdir}g" ] ; then
2649                 mkdir -p $DIR/${tdir}g
2650                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2651                         touch $DIR/${tdir}g/file$i
2652                 done
2653                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2654                         mkdir $DIR/${tdir}g/dir$i
2655                         for j in `seq 1 $LOCAL_NUMFILES` ; do
2656                                 touch $DIR/${tdir}g/dir$i/file$j
2657                         done
2658                 done
2659         fi
2660 }
2661
2662 setup_56_special() {
2663         LOCAL_NUMFILES=$1
2664         LOCAL_NUMDIRS=$2
2665         TDIR=$DIR/${tdir}g
2666         setup_56 $1 $2
2667         if [ ! -e "$TDIR/loop1b" ] ; then
2668                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2669                         mknod $TDIR/loop${i}b b 7 $i
2670                         mknod $TDIR/null${i}c c 1 3
2671                         ln -s $TDIR/file1 $TDIR/link${i}l
2672                 done
2673                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2674                         mknod $TDIR/dir$i/loop${i}b b 7 $i
2675                         mknod $TDIR/dir$i/null${i}c c 1 3
2676                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
2677                 done
2678         fi
2679 }
2680
2681 test_56g() {
2682         $LSTRIPE -d $DIR
2683
2684         setup_56 $NUMFILES $NUMDIRS
2685
2686         EXPECTED=$(($NUMDIRS + 2))
2687         # test lfs find with -name
2688         for i in `seq 1 $NUMFILES` ; do
2689                 NUMS=`$LFIND -name "*$i" $DIR/${tdir}g | wc -l`
2690                 [ $NUMS -eq $EXPECTED ] || error \
2691                         "lfs find -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2692         done
2693         echo "lfs find -name passed."
2694 }
2695 run_test 56g "check lfs find -name ============================="
2696
2697 test_56h() {
2698         $LSTRIPE -d $DIR
2699
2700         setup_56 $NUMFILES $NUMDIRS
2701
2702         EXPECTED=$((($NUMDIRS+1)*($NUMFILES-1)+$NUMFILES))
2703         # test lfs find with ! -name
2704         for i in `seq 1 $NUMFILES` ; do
2705                 NUMS=`$LFIND ! -name "*$i" $DIR/${tdir}g | wc -l`
2706                 [ $NUMS -eq $EXPECTED ] || error \
2707                         "lfs find ! -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2708         done
2709         echo "lfs find ! -name passed."
2710 }
2711 run_test 56h "check lfs find ! -name ============================="
2712
2713 test_56i() {
2714        tdir=${tdir}i
2715        mkdir -p $DIR/$tdir
2716        UUID=`$GETSTRIPE $DIR/$tdir | awk '/0: / { print $2 }'`
2717        OUT="`$LFIND -ost $UUID $DIR/$tdir`"
2718        [ "$OUT" ] && error "$LFIND returned directory '$OUT'" || true
2719 }
2720 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
2721
2722 test_56j() {
2723         setup_56_special $NUMFILES $NUMDIRS
2724
2725         EXPECTED=$((NUMDIRS+1))
2726         NUMS=`$LFIND -type d $DIR/${tdir}g | wc -l`
2727         [ $NUMS -eq $EXPECTED ] || \
2728                 error "lfs find -type d $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2729 }
2730 run_test 56j "check lfs find -type d ============================="
2731
2732 test_56k() {
2733         setup_56_special $NUMFILES $NUMDIRS
2734
2735         EXPECTED=$(((NUMDIRS+1) * NUMFILES))
2736         NUMS=`$LFIND -type f $DIR/${tdir}g | wc -l`
2737         [ $NUMS -eq $EXPECTED ] || \
2738                 error "lfs find -type f $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2739 }
2740 run_test 56k "check lfs find -type f ============================="
2741
2742 test_56l() {
2743         setup_56_special $NUMFILES $NUMDIRS
2744
2745         EXPECTED=$((NUMDIRS + NUMFILES))
2746         NUMS=`$LFIND -type b $DIR/${tdir}g | wc -l`
2747         [ $NUMS -eq $EXPECTED ] || \
2748                 error "lfs find -type b $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2749 }
2750 run_test 56l "check lfs find -type b ============================="
2751
2752 test_56m() {
2753         setup_56_special $NUMFILES $NUMDIRS
2754
2755         EXPECTED=$((NUMDIRS + NUMFILES))
2756         NUMS=`$LFIND -type c $DIR/${tdir}g | wc -l`
2757         [ $NUMS -eq $EXPECTED ] || \
2758                 error "lfs find -type c $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2759 }
2760 run_test 56m "check lfs find -type c ============================="
2761
2762 test_56n() {
2763         setup_56_special $NUMFILES $NUMDIRS
2764
2765         EXPECTED=$((NUMDIRS + NUMFILES))
2766         NUMS=`$LFIND -type l $DIR/${tdir}g | wc -l`
2767         [ $NUMS -eq $EXPECTED ] || \
2768                 error "lfs find -type l $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2769 }
2770 run_test 56n "check lfs find -type l ============================="
2771
2772 test_56o() {
2773         setup_56 $NUMFILES $NUMDIRS
2774         TDIR=$DIR/${tdir}g
2775
2776         utime $TDIR/file1 > /dev/null || error "utime (1)"
2777         utime $TDIR/file2 > /dev/null || error "utime (2)"
2778         utime $TDIR/dir1 > /dev/null || error "utime (3)"
2779         utime $TDIR/dir2 > /dev/null || error "utime (4)"
2780         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
2781
2782         EXPECTED=5
2783         NUMS=`$LFIND -mtime +1 $TDIR | wc -l`
2784         [ $NUMS -eq $EXPECTED ] || \
2785                 error "lfs find -mtime $TDIR wrong: found $NUMS, expected $EXPECTED"
2786 }
2787 run_test 56o "check lfs find -mtime for old files =========================="
2788
2789 test_56p() {
2790         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
2791
2792         TDIR=$DIR/${tdir}g
2793         rm -rf $TDIR
2794
2795         setup_56 $NUMFILES $NUMDIRS
2796
2797         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
2798         EXPECTED=$NUMFILES
2799         NUMS="`$LFIND -uid $RUNAS_ID $TDIR | wc -l`"
2800         [ $NUMS -eq $EXPECTED ] || \
2801                 error "lfs find -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
2802
2803         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
2804         NUMS="`$LFIND ! -uid $RUNAS_ID $TDIR | wc -l`"
2805         [ $NUMS -eq $EXPECTED ] || \
2806                 error "lfs find ! -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
2807
2808         echo "lfs find -uid and ! -uid passed."
2809 }
2810 run_test 56p "check lfs find -uid and ! -uid ==============================="
2811
2812 test_56q() {
2813         [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
2814
2815         TDIR=$DIR/${tdir}g
2816         rm -rf $TDIR
2817
2818         setup_56 $NUMFILES $NUMDIRS
2819
2820         chgrp $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
2821         EXPECTED=$NUMFILES
2822         NUMS="`$LFIND -gid $RUNAS_ID $TDIR | wc -l`"
2823         [ $NUMS -eq $EXPECTED ] || \
2824                 error "lfs find -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
2825
2826         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
2827         NUMS="`$LFIND ! -gid $RUNAS_ID $TDIR | wc -l`"
2828         [ $NUMS -eq $EXPECTED ] || \
2829                 error "lfs find ! -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
2830
2831         echo "lfs find -gid and ! -gid passed."
2832 }
2833 run_test 56q "check lfs find -gid and ! -gid ==============================="
2834
2835 test_57a() {
2836         # note test will not do anything if MDS is not local
2837         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2838
2839         local MNTDEV="osd.*MDT*.mntdev"
2840         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
2841         [ -z "$DEV" ] && error "can't access $MNTDEV"
2842         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
2843                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
2844                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2845                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2846                 rm $TMP/t57a.dump
2847         done
2848 }
2849 run_test 57a "verify MDS filesystem created with large inodes =="
2850
2851 test_57b() {
2852         local dir=$DIR/d57b
2853
2854         local FILECOUNT=100
2855         local FILE1=$dir/f1
2856         local FILEN=$dir/f$FILECOUNT
2857
2858         rm -rf $dir || error "removing $dir"
2859         mkdir -p $dir || error "creating $dir"
2860         local num=$(get_mds_dir $dir)
2861         local mymds=mds$num
2862
2863         echo "mcreating $FILECOUNT files"
2864         createmany -m $dir/f 1 $FILECOUNT || \
2865                 error "creating files in $dir"
2866
2867         # verify that files do not have EAs yet
2868         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2869         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2870
2871         sync
2872         sleep 1
2873         df $dir  #make sure we get new statfs data
2874         local MDSFREE=$(do_facet $mymds lctl get_param -n osd.*MDT000$((num -1)).kbytesfree)
2875         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
2876         echo "opening files to create objects/EAs"
2877         local FILE
2878         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
2879                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
2880         done
2881
2882         # verify that files have EAs now
2883         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2884         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2885
2886         sleep 1  #make sure we get new statfs data
2887         df $dir
2888         local MDSFREE2=$(do_facet $mymds lctl get_param -n osd.*MDT000$((num -1)).kbytesfree)
2889         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
2890         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
2891                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
2892                         error "MDC before $MDCFREE != after $MDCFREE2"
2893                 else
2894                         echo "MDC before $MDCFREE != after $MDCFREE2"
2895                         echo "unable to confirm if MDS has large inodes"
2896                 fi
2897         fi
2898         rm -rf $dir
2899 }
2900 run_test 57b "default LOV EAs are stored inside large inodes ==="
2901
2902 test_58() {
2903     [ -z "$(which wiretest 2>/dev/null)" ] && skip "could not find wiretest" && return
2904     wiretest
2905 }
2906 run_test 58 "verify cross-platform wire constants =============="
2907
2908 test_59() {
2909         echo "touch 130 files"
2910         createmany -o $DIR/f59- 130
2911         echo "rm 130 files"
2912         unlinkmany $DIR/f59- 130
2913         sync
2914         sleep 2
2915         # wait for commitment of removal
2916 }
2917 run_test 59 "verify cancellation of llog records async ========="
2918
2919 TEST60_HEAD="test_60 run $RANDOM"
2920 test_60a() {
2921         [ ! -f run-llog.sh ] && skip "missing subtest run-llog.sh" && return
2922         log "$TEST60_HEAD - from kernel mode"
2923         sh run-llog.sh
2924 }
2925 run_test 60a "llog sanity tests run from kernel module =========="
2926
2927 test_60b() { # bug 6411
2928         dmesg > $DIR/$tfile
2929         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
2930                                  /llog.test/ {
2931                                          if (marker)
2932                                                  from_marker++
2933                                          from_begin++
2934                                  }
2935                                  END {
2936                                          if (marker)
2937                                                  print from_marker
2938                                          else
2939                                                  print from_begin
2940                                  }"`
2941         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
2942 }
2943 run_test 60b "limit repeated messages from CERROR/CWARN ========"
2944
2945 test_60c() {
2946         echo "create 5000 files"
2947         createmany -o $DIR/f60c- 5000
2948 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
2949         lctl set_param fail_loc=0x80000137
2950         unlinkmany $DIR/f60c- 5000
2951         lctl set_param fail_loc=0
2952 }
2953 run_test 60c "unlink file when mds full"
2954
2955 test_60d() {
2956         SAVEPRINTK=$(lctl get_param -n printk)
2957
2958         # verify "lctl mark" is even working"
2959         MESSAGE="test message ID $RANDOM $$"
2960         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
2961         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
2962
2963         lctl set_param printk=0 || error "set lnet.printk failed"
2964         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
2965         MESSAGE="new test message ID $RANDOM $$"
2966         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
2967         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
2968         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
2969
2970         lctl set_param -n printk="$SAVEPRINTK"
2971 }
2972 run_test 60d "test printk console message masking"
2973
2974 test_61() {
2975         f="$DIR/f61"
2976         dd if=/dev/zero of=$f bs=`page_size` count=1
2977         cancel_lru_locks osc
2978         multiop $f OSMWUc || error
2979         sync
2980 }
2981 run_test 61 "mmap() writes don't make sync hang ================"
2982
2983 # bug 2330 - insufficient obd_match error checking causes LBUG
2984 test_62() {
2985         f="$DIR/f62"
2986         echo foo > $f
2987         cancel_lru_locks osc
2988         lctl set_param fail_loc=0x405
2989         cat $f && error "cat succeeded, expect -EIO"
2990         lctl set_param fail_loc=0
2991 }
2992 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
2993 # match every page all of the time.
2994 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2995
2996 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2997 test_63a() {    # was test_63
2998         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
2999         lctl set_param -n osc.*.max_dirty_mb 0
3000         for i in `seq 10` ; do
3001                 dd if=/dev/zero of=$DIR/f63 bs=8k &
3002                 sleep 5
3003                 kill $!
3004                 sleep 1
3005         done
3006
3007         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
3008         rm -f $DIR/f63 || true
3009 }
3010 run_test 63a "Verify oig_wait interruption does not crash ======="
3011
3012 # bug 2248 - async write errors didn't return to application on sync
3013 # bug 3677 - async write errors left page locked
3014 test_63b() {
3015         debugsave
3016         lctl set_param debug=-1
3017
3018         # ensure we have a grant to do async writes
3019         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
3020         rm $DIR/$tfile
3021
3022         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
3023         lctl set_param fail_loc=0x80000406
3024         multiop $DIR/$tfile Owy && \
3025                 error "sync didn't return ENOMEM"
3026         sync; sleep 2; sync     # do a real sync this time to flush page
3027         lctl get_param -n llite.*.dump_page_cache | grep locked && \
3028                 error "locked page left in cache after async error" || true
3029         debugrestore
3030 }
3031 run_test 63b "async write errors should be returned to fsync ==="
3032
3033 test_64a () {
3034         df $DIR
3035         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
3036 }
3037 run_test 64a "verify filter grant calculations (in kernel) ====="
3038
3039 test_64b () {
3040         [ ! -f oos.sh ] && skip "missing subtest oos.sh" && return
3041         sh oos.sh $MOUNT
3042 }
3043 run_test 64b "check out-of-space detection on client ==========="
3044
3045 # bug 1414 - set/get directories' stripe info
3046 test_65a() {
3047         mkdir -p $DIR/d65
3048         touch $DIR/d65/f1
3049         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
3050 }
3051 run_test 65a "directory with no stripe info ===================="
3052
3053 test_65b() {
3054         mkdir -p $DIR/d65
3055         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
3056         touch $DIR/d65/f2
3057         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
3058 }
3059 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
3060
3061 test_65c() {
3062         if [ $OSTCOUNT -gt 1 ]; then
3063                 mkdir -p $DIR/d65
3064                 $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 4)) -i 1 \
3065                         -c $(($OSTCOUNT - 1)) || error "setstripe"
3066                 touch $DIR/d65/f3
3067                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
3068         fi
3069 }
3070 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
3071
3072 test_65d() {
3073         mkdir -p $DIR/d65
3074         if [ $STRIPECOUNT -le 0 ]; then
3075                 sc=1
3076         elif [ $STRIPECOUNT -gt 160 ]; then
3077 #LOV_MAX_STRIPE_COUNT is 160
3078                 [ $OSTCOUNT -gt 160 ] && sc=160 || sc=$(($OSTCOUNT - 1))
3079         else
3080                 sc=$(($STRIPECOUNT - 1))
3081         fi
3082         $SETSTRIPE $DIR/d65 -s $STRIPESIZE -c $sc || error "setstripe"
3083         touch $DIR/d65/f4 $DIR/d65/f5
3084         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
3085 }
3086 run_test 65d "directory setstripe $STRIPESIZE -1 stripe_count =============="
3087
3088 test_65e() {
3089         mkdir -p $DIR/d65
3090
3091         $SETSTRIPE $DIR/d65 || error "setstripe"
3092         $GETSTRIPE -v $DIR/d65 | grep "Default" || error "no stripe info failed"
3093         touch $DIR/d65/f6
3094         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
3095 }
3096 run_test 65e "directory setstripe defaults ======================="
3097
3098 test_65f() {
3099         mkdir -p $DIR/d65f
3100         $RUNAS $SETSTRIPE $DIR/d65f && error "setstripe succeeded" || true
3101 }
3102 run_test 65f "dir setstripe permission (should return error) ==="
3103
3104 test_65g() {
3105         mkdir -p $DIR/d65
3106         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
3107         $SETSTRIPE -d $DIR/d65 || error "setstripe"
3108         $GETSTRIPE -v $DIR/d65 | grep "Default" || \
3109                 error "delete default stripe failed"
3110 }
3111 run_test 65g "directory setstripe -d ==========================="
3112
3113 test_65h() {
3114         mkdir -p $DIR/d65
3115         $SETSTRIPE $DIR/d65 -s $(($STRIPESIZE * 2)) -i 0 -c 1 || error "setstripe"
3116         mkdir -p $DIR/d65/dd1
3117         [ "`$GETSTRIPE -v $DIR/d65 | grep "^count"`" == \
3118           "`$GETSTRIPE -v $DIR/d65/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
3119 }
3120 run_test 65h "directory stripe info inherit ===================="
3121
3122 test_65i() { # bug6367
3123         $SETSTRIPE $MOUNT -s 65536 -c -1
3124 }
3125 run_test 65i "set non-default striping on root directory (bug 6367)="
3126
3127 test_65ia() { # bug12836
3128         $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
3129 }
3130 run_test 65ia "getstripe on -1 default directory striping"
3131
3132 test_65ib() { # bug12836
3133         $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
3134 }
3135 run_test 65ib "getstripe -v on -1 default directory striping"
3136
3137 test_65ic() { # bug12836
3138         $LFS find -mtime -1 $MOUNT || error "find $MOUNT failed"
3139 }
3140 run_test 65ic "new find on -1 default directory striping"
3141
3142 test_65j() { # bug6367
3143         sync; sleep 1
3144         # if we aren't already remounting for each test, do so for this test
3145         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
3146                 cleanup || error "failed to unmount"
3147                 setup
3148         fi
3149         $SETSTRIPE -d $MOUNT || error "setstripe failed"
3150 }
3151 run_test 65j "set default striping on root directory (bug 6367)="
3152
3153 test_65k() { # bug11679
3154         [ "$OSTCOUNT" -lt 2 ] && skip "too few OSTs" && return
3155         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3156
3157         echo "Check OST status: "
3158         MDS_OSCS=`do_facet $SINGLEMDS lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
3159         for OSC in $MDS_OSCS; do
3160                 echo $OSC "is activate"
3161                 do_facet $SINGLEMDS lctl --device %$OSC activate
3162         done
3163         do_facet client mkdir -p $DIR/$tdir
3164         for INACTIVE_OSC in $MDS_OSCS; do
3165                 echo $INACTIVE_OSC "is Deactivate:"
3166                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC deactivate
3167                 for STRIPE_OSC in $MDS_OSCS; do
3168                         STRIPE_OST=`osc_to_ost $STRIPE_OSC`
3169                         STRIPE_INDEX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
3170                                       grep $STRIPE_OST | awk -F: '{print $1}' | head -n 1`
3171
3172                         [ -f $DIR/$tdir/${STRIPE_INDEX} ] && continue
3173                         echo "$SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1"
3174                         do_facet client $SETSTRIPE $DIR/$tdir/${STRIPE_INDEX} -i ${STRIPE_INDEX} -c 1
3175                         RC=$?
3176                         [ $RC -ne 0 ] && error "setstripe should have succeeded"
3177                 done
3178                 do_facet client rm -f $DIR/$tdir/*
3179                 echo $INACTIVE_OSC "is Activate."
3180                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
3181         done
3182 }
3183 run_test 65k "validate manual striping works properly with deactivated OSCs"
3184
3185 test_65l() { # bug 12836
3186         mkdir -p $DIR/$tdir/test_dir
3187         $SETSTRIPE $DIR/$tdir/test_dir -c -1
3188         $LFS find -mtime -1 $DIR/$tdir >/dev/null
3189 }
3190 run_test 65l "lfs find on -1 stripe dir ========================"
3191
3192 # bug 2543 - update blocks count on client
3193 test_66() {
3194         COUNT=${COUNT:-8}
3195         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
3196         sync; sleep 1; sync
3197         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
3198         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
3199 }
3200 run_test 66 "update inode blocks count on client ==============="
3201
3202 LLOOP=
3203 cleanup_68() {
3204         trap 0
3205         if [ ! -z "$LLOOP" ]; then
3206                 if swapon -s | grep -q $LLOOP; then
3207                         swapoff $LLOOP || error "swapoff failed"
3208                 fi
3209
3210                 $LCTL blockdev_detach $LLOOP || error "detach failed"
3211                 rm -f $LLOOP
3212                 unset LLOOP
3213         fi
3214         rm -f $DIR/f68*
3215 }
3216
3217 meminfo() {
3218         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
3219 }
3220
3221 swap_used() {
3222         swapon -s | awk '($1 == "'$1'") { print $4 }'
3223 }
3224
3225 # test case for lloop driver, basic function
3226 test_68a() {
3227         [ "$UID" != 0 ] && skip "must run as root" && return
3228
3229         grep -q llite_lloop /proc/modules
3230         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
3231
3232         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
3233         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
3234         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
3235
3236         trap cleanup_68 EXIT
3237
3238         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
3239         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
3240
3241         cleanup_68
3242 }
3243 run_test 68a "lloop driver - basic test ========================"
3244
3245 # excercise swapping to lustre by adding a high priority swapfile entry
3246 # and then consuming memory until it is used.
3247 test_68b() {  # was test_68
3248         [ "$UID" != 0 ] && skip "must run as root" && return
3249         lctl get_param -n devices | grep -q obdfilter && \
3250                 skip "local OST" && return
3251
3252         grep -q llite_lloop /proc/modules
3253         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
3254
3255         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
3256                 skip "can't reliably test swap with TCP" && return
3257
3258         MEMTOTAL=`meminfo MemTotal`
3259         NR_BLOCKS=$((MEMTOTAL>>8))
3260         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
3261
3262         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
3263         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
3264         mkswap $DIR/f68b
3265
3266         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
3267
3268         trap cleanup_68 EXIT
3269
3270         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
3271
3272         echo "before: `swapon -s | grep $LLOOP`"
3273         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
3274         echo "after: `swapon -s | grep $LLOOP`"
3275         SWAPUSED=`swap_used $LLOOP`
3276
3277         cleanup_68
3278
3279         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
3280 }
3281 run_test 68b "support swapping to Lustre ========================"
3282
3283 # bug5265, obdfilter oa2dentry return -ENOENT
3284 # #define OBD_FAIL_OST_ENOENT 0x217
3285 test_69() {
3286         remote_ost_nodsh && skip "remote OST with nodsh" && return
3287
3288         f="$DIR/$tfile"
3289         $SETSTRIPE $f -c 1 -i 0
3290
3291         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
3292
3293         do_facet ost1 lctl set_param fail_loc=0x217
3294         truncate $f 1 # vmtruncate() will ignore truncate() error.
3295         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
3296
3297         do_facet ost1 lctl set_param fail_loc=0
3298         $DIRECTIO write $f 0 2 || error "write error"
3299
3300         cancel_lru_locks osc
3301         $DIRECTIO read $f 0 1 || error "read error"
3302
3303         do_facet ost1 lctl set_param fail_loc=0x217
3304         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
3305
3306         do_facet ost1 lctl set_param fail_loc=0
3307         rm -f $f
3308 }
3309 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
3310
3311 test_71() {
3312     mkdir -p $DIR/$tdir
3313     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
3314 }
3315 run_test 71 "Running dbench on lustre (don't segment fault) ===="
3316
3317 test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
3318         check_kernel_version 43 || return 0
3319         [ "$RUNAS_ID" = "$UID" ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
3320
3321         # Check that testing environment is properly set up. Skip if not
3322         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
3323                 skip "User $RUNAS_ID does not exist - skipping"
3324                 return 0
3325         }
3326         # We had better clear the $DIR to get enough space for dd
3327         rm -rf $DIR/*
3328         touch $DIR/f72
3329         chmod 777 $DIR/f72
3330         chmod ug+s $DIR/f72
3331         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
3332         # See if we are still setuid/sgid
3333         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
3334         # Now test that MDS is updated too
3335         cancel_lru_locks mdc
3336         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
3337         true
3338         rm -f $DIR/f72
3339 }
3340 run_test 72 "Test that remove suid works properly (bug5695) ===="
3341
3342 # bug 3462 - multiple simultaneous MDC requests
3343 test_73() {
3344         mkdir $DIR/d73-1
3345         mkdir $DIR/d73-2
3346         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
3347         pid1=$!
3348
3349         lctl set_param fail_loc=0x80000129
3350         multiop $DIR/d73-1/f73-2 Oc &
3351         sleep 1
3352         lctl set_param fail_loc=0
3353
3354         multiop $DIR/d73-2/f73-3 Oc &
3355         pid3=$!
3356
3357         kill -USR1 $pid1
3358         wait $pid1 || return 1
3359
3360         sleep 25
3361
3362         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
3363         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
3364         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
3365
3366         rm -rf $DIR/d73-*
3367 }
3368 run_test 73 "multiple MDC requests (should not deadlock)"
3369
3370 test_74a() { # bug 6149, 6184
3371         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
3372         #
3373         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
3374         # will spin in a tight reconnection loop
3375         touch $DIR/f74a
3376         lctl set_param fail_loc=0x8000030e
3377         # get any lock that won't be difficult - lookup works.
3378         ls $DIR/f74a
3379         lctl set_param fail_loc=0
3380         true
3381         rm -f $DIR/f74a
3382 }
3383 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
3384
3385 test_74b() { # bug 13310
3386         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
3387         #
3388         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
3389         # will spin in a tight reconnection loop
3390         lctl set_param fail_loc=0x8000030e
3391         # get a "difficult" lock
3392         touch $DIR/f74b
3393         lctl set_param fail_loc=0
3394         true
3395         rm -f $DIR/f74b
3396 }
3397 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
3398
3399 JOIN=${JOIN:-"lfs join"}
3400 F75=$DIR/f75
3401 F128k=${F75}_128k
3402 FHEAD=${F75}_head
3403 FTAIL=${F75}_tail
3404 export T75_PREP=no
3405 test75_prep() {
3406         [ $T75_PREP = "yes" ] && return
3407         echo "using F75=$F75, F128k=$F128k, FHEAD=$FHEAD, FTAIL=$FTAIL"
3408
3409         dd if=/dev/urandom of=${F75}_128k bs=128k count=1 || error "dd failed"
3410         log "finished dd"
3411         chmod 777 ${F128k}
3412         T75_PREP=yes
3413 }
3414
3415 test_75a() {
3416         test75_prep
3417
3418         cp -p ${F128k} ${FHEAD}
3419         log "finished cp to $FHEAD"
3420         cp -p ${F128k} ${FTAIL}
3421         log "finished cp to $FTAIL"
3422         cat ${F128k} ${F128k} > ${F75}_sim_sim
3423
3424         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3425         log "finished join $FHEAD to ${F75}_sim_sim"
3426         cmp ${FHEAD} ${F75}_sim_sim || error "${FHEAD} ${F75}_sim_sim differ"
3427         log "finished cmp $FHEAD to ${F75}_sim_sim"
3428         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} still exist after join"
3429 }
3430 run_test 75a "TEST join file ===================================="
3431
3432 test_75b() {
3433         test75_prep
3434
3435         cp -p ${F128k} ${FTAIL}
3436         cat ${F75}_sim_sim >> ${F75}_join_sim
3437         cat ${F128k} >> ${F75}_join_sim
3438         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3439         cmp ${FHEAD} ${F75}_join_sim || \
3440                 error "${FHEAD} ${F75}_join_sim are different"
3441         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join"
3442 }
3443 run_test 75b "TEST join file 2 =================================="
3444
3445 test_75c() {
3446         test75_prep
3447
3448         cp -p ${F128k} ${FTAIL}
3449         cat ${F128k} >> ${F75}_sim_join
3450         cat ${F75}_join_sim >> ${F75}_sim_join
3451         $JOIN ${FTAIL} ${FHEAD} || error "join error"
3452         cmp ${FTAIL} ${F75}_sim_join || \
3453                 error "${FTAIL} ${F75}_sim_join are different"
3454         $CHECKSTAT -a ${FHEAD} || error "tail ${FHEAD} exist after join"
3455 }
3456 run_test 75c "TEST join file 3 =================================="
3457
3458 test_75d() {
3459         test75_prep
3460
3461         cp -p ${F128k} ${FHEAD}
3462         cp -p ${F128k} ${FHEAD}_tmp
3463         cat ${F75}_sim_sim >> ${F75}_join_join
3464         cat ${F75}_sim_join >> ${F75}_join_join
3465         $JOIN ${FHEAD} ${FHEAD}_tmp || error "join ${FHEAD} ${FHEAD}_tmp error"
3466         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
3467         cmp ${FHEAD} ${F75}_join_join ||error "${FHEAD} ${F75}_join_join differ"        $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join"
3468         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)"
3469 }
3470 run_test 75d "TEST join file 4 =================================="
3471
3472 test_75e() {
3473         test75_prep
3474
3475         rm -rf ${FHEAD} || "delete join file error"
3476 }
3477 run_test 75e "TEST join file 5 (remove joined file) ============="
3478
3479 test_75f() {
3480         test75_prep
3481
3482         cp -p ${F128k} ${F75}_join_10_compare
3483         cp -p ${F128k} ${F75}_join_10
3484         for ((i = 0; i < 10; i++)); do
3485                 cat ${F128k} >> ${F75}_join_10_compare
3486                 cp -p ${F128k} ${FTAIL}
3487                 $JOIN ${F75}_join_10 ${FTAIL} || \
3488                         error "join ${F75}_join_10 ${FTAIL} error"
3489                 $CHECKSTAT -a ${FTAIL} || error "tail file exist after join"
3490         done
3491         cmp ${F75}_join_10 ${F75}_join_10_compare || \
3492                 error "files ${F75}_join_10 ${F75}_join_10_compare differ"
3493 }
3494 run_test 75f "TEST join file 6 (join 10 files) =================="
3495
3496 test_75g() {
3497         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
3498         $LFS getstripe ${F75}_join_10
3499
3500         $OPENUNLINK ${F75}_join_10 ${F75}_join_10 || error "files unlink open"
3501
3502         ls -l $F75*
3503 }
3504 run_test 75g "TEST join file 7 (open unlink) ===================="
3505
3506 num_inodes() {
3507         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
3508 }
3509
3510 test_76() { # bug 1443
3511         DETH=$(grep deathrow /proc/kallsyms /proc/ksyms 2> /dev/null | wc -l)
3512         [ $DETH -eq 0 ] && skip "No _iget." && return 0
3513         BEFORE_INODES=`num_inodes`
3514         echo "before inodes: $BEFORE_INODES"
3515         local COUNT=1000
3516         [ "$SLOW" = "no" ] && COUNT=100
3517         for i in `seq $COUNT`; do
3518                 touch $DIR/$tfile
3519                 rm -f $DIR/$tfile
3520         done
3521         AFTER_INODES=`num_inodes`
3522         echo "after inodes: $AFTER_INODES"
3523         [ $AFTER_INODES -gt $((BEFORE_INODES + 32)) ] && \
3524                 error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
3525         true
3526 }
3527 run_test 76 "destroy duplicate inodes in client inode cache ===="
3528
3529 export ORIG_CSUM=""
3530 set_checksums()
3531 {
3532         # Note: in sptlrpc modes which enable its own bulk checksum, the
3533         # original crc32_le bulk checksum will be automatically disabled,
3534         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
3535         # will be checked by sptlrpc code against sptlrpc bulk checksum.
3536         # In this case set_checksums() will not be no-op, because sptlrpc
3537         # bulk checksum will be enabled all through the test.
3538
3539         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
3540         lctl set_param -n osc.*.checksums $1
3541         return 0
3542 }
3543
3544 export ORIG_CSUM_TYPE=""
3545 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
3546 set_checksum_type()
3547 {
3548         [ "$ORIG_CSUM_TYPE" ] || \
3549                 ORIG_CSUM_TYPE=`lctl get_param -n osc/*osc-[^mM]*/checksum_type |
3550                                 sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`
3551         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
3552         log "set checksum type to $1"
3553         return 0
3554 }
3555 F77_TMP=$TMP/f77-temp
3556 F77SZ=8
3557 setup_f77() {
3558         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
3559                 error "error writing to $F77_TMP"
3560 }
3561
3562 test_77a() { # bug 10889
3563         $GSS && skip "could not run with gss" && return
3564         [ ! -f $F77_TMP ] && setup_f77
3565         set_checksums 1
3566         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
3567         set_checksums 0
3568         rm -f $DIR/$tfile
3569 }
3570 run_test 77a "normal checksum read/write operation ============="
3571
3572 test_77b() { # bug 10889
3573         $GSS && skip "could not run with gss" && return
3574         [ ! -f $F77_TMP ] && setup_f77
3575         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3576         lctl set_param fail_loc=0x80000409
3577         set_checksums 1
3578         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
3579                 error "dd error: $?"
3580         lctl set_param fail_loc=0
3581         set_checksums 0
3582 }
3583 run_test 77b "checksum error on client write ===================="
3584
3585 test_77c() { # bug 10889
3586         $GSS && skip "could not run with gss" && return
3587         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
3588         set_checksums 1
3589         for algo in $CKSUM_TYPES; do
3590                 cancel_lru_locks osc
3591                 set_checksum_type $algo
3592                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3593                 lctl set_param fail_loc=0x80000408
3594                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
3595                 lctl set_param fail_loc=0
3596         done
3597         set_checksums 0
3598         set_checksum_type $ORIG_CSUM_TYPE
3599         rm -f $DIR/f77b
3600 }
3601 run_test 77c "checksum error on client read ==================="
3602
3603 test_77d() { # bug 10889
3604         $GSS && skip "could not run with gss" && return
3605         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3606         lctl set_param fail_loc=0x80000409
3607         set_checksums 1
3608         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3609                 error "direct write: rc=$?"
3610         lctl set_param fail_loc=0
3611         set_checksums 0
3612 }
3613 run_test 77d "checksum error on OST direct write ==============="
3614
3615 test_77e() { # bug 10889
3616         $GSS && skip "could not run with gss" && return
3617         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
3618         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3619         lctl set_param fail_loc=0x80000408
3620         set_checksums 1
3621         cancel_lru_locks osc
3622         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3623                 error "direct read: rc=$?"
3624         lctl set_param fail_loc=0
3625         set_checksums 0
3626 }
3627 run_test 77e "checksum error on OST direct read ================"
3628
3629 test_77f() { # bug 10889
3630         $GSS && skip "could not run with gss" && return
3631         set_checksums 1
3632         for algo in $CKSUM_TYPES; do
3633                 cancel_lru_locks osc
3634                 set_checksum_type $algo
3635                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3636                 lctl set_param fail_loc=0x409
3637                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
3638                         error "direct write succeeded"
3639                 lctl set_param fail_loc=0
3640         done
3641         set_checksum_type $ORIG_CSUM_TYPE
3642         set_checksums 0
3643 }
3644 run_test 77f "repeat checksum error on write (expect error) ===="
3645
3646 test_77g() { # bug 10889
3647         $GSS && skip "could not run with gss" && return
3648         remote_ost_nodsh && skip "remote OST with nodsh" && return
3649
3650         [ ! -f $F77_TMP ] && setup_f77
3651
3652         $SETSTRIPE $DIR/f77g -c 1 -i 0
3653         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
3654         do_facet ost1 lctl set_param fail_loc=0x8000021a
3655         set_checksums 1
3656         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
3657                 error "write error: rc=$?"
3658         do_facet ost1 lctl set_param fail_loc=0
3659         set_checksums 0
3660 }
3661 run_test 77g "checksum error on OST write ======================"
3662
3663 test_77h() { # bug 10889
3664         $GSS && skip "could not run with gss" && return
3665         remote_ost_nodsh && skip "remote OST with nodsh" && return
3666
3667         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
3668         cancel_lru_locks osc
3669         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
3670         do_facet ost1 lctl set_param fail_loc=0x8000021b
3671         set_checksums 1
3672         cmp $F77_TMP $DIR/f77g || error "file compare failed"
3673         do_facet ost1 lctl set_param fail_loc=0
3674         set_checksums 0
3675 }
3676 run_test 77h "checksum error on OST read ======================="
3677
3678 test_77i() { # bug 13805
3679         $GSS && skip "could not run with gss" && return
3680         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
3681         lctl set_param fail_loc=0x40b
3682         remount_client $MOUNT
3683         lctl set_param fail_loc=0
3684         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
3685                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
3686                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
3687                 [ "$algo" = "crc32" ] || error "algo set to $algo instead of crc32"
3688         done
3689         remount_client $MOUNT
3690 }
3691 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
3692
3693 test_77j() { # bug 13805
3694         $GSS && skip "could not run with gss" && return
3695         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
3696         lctl set_param fail_loc=0x40c
3697         remount_client $MOUNT
3698         lctl set_param fail_loc=0
3699         sleep 2 # wait async osc connect to finish
3700         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
3701                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
3702                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
3703                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
3704         done
3705         remount_client $MOUNT
3706 }
3707 run_test 77j "client only supporting ADLER32 ===================="
3708
3709 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
3710 rm -f $F77_TMP
3711 unset F77_TMP
3712
3713 test_78() { # bug 10901
3714         NSEQ=5
3715         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
3716         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
3717         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
3718         echo "MemTotal: $MEMTOTAL"
3719 # reserve 256MB of memory for the kernel and other running processes,
3720 # and then take 1/2 of the remaining memory for the read/write buffers.
3721     if [ $MEMTOTAL -gt 512 ] ;then
3722         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
3723     else
3724         # for those poor memory-starved high-end clusters...
3725         MEMTOTAL=$((MEMTOTAL / 2))
3726     fi
3727         echo "Mem to use for directio: $MEMTOTAL"
3728         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
3729         [ $F78SIZE -gt 512 ] && F78SIZE=512
3730         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
3731         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
3732         echo "Smallest OST: $SMALLESTOST"
3733         [ $SMALLESTOST -lt 10240 ] && \
3734                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
3735
3736         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
3737                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
3738
3739         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
3740         echo "File size: $F78SIZE"
3741         $SETSTRIPE $DIR/$tfile -c $OSTCOUNT || error "setstripe failed"
3742         for i in `seq 1 $NSEQ`
3743         do
3744                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
3745                 echo directIO rdwr round $i of $NSEQ
3746                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
3747         done
3748
3749         rm -f $DIR/$tfile
3750 }
3751 run_test 78 "handle large O_DIRECT writes correctly ============"
3752
3753 test_79() { # bug 12743
3754         wait_delete_completed
3755
3756         BKTOTAL=$(calc_osc_kbytes kbytestotal)
3757         BKFREE=$(calc_osc_kbytes kbytesfree)
3758         BKAVAIL=$(calc_osc_kbytes kbytesavail)
3759
3760         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
3761         DFTOTAL=`echo $STRING | cut -d, -f1`
3762         DFUSED=`echo $STRING  | cut -d, -f2`
3763         DFAVAIL=`echo $STRING | cut -d, -f3`
3764         DFFREE=$(($DFTOTAL - $DFUSED))
3765
3766         ALLOWANCE=$((64 * $OSTCOUNT))
3767
3768         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
3769            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
3770                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
3771         fi
3772         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
3773            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
3774                 error "df free($DFFREE) mismatch OST free($BKFREE)"
3775         fi
3776         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
3777            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
3778                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
3779         fi
3780 }
3781 run_test 79 "df report consistency check ======================="
3782
3783 test_80() { # bug 10718
3784         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
3785         sync; sleep 1; sync
3786         local BEFORE=`date +%s`
3787         cancel_lru_locks osc
3788         local AFTER=`date +%s`
3789         local DIFF=$((AFTER-BEFORE))
3790         if [ $DIFF -gt 1 ] ; then
3791                 error "elapsed for 1M@1T = $DIFF"
3792         fi
3793         true
3794         rm -f $DIR/$tfile
3795 }
3796 run_test 80 "Page eviction is equally fast at high offsets too  ===="
3797
3798 test_99a() {
3799         [ -z "$(which cvs 2>/dev/null)" ] && skip "could not find cvs" && \
3800             return
3801         mkdir -p $DIR/d99cvsroot
3802         chown $RUNAS_ID $DIR/d99cvsroot
3803         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
3804         cd $TMP
3805
3806         $RUNAS cvs -d $DIR/d99cvsroot init || error
3807         cd $oldPWD
3808 }
3809 run_test 99a "cvs init ========================================="
3810
3811 test_99b() {
3812         [ -z "$(which cvs 2>/dev/null)" ] && skip "could not find cvs" && return
3813         [ ! -d $DIR/d99cvsroot ] && test_99a
3814         cd /etc/init.d
3815         # some versions of cvs import exit(1) when asked to import links or
3816         # files they can't read.  ignore those files.
3817         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
3818                         ! -perm +4 -printf '-I %f\n')
3819         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
3820                 d99reposname vtag rtag
3821 }
3822 run_test 99b "cvs import ======================================="
3823
3824 test_99c() {
3825         [ -z "$(which cvs 2>/dev/null)" ] && skip "could not find cvs" && return
3826         [ ! -d $DIR/d99cvsroot ] && test_99b
3827         cd $DIR
3828         mkdir -p $DIR/d99reposname
3829         chown $RUNAS_ID $DIR/d99reposname
3830         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
3831 }
3832 run_test 99c "cvs checkout ====================================="
3833
3834 test_99d() {
3835         [ -z "$(which cvs 2>/dev/null)" ] && skip "could not find cvs" && return
3836         [ ! -d $DIR/d99cvsroot ] && test_99c
3837         cd $DIR/d99reposname
3838         $RUNAS touch foo99
3839         $RUNAS cvs add -m 'addmsg' foo99
3840 }
3841 run_test 99d "cvs add =========================================="
3842
3843 test_99e() {
3844         [ -z "$(which cvs 2>/dev/null)" ] && skip "could not find cvs" && return
3845         [ ! -d $DIR/d99cvsroot ] && test_99c
3846         cd $DIR/d99reposname
3847         $RUNAS cvs update
3848 }
3849 run_test 99e "cvs update ======================================="
3850
3851 test_99f() {
3852         [ -z "$(which cvs 2>/dev/null)" ] && skip "could not find cvs" && return
3853         [ ! -d $DIR/d99cvsroot ] && test_99d
3854         cd $DIR/d99reposname
3855         $RUNAS cvs commit -m 'nomsg' foo99
3856     rm -fr $DIR/d99cvsroot
3857 }
3858 run_test 99f "cvs commit ======================================="
3859
3860 test_100() {
3861         [ "$NETTYPE" = tcp ] || \
3862                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
3863                         return ; }
3864
3865         remote_ost_nodsh && skip "remote OST with nodsh" && return
3866         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3867         remote_servers || \
3868                 { skip "useless for local single node setup" && return; }
3869
3870         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
3871                 [ "$PROT" != "tcp" ] && continue
3872                 RPORT=$(echo $REMOTE | cut -d: -f2)
3873                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
3874
3875                 rc=0
3876                 LPORT=`echo $LOCAL | cut -d: -f2`
3877                 if [ $LPORT -ge 1024 ]; then
3878                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
3879                         netstat -tna
3880                         error_exit "local: $LPORT > 1024, remote: $RPORT"
3881                 fi
3882         done
3883         [ "$rc" = 0 ] || error_exit "privileged port not found" )
3884 }
3885 run_test 100 "check local port using privileged port ==========="
3886
3887 function get_named_value()
3888 {
3889     local tag
3890
3891     tag=$1
3892     while read ;do
3893         line=$REPLY
3894         case $line in
3895         $tag*)
3896             echo $line | sed "s/^$tag//"
3897             break
3898             ;;
3899         esac
3900     done
3901 }
3902
3903 export CACHE_MAX=`lctl get_param -n llite.*.max_cached_mb | head -n 1`
3904 cleanup_101() {
3905         lctl set_param -n llite.*.max_cached_mb $CACHE_MAX
3906         trap 0
3907 }
3908
3909 test_101() {
3910         local s
3911         local discard
3912         local nreads=10000
3913         [ "$CPU" = "UML" ] && nreads=1000
3914         local cache_limit=32
3915
3916         lctl set_param -n osc.*-osc*.rpc_stats 0
3917         trap cleanup_101 EXIT
3918         lctl set_param -n llite.*.read_ahead_stats 0
3919         lctl set_param -n llite.*.max_cached_mb $cache_limit
3920
3921         #
3922         # randomly read 10000 of 64K chunks from file 3x 32MB in size
3923         #
3924         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
3925         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
3926
3927         discard=0
3928         for s in `lctl get_param -n llite.*.read_ahead_stats | \
3929                 get_named_value 'read but discarded' | cut -d" " -f1`; do
3930                         discard=$(($discard + $s))
3931         done
3932         cleanup_101
3933
3934         if [ $(($discard * 10)) -gt $nreads ] ;then
3935                 lctl get_param osc.*-osc*.rpc_stats
3936                 lctl get_param llite.*.read_ahead_stats
3937                 error "too many ($discard) discarded pages"
3938         fi
3939         rm -f $DIR/$tfile || true
3940 }
3941 run_test 101 "check read-ahead for random reads ================"
3942
3943 export SETUP_TEST101=no
3944 setup_test101() {
3945         [ "$SETUP_TEST101" = "yes" ] && return
3946         mkdir -p $DIR/$tdir
3947         STRIPE_SIZE=1048576
3948         STRIPE_COUNT=$OSTCOUNT
3949         STRIPE_OFFSET=0
3950
3951         trap cleanup_test101 EXIT
3952         # prepare the read-ahead file
3953         $SETSTRIPE $DIR/$tfile -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT
3954
3955         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
3956         SETUP_TEST101=yes
3957 }
3958
3959 cleanup_test101() {
3960         [ "$SETUP_TEST101" = "yes" ] || return
3961         trap 0
3962         rm -rf $DIR/$tdir
3963         rm -f $DIR/$tfile
3964         SETUP_TEST101=no
3965 }
3966
3967 calc_total() {
3968         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
3969 }
3970
3971 ra_check_101() {
3972         local READ_SIZE=$1
3973         local STRIPE_SIZE=1048576
3974         local RA_INC=1048576
3975         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
3976         local FILE_LENGTH=$((64*100))
3977         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
3978                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
3979         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
3980                         get_named_value 'read but discarded' | \
3981                         cut -d" " -f1 | calc_total`
3982
3983         if [ $DISCARD -gt $discard_limit ]; then
3984                 lctl get_param llite.*.read_ahead_stats
3985                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
3986         else
3987                 echo "Read-ahead success for size ${READ_SIZE}"
3988         fi
3989 }
3990
3991 test_101b() {
3992         [ "$OSTCOUNT" -lt "2" ] && skip "skipping stride IO stride-ahead test" && return
3993         local STRIPE_SIZE=1048576
3994         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
3995         local FILE_LENGTH=$((STRIPE_SIZE*100))
3996         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
3997         # prepare the read-ahead file
3998         setup_test101
3999         cancel_lru_locks osc
4000         for BIDX in 2 4 8 16 32 64 128 256
4001         do
4002                 local BSIZE=$((BIDX*4096))
4003                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
4004                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
4005                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
4006                 $LCTL set_param -n llite.*.read_ahead_stats 0
4007                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
4008                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
4009                 cancel_lru_locks osc
4010                 ra_check_101 $BSIZE
4011         done
4012         cleanup_test101
4013         true
4014 }
4015 run_test 101b "check stride-io mode read-ahead ================="
4016
4017 set_read_ahead() {
4018    lctl get_param -n llite.*.max_read_ahead_mb | head -n 1
4019    lctl set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
4020 }
4021
4022 test_101d() {
4023     local file=$DIR/$tfile
4024     local size=${FILESIZE_101c:-500}
4025     local ra_MB=${READAHEAD_MB:-40}
4026
4027     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
4028     [ $space -gt $((size / 1024)) ] ||
4029         { skip "Need free space ${size}M, have $space" && return; }
4030
4031     echo Creating ${size}M test file $file
4032     dd if=/dev/zero of=$file bs=1M count=$size
4033     echo Cancel LRU locks on lustre client to flush the client cache
4034     cancel_lru_locks osc
4035
4036     echo Disable read-ahead
4037     local old_READAHEAD=$(set_read_ahead 0)
4038
4039     echo Reading the test file $file with read-ahead disabled
4040     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
4041
4042     echo Cancel LRU locks on lustre client to flush the client cache
4043     cancel_lru_locks osc
4044     echo Enable read-ahead with ${ra_MB}MB
4045     set_read_ahead $ra_MB
4046
4047     echo Reading the test file $file with read-ahead enabled
4048     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
4049
4050     echo read-ahead disabled time read $time_ra_OFF
4051     echo read-ahead enabled  time read $time_ra_ON
4052
4053     set_read_ahead $old_READAHEAD
4054     rm -f $file
4055
4056     [ $time_ra_ON -lt $time_ra_OFF ] ||
4057         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
4058                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
4059 }
4060 run_test 101d "file read with and without read-ahead enabled  ================="
4061
4062 export SETUP_TEST102=no
4063 setup_test102() {
4064         [ "$SETUP_TEST102" = "yes" ] && return
4065         mkdir -p $DIR/$tdir
4066         chown $RUNAS_ID $DIR/$tdir
4067         STRIPE_SIZE=65536
4068         STRIPE_OFFSET=1
4069         STRIPE_COUNT=$OSTCOUNT
4070         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
4071
4072         trap cleanup_test102 EXIT
4073         cd $DIR
4074         $1 $SETSTRIPE $tdir -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT
4075         cd $DIR/$tdir
4076         for num in 1 2 3 4
4077         do
4078                 for count in `seq 1 $STRIPE_COUNT`
4079                 do
4080                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4081                         do
4082                                 local stripe_size=`expr $STRIPE_SIZE \* $num`
4083                                 local file=file"$num-$offset-$count"
4084                                 $1 $SETSTRIPE $file -s $stripe_size -i $offset -c $count
4085                         done
4086                 done
4087         done
4088
4089         cd $DIR
4090         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
4091         SETUP_TEST102=yes
4092 }
4093
4094 cleanup_test102() {
4095         trap 0
4096         [ "$SETUP_TEST102" = "yes" ] || return 0
4097         rm -f $TMP/f102.tar
4098         SETUP_TEST102=no
4099 }
4100
4101 test_102a() {
4102         local testfile=$DIR/xattr_testfile
4103
4104         rm -f $testfile
4105         touch $testfile
4106
4107         [ "$UID" != 0 ] && skip "must run as root" && return
4108         [ -z "`lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr`" ] && skip "must have user_xattr" && return
4109
4110         [ -z "$(which setfattr 2>/dev/null)" ] && skip "could not find setfattr" && return
4111
4112         echo "set/get xattr..."
4113         setfattr -n trusted.name1 -v value1 $testfile || error
4114         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
4115         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
4116
4117         setfattr -n user.author1 -v author1 $testfile || error
4118         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
4119         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
4120
4121         echo "listxattr..."
4122         setfattr -n trusted.name2 -v value2 $testfile || error
4123         setfattr -n trusted.name3 -v value3 $testfile || error
4124         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4125         grep "trusted.name" | wc -l` -eq 3 ] || error
4126
4127
4128         setfattr -n user.author2 -v author2 $testfile || error
4129         setfattr -n user.author3 -v author3 $testfile || error
4130         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
4131         grep "user" | wc -l` -eq 3 ] || error
4132
4133         echo "remove xattr..."
4134         setfattr -x trusted.name1 $testfile || error
4135         getfattr -d -m trusted $testfile 2> /dev/null | \
4136         grep "trusted.name1" && error || true
4137
4138         setfattr -x user.author1 $testfile || error
4139         getfattr -d -m user $testfile 2> /dev/null | \
4140         grep "user.author1" && error || true
4141
4142         # b10667: setting lustre special xattr be silently discarded
4143         echo "set lustre special xattr ..."
4144         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
4145
4146         rm -f $testfile
4147 }
4148 run_test 102a "user xattr test =================================="
4149
4150 test_102b() {
4151         # b10930: get/set/list trusted.lov xattr
4152         echo "get/set/list trusted.lov xattr ..."
4153         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
4154         local testfile=$DIR/$tfile
4155         $SETSTRIPE -s 65536 -i 1 -c 2 $testfile || error "setstripe failed"
4156         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
4157         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
4158
4159         local testfile2=${testfile}2
4160         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
4161                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
4162
4163         $MCREATE $testfile2
4164         setfattr -n trusted.lov -v $value $testfile2
4165         local tmp_file=${testfile}3
4166         $GETSTRIPE -v $testfile2 > $tmp_file
4167         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4168         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4169         [ "$stripe_size" -eq 65536 ] || error "stripe size $stripe_size != 65536"
4170         [ "$stripe_count" -eq 2 ] || error "stripe count $stripe_count != 2"
4171         rm -f $DIR/$tfile
4172 }
4173 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
4174
4175 test_102c() {
4176         # b10930: get/set/list lustre.lov xattr
4177         echo "get/set/list lustre.lov xattr ..."
4178         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
4179         mkdir -p $DIR/$tdir
4180         chown $RUNAS_ID $DIR/$tdir
4181         local testfile=$DIR/$tdir/$tfile
4182         $RUNAS $SETSTRIPE -s 65536 -i 1 -c 2 $testfile||error "setstripe failed"
4183         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
4184         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
4185
4186         local testfile2=${testfile}2
4187         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
4188                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
4189
4190         $RUNAS $MCREATE $testfile2
4191         $RUNAS setfattr -n lustre.lov -v $value $testfile2
4192         local tmp_file=${testfile}3
4193         $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
4194         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
4195         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
4196         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
4197         [ $stripe_count -eq 2 ] || error "stripe count $stripe_count != 2"
4198 }
4199 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
4200
4201 compare_stripe_info1() {
4202         local stripe_index_all_zero=1
4203
4204         for num in 1 2 3 4
4205         do
4206                 for count in `seq 1 $STRIPE_COUNT`
4207                 do
4208                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4209                         do
4210                                 local size=`expr $STRIPE_SIZE \* $num`
4211                                 local file=file"$num-$offset-$count"
4212                                 get_stripe_info client $PWD/$file "$1"
4213                                 if [ $stripe_size -ne $size ]; then
4214                                         error "$file: different stripe size $stripe_size, expected $size" && return
4215                                 fi
4216                                 if [ $stripe_count -ne $count ]; then
4217                                         error "$file: different stripe count $stripe_count, expected $count" && return
4218                                 fi
4219                                 if [ $stripe_index -ne 0 ]; then
4220                                        stripe_index_all_zero=0
4221                                 fi
4222                         done
4223                 done
4224         done
4225         [ $stripe_index_all_zero -eq 1 ] && error "all files are being extracted starting from OST index 0"
4226         return 0
4227 }
4228
4229 compare_stripe_info2() {
4230         for num in 1 2 3 4
4231         do
4232                 for count in `seq 1 $STRIPE_COUNT`
4233                 do
4234                         for offset in `seq 0 $[$STRIPE_COUNT - 1]`
4235                         do
4236                                 local size=`expr $STRIPE_SIZE \* $num`
4237                                 local file=file"$num-$offset-$count"
4238                                 get_stripe_info client $PWD/$file
4239                                 if [ $stripe_size -ne $size ]; then
4240                                         error "$file: different stripe size $stripe_size, expected $size" && return
4241                                 fi
4242                                 if [ $stripe_count -ne $count ]; then
4243                                         error "$file: different stripe count $stripe_count, expected $count" && return
4244                                 fi
4245                                 if [ $stripe_index -ne $offset ]; then
4246                                         error "$file: different stripe offset $stripe_index, expected $offset" && return
4247                                 fi
4248                         done
4249                 done
4250         done
4251 }
4252
4253 find_lustre_tar() {
4254         [ -n "$(which tar 2>/dev/null)" ] && strings $(which tar) | grep -q lustre && echo tar
4255 }
4256
4257 test_102d() {
4258         # b10930: tar test for trusted.lov xattr
4259         TAR=$(find_lustre_tar)
4260         [ -z "$TAR" ] && skip "lustre-aware tar is not installed" && return
4261         [ "$OSTCOUNT" -lt "2" ] && skip "skipping N-stripe test" && return
4262         setup_test102
4263         mkdir -p $DIR/d102d
4264         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
4265         cd $DIR/d102d/$tdir
4266         compare_stripe_info1
4267 }
4268 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
4269
4270 test_102f() {
4271         # b10930: tar test for trusted.lov xattr
4272         TAR=$(find_lustre_tar)
4273         [ -z "$TAR" ] && skip "lustre-aware tar is not installed" && return
4274         [ "$OSTCOUNT" -lt "2" ] && skip "skipping N-stripe test" && return
4275         setup_test102
4276         mkdir -p $DIR/d102f
4277         cd $DIR
4278         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
4279         cd $DIR/d102f/$tdir
4280         compare_stripe_info1
4281 }
4282 run_test 102f "tar copy files, not keep osts ==========="
4283
4284 test_102h() { # bug 15777
4285         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
4286                 skip "must have user_xattr" && return
4287         [ -z "$(which setfattr 2>/dev/null)" ] &&
4288                 skip "could not find setfattr" && return
4289
4290         XBIG=trusted.big
4291         XSIZE=1024
4292         touch $DIR/$tfile
4293         VALUE=datadatadatadatadatadatadatadata
4294         while [ $(echo $VALUE | wc -c) -lt $XSIZE ]; do
4295                 VALUE="$VALUE$VALUE"
4296         done
4297         log "save $XBIG on $DIR/$tfile"
4298         setfattr -n $XBIG -v "$VALUE" $DIR/$tfile ||
4299                 error "saving $XBIG on $DIR/$tfile failed"
4300         ORIG=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4301         OSIZE=$(echo $ORIG | wc -c)
4302         [ $OSIZE -lt $XSIZE ] && error "set $XBIG too small ($OSIZE < $XSIZE)"
4303
4304         XSML=trusted.sml
4305         log "save $XSML on $DIR/$tfile"
4306         setfattr -n $XSML -v val $DIR/$tfile ||
4307                 error "saving $XSML on $DIR/$tfile failed"
4308         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4309         if [ "$NEW" != "$ORIG" ]; then
4310                 log "orig: $ORIG"
4311                 log "new: $NEW"
4312                 error "$XBIG different after saving $XSML"
4313         fi
4314
4315         log "grow $XSML on $DIR/$tfile"
4316         setfattr -n $XSML -v "$VALUE" $DIR/$tfile ||
4317                 error "growing $XSML on $DIR/$tfile failed"
4318         NEW=$(getfattr -n $XBIG $DIR/$tfile 2> /dev/null | grep $XBIG)
4319         if [ "$NEW" != "$ORIG" ]; then
4320                 log "orig: $ORIG"
4321                 log "new: $NEW"
4322                 error "$XBIG different after growing $XSML"
4323         fi
4324         log "$XBIG still valid after growing $XSML"
4325         rm -f $file
4326 }
4327 run_test 102h "grow xattr from inside inode to external block"
4328
4329 test_102i() { # bug 17038
4330         touch $DIR/$tfile
4331         ln -s $DIR/$tfile $DIR/${tfile}link
4332         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
4333         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"
4334         rm -f $DIR/$tfile $DIR/${tfile}link
4335 }
4336 run_test 102i "lgetxattr test on symbolic link ============"
4337
4338 test_102j() {
4339         TAR=$(find_lustre_tar)
4340         [ -z "$TAR" ] && skip "lustre-aware tar is not installed" && return
4341         [ "$OSTCOUNT" -lt "2" ] && skip "skipping N-stripe test" && return
4342         setup_test102 "$RUNAS"
4343         mkdir -p $DIR/d102j
4344         chown $RUNAS_ID $DIR/d102j
4345         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
4346         cd $DIR/d102j/$tdir
4347         compare_stripe_info1 "$RUNAS"
4348 }
4349 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
4350
4351 cleanup_test102
4352
4353 run_acl_subtest()
4354 {
4355     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
4356     return $?
4357 }
4358
4359 test_103 () {
4360     [ "$UID" != 0 ] && skip "must run as root" && return
4361     [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
4362     [ -z "$(which setfacl 2>/dev/null)" ] && skip "could not find setfacl" && return
4363     $GSS && skip "could not run under gss" && return
4364
4365     declare -a identity_old
4366
4367     for num in `seq $MDSCOUNT`; do
4368         switch_identity $num true || identity_old[$num]=$?
4369     done
4370
4371     SAVE_UMASK=`umask`
4372     umask 0022
4373     cd $DIR
4374
4375     echo "performing cp ..."
4376     run_acl_subtest cp || error
4377     echo "performing getfacl-noacl..."
4378     run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
4379     echo "performing misc..."
4380     run_acl_subtest misc || error  "misc test failed"
4381     echo "performing permissions..."
4382     run_acl_subtest permissions || error "permissions failed"
4383     echo "performing setfacl..."
4384     run_acl_subtest setfacl || error  "setfacl test failed"
4385
4386     # inheritance test got from HP
4387     echo "performing inheritance..."
4388     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
4389     chmod +x make-tree || error "chmod +x failed"
4390     run_acl_subtest inheritance || error "inheritance test failed"
4391     rm -f make-tree
4392
4393     cd $SAVE_PWD
4394     umask $SAVE_UMASK
4395
4396     for num in `seq $MDSCOUNT`; do
4397         if [ "${identity_old[$num]}" = 1 ]; then
4398             switch_identity $num false || identity_old[$num]=$?
4399         fi
4400     done
4401 }
4402 run_test 103 "acl test ========================================="
4403
4404 test_104() {
4405         touch $DIR/$tfile
4406         lfs df || error "lfs df failed"
4407         lfs df -ih || error "lfs df -ih failed"
4408         lfs df -h $DIR || error "lfs df -h $DIR failed"
4409         lfs df -i $DIR || error "lfs df -i $DIR failed"
4410         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
4411         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
4412
4413         OSC=`lctl get_param -n devices | awk '/-osc-/ {print $4}' | head -n 1`
4414         lctl --device %$OSC deactivate
4415         lfs df || error "lfs df with deactivated OSC failed"
4416         lctl --device %$OSC recover
4417         lfs df || error "lfs df with reactivated OSC failed"
4418         rm -f $DIR/$tfile
4419 }
4420 run_test 104 "lfs df [-ih] [path] test ========================="
4421
4422 test_105a() {
4423         # doesn't work on 2.4 kernels
4424         touch $DIR/$tfile
4425         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4426         then
4427                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
4428         else
4429                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
4430         fi
4431         rm -f $DIR/$tfile
4432 }
4433 run_test 105a "flock when mounted without -o flock test ========"
4434
4435 test_105b() {
4436         touch $DIR/$tfile
4437         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4438         then
4439                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
4440         else
4441                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
4442         fi
4443         rm -f $DIR/$tfile
4444 }
4445 run_test 105b "fcntl when mounted without -o flock test ========"
4446
4447 test_105c() {
4448         touch $DIR/$tfile
4449         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
4450         then
4451                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
4452         else
4453                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
4454         fi
4455         rm -f $DIR/$tfile
4456 }
4457 run_test 105c "lockf when mounted without -o flock test ========"
4458
4459 test_105d() { # bug 15924
4460         mkdir -p $DIR/$tdir
4461         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
4462                 skip "mount w/o flock enabled" && return
4463         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
4464         $LCTL set_param fail_loc=0x80000315
4465         flocks_test 2 $DIR/$tdir
4466 }
4467 run_test 105d "flock race (should not freeze) ========"
4468
4469 test_106() { #bug 10921
4470         mkdir -p $DIR/$tdir
4471         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
4472         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
4473 }
4474 run_test 106 "attempt exec of dir followed by chown of that dir"
4475
4476 test_107() {
4477         CDIR=`pwd`
4478         cd $DIR
4479
4480         local file=core
4481         rm -f $file
4482
4483         local save_pattern=$(sysctl -n kernel.core_pattern)
4484         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
4485         sysctl -w kernel.core_pattern=$file
4486         sysctl -w kernel.core_uses_pid=0
4487
4488         ulimit -c unlimited
4489         sleep 60 &
4490         SLEEPPID=$!
4491
4492         sleep 1
4493
4494         kill -s 11 $SLEEPPID
4495         wait $SLEEPPID
4496         if [ -e $file ]; then
4497                 size=`stat -c%s $file`
4498                 [ $size -eq 0 ] && error "Fail to create core file $file"
4499         else
4500                 error "Fail to create core file $file"
4501         fi
4502         rm -f $file
4503         sysctl -w kernel.core_pattern=$save_pattern
4504         sysctl -w kernel.core_uses_pid=$save_uses_pid
4505         cd $CDIR
4506 }
4507 run_test 107 "Coredump on SIG"
4508
4509 test_110() {
4510         mkdir -p $DIR/d110
4511         mkdir $DIR/d110/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || error "mkdir with 255 char fail"
4512         mkdir $DIR/d110/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && error "mkdir with 256 char should fail, but not"
4513         touch $DIR/d110/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx || error "create with 255 char fail"
4514         touch $DIR/d110/yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy && error ""create with 256 char should fail, but not
4515
4516         ls -l $DIR/d110
4517     rm -fr $DIR/d110
4518 }
4519 run_test 110 "filename length checking"
4520
4521 test_115() {
4522         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4523             cut -c11-20)
4524         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
4525             return
4526         echo "Starting with $OSTIO_pre threads"
4527
4528         NUMTEST=20000
4529         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
4530         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
4531         echo "$NUMTEST creates/unlinks"
4532         mkdir -p $DIR/$tdir
4533         createmany -o $DIR/$tdir/$tfile $NUMTEST
4534         unlinkmany $DIR/$tdir/$tfile $NUMTEST
4535
4536         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
4537             cut -c11-20)
4538
4539         # don't return an error
4540         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
4541             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&\
4542             echo "This may be fine, depending on what ran before this test" &&\
4543             echo "and how fast this system is." && return
4544
4545         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
4546 }
4547 run_test 115 "verify dynamic thread creation===================="
4548
4549 free_min_max () {
4550         wait_delete_completed
4551         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
4552         echo OST kbytes available: ${AVAIL[@]}
4553         MAXI=0; MAXV=${AVAIL[0]}
4554         MINI=0; MINV=${AVAIL[0]}
4555         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
4556             #echo OST $i: ${AVAIL[i]}kb
4557             if [ ${AVAIL[i]} -gt $MAXV ]; then
4558                 MAXV=${AVAIL[i]}; MAXI=$i
4559             fi
4560             if [ ${AVAIL[i]} -lt $MINV ]; then
4561                 MINV=${AVAIL[i]}; MINI=$i
4562             fi
4563         done
4564         echo Min free space: OST $MINI: $MINV
4565         echo Max free space: OST $MAXI: $MAXV
4566 }
4567
4568 test_116() {
4569         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2 OSTs" && return
4570
4571         echo -n "Free space priority "
4572         lctl get_param -n lov.*-clilov-*.qos_prio_free
4573         DELAY=$(lctl get_param -n lov.*-clilov-*.qos_maxage | head -1 | awk '{print $1}')
4574         declare -a AVAIL
4575         free_min_max
4576         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI, skip" &&\
4577                 return
4578
4579         # generate uneven OSTs
4580         mkdir -p $DIR/$tdir/OST${MINI}
4581         declare -i FILL
4582         FILL=$(($MINV / 4))
4583         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
4584         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
4585         i=0
4586         while [ $FILL -gt 0 ]; do
4587             i=$(($i + 1))
4588             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
4589             FILL=$(($FILL - 2048))
4590             echo -n .
4591         done
4592         FILL=$(($MINV / 4))
4593         sync
4594         sleep $DELAY
4595
4596         free_min_max
4597         DIFF=$(($MAXV - $MINV))
4598         DIFF2=$(($DIFF * 100 / $MINV))
4599         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
4600         if [ $DIFF2 -gt 20 ]; then
4601             echo "ok"
4602         else
4603             echo "failed - QOS mode won't be used"
4604             error_ignore "QOS imbalance criteria not met"
4605             return
4606         fi
4607
4608         MINI1=$MINI; MINV1=$MINV
4609         MAXI1=$MAXI; MAXV1=$MAXV
4610
4611         # now fill using QOS
4612         echo writing a bunch of files to QOS-assigned OSTs
4613         $SETSTRIPE $DIR/$tdir -c 1
4614         i=0
4615         while [ $FILL -gt 0 ]; do
4616             i=$(($i + 1))
4617             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
4618             FILL=$(($FILL - 200))
4619             echo -n .
4620         done
4621         echo "wrote $i 200k files"
4622         sync
4623         sleep $DELAY
4624
4625         echo "Note: free space may not be updated, so measurements might be off"
4626         free_min_max
4627         DIFF2=$(($MAXV - $MINV))
4628         echo "free space delta: orig $DIFF final $DIFF2"
4629         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
4630         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
4631         echo "Wrote $DIFF to smaller OST $MINI1"
4632         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
4633         echo "Wrote $DIFF2 to larger OST $MAXI1"
4634         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
4635
4636         # Figure out which files were written where
4637         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
4638                awk '/'$MINI1': / {print $2; exit}')
4639         echo $UUID
4640         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4641         echo "$MINC files created on smaller OST $MINI1"
4642         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
4643                awk '/'$MAXI1': / {print $2; exit}')
4644         echo $UUID
4645         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
4646         echo "$MAXC files created on larger OST $MAXI1"
4647         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
4648         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
4649
4650         rm -rf $DIR/$tdir/OST${MINI}
4651 }
4652 run_test 116 "stripe QOS: free space balance ==================="
4653
4654 test_117() # bug 10891
4655 {
4656         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
4657         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
4658         lctl set_param fail_loc=0x21e
4659         > $DIR/$tfile || error "truncate failed"
4660         lctl set_param fail_loc=0
4661         echo "Truncate succeeded."
4662         rm -f $DIR/$tfile
4663 }
4664 run_test 117 "verify fsfilt_extend =========="
4665
4666 export OLD_RESENDCOUNT=""
4667 set_resend_count () {
4668         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
4669         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
4670         lctl set_param -n $PROC_RESENDCOUNT $1
4671         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
4672 }
4673
4674 [ "$SLOW" = "no" ] && set_resend_count 4 # for reduce test_118* time (bug 14842)
4675
4676 # Reset async IO behavior after error case
4677 reset_async() {
4678         FILE=$DIR/reset_async
4679
4680         # Ensure all OSCs are cleared
4681         $LSTRIPE -c -1 $FILE
4682         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
4683         sync
4684         rm $FILE
4685 }
4686
4687 test_118a() #bug 11710
4688 {
4689         reset_async
4690
4691         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4692         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4693         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4694
4695         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4696                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4697                 return 1;
4698         fi
4699         rm -f $DIR/$tfile
4700 }
4701 run_test 118a "verify O_SYNC works =========="
4702
4703 test_118b()
4704 {
4705         remote_ost_nodsh && skip "remote OST with nodsh" && return
4706
4707         reset_async
4708
4709         #define OBD_FAIL_OST_ENOENT 0x217
4710         set_nodes_failloc "$(osts_nodes)" 0x217
4711         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4712         RC=$?
4713         set_nodes_failloc "$(osts_nodes)" 0
4714         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4715         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4716                     grep -c writeback)
4717
4718         if [[ $RC -eq 0 ]]; then
4719                 error "Must return error due to dropped pages, rc=$RC"
4720                 return 1;
4721         fi
4722
4723         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4724                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4725                 return 1;
4726         fi
4727
4728         echo "Dirty pages not leaked on ENOENT"
4729
4730         # Due to the above error the OSC will issue all RPCs syncronously
4731         # until a subsequent RPC completes successfully without error.
4732         multiop $DIR/$tfile Ow4096yc
4733         rm -f $DIR/$tfile
4734
4735         return 0
4736 }
4737 run_test 118b "Reclaim dirty pages on fatal error =========="
4738
4739 test_118c()
4740 {
4741         remote_ost_nodsh && skip "remote OST with nodsh" && return
4742
4743         reset_async
4744
4745         #define OBD_FAIL_OST_EROFS               0x216
4746         set_nodes_failloc "$(osts_nodes)" 0x216
4747
4748         # multiop should block due to fsync until pages are written
4749         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4750         MULTIPID=$!
4751         sleep 1
4752
4753         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4754                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4755         fi
4756
4757         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4758                     grep -c writeback)
4759         if [[ $WRITEBACK -eq 0 ]]; then
4760                 error "No page in writeback, writeback=$WRITEBACK"
4761         fi
4762
4763         set_nodes_failloc "$(osts_nodes)" 0
4764         wait $MULTIPID
4765         RC=$?
4766         if [[ $RC -ne 0 ]]; then
4767                 error "Multiop fsync failed, rc=$RC"
4768         fi
4769
4770         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4771         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4772                     grep -c writeback)
4773         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4774                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4775         fi
4776
4777         rm -f $DIR/$tfile
4778         echo "Dirty pages flushed via fsync on EROFS"
4779         return 0
4780 }
4781 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
4782
4783 test_118d()
4784 {
4785         remote_ost_nodsh && skip "remote OST with nodsh" && return
4786
4787         reset_async
4788
4789         #define OBD_FAIL_OST_BRW_PAUSE_BULK
4790         set_nodes_failloc "$(osts_nodes)" 0x214
4791         # multiop should block due to fsync until pages are written
4792         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4793         MULTIPID=$!
4794         sleep 1
4795
4796         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
4797                 error "Multiop failed to block on fsync, pid=$MULTIPID"
4798         fi
4799
4800         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4801                     grep -c writeback)
4802         if [[ $WRITEBACK -eq 0 ]]; then
4803                 error "No page in writeback, writeback=$WRITEBACK"
4804         fi
4805
4806         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
4807         set_nodes_failloc "$(osts_nodes)" 0
4808
4809         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4810         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4811                     grep -c writeback)
4812         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4813                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4814         fi
4815
4816         rm -f $DIR/$tfile
4817         echo "Dirty pages gaurenteed flushed via fsync"
4818         return 0
4819 }
4820 run_test 118d "Fsync validation inject a delay of the bulk =========="
4821
4822 test_118f() {
4823         reset_async
4824
4825         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
4826         lctl set_param fail_loc=0x8000040a
4827
4828         # Should simulate EINVAL error which is fatal
4829         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4830         RC=$?
4831         if [[ $RC -eq 0 ]]; then
4832                 error "Must return error due to dropped pages, rc=$RC"
4833         fi
4834
4835         lctl set_param fail_loc=0x0
4836
4837         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
4838         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4839         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4840                     grep -c writeback)
4841         if [[ $LOCKED -ne 0 ]]; then
4842                 error "Locked pages remain in cache, locked=$LOCKED"
4843         fi
4844
4845         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4846                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4847         fi
4848
4849         rm -f $DIR/$tfile
4850         echo "No pages locked after fsync"
4851
4852         reset_async
4853         return 0
4854 }
4855 run_test 118f "Simulate unrecoverable OSC side error =========="
4856
4857 test_118g() {
4858         reset_async
4859
4860         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4861         lctl set_param fail_loc=0x406
4862
4863         # simulate local -ENOMEM
4864         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4865         RC=$?
4866
4867         lctl set_param fail_loc=0
4868         if [[ $RC -eq 0 ]]; then
4869                 error "Must return error due to dropped pages, rc=$RC"
4870         fi
4871
4872         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
4873         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4874         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4875                         grep -c writeback)
4876         if [[ $LOCKED -ne 0 ]]; then
4877                 error "Locked pages remain in cache, locked=$LOCKED"
4878         fi
4879
4880         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4881                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4882         fi
4883
4884         rm -f $DIR/$tfile
4885         echo "No pages locked after fsync"
4886
4887         reset_async
4888         return 0
4889 }
4890 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
4891
4892 test_118h() {
4893         remote_ost_nodsh && skip "remote OST with nodsh" && return
4894
4895         reset_async
4896
4897         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4898         set_nodes_failloc "$(osts_nodes)" 0x20e
4899         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4900         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4901         RC=$?
4902
4903         set_nodes_failloc "$(osts_nodes)" 0
4904         if [[ $RC -eq 0 ]]; then
4905                 error "Must return error due to dropped pages, rc=$RC"
4906         fi
4907
4908         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
4909         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4910         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
4911                     grep -c writeback)
4912         if [[ $LOCKED -ne 0 ]]; then
4913                 error "Locked pages remain in cache, locked=$LOCKED"
4914         fi
4915
4916         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4917                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4918         fi
4919
4920         rm -f $DIR/$tfile
4921         echo "No pages locked after fsync"
4922
4923         return 0
4924 }
4925 run_test 118h "Verify timeout in handling recoverables errors  =========="
4926
4927 test_118i() {
4928         remote_ost_nodsh && skip "remote OST with nodsh" && return
4929
4930         reset_async
4931
4932         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4933         set_nodes_failloc "$(osts_nodes)" 0x20e
4934
4935         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4936         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
4937         PID=$!
4938         sleep 5
4939         set_nodes_failloc "$(osts_nodes)" 0
4940
4941         wait $PID
4942         RC=$?
4943         if [[ $RC -ne 0 ]]; then
4944                 error "got error, but should be not, rc=$RC"
4945         fi
4946
4947         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
4948         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4949         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4950         if [[ $LOCKED -ne 0 ]]; then
4951                 error "Locked pages remain in cache, locked=$LOCKED"
4952         fi
4953
4954         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4955                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4956         fi
4957
4958         rm -f $DIR/$tfile
4959         echo "No pages locked after fsync"
4960
4961         return 0
4962 }
4963 run_test 118i "Fix error before timeout in recoverable error  =========="
4964
4965 test_118j() {
4966         remote_ost_nodsh && skip "remote OST with nodsh" && return
4967
4968         reset_async
4969
4970         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
4971         set_nodes_failloc "$(osts_nodes)" 0x220
4972
4973         # return -EIO from OST
4974         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4975         RC=$?
4976         set_nodes_failloc "$(osts_nodes)" 0x0
4977         if [[ $RC -eq 0 ]]; then
4978                 error "Must return error due to dropped pages, rc=$RC"
4979         fi
4980
4981         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
4982         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
4983         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
4984         if [[ $LOCKED -ne 0 ]]; then
4985                 error "Locked pages remain in cache, locked=$LOCKED"
4986         fi
4987
4988         # in recoverable error on OST we want resend and stay until it finished
4989         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4990                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4991         fi
4992
4993         rm -f $DIR/$tfile
4994         echo "No pages locked after fsync"
4995
4996         return 0
4997 }
4998 run_test 118j "Simulate unrecoverable OST side error =========="
4999
5000 test_118k()
5001 {
5002         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
5003
5004         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
5005         set_nodes_failloc "$(osts_nodes)" 0x20e
5006         mkdir -p $DIR/$tdir
5007
5008         for ((i=0;i<10;i++)); do
5009                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
5010                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
5011                 SLEEPPID=$!
5012                 sleep 0.500s
5013                 kill $SLEEPPID
5014                 wait $SLEEPPID
5015         done
5016
5017         set_nodes_failloc "$(osts_nodes)" 0
5018 }
5019 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
5020
5021 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
5022
5023 test_119a() # bug 11737
5024 {
5025         BSIZE=$((512 * 1024))
5026         directio write $DIR/$tfile 0 1 $BSIZE
5027         # We ask to read two blocks, which is more than a file size.
5028         # directio will indicate an error when requested and actual
5029         # sizes aren't equeal (a normal situation in this case) and
5030         # print actual read amount.
5031         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
5032         if [ "$NOB" != "$BSIZE" ]; then
5033                 error "read $NOB bytes instead of $BSIZE"
5034         fi
5035         rm -f $DIR/$tfile
5036 }
5037 run_test 119a "Short directIO read must return actual read amount"
5038
5039 test_119b() # bug 11737
5040 {
5041         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
5042
5043         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
5044         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
5045         sync
5046         multiop $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
5047                 error "direct read failed"
5048         rm -f $DIR/$tfile
5049 }
5050 run_test 119b "Sparse directIO read must return actual read amount"
5051
5052 test_119c() # bug 13099
5053 {
5054         BSIZE=1048576
5055         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
5056         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
5057         rm -f $DIR/$tfile
5058 }
5059 run_test 119c "Testing for direct read hitting hole"
5060
5061 test_119d() # bug 15950
5062 {
5063         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
5064         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
5065         BSIZE=1048576
5066         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
5067         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
5068         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
5069         lctl set_param fail_loc=0x40d
5070         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
5071         pid_dio=$!
5072         sleep 1
5073         cat $DIR/$tfile > /dev/null &
5074         lctl set_param fail_loc=0
5075         pid_reads=$!
5076         wait $pid_dio
5077         log "the DIO writes have completed, now wait for the reads (should not block very long)"
5078         sleep 2
5079         [ -n "`ps h -p $pid_reads -o comm`" ] && \
5080         error "the read rpcs have not completed in 2s"
5081         rm -f $DIR/$tfile
5082         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
5083 }
5084 run_test 119d "The DIO path should try to send a new rpc once one is completed"
5085
5086 test_120a() {
5087         mkdir -p $DIR/$tdir
5088         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5089                skip "no early lock cancel on server" && return 0
5090         lru_resize_disable mdc
5091         lru_resize_disable osc
5092         cancel_lru_locks mdc
5093         stat $DIR/$tdir > /dev/null
5094         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5095         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5096         mkdir $DIR/$tdir/d1
5097         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5098         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5099         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5100         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5101         lru_resize_enable mdc
5102         lru_resize_enable osc
5103 }
5104 run_test 120a "Early Lock Cancel: mkdir test"
5105
5106 test_120b() {
5107         mkdir -p $DIR/$tdir
5108         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5109                skip "no early lock cancel on server" && return 0
5110         lru_resize_disable mdc
5111         lru_resize_disable osc
5112         cancel_lru_locks mdc
5113         stat $DIR/$tdir > /dev/null
5114         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5115         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5116         touch $DIR/$tdir/f1
5117         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5118         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5119         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5120         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5121         lru_resize_enable mdc
5122         lru_resize_enable osc
5123 }
5124 run_test 120b "Early Lock Cancel: create test"
5125
5126 test_120c() {
5127         mkdir -p $DIR/$tdir
5128         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5129                skip "no early lock cancel on server" && return 0
5130         lru_resize_disable mdc
5131         lru_resize_disable osc
5132         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
5133         touch $DIR/$tdir/d1/f1
5134         cancel_lru_locks mdc
5135         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
5136         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5137         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5138         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
5139         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5140         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5141         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5142         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5143         lru_resize_enable mdc
5144         lru_resize_enable osc
5145 }
5146 run_test 120c "Early Lock Cancel: link test"
5147
5148 test_120d() {
5149         mkdir -p $DIR/$tdir
5150         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5151                skip "no early lock cancel on server" && return 0
5152         lru_resize_disable mdc
5153         lru_resize_disable osc
5154         touch $DIR/$tdir
5155         cancel_lru_locks mdc
5156         stat $DIR/$tdir > /dev/null
5157         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5158         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5159         chmod a+x $DIR/$tdir
5160         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
5161         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
5162         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5163         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5164         lru_resize_enable mdc
5165         lru_resize_enable osc
5166 }
5167 run_test 120d "Early Lock Cancel: setattr test"
5168
5169 test_120e() {
5170         mkdir -p $DIR/$tdir
5171         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5172                skip "no early lock cancel on server" && return 0
5173         lru_resize_disable mdc
5174         lru_resize_disable osc
5175         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
5176         cancel_lru_locks mdc
5177         cancel_lru_locks osc
5178         dd if=$DIR/$tdir/f1 of=/dev/null
5179         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
5180         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
5181               awk '/ldlm_cancel/ {print $2}'`
5182         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
5183               awk '/ldlm_bl_callback/ {print $2}'`
5184         unlink $DIR/$tdir/f1
5185         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
5186               awk '/ldlm_cancel/ {print $2}'`
5187         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
5188               awk '/ldlm_bl_callback/ {print $2}'`
5189         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5190         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5191         lru_resize_enable mdc
5192         lru_resize_enable osc
5193 }
5194 run_test 120e "Early Lock Cancel: unlink test"
5195
5196 test_120f() {
5197         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5198                skip "no early lock cancel on server" && return 0
5199         mkdir -p $DIR/$tdir
5200         lru_resize_disable mdc
5201         lru_resize_disable osc
5202         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
5203         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
5204         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
5205         cancel_lru_locks mdc
5206         cancel_lru_locks osc
5207         dd if=$DIR/$tdir/d1/f1 of=/dev/null
5208         dd if=$DIR/$tdir/d2/f2 of=/dev/null
5209         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
5210         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
5211               awk '/ldlm_cancel/ {print $2}'`
5212         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
5213               awk '/ldlm_bl_callback/ {print $2}'`
5214         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
5215         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
5216               awk '/ldlm_cancel/ {print $2}'`
5217         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
5218               awk '/ldlm_bl_callback/ {print $2}'`
5219         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
5220         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
5221         lru_resize_enable mdc
5222         lru_resize_enable osc
5223 }
5224 run_test 120f "Early Lock Cancel: rename test"
5225
5226 test_120g() {
5227         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
5228                skip "no early lock cancel on server" && return 0
5229         lru_resize_disable mdc
5230         lru_resize_disable osc
5231         count=10000
5232         echo create $count files
5233         mkdir -p $DIR/$tdir
5234         cancel_lru_locks mdc
5235         cancel_lru_locks osc
5236         t0=`date +%s`
5237
5238         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
5239               awk '/ldlm_cancel/ {print $2}'`
5240         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
5241               awk '/ldlm_bl_callback/ {print $2}'`
5242         createmany -o $DIR/$tdir/f $count
5243         sync
5244         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
5245               awk '/ldlm_cancel/ {print $2}'`
5246         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
5247               awk '/ldlm_bl_callback/ {print $2}'`
5248         t1=`date +%s`
5249         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
5250         echo rm $count files
5251         rm -r $DIR/$tdir
5252         sync
5253         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
5254               awk '/ldlm_cancel/ {print $2}'`
5255         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
5256               awk '/ldlm_bl_callback/ {print $2}'`
5257         t2=`date +%s`
5258         echo total: $count removes in $((t2-t1))
5259         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
5260         sleep 2
5261         # wait for commitment of removal
5262         lru_resize_enable mdc
5263         lru_resize_enable osc
5264 }
5265 run_test 120g "Early Lock Cancel: performance test"
5266
5267 test_121() { #bug #10589
5268         rm -rf $DIR/$tfile
5269         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
5270 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
5271         lctl set_param fail_loc=0x310
5272         cancel_lru_locks osc > /dev/null
5273         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
5274         lctl set_param fail_loc=0
5275         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
5276 }
5277 run_test 121 "read cancel race ========="
5278
5279 test_123a() { # was test 123, statahead(bug 11401)
5280         SLOWOK=0
5281         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
5282                 log "testing on UP system. Performance may be not as good as expected."
5283                 SLOWOK=1
5284         fi
5285
5286         rm -rf $DIR/$tdir
5287         mkdir -p $DIR/$tdir
5288         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
5289         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
5290         MULT=10
5291         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
5292                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
5293
5294                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
5295                 lctl set_param -n llite.*.statahead_max 0
5296                 lctl get_param llite.*.statahead_max
5297                 cancel_lru_locks mdc
5298                 cancel_lru_locks osc
5299                 stime=`date +%s`
5300                 time ls -l $DIR/$tdir | wc -l
5301                 etime=`date +%s`
5302                 delta=$((etime - stime))
5303                 log "ls $i files without statahead: $delta sec"
5304                 lctl set_param llite.*.statahead_max=$max
5305
5306                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
5307                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
5308                 cancel_lru_locks mdc
5309                 cancel_lru_locks osc
5310                 stime=`date +%s`
5311                 time ls -l $DIR/$tdir | wc -l
5312                 etime=`date +%s`
5313                 delta_sa=$((etime - stime))
5314                 log "ls $i files with statahead: $delta_sa sec"
5315                 lctl get_param -n llite.*.statahead_stats
5316                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
5317
5318                 if [ $swrong -lt $ewrong ]; then
5319                         log "statahead was stopped, maybe too many locks held!"
5320                 fi
5321
5322                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
5323
5324                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
5325                         if [  $SLOWOK -eq 0 ]; then
5326                                 error "ls $i files is slower with statahead!"
5327                                 debugsave
5328
5329                                 lctl set_param debug=-1
5330                                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
5331                                 lctl set_param -n llite.*.statahead_max 0
5332                                 lctl get_param llite.*.statahead_max
5333                                 cancel_lru_locks mdc
5334                                 cancel_lru_locks osc
5335                                 $LCTL clear
5336                                 stime=`date +%s`
5337                                 time ls -l $DIR/$tdir | wc -l
5338                                 etime=`date +%s`
5339                                 error "ls $i files (again) without statahead: $((etime - stime)) sec"
5340
5341                                 lctl set_param debug=-1
5342                                 lctl set_param llite.*.statahead_max=$max
5343                                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
5344                                 cancel_lru_locks mdc
5345                                 cancel_lru_locks osc
5346                                 $LCTL clear
5347                                 stime=`date +%s`
5348                                 time ls -l $DIR/$tdir | wc -l
5349                                 etime=`date +%s`
5350                                 error "ls $i files (again) with statahead: $((etime - stime)) sec"
5351                                 lctl get_param -n llite.*.statahead_stats
5352
5353                                 debugrestore
5354                         else
5355                                 log "ls $i files is slower with statahead!"
5356                         fi
5357                         break
5358                 fi
5359
5360                 [ $delta -gt 20 ] && break
5361                 [ $delta -gt 8 ] && MULT=$((50 / delta))
5362                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
5363         done
5364         log "ls done"
5365
5366         stime=`date +%s`
5367         rm -r $DIR/$tdir
5368         sync
5369         etime=`date +%s`
5370         delta=$((etime - stime))
5371         log "rm -r $DIR/$tdir/: $delta seconds"
5372         log "rm done"
5373         lctl get_param -n llite.*.statahead_stats
5374 }
5375 run_test 123a "verify statahead work"
5376
5377 test_123b () { # statahead(bug 15027)
5378         mkdir -p $DIR/$tdir
5379         createmany -o $DIR/$tdir/$tfile-%d 1000
5380
5381         cancel_lru_locks mdc
5382         cancel_lru_locks osc
5383
5384 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
5385         lctl set_param fail_loc=0x80000803
5386         ls -lR $DIR/$tdir > /dev/null
5387         log "ls done"
5388         lctl set_param fail_loc=0x0
5389         lctl get_param -n llite.*.statahead_stats
5390         rm -r $DIR/$tdir
5391         sync
5392
5393 }
5394 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
5395
5396 test_124a() {
5397         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
5398                skip "no lru resize on server" && return 0
5399         local NR=2000
5400         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
5401
5402         log "create $NR files at $DIR/$tdir"
5403         createmany -o $DIR/$tdir/f $NR ||
5404                 error "failed to create $NR files in $DIR/$tdir"
5405
5406         cancel_lru_locks mdc
5407         ls -l $DIR/$tdir > /dev/null
5408
5409         local NSDIR=""
5410         local LRU_SIZE=0
5411         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
5412                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5413                 LRU_SIZE=$(lctl get_param -n $PARAM)
5414                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
5415                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
5416                         log "NS=$(basename $NSDIR)"
5417                         break
5418                 fi
5419         done
5420
5421         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
5422                 skip "Not enough cached locks created!"
5423                 return 0
5424         fi
5425         log "LRU=$LRU_SIZE"
5426
5427         local SLEEP=30
5428
5429         # We know that lru resize allows one client to hold $LIMIT locks
5430         # for 10h. After that locks begin to be killed by client.
5431         local MAX_HRS=10
5432         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
5433
5434         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
5435         # killing locks. Some time was spent for creating locks. This means
5436         # that up to the moment of sleep finish we must have killed some of
5437         # them (10-100 locks). This depends on how fast ther were created.
5438         # Many of them were touched in almost the same moment and thus will
5439         # be killed in groups.
5440         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
5441
5442         # Use $LRU_SIZE_B here to take into account real number of locks
5443         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
5444         local LRU_SIZE_B=$LRU_SIZE
5445         log "LVF=$LVF"
5446         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
5447         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
5448
5449         # Let's make sure that we really have some margin. Client checks
5450         # cached locks every 10 sec.
5451         SLEEP=$((SLEEP+20))
5452         log "Sleep ${SLEEP} sec"
5453         local SEC=0
5454         while ((SEC<$SLEEP)); do
5455                 echo -n "..."
5456                 sleep 5
5457                 SEC=$((SEC+5))
5458                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
5459                 echo -n "$LRU_SIZE"
5460         done
5461         echo ""
5462         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
5463         local LRU_SIZE_A=`lctl get_param -n $NSDIR/lru_size`
5464
5465         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
5466                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
5467                 unlinkmany $DIR/$tdir/f $NR
5468                 return
5469         }
5470
5471         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
5472         log "unlink $NR files at $DIR/$tdir"
5473         unlinkmany $DIR/$tdir/f $NR
5474 }
5475 run_test 124a "lru resize ======================================="
5476
5477 get_max_pool_limit()
5478 {
5479         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
5480         local max=0
5481         for l in $limit; do
5482                 if test $l -gt $max; then
5483                         max=$l
5484                 fi
5485         done
5486         echo $max
5487 }
5488
5489 test_124b() {
5490         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
5491                skip "no lru resize on server" && return 0
5492
5493         LIMIT=`get_max_pool_limit`
5494
5495         NR=$(($(default_lru_size)*20))
5496         if [ $NR -gt $LIMIT ]; then
5497                 log "Limit lock number by $LIMIT locks"
5498                 NR=$LIMIT
5499         fi
5500         lru_resize_disable mdc
5501         mkdir -p $DIR/$tdir/disable_lru_resize ||
5502                 error "failed to create $DIR/$tdir/disable_lru_resize"
5503
5504         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
5505         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
5506         cancel_lru_locks mdc
5507         stime=`date +%s`
5508         PID=""
5509         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5510         PID="$PID $!"
5511         sleep 2
5512         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5513         PID="$PID $!"
5514         sleep 2
5515         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
5516         PID="$PID $!"
5517         wait $PID
5518         etime=`date +%s`
5519         nolruresize_delta=$((etime-stime))
5520         log "ls -la time: $nolruresize_delta seconds"
5521         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
5522         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
5523
5524         lru_resize_enable mdc
5525         mkdir -p $DIR/$tdir/enable_lru_resize ||
5526                 error "failed to create $DIR/$tdir/enable_lru_resize"
5527
5528         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
5529         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
5530         cancel_lru_locks mdc
5531         stime=`date +%s`
5532         PID=""
5533         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5534         PID="$PID $!"
5535         sleep 2
5536         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5537         PID="$PID $!"
5538         sleep 2
5539         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
5540         PID="$PID $!"
5541         wait $PID
5542         etime=`date +%s`
5543         lruresize_delta=$((etime-stime))
5544         log "ls -la time: $lruresize_delta seconds"
5545         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
5546
5547         if [ $lruresize_delta -gt $nolruresize_delta ]; then
5548                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
5549         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
5550                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
5551         else
5552                 log "lru resize performs the same with no lru resize"
5553         fi
5554         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
5555 }
5556 run_test 124b "lru resize (performance test) ======================="
5557
5558 test_125() { # 13358
5559         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
5560         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
5561         mkdir -p $DIR/d125 || error "mkdir failed"
5562         $SETSTRIPE $DIR/d125 -s 65536 -c -1 || error "setstripe failed"
5563         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
5564         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
5565 }
5566 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
5567
5568 test_126() { # bug 12829/13455
5569         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
5570         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
5571         $GSS && skip "must run as gss disabled" && return
5572
5573         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
5574         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
5575         rm -f $DIR/$tfile
5576         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
5577 }
5578 run_test 126 "check that the fsgid provided by the client is taken into account"
5579
5580 test_127() { # bug 15521
5581         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
5582         $LCTL set_param osc.*.stats=0
5583         FSIZE=$((2048 * 1024))
5584         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
5585         cancel_lru_locks osc
5586         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
5587
5588         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
5589         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
5590                 echo "got $COUNT $NAME"
5591                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
5592                 eval $NAME=$COUNT || error "Wrong proc format"
5593
5594                 case $NAME in
5595                         read_bytes|write_bytes)
5596                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
5597                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
5598                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
5599                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
5600                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
5601                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
5602                                 error "sumsquare is too small: $SUMSQ"
5603                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
5604                                 error "sumsquare is too big: $SUMSQ"
5605                         ;;
5606                         *) ;;
5607                 esac
5608         done < $DIR/${tfile}.tmp
5609
5610         #check that we actually got some stats
5611         [ "$read_bytes" ] || error "Missing read_bytes stats"
5612         [ "$write_bytes" ] || error "Missing write_bytes stats"
5613         [ "$read_bytes" != 0 ] || error "no read done"
5614         [ "$write_bytes" != 0 ] || error "no write done"
5615 }
5616 run_test 127 "verify the client stats are sane"
5617
5618 test_128() { # bug 15212
5619         touch $DIR/$tfile
5620         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
5621                 find $DIR/$tfile
5622                 find $DIR/$tfile
5623         EOF
5624
5625         result=$(grep error $TMP/$tfile.log)
5626         rm -f $DIR/$tfile
5627         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
5628 }
5629 run_test 128 "interactive lfs for 2 consecutive find's"
5630
5631 set_dir_limits () {
5632         local mntdev
5633         local node
5634
5635         local LDPROC=/proc/fs/ldiskfs
5636
5637         for node in $(mdts_nodes); do
5638                 devs=$(do_node $node "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
5639                 for dev in $devs; do
5640                         mntdev=$(do_node $node "lctl get_param -n osd.$dev.mntdev")
5641                         do_node $node "echo $1 >$LDPROC/\\\$(basename $mntdev)/max_dir_size"
5642                 done
5643         done
5644 }
5645 test_129() {
5646         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return 0
5647         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5648
5649         EFBIG=27
5650         MAX=16384
5651
5652         set_dir_limits $MAX
5653
5654         mkdir -p $DIR/$tdir
5655
5656         I=0
5657         J=0
5658         while [ ! $I -gt $((MAX * MDSCOUNT)) ]; do
5659                 multiop $DIR/$tdir/$J Oc
5660                 rc=$?
5661                 if [ $rc -eq $EFBIG ]; then
5662                         set_dir_limits 0
5663                         echo "return code $rc received as expected"
5664                         return 0
5665                 elif [ $rc -ne 0 ]; then
5666                         set_dir_limits 0
5667                         error_exit "return code $rc received instead of expected $EFBIG"
5668                 fi
5669                 J=$((J+1))
5670                 I=$(stat -c%s "$DIR/$tdir")
5671         done
5672
5673         error "exceeded dir size limit $MAX x $MDSCOUNT $((MAX * MDSCOUNT)) : $I bytes"
5674         do_facet $SINGLEMDS "echo 0 >$LDPROC"
5675 }
5676 run_test 129 "test directory size limit ========================"
5677
5678 OLDIFS="$IFS"
5679 cleanup_130() {
5680         trap 0
5681         IFS="$OLDIFS"
5682 }
5683
5684 test_130a() {
5685         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5686         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
5687
5688         trap cleanup_130 EXIT RETURN
5689
5690         local fm_file=$DIR/$tfile
5691         lfs setstripe -s 65536 -c 1 $fm_file || error "setstripe failed on $fm_file"
5692         dd if=/dev/zero of=$fm_file bs=65536 count=1 || error "dd failed for $fm_file"
5693
5694         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5695         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5696
5697         lun=`$GETSTRIPE $fm_file  | grep -A 10 obdidx | awk '{print $1}' | grep -v "obdidx"`
5698
5699         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
5700         IFS=$'\n'
5701         tot_len=0
5702         for line in $filefrag_op
5703         do
5704                 frag_lun=`echo $line | cut -d: -f5`
5705                 ext_len=`echo $line | cut -d: -f4`
5706                 if (( $frag_lun != $lun )); then
5707                         cleanup_130
5708                         error "FIEMAP on 1-stripe file($fm_file) failed"
5709                         return
5710                 fi
5711                 (( tot_len += ext_len ))
5712         done
5713
5714         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
5715                 cleanup_130
5716                 error "FIEMAP on 1-stripe file($fm_file) failed;"
5717                 return
5718         fi
5719
5720         cleanup_130
5721
5722         echo "FIEMAP on single striped file succeeded"
5723 }
5724 run_test 130a "FIEMAP (1-stripe file)"
5725
5726 test_130b() {
5727         [ "$OSTCOUNT" -lt "2" ] && skip "skipping FIEMAP on 2-stripe file test" && return
5728
5729         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5730         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
5731
5732         trap cleanup_130 EXIT RETURN
5733
5734         local fm_file=$DIR/$tfile
5735         lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
5736         dd if=/dev/zero of=$fm_file bs=1M count=2 || error "dd failed on $fm_file"
5737
5738         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5739         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5740
5741         last_lun=`echo $filefrag_op | cut -d: -f5`
5742
5743         IFS=$'\n'
5744         tot_len=0
5745         num_luns=1
5746         for line in $filefrag_op
5747         do
5748                 frag_lun=`echo $line | cut -d: -f5`
5749                 ext_len=`echo $line | cut -d: -f4`
5750                 if (( $frag_lun != $last_lun )); then
5751                         if (( tot_len != 1024 )); then
5752                                 cleanup_130
5753                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
5754                                 return
5755                         else
5756                                 (( num_luns += 1 ))
5757                                 tot_len=0
5758                         fi
5759                 fi
5760                 (( tot_len += ext_len ))
5761                 last_lun=$frag_lun
5762         done
5763         if (( num_luns != 2 || tot_len != 1024 )); then
5764                 cleanup_130
5765                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
5766                 return
5767         fi
5768
5769         cleanup_130
5770
5771         echo "FIEMAP on 2-stripe file succeeded"
5772 }
5773 run_test 130b "FIEMAP (2-stripe file)"
5774
5775 test_130c() {
5776         [ "$OSTCOUNT" -lt "2" ] && skip "skipping FIEMAP on 2-stripe file with hole test" && return
5777
5778         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5779         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
5780
5781         trap cleanup_130 EXIT RETURN
5782
5783         local fm_file=$DIR/$tfile
5784         lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
5785         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
5786
5787         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5788         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5789
5790         last_lun=`echo $filefrag_op | cut -d: -f5`
5791
5792         IFS=$'\n'
5793         tot_len=0
5794         num_luns=1
5795         for line in $filefrag_op
5796         do
5797                 frag_lun=`echo $line | cut -d: -f5`
5798                 ext_len=`echo $line | cut -d: -f4`
5799                 if (( $frag_lun != $last_lun )); then
5800                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
5801                         if (( logical != 512 )); then
5802                                 cleanup_130
5803                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
5804                                 return
5805                         fi
5806                         if (( tot_len != 512 )); then
5807                                 cleanup_130
5808                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
5809                                 return
5810                         else
5811                                 (( num_luns += 1 ))
5812                                 tot_len=0
5813                         fi
5814                 fi
5815                 (( tot_len += ext_len ))
5816                 last_lun=$frag_lun
5817         done
5818         if (( num_luns != 2 || tot_len != 512 )); then
5819                 cleanup_130
5820                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
5821                 return
5822         fi
5823
5824         cleanup_130
5825
5826         echo "FIEMAP on 2-stripe file with hole succeeded"
5827 }
5828 run_test 130c "FIEMAP (2-stripe file with hole)"
5829
5830 test_130d() {
5831         [ "$OSTCOUNT" -lt "3" ] && skip "skipping FIEMAP on N-stripe file test" && return
5832
5833         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5834         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
5835
5836         trap cleanup_130 EXIT RETURN
5837
5838         local fm_file=$DIR/$tfile
5839         lfs setstripe -s 65536 -c $OSTCOUNT $fm_file || error "setstripe failed on $fm_file"
5840         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
5841
5842         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5843         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
5844
5845         last_lun=`echo $filefrag_op | cut -d: -f5`
5846
5847         IFS=$'\n'
5848         tot_len=0
5849         num_luns=1
5850         for line in $filefrag_op
5851         do
5852                 frag_lun=`echo $line | cut -d: -f5`
5853                 ext_len=`echo $line | cut -d: -f4`
5854                 if (( $frag_lun != $last_lun )); then
5855                         if (( tot_len != 1024 )); then
5856                                 cleanup_130
5857                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
5858                                 return
5859                         else
5860                                 (( num_luns += 1 ))
5861                                 tot_len=0
5862                         fi
5863                 fi
5864                 (( tot_len += ext_len ))
5865                 last_lun=$frag_lun
5866         done
5867         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
5868                 cleanup_130
5869                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
5870                 return
5871         fi
5872
5873         cleanup_130
5874
5875         echo "FIEMAP on N-stripe file succeeded"
5876 }
5877 run_test 130d "FIEMAP (N-stripe file)"
5878
5879 test_130e() {
5880         [ "$OSTCOUNT" -lt "2" ] && skip "skipping continuation FIEMAP test" && return
5881
5882         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
5883         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
5884
5885         trap cleanup_130 EXIT RETURN
5886
5887         local fm_file=$DIR/$tfile
5888         lfs setstripe -s 131072 -c 2 $fm_file || error "setstripe failed on $fm_file"
5889         NUM_BLKS=512
5890         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
5891         for ((i = 0; i < $NUM_BLKS; i++))
5892         do
5893                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
5894         done
5895
5896         filefrag -ves $fm_file || error "filefrag $fm_file failed"
5897         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
5898
5899         last_lun=`echo $filefrag_op | cut -d: -f5`
5900
5901         IFS=$'\n'
5902         tot_len=0
5903         num_luns=1
5904         for line in $filefrag_op
5905         do
5906                 frag_lun=`echo $line | cut -d: -f5`
5907                 ext_len=`echo $line | cut -d: -f4`
5908                 if (( $frag_lun != $last_lun )); then
5909                         if (( tot_len != $EXPECTED_LEN )); then
5910                                 cleanup_130
5911                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
5912                                 return
5913                         else
5914                                 (( num_luns += 1 ))
5915                                 tot_len=0
5916                         fi
5917                 fi
5918                 (( tot_len += ext_len ))
5919                 last_lun=$frag_lun
5920         done
5921         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
5922                 cleanup_130
5923                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
5924                 return
5925         fi
5926
5927         cleanup_130
5928
5929         echo "FIEMAP with continuation calls succeeded"
5930 }
5931 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
5932
5933 # Test for writev/readv
5934 test_131a() {
5935         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
5936         error "writev test failed"
5937         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
5938         error "readv failed"
5939         rm -f $DIR/$tfile
5940 }
5941 run_test 131a "test iov's crossing stripe boundary for writev/readv"
5942
5943 test_131b() {
5944         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
5945         error "append writev test failed"
5946         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
5947         error "append writev test failed"
5948         rm -f $DIR/$tfile
5949 }
5950 run_test 131b "test append writev"
5951
5952 test_131c() {
5953         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
5954         error "NOT PASS"
5955 }
5956 run_test 131c "test read/write on file w/o objects"
5957
5958 test_131d() {
5959         rwv -f $DIR/$tfile -w -n 1 1572864
5960         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
5961         if [ "$NOB" != 1572864 ]; then
5962                 error "Short read filed: read $NOB bytes instead of 1572864"
5963         fi
5964         rm -f $DIR/$tfile
5965 }
5966 run_test 131d "test short read"
5967
5968 test_131e() {
5969         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
5970         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
5971         error "read hitting hole failed"
5972         rm -f $DIR/$tfile
5973 }
5974 run_test 131e "test read hitting hole"
5975
5976 get_ost_param() {
5977         local token=$1
5978         local gl_sum=0
5979         for node in $(osts_nodes); do
5980                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
5981                 [ x$gl = x"" ] && gl=0
5982                 gl_sum=$((gl_sum + gl))
5983         done
5984         echo $gl
5985 }
5986
5987 som_mode_switch() {
5988         local som=$1
5989         local gl1=$2
5990         local gl2=$3
5991
5992         if [ x$som = x"enabled" ]; then
5993                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
5994                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
5995         else
5996                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
5997                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
5998         fi
5999
6000         # do remount to make new mount-conf parameters actual
6001         echo remounting...
6002         sync
6003         stopall
6004         setupall
6005 }
6006
6007 test_132() { #1028, SOM
6008         local num=$(get_mds_dir $DIR)
6009         local mymds=mds${num}
6010
6011         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
6012         cancel_lru_locks osc
6013
6014         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
6015
6016         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
6017         stat $DIR/$tfile >/dev/null
6018         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
6019         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
6020         cancel_lru_locks osc
6021         som_mode_switch $som1 $gl1 $gl2
6022
6023         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
6024         if [ $som1 == $som2 ]; then
6025             error "som is still "$som2
6026             if [ x$som2 = x"enabled" ]; then
6027                 som2="disabled"
6028             else
6029                 som2="enabled"
6030             fi
6031         fi
6032
6033         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
6034         stat $DIR/$tfile >/dev/null
6035         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
6036         echo "SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
6037         som_mode_switch $som2 $gl1 $gl2
6038 }
6039 run_test 132 "som avoids glimpse rpc"
6040
6041 test_140() { #bug-17379
6042         mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
6043         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
6044         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
6045
6046         # VFS limits max symlink depth to 5(4KSTACK) or 8
6047         local i=0
6048         while i=`expr $i + 1`; do
6049                 mkdir -p $i || error "Creating dir $i"
6050                 cd $i || error "Changing to $i"
6051                 ln -s ../stat stat || error "Creating stat symlink"
6052                 # Read the symlink until ELOOP present,
6053                 # not LBUGing the system is considered success,
6054                 # we didn't overrun the stack.
6055                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
6056                 [ $ret -ne 0 ] && {
6057                         if [ $ret -eq 40 ]; then
6058                                 break  # -ELOOP
6059                         else
6060                                 error "Open stat symlink"
6061                                 return
6062                         fi
6063                 }
6064         done
6065         i=`expr $i - 1`
6066         echo "The symlink depth = $i"
6067         [ $i -eq 4 -o $i -eq 8 ] || error "Invalid symlink depth"
6068 }
6069 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
6070
6071 test_150() {
6072         local TF="$TMP/$tfile"
6073
6074         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
6075         cp $TF $DIR/$tfile
6076         cancel_lru_locks osc
6077         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
6078         remount_client $MOUNT
6079         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
6080
6081         $TRUNCATE $TF 6000
6082         $TRUNCATE $DIR/$tfile 6000
6083         cancel_lru_locks osc
6084         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
6085
6086         echo "12345" >>$TF
6087         echo "12345" >>$DIR/$tfile
6088         cancel_lru_locks osc
6089         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
6090
6091         echo "12345" >>$TF
6092         echo "12345" >>$DIR/$tfile
6093         cancel_lru_locks osc
6094         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
6095
6096         rm -f $TF
6097         true
6098 }
6099 run_test 150 "truncate/append tests"
6100
6101 function roc_access() {
6102         local list=$(comma_list $(osts_nodes))
6103         ACCNUM=`do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
6104                 grep 'cache_access'| awk '{print $2}' | \
6105                 awk '{sum=sum+$3} END{print sum}'`
6106         echo $ACCNUM
6107 }
6108
6109 function roc_hit() {
6110         local list=$(comma_list $(osts_nodes))
6111         ACCNUM=`do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
6112                 grep 'cache_hit'|awk '{print $2}' | \
6113                 awk '{sum=sum+$1} END{print sum}'`
6114         echo $ACCNUM
6115 }
6116
6117 test_151() {
6118         remote_ost_nodsh && skip "remote OST with nodsh" && return
6119
6120         local CPAGES=3
6121         local list=$(comma_list $(osts_nodes))
6122
6123         # check whether obdfilter is cache capable at all
6124         if ! do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable > /dev/null; then
6125                 echo "not cache-capable obdfilter"
6126                 return 0
6127         fi
6128
6129         # check cache is enabled on all obdfilters
6130         if do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable | grep 0 >&/dev/null; then
6131                 echo "oss cache is disabled"
6132                 return 0
6133         fi
6134
6135         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable 1
6136
6137         # pages should be in the case right after write
6138         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
6139         local BEFORE=`roc_hit`
6140         cancel_lru_locks osc
6141         cat $DIR/$tfile >/dev/null
6142         local AFTER=`roc_hit`
6143         if ! let "AFTER - BEFORE == CPAGES"; then
6144                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
6145         fi
6146
6147         # the following read invalidates the cache
6148         cancel_lru_locks osc
6149         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 0
6150         cat $DIR/$tfile >/dev/null
6151
6152         # now data shouldn't be found in the cache
6153         BEFORE=`roc_hit`
6154         cancel_lru_locks osc
6155         cat $DIR/$tfile >/dev/null
6156         AFTER=`roc_hit`
6157         if let "AFTER - BEFORE != 0"; then
6158                 error "IN CACHE: before: $BEFORE, after: $AFTER"
6159         fi
6160
6161         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 1
6162         rm -f $DIR/$tfile
6163 }
6164 run_test 151 "test cache on oss and controls ==============================="
6165
6166 test_152() {
6167         local TF="$TMP/$tfile"
6168
6169         # simulate ENOMEM during write
6170 #define OBD_FAIL_OST_NOMEM      0x226
6171         lctl set_param fail_loc=0x80000226
6172         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
6173         cp $TF $DIR/$tfile
6174         sync || error "sync failed"
6175         lctl set_param fail_loc=0
6176
6177         # discard client's cache
6178         cancel_lru_locks osc
6179
6180         # simulate ENOMEM during read
6181         lctl set_param fail_loc=0x80000226
6182         cmp $TF $DIR/$tfile || error "cmp failed"
6183         lctl set_param fail_loc=0
6184
6185         rm -f $TF
6186 }
6187 run_test 152 "test read/write with enomem ============================"
6188
6189 test_153() {
6190         multiop $DIR/$tfile Ow4096Ycu || error "multiop failed"
6191 }
6192 run_test 153 "test if fdatasync does not crash ======================="
6193
6194 test_154() {
6195         cp /etc/hosts $DIR/$tfile
6196
6197         fid=$($LFS path2fid $DIR/$tfile)
6198         rc=$?
6199         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
6200
6201         echo "open fid $fid"
6202         diff /etc/hosts $DIR/.lustre/fid/$fid || error "open by fid failed: did not find expected data in file."
6203
6204         echo "Opening a file by FID succeeded"
6205 }
6206 run_test 154 "Opening a file by FID"
6207
6208 #Changelogs
6209 err17935 () {
6210     if [ $MDSCOUNT -gt 1 ]; then
6211         error_ignore 17935 $*
6212     else
6213         error $*
6214     fi
6215 }
6216 test_160() {
6217     USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
6218     echo "Registered as changelog user $USER"
6219     do_facet $SINGLEMDS lctl get_param -n mdd.$MDT0.changelog_users | \
6220         grep -q $USER || error "User $USER not found in changelog_users"
6221
6222     # change something
6223     mkdir -p $DIR/$tdir/pics/2008/zachy
6224     touch $DIR/$tdir/pics/2008/zachy/timestamp
6225     cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
6226     mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
6227     ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
6228     ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
6229     rm $DIR/$tdir/pics/desktop.jpg
6230
6231     $LFS changelog $MDT0 | tail -5
6232
6233     echo "verifying changelog mask"
6234     do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="-mkdir"
6235     mkdir -p $DIR/$tdir/pics/2009/sofia
6236     do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+mkdir"
6237     mkdir $DIR/$tdir/pics/2009/zachary
6238     DIRS=$($LFS changelog $MDT0 | tail -5 | grep -c MKDIR)
6239     [ $DIRS -eq 1 ] || err17935 "changelog mask count $DIRS != 1"
6240
6241     # verify contents
6242     echo "verifying target fid"
6243     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
6244         tail -1 | awk '{print $5}')
6245     fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
6246     [ "$fidc" == "t=$fidf" ] || \
6247         err17935 "fid in changelog $fidc != file fid $fidf"
6248     echo "verifying parent fid"
6249     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
6250         tail -1 | awk '{print $6}')
6251     fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
6252     [ "$fidc" == "p=$fidf" ] || \
6253         err17935 "pfid in changelog $fidc != dir fid $fidf"
6254
6255     USER_REC1=$(do_facet $SINGLEMDS lctl get_param -n \
6256         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
6257     $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
6258     USER_REC2=$(do_facet $SINGLEMDS lctl get_param -n \
6259         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
6260     echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
6261     [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \
6262         err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2"
6263
6264     MIN_REC=$(do_facet $SINGLEMDS lctl get_param mdd.$MDT0.changelog_users | \
6265         awk 'min == "" || $2 < min {min = $2}; END {print min}')
6266     FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
6267     echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
6268     [ $FIRST_REC == $(($MIN_REC + 1)) ] || \
6269         err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC"
6270
6271     echo "verifying user deregister"
6272     do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $USER
6273     do_facet $SINGLEMDS lctl get_param -n mdd.$MDT0.changelog_users | \
6274         grep -q $USER && error "User $USER still found in changelog_users"
6275
6276     USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
6277         mdd.$MDT0.changelog_users | wc -l) - 2 ))
6278     if [ $USERS -eq 0 ]; then
6279         LAST_REC1=$(do_facet $SINGLEMDS lctl get_param -n \
6280             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
6281         touch $DIR/$tdir/chloe
6282         LAST_REC2=$(do_facet $SINGLEMDS lctl get_param -n \
6283             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
6284         echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2"
6285         [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
6286     else
6287         echo "$USERS other changelog users; can't verify off"
6288     fi
6289 }
6290 run_test 160 "changelog sanity"
6291
6292 test_161() {
6293     mkdir -p $DIR/$tdir
6294     cp /etc/hosts $DIR/$tdir/$tfile
6295     mkdir $DIR/$tdir/foo1
6296     mkdir $DIR/$tdir/foo2
6297     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
6298     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
6299     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
6300     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
6301     local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[')
6302     if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
6303         $LFS fid2path $DIR $FID
6304         err17935 "bad link ea"
6305     fi
6306     # middle
6307     rm $DIR/$tdir/foo2/zachary
6308     # last
6309     rm $DIR/$tdir/foo2/thor
6310     # first
6311     rm $DIR/$tdir/$tfile
6312     # rename
6313     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
6314     if [ "$($LFS fid2path $DIR --link 1 $FID)" != "/$tdir/foo2/maggie" ]
6315         then
6316         $LFS fid2path $DIR $FID
6317         err17935 "bad link rename"
6318     fi
6319     rm $DIR/$tdir/foo2/maggie
6320
6321     # overflow the EA
6322     local longname=filename_avg_len_is_thirty_two_
6323     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
6324         error "failed to hardlink many files"
6325     links=$($LFS fid2path $DIR $FID | wc -l)
6326     echo -n "${links}/1000 links in link EA"
6327     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
6328     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
6329         error "failed to unlink many hardlinks"
6330 }
6331 run_test 161 "link ea sanity"
6332
6333 check_path() {
6334     local expected=$1
6335     shift
6336     local fid=$2
6337
6338     local path=$(${LFS} fid2path $*)
6339     RC=$?
6340
6341     if [ $RC -ne 0 ]; then
6342         err17935 "path looked up of $expected failed. Error $RC"
6343         return $RC
6344     elif [ "${path}" != "${expected}" ]; then
6345         err17935 "path looked up \"${path}\" instead of \"${expected}\""
6346         return 2
6347     fi
6348     echo "fid $fid resolves to path $path"
6349 }
6350
6351 test_162() {
6352     # Make changes to filesystem
6353     mkdir -p $DIR/$tdir/d2
6354     touch $DIR/$tdir/d2/$tfile
6355     touch $DIR/$tdir/d2/x1
6356     touch $DIR/$tdir/d2/x2
6357     mkdir -p $DIR/$tdir/d2/a/b/c
6358     mkdir -p $DIR/$tdir/d2/p/q/r
6359     FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[')
6360     check_path "/$tdir/d2/$tfile" $DIR $FID --link 0
6361     ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
6362     mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
6363     FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[')
6364     # fid2path dir/fsname should both work
6365     check_path "/$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
6366     check_path "/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
6367     # check that there are 2 links
6368     ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
6369         err17935 "expected 2 links"
6370
6371     rm $DIR/$tdir/d2/p/q/r/hlink
6372     check_path "/$tdir/d2/a/b/c/new_file" $DIR $FID --link 0
6373     # Doesnt work with CMD yet: 17935
6374     return 0
6375 }
6376 run_test 162 "path lookup sanity"
6377
6378 test_169() {
6379         # do directio so as not to populate the page cache
6380         log "creating a 10 Mb file"
6381         multiop $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
6382         log "starting reads"
6383         dd if=$DIR/$tfile of=/dev/null bs=4096 &
6384         log "truncating the file"
6385         multiop $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
6386         log "killing dd"
6387         kill %+ || true # reads might have finished
6388         echo "wait until dd is finished"
6389         wait
6390         log "removing the temporary file"
6391         rm -rf $DIR/$tfile || error "tmp file removal failed"
6392 }
6393 run_test 169 "parallel read and truncate should not deadlock ==="
6394
6395 test_170() {
6396         $LCTL clear     # bug 18514
6397         $LCTL debug_daemon start $TMP/${tfile}_log_good
6398         touch $DIR/$tfile
6399         $LCTL debug_daemon stop
6400         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
6401                error "sed failed to read log_good"
6402
6403         $LCTL debug_daemon start $TMP/${tfile}_log_good
6404         rm -rf $DIR/$tfile
6405         $LCTL debug_daemon stop
6406
6407         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
6408                error "lctl df log_bad failed"
6409
6410         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
6411         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
6412
6413         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
6414         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
6415
6416         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
6417                 error "bad_line good_line1 good_line2 are empty"
6418
6419         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
6420         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
6421         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
6422
6423         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
6424         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
6425         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
6426
6427         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
6428                 error "bad_line_new good_line_new are empty"
6429
6430         local expected_good=$((good_line1 + good_line2*2))
6431
6432         rm -f $TMP/${tfile}*
6433         if [ $bad_line -ne $bad_line_new ]; then
6434                 error "expected $bad_line bad lines, but got $bad_line_new"
6435                 return 1
6436         fi
6437
6438         if [ $expected_good -ne $good_line_new ]; then
6439                 error "expected $expected_good good lines, but got $good_line_new"
6440                 return 2
6441         fi
6442         true
6443 }
6444 run_test 170 "test lctl df to handle corrupted log ====================="
6445
6446 # OST pools tests
6447 POOL=${POOL:-cea1}
6448 TGT_COUNT=$OSTCOUNT
6449 TGTPOOL_FIRST=1
6450 TGTPOOL_MAX=$(($TGT_COUNT - 1))
6451 TGTPOOL_STEP=2
6452 TGTPOOL_LIST=`seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`
6453 POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
6454 POOL_DIR=$POOL_ROOT/dir_tst
6455 POOL_FILE=$POOL_ROOT/file_tst
6456
6457 check_file_in_pool()
6458 {
6459         file=$1
6460         res=$($GETSTRIPE $file | grep 0x | cut -f2)
6461         for i in $res
6462         do
6463                 found=$(echo :$TGTPOOL_LIST: | tr " " ":"  | grep :$i:)
6464                 if [[ "$found" == "" ]]
6465                 then
6466                         echo "pool list: $TGTPOOL_LIST"
6467                         echo "striping: $res"
6468                         error "$file not allocated in $POOL"
6469                         return 1
6470                 fi
6471         done
6472         return 0
6473 }
6474
6475 test_200a() {
6476         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6477         do_facet mgs $LCTL pool_new $FSNAME.$POOL
6478         # get param should return err until pool is created
6479         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "" || error "Pool creation of $POOL failed"
6480 }
6481 run_test 200a "Create new pool =========================================="
6482
6483 test_200b() {
6484         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6485         TGT=$(for i in `seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`; do printf "$FSNAME-OST%04x_UUID " $i; done)
6486         do_facet mgs $LCTL pool_add $FSNAME.$POOL \
6487                 $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]
6488         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | sort -u | tr '\n' ' ' " "$TGT" || error "Add to pool failed"
6489 }
6490 run_test 200b "Add targets to a pool ===================================="
6491
6492 test_200c() {
6493         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6494         mkdir -p $POOL_DIR
6495         $SETSTRIPE -c 2 -p $POOL $POOL_DIR
6496         [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
6497 }
6498 run_test 200c "Set pool on a directory ================================="
6499
6500 test_200d() {
6501         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6502         res=$($GETSTRIPE --pool $POOL_DIR | awk '/^pool:/ {print $2}')
6503         [ "$res" = $POOL ] || error "Pool on $POOL_DIR is $res, not $POOL"
6504 }
6505 run_test 200d "Check pool on a directory ==============================="
6506
6507 test_200e() {
6508         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6509         failed=0
6510         for i in $(seq -w 1 $(($TGT_COUNT * 3)))
6511         do
6512                 file=$POOL_DIR/file-$i
6513                 touch $file
6514                 check_file_in_pool $file
6515                 if [[ $? != 0 ]]
6516                 then
6517                         failed=$(($failed + 1))
6518                 fi
6519         done
6520         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
6521 }
6522 run_test 200e "Check files allocation from directory pool =============="
6523
6524 test_200f() {
6525         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6526         mkdir -p $POOL_FILE
6527         failed=0
6528         for i in $(seq -w 1 $(($TGT_COUNT * 3)))
6529         do
6530                 file=$POOL_FILE/spoo-$i
6531                 $SETSTRIPE -p $POOL $file
6532                 check_file_in_pool $file
6533                 if [[ $? != 0 ]]
6534                 then
6535                         failed=$(($failed + 1))
6536                 fi
6537         done
6538         [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
6539 }
6540 run_test 200f "Create files in a pool ==================================="
6541
6542 test_200g() {
6543         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6544         TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
6545         do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
6546         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | grep $TGT" "" || error "$TGT not removed from $FSNAME.$POOL"
6547 }
6548 run_test 200g "Remove a target from a pool ============================="
6549
6550 test_200h() {
6551         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6552         for TGT in $($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | sort -u)
6553         do
6554                 do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
6555         done
6556         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL" ""\
6557             || error "Pool $FSNAME.$POOL cannot be drained"
6558         # striping on an empty pool should fall back to "pool of everything"
6559         $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile || error "failed to create file with empty pool"
6560 }
6561 run_test 200h "Remove all targets from a pool =========================="
6562
6563 test_200i() {
6564         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6565         do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
6566         # get param should return err once pool is gone
6567         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "foo" && return 0
6568         error "Pool $FSNAME.$POOL is not destroyed"
6569 }
6570 run_test 200i "Remove a pool ============================================"
6571
6572 test_212() {
6573         size=`date +%s`
6574         size=$((size % 8192 + 1))
6575         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
6576         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
6577         rm -f $DIR/f212 $DIR/f212.xyz
6578 }
6579 run_test 212 "Sendfile test ============================================"
6580
6581 test_213() {
6582         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
6583         cancel_lru_locks osc
6584         lctl set_param fail_loc=0x8000040f
6585         # generate a read lock
6586         cat $DIR/$tfile > /dev/null
6587         # write to the file, it will try to cancel the above read lock.
6588         cat /etc/hosts >> $DIR/$tfile
6589 }
6590 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
6591
6592 #
6593 # tests that do cleanup/setup should be run at the end
6594 #
6595
6596 test_900() {
6597         local ls
6598         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
6599         $LCTL set_param fail_loc=0x903
6600         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
6601         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
6602                 echo "clear" > $ls
6603         done
6604         FAIL_ON_ERROR=true cleanup
6605         FAIL_ON_ERROR=true setup
6606 }
6607 run_test 900 "umount should not race with any mgc requeue thread"
6608
6609 log "cleanup: ======================================================"
6610 check_and_cleanup_lustre
6611 if [ "$I_MOUNTED" != "yes" ]; then
6612         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
6613 fi
6614
6615 echo '=========================== finished ==============================='
6616 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
6617 echo "$0: completed"