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