Whamcloud - gitweb
LU-1538 tests: fix test cases when OST is full
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
11 ALWAYS_EXCEPT="                27u   42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 # with LOD/OSP landing
15 # bug number for skipped tests: LU-2036
16 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
17
18
19 # Tests that fail on uml
20 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
21 #                                    buffer i/o errs             sock spc runas
22 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 27m 27n 27o 27p 27q 27r 31d 54a  64b 99a 99b 99c 99d 99e 99f 101a"
23
24 SRCDIR=$(cd $(dirname $0); echo $PWD)
25 export PATH=$PATH:/sbin
26
27 TMP=${TMP:-/tmp}
28
29 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
30 CREATETEST=${CREATETEST:-createtest}
31 LFS=${LFS:-lfs}
32 LFIND=${LFIND:-"$LFS find"}
33 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
34 LCTL=${LCTL:-lctl}
35 MCREATE=${MCREATE:-mcreate}
36 OPENFILE=${OPENFILE:-openfile}
37 OPENUNLINK=${OPENUNLINK:-openunlink}
38 export MULTIOP=${MULTIOP:-multiop}
39 READS=${READS:-"reads"}
40 MUNLINK=${MUNLINK:-munlink}
41 SOCKETSERVER=${SOCKETSERVER:-socketserver}
42 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
43 MEMHOG=${MEMHOG:-memhog}
44 DIRECTIO=${DIRECTIO:-directio}
45 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
46 UMOUNT=${UMOUNT:-"umount -d"}
47 STRIPES_PER_OBJ=-1
48 CHECK_GRANT=${CHECK_GRANT:-"yes"}
49 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
50
51 export NAME=${NAME:-local}
52
53 SAVE_PWD=$PWD
54
55 CLEANUP=${CLEANUP:-:}
56 SETUP=${SETUP:-:}
57 TRACE=${TRACE:-""}
58 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
59 . $LUSTRE/tests/test-framework.sh
60 init_test_env $@
61 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
62 init_logging
63
64 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24v 27m 36f 36g 36h 51b 60c 63 64b 68 71 73 77f 78 101a 103 115 120g 124b"
65
66 FAIL_ON_ERROR=false
67
68 cleanup() {
69         echo -n "cln.."
70         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
71         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
72 }
73 setup() {
74         echo -n "mnt.."
75         load_modules
76         setupall || exit 10
77         echo "done"
78 }
79
80 check_kernel_version() {
81         WANT_VER=$1
82         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
83         case $GOT_VER in
84         patchless|patchless_client) return 0;;
85         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
86         esac
87         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
88         return 1
89 }
90
91 if [ "$ONLY" == "cleanup" ]; then
92        sh llmountcleanup.sh
93        exit 0
94 fi
95
96 check_and_setup_lustre
97
98 DIR=${DIR:-$MOUNT}
99 assert_DIR
100
101 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
102     awk '{gsub(/_UUID/,""); print $1}' | head -1)
103 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
104 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
105 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
106 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
107 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
108 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
109
110 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
111 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
112 rm -rf $DIR/[Rdfs][0-9]*
113
114 # $RUNAS_ID may get set incorrectly somewhere else
115 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
116
117 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
118
119 build_test_filter
120
121 if [ "${ONLY}" = "MOUNT" ] ; then
122         echo "Lustre is up, please go on"
123         exit
124 fi
125
126 echo "preparing for tests involving mounts"
127 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
128 touch $EXT2_DEV
129 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
130 echo # add a newline after mke2fs.
131
132 umask 077
133
134 OLDDEBUG="`lctl get_param -n debug 2> /dev/null`"
135 lctl set_param debug=-1 2> /dev/null || true
136 test_0() {
137         touch $DIR/$tfile
138         $CHECKSTAT -t file $DIR/$tfile || error
139         rm $DIR/$tfile
140         $CHECKSTAT -a $DIR/$tfile || error
141 }
142 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
143
144 test_0b() {
145         chmod 0755 $DIR || error
146         $CHECKSTAT -p 0755 $DIR || error
147 }
148 run_test 0b "chmod 0755 $DIR ============================="
149
150 test_0c() {
151     $LCTL get_param mdc.*.import | grep  "state: FULL" || error "import not FULL"
152     $LCTL get_param mdc.*.import | grep  "target: $FSNAME-MDT" || error "bad target"
153 }
154 run_test 0c "check import proc ============================="
155
156 test_1a() {
157         mkdir $DIR/d1
158         mkdir $DIR/d1/d2
159         mkdir $DIR/d1/d2 && error "we expect EEXIST, but not returned"
160         $CHECKSTAT -t dir $DIR/d1/d2 || error
161 }
162 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
163
164 test_1b() {
165         rmdir $DIR/d1/d2
166         rmdir $DIR/d1
167         $CHECKSTAT -a $DIR/d1 || error
168 }
169 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
170
171 test_2a() {
172         mkdir $DIR/d2
173         touch $DIR/d2/f
174         $CHECKSTAT -t file $DIR/d2/f || error
175 }
176 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
177
178 test_2b() {
179         rm -r $DIR/d2
180         $CHECKSTAT -a $DIR/d2 || error
181 }
182 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
183
184 test_3a() {
185         mkdir $DIR/d3
186         $CHECKSTAT -t dir $DIR/d3 || error
187 }
188 run_test 3a "mkdir .../d3 ======================================"
189
190 test_3b() {
191         if [ ! -d $DIR/d3 ]; then
192                 mkdir $DIR/d3
193         fi
194         touch $DIR/d3/f
195         $CHECKSTAT -t file $DIR/d3/f || error
196 }
197 run_test 3b "touch .../d3/f ===================================="
198
199 test_3c() {
200         rm -r $DIR/d3
201         $CHECKSTAT -a $DIR/d3 || error
202 }
203 run_test 3c "rm -r .../d3 ======================================"
204
205 test_4a() {
206         mkdir $DIR/d4
207         $CHECKSTAT -t dir $DIR/d4 || error
208 }
209 run_test 4a "mkdir .../d4 ======================================"
210
211 test_4b() {
212         if [ ! -d $DIR/d4 ]; then
213                 mkdir $DIR/d4
214         fi
215         mkdir $DIR/d4/d2
216         $CHECKSTAT -t dir $DIR/d4/d2 || error
217 }
218 run_test 4b "mkdir .../d4/d2 ==================================="
219
220 test_5() {
221         mkdir $DIR/d5
222         mkdir $DIR/d5/d2
223         chmod 0707 $DIR/d5/d2
224         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
225 }
226 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
227
228 test_6a() {
229         touch $DIR/f6a
230         chmod 0666 $DIR/f6a || error
231         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
232 }
233 run_test 6a "touch .../f6a; chmod .../f6a ======================"
234
235 test_6b() {
236         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
237         if [ ! -f $DIR/f6a ]; then
238                 touch $DIR/f6a
239                 chmod 0666 $DIR/f6a
240         fi
241         $RUNAS chmod 0444 $DIR/f6a && error
242         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
243 }
244 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
245
246 test_6c() {
247         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
248         touch $DIR/f6c
249         chown $RUNAS_ID $DIR/f6c || error
250         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
251 }
252 run_test 6c "touch .../f6c; chown .../f6c ======================"
253
254 test_6d() {
255         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
256         if [ ! -f $DIR/f6c ]; then
257                 touch $DIR/f6c
258                 chown $RUNAS_ID $DIR/f6c
259         fi
260         $RUNAS chown $UID $DIR/f6c && error
261         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
262 }
263 run_test 6d "$RUNAS chown .../f6c (should return error) =="
264
265 test_6e() {
266         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
267         touch $DIR/f6e
268         chgrp $RUNAS_ID $DIR/f6e || error
269         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
270 }
271 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
272
273 test_6f() {
274         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
275         if [ ! -f $DIR/f6e ]; then
276                 touch $DIR/f6e
277                 chgrp $RUNAS_ID $DIR/f6e
278         fi
279         $RUNAS chgrp $UID $DIR/f6e && error
280         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
281 }
282 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
283
284 test_6g() {
285         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
286         mkdir $DIR/d6g || error
287         chmod 777 $DIR/d6g || error
288         $RUNAS mkdir $DIR/d6g/d || error
289         chmod g+s $DIR/d6g/d || error
290         mkdir $DIR/d6g/d/subdir
291         $CHECKSTAT -g \#$RUNAS_GID $DIR/d6g/d/subdir || error
292 }
293 run_test 6g "Is new dir in sgid dir inheriting group?"
294
295 test_6h() { # bug 7331
296         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
297         touch $DIR/f6h || error "touch failed"
298         chown $RUNAS_ID:$RUNAS_GID $DIR/f6h || error "initial chown failed"
299         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
300         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/f6h || error
301 }
302 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
303
304 test_7a() {
305         mkdir $DIR/d7
306         $MCREATE $DIR/d7/f
307         chmod 0666 $DIR/d7/f
308         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
309 }
310 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
311
312 test_7b() {
313         if [ ! -d $DIR/d7 ]; then
314                 mkdir $DIR/d7
315         fi
316         $MCREATE $DIR/d7/f2
317         echo -n foo > $DIR/d7/f2
318         [ "`cat $DIR/d7/f2`" = "foo" ] || error
319         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
320 }
321 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
322
323 test_8() {
324         mkdir $DIR/d8
325         touch $DIR/d8/f
326         chmod 0666 $DIR/d8/f
327         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
328 }
329 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
330
331 test_9() {
332         mkdir $DIR/d9
333         mkdir $DIR/d9/d2
334         mkdir $DIR/d9/d2/d3
335         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
336 }
337 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
338
339 test_10() {
340         mkdir $DIR/d10
341         mkdir $DIR/d10/d2
342         touch $DIR/d10/d2/f
343         $CHECKSTAT -t file $DIR/d10/d2/f || error
344 }
345 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
346
347 test_11() {
348         mkdir $DIR/d11
349         mkdir $DIR/d11/d2
350         chmod 0666 $DIR/d11/d2
351         chmod 0705 $DIR/d11/d2
352         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
353 }
354 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
355
356 test_12() {
357         mkdir $DIR/d12
358         touch $DIR/d12/f
359         chmod 0666 $DIR/d12/f
360         chmod 0654 $DIR/d12/f
361         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
362 }
363 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
364
365 test_13() {
366         mkdir $DIR/d13
367         dd if=/dev/zero of=$DIR/d13/f count=10
368         >  $DIR/d13/f
369         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
370 }
371 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
372
373 test_14() {
374         mkdir $DIR/d14
375         touch $DIR/d14/f
376         rm $DIR/d14/f
377         $CHECKSTAT -a $DIR/d14/f || error
378 }
379 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
380
381 test_15() {
382         mkdir $DIR/d15
383         touch $DIR/d15/f
384         mv $DIR/d15/f $DIR/d15/f2
385         $CHECKSTAT -t file $DIR/d15/f2 || error
386 }
387 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
388
389 test_16() {
390         mkdir $DIR/d16
391         touch $DIR/d16/f
392         rm -rf $DIR/d16/f
393         $CHECKSTAT -a $DIR/d16/f || error
394 }
395 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
396
397 test_17a() {
398         mkdir -p $DIR/d17
399         touch $DIR/d17/f
400         ln -s $DIR/d17/f $DIR/d17/l-exist
401         ls -l $DIR/d17
402         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
403         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
404         rm -f $DIR/d17/l-exist
405         $CHECKSTAT -a $DIR/d17/l-exist || error
406 }
407 run_test 17a "symlinks: create, remove (real) =================="
408
409 test_17b() {
410         mkdir -p $DIR/d17
411         ln -s no-such-file $DIR/d17/l-dangle
412         ls -l $DIR/d17
413         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
414         $CHECKSTAT -fa $DIR/d17/l-dangle || error
415         rm -f $DIR/d17/l-dangle
416         $CHECKSTAT -a $DIR/d17/l-dangle || error
417 }
418 run_test 17b "symlinks: create, remove (dangling) =============="
419
420 test_17c() { # bug 3440 - don't save failed open RPC for replay
421         mkdir -p $DIR/d17
422         ln -s foo $DIR/d17/f17c
423         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
424 }
425 run_test 17c "symlinks: open dangling (should return error) ===="
426
427 test_17d() {
428         mkdir -p $DIR/d17
429         ln -s foo $DIR/d17/f17d
430         touch $DIR/d17/f17d || error "creating to new symlink"
431 }
432 run_test 17d "symlinks: create dangling ========================"
433
434 test_17e() {
435         mkdir -p $DIR/$tdir
436         local foo=$DIR/$tdir/$tfile
437         ln -s $foo $foo || error "create symlink failed"
438         ls -l $foo || error "ls -l failed"
439         ls $foo && error "ls not failed" || true
440 }
441 run_test 17e "symlinks: create recursive symlink (should return error) ===="
442
443 test_17f() {
444         mkdir -p $DIR/d17f
445         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
446         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
447         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
448         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
449         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
450         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
451         ls -l  $DIR/d17f
452 }
453 run_test 17f "symlinks: long and very long symlink name ========================"
454
455 test_17g() {
456         mkdir -p $DIR/$tdir
457         LONGSYMLINK="$(dd if=/dev/zero bs=4095 count=1 | tr '\0' 'x')"
458         ln -s $LONGSYMLINK $DIR/$tdir/$tfile
459         ls -l $DIR/$tdir
460 }
461 run_test 17g "symlinks: really long symlink name ==============================="
462
463 test_17h() { #bug 17378
464         remote_mds_nodsh && skip "remote MDS with nodsh" && return
465         mkdir -p $DIR/$tdir
466         $SETSTRIPE -c -1 $DIR/$tdir
467 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
468         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000141
469         touch $DIR/$tdir/$tfile || true
470 }
471 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
472
473 test_17i() { #bug 20018
474         remote_mds_nodsh && skip "remote MDS with nodsh" && return
475         mkdir -p $DIR/$tdir
476         local foo=$DIR/$tdir/$tfile
477         ln -s $foo $foo || error "create symlink failed"
478 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
479         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000143
480         ls -l $foo && error "error not detected"
481         return 0
482 }
483 run_test 17i "don't panic on short symlink"
484
485 test_17k() { #bug 22301
486         rsync --help | grep -q xattr ||
487                 skip_env "$(rsync --version| head -1) does not support xattrs"
488         mkdir -p $DIR/{$tdir,$tdir.new}
489         touch $DIR/$tdir/$tfile
490         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
491         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
492                 error "rsync failed with xattrs enabled"
493 }
494 run_test 17k "symlinks: rsync with xattrs enabled ========================="
495
496 # LU-1540
497 test_17m() {
498         local short_sym="0123456789"
499         local WDIR=$DIR/${tdir}m
500         local mds_index
501         local devname
502         local cmd
503         local i
504         local rc=0
505
506         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
507         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
508                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
509
510         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
511                 skip "only for ldiskfs MDT" && return 0
512
513         mkdir -p $WDIR
514         long_sym=$short_sym
515         # create a long symlink file
516         for ((i = 0; i < 4; ++i)); do
517                 long_sym=${long_sym}${long_sym}
518         done
519
520         echo "create 512 short and long symlink files under $WDIR"
521         for ((i = 0; i < 256; ++i)); do
522                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
523                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
524         done
525
526         echo "erase them"
527         rm -f $WDIR/*
528         sync
529         sleep 2
530
531         echo "recreate the 512 symlink files with a shorter string"
532         for ((i = 0; i < 512; ++i)); do
533                 # rewrite the symlink file with a shorter string
534                 ln -sf ${long_sym} $WDIR/long-$i
535                 ln -sf ${short_sym} $WDIR/short-$i
536         done
537
538         mds_index=$($LFS getstripe -M $WDIR)
539         mds_index=$((mds_index+1))
540         devname=$(mdsdevname $mds_index)
541         cmd="$E2FSCK -fnvd $devname"
542
543         echo "stop and checking mds${mds_index}: $cmd"
544         # e2fsck should not return error
545         stop mds${mds_index} -f
546         do_facet mds${mds_index} $cmd || rc=$?
547
548         start mds${mds_index} $devname $MDS_MOUNT_OPTS
549         df $MOUNT > /dev/null 2>&1
550         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
551                 "short/long symlink MDT: rc=$rc"
552         return $rc
553 }
554 run_test 17m "run e2fsck against MDT which contains short/long symlink"
555
556 test_18() {
557         touch $DIR/f
558         ls $DIR || error
559 }
560 run_test 18 "touch .../f ; ls ... =============================="
561
562 test_19a() {
563         touch $DIR/f19
564         ls -l $DIR
565         rm $DIR/f19
566         $CHECKSTAT -a $DIR/f19 || error
567 }
568 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
569
570 test_19b() {
571         ls -l $DIR/f19 && error || true
572 }
573 run_test 19b "ls -l .../f19 (should return error) =============="
574
575 test_19c() {
576         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
577         $RUNAS touch $DIR/f19 && error || true
578 }
579 run_test 19c "$RUNAS touch .../f19 (should return error) =="
580
581 test_19d() {
582         cat $DIR/f19 && error || true
583 }
584 run_test 19d "cat .../f19 (should return error) =============="
585
586 test_20() {
587         touch $DIR/f
588         rm $DIR/f
589         log "1 done"
590         touch $DIR/f
591         rm $DIR/f
592         log "2 done"
593         touch $DIR/f
594         rm $DIR/f
595         log "3 done"
596         $CHECKSTAT -a $DIR/f || error
597 }
598 run_test 20 "touch .../f ; ls -l ... ==========================="
599
600 test_21() {
601         mkdir $DIR/d21
602         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
603         ln -s dangle $DIR/d21/link
604         echo foo >> $DIR/d21/link
605         cat $DIR/d21/dangle
606         $CHECKSTAT -t link $DIR/d21/link || error
607         $CHECKSTAT -f -t file $DIR/d21/link || error
608 }
609 run_test 21 "write to dangling link ============================"
610
611 test_22() {
612         WDIR=$DIR/$tdir
613         mkdir -p $WDIR
614         chown $RUNAS_ID:$RUNAS_GID $WDIR
615         (cd $WDIR || error "cd $WDIR failed";
616         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
617         $RUNAS tar xf -)
618         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
619         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
620         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
621 }
622 run_test 22 "unpack tar archive as non-root user ==============="
623
624 # was test_23
625 test_23a() {
626         mkdir -p $DIR/$tdir
627         local file=$DIR/$tdir/$tfile
628
629         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
630         openfile -f O_CREAT:O_EXCL $file &&
631                 error "$file recreate succeeded" || true
632 }
633 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
634
635 test_23b() { # bug 18988
636         mkdir -p $DIR/$tdir
637         local file=$DIR/$tdir/$tfile
638
639         rm -f $file
640         echo foo > $file || error "write filed"
641         echo bar >> $file || error "append filed"
642         $CHECKSTAT -s 8 $file || error "wrong size"
643         rm $file
644 }
645 run_test 23b "O_APPEND check =========================="
646
647 test_24a() {
648         echo '== rename sanity =============================================='
649         echo '-- same directory rename'
650         mkdir $DIR/R1
651         touch $DIR/R1/f
652         mv $DIR/R1/f $DIR/R1/g
653         $CHECKSTAT -t file $DIR/R1/g || error
654 }
655 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
656
657 test_24b() {
658         mkdir $DIR/R2
659         touch $DIR/R2/{f,g}
660         mv $DIR/R2/f $DIR/R2/g
661         $CHECKSTAT -a $DIR/R2/f || error
662         $CHECKSTAT -t file $DIR/R2/g || error
663 }
664 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
665
666 test_24c() {
667         mkdir $DIR/R3
668         mkdir $DIR/R3/f
669         mv $DIR/R3/f $DIR/R3/g
670         $CHECKSTAT -a $DIR/R3/f || error
671         $CHECKSTAT -t dir $DIR/R3/g || error
672 }
673 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
674
675 test_24d() {
676         mkdir $DIR/R4
677         mkdir $DIR/R4/{f,g}
678         mrename $DIR/R4/f $DIR/R4/g
679         $CHECKSTAT -a $DIR/R4/f || error
680         $CHECKSTAT -t dir $DIR/R4/g || error
681 }
682 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
683
684 test_24e() {
685         echo '-- cross directory renames --'
686         mkdir $DIR/R5{a,b}
687         touch $DIR/R5a/f
688         mv $DIR/R5a/f $DIR/R5b/g
689         $CHECKSTAT -a $DIR/R5a/f || error
690         $CHECKSTAT -t file $DIR/R5b/g || error
691 }
692 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
693
694 test_24f() {
695         mkdir $DIR/R6{a,b}
696         touch $DIR/R6a/f $DIR/R6b/g
697         mv $DIR/R6a/f $DIR/R6b/g
698         $CHECKSTAT -a $DIR/R6a/f || error
699         $CHECKSTAT -t file $DIR/R6b/g || error
700 }
701 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
702
703 test_24g() {
704         mkdir $DIR/R7{a,b}
705         mkdir $DIR/R7a/d
706         mv $DIR/R7a/d $DIR/R7b/e
707         $CHECKSTAT -a $DIR/R7a/d || error
708         $CHECKSTAT -t dir $DIR/R7b/e || error
709 }
710 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
711
712 test_24h() {
713         mkdir $DIR/R8{a,b}
714         mkdir $DIR/R8a/d $DIR/R8b/e
715         mrename $DIR/R8a/d $DIR/R8b/e
716         $CHECKSTAT -a $DIR/R8a/d || error
717         $CHECKSTAT -t dir $DIR/R8b/e || error
718 }
719 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
720
721 test_24i() {
722         echo "-- rename error cases"
723         mkdir $DIR/R9
724         mkdir $DIR/R9/a
725         touch $DIR/R9/f
726         mrename $DIR/R9/f $DIR/R9/a
727         $CHECKSTAT -t file $DIR/R9/f || error
728         $CHECKSTAT -t dir  $DIR/R9/a || error
729         $CHECKSTAT -a $DIR/R9/a/f || error
730 }
731 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
732
733 test_24j() {
734         mkdir $DIR/R10
735         mrename $DIR/R10/f $DIR/R10/g
736         $CHECKSTAT -t dir $DIR/R10 || error
737         $CHECKSTAT -a $DIR/R10/f || error
738         $CHECKSTAT -a $DIR/R10/g || error
739 }
740 run_test 24j "source does not exist ============================"
741
742 test_24k() {
743         mkdir $DIR/R11a $DIR/R11a/d
744         touch $DIR/R11a/f
745         mv $DIR/R11a/f $DIR/R11a/d
746         $CHECKSTAT -a $DIR/R11a/f || error
747         $CHECKSTAT -t file $DIR/R11a/d/f || error
748 }
749 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
750
751 # bug 2429 - rename foo foo foo creates invalid file
752 test_24l() {
753         f="$DIR/f24l"
754         $MULTIOP $f OcNs || error
755 }
756 run_test 24l "Renaming a file to itself ========================"
757
758 test_24m() {
759         f="$DIR/f24m"
760         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
761         # on ext3 this does not remove either the source or target files
762         # though the "expected" operation would be to remove the source
763         $CHECKSTAT -t file ${f} || error "${f} missing"
764         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
765 }
766 run_test 24m "Renaming a file to a hard link to itself ========="
767
768 test_24n() {
769     f="$DIR/f24n"
770     # this stats the old file after it was renamed, so it should fail
771     touch ${f}
772     $CHECKSTAT ${f}
773     mv ${f} ${f}.rename
774     $CHECKSTAT ${f}.rename
775     $CHECKSTAT -a ${f}
776 }
777 run_test 24n "Statting the old file after renaming (Posix rename 2)"
778
779 test_24o() {
780         check_kernel_version 37 || return 0
781         mkdir -p $DIR/d24o
782         rename_many -s random -v -n 10 $DIR/d24o
783 }
784 run_test 24o "rename of files during htree split ==============="
785
786 test_24p() {
787         mkdir $DIR/R12{a,b}
788         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
789         mrename $DIR/R12a $DIR/R12b
790         $CHECKSTAT -a $DIR/R12a || error
791         $CHECKSTAT -t dir $DIR/R12b || error
792         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
793         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
794 }
795 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
796
797 test_24q() {
798         mkdir $DIR/R13{a,b}
799         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
800         multiop_bg_pause $DIR/R13b D_c || return 1
801         MULTIPID=$!
802
803         mrename $DIR/R13a $DIR/R13b
804         $CHECKSTAT -a $DIR/R13a || error
805         $CHECKSTAT -t dir $DIR/R13b || error
806         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
807         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
808         kill -USR1 $MULTIPID
809         wait $MULTIPID || error "multiop close failed"
810 }
811 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
812
813 test_24r() { #bug 3789
814         mkdir $DIR/R14a $DIR/R14a/b
815         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
816         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
817         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
818 }
819 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
820
821 test_24s() {
822         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
823         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
824         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
825         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
826 }
827 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
828 test_24t() {
829         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
830         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
831         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
832         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
833 }
834 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
835
836 test_24u() { # bug12192
837         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
838         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
839 }
840 run_test 24u "create stripe file"
841
842 page_size() {
843         getconf PAGE_SIZE
844 }
845
846 test_24v() {
847         local NRFILES=100000
848         local FREE_INODES=`lfs df -i|grep "filesystem summary" | awk '{print $5}'`
849         [ $FREE_INODES -lt $NRFILES ] && \
850                 skip "not enough free inodes $FREE_INODES required $NRFILES" && \
851                 return
852
853         mkdir -p $DIR/d24v
854         createmany -m $DIR/d24v/$tfile $NRFILES
855
856         cancel_lru_locks mdc
857         lctl set_param mdc.*.stats clear
858
859         ls $DIR/d24v >/dev/null || error "error in listing large dir"
860
861         # LU-5 large readdir
862         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
863         #               8 bytes for name(filename is mostly 5 in this test) +
864         #               8 bytes for luda_type
865         # take into account of overhead in lu_dirpage header and end mark in
866         # each page, plus one in RPC_NUM calculation.
867         DIRENT_SIZE=48
868         RPC_SIZE=$(($(lctl get_param -n mdc.*.max_pages_per_rpc)*$(page_size)))
869         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
870         mds_readpage=`lctl get_param mdc.*.stats | \
871                                 awk '/^mds_readpage/ {print $2}'`
872         [ $mds_readpage -gt $RPC_NUM ] && \
873                 error "large readdir doesn't take effect"
874
875         rm $DIR/d24v -rf
876 }
877 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
878
879 test_24w() { # bug21506
880         SZ1=234852
881         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
882         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
883         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
884         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
885         [ "$SZ1" = "$SZ2" ] || \
886                 error "Error reading at the end of the file $tfile"
887 }
888 run_test 24w "Reading a file larger than 4Gb"
889
890 test_25a() {
891         echo '== symlink sanity ============================================='
892
893         mkdir $DIR/d25
894         ln -s d25 $DIR/s25
895         touch $DIR/s25/foo || error
896 }
897 run_test 25a "create file in symlinked directory ==============="
898
899 test_25b() {
900         [ ! -d $DIR/d25 ] && test_25a
901         $CHECKSTAT -t file $DIR/s25/foo || error
902 }
903 run_test 25b "lookup file in symlinked directory ==============="
904
905 test_26a() {
906         mkdir $DIR/d26
907         mkdir $DIR/d26/d26-2
908         ln -s d26/d26-2 $DIR/s26
909         touch $DIR/s26/foo || error
910 }
911 run_test 26a "multiple component symlink ======================="
912
913 test_26b() {
914         mkdir -p $DIR/d26b/d26-2
915         ln -s d26b/d26-2/foo $DIR/s26-2
916         touch $DIR/s26-2 || error
917 }
918 run_test 26b "multiple component symlink at end of lookup ======"
919
920 test_26c() {
921         mkdir $DIR/d26.2
922         touch $DIR/d26.2/foo
923         ln -s d26.2 $DIR/s26.2-1
924         ln -s s26.2-1 $DIR/s26.2-2
925         ln -s s26.2-2 $DIR/s26.2-3
926         chmod 0666 $DIR/s26.2-3/foo
927 }
928 run_test 26c "chain of symlinks ================================"
929
930 # recursive symlinks (bug 439)
931 test_26d() {
932         ln -s d26-3/foo $DIR/d26-3
933 }
934 run_test 26d "create multiple component recursive symlink ======"
935
936 test_26e() {
937         [ ! -h $DIR/d26-3 ] && test_26d
938         rm $DIR/d26-3
939 }
940 run_test 26e "unlink multiple component recursive symlink ======"
941
942 # recursive symlinks (bug 7022)
943 test_26f() {
944         mkdir -p $DIR/$tdir
945         mkdir $DIR/$tdir/$tfile        || error "mkdir $DIR/$tdir/$tfile failed"
946         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
947         mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
948         mkdir $tfile             || error "mkdir $tfile failed"
949         cd $tfile                || error "cd $tfile failed"
950         ln -s .. dotdot          || error "ln dotdot failed"
951         ln -s dotdot/lndir lndir || error "ln lndir failed"
952         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
953         output=`ls $tfile/$tfile/lndir/bar1`
954         [ "$output" = bar1 ] && error "unexpected output"
955         rm -r $tfile             || error "rm $tfile failed"
956         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
957 }
958 run_test 26f "rm -r of a directory which has recursive symlink ="
959
960 test_27a() {
961         echo '== stripe sanity =============================================='
962         mkdir -p $DIR/d27 || error "mkdir failed"
963         $GETSTRIPE $DIR/d27
964         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
965         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
966         pass
967         log "== test_27a: write to one stripe file ========================="
968         cp /etc/hosts $DIR/d27/f0 || error
969 }
970 run_test 27a "one stripe file =================================="
971
972 test_27b() {
973         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
974         mkdir -p $DIR/d27
975         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
976         $GETSTRIPE -c $DIR/d27/f01
977         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
978                 error "two-stripe file doesn't have two stripes"
979 }
980 run_test 27b "create two stripe file"
981
982 test_27c() {
983         [ -f $DIR/d27/f01 ] || skip "test_27b not run" && return
984
985         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
986 }
987 run_test 27c "write to two stripe file"
988
989 test_27d() {
990         mkdir -p $DIR/d27
991         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
992         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
993         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
994 }
995 run_test 27d "create file with default settings ================"
996
997 test_27e() {
998         mkdir -p $DIR/d27
999         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1000         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1001         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1002 }
1003 run_test 27e "setstripe existing file (should return error) ======"
1004
1005 test_27f() {
1006         mkdir -p $DIR/d27
1007         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1008         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
1009         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1010 }
1011 run_test 27f "setstripe with bad stripe size (should return error)"
1012
1013 test_27g() {
1014         mkdir -p $DIR/d27
1015         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1016         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1017                 error "$DIR/d27/fnone has object"
1018 }
1019 run_test 27g "$GETSTRIPE with no objects"
1020
1021 test_27i() {
1022         touch $DIR/d27/fsome || error "touch failed"
1023         [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
1024 }
1025 run_test 27i "$GETSTRIPE with some objects"
1026
1027 test_27j() {
1028         mkdir -p $DIR/d27
1029         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1030 }
1031 run_test 27j "setstripe with bad stripe offset (should return error)"
1032
1033 test_27k() { # bug 2844
1034         mkdir -p $DIR/d27
1035         FILE=$DIR/d27/f27k
1036         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1037         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
1038         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1039         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1040         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1041         dd if=/dev/zero of=$FILE bs=4k count=1
1042         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1043         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1044 }
1045 run_test 27k "limit i_blksize for broken user apps ============="
1046
1047 test_27l() {
1048         mkdir -p $DIR/d27
1049         mcreate $DIR/f27l || error "creating file"
1050         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1051                 error "setstripe should have failed" || true
1052 }
1053 run_test 27l "check setstripe permissions (should return error)"
1054
1055 test_27m() {
1056         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1057         if [ $ORIGFREE -gt $MAXFREE ]; then
1058                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1059                 return
1060         fi
1061         mkdir -p $DIR/d27
1062         $SETSTRIPE -i 0 -c 1 $DIR/d27/f27m_1
1063         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE &&
1064                 error "dd should fill OST0"
1065         i=2
1066         while $SETSTRIPE -i 0 -c 1 $DIR/d27/f27m_$i; do
1067                 i=`expr $i + 1`
1068                 [ $i -gt 256 ] && break
1069         done
1070         i=`expr $i + 1`
1071         touch $DIR/d27/f27m_$i
1072         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
1073                 error "OST0 was full but new created file still use it"
1074         i=`expr $i + 1`
1075         touch $DIR/d27/f27m_$i
1076         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
1077                 error "OST0 was full but new created file still use it"
1078         rm -r $DIR/d27
1079         sleep 15
1080 }
1081 run_test 27m "create file while OST0 was full =================="
1082
1083 sleep_maxage() {
1084         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1085         sleep $DELAY
1086 }
1087
1088 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1089 # if the OST isn't full anymore.
1090 reset_enospc() {
1091         local OSTIDX=${1:-""}
1092
1093         local list=$(comma_list $(osts_nodes))
1094         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1095
1096         do_nodes $list lctl set_param fail_loc=0
1097         sync    # initiate all OST_DESTROYs from MDS to OST
1098         sleep_maxage
1099 }
1100
1101 exhaust_precreations() {
1102         local OSTIDX=$1
1103         local FAILLOC=$2
1104         local FAILIDX=${3:-$OSTIDX}
1105
1106         mkdir -p $DIR/$tdir
1107         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1108         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1109
1110         local OST=$(ostname_from_index $OSTIDX)
1111         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1112                           sed -e 's/_UUID$//;s/^.*-//')
1113
1114         # on the mdt's osc
1115         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1116         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1117         osc.$mdtosc_proc1.prealloc_last_id)
1118         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1119         osc.$mdtosc_proc1.prealloc_next_id)
1120
1121         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1122         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1123
1124         mkdir -p $DIR/$tdir/${OST}
1125         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1126 #define OBD_FAIL_OST_ENOSPC              0x215
1127         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1128         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1129         echo "Creating to objid $last_id on ost $OST..."
1130         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1131         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1132         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1133         sleep_maxage
1134 }
1135
1136 exhaust_all_precreations() {
1137         local i
1138         for (( i=0; i < OSTCOUNT; i++ )) ; do
1139                 exhaust_precreations $i $1 -1
1140         done
1141 }
1142
1143 test_27n() {
1144         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1145         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1146         remote_ost_nodsh && skip "remote OST with nodsh" && return
1147
1148         reset_enospc
1149         rm -f $DIR/$tdir/$tfile
1150         exhaust_precreations 0 0x80000215
1151         $SETSTRIPE -c -1 $DIR/$tdir
1152         touch $DIR/$tdir/$tfile || error
1153         $GETSTRIPE $DIR/$tdir/$tfile
1154         reset_enospc
1155 }
1156 run_test 27n "create file with some full OSTs =================="
1157
1158 test_27o() {
1159         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1160         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1161         remote_ost_nodsh && skip "remote OST with nodsh" && return
1162
1163         reset_enospc
1164         rm -f $DIR/$tdir/$tfile
1165         exhaust_all_precreations 0x215
1166
1167         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1168
1169         reset_enospc
1170         rm -rf $DIR/$tdir/*
1171 }
1172 run_test 27o "create file with all full OSTs (should error) ===="
1173
1174 test_27p() {
1175         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1176         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1177         remote_ost_nodsh && skip "remote OST with nodsh" && return
1178
1179         reset_enospc
1180         rm -f $DIR/$tdir/$tfile
1181         mkdir -p $DIR/$tdir
1182
1183         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1184         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1185         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1186
1187         exhaust_precreations 0 0x80000215
1188         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1189         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1190         $GETSTRIPE $DIR/$tdir/$tfile
1191
1192         reset_enospc
1193 }
1194 run_test 27p "append to a truncated file with some full OSTs ==="
1195
1196 test_27q() {
1197         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1198         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1199         remote_ost_nodsh && skip "remote OST with nodsh" && return
1200
1201         reset_enospc
1202         rm -f $DIR/$tdir/$tfile
1203
1204         mkdir -p $DIR/$tdir
1205         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1206         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1207         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1208
1209         exhaust_all_precreations 0x215
1210
1211         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1212         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1213
1214         reset_enospc
1215 }
1216 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1217
1218 test_27r() {
1219         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1220         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1221         remote_ost_nodsh && skip "remote OST with nodsh" && return
1222
1223         reset_enospc
1224         rm -f $DIR/$tdir/$tfile
1225         exhaust_precreations 0 0x80000215
1226
1227         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1228
1229         reset_enospc
1230 }
1231 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1232
1233 test_27s() { # bug 10725
1234         mkdir -p $DIR/$tdir
1235         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1236         local stripe_count=0
1237         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1238         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1239                 error "stripe width >= 2^32 succeeded" || true
1240
1241 }
1242 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1243
1244 test_27t() { # bug 10864
1245         WDIR=`pwd`
1246         WLFS=`which lfs`
1247         cd $DIR
1248         touch $tfile
1249         $WLFS getstripe $tfile
1250         cd $WDIR
1251 }
1252 run_test 27t "check that utils parse path correctly"
1253
1254 test_27u() { # bug 4900
1255         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1256         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1257
1258 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1259         do_facet $SINGLEMDS lctl set_param fail_loc=0x139
1260         mkdir -p $DIR/$tdir
1261         createmany -o $DIR/$tdir/t- 1000
1262         do_facet $SINGLEMDS lctl set_param fail_loc=0
1263
1264         TLOG=$DIR/$tfile.getstripe
1265         $GETSTRIPE $DIR/$tdir > $TLOG
1266         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1267         unlinkmany $DIR/$tdir/t- 1000
1268         [ $OBJS -gt 0 ] && \
1269                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1270 }
1271 run_test 27u "skip object creation on OSC w/o objects =========="
1272
1273 test_27v() { # bug 4900
1274         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1275         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1276         remote_ost_nodsh && skip "remote OST with nodsh" && return
1277
1278         exhaust_all_precreations 0x215
1279         reset_enospc
1280
1281         mkdir -p $DIR/$tdir
1282         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1283
1284         touch $DIR/$tdir/$tfile
1285         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1286         # all except ost1
1287         for (( i=1; i < OSTCOUNT; i++ )); do
1288                 do_facet ost$i lctl set_param fail_loc=0x705
1289         done
1290         local START=`date +%s`
1291         createmany -o $DIR/$tdir/$tfile 32
1292
1293         local FINISH=`date +%s`
1294         local TIMEOUT=`lctl get_param -n timeout`
1295         local PROCESS=$((FINISH - START))
1296         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1297                error "$FINISH - $START >= $TIMEOUT / 2"
1298         sleep $((TIMEOUT / 2 - PROCESS))
1299         reset_enospc
1300 }
1301 run_test 27v "skip object creation on slow OST ================="
1302
1303 test_27w() { # bug 10997
1304         mkdir -p $DIR/$tdir || error "mkdir failed"
1305         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1306         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1307                 error "stripe size $size != 65536" || true
1308         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1309                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1310 }
1311 run_test 27w "check $SETSTRIPE -S option"
1312
1313 test_27wa() {
1314         [ "$OSTCOUNT" -lt "2" ] &&
1315                 skip_env "skipping multiple stripe count/offset test" && return
1316
1317         mkdir -p $DIR/$tdir || error "mkdir failed"
1318         for i in $(seq 1 $OSTCOUNT); do
1319                 offset=$((i - 1))
1320                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1321                         error "setstripe -c $i -i $offset failed"
1322                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1323                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1324                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1325                 [ $index -ne $offset ] &&
1326                         error "stripe offset $index != $offset" || true
1327         done
1328 }
1329 run_test 27wa "check $SETSTRIPE -c -i options"
1330
1331 test_27x() {
1332         remote_ost_nodsh && skip "remote OST with nodsh" && return
1333         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1334         OFFSET=$(($OSTCOUNT - 1))
1335         OSTIDX=0
1336         local OST=$(ostname_from_index $OSTIDX)
1337
1338         mkdir -p $DIR/$tdir
1339         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1340         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1341         sleep_maxage
1342         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1343         for i in `seq 0 $OFFSET`; do
1344                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1345                 error "OST0 was degraded but new created file still use it"
1346         done
1347         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1348 }
1349 run_test 27x "create files while OST0 is degraded"
1350
1351 test_27y() {
1352         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1353         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1354         remote_ost_nodsh && skip "remote OST with nodsh" && return
1355
1356         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1357         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1358             osc.$mdtosc.prealloc_last_id)
1359         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1360             osc.$mdtosc.prealloc_next_id)
1361         local fcount=$((last_id - next_id))
1362         [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1363         [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1364
1365         MDS_OSCS=`do_facet $SINGLEMDS lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
1366         OFFSET=$(($OSTCOUNT-1))
1367         OST=-1
1368         for OSC in $MDS_OSCS; do
1369                 if [ $OST == -1 ]; then {
1370                         OST=`osc_to_ost $OSC`
1371                 } else {
1372                         echo $OSC "is Deactivate:"
1373                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1374                 } fi
1375         done
1376
1377         OSTIDX=$(index_from_ostuuid $OST)
1378         mkdir -p $DIR/$tdir
1379         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1380
1381         do_facet ost$((OSTIDX+1)) lctl set_param -n obdfilter.$OST.degraded 1
1382         sleep_maxage
1383         createmany -o $DIR/$tdir/$tfile $fcount
1384         do_facet ost$((OSTIDX+1)) lctl set_param -n obdfilter.$OST.degraded 0
1385
1386         for i in `seq 0 $OFFSET`; do
1387                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "$OSTIDX"` ] || \
1388                       error "files created on deactivated OSTs instead of degraded OST"
1389         done
1390         for OSC in $MDS_OSCS; do
1391                 [ `osc_to_ost $OSC` != $OST  ] && {
1392                         echo $OSC "is activate"
1393                         do_facet $SINGLEMDS lctl --device %$OSC activate
1394                 }
1395         done
1396 }
1397 run_test 27y "create files while OST0 is degraded and the rest inactive"
1398
1399 check_seq_oid()
1400 {
1401         log "check file $1"
1402
1403         lmm_count=$($GETSTRIPE -c $1)
1404         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1405         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1406
1407         local old_ifs="$IFS"
1408         IFS=$'[:]'
1409         fid=($($LFS path2fid $1))
1410         IFS="$old_ifs"
1411
1412         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1413         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1414
1415         # compare lmm_seq and lu_fid->f_seq
1416         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1417         # compare lmm_object_id and lu_fid->oid
1418         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1419
1420         # check the trusted.fid attribute of the OST objects of the file
1421         local have_obdidx=false
1422         local stripe_nr=0
1423         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1424                 # skip lines up to and including "obdidx"
1425                 [ -z "$obdidx" ] && break
1426                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1427                 $have_obdidx || continue
1428
1429                 local ost=$((obdidx + 1))
1430                 local dev=$(ostdevname $ost)
1431
1432                 if [ $(facet_fstype ost$ost) != ldiskfs ]; then
1433                         echo "Currently only works with ldiskfs-based OSTs"
1434                         continue
1435                 fi
1436
1437                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1438
1439                 #don't unmount/remount the OSTs if we don't need to do that
1440                 #local dir=$(facet_mntpt ost$ost)
1441                 #stop ost$dev
1442                 #do_facet ost$dev mount -t $FSTYPE $dev $dir $OST_MOUNT_OPTS ||
1443                 #       { error "mounting $dev as $FSTYPE failed"; return 3; }
1444                 #local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid)
1445                 #local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
1446
1447                 local obj_file="O/$seq/d$((oid %32))/$oid"
1448                 local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1449                            $dev 2>/dev/null" | grep "parent=")
1450
1451                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1452
1453                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1454
1455                 #do_facet ost$ost umount -d $dir
1456                 #start ost$ost $dev $OST_MOUNT_OPTS
1457
1458                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1459                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1460                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1461                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1462                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1463                 local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1464
1465                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1466                 [ $ff_pseq = $lmm_seq ] ||
1467                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1468                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1469                 [ $ff_poid = $lmm_oid ] ||
1470                         error "FF parent OID $ff_poid != $lmm_oid"
1471                 [ $ff_pstripe = $stripe_nr ] ||
1472                         error "FF stripe $ff_pstripe != $stripe_nr"
1473
1474                 stripe_nr=$((stripe_nr + 1))
1475         done
1476 }
1477
1478 test_27z() {
1479         remote_ost_nodsh && skip "remote OST with nodsh" && return
1480         mkdir -p $DIR/$tdir
1481
1482         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1483                 { error "setstripe -c -1 failed"; return 1; }
1484         # We need to send a write to every object to get parent FID info set.
1485         # This _should_ also work for setattr, but does not currently.
1486         # touch $DIR/$tdir/$tfile-1 ||
1487         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1488                 { error "dd $tfile-1 failed"; return 2; }
1489         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1490                 { error "setstripe -c -1 failed"; return 3; }
1491         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1492                 { error "dd $tfile-2 failed"; return 4; }
1493
1494         # make sure write RPCs have been sent to OSTs
1495         sync; sleep 5; sync
1496
1497         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1498         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1499 }
1500 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1501
1502 test_27A() { # b=19102
1503         local restore_size=$($GETSTRIPE -S $MOUNT)
1504         local restore_count=$($GETSTRIPE -c $MOUNT)
1505         local restore_offset=$($GETSTRIPE -i $MOUNT)
1506         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1507         local default_size=$($GETSTRIPE -S $MOUNT)
1508         local default_count=$($GETSTRIPE -c $MOUNT)
1509         local default_offset=$($GETSTRIPE -i $MOUNT)
1510         local dsize=$((1024 * 1024))
1511         [ $default_size -eq $dsize ] ||
1512                 error "stripe size $default_size != $dsize"
1513         [ $default_count -eq 1 ] || error "stripe count $default_count != 1"
1514         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1515         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1516 }
1517 run_test 27A "check filesystem-wide default LOV EA values"
1518
1519 # createtest also checks that device nodes are created and
1520 # then visible correctly (#2091)
1521 test_28() { # bug 2091
1522         mkdir $DIR/d28
1523         $CREATETEST $DIR/d28/ct || error
1524 }
1525 run_test 28 "create/mknod/mkdir with bad file types ============"
1526
1527 test_29() {
1528         cancel_lru_locks mdc
1529         mkdir $DIR/d29
1530         touch $DIR/d29/foo
1531         log 'first d29'
1532         ls -l $DIR/d29
1533
1534         declare -i LOCKCOUNTORIG=0
1535         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1536                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1537         done
1538         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1539
1540         declare -i LOCKUNUSEDCOUNTORIG=0
1541         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1542                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1543         done
1544
1545         log 'second d29'
1546         ls -l $DIR/d29
1547         log 'done'
1548
1549         declare -i LOCKCOUNTCURRENT=0
1550         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1551                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1552         done
1553
1554         declare -i LOCKUNUSEDCOUNTCURRENT=0
1555         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1556                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1557         done
1558
1559         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1560                 lctl set_param -n ldlm.dump_namespaces ""
1561                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1562                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1563                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1564                 return 2
1565         fi
1566         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1567                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1568                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1569                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1570                 return 3
1571         fi
1572 }
1573 run_test 29 "IT_GETATTR regression  ============================"
1574
1575 test_30a() { # was test_30
1576         cp `which ls` $DIR || cp /bin/ls $DIR
1577         $DIR/ls / || error
1578         rm $DIR/ls
1579 }
1580 run_test 30a "execute binary from Lustre (execve) =============="
1581
1582 test_30b() {
1583         cp `which ls` $DIR || cp /bin/ls $DIR
1584         chmod go+rx $DIR/ls
1585         $RUNAS $DIR/ls / || error
1586         rm $DIR/ls
1587 }
1588 run_test 30b "execute binary from Lustre as non-root ==========="
1589
1590 test_30c() { # b=22376
1591         cp `which ls` $DIR || cp /bin/ls $DIR
1592         chmod a-rw $DIR/ls
1593         cancel_lru_locks mdc
1594         cancel_lru_locks osc
1595         $RUNAS $DIR/ls / || error
1596         rm -f $DIR/ls
1597 }
1598 run_test 30c "execute binary from Lustre without read perms ===="
1599
1600 test_31a() {
1601         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1602         $CHECKSTAT -a $DIR/f31 || error
1603 }
1604 run_test 31a "open-unlink file =================================="
1605
1606 test_31b() {
1607         touch $DIR/f31 || error
1608         ln $DIR/f31 $DIR/f31b || error
1609         $MULTIOP $DIR/f31b Ouc || error
1610         $CHECKSTAT -t file $DIR/f31 || error
1611 }
1612 run_test 31b "unlink file with multiple links while open ======="
1613
1614 test_31c() {
1615         touch $DIR/f31 || error
1616         ln $DIR/f31 $DIR/f31c || error
1617         multiop_bg_pause $DIR/f31 O_uc || return 1
1618         MULTIPID=$!
1619         $MULTIOP $DIR/f31c Ouc
1620         kill -USR1 $MULTIPID
1621         wait $MULTIPID
1622 }
1623 run_test 31c "open-unlink file with multiple links ============="
1624
1625 test_31d() {
1626         opendirunlink $DIR/d31d $DIR/d31d || error
1627         $CHECKSTAT -a $DIR/d31d || error
1628 }
1629 run_test 31d "remove of open directory ========================="
1630
1631 test_31e() { # bug 2904
1632         check_kernel_version 34 || return 0
1633         openfilleddirunlink $DIR/d31e || error
1634 }
1635 run_test 31e "remove of open non-empty directory ==============="
1636
1637 test_31f() { # bug 4554
1638         set -vx
1639         mkdir $DIR/d31f
1640         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1641         cp /etc/hosts $DIR/d31f
1642         ls -l $DIR/d31f
1643         $GETSTRIPE $DIR/d31f/hosts
1644         multiop_bg_pause $DIR/d31f D_c || return 1
1645         MULTIPID=$!
1646
1647         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1648         mkdir $DIR/d31f
1649         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1650         cp /etc/hosts $DIR/d31f
1651         ls -l $DIR/d31f
1652         $GETSTRIPE $DIR/d31f/hosts
1653         multiop_bg_pause $DIR/d31f D_c || return 1
1654         MULTIPID2=$!
1655
1656         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1657         wait $MULTIPID || error "first opendir $MULTIPID failed"
1658
1659         sleep 6
1660
1661         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1662         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1663         set +vx
1664 }
1665 run_test 31f "remove of open directory with open-unlink file ==="
1666
1667 test_31g() {
1668         echo "-- cross directory link --"
1669         mkdir $DIR/d31g{a,b}
1670         touch $DIR/d31ga/f
1671         ln $DIR/d31ga/f $DIR/d31gb/g
1672         $CHECKSTAT -t file $DIR/d31ga/f || error "source"
1673         [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
1674         $CHECKSTAT -t file $DIR/d31gb/g || error "target"
1675         [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
1676 }
1677 run_test 31g "cross directory link==============="
1678
1679 test_31h() {
1680         echo "-- cross directory link --"
1681         mkdir $DIR/d31h
1682         mkdir $DIR/d31h/dir
1683         touch $DIR/d31h/f
1684         ln $DIR/d31h/f $DIR/d31h/dir/g
1685         $CHECKSTAT -t file $DIR/d31h/f || error "source"
1686         [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
1687         $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
1688         [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
1689 }
1690 run_test 31h "cross directory link under child==============="
1691
1692 test_31i() {
1693         echo "-- cross directory link --"
1694         mkdir $DIR/d31i
1695         mkdir $DIR/d31i/dir
1696         touch $DIR/d31i/dir/f
1697         ln $DIR/d31i/dir/f $DIR/d31i/g
1698         $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
1699         [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
1700         $CHECKSTAT -t file $DIR/d31i/g || error "target"
1701         [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
1702 }
1703 run_test 31i "cross directory link under parent==============="
1704
1705
1706 test_31j() {
1707         mkdir $DIR/d31j
1708         mkdir $DIR/d31j/dir1
1709         ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
1710         link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
1711         mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
1712         mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
1713         return 0
1714 }
1715 run_test 31j "link for directory==============="
1716
1717
1718 test_31k() {
1719         mkdir $DIR/d31k
1720         touch $DIR/d31k/s
1721         touch $DIR/d31k/exist
1722         mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
1723         mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
1724         mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
1725         mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
1726         mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
1727         mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
1728         mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
1729         return 0
1730 }
1731 run_test 31k "link to file: the same, non-existing, dir==============="
1732
1733 test_31m() {
1734         mkdir $DIR/d31m
1735         touch $DIR/d31m/s
1736         mkdir $DIR/d31m2
1737         touch $DIR/d31m2/exist
1738         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
1739         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
1740         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
1741         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
1742         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
1743         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
1744         return 0
1745 }
1746 run_test 31m "link to file: the same, non-existing, dir==============="
1747
1748 test_32a() {
1749         echo "== more mountpoints and symlinks ================="
1750         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1751         mkdir -p $DIR/d32a/ext2-mountpoint
1752         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1753         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error
1754         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1755 }
1756 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1757
1758 test_32b() {
1759         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1760         mkdir -p $DIR/d32b/ext2-mountpoint
1761         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1762         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1763         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1764 }
1765 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1766
1767 test_32c() {
1768         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1769         mkdir -p $DIR/d32c/ext2-mountpoint
1770         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1771         mkdir -p $DIR/d32c/d2/test_dir
1772         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1773         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1774 }
1775 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1776
1777 test_32d() {
1778         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1779         mkdir -p $DIR/d32d/ext2-mountpoint
1780         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1781         mkdir -p $DIR/d32d/d2/test_dir
1782         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1783         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1784 }
1785 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1786
1787 test_32e() {
1788         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1789         mkdir -p $DIR/d32e/tmp
1790         TMP_DIR=$DIR/d32e/tmp
1791         ln -s $DIR/d32e $TMP_DIR/symlink11
1792         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1793         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1794         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1795 }
1796 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1797
1798 test_32f() {
1799         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1800         mkdir -p $DIR/d32f/tmp
1801         TMP_DIR=$DIR/d32f/tmp
1802         ln -s $DIR/d32f $TMP_DIR/symlink11
1803         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1804         ls $DIR/d32f/tmp/symlink11  || error
1805         ls $DIR/d32f/symlink01 || error
1806 }
1807 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1808
1809 test_32g() {
1810         TMP_DIR=$DIR/$tdir/tmp
1811         mkdir -p $TMP_DIR $DIR/${tdir}2
1812         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1813         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1814         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1815         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1816         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1817         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1818 }
1819 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1820
1821 test_32h() {
1822         rm -fr $DIR/$tdir $DIR/${tdir}2
1823         TMP_DIR=$DIR/$tdir/tmp
1824         mkdir -p $TMP_DIR $DIR/${tdir}2
1825         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
1826         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1827         ls $TMP_DIR/symlink12 || error
1828         ls $DIR/$tdir/symlink02  || error
1829 }
1830 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1831
1832 test_32i() {
1833         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1834         mkdir -p $DIR/d32i/ext2-mountpoint
1835         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1836         touch $DIR/d32i/test_file
1837         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error
1838         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1839 }
1840 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1841
1842 test_32j() {
1843         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1844         mkdir -p $DIR/d32j/ext2-mountpoint
1845         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1846         touch $DIR/d32j/test_file
1847         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1848         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1849 }
1850 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1851
1852 test_32k() {
1853         rm -fr $DIR/d32k
1854         mkdir -p $DIR/d32k/ext2-mountpoint
1855         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint
1856         mkdir -p $DIR/d32k/d2
1857         touch $DIR/d32k/d2/test_file || error
1858         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1859         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1860 }
1861 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1862
1863 test_32l() {
1864         rm -fr $DIR/d32l
1865         mkdir -p $DIR/d32l/ext2-mountpoint
1866         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1867         mkdir -p $DIR/d32l/d2
1868         touch $DIR/d32l/d2/test_file
1869         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1870         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1871 }
1872 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1873
1874 test_32m() {
1875         rm -fr $DIR/d32m
1876         mkdir -p $DIR/d32m/tmp
1877         TMP_DIR=$DIR/d32m/tmp
1878         ln -s $DIR $TMP_DIR/symlink11
1879         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1880         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1881         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1882 }
1883 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1884
1885 test_32n() {
1886         rm -fr $DIR/d32n
1887         mkdir -p $DIR/d32n/tmp
1888         TMP_DIR=$DIR/d32n/tmp
1889         ln -s $DIR $TMP_DIR/symlink11
1890         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
1891         ls -l $DIR/d32n/tmp/symlink11  || error
1892         ls -l $DIR/d32n/symlink01 || error
1893 }
1894 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1895
1896 test_32o() {
1897         rm -fr $DIR/d32o $DIR/$tfile
1898         touch $DIR/$tfile
1899         mkdir -p $DIR/d32o/tmp
1900         TMP_DIR=$DIR/d32o/tmp
1901         ln -s $DIR/$tfile $TMP_DIR/symlink12
1902         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1903         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1904         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1905         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1906         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1907 }
1908 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1909
1910 test_32p() {
1911     log 32p_1
1912         rm -fr $DIR/d32p
1913     log 32p_2
1914         rm -f $DIR/$tfile
1915     log 32p_3
1916         touch $DIR/$tfile
1917     log 32p_4
1918         mkdir -p $DIR/d32p/tmp
1919     log 32p_5
1920         TMP_DIR=$DIR/d32p/tmp
1921     log 32p_6
1922         ln -s $DIR/$tfile $TMP_DIR/symlink12
1923     log 32p_7
1924         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
1925     log 32p_8
1926         cat $DIR/d32p/tmp/symlink12 || error
1927     log 32p_9
1928         cat $DIR/d32p/symlink02 || error
1929     log 32p_10
1930 }
1931 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1932
1933 test_32q() {
1934         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1935         mkdir -p $DIR/d32q
1936         touch $DIR/d32q/under_the_mount
1937         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1938         ls $DIR/d32q/under_the_mount && error || true
1939         $UMOUNT $DIR/d32q || error
1940 }
1941 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1942
1943 test_32r() {
1944         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1945         mkdir -p $DIR/d32r
1946         touch $DIR/d32r/under_the_mount
1947         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1948         ls $DIR/d32r | grep -q under_the_mount && error || true
1949         $UMOUNT $DIR/d32r || error
1950 }
1951 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1952
1953 test_33() {
1954         rm -f $DIR/$tfile
1955         touch $DIR/$tfile
1956         chmod 444 $DIR/$tfile
1957         chown $RUNAS_ID $DIR/$tfile
1958         log 33_1
1959         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1960         log 33_2
1961 }
1962 run_test 33 "write file with mode 444 (should return error) ===="
1963
1964 test_33a() {
1965         rm -fr $DIR/d33
1966         mkdir -p $DIR/d33
1967         chown $RUNAS_ID $DIR/d33
1968         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1969         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1970                 error "open RDWR" || true
1971 }
1972 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1973
1974 test_33b() {
1975         rm -fr $DIR/d33
1976         mkdir -p $DIR/d33
1977         chown $RUNAS_ID $DIR/d33
1978         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
1979 }
1980 run_test 33b "test open file with malformed flags (No panic and return error)"
1981
1982 test_33c() {
1983         local ostnum
1984         local ostname
1985         local write_bytes
1986         local all_zeros
1987
1988         remote_ost_nodsh && skip "remote OST with nodsh" && return
1989         all_zeros=:
1990         rm -fr $DIR/d33
1991         mkdir -p $DIR/d33
1992         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
1993
1994         sync
1995         for ostnum in $(seq $OSTCOUNT); do
1996                 # test-framework's OST numbering is one-based, while Lustre's
1997                 # is zero-based
1998                 ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
1999                 # Parsing llobdstat's output sucks; we could grep the /proc
2000                 # path, but that's likely to not be as portable as using the
2001                 # llobdstat utility.  So we parse lctl output instead.
2002                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2003                         obdfilter/$ostname/stats |
2004                         awk '/^write_bytes/ {print $7}' )
2005                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2006                 if (( ${write_bytes:-0} > 0 ))
2007                 then
2008                         all_zeros=false
2009                         break;
2010                 fi
2011         done
2012
2013         $all_zeros || return 0
2014
2015         # Write four bytes
2016         echo foo > $DIR/d33/bar
2017         # Really write them
2018         sync
2019
2020         # Total up write_bytes after writing.  We'd better find non-zeros.
2021         for ostnum in $(seq $OSTCOUNT); do
2022                 ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
2023                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2024                         obdfilter/$ostname/stats |
2025                         awk '/^write_bytes/ {print $7}' )
2026                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2027                 if (( ${write_bytes:-0} > 0 ))
2028                 then
2029                         all_zeros=false
2030                         break;
2031                 fi
2032         done
2033
2034         if $all_zeros
2035         then
2036                 for ostnum in $(seq $OSTCOUNT); do
2037                         ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
2038                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2039                         do_facet ost$ostnum lctl get_param -n \
2040                                 obdfilter/$ostname/stats
2041                 done
2042                 error "OST not keeping write_bytes stats (b22312)"
2043         fi
2044 }
2045 run_test 33c "test llobdstat and write_bytes"
2046
2047 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2048 test_34a() {
2049         rm -f $DIR/f34
2050         $MCREATE $DIR/f34 || error
2051         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2052         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2053         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2054         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2055 }
2056 run_test 34a "truncate file that has not been opened ==========="
2057
2058 test_34b() {
2059         [ ! -f $DIR/f34 ] && test_34a
2060         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2061         $OPENFILE -f O_RDONLY $DIR/f34
2062         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2063         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2064 }
2065 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2066
2067 test_34c() {
2068         [ ! -f $DIR/f34 ] && test_34a
2069         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2070         $OPENFILE -f O_RDWR $DIR/f34
2071         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2072         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2073 }
2074 run_test 34c "O_RDWR opening file-with-size works =============="
2075
2076 test_34d() {
2077         [ ! -f $DIR/f34 ] && test_34a
2078         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2079         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2080         rm $DIR/f34
2081 }
2082 run_test 34d "write to sparse file ============================="
2083
2084 test_34e() {
2085         rm -f $DIR/f34e
2086         $MCREATE $DIR/f34e || error
2087         $TRUNCATE $DIR/f34e 1000 || error
2088         $CHECKSTAT -s 1000 $DIR/f34e || error
2089         $OPENFILE -f O_RDWR $DIR/f34e
2090         $CHECKSTAT -s 1000 $DIR/f34e || error
2091 }
2092 run_test 34e "create objects, some with size and some without =="
2093
2094 test_34f() { # bug 6242, 6243
2095         SIZE34F=48000
2096         rm -f $DIR/f34f
2097         $MCREATE $DIR/f34f || error
2098         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2099         dd if=$DIR/f34f of=$TMP/f34f
2100         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2101         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2102         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2103         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2104         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2105 }
2106 run_test 34f "read from a file with no objects until EOF ======="
2107
2108 test_34g() {
2109         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2110         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2111         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2112         cancel_lru_locks osc
2113         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2114                 error "wrong size after lock cancel"
2115
2116         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2117         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2118                 error "expanding truncate failed"
2119         cancel_lru_locks osc
2120         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2121                 error "wrong expanded size after lock cancel"
2122 }
2123 run_test 34g "truncate long file ==============================="
2124
2125 test_34h() {
2126         local gid=10
2127         local sz=1000
2128
2129         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2130         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2131         MULTIPID=$!
2132         sleep 2
2133
2134         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2135                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2136                 kill -9 $MULTIPID
2137         fi
2138         wait $MULTIPID
2139         local nsz=`stat -c %s $DIR/$tfile`
2140         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2141 }
2142 run_test 34h "ftruncate file under grouplock should not block"
2143
2144 test_35a() {
2145         cp /bin/sh $DIR/f35a
2146         chmod 444 $DIR/f35a
2147         chown $RUNAS_ID $DIR/f35a
2148         $RUNAS $DIR/f35a && error || true
2149         rm $DIR/f35a
2150 }
2151 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2152
2153 test_36a() {
2154         rm -f $DIR/f36
2155         utime $DIR/f36 || error
2156 }
2157 run_test 36a "MDS utime check (mknod, utime) ==================="
2158
2159 test_36b() {
2160         echo "" > $DIR/f36
2161         utime $DIR/f36 || error
2162 }
2163 run_test 36b "OST utime check (open, utime) ===================="
2164
2165 test_36c() {
2166         rm -f $DIR/d36/f36
2167         mkdir $DIR/d36
2168         chown $RUNAS_ID $DIR/d36
2169         $RUNAS utime $DIR/d36/f36 || error
2170 }
2171 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2172
2173 test_36d() {
2174         [ ! -d $DIR/d36 ] && test_36c
2175         echo "" > $DIR/d36/f36
2176         $RUNAS utime $DIR/d36/f36 || error
2177 }
2178 run_test 36d "non-root OST utime check (open, utime) ==========="
2179
2180 test_36e() {
2181         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2182         mkdir -p $DIR/$tdir
2183         touch $DIR/$tdir/$tfile
2184         $RUNAS utime $DIR/$tdir/$tfile && \
2185                 error "utime worked, expected failure" || true
2186 }
2187 run_test 36e "utime on non-owned file (should return error) ===="
2188
2189 subr_36fh() {
2190         local fl="$1"
2191         local LANG_SAVE=$LANG
2192         local LC_LANG_SAVE=$LC_LANG
2193         export LANG=C LC_LANG=C # for date language
2194
2195         DATESTR="Dec 20  2000"
2196         mkdir -p $DIR/$tdir
2197         lctl set_param fail_loc=$fl
2198         date; date +%s
2199         cp /etc/hosts $DIR/$tdir/$tfile
2200         sync & # write RPC generated with "current" inode timestamp, but delayed
2201         sleep 1
2202         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2203         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2204         cancel_lru_locks osc
2205         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2206         date; date +%s
2207         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2208                 echo "BEFORE: $LS_BEFORE" && \
2209                 echo "AFTER : $LS_AFTER" && \
2210                 echo "WANT  : $DATESTR" && \
2211                 error "$DIR/$tdir/$tfile timestamps changed" || true
2212
2213         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2214 }
2215
2216 test_36f() {
2217         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2218         subr_36fh "0x80000214"
2219 }
2220 run_test 36f "utime on file racing with OST BRW write =========="
2221
2222 test_36g() {
2223         remote_ost_nodsh && skip "remote OST with nodsh" && return
2224         local fmd_max_age
2225         local fmd_before
2226         local fmd_after
2227
2228         mkdir -p $DIR/$tdir
2229         fmd_max_age=$(do_facet ost1 \
2230                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2231                 head -n 1")
2232
2233         fmd_before=$(do_facet ost1 \
2234                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2235         touch $DIR/$tdir/$tfile
2236         sleep $((fmd_max_age + 12))
2237         fmd_after=$(do_facet ost1 \
2238                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2239
2240         echo "fmd_before: $fmd_before"
2241         echo "fmd_after: $fmd_after"
2242         [ "$fmd_after" -gt "$fmd_before" ] && \
2243                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2244                 error "fmd didn't expire after ping" || true
2245 }
2246 run_test 36g "filter mod data cache expiry ====================="
2247
2248 test_36h() {
2249         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2250         subr_36fh "0x80000227"
2251 }
2252 run_test 36h "utime on file racing with OST BRW write =========="
2253
2254 test_37() {
2255         mkdir -p $DIR/$tdir
2256         echo f > $DIR/$tdir/fbugfile
2257         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2258         ls $DIR/$tdir | grep "\<fbugfile\>" && error
2259         $UMOUNT $DIR/$tdir || error
2260         rm -f $DIR/$tdir/fbugfile || error
2261 }
2262 run_test 37 "ls a mounted file system to check old content ====="
2263
2264 test_38() {
2265         local file=$DIR/$tfile
2266         touch $file
2267         openfile -f O_DIRECTORY $file
2268         local RC=$?
2269         local ENOTDIR=20
2270         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2271         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2272 }
2273 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2274
2275 test_39() {
2276         touch $DIR/$tfile
2277         touch $DIR/${tfile}2
2278 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2279 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2280 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2281         sleep 2
2282         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2283         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2284                 echo "mtime"
2285                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2286                 echo "atime"
2287                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2288                 echo "ctime"
2289                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2290                 error "O_TRUNC didn't change timestamps"
2291         fi
2292 }
2293 run_test 39 "mtime changed on create ==========================="
2294
2295 test_39b() {
2296         mkdir -p $DIR/$tdir
2297         cp -p /etc/passwd $DIR/$tdir/fopen
2298         cp -p /etc/passwd $DIR/$tdir/flink
2299         cp -p /etc/passwd $DIR/$tdir/funlink
2300         cp -p /etc/passwd $DIR/$tdir/frename
2301         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2302
2303         sleep 1
2304         echo "aaaaaa" >> $DIR/$tdir/fopen
2305         echo "aaaaaa" >> $DIR/$tdir/flink
2306         echo "aaaaaa" >> $DIR/$tdir/funlink
2307         echo "aaaaaa" >> $DIR/$tdir/frename
2308
2309         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2310         local link_new=`stat -c %Y $DIR/$tdir/flink`
2311         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2312         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2313
2314         cat $DIR/$tdir/fopen > /dev/null
2315         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2316         rm -f $DIR/$tdir/funlink2
2317         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2318
2319         for (( i=0; i < 2; i++ )) ; do
2320                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2321                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2322                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2323                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2324
2325                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2326                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2327                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2328                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2329
2330                 cancel_lru_locks osc
2331                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2332         done
2333 }
2334 run_test 39b "mtime change on open, link, unlink, rename  ======"
2335
2336 # this should be set to past
2337 TEST_39_MTIME=`date -d "1 year ago" +%s`
2338
2339 # bug 11063
2340 test_39c() {
2341         touch $DIR1/$tfile
2342         sleep 2
2343         local mtime0=`stat -c %Y $DIR1/$tfile`
2344
2345         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2346         local mtime1=`stat -c %Y $DIR1/$tfile`
2347         [ "$mtime1" = $TEST_39_MTIME ] || \
2348                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2349
2350         local d1=`date +%s`
2351         echo hello >> $DIR1/$tfile
2352         local d2=`date +%s`
2353         local mtime2=`stat -c %Y $DIR1/$tfile`
2354         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2355                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2356
2357         mv $DIR1/$tfile $DIR1/$tfile-1
2358
2359         for (( i=0; i < 2; i++ )) ; do
2360                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2361                 [ "$mtime2" = "$mtime3" ] || \
2362                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2363
2364                 cancel_lru_locks osc
2365                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2366         done
2367 }
2368 run_test 39c "mtime change on rename ==========================="
2369
2370 # bug 21114
2371 test_39d() {
2372         touch $DIR1/$tfile
2373
2374         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2375
2376         for (( i=0; i < 2; i++ )) ; do
2377                 local mtime=`stat -c %Y $DIR1/$tfile`
2378                 [ $mtime = $TEST_39_MTIME ] || \
2379                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2380
2381                 cancel_lru_locks osc
2382                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2383         done
2384 }
2385 run_test 39d "create, utime, stat =============================="
2386
2387 # bug 21114
2388 test_39e() {
2389         touch $DIR1/$tfile
2390         local mtime1=`stat -c %Y $DIR1/$tfile`
2391
2392         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2393
2394         for (( i=0; i < 2; i++ )) ; do
2395                 local mtime2=`stat -c %Y $DIR1/$tfile`
2396                 [ $mtime2 = $TEST_39_MTIME ] || \
2397                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2398
2399                 cancel_lru_locks osc
2400                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2401         done
2402 }
2403 run_test 39e "create, stat, utime, stat ========================"
2404
2405 # bug 21114
2406 test_39f() {
2407         touch $DIR1/$tfile
2408         mtime1=`stat -c %Y $DIR1/$tfile`
2409
2410         sleep 2
2411         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2412
2413         for (( i=0; i < 2; i++ )) ; do
2414                 local mtime2=`stat -c %Y $DIR1/$tfile`
2415                 [ $mtime2 = $TEST_39_MTIME ] || \
2416                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2417
2418                 cancel_lru_locks osc
2419                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2420         done
2421 }
2422 run_test 39f "create, stat, sleep, utime, stat ================="
2423
2424 # bug 11063
2425 test_39g() {
2426         echo hello >> $DIR1/$tfile
2427         local mtime1=`stat -c %Y $DIR1/$tfile`
2428
2429         sleep 2
2430         chmod o+r $DIR1/$tfile
2431
2432         for (( i=0; i < 2; i++ )) ; do
2433                 local mtime2=`stat -c %Y $DIR1/$tfile`
2434                 [ "$mtime1" = "$mtime2" ] || \
2435                         error "lost mtime: $mtime2, should be $mtime1"
2436
2437                 cancel_lru_locks osc
2438                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2439         done
2440 }
2441 run_test 39g "write, chmod, stat ==============================="
2442
2443 # bug 11063
2444 test_39h() {
2445         touch $DIR1/$tfile
2446         sleep 1
2447
2448         local d1=`date`
2449         echo hello >> $DIR1/$tfile
2450         local mtime1=`stat -c %Y $DIR1/$tfile`
2451
2452         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2453         local d2=`date`
2454         if [ "$d1" != "$d2" ]; then
2455                 echo "write and touch not within one second"
2456         else
2457                 for (( i=0; i < 2; i++ )) ; do
2458                         local mtime2=`stat -c %Y $DIR1/$tfile`
2459                         [ "$mtime2" = $TEST_39_MTIME ] || \
2460                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2461
2462                         cancel_lru_locks osc
2463                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2464                 done
2465         fi
2466 }
2467 run_test 39h "write, utime within one second, stat ============="
2468
2469 test_39i() {
2470         touch $DIR1/$tfile
2471         sleep 1
2472
2473         echo hello >> $DIR1/$tfile
2474         local mtime1=`stat -c %Y $DIR1/$tfile`
2475
2476         mv $DIR1/$tfile $DIR1/$tfile-1
2477
2478         for (( i=0; i < 2; i++ )) ; do
2479                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2480
2481                 [ "$mtime1" = "$mtime2" ] || \
2482                         error "lost mtime: $mtime2, should be $mtime1"
2483
2484                 cancel_lru_locks osc
2485                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2486         done
2487 }
2488 run_test 39i "write, rename, stat =============================="
2489
2490 test_39j() {
2491         start_full_debug_logging
2492         touch $DIR1/$tfile
2493         sleep 1
2494
2495         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
2496         lctl set_param fail_loc=0x80000412
2497         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
2498                 error "multiop failed"
2499         local multipid=$!
2500         local mtime1=`stat -c %Y $DIR1/$tfile`
2501
2502         mv $DIR1/$tfile $DIR1/$tfile-1
2503
2504         kill -USR1 $multipid
2505         wait $multipid || error "multiop close failed"
2506
2507         for (( i=0; i < 2; i++ )) ; do
2508                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2509                 [ "$mtime1" = "$mtime2" ] ||
2510                         error "mtime is lost on close: $mtime2, " \
2511                               "should be $mtime1"
2512
2513                 cancel_lru_locks osc
2514                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2515         done
2516         lctl set_param fail_loc=0
2517         stop_full_debug_logging
2518 }
2519 run_test 39j "write, rename, close, stat ======================="
2520
2521 test_39k() {
2522         touch $DIR1/$tfile
2523         sleep 1
2524
2525         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
2526         local multipid=$!
2527         local mtime1=`stat -c %Y $DIR1/$tfile`
2528
2529         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2530
2531         kill -USR1 $multipid
2532         wait $multipid || error "multiop close failed"
2533
2534         for (( i=0; i < 2; i++ )) ; do
2535                 local mtime2=`stat -c %Y $DIR1/$tfile`
2536
2537                 [ "$mtime2" = $TEST_39_MTIME ] || \
2538                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
2539
2540                 cancel_lru_locks osc
2541                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2542         done
2543 }
2544 run_test 39k "write, utime, close, stat ========================"
2545
2546 # this should be set to future
2547 TEST_39_ATIME=`date -d "1 year" +%s`
2548
2549 is_sles11()                                             # LU-1783
2550 {
2551         if [ -r /etc/SuSE-release ]
2552         then
2553                 local vers=`grep VERSION /etc/SuSE-release | awk '{print $3}'`
2554                 local patchlev=`grep PATCHLEVEL /etc/SuSE-release \
2555                         | awk '{print $3}'`
2556                 if [ $vers -eq 11 ] && [ $patchlev -eq 1 ]
2557                 then
2558                         return 0
2559                 fi
2560         fi
2561         return 1
2562 }
2563
2564 test_39l() {
2565         is_sles11 && skip "SLES 11 SP1" && return       # LU-1783
2566         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2567         local atime_diff=$(do_facet $SINGLEMDS lctl get_param -n mdd.*.atime_diff)
2568
2569         mkdir -p $DIR/$tdir
2570
2571         # test setting directory atime to future
2572         touch -a -d @$TEST_39_ATIME $DIR/$tdir
2573         local atime=$(stat -c %X $DIR/$tdir)
2574         [ "$atime" = $TEST_39_ATIME ] || \
2575                 error "atime is not set to future: $atime, should be $TEST_39_ATIME"
2576
2577         # test setting directory atime from future to now
2578         local d1=$(date +%s)
2579         ls $DIR/$tdir
2580         local d2=$(date +%s)
2581
2582         cancel_lru_locks mdc
2583         atime=$(stat -c %X $DIR/$tdir)
2584         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2585                 error "atime is not updated from future: $atime, should be $d1<atime<$d2"
2586
2587         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=2
2588         sleep 3
2589
2590         # test setting directory atime when now > dir atime + atime_diff
2591         d1=$(date +%s)
2592         ls $DIR/$tdir
2593         d2=$(date +%s)
2594         cancel_lru_locks mdc
2595         atime=$(stat -c %X $DIR/$tdir)
2596         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2597                 error "atime is not updated  : $atime, should be $d2"
2598
2599         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=60
2600         sleep 3
2601
2602         # test not setting directory atime when now < dir atime + atime_diff
2603         ls $DIR/$tdir
2604         cancel_lru_locks mdc
2605         atime=$(stat -c %X $DIR/$tdir)
2606         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2607                 error "atime is updated to $atime, should remain $d1<atime<$d2"
2608
2609         do_facet $SINGLEMDS lctl set_param -n mdd.*.atime_diff=$atime_diff
2610 }
2611 run_test 39l "directory atime update ==========================="
2612
2613 test_39m() {
2614         touch $DIR1/$tfile
2615         sleep 2
2616         local far_past_mtime=$(date -d "May 29 1953" +%s)
2617         local far_past_atime=$(date -d "Dec 17 1903" +%s)
2618
2619         touch -m -d @$far_past_mtime $DIR1/$tfile
2620         touch -a -d @$far_past_atime $DIR1/$tfile
2621
2622         for (( i=0; i < 2; i++ )) ; do
2623                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
2624                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
2625                         error "atime or mtime set incorrectly"
2626
2627                 cancel_lru_locks osc
2628                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2629         done
2630 }
2631 run_test 39m "test atime and mtime before 1970"
2632
2633 test_40() {
2634         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
2635         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
2636         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
2637 }
2638 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
2639
2640 test_41() {
2641         # bug 1553
2642         small_write $DIR/f41 18
2643 }
2644 run_test 41 "test small file write + fstat ====================="
2645
2646 count_ost_writes() {
2647         lctl get_param -n osc.*.stats |
2648             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
2649 }
2650
2651 # decent default
2652 WRITEBACK_SAVE=500
2653 DIRTY_RATIO_SAVE=40
2654 MAX_DIRTY_RATIO=50
2655 BG_DIRTY_RATIO_SAVE=10
2656 MAX_BG_DIRTY_RATIO=25
2657
2658 start_writeback() {
2659         trap 0
2660         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
2661         # dirty_ratio, dirty_background_ratio
2662         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
2663                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
2664                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
2665                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
2666         else
2667                 # if file not here, we are a 2.4 kernel
2668                 kill -CONT `pidof kupdated`
2669         fi
2670 }
2671
2672 stop_writeback() {
2673         # setup the trap first, so someone cannot exit the test at the
2674         # exact wrong time and mess up a machine
2675         trap start_writeback EXIT
2676         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
2677         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
2678                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
2679                 sysctl -w vm.dirty_writeback_centisecs=0
2680                 sysctl -w vm.dirty_writeback_centisecs=0
2681                 # save and increase /proc/sys/vm/dirty_ratio
2682                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
2683                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
2684                 # save and increase /proc/sys/vm/dirty_background_ratio
2685                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
2686                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
2687         else
2688                 # if file not here, we are a 2.4 kernel
2689                 kill -STOP `pidof kupdated`
2690         fi
2691 }
2692
2693 # ensure that all stripes have some grant before we test client-side cache
2694 setup_test42() {
2695         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
2696                 dd if=/dev/zero of=$i bs=4k count=1
2697                 rm $i
2698         done
2699 }
2700
2701 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
2702 # file truncation, and file removal.
2703 test_42a() {
2704         setup_test42
2705         cancel_lru_locks osc
2706         stop_writeback
2707         sync; sleep 1; sync # just to be safe
2708         BEFOREWRITES=`count_ost_writes`
2709         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
2710         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
2711         AFTERWRITES=`count_ost_writes`
2712         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
2713                 error "$BEFOREWRITES < $AFTERWRITES"
2714         start_writeback
2715 }
2716 run_test 42a "ensure that we don't flush on close =============="
2717
2718 test_42b() {
2719         setup_test42
2720         cancel_lru_locks osc
2721         stop_writeback
2722         sync
2723         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
2724         BEFOREWRITES=`count_ost_writes`
2725         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
2726         AFTERWRITES=`count_ost_writes`
2727         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
2728                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
2729         fi
2730         BEFOREWRITES=`count_ost_writes`
2731         sync || error "sync: $?"
2732         AFTERWRITES=`count_ost_writes`
2733         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
2734                 error "$BEFOREWRITES < $AFTERWRITES on sync"
2735         fi
2736         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
2737         start_writeback
2738         return 0
2739 }
2740 run_test 42b "test destroy of file with cached dirty data ======"
2741
2742 # if these tests just want to test the effect of truncation,
2743 # they have to be very careful.  consider:
2744 # - the first open gets a {0,EOF}PR lock
2745 # - the first write conflicts and gets a {0, count-1}PW
2746 # - the rest of the writes are under {count,EOF}PW
2747 # - the open for truncate tries to match a {0,EOF}PR
2748 #   for the filesize and cancels the PWs.
2749 # any number of fixes (don't get {0,EOF} on open, match
2750 # composite locks, do smarter file size management) fix
2751 # this, but for now we want these tests to verify that
2752 # the cancellation with truncate intent works, so we
2753 # start the file with a full-file pw lock to match against
2754 # until the truncate.
2755 trunc_test() {
2756         test=$1
2757         file=$DIR/$test
2758         offset=$2
2759         cancel_lru_locks osc
2760         stop_writeback
2761         # prime the file with 0,EOF PW to match
2762         touch $file
2763         $TRUNCATE $file 0
2764         sync; sync
2765         # now the real test..
2766         dd if=/dev/zero of=$file bs=1024 count=100
2767         BEFOREWRITES=`count_ost_writes`
2768         $TRUNCATE $file $offset
2769         cancel_lru_locks osc
2770         AFTERWRITES=`count_ost_writes`
2771         start_writeback
2772 }
2773
2774 test_42c() {
2775         trunc_test 42c 1024
2776         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
2777             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
2778         rm $file
2779 }
2780 run_test 42c "test partial truncate of file with cached dirty data"
2781
2782 test_42d() {
2783         trunc_test 42d 0
2784         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
2785             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
2786         rm $file
2787 }
2788 run_test 42d "test complete truncate of file with cached dirty data"
2789
2790 test_42e() { # bug22074
2791         local TDIR=$DIR/${tdir}e
2792         local pagesz=$(page_size)
2793         local pages=16 # hardcoded 16 pages, don't change it.
2794         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
2795         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
2796         local max_dirty_mb
2797         local warmup_files
2798
2799         mkdir -p $TDIR
2800         $SETSTRIPE -c 1 $TDIR
2801         createmany -o $TDIR/f $files
2802
2803         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
2804
2805         # we assume that with $OSTCOUNT files, at least one of them will
2806         # be allocated on OST0.
2807         warmup_files=$((OSTCOUNT * max_dirty_mb))
2808         createmany -o $TDIR/w $warmup_files
2809
2810         # write a large amount of data into one file and sync, to get good
2811         # avail_grant number from OST.
2812         for ((i=0; i<$warmup_files; i++)); do
2813                 idx=$($GETSTRIPE -i $TDIR/w$i)
2814                 [ $idx -ne 0 ] && continue
2815                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
2816                 break
2817         done
2818         [ $i -gt $warmup_files ] && error "OST0 is still cold"
2819         sync
2820         $LCTL get_param $proc_osc0/cur_dirty_bytes
2821         $LCTL get_param $proc_osc0/cur_grant_bytes
2822
2823         # create as much dirty pages as we can while not to trigger the actual
2824         # RPCs directly. but depends on the env, VFS may trigger flush during this
2825         # period, hopefully we are good.
2826         for ((i=0; i<$warmup_files; i++)); do
2827                 idx=$($GETSTRIPE -i $TDIR/w$i)
2828                 [ $idx -ne 0 ] && continue
2829                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
2830         done
2831         $LCTL get_param $proc_osc0/cur_dirty_bytes
2832         $LCTL get_param $proc_osc0/cur_grant_bytes
2833
2834         # perform the real test
2835         $LCTL set_param $proc_osc0/rpc_stats 0
2836         for ((;i<$files; i++)); do
2837                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
2838                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
2839         done
2840         sync
2841         $LCTL get_param $proc_osc0/rpc_stats
2842
2843         local percent=0
2844         local have_ppr=false
2845         $LCTL get_param $proc_osc0/rpc_stats |
2846                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
2847                         # skip lines until we are at the RPC histogram data
2848                         [ "$PPR" == "pages" ] && have_ppr=true && continue
2849                         $have_ppr || continue
2850
2851                         # we only want the percent stat for < 16 pages
2852                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
2853
2854                         percent=$((percent + WPCT))
2855                         if [ $percent -gt 15 ]; then
2856                                 error "less than 16-pages write RPCs" \
2857                                       "$percent% > 15%"
2858                                 break
2859                         fi
2860                 done
2861         rm -rf $TDIR
2862 }
2863 run_test 42e "verify sub-RPC writes are not done synchronously"
2864
2865 test_43() {
2866         mkdir -p $DIR/$tdir
2867         cp -p /bin/ls $DIR/$tdir/$tfile
2868         $MULTIOP $DIR/$tdir/$tfile Ow_c &
2869         pid=$!
2870         # give multiop a chance to open
2871         sleep 1
2872
2873         $DIR/$tdir/$tfile && error || true
2874         kill -USR1 $pid
2875 }
2876 run_test 43 "execution of file opened for write should return -ETXTBSY"
2877
2878 test_43a() {
2879         mkdir -p $DIR/d43
2880         cp -p `which $MULTIOP` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2881         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2882         MULTIOP_PID=$!
2883         $MULTIOP $DIR/d43/multiop Oc && error "expected error, got success"
2884         kill -USR1 $MULTIOP_PID || return 2
2885         wait $MULTIOP_PID || return 3
2886         rm $TMP/test43.junk
2887 }
2888 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
2889
2890 test_43b() {
2891         mkdir -p $DIR/d43
2892         cp -p `which $MULTIOP` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
2893         MULTIOP_PROG=$DIR/d43/multiop multiop_bg_pause $TMP/test43.junk O_c || return 1
2894         MULTIOP_PID=$!
2895         $TRUNCATE $DIR/d43/multiop 0 && error "expected error, got success"
2896         kill -USR1 $MULTIOP_PID || return 2
2897         wait $MULTIOP_PID || return 3
2898         rm $TMP/test43.junk
2899 }
2900 run_test 43b "truncate of file being executed should return -ETXTBSY"
2901
2902 test_43c() {
2903         local testdir="$DIR/d43c"
2904         mkdir -p $testdir
2905         cp $SHELL $testdir/
2906         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
2907                 ( cd $testdir && md5sum -c)
2908 }
2909 run_test 43c "md5sum of copy into lustre========================"
2910
2911 test_44() {
2912         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
2913         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
2914         dd if=$DIR/f1 bs=4k count=1 > /dev/null
2915 }
2916 run_test 44 "zero length read from a sparse stripe ============="
2917
2918 test_44a() {
2919     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
2920                          awk '{print $2}'`
2921     [ -z "$nstripe" ] && skip "can't get stripe info" && return
2922     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
2923     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
2924                       awk '{print $2}'`
2925     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
2926         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
2927     fi
2928
2929     OFFSETS="0 $((stride/2)) $((stride-1))"
2930     for offset in $OFFSETS ; do
2931       for i in `seq 0 $((nstripe-1))`; do
2932         local GLOBALOFFSETS=""
2933         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
2934         local myfn=$DIR/d44a-$size
2935         echo "--------writing $myfn at $size"
2936         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
2937         GLOBALOFFSETS="$GLOBALOFFSETS $size"
2938         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2939                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2940
2941         for j in `seq 0 $((nstripe-1))`; do
2942             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
2943             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
2944             GLOBALOFFSETS="$GLOBALOFFSETS $size"
2945         done
2946         ll_sparseness_verify $myfn $GLOBALOFFSETS \
2947                             || error "ll_sparseness_verify $GLOBALOFFSETS"
2948         rm -f $myfn
2949       done
2950     done
2951 }
2952 run_test 44a "test sparse pwrite ==============================="
2953
2954 dirty_osc_total() {
2955         tot=0
2956         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
2957                 tot=$(($tot + $d))
2958         done
2959         echo $tot
2960 }
2961 do_dirty_record() {
2962         before=`dirty_osc_total`
2963         echo executing "\"$*\""
2964         eval $*
2965         after=`dirty_osc_total`
2966         echo before $before, after $after
2967 }
2968 test_45() {
2969         f="$DIR/f45"
2970         # Obtain grants from OST if it supports it
2971         echo blah > ${f}_grant
2972         stop_writeback
2973         sync
2974         do_dirty_record "echo blah > $f"
2975         [ $before -eq $after ] && error "write wasn't cached"
2976         do_dirty_record "> $f"
2977         [ $before -gt $after ] || error "truncate didn't lower dirty count"
2978         do_dirty_record "echo blah > $f"
2979         [ $before -eq $after ] && error "write wasn't cached"
2980         do_dirty_record "sync"
2981         [ $before -gt $after ] || error "writeback didn't lower dirty count"
2982         do_dirty_record "echo blah > $f"
2983         [ $before -eq $after ] && error "write wasn't cached"
2984         do_dirty_record "cancel_lru_locks osc"
2985         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
2986         start_writeback
2987 }
2988 run_test 45 "osc io page accounting ============================"
2989
2990 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
2991 # test tickles a bug where re-dirtying a page was failing to be mapped to the
2992 # objects offset and an assert hit when an rpc was built with 1023's mapped
2993 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
2994 test_46() {
2995         f="$DIR/f46"
2996         stop_writeback
2997         sync
2998         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
2999         sync
3000         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3001         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3002         sync
3003         start_writeback
3004 }
3005 run_test 46 "dirtying a previously written page ================"
3006
3007 # test_47 is removed "Device nodes check" is moved to test_28
3008
3009 test_48a() { # bug 2399
3010         check_kernel_version 34 || return 0
3011         mkdir -p $DIR/d48a
3012         cd $DIR/d48a
3013         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
3014         mkdir $DIR/d48a || error "recreate directory failed"
3015         touch foo || error "'touch foo' failed after recreating cwd"
3016         mkdir bar || error "'mkdir foo' failed after recreating cwd"
3017         if check_kernel_version 44; then
3018                 touch .foo || error "'touch .foo' failed after recreating cwd"
3019                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3020         fi
3021         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3022         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3023         cd . || error "'cd .' failed after recreating cwd"
3024         mkdir . && error "'mkdir .' worked after recreating cwd"
3025         rmdir . && error "'rmdir .' worked after recreating cwd"
3026         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3027         cd .. || error "'cd ..' failed after recreating cwd"
3028 }
3029 run_test 48a "Access renamed working dir (should return errors)="
3030
3031 test_48b() { # bug 2399
3032         check_kernel_version 34 || return 0
3033         mkdir -p $DIR/d48b
3034         cd $DIR/d48b
3035         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
3036         touch foo && error "'touch foo' worked after removing cwd"
3037         mkdir foo && error "'mkdir foo' worked after removing cwd"
3038         if check_kernel_version 44; then
3039                 touch .foo && error "'touch .foo' worked after removing cwd"
3040                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3041         fi
3042         ls . > /dev/null && error "'ls .' worked after removing cwd"
3043         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3044         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3045         mkdir . && error "'mkdir .' worked after removing cwd"
3046         rmdir . && error "'rmdir .' worked after removing cwd"
3047         ln -s . foo && error "'ln -s .' worked after removing cwd"
3048         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3049 }
3050 run_test 48b "Access removed working dir (should return errors)="
3051
3052 test_48c() { # bug 2350
3053         check_kernel_version 36 || return 0
3054         #lctl set_param debug=-1
3055         #set -vx
3056         mkdir -p $DIR/d48c/dir
3057         cd $DIR/d48c/dir
3058         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
3059         $TRACE touch foo && error "'touch foo' worked after removing cwd"
3060         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
3061         if check_kernel_version 44; then
3062                 touch .foo && error "'touch .foo' worked after removing cwd"
3063                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3064         fi
3065         $TRACE ls . && error "'ls .' worked after removing cwd"
3066         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3067         is_patchless || ( $TRACE cd . && error "'cd .' worked after removing cwd" )
3068         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
3069         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3070         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3071         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3072 }
3073 run_test 48c "Access removed working subdir (should return errors)"
3074
3075 test_48d() { # bug 2350
3076         check_kernel_version 36 || return 0
3077         #lctl set_param debug=-1
3078         #set -vx
3079         mkdir -p $DIR/d48d/dir
3080         cd $DIR/d48d/dir
3081         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
3082         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
3083         $TRACE touch foo && error "'touch foo' worked after removing parent"
3084         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
3085         if check_kernel_version 44; then
3086                 touch .foo && error "'touch .foo' worked after removing parent"
3087                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
3088         fi
3089         $TRACE ls . && error "'ls .' worked after removing parent"
3090         $TRACE ls .. && error "'ls ..' worked after removing parent"
3091         is_patchless || ( $TRACE cd . && error "'cd .' worked after recreate parent" )
3092         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
3093         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3094         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3095         is_patchless || ( $TRACE cd .. && error "'cd ..' worked after removing parent" || true )
3096 }
3097 run_test 48d "Access removed parent subdir (should return errors)"
3098
3099 test_48e() { # bug 4134
3100         check_kernel_version 41 || return 0
3101         #lctl set_param debug=-1
3102         #set -vx
3103         mkdir -p $DIR/d48e/dir
3104         cd $DIR/d48e/dir
3105         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
3106         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
3107         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
3108         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
3109         # On a buggy kernel addition of "touch foo" after cd .. will
3110         # produce kernel oops in lookup_hash_it
3111         touch ../foo && error "'cd ..' worked after recreate parent"
3112         cd $DIR
3113         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
3114 }
3115 run_test 48e "Access to recreated parent subdir (should return errors)"
3116
3117 test_49() { # LU-1030
3118         # get ost1 size - lustre-OST0000
3119         ost1_size=$(do_facet ost1 lfs df |grep ${ost1_svc} |awk '{print $4}')
3120         # write 800M at maximum
3121         [ $ost1_size -gt 819200 ] && ost1_size=819200
3122
3123         lfs setstripe -c 1 -i 0 $DIR/$tfile
3124         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3125         local dd_pid=$!
3126
3127         # change max_pages_per_rpc while writing the file
3128         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3129         local orig_mppc=`$LCTL get_param -n $osc1_mppc`
3130         # loop until dd process exits
3131         while ps ax -opid | grep -wq $dd_pid; do
3132                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3133                 sleep $((RANDOM % 5 + 1))
3134         done
3135         # restore original max_pages_per_rpc
3136         $LCTL set_param $osc1_mppc=$orig_mppc
3137         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3138 }
3139 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3140
3141 test_50() {
3142         # bug 1485
3143         mkdir $DIR/d50
3144         cd $DIR/d50
3145         ls /proc/$$/cwd || error
3146 }
3147 run_test 50 "special situations: /proc symlinks  ==============="
3148
3149 test_51a() {    # was test_51
3150         # bug 1516 - create an empty entry right after ".." then split dir
3151         mkdir $DIR/d51
3152         touch $DIR/d51/foo
3153         $MCREATE $DIR/d51/bar
3154         rm $DIR/d51/foo
3155         createmany -m $DIR/d51/longfile 201
3156         FNUM=202
3157         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
3158                 $MCREATE $DIR/d51/longfile$FNUM
3159                 FNUM=$(($FNUM + 1))
3160                 echo -n "+"
3161         done
3162         echo
3163         ls -l $DIR/d51 > /dev/null || error
3164 }
3165 run_test 51a "special situations: split htree with empty entry =="
3166
3167 export NUMTEST=70000
3168 test_51b() {
3169         local BASE=$DIR/$tdir
3170         mkdir -p $BASE
3171
3172         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3173         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3174         [ $numfree -lt 21000 ] && skip "not enough free inodes ($numfree)" &&
3175                 return
3176
3177         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3178                 echo "reduced count to $NUMTEST due to inodes"
3179
3180         # need to check free space for the directories as well
3181         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3182         numfree=$((blkfree / 4))
3183         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3184                 echo "reduced count to $NUMTEST due to blocks"
3185
3186         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3187                 echo "failed" > $BASE/fnum
3188 }
3189 run_test 51b "exceed 64k subdirectory nlink limit"
3190
3191 test_51ba() { # LU-993
3192         local BASE=$DIR/$tdir
3193         # unlink all but 100 subdirectories, then check it still works
3194         local LEFT=100
3195         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3196
3197         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3198         local DELETE=$((NUMTEST - LEFT))
3199
3200         # continue on to run this test even if 51b didn't finish,
3201         # just to delete the many subdirectories created.
3202         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3203
3204         # for ldiskfs the nlink count should be 1, but this is OSD specific
3205         # and so this is listed for informational purposes only
3206         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3207         unlinkmany -d $BASE/d $DELETE
3208         RC=$?
3209
3210         if [ $RC -ne 0 ]; then
3211                 if [ "$NUMPREV" == "failed" ]; then
3212                         skip "previous setup failed"
3213                         return 0
3214                 else
3215                         error "unlink of first $DELETE subdirs failed"
3216                         return $RC
3217                 fi
3218         fi
3219
3220         echo "nlink between: $(stat -c %h $BASE)"
3221         # trim the first line of ls output
3222         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3223         [ $FOUND -ne $LEFT ] &&
3224                 error "can't find subdirs: found only $FOUND/$LEFT"
3225
3226         unlinkmany -d $BASE/d $DELETE $LEFT ||
3227                 error "unlink of second $LEFT subdirs failed"
3228         # regardless of whether the backing filesystem tracks nlink accurately
3229         # or not, the nlink count shouldn't be more than "." and ".." here
3230         local AFTER=$(stat -c %h $BASE)
3231         [ $AFTER -gt 2 ] && error "nlink after: $AFTER > 2" ||
3232                 echo "nlink after: $AFTER"
3233 }
3234 run_test 51ba "verify nlink for many subdirectory cleanup"
3235
3236 test_51bb() {
3237         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3238
3239         local ndirs=${TEST51BB_NDIRS:-10}
3240         local nfiles=${TEST51BB_NFILES:-100}
3241
3242         local numfree=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3243
3244         [ $numfree -lt $(( ndirs * nfiles)) ] && \
3245                 nfiles=$(( numfree / ndirs - 10 ))
3246
3247         local dir=$DIR/d51bb
3248         mkdir -p $dir
3249         local savePOLICY=$(lctl get_param -n lmv.*.placement)
3250         lctl set_param -n lmv.*.placement=CHAR
3251
3252         lfs df -i $dir
3253         local IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3254         OLDUSED=($IUSED)
3255
3256         declare -a dirs
3257         for ((i=0; i < $ndirs; i++)); do
3258                 dirs[i]=$dir/$RANDOM
3259                 echo Creating directory ${dirs[i]}
3260                 mkdir -p ${dirs[i]}
3261                 ls $dir
3262                 echo Creating $nfiles in dir ${dirs[i]} ...
3263                 echo "createmany -o ${dirs[i]}/$tfile- $nfiles"
3264                 createmany -o ${dirs[i]}/$tfile- $nfiles
3265         done
3266         ls $dir
3267
3268         sleep 1
3269
3270         IUSED=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3271         NEWUSED=($IUSED)
3272
3273         local rc=0
3274         for ((i=0; i<${#NEWUSED[@]}; i++)); do
3275                 echo "mds $i: inodes count OLD ${OLDUSED[$i]} NEW ${NEWUSED[$i]}"
3276                 [ ${OLDUSED[$i]} -lt ${NEWUSED[$i]} ] || rc=$((rc + 1))
3277         done
3278
3279         lctl set_param -n lmv.*.placement=$savePOLICY
3280
3281         [ $rc -ne $MDSCOUNT ] || \
3282                 error "Objects/inodes are not distributed over all mds servers"
3283 }
3284 run_test 51bb "mkdir createmany CMD $MDSCOUNT  ===================="
3285
3286 test_51d() {
3287         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3288         mkdir -p $DIR/d51d
3289         createmany -o $DIR/d51d/t- 1000
3290         $GETSTRIPE $DIR/d51d > $TMP/files
3291         for N in `seq 0 $((OSTCOUNT - 1))`; do
3292             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3293             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3294             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3295         done
3296         unlinkmany $DIR/d51d/t- 1000
3297
3298         NLAST=0
3299         for N in `seq 1 $((OSTCOUNT - 1))`; do
3300             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3301                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3302             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3303                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3304
3305             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3306                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3307             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3308                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3309             NLAST=$N
3310         done
3311 }
3312 run_test 51d "check object distribution ===================="
3313
3314 test_52a() {
3315         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
3316         mkdir -p $DIR/d52a
3317         touch $DIR/d52a/foo
3318         chattr +a $DIR/d52a/foo || error "chattr +a failed"
3319         echo bar >> $DIR/d52a/foo || error "append bar failed"
3320         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
3321         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
3322         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
3323         echo foo >> $DIR/d52a/foo || error "append foo failed"
3324         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
3325         lsattr $DIR/d52a/foo | egrep -q "^-+a[-e]+ $DIR/d52a/foo" || error "lsattr"
3326         chattr -a $DIR/d52a/foo || error "chattr -a failed"
3327         cp -r $DIR/d52a /tmp/
3328         rm -fr $DIR/d52a || error "cleanup rm failed"
3329 }
3330 run_test 52a "append-only flag test (should return errors) ====="
3331
3332 test_52b() {
3333         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
3334         mkdir -p $DIR/d52b
3335         touch $DIR/d52b/foo
3336         chattr +i $DIR/d52b/foo || error "chattr +i failed"
3337         cat test > $DIR/d52b/foo && error "cat test worked"
3338         cp /etc/hosts $DIR/d52b/foo && error "cp worked"
3339         rm -f $DIR/d52b/foo 2>/dev/null && error "rm worked"
3340         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error  "link worked"
3341         echo foo >> $DIR/d52b/foo && error "echo worked"
3342         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error "rename worked"
3343         [ -f $DIR/d52b/foo ] || error
3344         [ -f $DIR/d52b/foo_ren ] && error
3345         lsattr $DIR/d52b/foo | egrep -q "^-+i[-e]+ $DIR/d52b/foo" || error "lsattr"
3346         chattr -i $DIR/d52b/foo || error "chattr failed"
3347
3348         rm -fr $DIR/d52b || error
3349 }
3350 run_test 52b "immutable flag test (should return errors) ======="
3351
3352 test_53() {
3353         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3354         remote_ost_nodsh && skip "remote OST with nodsh" && return
3355
3356         local param
3357         local ostname
3358         local mds_last
3359         local ost_last
3360         local ostnum
3361
3362         # only test MDT0000
3363         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3364         for value in $(do_facet $SINGLEMDS lctl get_param osc.$mdtosc.prealloc_last_id) ; do
3365                 param=`echo ${value[0]} | cut -d "=" -f1`
3366                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
3367                 mds_last=$(do_facet $SINGLEMDS lctl get_param -n $param)
3368                 ostnum=$(echo $ostname | sed "s/${FSNAME}-OST//g" | awk '{print ($1+1)}' )
3369                 ost_last=$(do_facet ost$ostnum lctl get_param -n obdfilter.$ostname.last_id | head -n 1)
3370                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3371                 if [ $ost_last != $mds_last ]; then
3372                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3373                 fi
3374         done
3375 }
3376 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
3377
3378 test_54a() {
3379         [ ! -f "$SOCKETSERVER" ] && skip_env "no socketserver, skipping" && return
3380         [ ! -f "$SOCKETCLIENT" ] && skip_env "no socketclient, skipping" && return
3381         $SOCKETSERVER $DIR/socket
3382         $SOCKETCLIENT $DIR/socket || error
3383         $MUNLINK $DIR/socket
3384 }
3385 run_test 54a "unix domain socket test =========================="
3386
3387 test_54b() {
3388         f="$DIR/f54b"
3389         mknod $f c 1 3
3390         chmod 0666 $f
3391         dd if=/dev/zero of=$f bs=`page_size` count=1
3392 }
3393 run_test 54b "char device works in lustre ======================"
3394
3395 find_loop_dev() {
3396         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
3397         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
3398         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
3399
3400         for i in `seq 3 7`; do
3401                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
3402                 LOOPDEV=$LOOPBASE$i
3403                 LOOPNUM=$i
3404                 break
3405         done
3406 }
3407
3408 test_54c() {
3409         tfile="$DIR/f54c"
3410         tdir="$DIR/d54c"
3411         loopdev="$DIR/loop54c"
3412
3413         find_loop_dev
3414         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
3415         mknod $loopdev b 7 $LOOPNUM
3416         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
3417         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
3418         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
3419         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
3420         mkdir -p $tdir
3421         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
3422         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
3423         df $tdir
3424         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
3425         $UMOUNT $tdir
3426         losetup -d $loopdev
3427         rm $loopdev
3428 }
3429 run_test 54c "block device works in lustre ====================="
3430
3431 test_54d() {
3432         f="$DIR/f54d"
3433         string="aaaaaa"
3434         mknod $f p
3435         [ "$string" = `echo $string > $f | cat $f` ] || error
3436 }
3437 run_test 54d "fifo device works in lustre ======================"
3438
3439 test_54e() {
3440         check_kernel_version 46 || return 0
3441         f="$DIR/f54e"
3442         string="aaaaaa"
3443         cp -aL /dev/console $f
3444         echo $string > $f || error
3445 }
3446 run_test 54e "console/tty device works in lustre ======================"
3447
3448 #The test_55 used to be iopen test and it was removed by bz#24037.
3449 #run_test 55 "check iopen_connect_dentry() ======================"
3450
3451 test_56a() {    # was test_56
3452         rm -rf $DIR/d56
3453         $SETSTRIPE -d $DIR
3454         mkdir $DIR/d56
3455         mkdir $DIR/d56/dir
3456         NUMFILES=3
3457         NUMFILESx2=$(($NUMFILES * 2))
3458         for i in `seq 1 $NUMFILES` ; do
3459                 touch $DIR/d56/file$i
3460                 touch $DIR/d56/dir/file$i
3461         done
3462
3463         # test lfs getstripe with --recursive
3464         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
3465         [ $FILENUM -eq $NUMFILESx2 ] ||
3466                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
3467         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
3468         [ $FILENUM -eq $NUMFILES ] ||
3469                 error "$GETSTRIPE $DIR/d56: found $FILENUM, not $NUMFILES"
3470         echo "$GETSTRIPE --recursive passed."
3471
3472         # test lfs getstripe with file instead of dir
3473         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
3474         [ $FILENUM  -eq 1 ] || error \
3475                  "$GETSTRIPE $DIR/d56/file1: found $FILENUM, not 1"
3476         echo "$GETSTRIPE file1 passed."
3477
3478         #test lfs getstripe with --verbose
3479         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||
3480                 error "$GETSTRIPE --verbose $DIR/d56: want $NUMFILES lmm_magic"
3481         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] ||
3482             error "$GETSTRIPE $DIR/d56: showed lmm_magic"
3483         echo "$GETSTRIPE --verbose passed."
3484
3485         #test lfs getstripe with --obd
3486         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" ||
3487                 error "$GETSTRIPE --obd wrong_uuid should return error message"
3488
3489         [  "$OSTCOUNT" -lt 2 ] &&
3490                 skip_env "skipping other $GETSTRIPE --obd test" && return
3491
3492         OSTIDX=1
3493         OBDUUID=$(ostuuid_from_index $OSTIDX)
3494         FILENUM=`$GETSTRIPE -ir $DIR/d56 | grep -x $OSTIDX | wc -l`
3495         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | grep obdidx | wc -l`
3496         [ $FOUND -eq $FILENUM ] ||
3497                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
3498         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 |
3499                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
3500                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
3501                 error "$GETSTRIPE --obd: should not show file on other obd"
3502         echo "$GETSTRIPE --obd passed"
3503 }
3504 run_test 56a "check $GETSTRIPE"
3505
3506 NUMFILES=3
3507 NUMDIRS=3
3508 setup_56() {
3509         local LOCAL_NUMFILES="$1"
3510         local LOCAL_NUMDIRS="$2"
3511         local MKDIR_PARAMS="$3"
3512
3513         if [ ! -d "$TDIR" ] ; then
3514                 mkdir -p $TDIR
3515                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
3516                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3517                         touch $TDIR/file$i
3518                 done
3519                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3520                         mkdir $TDIR/dir$i
3521                         for j in `seq 1 $LOCAL_NUMFILES` ; do
3522                                 touch $TDIR/dir$i/file$j
3523                         done
3524                 done
3525         fi
3526 }
3527
3528 setup_56_special() {
3529         LOCAL_NUMFILES=$1
3530         LOCAL_NUMDIRS=$2
3531         setup_56 $1 $2
3532         if [ ! -e "$TDIR/loop1b" ] ; then
3533                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3534                         mknod $TDIR/loop${i}b b 7 $i
3535                         mknod $TDIR/null${i}c c 1 3
3536                         ln -s $TDIR/file1 $TDIR/link${i}l
3537                 done
3538                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3539                         mknod $TDIR/dir$i/loop${i}b b 7 $i
3540                         mknod $TDIR/dir$i/null${i}c c 1 3
3541                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
3542                 done
3543         fi
3544 }
3545
3546 test_56g() {
3547         $SETSTRIPE -d $DIR
3548
3549         TDIR=$DIR/${tdir}g
3550         setup_56 $NUMFILES $NUMDIRS
3551
3552         EXPECTED=$(($NUMDIRS + 2))
3553         # test lfs find with -name
3554         for i in $(seq 1 $NUMFILES) ; do
3555                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
3556                 [ $NUMS -eq $EXPECTED ] ||
3557                         error "lfs find -name \"*$i\" $TDIR wrong: "\
3558                               "found $NUMS, expected $EXPECTED"
3559         done
3560 }
3561 run_test 56g "check lfs find -name ============================="
3562
3563 test_56h() {
3564         $SETSTRIPE -d $DIR
3565
3566         TDIR=$DIR/${tdir}g
3567         setup_56 $NUMFILES $NUMDIRS
3568
3569         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
3570         # test lfs find with ! -name
3571         for i in $(seq 1 $NUMFILES) ; do
3572                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
3573                 [ $NUMS -eq $EXPECTED ] ||
3574                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
3575                               "found $NUMS, expected $EXPECTED"
3576         done
3577 }
3578 run_test 56h "check lfs find ! -name ============================="
3579
3580 test_56i() {
3581        tdir=${tdir}i
3582        mkdir -p $DIR/$tdir
3583        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
3584        CMD="$LFIND -ost $UUID $DIR/$tdir"
3585        OUT=$($CMD)
3586        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
3587 }
3588 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
3589
3590 test_56j() {
3591         TDIR=$DIR/${tdir}g
3592         setup_56_special $NUMFILES $NUMDIRS
3593
3594         EXPECTED=$((NUMDIRS + 1))
3595         CMD="$LFIND -type d $TDIR"
3596         NUMS=$($CMD | wc -l)
3597         [ $NUMS -eq $EXPECTED ] ||
3598                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3599 }
3600 run_test 56j "check lfs find -type d ============================="
3601
3602 test_56k() {
3603         TDIR=$DIR/${tdir}g
3604         setup_56_special $NUMFILES $NUMDIRS
3605
3606         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3607         CMD="$LFIND -type f $TDIR"
3608         NUMS=$($CMD | wc -l)
3609         [ $NUMS -eq $EXPECTED ] ||
3610                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3611 }
3612 run_test 56k "check lfs find -type f ============================="
3613
3614 test_56l() {
3615         TDIR=$DIR/${tdir}g
3616         setup_56_special $NUMFILES $NUMDIRS
3617
3618         EXPECTED=$((NUMDIRS + NUMFILES))
3619         CMD="$LFIND -type b $TDIR"
3620         NUMS=$($CMD | wc -l)
3621         [ $NUMS -eq $EXPECTED ] ||
3622                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3623 }
3624 run_test 56l "check lfs find -type b ============================="
3625
3626 test_56m() {
3627         TDIR=$DIR/${tdir}g
3628         setup_56_special $NUMFILES $NUMDIRS
3629
3630         EXPECTED=$((NUMDIRS + NUMFILES))
3631         CMD="$LFIND -type c $TDIR"
3632         NUMS=$($CMD | wc -l)
3633         [ $NUMS -eq $EXPECTED ] ||
3634                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3635 }
3636 run_test 56m "check lfs find -type c ============================="
3637
3638 test_56n() {
3639         TDIR=$DIR/${tdir}g
3640         setup_56_special $NUMFILES $NUMDIRS
3641
3642         EXPECTED=$((NUMDIRS + NUMFILES))
3643         CMD="$LFIND -type l $TDIR"
3644         NUMS=$($CMD | wc -l)
3645         [ $NUMS -eq $EXPECTED ] ||
3646                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3647 }
3648 run_test 56n "check lfs find -type l ============================="
3649
3650 test_56o() {
3651         TDIR=$DIR/${tdir}o
3652         setup_56 $NUMFILES $NUMDIRS
3653
3654         utime $TDIR/file1 > /dev/null || error "utime (1)"
3655         utime $TDIR/file2 > /dev/null || error "utime (2)"
3656         utime $TDIR/dir1 > /dev/null || error "utime (3)"
3657         utime $TDIR/dir2 > /dev/null || error "utime (4)"
3658         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
3659         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
3660
3661         EXPECTED=4
3662         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
3663         [ $NUMS -eq $EXPECTED ] || \
3664                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
3665
3666         EXPECTED=12
3667         CMD="$LFIND -mtime 0 $TDIR"
3668         NUMS=$($CMD | wc -l)
3669         [ $NUMS -eq $EXPECTED ] ||
3670                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3671 }
3672 run_test 56o "check lfs find -mtime for old files =========================="
3673
3674 test_56p() {
3675         [ $RUNAS_ID -eq $UID ] &&
3676                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3677
3678         TDIR=$DIR/${tdir}p
3679         setup_56 $NUMFILES $NUMDIRS
3680
3681         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
3682         EXPECTED=$NUMFILES
3683         CMD="$LFIND -uid $RUNAS_ID $TDIR"
3684         NUMS=$($CMD | wc -l)
3685         [ $NUMS -eq $EXPECTED ] || \
3686                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3687
3688         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
3689         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
3690         NUMS=$($CMD | wc -l)
3691         [ $NUMS -eq $EXPECTED ] || \
3692                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3693 }
3694 run_test 56p "check lfs find -uid and ! -uid ==============================="
3695
3696 test_56q() {
3697         [ $RUNAS_ID -eq $UID ] &&
3698                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3699
3700         TDIR=$DIR/${tdir}q
3701         setup_56 $NUMFILES $NUMDIRS
3702
3703         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
3704
3705         EXPECTED=$NUMFILES
3706         CMD="$LFIND -gid $RUNAS_GID $TDIR"
3707         NUMS=$($CMD | wc -l)
3708         [ $NUMS -eq $EXPECTED ] ||
3709                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3710
3711         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
3712         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
3713         NUMS=$($CMD | wc -l)
3714         [ $NUMS -eq $EXPECTED ] ||
3715                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3716 }
3717 run_test 56q "check lfs find -gid and ! -gid ==============================="
3718
3719 test_56r() {
3720         TDIR=$DIR/${tdir}r
3721         setup_56 $NUMFILES $NUMDIRS
3722
3723         EXPECTED=12
3724         CMD="$LFIND -size 0 -type f $TDIR"
3725         NUMS=$($CMD | wc -l)
3726         [ $NUMS -eq $EXPECTED ] ||
3727                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3728         EXPECTED=0
3729         CMD="$LFIND ! -size 0 -type f $TDIR"
3730         NUMS=$($CMD | wc -l)
3731         [ $NUMS -eq $EXPECTED ] ||
3732                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3733         echo "test" > $TDIR/$tfile
3734         echo "test2" > $TDIR/$tfile.2 && sync
3735         EXPECTED=1
3736         CMD="$LFIND -size 5 -type f $TDIR"
3737         NUMS=$($CMD | wc -l)
3738         [ $NUMS -eq $EXPECTED ] ||
3739                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3740         EXPECTED=1
3741         CMD="$LFIND -size +5 -type f $TDIR"
3742         NUMS=$($CMD | wc -l)
3743         [ $NUMS -eq $EXPECTED ] ||
3744                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3745         EXPECTED=2
3746         CMD="$LFIND -size +0 -type f $TDIR"
3747         NUMS=$($CMD | wc -l)
3748         [ $NUMS -eq $EXPECTED ] ||
3749                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3750         EXPECTED=2
3751         CMD="$LFIND ! -size -5 -type f $TDIR"
3752         NUMS=$($CMD | wc -l)
3753         [ $NUMS -eq $EXPECTED ] ||
3754                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3755         EXPECTED=12
3756         CMD="$LFIND -size -5 -type f $TDIR"
3757         NUMS=$($CMD | wc -l)
3758         [ $NUMS -eq $EXPECTED ] ||
3759                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3760 }
3761 run_test 56r "check lfs find -size works =========================="
3762
3763 test_56s() { # LU-611
3764         TDIR=$DIR/${tdir}s
3765         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
3766
3767         if [ $OSTCOUNT -gt 1 ]; then
3768                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
3769                 ONESTRIPE=4
3770                 EXTRA=4
3771         else
3772                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
3773                 EXTRA=0
3774         fi
3775
3776         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3777         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
3778         NUMS=$($CMD | wc -l)
3779         [ $NUMS -eq $EXPECTED ] ||
3780                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3781
3782         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
3783         CMD="$LFIND -stripe-count +0 -type f $TDIR"
3784         NUMS=$($CMD | wc -l)
3785         [ $NUMS -eq $EXPECTED ] ||
3786                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3787
3788         EXPECTED=$ONESTRIPE
3789         CMD="$LFIND -stripe-count 1 -type f $TDIR"
3790         NUMS=$($CMD | wc -l)
3791         [ $NUMS -eq $EXPECTED ] ||
3792                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3793
3794         CMD="$LFIND -stripe-count -2 -type f $TDIR"
3795         NUMS=$($CMD | wc -l)
3796         [ $NUMS -eq $EXPECTED ] ||
3797                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3798
3799         EXPECTED=0
3800         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
3801         NUMS=$($CMD | wc -l)
3802         [ $NUMS -eq $EXPECTED ] ||
3803                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3804 }
3805 run_test 56s "check lfs find -stripe-count works"
3806
3807 test_56t() { # LU-611
3808         TDIR=$DIR/${tdir}t
3809         setup_56 $NUMFILES $NUMDIRS "-s 512k"
3810
3811         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
3812
3813         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3814         CMD="$LFIND -stripe-size 512k -type f $TDIR"
3815         NUMS=$($CMD | wc -l)
3816         [ $NUMS -eq $EXPECTED ] ||
3817                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3818
3819         CMD="$LFIND -stripe-size +320k -type f $TDIR"
3820         NUMS=$($CMD | wc -l)
3821         [ $NUMS -eq $EXPECTED ] ||
3822                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3823
3824         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
3825         CMD="$LFIND -stripe-size +200k -type f $TDIR"
3826         NUMS=$($CMD | wc -l)
3827         [ $NUMS -eq $EXPECTED ] ||
3828                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3829
3830         CMD="$LFIND -stripe-size -640k -type f $TDIR"
3831         NUMS=$($CMD | wc -l)
3832         [ $NUMS -eq $EXPECTED ] ||
3833                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3834
3835         EXPECTED=4
3836         CMD="$LFIND -stripe-size 256k -type f $TDIR"
3837         NUMS=$($CMD | wc -l)
3838         [ $NUMS -eq $EXPECTED ] ||
3839                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3840
3841         CMD="$LFIND -stripe-size -320k -type f $TDIR"
3842         NUMS=$($CMD | wc -l)
3843         [ $NUMS -eq $EXPECTED ] ||
3844                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3845
3846         EXPECTED=0
3847         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
3848         NUMS=$($CMD | wc -l)
3849         [ $NUMS -eq $EXPECTED ] ||
3850                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3851 }
3852 run_test 56t "check lfs find -stripe-size works"
3853
3854 test_56u() { # LU-611
3855         TDIR=$DIR/${tdir}u
3856         setup_56 $NUMFILES $NUMDIRS "-i 0"
3857
3858         if [ $OSTCOUNT -gt 1 ]; then
3859                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
3860                 ONESTRIPE=4
3861         else
3862                 ONESTRIPE=0
3863         fi
3864
3865         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
3866         CMD="$LFIND -stripe-index 0 -type f $TDIR"
3867         NUMS=$($CMD | wc -l)
3868         [ $NUMS -eq $EXPECTED ] ||
3869                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3870
3871         EXPECTED=$ONESTRIPE
3872         CMD="$LFIND -stripe-index 1 -type f $TDIR"
3873         NUMS=$($CMD | wc -l)
3874         [ $NUMS -eq $EXPECTED ] ||
3875                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3876
3877         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
3878         NUMS=$($CMD | wc -l)
3879         [ $NUMS -eq $EXPECTED ] ||
3880                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3881
3882         EXPECTED=0
3883         # This should produce an error and not return any files
3884         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
3885         NUMS=$($CMD 2>/dev/null | wc -l)
3886         [ $NUMS -eq $EXPECTED ] ||
3887                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3888
3889         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
3890         CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
3891         NUMS=$($CMD | wc -l)
3892         [ $NUMS -eq $EXPECTED ] ||
3893                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3894 }
3895 run_test 56u "check lfs find -stripe-index works"
3896
3897 test_56v() {
3898     local MDT_IDX=0
3899
3900     TDIR=$DIR/${tdir}v
3901     rm -rf $TDIR
3902     setup_56 $NUMFILES $NUMDIRS
3903
3904     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
3905     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
3906
3907     for file in $($LFIND -mdt $UUID $TDIR); do
3908         file_mdt_idx=$($GETSTRIPE -M $file)
3909         [ $file_mdt_idx -eq $MDT_IDX ] ||
3910             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
3911     done
3912 }
3913 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
3914
3915 # Get and check the actual stripe count of one file.
3916 # Usage: check_stripe_count <file> <expected_stripe_count>
3917 check_stripe_count() {
3918     local file=$1
3919     local expected=$2
3920     local actual
3921
3922     [[ -z "$file" || -z "$expected" ]] &&
3923         error "check_stripe_count: invalid argument!"
3924
3925     local cmd="$GETSTRIPE -c $file"
3926     actual=$($cmd) || error "$cmd failed"
3927     actual=${actual%% *}
3928
3929     if [[ $actual -ne $expected ]]; then
3930         [[ $expected -eq -1 ]] ||
3931             error "$cmd wrong: found $actual, expected $expected"
3932         [[ $actual -eq $OSTCOUNT ]] ||
3933             error "$cmd wrong: found $actual, expected $OSTCOUNT"
3934     fi
3935 }
3936
3937 test_56w() {
3938     TDIR=$DIR/${tdir}w
3939
3940     rm -rf $TDIR || error "remove $TDIR failed"
3941     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
3942
3943     local stripe_size
3944     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
3945         error "$GETSTRIPE -S -d $TDIR failed"
3946     stripe_size=${stripe_size%% *}
3947
3948     local file_size=$((stripe_size * OSTCOUNT))
3949     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
3950     local required_space=$((file_num * file_size))
3951     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
3952     [[ $free_space -le $((required_space / 1024)) ]] &&
3953         skip_env "need at least $required_space bytes free space," \
3954                  "have $free_space kbytes" && return
3955
3956     local dd_bs=65536
3957     local dd_count=$((file_size / dd_bs))
3958
3959     # write data into the files
3960     local i
3961     local j
3962     local file
3963     for i in $(seq 1 $NUMFILES); do
3964         file=$TDIR/file$i
3965         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
3966             error "write data into $file failed"
3967     done
3968     for i in $(seq 1 $NUMDIRS); do
3969         for j in $(seq 1 $NUMFILES); do
3970             file=$TDIR/dir$i/file$j
3971             yes | dd bs=$dd_bs count=$dd_count of=$file \
3972                 >/dev/null 2>&1 ||
3973                 error "write data into $file failed"
3974         done
3975     done
3976
3977     local expected=-1
3978     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
3979
3980     # lfs_migrate file
3981     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
3982     echo "$cmd"
3983     eval $cmd || error "$cmd failed"
3984
3985     check_stripe_count $TDIR/file1 $expected
3986
3987     # lfs_migrate dir
3988     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
3989     echo "$cmd"
3990     eval $cmd || error "$cmd failed"
3991
3992     for j in $(seq 1 $NUMFILES); do
3993         check_stripe_count $TDIR/dir1/file$j $expected
3994     done
3995
3996     # lfs_migrate works with lfs find
3997     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
3998          $LFS_MIGRATE -y -c $expected"
3999     echo "$cmd"
4000     eval $cmd || error "$cmd failed"
4001
4002     for i in $(seq 2 $NUMFILES); do
4003         check_stripe_count $TDIR/file$i $expected
4004     done
4005     for i in $(seq 2 $NUMDIRS); do
4006         for j in $(seq 1 $NUMFILES); do
4007             check_stripe_count $TDIR/dir$i/file$j $expected
4008         done
4009     done
4010 }
4011 run_test 56w "check lfs_migrate -c stripe_count works"
4012
4013 test_57a() {
4014         # note test will not do anything if MDS is not local
4015         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4016                 skip "Only applicable to ldiskfs-based MDTs"
4017                 return
4018         fi
4019
4020         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4021         local MNTDEV="osd*.*MDT*.mntdev"
4022         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4023         [ -z "$DEV" ] && error "can't access $MNTDEV"
4024         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4025                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4026                         error "can't access $DEV"
4027                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
4028                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
4029                 rm $TMP/t57a.dump
4030         done
4031 }
4032 run_test 57a "verify MDS filesystem created with large inodes =="
4033
4034 test_57b() {
4035         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4036                 skip "Only applicable to ldiskfs-based MDTs"
4037                 return
4038         fi
4039
4040         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4041         local dir=$DIR/d57b
4042
4043         local FILECOUNT=100
4044         local FILE1=$dir/f1
4045         local FILEN=$dir/f$FILECOUNT
4046
4047         rm -rf $dir || error "removing $dir"
4048         mkdir -p $dir || error "creating $dir"
4049         local num=$(get_mds_dir $dir)
4050         local mymds=mds$num
4051
4052         echo "mcreating $FILECOUNT files"
4053         createmany -m $dir/f 1 $FILECOUNT || \
4054                 error "creating files in $dir"
4055
4056         # verify that files do not have EAs yet
4057         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4058         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4059
4060         sync
4061         sleep 1
4062         df $dir  #make sure we get new statfs data
4063         local MDSFREE=$(do_facet $mymds \
4064                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4065         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4066         echo "opening files to create objects/EAs"
4067         local FILE
4068         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4069                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4070         done
4071
4072         # verify that files have EAs now
4073         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4074         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4075
4076         sleep 1  #make sure we get new statfs data
4077         df $dir
4078         local MDSFREE2=$(do_facet $mymds \
4079                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4080         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4081         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
4082                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4083                         error "MDC before $MDCFREE != after $MDCFREE2"
4084                 else
4085                         echo "MDC before $MDCFREE != after $MDCFREE2"
4086                         echo "unable to confirm if MDS has large inodes"
4087                 fi
4088         fi
4089         rm -rf $dir
4090 }
4091 run_test 57b "default LOV EAs are stored inside large inodes ==="
4092
4093 test_58() {
4094     [ -z "$(which wiretest 2>/dev/null)" ] && skip_env "could not find wiretest" && return
4095     wiretest
4096 }
4097 run_test 58 "verify cross-platform wire constants =============="
4098
4099 test_59() {
4100         echo "touch 130 files"
4101         createmany -o $DIR/f59- 130
4102         echo "rm 130 files"
4103         unlinkmany $DIR/f59- 130
4104         sync
4105         sleep 2
4106         # wait for commitment of removal
4107 }
4108 run_test 59 "verify cancellation of llog records async ========="
4109
4110 TEST60_HEAD="test_60 run $RANDOM"
4111 test_60a() {
4112         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4113         [ ! -f run-llog.sh ] && skip_env "missing subtest run-llog.sh" && return
4114         log "$TEST60_HEAD - from kernel mode"
4115         do_facet mgs sh run-llog.sh
4116 }
4117 run_test 60a "llog sanity tests run from kernel module =========="
4118
4119 test_60b() { # bug 6411
4120         dmesg > $DIR/$tfile
4121         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4122                                  /llog.test/ {
4123                                          if (marker)
4124                                                  from_marker++
4125                                          from_begin++
4126                                  }
4127                                  END {
4128                                          if (marker)
4129                                                  print from_marker
4130                                          else
4131                                                  print from_begin
4132                                  }"`
4133         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
4134 }
4135 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4136
4137 test_60c() {
4138         echo "create 5000 files"
4139         createmany -o $DIR/f60c- 5000
4140 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4141         lctl set_param fail_loc=0x80000137
4142         unlinkmany $DIR/f60c- 5000
4143         lctl set_param fail_loc=0
4144 }
4145 run_test 60c "unlink file when mds full"
4146
4147 test_60d() {
4148         SAVEPRINTK=$(lctl get_param -n printk)
4149
4150         # verify "lctl mark" is even working"
4151         MESSAGE="test message ID $RANDOM $$"
4152         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4153         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4154
4155         lctl set_param printk=0 || error "set lnet.printk failed"
4156         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4157         MESSAGE="new test message ID $RANDOM $$"
4158         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4159         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4160         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4161
4162         lctl set_param -n printk="$SAVEPRINTK"
4163 }
4164 run_test 60d "test printk console message masking"
4165
4166 test_61() {
4167         f="$DIR/f61"
4168         dd if=/dev/zero of=$f bs=`page_size` count=1
4169         cancel_lru_locks osc
4170         $MULTIOP $f OSMWUc || error
4171         sync
4172 }
4173 run_test 61 "mmap() writes don't make sync hang ================"
4174
4175 # bug 2330 - insufficient obd_match error checking causes LBUG
4176 test_62() {
4177         f="$DIR/f62"
4178         echo foo > $f
4179         cancel_lru_locks osc
4180         lctl set_param fail_loc=0x405
4181         cat $f && error "cat succeeded, expect -EIO"
4182         lctl set_param fail_loc=0
4183 }
4184 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4185 # match every page all of the time.
4186 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4187
4188 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4189 test_63a() {    # was test_63
4190         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4191         lctl set_param -n osc.*.max_dirty_mb 0
4192         for i in `seq 10` ; do
4193                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4194                 sleep 5
4195                 kill $!
4196                 sleep 1
4197         done
4198
4199         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
4200         rm -f $DIR/f63 || true
4201 }
4202 run_test 63a "Verify oig_wait interruption does not crash ======="
4203
4204 # bug 2248 - async write errors didn't return to application on sync
4205 # bug 3677 - async write errors left page locked
4206 test_63b() {
4207         debugsave
4208         lctl set_param debug=-1
4209
4210         # ensure we have a grant to do async writes
4211         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4212         rm $DIR/$tfile
4213
4214         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4215         lctl set_param fail_loc=0x80000406
4216         $MULTIOP $DIR/$tfile Owy && \
4217                 error "sync didn't return ENOMEM"
4218         sync; sleep 2; sync     # do a real sync this time to flush page
4219         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4220                 error "locked page left in cache after async error" || true
4221         debugrestore
4222 }
4223 run_test 63b "async write errors should be returned to fsync ==="
4224
4225 test_64a () {
4226         df $DIR
4227         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4228 }
4229 run_test 64a "verify filter grant calculations (in kernel) ====="
4230
4231 test_64b () {
4232         [ ! -f oos.sh ] && skip_env "missing subtest oos.sh" && return
4233         sh oos.sh $MOUNT
4234 }
4235 run_test 64b "check out-of-space detection on client ==========="
4236
4237 # bug 1414 - set/get directories' stripe info
4238 test_65a() {
4239         mkdir -p $DIR/d65
4240         touch $DIR/d65/f1
4241         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
4242 }
4243 run_test 65a "directory with no stripe info ===================="
4244
4245 test_65b() {
4246         mkdir -p $DIR/d65
4247         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65||error "setstripe"
4248         touch $DIR/d65/f2
4249         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
4250 }
4251 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4252
4253 test_65c() {
4254         if [ $OSTCOUNT -gt 1 ]; then
4255                 mkdir -p $DIR/d65
4256                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4257                         -c $(($OSTCOUNT - 1)) $DIR/d65 || error "setstripe"
4258                 touch $DIR/d65/f3
4259                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
4260         fi
4261 }
4262 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4263
4264 test_65d() {
4265         mkdir -p $DIR/d65
4266         if [ $STRIPECOUNT -le 0 ]; then
4267                 sc=1
4268         elif [ $STRIPECOUNT -gt 2000 ]; then
4269 #LOV_MAX_STRIPE_COUNT is 2000
4270                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
4271         else
4272                 sc=$(($STRIPECOUNT - 1))
4273         fi
4274         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/d65 || error "setstripe"
4275         touch $DIR/d65/f4 $DIR/d65/f5
4276         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
4277 }
4278 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
4279
4280 test_65e() {
4281         mkdir -p $DIR/d65
4282
4283         $SETSTRIPE $DIR/d65 || error "setstripe"
4284         $GETSTRIPE -v $DIR/d65 | grep "Default" || error "no stripe info failed"
4285         touch $DIR/d65/f6
4286         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
4287 }
4288 run_test 65e "directory setstripe defaults ======================="
4289
4290 test_65f() {
4291         mkdir -p $DIR/d65f
4292         $RUNAS $SETSTRIPE $DIR/d65f && error "setstripe succeeded" || true
4293 }
4294 run_test 65f "dir setstripe permission (should return error) ==="
4295
4296 test_65g() {
4297         mkdir -p $DIR/d65
4298         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65 ||error "setstripe"
4299         $SETSTRIPE -d $DIR/d65 || error "setstripe"
4300         $GETSTRIPE -v $DIR/d65 | grep "Default" || \
4301                 error "delete default stripe failed"
4302 }
4303 run_test 65g "directory setstripe -d ==========================="
4304
4305 test_65h() {
4306         mkdir -p $DIR/d65
4307         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/d65 ||error "setstripe"
4308         mkdir -p $DIR/d65/dd1
4309         [ $($GETSTRIPE -c $DIR/d65) == $($GETSTRIPE -c $DIR/d65/dd1) ] ||
4310                 error "stripe info inherit failed"
4311 }
4312 run_test 65h "directory stripe info inherit ===================="
4313
4314 test_65i() { # bug6367
4315         $SETSTRIPE -S 65536 -c -1 $MOUNT
4316 }
4317 run_test 65i "set non-default striping on root directory (bug 6367)="
4318
4319 test_65ia() { # bug12836
4320         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
4321 }
4322 run_test 65ia "getstripe on -1 default directory striping"
4323
4324 test_65ib() { # bug12836
4325         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
4326 }
4327 run_test 65ib "getstripe -v on -1 default directory striping"
4328
4329 test_65ic() { # bug12836
4330         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
4331 }
4332 run_test 65ic "new find on -1 default directory striping"
4333
4334 test_65j() { # bug6367
4335         sync; sleep 1
4336         # if we aren't already remounting for each test, do so for this test
4337         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
4338                 cleanup || error "failed to unmount"
4339                 setup
4340         fi
4341         $SETSTRIPE -d $MOUNT || error "setstripe failed"
4342 }
4343 run_test 65j "set default striping on root directory (bug 6367)="
4344
4345 test_65k() { # bug11679
4346     [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
4347     remote_mds_nodsh && skip "remote MDS with nodsh" && return
4348
4349     echo "Check OST status: "
4350     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
4351               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
4352
4353     for OSC in $MDS_OSCS; do
4354         echo $OSC "is activate"
4355         do_facet $SINGLEMDS lctl --device %$OSC activate
4356     done
4357
4358     do_facet client mkdir -p $DIR/$tdir
4359     for INACTIVE_OSC in $MDS_OSCS; do
4360         echo "Deactivate: " $INACTIVE_OSC
4361         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
4362         for STRIPE_OSC in $MDS_OSCS; do
4363             OST=`osc_to_ost $STRIPE_OSC`
4364             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
4365                  awk -F: /$OST/'{ print $1 }' | head -n 1`
4366
4367             [ -f $DIR/$tdir/$IDX ] && continue
4368             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
4369             do_facet client $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
4370             RC=$?
4371             [ $RC -ne 0 ] && error "setstripe should have succeeded"
4372         done
4373         do_facet client rm -f $DIR/$tdir/*
4374         echo $INACTIVE_OSC "is Activate."
4375         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
4376     done
4377 }
4378 run_test 65k "validate manual striping works properly with deactivated OSCs"
4379
4380 test_65l() { # bug 12836
4381         mkdir -p $DIR/$tdir/test_dir
4382         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
4383         $LFS find -mtime -1 $DIR/$tdir >/dev/null
4384 }
4385 run_test 65l "lfs find on -1 stripe dir ========================"
4386
4387 # bug 2543 - update blocks count on client
4388 test_66() {
4389         COUNT=${COUNT:-8}
4390         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
4391         sync; sync_all_data; sync; sync_all_data
4392         cancel_lru_locks osc
4393         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
4394         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
4395 }
4396 run_test 66 "update inode blocks count on client ==============="
4397
4398 LLOOP=
4399 LLITELOOPLOAD=
4400 cleanup_68() {
4401         trap 0
4402         if [ ! -z "$LLOOP" ]; then
4403                 if swapon -s | grep -q $LLOOP; then
4404                         swapoff $LLOOP || error "swapoff failed"
4405                 fi
4406
4407                 $LCTL blockdev_detach $LLOOP || error "detach failed"
4408                 rm -f $LLOOP
4409                 unset LLOOP
4410         fi
4411         if [ ! -z "$LLITELOOPLOAD" ]; then
4412                 rmmod llite_lloop
4413                 unset LLITELOOPLOAD
4414         fi
4415         rm -f $DIR/f68*
4416 }
4417
4418 meminfo() {
4419         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
4420 }
4421
4422 swap_used() {
4423         swapon -s | awk '($1 == "'$1'") { print $4 }'
4424 }
4425
4426 # test case for lloop driver, basic function
4427 test_68a() {
4428         [ "$UID" != 0 ] && skip_env "must run as root" && return
4429         llite_lloop_enabled || \
4430                 { skip_env "llite_lloop module disabled" && return; }
4431
4432         trap cleanup_68 EXIT
4433
4434         if ! module_loaded llite_lloop; then
4435                 if load_module llite/llite_lloop; then
4436                         LLITELOOPLOAD=yes
4437                 else
4438                         skip_env "can't find module llite_lloop"
4439                         return
4440                 fi
4441         fi
4442
4443         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4444         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
4445         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
4446
4447         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
4448         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
4449
4450         cleanup_68
4451 }
4452 run_test 68a "lloop driver - basic test ========================"
4453
4454 # excercise swapping to lustre by adding a high priority swapfile entry
4455 # and then consuming memory until it is used.
4456 test_68b() {  # was test_68
4457         [ "$UID" != 0 ] && skip_env "must run as root" && return
4458         lctl get_param -n devices | grep -q obdfilter && \
4459                 skip "local OST" && return
4460
4461         grep -q llite_lloop /proc/modules
4462         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
4463
4464         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
4465                 skip "can't reliably test swap with TCP" && return
4466
4467         MEMTOTAL=`meminfo MemTotal`
4468         NR_BLOCKS=$((MEMTOTAL>>8))
4469         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
4470
4471         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4472         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
4473         mkswap $DIR/f68b
4474
4475         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
4476
4477         trap cleanup_68 EXIT
4478
4479         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
4480
4481         echo "before: `swapon -s | grep $LLOOP`"
4482         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
4483         echo "after: `swapon -s | grep $LLOOP`"
4484         SWAPUSED=`swap_used $LLOOP`
4485
4486         cleanup_68
4487
4488         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
4489 }
4490 run_test 68b "support swapping to Lustre ========================"
4491
4492 # bug5265, obdfilter oa2dentry return -ENOENT
4493 # #define OBD_FAIL_OST_ENOENT 0x217
4494 test_69() {
4495         remote_ost_nodsh && skip "remote OST with nodsh" && return
4496
4497         f="$DIR/$tfile"
4498         $SETSTRIPE -c 1 -i 0 $f
4499
4500         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
4501
4502         do_facet ost1 lctl set_param fail_loc=0x217
4503         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
4504         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
4505
4506         do_facet ost1 lctl set_param fail_loc=0
4507         $DIRECTIO write $f 0 2 || error "write error"
4508
4509         cancel_lru_locks osc
4510         $DIRECTIO read $f 0 1 || error "read error"
4511
4512         do_facet ost1 lctl set_param fail_loc=0x217
4513         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
4514
4515         do_facet ost1 lctl set_param fail_loc=0
4516         rm -f $f
4517 }
4518 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
4519
4520 test_71() {
4521     mkdir -p $DIR/$tdir
4522     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
4523 }
4524 run_test 71 "Running dbench on lustre (don't segment fault) ===="
4525
4526 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
4527         check_kernel_version 43 || return 0
4528         [ "$RUNAS_ID" = "$UID" ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4529
4530         # Check that testing environment is properly set up. Skip if not
4531         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
4532                 skip_env "User $RUNAS_ID does not exist - skipping"
4533                 return 0
4534         }
4535         # We had better clear the $DIR to get enough space for dd
4536         rm -rf $DIR/*
4537         touch $DIR/f72
4538         chmod 777 $DIR/f72
4539         chmod ug+s $DIR/f72
4540         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
4541         # See if we are still setuid/sgid
4542         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
4543         # Now test that MDS is updated too
4544         cancel_lru_locks mdc
4545         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
4546         true
4547         rm -f $DIR/f72
4548 }
4549 run_test 72a "Test that remove suid works properly (bug5695) ===="
4550
4551 test_72b() { # bug 24226 -- keep mode setting when size is not changing
4552         local perm
4553
4554         [ "$RUNAS_ID" = "$UID" ] && \
4555                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4556         [ "$RUNAS_ID" -eq 0 ] && \
4557                 skip_env "RUNAS_ID = 0 -- skipping" && return
4558
4559         # Check that testing environment is properly set up. Skip if not
4560         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
4561                 skip_env "User $RUNAS_ID does not exist - skipping"
4562                 return 0
4563         }
4564         touch $DIR/${tfile}-f{g,u}
4565         mkdir $DIR/${tfile}-d{g,u}
4566         chmod 770 $DIR/${tfile}-{f,d}{g,u}
4567         chmod g+s $DIR/${tfile}-{f,d}g
4568         chmod u+s $DIR/${tfile}-{f,d}u
4569         for perm in 777 2777 4777; do
4570                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
4571                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
4572                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
4573                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
4574         done
4575         true
4576 }
4577 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
4578
4579 # bug 3462 - multiple simultaneous MDC requests
4580 test_73() {
4581         mkdir $DIR/d73-1
4582         mkdir $DIR/d73-2
4583         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
4584         pid1=$!
4585
4586         lctl set_param fail_loc=0x80000129
4587         $MULTIOP $DIR/d73-1/f73-2 Oc &
4588         sleep 1
4589         lctl set_param fail_loc=0
4590
4591         $MULTIOP $DIR/d73-2/f73-3 Oc &
4592         pid3=$!
4593
4594         kill -USR1 $pid1
4595         wait $pid1 || return 1
4596
4597         sleep 25
4598
4599         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
4600         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
4601         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
4602
4603         rm -rf $DIR/d73-*
4604 }
4605 run_test 73 "multiple MDC requests (should not deadlock)"
4606
4607 test_74a() { # bug 6149, 6184
4608         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
4609         #
4610         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
4611         # will spin in a tight reconnection loop
4612         touch $DIR/f74a
4613         lctl set_param fail_loc=0x8000030e
4614         # get any lock that won't be difficult - lookup works.
4615         ls $DIR/f74a
4616         lctl set_param fail_loc=0
4617         true
4618         rm -f $DIR/f74a
4619 }
4620 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
4621
4622 test_74b() { # bug 13310
4623         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
4624         #
4625         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
4626         # will spin in a tight reconnection loop
4627         lctl set_param fail_loc=0x8000030e
4628         # get a "difficult" lock
4629         touch $DIR/f74b
4630         lctl set_param fail_loc=0
4631         true
4632         rm -f $DIR/f74b
4633 }
4634 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
4635
4636 test_74c() {
4637 #define OBD_FAIL_LDLM_NEW_LOCK
4638         lctl set_param fail_loc=0x80000319
4639         touch $DIR/$tfile && error "Touch successful"
4640         true
4641 }
4642 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
4643
4644 num_inodes() {
4645         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
4646 }
4647
4648 get_inode_slab_tunables() {
4649         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
4650 }
4651
4652 set_inode_slab_tunables() {
4653         echo "lustre_inode_cache $1" > /proc/slabinfo
4654 }
4655
4656 test_76() { # Now for bug 20433, added originally in bug 1443
4657         local SLAB_SETTINGS=`get_inode_slab_tunables`
4658         local CPUS=`getconf _NPROCESSORS_ONLN`
4659         # we cannot set limit below 1 which means 1 inode in each
4660         # per-cpu cache is still allowed
4661         set_inode_slab_tunables "1 1 0"
4662         cancel_lru_locks osc
4663         BEFORE_INODES=`num_inodes`
4664         echo "before inodes: $BEFORE_INODES"
4665         local COUNT=1000
4666         [ "$SLOW" = "no" ] && COUNT=100
4667         for i in `seq $COUNT`; do
4668                 touch $DIR/$tfile
4669                 rm -f $DIR/$tfile
4670         done
4671         cancel_lru_locks osc
4672         AFTER_INODES=`num_inodes`
4673         echo "after inodes: $AFTER_INODES"
4674         local wait=0
4675         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
4676                 sleep 2
4677                 AFTER_INODES=`num_inodes`
4678                 wait=$((wait+2))
4679                 echo "wait $wait seconds inodes: $AFTER_INODES"
4680                 if [ $wait -gt 30 ]; then
4681                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
4682                 fi
4683         done
4684         set_inode_slab_tunables "$SLAB_SETTINGS"
4685 }
4686 run_test 76 "confirm clients recycle inodes properly ===="
4687
4688
4689 export ORIG_CSUM=""
4690 set_checksums()
4691 {
4692         # Note: in sptlrpc modes which enable its own bulk checksum, the
4693         # original crc32_le bulk checksum will be automatically disabled,
4694         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
4695         # will be checked by sptlrpc code against sptlrpc bulk checksum.
4696         # In this case set_checksums() will not be no-op, because sptlrpc
4697         # bulk checksum will be enabled all through the test.
4698
4699         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
4700         lctl set_param -n osc.*.checksums $1
4701         return 0
4702 }
4703
4704 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
4705                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
4706 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
4707 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
4708 set_checksum_type()
4709 {
4710         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
4711         log "set checksum type to $1"
4712         return 0
4713 }
4714 F77_TMP=$TMP/f77-temp
4715 F77SZ=8
4716 setup_f77() {
4717         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
4718                 error "error writing to $F77_TMP"
4719 }
4720
4721 test_77a() { # bug 10889
4722         $GSS && skip "could not run with gss" && return
4723         [ ! -f $F77_TMP ] && setup_f77
4724         set_checksums 1
4725         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
4726         set_checksums 0
4727         rm -f $DIR/$tfile
4728 }
4729 run_test 77a "normal checksum read/write operation ============="
4730
4731 test_77b() { # bug 10889
4732         $GSS && skip "could not run with gss" && return
4733         [ ! -f $F77_TMP ] && setup_f77
4734         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4735         lctl set_param fail_loc=0x80000409
4736         set_checksums 1
4737         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
4738                 error "dd error: $?"
4739         lctl set_param fail_loc=0
4740         set_checksums 0
4741 }
4742 run_test 77b "checksum error on client write ===================="
4743
4744 test_77c() { # bug 10889
4745         $GSS && skip "could not run with gss" && return
4746         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
4747         set_checksums 1
4748         for algo in $CKSUM_TYPES; do
4749                 cancel_lru_locks osc
4750                 set_checksum_type $algo
4751                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
4752                 lctl set_param fail_loc=0x80000408
4753                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
4754                 lctl set_param fail_loc=0
4755         done
4756         set_checksums 0
4757         set_checksum_type $ORIG_CSUM_TYPE
4758         rm -f $DIR/f77b
4759 }
4760 run_test 77c "checksum error on client read ==================="
4761
4762 test_77d() { # bug 10889
4763         $GSS && skip "could not run with gss" && return
4764         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4765         lctl set_param fail_loc=0x80000409
4766         set_checksums 1
4767         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
4768                 error "direct write: rc=$?"
4769         lctl set_param fail_loc=0
4770         set_checksums 0
4771 }
4772 run_test 77d "checksum error on OST direct write ==============="
4773
4774 test_77e() { # bug 10889
4775         $GSS && skip "could not run with gss" && return
4776         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
4777         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
4778         lctl set_param fail_loc=0x80000408
4779         set_checksums 1
4780         cancel_lru_locks osc
4781         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
4782                 error "direct read: rc=$?"
4783         lctl set_param fail_loc=0
4784         set_checksums 0
4785 }
4786 run_test 77e "checksum error on OST direct read ================"
4787
4788 test_77f() { # bug 10889
4789         $GSS && skip "could not run with gss" && return
4790         set_checksums 1
4791         for algo in $CKSUM_TYPES; do
4792                 cancel_lru_locks osc
4793                 set_checksum_type $algo
4794                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
4795                 lctl set_param fail_loc=0x409
4796                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
4797                         error "direct write succeeded"
4798                 lctl set_param fail_loc=0
4799         done
4800         set_checksum_type $ORIG_CSUM_TYPE
4801         set_checksums 0
4802 }
4803 run_test 77f "repeat checksum error on write (expect error) ===="
4804
4805 test_77g() { # bug 10889
4806         $GSS && skip "could not run with gss" && return
4807         remote_ost_nodsh && skip "remote OST with nodsh" && return
4808
4809         [ ! -f $F77_TMP ] && setup_f77
4810
4811         $SETSTRIPE -c 1 -i 0 $DIR/f77g
4812         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
4813         do_facet ost1 lctl set_param fail_loc=0x8000021a
4814         set_checksums 1
4815         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
4816                 error "write error: rc=$?"
4817         do_facet ost1 lctl set_param fail_loc=0
4818         set_checksums 0
4819 }
4820 run_test 77g "checksum error on OST write ======================"
4821
4822 test_77h() { # bug 10889
4823         $GSS && skip "could not run with gss" && return
4824         remote_ost_nodsh && skip "remote OST with nodsh" && return
4825
4826         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
4827         cancel_lru_locks osc
4828         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
4829         do_facet ost1 lctl set_param fail_loc=0x8000021b
4830         set_checksums 1
4831         cmp $F77_TMP $DIR/f77g || error "file compare failed"
4832         do_facet ost1 lctl set_param fail_loc=0
4833         set_checksums 0
4834 }
4835 run_test 77h "checksum error on OST read ======================="
4836
4837 test_77i() { # bug 13805
4838         $GSS && skip "could not run with gss" && return
4839         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
4840         lctl set_param fail_loc=0x40b
4841         remount_client $MOUNT
4842         lctl set_param fail_loc=0
4843         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
4844                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
4845                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
4846                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
4847         done
4848         remount_client $MOUNT
4849 }
4850 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
4851
4852 test_77j() { # bug 13805
4853         $GSS && skip "could not run with gss" && return
4854         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
4855         lctl set_param fail_loc=0x40c
4856         remount_client $MOUNT
4857         lctl set_param fail_loc=0
4858         sleep 2 # wait async osc connect to finish
4859         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
4860                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
4861                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
4862                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
4863         done
4864         remount_client $MOUNT
4865 }
4866 run_test 77j "client only supporting ADLER32 ===================="
4867
4868 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
4869 rm -f $F77_TMP
4870 unset F77_TMP
4871
4872 test_78() { # bug 10901
4873         remote_ost || { skip_env "local OST" && return; }
4874
4875         NSEQ=5
4876         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
4877         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
4878         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
4879         echo "MemTotal: $MEMTOTAL"
4880 # reserve 256MB of memory for the kernel and other running processes,
4881 # and then take 1/2 of the remaining memory for the read/write buffers.
4882     if [ $MEMTOTAL -gt 512 ] ;then
4883         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
4884     else
4885         # for those poor memory-starved high-end clusters...
4886         MEMTOTAL=$((MEMTOTAL / 2))
4887     fi
4888         echo "Mem to use for directio: $MEMTOTAL"
4889         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
4890         [ $F78SIZE -gt 512 ] && F78SIZE=512
4891         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
4892         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
4893         echo "Smallest OST: $SMALLESTOST"
4894         [ $SMALLESTOST -lt 10240 ] && \
4895                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
4896
4897         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
4898                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
4899
4900         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
4901         echo "File size: $F78SIZE"
4902         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
4903         for i in `seq 1 $NSEQ`
4904         do
4905                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
4906                 echo directIO rdwr round $i of $NSEQ
4907                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
4908         done
4909
4910         rm -f $DIR/$tfile
4911 }
4912 run_test 78 "handle large O_DIRECT writes correctly ============"
4913
4914 test_79() { # bug 12743
4915         wait_delete_completed
4916
4917         BKTOTAL=$(calc_osc_kbytes kbytestotal)
4918         BKFREE=$(calc_osc_kbytes kbytesfree)
4919         BKAVAIL=$(calc_osc_kbytes kbytesavail)
4920
4921         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
4922         DFTOTAL=`echo $STRING | cut -d, -f1`
4923         DFUSED=`echo $STRING  | cut -d, -f2`
4924         DFAVAIL=`echo $STRING | cut -d, -f3`
4925         DFFREE=$(($DFTOTAL - $DFUSED))
4926
4927         ALLOWANCE=$((64 * $OSTCOUNT))
4928
4929         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
4930            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
4931                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
4932         fi
4933         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
4934            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
4935                 error "df free($DFFREE) mismatch OST free($BKFREE)"
4936         fi
4937         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
4938            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
4939                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
4940         fi
4941 }
4942 run_test 79 "df report consistency check ======================="
4943
4944 test_80() { # bug 10718
4945         # relax strong synchronous semantics for slow backends like ZFS
4946         local soc="obdfilter.*.sync_on_lock_cancel"
4947         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
4948         local hosts=
4949         if [ "$soc_old" != "never" -a "$FSTYPE" != "ldiskfs" ]; then
4950                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
4951                           facet_active_host $host; done | sort -u)
4952                 do_nodes $hosts lctl set_param $soc=never
4953         fi
4954
4955         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
4956         sync; sleep 1; sync
4957         local BEFORE=`date +%s`
4958         cancel_lru_locks osc
4959         local AFTER=`date +%s`
4960         local DIFF=$((AFTER-BEFORE))
4961         if [ $DIFF -gt 1 ] ; then
4962                 error "elapsed for 1M@1T = $DIFF"
4963         fi
4964
4965         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
4966
4967         true
4968         rm -f $DIR/$tfile
4969 }
4970 run_test 80 "Page eviction is equally fast at high offsets too  ===="
4971
4972 test_81a() { # LU-456
4973         remote_ost_nodsh && skip "remote OST with nodsh" && return
4974         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
4975         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
4976         do_facet ost1 lctl set_param fail_loc=0x80000228
4977
4978         # write should trigger a retry and success
4979         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
4980         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4981         RC=$?
4982         if [ $RC -ne 0 ] ; then
4983                 error "write should success, but failed for $RC"
4984         fi
4985 }
4986 run_test 81a "OST should retry write when get -ENOSPC ==============="
4987
4988 test_81b() { # LU-456
4989         remote_ost_nodsh && skip "remote OST with nodsh" && return
4990         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
4991         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
4992         do_facet ost1 lctl set_param fail_loc=0x228
4993
4994         # write should retry several times and return -ENOSPC finally
4995         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
4996         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
4997         RC=$?
4998         ENOSPC=28
4999         if [ $RC -ne $ENOSPC ] ; then
5000                 error "dd should fail for -ENOSPC, but succeed."
5001         fi
5002 }
5003 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5004
5005 test_82() { # LU-1031
5006         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5007         local gid1=14091995
5008         local gid2=16022000
5009
5010         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5011         local MULTIPID1=$!
5012         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5013         local MULTIPID2=$!
5014         kill -USR1 $MULTIPID2
5015         sleep 2
5016         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5017                 error "First grouplock does not block second one"
5018         else
5019                 echo "Second grouplock blocks first one"
5020         fi
5021         kill -USR1 $MULTIPID1
5022         wait $MULTIPID1
5023         wait $MULTIPID2
5024 }
5025 run_test 82 "Basic grouplock test ==============================="
5026
5027 test_99a() {
5028         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && \
5029             return
5030         mkdir -p $DIR/d99cvsroot
5031         chown $RUNAS_ID $DIR/d99cvsroot
5032         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5033         cd $TMP
5034
5035         $RUNAS cvs -d $DIR/d99cvsroot init || error
5036         cd $oldPWD
5037 }
5038 run_test 99a "cvs init ========================================="
5039
5040 test_99b() {
5041         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5042         [ ! -d $DIR/d99cvsroot ] && test_99a
5043         cd /etc/init.d
5044         # some versions of cvs import exit(1) when asked to import links or
5045         # files they can't read.  ignore those files.
5046         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5047                         ! -perm +4 -printf '-I %f\n')
5048         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5049                 d99reposname vtag rtag
5050 }
5051 run_test 99b "cvs import ======================================="
5052
5053 test_99c() {
5054         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5055         [ ! -d $DIR/d99cvsroot ] && test_99b
5056         cd $DIR
5057         mkdir -p $DIR/d99reposname
5058         chown $RUNAS_ID $DIR/d99reposname
5059         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5060 }
5061 run_test 99c "cvs checkout ====================================="
5062
5063 test_99d() {
5064         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5065         [ ! -d $DIR/d99cvsroot ] && test_99c
5066         cd $DIR/d99reposname
5067         $RUNAS touch foo99
5068         $RUNAS cvs add -m 'addmsg' foo99
5069 }
5070 run_test 99d "cvs add =========================================="
5071
5072 test_99e() {
5073         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5074         [ ! -d $DIR/d99cvsroot ] && test_99c
5075         cd $DIR/d99reposname
5076         $RUNAS cvs update
5077 }
5078 run_test 99e "cvs update ======================================="
5079
5080 test_99f() {
5081         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5082         [ ! -d $DIR/d99cvsroot ] && test_99d
5083         cd $DIR/d99reposname
5084         $RUNAS cvs commit -m 'nomsg' foo99
5085     rm -fr $DIR/d99cvsroot
5086 }
5087 run_test 99f "cvs commit ======================================="
5088
5089 test_100() {
5090         [ "$NETTYPE" = tcp ] || \
5091                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5092                         return ; }
5093
5094         remote_ost_nodsh && skip "remote OST with nodsh" && return
5095         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5096         remote_servers || \
5097                 { skip "useless for local single node setup" && return; }
5098
5099         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5100                 [ "$PROT" != "tcp" ] && continue
5101                 RPORT=$(echo $REMOTE | cut -d: -f2)
5102                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5103
5104                 rc=0
5105                 LPORT=`echo $LOCAL | cut -d: -f2`
5106                 if [ $LPORT -ge 1024 ]; then
5107                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5108                         netstat -tna
5109                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5110                 fi
5111         done
5112         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5113 }
5114 run_test 100 "check local port using privileged port ==========="
5115
5116 function get_named_value()
5117 {
5118     local tag
5119
5120     tag=$1
5121     while read ;do
5122         line=$REPLY
5123         case $line in
5124         $tag*)
5125             echo $line | sed "s/^$tag[ ]*//"
5126             break
5127             ;;
5128         esac
5129     done
5130 }
5131
5132 export CACHE_MAX=`$LCTL get_param -n llite.*.max_cached_mb | head -n 1`
5133 cleanup_101a() {
5134         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5135         trap 0
5136 }
5137
5138 test_101a() {
5139         local s
5140         local discard
5141         local nreads=10000
5142         [ "$CPU" = "UML" ] && nreads=1000
5143         local cache_limit=32
5144
5145         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5146         trap cleanup_101a EXIT
5147         $LCTL set_param -n llite.*.read_ahead_stats 0
5148         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5149
5150         #
5151         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5152         #
5153         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5154         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5155
5156         discard=0
5157         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
5158                 get_named_value 'read but discarded' | cut -d" " -f1`; do
5159                         discard=$(($discard + $s))
5160         done
5161         cleanup_101a
5162
5163         if [ $(($discard * 10)) -gt $nreads ] ;then
5164                 $LCTL get_param osc.*-osc*.rpc_stats
5165                 $LCTL get_param llite.*.read_ahead_stats
5166                 error "too many ($discard) discarded pages"
5167         fi
5168         rm -f $DIR/$tfile || true
5169 }
5170 run_test 101a "check read-ahead for random reads ================"
5171
5172 setup_test101bc() {
5173         mkdir -p $DIR/$tdir
5174         STRIPE_SIZE=1048576
5175         STRIPE_COUNT=$OSTCOUNT
5176         STRIPE_OFFSET=0
5177
5178         local list=$(comma_list $(osts_nodes))
5179         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=0
5180         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable=0
5181
5182         trap cleanup_test101bc EXIT
5183         # prepare the read-ahead file
5184         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5185
5186         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
5187 }
5188
5189 cleanup_test101bc() {
5190         trap 0
5191         rm -rf $DIR/$tdir
5192         rm -f $DIR/$tfile
5193
5194         local list=$(comma_list $(osts_nodes))
5195         do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable=1
5196         do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable=1
5197 }
5198
5199 calc_total() {
5200         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5201 }
5202
5203 ra_check_101() {
5204         local READ_SIZE=$1
5205         local STRIPE_SIZE=1048576
5206         local RA_INC=1048576
5207         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5208         local FILE_LENGTH=$((64*100))
5209         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5210                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5211         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5212                         get_named_value 'read but discarded' | \
5213                         cut -d" " -f1 | calc_total`
5214         if [ $DISCARD -gt $discard_limit ]; then
5215                 $LCTL get_param llite.*.read_ahead_stats
5216                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5217         else
5218                 echo "Read-ahead success for size ${READ_SIZE}"
5219         fi
5220 }
5221
5222 test_101b() {
5223         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5224         local STRIPE_SIZE=1048576
5225         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5226         local FILE_LENGTH=$((STRIPE_SIZE*100))
5227         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
5228         # prepare the read-ahead file
5229         setup_test101bc
5230         cancel_lru_locks osc
5231         for BIDX in 2 4 8 16 32 64 128 256
5232         do
5233                 local BSIZE=$((BIDX*4096))
5234                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5235                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5236                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5237                 $LCTL set_param -n llite.*.read_ahead_stats 0
5238                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5239                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5240                 cancel_lru_locks osc
5241                 ra_check_101 $BSIZE
5242         done
5243         cleanup_test101bc
5244         true
5245 }
5246 run_test 101b "check stride-io mode read-ahead ================="
5247
5248 test_101c() {
5249     local STRIPE_SIZE=1048576
5250     local FILE_LENGTH=$((STRIPE_SIZE*100))
5251     local nreads=10000
5252     local osc
5253
5254     setup_test101bc
5255
5256     cancel_lru_locks osc
5257     $LCTL set_param osc.*.rpc_stats 0
5258     $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
5259     for osc in $($LCTL get_param -N osc.*); do
5260         if [ "$osc" == "osc.num_refs" ]; then
5261             continue
5262         fi
5263
5264         local lines=$($LCTL get_param -n ${osc}.rpc_stats | wc | awk '{print $1}')
5265         if [ $lines -le 20 ]; then
5266             continue
5267         fi
5268
5269         local rpc4k=$($LCTL get_param -n ${osc}.rpc_stats |
5270                                      awk '$1 == "1:" { print $2; exit; }')
5271         local rpc8k=$($LCTL get_param -n ${osc}.rpc_stats |
5272                                      awk '$1 == "2:" { print $2; exit; }')
5273         local rpc16k=$($LCTL get_param -n ${osc}.rpc_stats |
5274                                      awk '$1 == "4:" { print $2; exit; }')
5275         local rpc32k=$($LCTL get_param -n ${osc}.rpc_stats |
5276                                      awk '$1 == "8:" { print $2; exit; }')
5277
5278         [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
5279         [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
5280         [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
5281         [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
5282         echo "${osc} rpc check passed!"
5283     done
5284     cleanup_test101bc
5285     true
5286 }
5287 run_test 101c "check stripe_size aligned read-ahead ================="
5288
5289 set_read_ahead() {
5290    $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
5291    $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
5292 }
5293
5294 test_101d() {
5295     local file=$DIR/$tfile
5296     local size=${FILESIZE_101c:-500}
5297     local ra_MB=${READAHEAD_MB:-40}
5298
5299     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5300     [ $space -gt $((size / 1024)) ] ||
5301         { skip "Need free space ${size}M, have $space" && return; }
5302
5303     echo Creating ${size}M test file $file
5304     dd if=/dev/zero of=$file bs=1M count=$size || error "dd failed"
5305     echo Cancel LRU locks on lustre client to flush the client cache
5306     cancel_lru_locks osc
5307
5308     echo Disable read-ahead
5309     local old_READAHEAD=$(set_read_ahead 0)
5310
5311     echo Reading the test file $file with read-ahead disabled
5312     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5313
5314     echo Cancel LRU locks on lustre client to flush the client cache
5315     cancel_lru_locks osc
5316     echo Enable read-ahead with ${ra_MB}MB
5317     set_read_ahead $ra_MB
5318
5319     echo Reading the test file $file with read-ahead enabled
5320     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5321
5322     echo read-ahead disabled time read $time_ra_OFF
5323     echo read-ahead enabled  time read $time_ra_ON
5324
5325         set_read_ahead $old_READAHEAD
5326         rm -f $file
5327         wait_delete_completed
5328
5329     [ $time_ra_ON -lt $time_ra_OFF ] ||
5330         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
5331                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
5332 }
5333 run_test 101d "file read with and without read-ahead enabled  ================="
5334
5335 test_101e() {
5336     local file=$DIR/$tfile
5337     local size=500  #KB
5338     local count=100
5339     local blksize=1024
5340
5341     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5342     local need_space=$((count * size))
5343     [ $space -gt $need_space ] ||
5344         { skip_env "Need free space $need_space, have $space" && return; }
5345
5346     echo Creating $count ${size}K test files
5347     for ((i = 0; i < $count; i++)); do
5348         dd if=/dev/zero of=${file}_${i} bs=$blksize count=$size 2>/dev/null
5349     done
5350
5351     echo Cancel LRU locks on lustre client to flush the client cache
5352     cancel_lru_locks osc
5353
5354     echo Reset readahead stats
5355     $LCTL set_param -n llite.*.read_ahead_stats 0
5356
5357     for ((i = 0; i < $count; i++)); do
5358         dd if=${file}_${i} of=/dev/null bs=$blksize count=$size 2>/dev/null
5359     done
5360
5361     local miss=$($LCTL get_param -n llite.*.read_ahead_stats | \
5362           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5363
5364     for ((i = 0; i < $count; i++)); do
5365         rm -rf ${file}_${i} 2>/dev/null
5366     done
5367
5368     #10000 means 20% reads are missing in readahead
5369     [ $miss -lt 10000 ] ||  error "misses too much for small reads"
5370 }
5371 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
5372
5373 cleanup_test101f() {
5374     trap 0
5375     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
5376     rm -rf $DIR/$tfile 2>/dev/null
5377 }
5378
5379 test_101f() {
5380     local file=$DIR/$tfile
5381     local nreads=1000
5382
5383     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
5384     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
5385     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
5386     trap cleanup_test101f EXIT
5387
5388     echo Cancel LRU locks on lustre client to flush the client cache
5389     cancel_lru_locks osc
5390
5391     echo Reset readahead stats
5392     $LCTL set_param -n llite.*.read_ahead_stats 0
5393     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
5394     # readahead should read in 2M file on second read, so only miss
5395     # 2 pages.
5396     echo Random 4K reads on 2M file for 1000 times
5397     $READS -f $file -s 2097152 -b 4096 -n $nreads
5398
5399     echo checking missing pages
5400     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
5401           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5402
5403     [ $miss -lt 3 ] || error "misses too much pages!"
5404     cleanup_test101f
5405 }
5406 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
5407
5408 setup_test102() {
5409         mkdir -p $DIR/$tdir
5410         chown $RUNAS_ID $DIR/$tdir
5411         STRIPE_SIZE=65536
5412         STRIPE_OFFSET=1
5413         STRIPE_COUNT=$OSTCOUNT
5414         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
5415
5416         trap cleanup_test102 EXIT
5417         cd $DIR
5418         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
5419         cd $DIR/$tdir
5420         for num in 1 2 3 4; do
5421                 for count in $(seq 1 $STRIPE_COUNT); do
5422                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
5423                                 local size=`expr $STRIPE_SIZE \* $num`
5424                                 local file=file"$num-$idx-$count"
5425                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
5426                         done
5427                 done
5428         done
5429
5430         cd $DIR
5431         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
5432 }
5433
5434 cleanup_test102() {
5435         trap 0
5436         rm -f $TMP/f102.tar
5437         rm -rf $DIR/d0.sanity/d102
5438 }
5439
5440 test_102a() {
5441         local testfile=$DIR/xattr_testfile
5442
5443         touch $testfile
5444
5445         [ "$UID" != 0 ] && skip_env "must run as root" && return
5446         [ -z "`lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr`" ] &&
5447                 skip_env "must have user_xattr" && return
5448
5449         [ -z "$(which setfattr 2>/dev/null)" ] &&
5450                 skip_env "could not find setfattr" && return
5451
5452         echo "set/get xattr..."
5453         setfattr -n trusted.name1 -v value1 $testfile || error
5454         getfattr -n trusted.name1 $testfile 2> /dev/null |
5455           grep "trusted.name1=.value1" ||
5456                 error "$testfile missing trusted.name1=value1"
5457
5458         setfattr -n user.author1 -v author1 $testfile || error
5459         getfattr -n user.author1 $testfile 2> /dev/null |
5460           grep "user.author1=.author1" ||
5461                 error "$testfile missing trusted.author1=author1"
5462
5463         echo "listxattr..."
5464         setfattr -n trusted.name2 -v value2 $testfile ||
5465                 error "$testfile unable to set trusted.name2"
5466         setfattr -n trusted.name3 -v value3 $testfile ||
5467                 error "$testfile unable to set trusted.name3"
5468         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
5469             grep "trusted.name" | wc -l) -eq 3 ] ||
5470                 error "$testfile missing 3 trusted.name xattrs"
5471
5472         setfattr -n user.author2 -v author2 $testfile ||
5473                 error "$testfile unable to set user.author2"
5474         setfattr -n user.author3 -v author3 $testfile ||
5475                 error "$testfile unable to set user.author3"
5476         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
5477             grep "user.author" | wc -l) -eq 3 ] ||
5478                 error "$testfile missing 3 user.author xattrs"
5479
5480         echo "remove xattr..."
5481         setfattr -x trusted.name1 $testfile ||
5482                 error "$testfile error deleting trusted.name1"
5483         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
5484                 error "$testfile did not delete trusted.name1 xattr"
5485
5486         setfattr -x user.author1 $testfile ||
5487                 error "$testfile error deleting user.author1"
5488         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
5489                 error "$testfile did not delete trusted.name1 xattr"
5490
5491         # b10667: setting lustre special xattr be silently discarded
5492         echo "set lustre special xattr ..."
5493         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
5494                 error "$testfile allowed setting trusted.lov"
5495 }
5496 run_test 102a "user xattr test =================================="
5497
5498 test_102b() {
5499         # b10930: get/set/list trusted.lov xattr
5500         echo "get/set/list trusted.lov xattr ..."
5501         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5502         local testfile=$DIR/$tfile
5503         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
5504                 error "setstripe failed"
5505         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
5506                 error "getstripe failed"
5507         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
5508         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
5509
5510         local testfile2=${testfile}2
5511         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
5512                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
5513
5514         $MCREATE $testfile2
5515         setfattr -n trusted.lov -v $value $testfile2
5516         local stripe_size=$($GETSTRIPE -S $testfile2)
5517         local stripe_count=$($GETSTRIPE -c $testfile2)
5518         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
5519         [ $stripe_count -eq $STRIPECOUNT ] ||
5520                 error "stripe count $stripe_count != $STRIPECOUNT"
5521         rm -f $DIR/$tfile
5522 }
5523 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
5524
5525 test_102c() {
5526         # b10930: get/set/list lustre.lov xattr
5527         echo "get/set/list lustre.lov xattr ..."
5528         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5529         mkdir -p $DIR/$tdir
5530         chown $RUNAS_ID $DIR/$tdir
5531         local testfile=$DIR/$tdir/$tfile
5532         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
5533                 error "setstripe failed"
5534         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
5535                 error "getstripe failed"
5536         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
5537         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
5538
5539         local testfile2=${testfile}2
5540         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
5541                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
5542
5543         $RUNAS $MCREATE $testfile2
5544         $RUNAS setfattr -n lustre.lov -v $value $testfile2
5545         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
5546         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
5547         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
5548         [ $stripe_count -eq $STRIPECOUNT ] ||
5549                 error "stripe count $stripe_count != $STRIPECOUNT"
5550 }
5551 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
5552
5553 compare_stripe_info1() {
5554         local stripe_index_all_zero=true
5555
5556         for num in 1 2 3 4; do
5557                 for count in $(seq 1 $STRIPE_COUNT); do
5558                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
5559                                 local size=$((STRIPE_SIZE * num))
5560                                 local file=file"$num-$offset-$count"
5561                                 stripe_size=$(lfs getstripe -S $PWD/$file)
5562                                 [ $stripe_size -ne $size ] &&
5563                                     error "$file: size $stripe_size != $size"
5564                                 stripe_count=$(lfs getstripe -c $PWD/$file)
5565                                 # allow fewer stripes to be created, ORI-601
5566                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
5567                                     error "$file: count $stripe_count != $count"
5568                                 stripe_index=$(lfs getstripe -i $PWD/$file)
5569                                 [ $stripe_index -ne 0 ] &&
5570                                         stripe_index_all_zero=false
5571                         done
5572                 done
5573         done
5574         $stripe_index_all_zero &&
5575                 error "all files are being extracted starting from OST index 0"
5576         return 0
5577 }
5578
5579 find_lustre_tar() {
5580         [ -n "$(which tar 2>/dev/null)" ] &&
5581                 strings $(which tar) | grep -q "lustre" && echo tar
5582 }
5583
5584 test_102d() {
5585         # b10930: tar test for trusted.lov xattr
5586         TAR=$(find_lustre_tar)
5587         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5588         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5589         setup_test102
5590         mkdir -p $DIR/d102d
5591         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
5592         cd $DIR/d102d/$tdir
5593         compare_stripe_info1
5594 }
5595 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
5596
5597 test_102f() {
5598         # b10930: tar test for trusted.lov xattr
5599         TAR=$(find_lustre_tar)
5600         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5601         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5602         setup_test102
5603         mkdir -p $DIR/d102f
5604         cd $DIR
5605         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
5606         cd $DIR/d102f/$tdir
5607         compare_stripe_info1
5608 }
5609 run_test 102f "tar copy files, not keep osts ==========="
5610
5611 grow_xattr() {
5612         local xsize=${1:-1024}  # in bytes
5613         local file=$DIR/$tfile
5614
5615         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
5616                 skip "must have user_xattr" && return 0
5617         [ -z "$(which setfattr 2>/dev/null)" ] &&
5618                 skip_env "could not find setfattr" && return 0
5619         [ -z "$(which getfattr 2>/dev/null)" ] &&
5620                 skip_env "could not find getfattr" && return 0
5621
5622         touch $file
5623
5624         local value="$(generate_string $xsize)"
5625
5626         local xbig=trusted.big
5627         log "save $xbig on $file"
5628         setfattr -n $xbig -v $value $file ||
5629                 error "saving $xbig on $file failed"
5630
5631         local orig=$(get_xattr_value $xbig $file)
5632         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
5633
5634         local xsml=trusted.sml
5635         log "save $xsml on $file"
5636         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
5637
5638         local new=$(get_xattr_value $xbig $file)
5639         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
5640
5641         log "grow $xsml on $file"
5642         setfattr -n $xsml -v "$value" $file ||
5643                 error "growing $xsml on $file failed"
5644
5645         new=$(get_xattr_value $xbig $file)
5646         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
5647         log "$xbig still valid after growing $xsml"
5648
5649         rm -f $file
5650 }
5651
5652 test_102h() { # bug 15777
5653         grow_xattr 1024
5654 }
5655 run_test 102h "grow xattr from inside inode to external block"
5656
5657 test_102ha() {
5658         large_xattr_enabled || { skip "large_xattr disabled" && return; }
5659         grow_xattr $(max_xattr_size)
5660 }
5661 run_test 102ha "grow xattr from inside inode to external inode"
5662
5663 test_102i() { # bug 17038
5664         touch $DIR/$tfile
5665         ln -s $DIR/$tfile $DIR/${tfile}link
5666         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
5667         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"
5668         rm -f $DIR/$tfile $DIR/${tfile}link
5669 }
5670 run_test 102i "lgetxattr test on symbolic link ============"
5671
5672 test_102j() {
5673         TAR=$(find_lustre_tar)
5674         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
5675         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
5676         setup_test102 "$RUNAS"
5677         mkdir -p $DIR/d102j
5678         chown $RUNAS_ID $DIR/d102j
5679         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
5680         cd $DIR/d102j/$tdir
5681         compare_stripe_info1 "$RUNAS"
5682 }
5683 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
5684
5685 test_102k() {
5686         touch $DIR/$tfile
5687         # b22187 just check that does not crash for regular file.
5688         setfattr -n trusted.lov $DIR/$tfile
5689         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
5690         local test_kdir=$DIR/d102k
5691         mkdir $test_kdir
5692         local default_size=`$GETSTRIPE -S $test_kdir`
5693         local default_count=`$GETSTRIPE -c $test_kdir`
5694         local default_offset=`$GETSTRIPE -i $test_kdir`
5695         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $test_kdir ||
5696                 error 'dir setstripe failed'
5697         setfattr -n trusted.lov $test_kdir
5698         local stripe_size=`$GETSTRIPE -S $test_kdir`
5699         local stripe_count=`$GETSTRIPE -c $test_kdir`
5700         local stripe_offset=`$GETSTRIPE -i $test_kdir`
5701         [ $stripe_size -eq $default_size ] ||
5702                 error "stripe size $stripe_size != $default_size"
5703         [ $stripe_count -eq $default_count ] ||
5704                 error "stripe count $stripe_count != $default_count"
5705         [ $stripe_offset -eq $default_offset ] ||
5706                 error "stripe offset $stripe_offset != $default_offset"
5707         rm -rf $DIR/$tfile $test_kdir
5708 }
5709 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
5710
5711 test_102l() {
5712         # LU-532 trusted. xattr is invisible to non-root
5713         local testfile=$DIR/$tfile
5714
5715         touch $testfile
5716
5717         echo "listxattr as user..."
5718         chown $RUNAS_ID $testfile
5719         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
5720             grep -q "trusted" &&
5721                 error "$testfile trusted xattrs are user visible"
5722
5723         return 0;
5724 }
5725 run_test 102l "listxattr filter test =================================="
5726
5727 cleanup_test102
5728
5729 run_acl_subtest()
5730 {
5731     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
5732     return $?
5733 }
5734
5735 test_103 () {
5736     [ "$UID" != 0 ] && skip_env "must run as root" && return
5737     [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
5738     [ -z "$(which setfacl 2>/dev/null)" ] && skip_env "could not find setfacl" && return
5739     $GSS && skip "could not run under gss" && return
5740
5741     declare -a identity_old
5742
5743     for num in `seq $MDSCOUNT`; do
5744         switch_identity $num true || identity_old[$num]=$?
5745     done
5746
5747     SAVE_UMASK=`umask`
5748     umask 0022
5749     cd $DIR
5750
5751     echo "performing cp ..."
5752     run_acl_subtest cp || error
5753     echo "performing getfacl-noacl..."
5754     run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
5755     echo "performing misc..."
5756     run_acl_subtest misc || error  "misc test failed"
5757     echo "performing permissions..."
5758     run_acl_subtest permissions || error "permissions failed"
5759     echo "performing setfacl..."
5760     run_acl_subtest setfacl || error  "setfacl test failed"
5761
5762     # inheritance test got from HP
5763     echo "performing inheritance..."
5764     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
5765     chmod +x make-tree || error "chmod +x failed"
5766     run_acl_subtest inheritance || error "inheritance test failed"
5767     rm -f make-tree
5768
5769     cd $SAVE_PWD
5770     umask $SAVE_UMASK
5771
5772     for num in `seq $MDSCOUNT`; do
5773         if [ "${identity_old[$num]}" = 1 ]; then
5774             switch_identity $num false || identity_old[$num]=$?
5775         fi
5776     done
5777 }
5778 run_test 103 "acl test ========================================="
5779
5780 test_104a() {
5781         touch $DIR/$tfile
5782         lfs df || error "lfs df failed"
5783         lfs df -ih || error "lfs df -ih failed"
5784         lfs df -h $DIR || error "lfs df -h $DIR failed"
5785         lfs df -i $DIR || error "lfs df -i $DIR failed"
5786         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
5787         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
5788
5789         OSC=`lctl dl |grep OST0000-osc-[^M] |awk '{print $4}'`
5790         lctl --device %$OSC deactivate
5791         lfs df || error "lfs df with deactivated OSC failed"
5792         lctl --device %$OSC activate
5793         # wait the osc back to normal
5794         wait_osc_import_state client ost FULL
5795
5796         lfs df || error "lfs df with reactivated OSC failed"
5797         rm -f $DIR/$tfile
5798 }
5799 run_test 104a "lfs df [-ih] [path] test ========================="
5800
5801 test_104b() {
5802         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5803         chmod 666 /dev/obd
5804         denied_cnt=$((`$RUNAS $LFS check servers 2>&1 | grep "Permission denied" | wc -l`))
5805         if [ $denied_cnt -ne 0 ];
5806         then
5807                     error "lfs check servers test failed"
5808         fi
5809 }
5810 run_test 104b "$RUNAS lfs check servers test ===================="
5811
5812 test_105a() {
5813         # doesn't work on 2.4 kernels
5814         touch $DIR/$tfile
5815         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5816         then
5817                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
5818         else
5819                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
5820         fi
5821         rm -f $DIR/$tfile
5822 }
5823 run_test 105a "flock when mounted without -o flock test ========"
5824
5825 test_105b() {
5826         touch $DIR/$tfile
5827         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5828         then
5829                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
5830         else
5831                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
5832         fi
5833         rm -f $DIR/$tfile
5834 }
5835 run_test 105b "fcntl when mounted without -o flock test ========"
5836
5837 test_105c() {
5838         touch $DIR/$tfile
5839         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
5840         then
5841                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
5842         else
5843                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
5844         fi
5845         rm -f $DIR/$tfile
5846 }
5847 run_test 105c "lockf when mounted without -o flock test ========"
5848
5849 test_105d() { # bug 15924
5850         mkdir -p $DIR/$tdir
5851         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
5852                 skip "mount w/o flock enabled" && return
5853         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
5854         $LCTL set_param fail_loc=0x80000315
5855         flocks_test 2 $DIR/$tdir
5856 }
5857 run_test 105d "flock race (should not freeze) ========"
5858
5859 test_105e() { # bug 22660 && 22040
5860         [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \
5861                 skip "mount w/o flock enabled" && return
5862         touch $DIR/$tfile
5863         flocks_test 3 $DIR/$tfile
5864 }
5865 run_test 105e "Two conflicting flocks from same process ======="
5866
5867 test_106() { #bug 10921
5868         mkdir -p $DIR/$tdir
5869         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
5870         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
5871 }
5872 run_test 106 "attempt exec of dir followed by chown of that dir"
5873
5874 test_107() {
5875         CDIR=`pwd`
5876         cd $DIR
5877
5878         local file=core
5879         rm -f $file
5880
5881         local save_pattern=$(sysctl -n kernel.core_pattern)
5882         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
5883         sysctl -w kernel.core_pattern=$file
5884         sysctl -w kernel.core_uses_pid=0
5885
5886         ulimit -c unlimited
5887         sleep 60 &
5888         SLEEPPID=$!
5889
5890         sleep 1
5891
5892         kill -s 11 $SLEEPPID
5893         wait $SLEEPPID
5894         if [ -e $file ]; then
5895                 size=`stat -c%s $file`
5896                 [ $size -eq 0 ] && error "Fail to create core file $file"
5897         else
5898                 error "Fail to create core file $file"
5899         fi
5900         rm -f $file
5901         sysctl -w kernel.core_pattern=$save_pattern
5902         sysctl -w kernel.core_uses_pid=$save_uses_pid
5903         cd $CDIR
5904 }
5905 run_test 107 "Coredump on SIG"
5906
5907 test_110() {
5908         mkdir -p $DIR/d110
5909         mkdir $DIR/d110/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || error "mkdir with 255 char fail"
5910         mkdir $DIR/d110/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && error "mkdir with 256 char should fail, but not"
5911         touch $DIR/d110/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx || error "create with 255 char fail"
5912         touch $DIR/d110/yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy && error ""create with 256 char should fail, but not
5913
5914         ls -l $DIR/d110
5915     rm -fr $DIR/d110
5916 }
5917 run_test 110 "filename length checking"
5918
5919 test_115() {
5920         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
5921             cut -c11-20)
5922         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
5923             return
5924         echo "Starting with $OSTIO_pre threads"
5925
5926         NUMTEST=20000
5927         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
5928         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
5929         echo "$NUMTEST creates/unlinks"
5930         mkdir -p $DIR/$tdir
5931         createmany -o $DIR/$tdir/$tfile $NUMTEST
5932         unlinkmany $DIR/$tdir/$tfile $NUMTEST
5933
5934         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
5935             cut -c11-20)
5936
5937         # don't return an error
5938         [ $OSTIO_post == $OSTIO_pre ] && echo \
5939             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
5940             echo "This may be fine, depending on what ran before this test" &&
5941             echo "and how fast this system is." && return
5942
5943         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
5944 }
5945 run_test 115 "verify dynamic thread creation===================="
5946
5947 free_min_max () {
5948         wait_delete_completed
5949         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
5950         echo OST kbytes available: ${AVAIL[@]}
5951         MAXI=0; MAXV=${AVAIL[0]}
5952         MINI=0; MINV=${AVAIL[0]}
5953         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
5954             #echo OST $i: ${AVAIL[i]}kb
5955             if [ ${AVAIL[i]} -gt $MAXV ]; then
5956                 MAXV=${AVAIL[i]}; MAXI=$i
5957             fi
5958             if [ ${AVAIL[i]} -lt $MINV ]; then
5959                 MINV=${AVAIL[i]}; MINI=$i
5960             fi
5961         done
5962         echo Min free space: OST $MINI: $MINV
5963         echo Max free space: OST $MAXI: $MAXV
5964 }
5965
5966 test_116a() { # was previously test_116()
5967         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
5968
5969         echo -n "Free space priority "
5970         lctl get_param -n lov.*-clilov-*.qos_prio_free
5971         declare -a AVAIL
5972         free_min_max
5973         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI, skip" &&\
5974                 return
5975
5976         # generate uneven OSTs
5977         mkdir -p $DIR/$tdir/OST${MINI}
5978         declare -i FILL
5979         FILL=$(($MINV / 4))
5980         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
5981         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
5982         i=0
5983         while [ $FILL -gt 0 ]; do
5984             i=$(($i + 1))
5985             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
5986             FILL=$(($FILL - 2048))
5987             echo -n .
5988         done
5989         FILL=$(($MINV / 4))
5990         sync
5991         sleep_maxage
5992
5993         free_min_max
5994         DIFF=$(($MAXV - $MINV))
5995         DIFF2=$(($DIFF * 100 / $MINV))
5996         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
5997         if [ $DIFF2 -gt 20 ]; then
5998             echo "ok"
5999         else
6000             echo "failed - QOS mode won't be used"
6001             error_ignore "QOS imbalance criteria not met"
6002             return
6003         fi
6004
6005         MINI1=$MINI; MINV1=$MINV
6006         MAXI1=$MAXI; MAXV1=$MAXV
6007
6008         # now fill using QOS
6009         echo writing a bunch of files to QOS-assigned OSTs
6010         $SETSTRIPE -c 1 $DIR/$tdir
6011         i=0
6012         while [ $FILL -gt 0 ]; do
6013             i=$(($i + 1))
6014             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
6015             FILL=$(($FILL - 200))
6016             echo -n .
6017         done
6018         echo "wrote $i 200k files"
6019         sync
6020         sleep_maxage
6021
6022         echo "Note: free space may not be updated, so measurements might be off"
6023         free_min_max
6024         DIFF2=$(($MAXV - $MINV))
6025         echo "free space delta: orig $DIFF final $DIFF2"
6026         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6027         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6028         echo "Wrote $DIFF to smaller OST $MINI1"
6029         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6030         echo "Wrote $DIFF2 to larger OST $MAXI1"
6031         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
6032
6033         # Figure out which files were written where
6034         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6035                awk '/'$MINI1': / {print $2; exit}')
6036         echo $UUID
6037         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
6038         echo "$MINC files created on smaller OST $MINI1"
6039         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6040                awk '/'$MAXI1': / {print $2; exit}')
6041         echo $UUID
6042         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
6043         echo "$MAXC files created on larger OST $MAXI1"
6044         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
6045         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
6046
6047         rm -rf $DIR/$tdir
6048 }
6049 run_test 116a "stripe QOS: free space balance ==================="
6050
6051 test_116b() { # LU-2093
6052 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
6053         local old_rr
6054         old_rr=$(do_facet $SINGLEMDS lctl get_param -n lov.*mdtlov*.qos_threshold_rr)
6055         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr 0
6056         mkdir -p $DIR/$tdir
6057         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
6058         createmany -o $DIR/$tdir/f- 20 || error "can't create"
6059         do_facet $SINGLEMDS lctl set_param fail_loc=0
6060         rm -rf $DIR/$tdir
6061         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr $old_rr
6062 }
6063 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
6064
6065 test_117() # bug 10891
6066 {
6067         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
6068         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
6069         lctl set_param fail_loc=0x21e
6070         > $DIR/$tfile || error "truncate failed"
6071         lctl set_param fail_loc=0
6072         echo "Truncate succeeded."
6073         rm -f $DIR/$tfile
6074 }
6075 run_test 117 "verify fsfilt_extend =========="
6076
6077 export OLD_RESENDCOUNT=""
6078 set_resend_count () {
6079         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
6080         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
6081         lctl set_param -n $PROC_RESENDCOUNT $1
6082         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
6083 }
6084
6085 [ "$SLOW" = "no" ] && set_resend_count 4 # for reduce test_118* time (bug 14842)
6086
6087 # Reset async IO behavior after error case
6088 reset_async() {
6089         FILE=$DIR/reset_async
6090
6091         # Ensure all OSCs are cleared
6092         $SETSTRIPE -c -1 $FILE
6093         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
6094         sync
6095         rm $FILE
6096 }
6097
6098 test_118a() #bug 11710
6099 {
6100         reset_async
6101
6102         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6103         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6104         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6105
6106         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6107                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6108                 return 1;
6109         fi
6110         rm -f $DIR/$tfile
6111 }
6112 run_test 118a "verify O_SYNC works =========="
6113
6114 test_118b()
6115 {
6116         remote_ost_nodsh && skip "remote OST with nodsh" && return
6117
6118         reset_async
6119
6120         #define OBD_FAIL_OST_ENOENT 0x217
6121         set_nodes_failloc "$(osts_nodes)" 0x217
6122         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6123         RC=$?
6124         set_nodes_failloc "$(osts_nodes)" 0
6125         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6126         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6127                     grep -c writeback)
6128
6129         if [[ $RC -eq 0 ]]; then
6130                 error "Must return error due to dropped pages, rc=$RC"
6131                 return 1;
6132         fi
6133
6134         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6135                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6136                 return 1;
6137         fi
6138
6139         echo "Dirty pages not leaked on ENOENT"
6140
6141         # Due to the above error the OSC will issue all RPCs syncronously
6142         # until a subsequent RPC completes successfully without error.
6143         $MULTIOP $DIR/$tfile Ow4096yc
6144         rm -f $DIR/$tfile
6145
6146         return 0
6147 }
6148 run_test 118b "Reclaim dirty pages on fatal error =========="
6149
6150 test_118c()
6151 {
6152         remote_ost_nodsh && skip "remote OST with nodsh" && return
6153
6154         reset_async
6155
6156         #define OBD_FAIL_OST_EROFS               0x216
6157         set_nodes_failloc "$(osts_nodes)" 0x216
6158
6159         # multiop should block due to fsync until pages are written
6160         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6161         MULTIPID=$!
6162         sleep 1
6163
6164         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6165                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6166         fi
6167
6168         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6169                     grep -c writeback)
6170         if [[ $WRITEBACK -eq 0 ]]; then
6171                 error "No page in writeback, writeback=$WRITEBACK"
6172         fi
6173
6174         set_nodes_failloc "$(osts_nodes)" 0
6175         wait $MULTIPID
6176         RC=$?
6177         if [[ $RC -ne 0 ]]; then
6178                 error "Multiop fsync failed, rc=$RC"
6179         fi
6180
6181         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6182         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6183                     grep -c writeback)
6184         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6185                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6186         fi
6187
6188         rm -f $DIR/$tfile
6189         echo "Dirty pages flushed via fsync on EROFS"
6190         return 0
6191 }
6192 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
6193
6194 test_118d()
6195 {
6196         remote_ost_nodsh && skip "remote OST with nodsh" && return
6197
6198         reset_async
6199
6200         #define OBD_FAIL_OST_BRW_PAUSE_BULK
6201         set_nodes_failloc "$(osts_nodes)" 0x214
6202         # multiop should block due to fsync until pages are written
6203         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6204         MULTIPID=$!
6205         sleep 1
6206
6207         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6208                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6209         fi
6210
6211         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6212                     grep -c writeback)
6213         if [[ $WRITEBACK -eq 0 ]]; then
6214                 error "No page in writeback, writeback=$WRITEBACK"
6215         fi
6216
6217         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
6218         set_nodes_failloc "$(osts_nodes)" 0
6219
6220         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6221         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6222                     grep -c writeback)
6223         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6224                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6225         fi
6226
6227         rm -f $DIR/$tfile
6228         echo "Dirty pages gaurenteed flushed via fsync"
6229         return 0
6230 }
6231 run_test 118d "Fsync validation inject a delay of the bulk =========="
6232
6233 test_118f() {
6234         reset_async
6235
6236         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
6237         lctl set_param fail_loc=0x8000040a
6238
6239         # Should simulate EINVAL error which is fatal
6240         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6241         RC=$?
6242         if [[ $RC -eq 0 ]]; then
6243                 error "Must return error due to dropped pages, rc=$RC"
6244         fi
6245
6246         lctl set_param fail_loc=0x0
6247
6248         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6249         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6250         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6251                     grep -c writeback)
6252         if [[ $LOCKED -ne 0 ]]; then
6253                 error "Locked pages remain in cache, locked=$LOCKED"
6254         fi
6255
6256         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6257                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6258         fi
6259
6260         rm -f $DIR/$tfile
6261         echo "No pages locked after fsync"
6262
6263         reset_async
6264         return 0
6265 }
6266 run_test 118f "Simulate unrecoverable OSC side error =========="
6267
6268 test_118g() {
6269         reset_async
6270
6271         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
6272         lctl set_param fail_loc=0x406
6273
6274         # simulate local -ENOMEM
6275         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6276         RC=$?
6277
6278         lctl set_param fail_loc=0
6279         if [[ $RC -eq 0 ]]; then
6280                 error "Must return error due to dropped pages, rc=$RC"
6281         fi
6282
6283         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6284         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6285         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6286                         grep -c writeback)
6287         if [[ $LOCKED -ne 0 ]]; then
6288                 error "Locked pages remain in cache, locked=$LOCKED"
6289         fi
6290
6291         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6292                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6293         fi
6294
6295         rm -f $DIR/$tfile
6296         echo "No pages locked after fsync"
6297
6298         reset_async
6299         return 0
6300 }
6301 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
6302
6303 test_118h() {
6304         remote_ost_nodsh && skip "remote OST with nodsh" && return
6305
6306         reset_async
6307
6308         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6309         set_nodes_failloc "$(osts_nodes)" 0x20e
6310         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6311         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6312         RC=$?
6313
6314         set_nodes_failloc "$(osts_nodes)" 0
6315         if [[ $RC -eq 0 ]]; then
6316                 error "Must return error due to dropped pages, rc=$RC"
6317         fi
6318
6319         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6320         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6321         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6322                     grep -c writeback)
6323         if [[ $LOCKED -ne 0 ]]; then
6324                 error "Locked pages remain in cache, locked=$LOCKED"
6325         fi
6326
6327         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6328                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6329         fi
6330
6331         rm -f $DIR/$tfile
6332         echo "No pages locked after fsync"
6333
6334         return 0
6335 }
6336 run_test 118h "Verify timeout in handling recoverables errors  =========="
6337
6338 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
6339
6340 test_118i() {
6341         remote_ost_nodsh && skip "remote OST with nodsh" && return
6342
6343         reset_async
6344
6345         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6346         set_nodes_failloc "$(osts_nodes)" 0x20e
6347
6348         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6349         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6350         PID=$!
6351         sleep 5
6352         set_nodes_failloc "$(osts_nodes)" 0
6353
6354         wait $PID
6355         RC=$?
6356         if [[ $RC -ne 0 ]]; then
6357                 error "got error, but should be not, rc=$RC"
6358         fi
6359
6360         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6361         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6362         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6363         if [[ $LOCKED -ne 0 ]]; then
6364                 error "Locked pages remain in cache, locked=$LOCKED"
6365         fi
6366
6367         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6368                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6369         fi
6370
6371         rm -f $DIR/$tfile
6372         echo "No pages locked after fsync"
6373
6374         return 0
6375 }
6376 run_test 118i "Fix error before timeout in recoverable error  =========="
6377
6378 [ "$SLOW" = "no" ] && set_resend_count 4
6379
6380 test_118j() {
6381         remote_ost_nodsh && skip "remote OST with nodsh" && return
6382
6383         reset_async
6384
6385         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
6386         set_nodes_failloc "$(osts_nodes)" 0x220
6387
6388         # return -EIO from OST
6389         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6390         RC=$?
6391         set_nodes_failloc "$(osts_nodes)" 0x0
6392         if [[ $RC -eq 0 ]]; then
6393                 error "Must return error due to dropped pages, rc=$RC"
6394         fi
6395
6396         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6397         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6398         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6399         if [[ $LOCKED -ne 0 ]]; then
6400                 error "Locked pages remain in cache, locked=$LOCKED"
6401         fi
6402
6403         # in recoverable error on OST we want resend and stay until it finished
6404         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6405                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6406         fi
6407
6408         rm -f $DIR/$tfile
6409         echo "No pages locked after fsync"
6410
6411         return 0
6412 }
6413 run_test 118j "Simulate unrecoverable OST side error =========="
6414
6415 test_118k()
6416 {
6417         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
6418
6419         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6420         set_nodes_failloc "$(osts_nodes)" 0x20e
6421         mkdir -p $DIR/$tdir
6422
6423         for ((i=0;i<10;i++)); do
6424                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
6425                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
6426                 SLEEPPID=$!
6427                 sleep 0.500s
6428                 kill $SLEEPPID
6429                 wait $SLEEPPID
6430         done
6431
6432         set_nodes_failloc "$(osts_nodes)" 0
6433         rm -rf $DIR/$tdir
6434 }
6435 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
6436
6437 test_118l()
6438 {
6439         # LU-646
6440         mkdir -p $DIR/$tdir
6441         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
6442         rm -rf $DIR/$tdir
6443 }
6444 run_test 118l "fsync dir ========="
6445
6446 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
6447
6448 test_119a() # bug 11737
6449 {
6450         BSIZE=$((512 * 1024))
6451         directio write $DIR/$tfile 0 1 $BSIZE
6452         # We ask to read two blocks, which is more than a file size.
6453         # directio will indicate an error when requested and actual
6454         # sizes aren't equeal (a normal situation in this case) and
6455         # print actual read amount.
6456         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
6457         if [ "$NOB" != "$BSIZE" ]; then
6458                 error "read $NOB bytes instead of $BSIZE"
6459         fi
6460         rm -f $DIR/$tfile
6461 }
6462 run_test 119a "Short directIO read must return actual read amount"
6463
6464 test_119b() # bug 11737
6465 {
6466         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6467
6468         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
6469         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
6470         sync
6471         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
6472                 error "direct read failed"
6473         rm -f $DIR/$tfile
6474 }
6475 run_test 119b "Sparse directIO read must return actual read amount"
6476
6477 test_119c() # bug 13099
6478 {
6479         BSIZE=1048576
6480         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
6481         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
6482         rm -f $DIR/$tfile
6483 }
6484 run_test 119c "Testing for direct read hitting hole"
6485
6486 test_119d() # bug 15950
6487 {
6488         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
6489         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
6490         BSIZE=1048576
6491         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
6492         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
6493         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
6494         lctl set_param fail_loc=0x40d
6495         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
6496         pid_dio=$!
6497         sleep 1
6498         cat $DIR/$tfile > /dev/null &
6499         lctl set_param fail_loc=0
6500         pid_reads=$!
6501         wait $pid_dio
6502         log "the DIO writes have completed, now wait for the reads (should not block very long)"
6503         sleep 2
6504         [ -n "`ps h -p $pid_reads -o comm`" ] && \
6505         error "the read rpcs have not completed in 2s"
6506         rm -f $DIR/$tfile
6507         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
6508 }
6509 run_test 119d "The DIO path should try to send a new rpc once one is completed"
6510
6511 test_120a() {
6512         mkdir -p $DIR/$tdir
6513         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6514                skip "no early lock cancel on server" && return 0
6515         lru_resize_disable mdc
6516         lru_resize_disable osc
6517         cancel_lru_locks mdc
6518         stat $DIR/$tdir > /dev/null
6519         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6520         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6521         mkdir $DIR/$tdir/d1
6522         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6523         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6524         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6525         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6526         lru_resize_enable mdc
6527         lru_resize_enable osc
6528 }
6529 run_test 120a "Early Lock Cancel: mkdir test"
6530
6531 test_120b() {
6532         mkdir -p $DIR/$tdir
6533         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6534                skip "no early lock cancel on server" && return 0
6535         lru_resize_disable mdc
6536         lru_resize_disable osc
6537         cancel_lru_locks mdc
6538         stat $DIR/$tdir > /dev/null
6539         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6540         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6541         touch $DIR/$tdir/f1
6542         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6543         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6544         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6545         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6546         lru_resize_enable mdc
6547         lru_resize_enable osc
6548 }
6549 run_test 120b "Early Lock Cancel: create test"
6550
6551 test_120c() {
6552         mkdir -p $DIR/$tdir
6553         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6554                skip "no early lock cancel on server" && return 0
6555         lru_resize_disable mdc
6556         lru_resize_disable osc
6557         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
6558         touch $DIR/$tdir/d1/f1
6559         cancel_lru_locks mdc
6560         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
6561         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6562         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6563         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
6564         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6565         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6566         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6567         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6568         lru_resize_enable mdc
6569         lru_resize_enable osc
6570 }
6571 run_test 120c "Early Lock Cancel: link test"
6572
6573 test_120d() {
6574         mkdir -p $DIR/$tdir
6575         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6576                skip "no early lock cancel on server" && return 0
6577         lru_resize_disable mdc
6578         lru_resize_disable osc
6579         touch $DIR/$tdir
6580         cancel_lru_locks mdc
6581         stat $DIR/$tdir > /dev/null
6582         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6583         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6584         chmod a+x $DIR/$tdir
6585         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
6586         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
6587         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6588         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6589         lru_resize_enable mdc
6590         lru_resize_enable osc
6591 }
6592 run_test 120d "Early Lock Cancel: setattr test"
6593
6594 test_120e() {
6595         mkdir -p $DIR/$tdir
6596         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6597                skip "no early lock cancel on server" && return 0
6598         lru_resize_disable mdc
6599         lru_resize_disable osc
6600         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
6601         cancel_lru_locks mdc
6602         cancel_lru_locks osc
6603         dd if=$DIR/$tdir/f1 of=/dev/null
6604         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
6605         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6606               awk '/ldlm_cancel/ {print $2}'`
6607         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6608               awk '/ldlm_bl_callback/ {print $2}'`
6609         unlink $DIR/$tdir/f1
6610         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6611               awk '/ldlm_cancel/ {print $2}'`
6612         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6613               awk '/ldlm_bl_callback/ {print $2}'`
6614         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6615         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6616         lru_resize_enable mdc
6617         lru_resize_enable osc
6618 }
6619 run_test 120e "Early Lock Cancel: unlink test"
6620
6621 test_120f() {
6622         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6623                skip "no early lock cancel on server" && return 0
6624         mkdir -p $DIR/$tdir
6625         lru_resize_disable mdc
6626         lru_resize_disable osc
6627         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
6628         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
6629         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
6630         cancel_lru_locks mdc
6631         cancel_lru_locks osc
6632         dd if=$DIR/$tdir/d1/f1 of=/dev/null
6633         dd if=$DIR/$tdir/d2/f2 of=/dev/null
6634         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
6635         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6636               awk '/ldlm_cancel/ {print $2}'`
6637         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6638               awk '/ldlm_bl_callback/ {print $2}'`
6639         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
6640         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6641               awk '/ldlm_cancel/ {print $2}'`
6642         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6643               awk '/ldlm_bl_callback/ {print $2}'`
6644         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
6645         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
6646         lru_resize_enable mdc
6647         lru_resize_enable osc
6648 }
6649 run_test 120f "Early Lock Cancel: rename test"
6650
6651 test_120g() {
6652         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
6653                skip "no early lock cancel on server" && return 0
6654         lru_resize_disable mdc
6655         lru_resize_disable osc
6656         count=10000
6657         echo create $count files
6658         mkdir -p $DIR/$tdir
6659         cancel_lru_locks mdc
6660         cancel_lru_locks osc
6661         t0=`date +%s`
6662
6663         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6664               awk '/ldlm_cancel/ {print $2}'`
6665         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6666               awk '/ldlm_bl_callback/ {print $2}'`
6667         createmany -o $DIR/$tdir/f $count
6668         sync
6669         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6670               awk '/ldlm_cancel/ {print $2}'`
6671         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6672               awk '/ldlm_bl_callback/ {print $2}'`
6673         t1=`date +%s`
6674         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
6675         echo rm $count files
6676         rm -r $DIR/$tdir
6677         sync
6678         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
6679               awk '/ldlm_cancel/ {print $2}'`
6680         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
6681               awk '/ldlm_bl_callback/ {print $2}'`
6682         t2=`date +%s`
6683         echo total: $count removes in $((t2-t1))
6684         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
6685         sleep 2
6686         # wait for commitment of removal
6687         lru_resize_enable mdc
6688         lru_resize_enable osc
6689 }
6690 run_test 120g "Early Lock Cancel: performance test"
6691
6692 test_121() { #bug #10589
6693         rm -rf $DIR/$tfile
6694         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
6695 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
6696         lctl set_param fail_loc=0x310
6697         cancel_lru_locks osc > /dev/null
6698         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
6699         lctl set_param fail_loc=0
6700         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
6701 }
6702 run_test 121 "read cancel race ========="
6703
6704 test_123a() { # was test 123, statahead(bug 11401)
6705         SLOWOK=0
6706         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
6707             log "testing on UP system. Performance may be not as good as expected."
6708                         SLOWOK=1
6709         fi
6710
6711         rm -rf $DIR/$tdir
6712         mkdir -p $DIR/$tdir
6713         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6714         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
6715         MULT=10
6716         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
6717                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
6718
6719                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
6720                 lctl set_param -n llite.*.statahead_max 0
6721                 lctl get_param llite.*.statahead_max
6722                 cancel_lru_locks mdc
6723                 cancel_lru_locks osc
6724                 stime=`date +%s`
6725                 time ls -l $DIR/$tdir | wc -l
6726                 etime=`date +%s`
6727                 delta=$((etime - stime))
6728                 log "ls $i files without statahead: $delta sec"
6729                 lctl set_param llite.*.statahead_max=$max
6730
6731                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
6732                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
6733                 cancel_lru_locks mdc
6734                 cancel_lru_locks osc
6735                 stime=`date +%s`
6736                 time ls -l $DIR/$tdir | wc -l
6737                 etime=`date +%s`
6738                 delta_sa=$((etime - stime))
6739                 log "ls $i files with statahead: $delta_sa sec"
6740                 lctl get_param -n llite.*.statahead_stats
6741                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
6742
6743                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
6744                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
6745
6746                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
6747                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
6748                     lctl set_param -n llite.*.statahead_max 0
6749                     lctl get_param llite.*.statahead_max
6750                     cancel_lru_locks mdc
6751                     cancel_lru_locks osc
6752                     stime=`date +%s`
6753                     time ls -l $DIR/$tdir | wc -l
6754                     etime=`date +%s`
6755                     delta=$((etime - stime))
6756                     log "ls $i files again without statahead: $delta sec"
6757                     lctl set_param llite.*.statahead_max=$max
6758                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
6759                         if [  $SLOWOK -eq 0 ]; then
6760                                 error "ls $i files is slower with statahead!"
6761                         else
6762                                 log "ls $i files is slower with statahead!"
6763                         fi
6764                         break
6765                     fi
6766                 fi
6767
6768                 [ $delta -gt 20 ] && break
6769                 [ $delta -gt 8 ] && MULT=$((50 / delta))
6770                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
6771         done
6772         log "ls done"
6773
6774         stime=`date +%s`
6775         rm -r $DIR/$tdir
6776         sync
6777         etime=`date +%s`
6778         delta=$((etime - stime))
6779         log "rm -r $DIR/$tdir/: $delta seconds"
6780         log "rm done"
6781         lctl get_param -n llite.*.statahead_stats
6782 }
6783 run_test 123a "verify statahead work"
6784
6785 test_123b () { # statahead(bug 15027)
6786         mkdir -p $DIR/$tdir
6787         createmany -o $DIR/$tdir/$tfile-%d 1000
6788
6789         cancel_lru_locks mdc
6790         cancel_lru_locks osc
6791
6792 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
6793         lctl set_param fail_loc=0x80000803
6794         ls -lR $DIR/$tdir > /dev/null
6795         log "ls done"
6796         lctl set_param fail_loc=0x0
6797         lctl get_param -n llite.*.statahead_stats
6798         rm -r $DIR/$tdir
6799         sync
6800
6801 }
6802 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
6803
6804 test_124a() {
6805         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
6806                skip "no lru resize on server" && return 0
6807         local NR=2000
6808         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
6809
6810         log "create $NR files at $DIR/$tdir"
6811         createmany -o $DIR/$tdir/f $NR ||
6812                 error "failed to create $NR files in $DIR/$tdir"
6813
6814         cancel_lru_locks mdc
6815         ls -l $DIR/$tdir > /dev/null
6816
6817         local NSDIR=""
6818         local LRU_SIZE=0
6819         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
6820                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6821                 LRU_SIZE=$(lctl get_param -n $PARAM)
6822                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
6823                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
6824                                                 log "NSDIR=$NSDIR"
6825                         log "NS=$(basename $NSDIR)"
6826                         break
6827                 fi
6828         done
6829
6830         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
6831                 skip "Not enough cached locks created!"
6832                 return 0
6833         fi
6834         log "LRU=$LRU_SIZE"
6835
6836         local SLEEP=30
6837
6838         # We know that lru resize allows one client to hold $LIMIT locks
6839         # for 10h. After that locks begin to be killed by client.
6840         local MAX_HRS=10
6841         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
6842                 log "LIMIT=$LIMIT"
6843
6844         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
6845         # killing locks. Some time was spent for creating locks. This means
6846         # that up to the moment of sleep finish we must have killed some of
6847         # them (10-100 locks). This depends on how fast ther were created.
6848         # Many of them were touched in almost the same moment and thus will
6849         # be killed in groups.
6850         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
6851
6852         # Use $LRU_SIZE_B here to take into account real number of locks
6853         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
6854         local LRU_SIZE_B=$LRU_SIZE
6855         log "LVF=$LVF"
6856         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
6857                 log "OLD_LVF=$OLD_LVF"
6858         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
6859
6860         # Let's make sure that we really have some margin. Client checks
6861         # cached locks every 10 sec.
6862         SLEEP=$((SLEEP+20))
6863         log "Sleep ${SLEEP} sec"
6864         local SEC=0
6865         while ((SEC<$SLEEP)); do
6866                 echo -n "..."
6867                 sleep 5
6868                 SEC=$((SEC+5))
6869                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
6870                 echo -n "$LRU_SIZE"
6871         done
6872         echo ""
6873         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
6874         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
6875
6876         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
6877                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
6878                 unlinkmany $DIR/$tdir/f $NR
6879                 return
6880         }
6881
6882         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
6883         log "unlink $NR files at $DIR/$tdir"
6884         unlinkmany $DIR/$tdir/f $NR
6885 }
6886 run_test 124a "lru resize ======================================="
6887
6888 get_max_pool_limit()
6889 {
6890         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
6891         local max=0
6892         for l in $limit; do
6893                 if test $l -gt $max; then
6894                         max=$l
6895                 fi
6896         done
6897         echo $max
6898 }
6899
6900 test_124b() {
6901         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
6902                skip "no lru resize on server" && return 0
6903
6904         LIMIT=`get_max_pool_limit`
6905
6906         NR=$(($(default_lru_size)*20))
6907         if [ $NR -gt $LIMIT ]; then
6908                 log "Limit lock number by $LIMIT locks"
6909                 NR=$LIMIT
6910         fi
6911         lru_resize_disable mdc
6912         mkdir -p $DIR/$tdir/disable_lru_resize ||
6913                 error "failed to create $DIR/$tdir/disable_lru_resize"
6914
6915         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
6916         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
6917         cancel_lru_locks mdc
6918         stime=`date +%s`
6919         PID=""
6920         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6921         PID="$PID $!"
6922         sleep 2
6923         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6924         PID="$PID $!"
6925         sleep 2
6926         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
6927         PID="$PID $!"
6928         wait $PID
6929         etime=`date +%s`
6930         nolruresize_delta=$((etime-stime))
6931         log "ls -la time: $nolruresize_delta seconds"
6932         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
6933         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
6934
6935         lru_resize_enable mdc
6936         mkdir -p $DIR/$tdir/enable_lru_resize ||
6937                 error "failed to create $DIR/$tdir/enable_lru_resize"
6938
6939         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
6940         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
6941         cancel_lru_locks mdc
6942         stime=`date +%s`
6943         PID=""
6944         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6945         PID="$PID $!"
6946         sleep 2
6947         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6948         PID="$PID $!"
6949         sleep 2
6950         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
6951         PID="$PID $!"
6952         wait $PID
6953         etime=`date +%s`
6954         lruresize_delta=$((etime-stime))
6955         log "ls -la time: $lruresize_delta seconds"
6956         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
6957
6958         if [ $lruresize_delta -gt $nolruresize_delta ]; then
6959                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
6960         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
6961                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
6962         else
6963                 log "lru resize performs the same with no lru resize"
6964         fi
6965         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
6966 }
6967 run_test 124b "lru resize (performance test) ======================="
6968
6969 test_125() { # 13358
6970         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
6971         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
6972         mkdir -p $DIR/d125 || error "mkdir failed"
6973         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
6974         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
6975         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
6976 }
6977 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
6978
6979 test_126() { # bug 12829/13455
6980         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
6981         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
6982         $GSS && skip "must run as gss disabled" && return
6983
6984         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
6985         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
6986         rm -f $DIR/$tfile
6987         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
6988 }
6989 run_test 126 "check that the fsgid provided by the client is taken into account"
6990
6991 test_127a() { # bug 15521
6992         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
6993         $LCTL set_param osc.*.stats=0
6994         FSIZE=$((2048 * 1024))
6995         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
6996         cancel_lru_locks osc
6997         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
6998
6999         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
7000         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7001                 echo "got $COUNT $NAME"
7002                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
7003                 eval $NAME=$COUNT || error "Wrong proc format"
7004
7005                 case $NAME in
7006                         read_bytes|write_bytes)
7007                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
7008                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
7009                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
7010                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
7011                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
7012                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
7013                                 error "sumsquare is too small: $SUMSQ"
7014                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
7015                                 error "sumsquare is too big: $SUMSQ"
7016                         ;;
7017                         *) ;;
7018                 esac
7019         done < $DIR/${tfile}.tmp
7020
7021         #check that we actually got some stats
7022         [ "$read_bytes" ] || error "Missing read_bytes stats"
7023         [ "$write_bytes" ] || error "Missing write_bytes stats"
7024         [ "$read_bytes" != 0 ] || error "no read done"
7025         [ "$write_bytes" != 0 ] || error "no write done"
7026 }
7027 run_test 127a "verify the client stats are sane"
7028
7029 test_127b() { # bug LU-333
7030         $LCTL set_param llite.*.stats=0
7031         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
7032         # perform 2 reads and writes so MAX is different from SUM.
7033         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7034         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7035         cancel_lru_locks osc
7036         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7037         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7038
7039         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
7040         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7041                 echo "got $COUNT $NAME"
7042                 eval $NAME=$COUNT || error "Wrong proc format"
7043
7044         case $NAME in
7045                 read_bytes)
7046                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7047                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7048                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7049                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7050                         ;;
7051                 write_bytes)
7052                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7053                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7054                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7055                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7056                         ;;
7057                         *) ;;
7058                 esac
7059         done < $TMP/${tfile}.tmp
7060
7061         #check that we actually got some stats
7062         [ "$read_bytes" ] || error "Missing read_bytes stats"
7063         [ "$write_bytes" ] || error "Missing write_bytes stats"
7064         [ "$read_bytes" != 0 ] || error "no read done"
7065         [ "$write_bytes" != 0 ] || error "no write done"
7066 }
7067 run_test 127b "verify the llite client stats are sane"
7068
7069 test_128() { # bug 15212
7070         touch $DIR/$tfile
7071         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
7072                 find $DIR/$tfile
7073                 find $DIR/$tfile
7074         EOF
7075
7076         result=$(grep error $TMP/$tfile.log)
7077         rm -f $DIR/$tfile
7078         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
7079 }
7080 run_test 128 "interactive lfs for 2 consecutive find's"
7081
7082 set_dir_limits () {
7083         local mntdev
7084         local canondev
7085         local node
7086
7087         local LDPROC=/proc/fs/ldiskfs
7088
7089         for facet in $(get_facets MDS); do
7090                 canondev=$(ldiskfs_canon *.$(convert_facet2label $facet).mntdev $facet)
7091                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" || LDPROC=/sys/fs/ldiskfs
7092                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
7093         done
7094 }
7095 test_129() {
7096         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
7097                 skip "Only applicable to ldiskfs-based MDTs"
7098                 return
7099         fi
7100         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7101
7102         EFBIG=27
7103         MAX=16384
7104
7105         set_dir_limits $MAX
7106
7107         mkdir -p $DIR/$tdir
7108
7109         I=0
7110         J=0
7111         while [ ! $I -gt $((MAX * MDSCOUNT)) ]; do
7112                 $MULTIOP $DIR/$tdir/$J Oc
7113                 rc=$?
7114                 if [ $rc -eq $EFBIG ]; then
7115                         set_dir_limits 0
7116                         echo "return code $rc received as expected"
7117                         return 0
7118                 elif [ $rc -ne 0 ]; then
7119                         set_dir_limits 0
7120                         error_exit "return code $rc received instead of expected $EFBIG"
7121                 fi
7122                 J=$((J+1))
7123                 I=$(stat -c%s "$DIR/$tdir")
7124         done
7125
7126         set_dir_limits 0
7127         error "exceeded dir size limit $MAX x $MDSCOUNT $((MAX * MDSCOUNT)) : $I bytes"
7128 }
7129 run_test 129 "test directory size limit ========================"
7130
7131 OLDIFS="$IFS"
7132 cleanup_130() {
7133         trap 0
7134         IFS="$OLDIFS"
7135 }
7136
7137 test_130a() {
7138         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7139         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
7140                 return
7141
7142         trap cleanup_130 EXIT RETURN
7143
7144         local fm_file=$DIR/$tfile
7145         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
7146         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
7147                 error "dd failed for $fm_file"
7148
7149         # LU-1795: test filefrag/FIEMAP once, even if unsupported
7150         filefrag -ves $fm_file
7151         RC=$?
7152         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7153                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7154         [ $RC != 0 ] && error "filefrag $fm_file failed"
7155
7156         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
7157                       grep -v "ext:" | grep -v "found")
7158         lun=$($GETSTRIPE -i $fm_file)
7159
7160         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
7161         IFS=$'\n'
7162         tot_len=0
7163         for line in $filefrag_op
7164         do
7165                 frag_lun=`echo $line | cut -d: -f5`
7166                 ext_len=`echo $line | cut -d: -f4`
7167                 if (( $frag_lun != $lun )); then
7168                         cleanup_130
7169                         error "FIEMAP on 1-stripe file($fm_file) failed"
7170                         return
7171                 fi
7172                 (( tot_len += ext_len ))
7173         done
7174
7175         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
7176                 cleanup_130
7177                 error "FIEMAP on 1-stripe file($fm_file) failed;"
7178                 return
7179         fi
7180
7181         cleanup_130
7182
7183         echo "FIEMAP on single striped file succeeded"
7184 }
7185 run_test 130a "FIEMAP (1-stripe file)"
7186
7187 test_130b() {
7188         [ "$OSTCOUNT" -lt "2" ] &&
7189                 skip_env "skipping FIEMAP on 2-stripe file test" && return
7190
7191         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7192         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
7193                 return
7194
7195         trap cleanup_130 EXIT RETURN
7196
7197         local fm_file=$DIR/$tfile
7198         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7199         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7200                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7201
7202         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
7203                 error "dd failed on $fm_file"
7204
7205         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7206         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
7207                       grep -v "ext:" | grep -v "found")
7208
7209         last_lun=$(echo $filefrag_op | cut -d: -f5)
7210
7211         IFS=$'\n'
7212         tot_len=0
7213         num_luns=1
7214         for line in $filefrag_op
7215         do
7216                 frag_lun=`echo $line | cut -d: -f5`
7217                 ext_len=`echo $line | cut -d: -f4`
7218                 if (( $frag_lun != $last_lun )); then
7219                         if (( tot_len != 1024 )); then
7220                                 cleanup_130
7221                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
7222                                 return
7223                         else
7224                                 (( num_luns += 1 ))
7225                                 tot_len=0
7226                         fi
7227                 fi
7228                 (( tot_len += ext_len ))
7229                 last_lun=$frag_lun
7230         done
7231         if (( num_luns != 2 || tot_len != 1024 )); then
7232                 cleanup_130
7233                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7234                 return
7235         fi
7236
7237         cleanup_130
7238
7239         echo "FIEMAP on 2-stripe file succeeded"
7240 }
7241 run_test 130b "FIEMAP (2-stripe file)"
7242
7243 test_130c() {
7244         [ "$OSTCOUNT" -lt "2" ] &&
7245                 skip_env "skipping FIEMAP on 2-stripe file" && return
7246
7247         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7248         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
7249                 return
7250
7251         trap cleanup_130 EXIT RETURN
7252
7253         local fm_file=$DIR/$tfile
7254         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7255         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7256                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7257
7258         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
7259
7260         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7261         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7262
7263         last_lun=`echo $filefrag_op | cut -d: -f5`
7264
7265         IFS=$'\n'
7266         tot_len=0
7267         num_luns=1
7268         for line in $filefrag_op
7269         do
7270                 frag_lun=`echo $line | cut -d: -f5`
7271                 ext_len=`echo $line | cut -d: -f4`
7272                 if (( $frag_lun != $last_lun )); then
7273                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
7274                         if (( logical != 512 )); then
7275                                 cleanup_130
7276                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
7277                                 return
7278                         fi
7279                         if (( tot_len != 512 )); then
7280                                 cleanup_130
7281                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7282                                 return
7283                         else
7284                                 (( num_luns += 1 ))
7285                                 tot_len=0
7286                         fi
7287                 fi
7288                 (( tot_len += ext_len ))
7289                 last_lun=$frag_lun
7290         done
7291         if (( num_luns != 2 || tot_len != 512 )); then
7292                 cleanup_130
7293                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7294                 return
7295         fi
7296
7297         cleanup_130
7298
7299         echo "FIEMAP on 2-stripe file with hole succeeded"
7300 }
7301 run_test 130c "FIEMAP (2-stripe file with hole)"
7302
7303 test_130d() {
7304         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
7305
7306         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7307         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7308
7309         trap cleanup_130 EXIT RETURN
7310
7311         local fm_file=$DIR/$tfile
7312         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
7313         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7314                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7315         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
7316
7317         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7318         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7319
7320         last_lun=`echo $filefrag_op | cut -d: -f5`
7321
7322         IFS=$'\n'
7323         tot_len=0
7324         num_luns=1
7325         for line in $filefrag_op
7326         do
7327                 frag_lun=`echo $line | cut -d: -f5`
7328                 ext_len=`echo $line | cut -d: -f4`
7329                 if (( $frag_lun != $last_lun )); then
7330                         if (( tot_len != 1024 )); then
7331                                 cleanup_130
7332                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7333                                 return
7334                         else
7335                                 (( num_luns += 1 ))
7336                                 tot_len=0
7337                         fi
7338                 fi
7339                 (( tot_len += ext_len ))
7340                 last_lun=$frag_lun
7341         done
7342         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
7343                 cleanup_130
7344                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7345                 return
7346         fi
7347
7348         cleanup_130
7349
7350         echo "FIEMAP on N-stripe file succeeded"
7351 }
7352 run_test 130d "FIEMAP (N-stripe file)"
7353
7354 test_130e() {
7355         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
7356
7357         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7358         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7359
7360         trap cleanup_130 EXIT RETURN
7361
7362         local fm_file=$DIR/$tfile
7363         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
7364         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7365                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7366
7367         NUM_BLKS=512
7368         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
7369         for ((i = 0; i < $NUM_BLKS; i++))
7370         do
7371                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
7372         done
7373
7374         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7375         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
7376
7377         last_lun=`echo $filefrag_op | cut -d: -f5`
7378
7379         IFS=$'\n'
7380         tot_len=0
7381         num_luns=1
7382         for line in $filefrag_op
7383         do
7384                 frag_lun=`echo $line | cut -d: -f5`
7385                 ext_len=`echo $line | cut -d: -f4`
7386                 if (( $frag_lun != $last_lun )); then
7387                         if (( tot_len != $EXPECTED_LEN )); then
7388                                 cleanup_130
7389                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
7390                                 return
7391                         else
7392                                 (( num_luns += 1 ))
7393                                 tot_len=0
7394                         fi
7395                 fi
7396                 (( tot_len += ext_len ))
7397                 last_lun=$frag_lun
7398         done
7399         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
7400                 cleanup_130
7401                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7402                 return
7403         fi
7404
7405         cleanup_130
7406
7407         echo "FIEMAP with continuation calls succeeded"
7408 }
7409 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
7410
7411 # Test for writev/readv
7412 test_131a() {
7413         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
7414         error "writev test failed"
7415         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
7416         error "readv failed"
7417         rm -f $DIR/$tfile
7418 }
7419 run_test 131a "test iov's crossing stripe boundary for writev/readv"
7420
7421 test_131b() {
7422         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
7423         error "append writev test failed"
7424         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
7425         error "append writev test failed"
7426         rm -f $DIR/$tfile
7427 }
7428 run_test 131b "test append writev"
7429
7430 test_131c() {
7431         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
7432         error "NOT PASS"
7433 }
7434 run_test 131c "test read/write on file w/o objects"
7435
7436 test_131d() {
7437         rwv -f $DIR/$tfile -w -n 1 1572864
7438         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
7439         if [ "$NOB" != 1572864 ]; then
7440                 error "Short read filed: read $NOB bytes instead of 1572864"
7441         fi
7442         rm -f $DIR/$tfile
7443 }
7444 run_test 131d "test short read"
7445
7446 test_131e() {
7447         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
7448         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
7449         error "read hitting hole failed"
7450         rm -f $DIR/$tfile
7451 }
7452 run_test 131e "test read hitting hole"
7453
7454 get_ost_param() {
7455         local token=$1
7456         local gl_sum=0
7457         for node in $(osts_nodes); do
7458                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
7459                 [ x$gl = x"" ] && gl=0
7460                 gl_sum=$((gl_sum + gl))
7461         done
7462         echo $gl
7463 }
7464
7465 som_mode_switch() {
7466         local som=$1
7467         local gl1=$2
7468         local gl2=$3
7469
7470         if [ x$som = x"enabled" ]; then
7471                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
7472                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
7473                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
7474         else
7475                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
7476                 MOUNTOPT="$MOUNTOPT,som_preview"
7477                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
7478         fi
7479
7480         # do remount to make new mount-conf parameters actual
7481         echo remounting...
7482         sync
7483         stopall
7484         setupall
7485 }
7486
7487 test_132() { #1028, SOM
7488         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7489         local num=$(get_mds_dir $DIR)
7490         local mymds=mds${num}
7491         local MOUNTOPT_SAVE=$MOUNTOPT
7492
7493         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
7494         cancel_lru_locks osc
7495
7496         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
7497
7498         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
7499         stat $DIR/$tfile >/dev/null
7500         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
7501         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
7502         rm $DIR/$tfile
7503         som_mode_switch $som1 $gl1 $gl2
7504
7505         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
7506         cancel_lru_locks osc
7507
7508         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
7509         if [ $som1 == $som2 ]; then
7510             error "som is still "$som2
7511             if [ x$som2 = x"enabled" ]; then
7512                 som2="disabled"
7513             else
7514                 som2="enabled"
7515             fi
7516         fi
7517
7518         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
7519         stat $DIR/$tfile >/dev/null
7520         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
7521         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
7522         som_mode_switch $som2 $gl1 $gl2
7523         MOUNTOPT=$MOUNTOPT_SAVE
7524 }
7525 run_test 132 "som avoids glimpse rpc"
7526
7527 check_stats() {
7528         local res
7529         local count
7530         case $1 in
7531         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
7532                  ;;
7533         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
7534                  ;;
7535         *) error "Wrong argument $1" ;;
7536         esac
7537         echo $res
7538         count=`echo $res | awk '{print $2}'`
7539         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
7540         # if the argument $3 is zero, it means any stat increment is ok.
7541         if [ $3 -gt 0 ] ; then
7542                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
7543         fi
7544 }
7545
7546 test_133a() {
7547         remote_ost_nodsh && skip "remote OST with nodsh" && return
7548         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7549
7550         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
7551                 { skip "MDS doesn't support rename stats"; return; }
7552         local testdir=$DIR/${tdir}/stats_testdir
7553         mkdir -p $DIR/${tdir}
7554
7555         # clear stats.
7556         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7557         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7558
7559         # verify mdt stats first.
7560         mkdir ${testdir} || error "mkdir failed"
7561         check_stats $SINGLEMDS "mkdir" 1
7562         touch ${testdir}/${tfile} || "touch failed"
7563         check_stats $SINGLEMDS "open" 1
7564         check_stats $SINGLEMDS "close" 1
7565         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
7566         check_stats $SINGLEMDS "mknod" 1
7567         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
7568         check_stats $SINGLEMDS "unlink" 1
7569         rm -f ${testdir}/${tfile} || error "file remove failed"
7570         check_stats $SINGLEMDS "unlink" 2
7571
7572         # remove working dir and check mdt stats again.
7573         rmdir ${testdir} || error "rmdir failed"
7574         check_stats $SINGLEMDS "rmdir" 1
7575
7576         local testdir1=$DIR/${tdir}/stats_testdir1
7577         mkdir -p ${testdir}
7578         mkdir -p ${testdir1}
7579         touch ${testdir1}/test1
7580         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
7581         check_stats $SINGLEMDS "crossdir_rename" 1
7582
7583         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
7584         check_stats $SINGLEMDS "samedir_rename" 1
7585
7586         rm -rf $DIR/${tdir}
7587 }
7588 run_test 133a "Verifying MDT stats ========================================"
7589
7590 test_133b() {
7591         remote_ost_nodsh && skip "remote OST with nodsh" && return
7592         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7593         local testdir=$DIR/${tdir}/stats_testdir
7594         mkdir -p ${testdir} || error "mkdir failed"
7595         touch ${testdir}/${tfile} || "touch failed"
7596         cancel_lru_locks mdc
7597
7598         # clear stats.
7599         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7600         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7601
7602         # extra mdt stats verification.
7603         chmod 444 ${testdir}/${tfile} || error "chmod failed"
7604         check_stats $SINGLEMDS "setattr" 1
7605         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7606         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
7607         then            # LU-1740
7608                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
7609                 check_stats $SINGLEMDS "getattr" 1
7610         fi
7611         $LFS df || error "lfs failed"
7612         check_stats $SINGLEMDS "statfs" 1
7613
7614         rm -rf $DIR/${tdir}
7615 }
7616 run_test 133b "Verifying extra MDT stats =================================="
7617
7618 test_133c() {
7619         remote_ost_nodsh && skip "remote OST with nodsh" && return
7620         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7621         local testdir=$DIR/${tdir}/stats_testdir
7622         mkdir -p ${testdir} || error "mkdir failed"
7623
7624         # verify obdfilter stats.
7625         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
7626         sync
7627         cancel_lru_locks osc
7628         wait_delete_completed
7629
7630         # clear stats.
7631         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
7632         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
7633
7634         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
7635         sync
7636         cancel_lru_locks osc
7637         check_stats ost "write" 1
7638
7639         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
7640         check_stats ost "read" 1
7641
7642         > ${testdir}/${tfile} || error "truncate failed"
7643         check_stats ost "punch" 1
7644
7645         rm -f ${testdir}/${tfile} || error "file remove failed"
7646         wait_delete_completed
7647         check_stats ost "destroy" 1
7648
7649         rm -rf $DIR/${tdir}
7650 }
7651 run_test 133c "Verifying OST stats ========================================"
7652
7653 order_2() {
7654     local value=$1
7655     local orig=$value
7656     local order=1
7657
7658     while [ $value -ge 2 ]; do
7659         order=$((order*2))
7660         value=$((value/2))
7661     done
7662
7663     if [ $orig -gt $order ]; then
7664         order=$((order*2))
7665     fi
7666     echo $order
7667 }
7668
7669 size_in_KMGT() {
7670     local value=$1
7671     local size=('K' 'M' 'G' 'T');
7672     local i=0
7673     local size_string=$value
7674
7675     while [ $value -ge 1024 ]; do
7676         if [ $i -gt 3 ]; then
7677             #T is the biggest unit we get here, if that is bigger,
7678             #just return XXXT
7679             size_string=${value}T
7680             break
7681         fi
7682         value=$((value >> 10))
7683         if [ $value -lt 1024 ]; then
7684             size_string=${value}${size[$i]}
7685             break
7686         fi
7687         i=$((i + 1))
7688     done
7689
7690     echo $size_string
7691 }
7692
7693 get_rename_size() {
7694     local size=$1
7695     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
7696                    awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
7697     echo $sample
7698 }
7699
7700 test_133d() {
7701     remote_ost_nodsh && skip "remote OST with nodsh" && return
7702     remote_mds_nodsh && skip "remote MDS with nodsh" && return
7703     do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
7704         { skip "MDS doesn't support rename stats"; return; }
7705
7706     local testdir1=$DIR/${tdir}/stats_testdir1
7707     local testdir2=$DIR/${tdir}/stats_testdir2
7708
7709     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
7710
7711     mkdir -p ${testdir1} || error "mkdir failed"
7712     mkdir -p ${testdir2} || error "mkdir failed"
7713
7714     createmany -o $testdir1/test 512 || error "createmany failed"
7715
7716         # check samedir rename size
7717         mv ${testdir1}/test0 ${testdir1}/test_0
7718
7719         local testdir1_size=$(ls -l $DIR/${tdir} |
7720                 awk '/stats_testdir1/ {print $5}')
7721         local testdir2_size=$(ls -l $DIR/${tdir} |
7722                 awk '/stats_testdir2/ {print $5}')
7723
7724         testdir1_size=$(order_2 $testdir1_size)
7725         testdir2_size=$(order_2 $testdir2_size)
7726
7727         testdir1_size=$(size_in_KMGT $testdir1_size)
7728         testdir2_size=$(size_in_KMGT $testdir2_size)
7729
7730         echo "source rename dir size: ${testdir1_size}"
7731         echo "target rename dir size: ${testdir2_size}"
7732
7733     local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
7734     eval $cmd || error "$cmd failed"
7735     local samedir=$($cmd | grep 'same_dir')
7736     local same_sample=$(get_rename_size $testdir1_size)
7737     [ -z "$samedir" ] && error "samedir_rename_size count error"
7738     [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
7739     echo "Check same dir rename stats success"
7740
7741     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
7742
7743     # check crossdir rename size
7744     mv ${testdir1}/test_0 ${testdir2}/test_0
7745
7746         testdir1_size=$(ls -l $DIR/${tdir} |
7747                 awk '/stats_testdir1/ {print $5}')
7748         testdir2_size=$(ls -l $DIR/${tdir} |
7749                 awk '/stats_testdir2/ {print $5}')
7750
7751         testdir1_size=$(order_2 $testdir1_size)
7752         testdir2_size=$(order_2 $testdir2_size)
7753
7754         testdir1_size=$(size_in_KMGT $testdir1_size)
7755         testdir2_size=$(size_in_KMGT $testdir2_size)
7756
7757         echo "source rename dir size: ${testdir1_size}"
7758         echo "target rename dir size: ${testdir2_size}"
7759
7760     eval $cmd || error "$cmd failed"
7761     local crossdir=$($cmd | grep 'crossdir')
7762     local src_sample=$(get_rename_size $testdir1_size)
7763     local tgt_sample=$(get_rename_size $testdir2_size)
7764     [ -z "$crossdir" ] && error "crossdir_rename_size count error"
7765     [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
7766     [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
7767     echo "Check cross dir rename stats success"
7768     rm -rf $DIR/${tdir}
7769 }
7770 run_test 133d "Verifying rename_stats ========================================"
7771
7772 test_140() { #bug-17379
7773         mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
7774         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
7775         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
7776
7777         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
7778         local i=0
7779         while i=`expr $i + 1`; do
7780                 mkdir -p $i || error "Creating dir $i"
7781                 cd $i || error "Changing to $i"
7782                 ln -s ../stat stat || error "Creating stat symlink"
7783                 # Read the symlink until ELOOP present,
7784                 # not LBUGing the system is considered success,
7785                 # we didn't overrun the stack.
7786                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
7787                 [ $ret -ne 0 ] && {
7788                         if [ $ret -eq 40 ]; then
7789                                 break  # -ELOOP
7790                         else
7791                                 error "Open stat symlink"
7792                                 return
7793                         fi
7794                 }
7795         done
7796         i=`expr $i - 1`
7797         echo "The symlink depth = $i"
7798         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 ] || error "Invalid symlink depth"
7799 }
7800 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
7801
7802 test_150() {
7803         local TF="$TMP/$tfile"
7804
7805         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
7806         cp $TF $DIR/$tfile
7807         cancel_lru_locks osc
7808         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
7809         remount_client $MOUNT
7810         df -P $MOUNT
7811         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
7812
7813         $TRUNCATE $TF 6000
7814         $TRUNCATE $DIR/$tfile 6000
7815         cancel_lru_locks osc
7816         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
7817
7818         echo "12345" >>$TF
7819         echo "12345" >>$DIR/$tfile
7820         cancel_lru_locks osc
7821         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
7822
7823         echo "12345" >>$TF
7824         echo "12345" >>$DIR/$tfile
7825         cancel_lru_locks osc
7826         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
7827
7828         rm -f $TF
7829         true
7830 }
7831 run_test 150 "truncate/append tests"
7832
7833 function roc_hit() {
7834         local list=$(comma_list $(osts_nodes))
7835
7836         echo $(get_obdfilter_param $list '' stats |
7837                awk '/'cache_hit'/ {sum+=$2} END {print sum}')
7838 }
7839
7840 function set_cache() {
7841         local on=1
7842
7843         if [ "$2" == "off" ]; then
7844                 on=0;
7845         fi
7846         local list=$(comma_list $(osts_nodes))
7847         set_obdfilter_param $list '' $1_cache_enable $on
7848
7849         cancel_lru_locks osc
7850 }
7851
7852 test_151() {
7853         remote_ost_nodsh && skip "remote OST with nodsh" && return
7854
7855         local CPAGES=3
7856         local list=$(comma_list $(osts_nodes))
7857
7858         # check whether obdfilter is cache capable at all
7859         if ! get_obdfilter_param $list '' read_cache_enable >/dev/null; then
7860                 echo "not cache-capable obdfilter"
7861                 return 0
7862         fi
7863
7864         # check cache is enabled on all obdfilters
7865         if get_obdfilter_param $list '' read_cache_enable | grep 0; then
7866                 echo "oss cache is disabled"
7867                 return 0
7868         fi
7869
7870         set_obdfilter_param $list '' writethrough_cache_enable 1
7871
7872         # pages should be in the case right after write
7873         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
7874         local BEFORE=`roc_hit`
7875         cancel_lru_locks osc
7876         cat $DIR/$tfile >/dev/null
7877         local AFTER=`roc_hit`
7878         if ! let "AFTER - BEFORE == CPAGES"; then
7879                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
7880         fi
7881
7882         # the following read invalidates the cache
7883         cancel_lru_locks osc
7884         set_obdfilter_param $list '' read_cache_enable 0
7885         cat $DIR/$tfile >/dev/null
7886
7887         # now data shouldn't be found in the cache
7888         BEFORE=`roc_hit`
7889         cancel_lru_locks osc
7890         cat $DIR/$tfile >/dev/null
7891         AFTER=`roc_hit`
7892         if let "AFTER - BEFORE != 0"; then
7893                 error "IN CACHE: before: $BEFORE, after: $AFTER"
7894         fi
7895
7896         set_obdfilter_param $list '' read_cache_enable 1
7897         rm -f $DIR/$tfile
7898 }
7899 run_test 151 "test cache on oss and controls ==============================="
7900
7901 test_152() {
7902         local TF="$TMP/$tfile"
7903
7904         # simulate ENOMEM during write
7905 #define OBD_FAIL_OST_NOMEM      0x226
7906         lctl set_param fail_loc=0x80000226
7907         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
7908         cp $TF $DIR/$tfile
7909         sync || error "sync failed"
7910         lctl set_param fail_loc=0
7911
7912         # discard client's cache
7913         cancel_lru_locks osc
7914
7915         # simulate ENOMEM during read
7916         lctl set_param fail_loc=0x80000226
7917         cmp $TF $DIR/$tfile || error "cmp failed"
7918         lctl set_param fail_loc=0
7919
7920         rm -f $TF
7921 }
7922 run_test 152 "test read/write with enomem ============================"
7923
7924 test_153() {
7925         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
7926 }
7927 run_test 153 "test if fdatasync does not crash ======================="
7928
7929 test_154() {
7930         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
7931                 { skip "Need MDS version at least 2.2.51"; return 0; }
7932
7933         cp /etc/hosts $DIR/$tfile
7934
7935         fid=$($LFS path2fid $DIR/$tfile)
7936         rc=$?
7937         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
7938
7939         ffid=$DIR/.lustre/fid/$fid
7940
7941         echo "stat fid $fid"
7942         stat $ffid > /dev/null || error "stat $ffid failed."
7943         echo "touch fid $fid"
7944         touch $ffid || error "touch $ffid failed."
7945         echo "write to fid $fid"
7946         cat /etc/hosts > $ffid || error "write $ffid failed."
7947         echo "read fid $fid"
7948         diff /etc/hosts $ffid || error "read $ffid failed."
7949         echo "append write to fid $fid"
7950         cat /etc/hosts >> $ffid || error "append write $ffid failed."
7951         echo "rename fid $fid"
7952         mv $ffid $DIR/$tfile.1 && error "rename $ffid to $tfile.1 should fail."
7953         touch $DIR/$tfile.1
7954         mv $DIR/$tfile.1 $ffid && error "rename $tfile.1 to $ffid should fail."
7955         rm -f $DIR/$tfile.1
7956         echo "truncate fid $fid"
7957         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
7958         echo "link fid $fid"
7959         ln -f $ffid $DIR/tfile.lnk || error "link $ffid failed."
7960         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
7961                 echo "setfacl fid $fid"
7962                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
7963                 echo "getfacl fid $fid"
7964                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
7965         fi
7966         echo "unlink fid $fid"
7967         unlink $DIR/.lustre/fid/$fid && error "unlink $ffid should fail."
7968         echo "mknod fid $fid"
7969         mknod $ffid c 1 3 && error "mknod $ffid should fail."
7970
7971         fid=[0xf00000400:0x1:0x0]
7972         ffid=$DIR/.lustre/fid/$fid
7973
7974         echo "stat non-exist fid $fid"
7975         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
7976         echo "write to non-exist fid $fid"
7977         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
7978         echo "link new fid $fid"
7979         ln $DIR/$tfile $ffid && error "link $ffid should fail."
7980
7981         mkdir -p $DIR/$tdir
7982         touch $DIR/$tdir/$tfile
7983         fid=$($LFS path2fid $DIR/$tdir)
7984         rc=$?
7985         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
7986
7987         ffid=$DIR/.lustre/fid/$fid
7988
7989         echo "ls $fid"
7990         ls $ffid > /dev/null || error "ls $ffid failed."
7991         echo "touch $fid/$tfile.1"
7992         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
7993
7994         echo "touch $DIR/.lustre/fid/$tfile"
7995         touch $DIR/.lustre/fid/$tfile && \
7996                 error "touch $DIR/.lustre/fid/$tfile should fail."
7997
7998         echo "setxattr to $DIR/.lustre/fid"
7999         setfattr -n trusted.name1 -v value1 $DIR/.lustre/fid &&
8000                 error "setxattr should fail."
8001
8002         echo "listxattr for $DIR/.lustre/fid"
8003         getfattr -d -m "^trusted" $DIR/.lustre/fid &&
8004                 error "listxattr should fail."
8005
8006         echo "delxattr from $DIR/.lustre/fid"
8007         setfattr -x trusted.name1 $DIR/.lustre/fid &&
8008                 error "delxattr should fail."
8009
8010         echo "touch invalid fid: $DIR/.lustre/fid/[0x200000400:0x2:0x3]"
8011         touch $DIR/.lustre/fid/[0x200000400:0x2:0x3] &&
8012                 error "touch invalid fid should fail."
8013
8014         echo "touch non-normal fid: $DIR/.lustre/fid/[0x1:0x2:0x0]"
8015         touch $DIR/.lustre/fid/[0x1:0x2:0x0] &&
8016                 error "touch non-normal fid should fail."
8017
8018         echo "rename $tdir to $DIR/.lustre/fid"
8019         mrename $DIR/$tdir $DIR/.lustre/fid &&
8020                 error "rename to $DIR/.lustre/fid should fail."
8021
8022         echo "rename .lustre to itself"
8023         fid=$($LFS path2fid $DIR)
8024         mrename $DIR/.lustre $DIR/.lustre/fid/$fid/.lustre &&
8025                 error "rename .lustre to itself should fail."
8026
8027         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $DIR/$tfile-2
8028         fid=$($LFS path2fid $DIR/$tfile-2)
8029         echo "cp /etc/passwd $DIR/.lustre/fid/$fid"
8030         cp /etc/passwd $DIR/.lustre/fid/$fid &&
8031                 error "create lov data thru .lustre should fail."
8032         echo "cp /etc/passwd $DIR/$tfile-2"
8033         cp /etc/passwd $DIR/$tfile-2 || error "copy to $DIR/$tfile-2 failed."
8034         echo "diff /etc/passwd $DIR/.lustre/fid/$fid"
8035         diff /etc/passwd $DIR/.lustre/fid/$fid ||
8036                 error "diff /etc/passwd $DIR/.lustre/fid/$fid failed."
8037
8038         echo "Open-by-FID succeeded"
8039 }
8040 run_test 154 "Open-by-FID"
8041
8042 test_155_small_load() {
8043     local temp=$TMP/$tfile
8044     local file=$DIR/$tfile
8045
8046     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
8047         error "dd of=$temp bs=6096 count=1 failed"
8048     cp $temp $file
8049     cancel_lru_locks osc
8050     cmp $temp $file || error "$temp $file differ"
8051
8052     $TRUNCATE $temp 6000
8053     $TRUNCATE $file 6000
8054     cmp $temp $file || error "$temp $file differ (truncate1)"
8055
8056     echo "12345" >>$temp
8057     echo "12345" >>$file
8058     cmp $temp $file || error "$temp $file differ (append1)"
8059
8060     echo "12345" >>$temp
8061     echo "12345" >>$file
8062     cmp $temp $file || error "$temp $file differ (append2)"
8063
8064     rm -f $temp $file
8065     true
8066 }
8067
8068 test_155_big_load() {
8069     remote_ost_nodsh && skip "remote OST with nodsh" && return
8070     local temp=$TMP/$tfile
8071     local file=$DIR/$tfile
8072
8073     free_min_max
8074     local cache_size=$(do_facet ost$((MAXI+1)) \
8075         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
8076     local large_file_size=$((cache_size * 2))
8077
8078     echo "OSS cache size: $cache_size KB"
8079     echo "Large file size: $large_file_size KB"
8080
8081     [ $MAXV -le $large_file_size ] && \
8082         skip_env "max available OST size needs > $large_file_size KB" && \
8083         return 0
8084
8085     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
8086
8087     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
8088         error "dd of=$temp bs=$large_file_size count=1k failed"
8089     cp $temp $file
8090     ls -lh $temp $file
8091     cancel_lru_locks osc
8092     cmp $temp $file || error "$temp $file differ"
8093
8094     rm -f $temp $file
8095     true
8096 }
8097
8098 test_155a() {
8099     set_cache read on
8100     set_cache writethrough on
8101     test_155_small_load
8102 }
8103 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
8104
8105 test_155b() {
8106     set_cache read on
8107     set_cache writethrough off
8108     test_155_small_load
8109 }
8110 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
8111
8112 test_155c() {
8113     set_cache read off
8114     set_cache writethrough on
8115     test_155_small_load
8116 }
8117 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
8118
8119 test_155d() {
8120     set_cache read off
8121     set_cache writethrough off
8122     test_155_small_load
8123 }
8124 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
8125
8126 test_155e() {
8127     set_cache read on
8128     set_cache writethrough on
8129     test_155_big_load
8130 }
8131 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
8132
8133 test_155f() {
8134     set_cache read on
8135     set_cache writethrough off
8136     test_155_big_load
8137 }
8138 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
8139
8140 test_155g() {
8141     set_cache read off
8142     set_cache writethrough on
8143     test_155_big_load
8144 }
8145 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
8146
8147 test_155h() {
8148     set_cache read off
8149     set_cache writethrough off
8150     test_155_big_load
8151 }
8152 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
8153
8154 test_156() {
8155     local CPAGES=3
8156     local BEFORE
8157     local AFTER
8158     local file="$DIR/$tfile"
8159
8160     log "Turn on read and write cache"
8161     set_cache read on
8162     set_cache writethrough on
8163
8164     log "Write data and read it back."
8165     log "Read should be satisfied from the cache."
8166     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8167     BEFORE=`roc_hit`
8168     cancel_lru_locks osc
8169     cat $file >/dev/null
8170     AFTER=`roc_hit`
8171     if ! let "AFTER - BEFORE == CPAGES"; then
8172         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8173     else
8174         log "cache hits:: before: $BEFORE, after: $AFTER"
8175     fi
8176
8177     log "Read again; it should be satisfied from the cache."
8178     BEFORE=$AFTER
8179     cancel_lru_locks osc
8180     cat $file >/dev/null
8181     AFTER=`roc_hit`
8182     if ! let "AFTER - BEFORE == CPAGES"; then
8183         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8184     else
8185         log "cache hits:: before: $BEFORE, after: $AFTER"
8186     fi
8187
8188
8189     log "Turn off the read cache and turn on the write cache"
8190     set_cache read off
8191     set_cache writethrough on
8192
8193     log "Read again; it should be satisfied from the cache."
8194     BEFORE=`roc_hit`
8195     cancel_lru_locks osc
8196     cat $file >/dev/null
8197     AFTER=`roc_hit`
8198     if ! let "AFTER - BEFORE == CPAGES"; then
8199         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8200     else
8201         log "cache hits:: before: $BEFORE, after: $AFTER"
8202     fi
8203
8204     log "Read again; it should not be satisfied from the cache."
8205     BEFORE=$AFTER
8206     cancel_lru_locks osc
8207     cat $file >/dev/null
8208     AFTER=`roc_hit`
8209     if ! let "AFTER - BEFORE == 0"; then
8210         error "IN CACHE: before: $BEFORE, after: $AFTER"
8211     else
8212         log "cache hits:: before: $BEFORE, after: $AFTER"
8213     fi
8214
8215     log "Write data and read it back."
8216     log "Read should be satisfied from the cache."
8217     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8218     BEFORE=`roc_hit`
8219     cancel_lru_locks osc
8220     cat $file >/dev/null
8221     AFTER=`roc_hit`
8222     if ! let "AFTER - BEFORE == CPAGES"; then
8223         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8224     else
8225         log "cache hits:: before: $BEFORE, after: $AFTER"
8226     fi
8227
8228     log "Read again; it should not be satisfied from the cache."
8229     BEFORE=$AFTER
8230     cancel_lru_locks osc
8231     cat $file >/dev/null
8232     AFTER=`roc_hit`
8233     if ! let "AFTER - BEFORE == 0"; then
8234         error "IN CACHE: before: $BEFORE, after: $AFTER"
8235     else
8236         log "cache hits:: before: $BEFORE, after: $AFTER"
8237     fi
8238
8239
8240     log "Turn off read and write cache"
8241     set_cache read off
8242     set_cache writethrough off
8243
8244     log "Write data and read it back"
8245     log "It should not be satisfied from the cache."
8246     rm -f $file
8247     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8248     cancel_lru_locks osc
8249     BEFORE=`roc_hit`
8250     cat $file >/dev/null
8251     AFTER=`roc_hit`
8252     if ! let "AFTER - BEFORE == 0"; then
8253         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
8254     else
8255         log "cache hits:: before: $BEFORE, after: $AFTER"
8256     fi
8257
8258
8259     log "Turn on the read cache and turn off the write cache"
8260     set_cache read on
8261     set_cache writethrough off
8262
8263     log "Write data and read it back"
8264     log "It should not be satisfied from the cache."
8265     rm -f $file
8266     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8267     BEFORE=`roc_hit`
8268     cancel_lru_locks osc
8269     cat $file >/dev/null
8270     AFTER=`roc_hit`
8271     if ! let "AFTER - BEFORE == 0"; then
8272         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
8273     else
8274         log "cache hits:: before: $BEFORE, after: $AFTER"
8275     fi
8276
8277     log "Read again; it should be satisfied from the cache."
8278     BEFORE=`roc_hit`
8279     cancel_lru_locks osc
8280     cat $file >/dev/null
8281     AFTER=`roc_hit`
8282     if ! let "AFTER - BEFORE == CPAGES"; then
8283         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8284     else
8285         log "cache hits:: before: $BEFORE, after: $AFTER"
8286     fi
8287
8288     rm -f $file
8289 }
8290 run_test 156 "Verification of tunables ============================"
8291
8292 #Changelogs
8293 err17935 () {
8294     if [ $MDSCOUNT -gt 1 ]; then
8295         error_ignore 17935 $*
8296     else
8297         error $*
8298     fi
8299 }
8300
8301 changelog_chmask()
8302 {
8303     MASK=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_mask |\
8304            grep -c $1)
8305
8306     if [ $MASK -eq 1 ]; then
8307         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="-$1"
8308     else
8309         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="+$1"
8310     fi
8311 }
8312
8313 test_160() {
8314     remote_mds_nodsh && skip "remote MDS with nodsh" && return
8315     [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
8316         { skip "Need MDS version at least 2.2.0"; return; }
8317     USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
8318     echo "Registered as changelog user $USER"
8319     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
8320         grep -q $USER || error "User $USER not found in changelog_users"
8321
8322     # change something
8323     mkdir -p $DIR/$tdir/pics/2008/zachy
8324     touch $DIR/$tdir/pics/2008/zachy/timestamp
8325     cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
8326     mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
8327     ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
8328     ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
8329     rm $DIR/$tdir/pics/desktop.jpg
8330
8331     $LFS changelog $MDT0 | tail -5
8332
8333     echo "verifying changelog mask"
8334     changelog_chmask "MKDIR"
8335     changelog_chmask "CLOSE"
8336
8337     mkdir -p $DIR/$tdir/pics/zach/sofia
8338     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
8339
8340     changelog_chmask "MKDIR"
8341     changelog_chmask "CLOSE"
8342
8343     mkdir -p $DIR/$tdir/pics/2008/sofia
8344     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
8345
8346     $LFS changelog $MDT0
8347     MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
8348     CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
8349     [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
8350     [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
8351
8352     # verify contents
8353     echo "verifying target fid"
8354     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
8355         tail -1 | awk '{print $6}')
8356     fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
8357     [ "$fidc" == "t=$fidf" ] || \
8358         err17935 "fid in changelog $fidc != file fid $fidf"
8359     echo "verifying parent fid"
8360     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
8361         tail -1 | awk '{print $7}')
8362     fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
8363     [ "$fidc" == "p=$fidf" ] || \
8364         err17935 "pfid in changelog $fidc != dir fid $fidf"
8365
8366     USER_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
8367         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
8368     $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
8369     USER_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
8370         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
8371     echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
8372     [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \
8373         err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2"
8374
8375     MIN_REC=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_users | \
8376         awk 'min == "" || $2 < min {min = $2}; END {print min}')
8377     FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
8378     echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
8379     [ $FIRST_REC == $(($MIN_REC + 1)) ] || \
8380         err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC"
8381
8382     echo "verifying user deregister"
8383     do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
8384     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
8385         grep -q $USER && error "User $USER still found in changelog_users"
8386
8387     USERS=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
8388         mdd.$MDT0.changelog_users | wc -l) - 2 ))
8389     if [ $USERS -eq 0 ]; then
8390         LAST_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
8391             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
8392         touch $DIR/$tdir/chloe
8393         LAST_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
8394             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
8395         echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2"
8396         [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
8397     else
8398         echo "$USERS other changelog users; can't verify off"
8399     fi
8400 }
8401 run_test 160 "changelog sanity"
8402
8403 test_161() {
8404     mkdir -p $DIR/$tdir
8405     cp /etc/hosts $DIR/$tdir/$tfile
8406     mkdir $DIR/$tdir/foo1
8407     mkdir $DIR/$tdir/foo2
8408     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
8409     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
8410     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
8411     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
8412     local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[')
8413     if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
8414         $LFS fid2path $DIR $FID
8415         err17935 "bad link ea"
8416     fi
8417     # middle
8418     rm $DIR/$tdir/foo2/zachary
8419     # last
8420     rm $DIR/$tdir/foo2/thor
8421     # first
8422     rm $DIR/$tdir/$tfile
8423     # rename
8424     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
8425     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
8426         then
8427         $LFS fid2path $DIR $FID
8428         err17935 "bad link rename"
8429     fi
8430     rm $DIR/$tdir/foo2/maggie
8431
8432     # overflow the EA
8433     local longname=filename_avg_len_is_thirty_two_
8434     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
8435         error "failed to hardlink many files"
8436     links=$($LFS fid2path $DIR $FID | wc -l)
8437     echo -n "${links}/1000 links in link EA"
8438     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
8439     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
8440         error "failed to unlink many hardlinks"
8441 }
8442 run_test 161 "link ea sanity"
8443
8444 check_path() {
8445     local expected=$1
8446     shift
8447     local fid=$2
8448
8449     local path=$(${LFS} fid2path $*)
8450     RC=$?
8451
8452     if [ $RC -ne 0 ]; then
8453         err17935 "path looked up of $expected failed. Error $RC"
8454         return $RC
8455     elif [ "${path}" != "${expected}" ]; then
8456         err17935 "path looked up \"${path}\" instead of \"${expected}\""
8457         return 2
8458     fi
8459     echo "fid $fid resolves to path $path (expected $expected)"
8460 }
8461
8462 test_162() {
8463         # Make changes to filesystem
8464         mkdir -p $DIR/$tdir/d2
8465         touch $DIR/$tdir/d2/$tfile
8466         touch $DIR/$tdir/d2/x1
8467         touch $DIR/$tdir/d2/x2
8468         mkdir -p $DIR/$tdir/d2/a/b/c
8469         mkdir -p $DIR/$tdir/d2/p/q/r
8470         # regular file
8471         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
8472         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
8473
8474         # softlink
8475         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
8476         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
8477         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
8478
8479         # softlink to wrong file
8480         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
8481         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
8482         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
8483
8484         # hardlink
8485         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
8486         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
8487         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
8488         # fid2path dir/fsname should both work
8489         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
8490         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
8491
8492         # hardlink count: check that there are 2 links
8493         # Doesnt work with CMD yet: 17935
8494         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
8495                 err17935 "expected 2 links"
8496
8497         # hardlink indexing: remove the first link
8498         rm $DIR/$tdir/d2/p/q/r/hlink
8499         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
8500
8501         return 0
8502 }
8503 run_test 162 "path lookup sanity"
8504
8505 test_163() {
8506         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8507         copytool --test $FSNAME || { skip "copytool not runnable: $?" && return; }
8508         copytool $FSNAME &
8509         sleep 1
8510         local uuid=$($LCTL get_param -n mdc.${FSNAME}-MDT0000-mdc-*.uuid)
8511         # this proc file is temporary and linux-only
8512         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT0000.mdccomm=$uuid ||\
8513          error "kernel->userspace send failed"
8514         kill -INT $!
8515 }
8516 run_test 163 "kernel <-> userspace comms"
8517
8518 test_169() {
8519         # do directio so as not to populate the page cache
8520         log "creating a 10 Mb file"
8521         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
8522         log "starting reads"
8523         dd if=$DIR/$tfile of=/dev/null bs=4096 &
8524         log "truncating the file"
8525         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
8526         log "killing dd"
8527         kill %+ || true # reads might have finished
8528         echo "wait until dd is finished"
8529         wait
8530         log "removing the temporary file"
8531         rm -rf $DIR/$tfile || error "tmp file removal failed"
8532 }
8533 run_test 169 "parallel read and truncate should not deadlock"
8534
8535 test_170() {
8536         $LCTL clear     # bug 18514
8537         $LCTL debug_daemon start $TMP/${tfile}_log_good
8538         touch $DIR/$tfile
8539         $LCTL debug_daemon stop
8540         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
8541                error "sed failed to read log_good"
8542
8543         $LCTL debug_daemon start $TMP/${tfile}_log_good
8544         rm -rf $DIR/$tfile
8545         $LCTL debug_daemon stop
8546
8547         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
8548                error "lctl df log_bad failed"
8549
8550         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
8551         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
8552
8553         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
8554         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
8555
8556         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
8557                 error "bad_line good_line1 good_line2 are empty"
8558
8559         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
8560         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
8561         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
8562
8563         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
8564         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
8565         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
8566
8567         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
8568                 error "bad_line_new good_line_new are empty"
8569
8570         local expected_good=$((good_line1 + good_line2*2))
8571
8572         rm -f $TMP/${tfile}*
8573         # LU-231, short malformed line may not be counted into bad lines
8574         if [ $bad_line -ne $bad_line_new ] &&
8575                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
8576                 error "expected $bad_line bad lines, but got $bad_line_new"
8577                 return 1
8578         fi
8579
8580         if [ $expected_good -ne $good_line_new ]; then
8581                 error "expected $expected_good good lines, but got $good_line_new"
8582                 return 2
8583         fi
8584         true
8585 }
8586 run_test 170 "test lctl df to handle corrupted log ====================="
8587
8588 test_171() { # bug20592
8589 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
8590         $LCTL set_param fail_loc=0x50e
8591         $LCTL set_param fail_val=3000
8592         multiop_bg_pause $DIR/$tfile O_s || true
8593         local MULTIPID=$!
8594         kill -USR1 $MULTIPID
8595         # cause log dump
8596         sleep 3
8597         wait $MULTIPID
8598         if dmesg | grep "recursive fault"; then
8599                 error "caught a recursive fault"
8600         fi
8601         $LCTL set_param fail_loc=0
8602         true
8603 }
8604 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
8605
8606 # it would be good to share it with obdfilter-survey/libecho code
8607 setup_obdecho_osc () {
8608         local rc=0
8609         local ost_nid=$1
8610         local obdfilter_name=$2
8611         echo "Creating new osc for $obdfilter_name on $ost_nid"
8612         # make sure we can find loopback nid
8613         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
8614
8615         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
8616                            ${obdfilter_name}_osc_UUID || rc=2; }
8617         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
8618                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
8619         return $rc
8620 }
8621
8622 cleanup_obdecho_osc () {
8623         local obdfilter_name=$1
8624         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
8625         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
8626         return 0
8627 }
8628
8629 obdecho_create_test() {
8630         local OBD=$1
8631         local node=$2
8632         local rc=0
8633         local id
8634         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
8635         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
8636                            rc=2; }
8637         if [ $rc -eq 0 ]; then
8638             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
8639             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
8640         fi
8641         echo "New object id is $id"
8642         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec test_brw 10 w v 64 $id" ||
8643                            rc=4; }
8644         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
8645                                         "cleanup" || rc=5; }
8646         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
8647                                         "detach" || rc=6; }
8648         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
8649         return $rc
8650 }
8651
8652 test_180a() {
8653         remote_ost_nodsh && skip "remote OST with nodsh" && return
8654         local rc=0
8655         local rmmod_local=0
8656
8657         if ! module_loaded obdecho; then
8658             load_module obdecho/obdecho
8659             rmmod_local=1
8660         fi
8661
8662         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
8663         local host=$(lctl get_param -n osc.$osc.import |
8664                              awk '/current_connection:/ {print $2}' )
8665         local target=$(lctl get_param -n osc.$osc.import |
8666                              awk '/target:/ {print $2}' )
8667         target=${target%_UUID}
8668
8669         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
8670         [ $rc -eq 0 ] && { obdecho_create_test ${target}_osc client || rc=2; }
8671         [[ -n $target ]] && cleanup_obdecho_osc $target
8672         [ $rmmod_local -eq 1 ] && rmmod obdecho
8673         return $rc
8674 }
8675 run_test 180a "test obdecho on osc"
8676
8677 test_180b() {
8678         remote_ost_nodsh && skip "remote OST with nodsh" && return
8679         local rc=0
8680         local rmmod_remote=0
8681
8682         do_facet ost1 "lsmod | grep -q obdecho || "                      \
8683                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
8684                       "modprobe obdecho; }" && rmmod_remote=1
8685         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
8686         [[ -n $target ]] && { obdecho_create_test $target ost1 || rc=1; }
8687         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
8688         return $rc
8689 }
8690 run_test 180b "test obdecho directly on obdfilter"
8691
8692 test_181() { # bug 22177
8693         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
8694         # create enough files to index the directory
8695         createmany -o $DIR/$tdir/foobar 4000
8696         # print attributes for debug purpose
8697         lsattr -d .
8698         # open dir
8699         multiop_bg_pause $DIR/$tdir D_Sc || return 1
8700         MULTIPID=$!
8701         # remove the files & current working dir
8702         unlinkmany $DIR/$tdir/foobar 4000
8703         rmdir $DIR/$tdir
8704         kill -USR1 $MULTIPID
8705         wait $MULTIPID
8706         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
8707         return 0
8708 }
8709 run_test 181 "Test open-unlinked dir ========================"
8710
8711 test_182() {
8712         # disable MDC RPC lock wouldn't crash client
8713         local fcount=1000
8714         local tcount=4
8715
8716         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
8717 #define OBD_FAIL_MDC_RPCS_SEM           0x804
8718         $LCTL set_param fail_loc=0x804
8719
8720         for (( i=0; i < $tcount; i++ )) ; do
8721                 mkdir $DIR/$tdir/$i
8722                 createmany -o $DIR/$tdir/$i/f- $fcount &
8723         done
8724         wait
8725
8726         for (( i=0; i < $tcount; i++ )) ; do
8727                 unlinkmany $DIR/$tdir/$i/f- $fcount &
8728         done
8729         wait
8730
8731         rm -rf $DIR/$tdir
8732
8733         $LCTL set_param fail_loc=0
8734 }
8735 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
8736
8737 # OST pools tests
8738 check_file_in_pool()
8739 {
8740         local file=$1
8741         local pool=$2
8742         local tlist="$3"
8743         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
8744         for i in $res
8745         do
8746                 for t in $tlist ; do
8747                         [ "$i" -eq "$t" ] && continue 2
8748                 done
8749
8750                 echo "pool list: $tlist"
8751                 echo "striping: $res"
8752                 error_noexit "$file not allocated in $pool"
8753                 return 1
8754         done
8755         return 0
8756 }
8757
8758 pool_add() {
8759         echo "Creating new pool"
8760         local pool=$1
8761
8762         create_pool $FSNAME.$pool ||
8763                 { error_noexit "No pool created, result code $?"; return 1; }
8764         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
8765                 { error_noexit "$pool not in lfs pool_list"; return 2; }
8766 }
8767
8768 pool_add_targets() {
8769         echo "Adding targets to pool"
8770         local pool=$1
8771         local first=$2
8772         local last=$3
8773         local step=${4:-1}
8774
8775         local list=$(seq $first $step $last)
8776
8777         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
8778         do_facet mgs $LCTL pool_add \
8779                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
8780         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
8781                         | sort -u | tr '\n' ' ' " "$t" || { 
8782                 error_noexit "Add to pool failed"
8783                 return 1
8784         }
8785         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
8786         local addcount=$(((last - first) / step + 1))
8787         [ $lfscount -eq $addcount ] || {
8788                 error_noexit "lfs pool_list bad ost count" \
8789                                                 "$lfscount != $addcount"
8790                 return 2
8791         }
8792 }
8793
8794 pool_set_dir() {
8795         local pool=$1
8796         local tdir=$2
8797         echo "Setting pool on directory $tdir"
8798
8799         $SETSTRIPE -c 2 -p $pool $tdir && return 0
8800
8801         error_noexit "Cannot set pool $pool to $tdir"
8802         return 1
8803 }
8804
8805 pool_check_dir() {
8806         local pool=$1
8807         local tdir=$2
8808         echo "Checking pool on directory $tdir"
8809
8810         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
8811         [ "$res" = "$pool" ] && return 0
8812
8813         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
8814         return 1
8815 }
8816
8817 pool_dir_rel_path() {
8818         echo "Testing relative path works well"
8819         local pool=$1
8820         local tdir=$2
8821         local root=$3
8822
8823         mkdir -p $root/$tdir/$tdir
8824         cd $root/$tdir
8825         pool_set_dir $pool $tdir          || return 1
8826         pool_set_dir $pool ./$tdir        || return 2
8827         pool_set_dir $pool ../$tdir       || return 3
8828         pool_set_dir $pool ../$tdir/$tdir || return 4
8829         rm -rf $tdir; cd - > /dev/null
8830 }
8831
8832 pool_alloc_files() {
8833         echo "Checking files allocation from directory pool"
8834         local pool=$1
8835         local tdir=$2
8836         local count=$3
8837         local tlist="$4"
8838
8839         local failed=0
8840         for i in $(seq -w 1 $count)
8841         do
8842                 local file=$tdir/file-$i
8843                 touch $file
8844                 check_file_in_pool $file $pool "$tlist" || \
8845                         failed=$((failed + 1))
8846         done
8847         [ "$failed" = 0 ] && return 0
8848
8849         error_noexit "$failed files not allocated in $pool"
8850         return 1
8851 }
8852
8853 pool_create_files() {
8854         echo "Creating files in pool"
8855         local pool=$1
8856         local tdir=$2
8857         local count=$3
8858         local tlist="$4"
8859
8860         mkdir -p $tdir
8861         local failed=0
8862         for i in $(seq -w 1 $count)
8863         do
8864                 local file=$tdir/spoo-$i
8865                 $SETSTRIPE -p $pool $file
8866                 check_file_in_pool $file $pool "$tlist" || \
8867                         failed=$((failed + 1))
8868         done
8869         [ "$failed" = 0 ] && return 0
8870
8871         error_noexit "$failed files not allocated in $pool"
8872         return 1
8873 }
8874
8875 pool_lfs_df() {
8876         echo "Checking 'lfs df' output"
8877         local pool=$1
8878
8879         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
8880                         tr '\n' ' ')
8881         local res=$($LFS df --pool $FSNAME.$pool |
8882                         awk '{print $1}' |
8883                         grep "$FSNAME-OST" |
8884                         tr '\n' ' ')
8885         [ "$res" = "$t" ] && return 0
8886
8887         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
8888         return 1
8889 }
8890
8891 pool_file_rel_path() {
8892         echo "Creating files in a pool with relative pathname"
8893         local pool=$1
8894         local tdir=$2
8895
8896         mkdir -p $tdir ||
8897                 { error_noexit "unable to create $tdir"; return 1 ; }
8898         local file="/..$tdir/$tfile-1"
8899         $SETSTRIPE -p $pool $file ||
8900                 { error_noexit "unable to create $file" ; return 2 ; }
8901
8902         cd $tdir
8903         $SETSTRIPE -p $pool $tfile-2 || {
8904                 error_noexit "unable to create $tfile-2 in $tdir"
8905                 return 3
8906         }
8907 }
8908
8909 pool_remove_first_target() {
8910         echo "Removing first target from a pool"
8911         local pool=$1
8912
8913         local pname="lov.$FSNAME-*.pools.$pool"
8914         local t=$($LCTL get_param -n $pname | head -1)
8915         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8916         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
8917                 error_noexit "$t not removed from $FSNAME.$pool"
8918                 return 1
8919         }
8920 }
8921
8922 pool_remove_all_targets() {
8923         echo "Removing all targets from pool"
8924         local pool=$1
8925         local file=$2
8926         local pname="lov.$FSNAME-*.pools.$pool"
8927         for t in $($LCTL get_param -n $pname | sort -u)
8928         do
8929                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8930         done
8931         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
8932                 error_noexit "Pool $FSNAME.$pool cannot be drained"
8933                 return 1
8934         }
8935         # striping on an empty/nonexistant pool should fall back 
8936         # to "pool of everything"
8937         touch $file || {
8938                 error_noexit "failed to use fallback striping for empty pool"
8939                 return 2
8940         }
8941         # setstripe on an empty pool should fail
8942         $SETSTRIPE -p $pool $file 2>/dev/null && {
8943                 error_noexit "expected failure when creating file" \
8944                                                         "with empty pool"
8945                 return 3
8946         }
8947         return 0
8948 }
8949
8950 pool_remove() {
8951         echo "Destroying pool"
8952         local pool=$1
8953         local file=$2
8954
8955         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
8956
8957         sleep 2
8958         # striping on an empty/nonexistant pool should fall back 
8959         # to "pool of everything"
8960         touch $file || {
8961                 error_noexit "failed to use fallback striping for missing pool"
8962                 return 1
8963         }
8964         # setstripe on an empty pool should fail
8965         $SETSTRIPE -p $pool $file 2>/dev/null && {
8966                 error_noexit "expected failure when creating file" \
8967                                                         "with missing pool"
8968                 return 2
8969         }
8970
8971         # get param should return err once pool is gone
8972         if wait_update $HOSTNAME "lctl get_param -n \
8973                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
8974         then
8975                 remove_pool_from_list $FSNAME.$pool
8976                 return 0
8977         fi
8978         error_noexit "Pool $FSNAME.$pool is not destroyed"
8979         return 3
8980 }
8981
8982 test_200() {
8983         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
8984
8985         local POOL=${POOL:-cea1}
8986         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
8987         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
8988         # Pool OST targets
8989         local first_ost=0
8990         local last_ost=$(($OSTCOUNT - 1))
8991         local ost_step=2
8992         local ost_list=$(seq $first_ost $ost_step $last_ost)
8993         local ost_range="$first_ost $last_ost $ost_step"
8994         local test_path=$POOL_ROOT/$POOL_DIR_NAME
8995         local file_dir=$POOL_ROOT/file_tst
8996
8997         local rc=0
8998         while : ; do
8999                 # former test_200a test_200b
9000                 pool_add $POOL                          || { rc=$? ; break; }
9001                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
9002                 # former test_200c test_200d
9003                 mkdir -p $test_path
9004                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
9005                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
9006                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
9007                                                         || { rc=$? ; break; }
9008                 # former test_200e test_200f
9009                 local files=$((OSTCOUNT*3))
9010                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
9011                                                         || { rc=$? ; break; }
9012                 pool_create_files $POOL $file_dir $files "$ost_list" \
9013                                                         || { rc=$? ; break; }
9014                 # former test_200g test_200h
9015                 pool_lfs_df $POOL                       || { rc=$? ; break; }
9016                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
9017
9018                 # former test_201a test_201b test_201c
9019                 pool_remove_first_target $POOL          || { rc=$? ; break; }
9020
9021                 local f=$test_path/$tfile
9022                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
9023                 pool_remove $POOL $f                    || { rc=$? ; break; }
9024                 break
9025         done
9026
9027         cleanup_pools
9028         return $rc
9029 }
9030 run_test 200 "OST pools"
9031
9032 # usage: default_attr <count | size | offset>
9033 default_attr() {
9034         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
9035 }
9036
9037 # usage: check_default_stripe_attr
9038 check_default_stripe_attr() {
9039         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
9040         case $1 in
9041         --stripe-count|--count)
9042                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
9043         --stripe-size|--size)
9044                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
9045         --stripe-index|--index)
9046                 EXPECTED=-1;;
9047         *)
9048                 error "unknown getstripe attr '$1'"
9049         esac
9050
9051         [ $ACTUAL != $EXPECTED ] &&
9052                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
9053 }
9054
9055 test_204a() {
9056         mkdir -p $DIR/$tdir
9057         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
9058
9059         check_default_stripe_attr --stripe-count
9060         check_default_stripe_attr --stripe-size
9061         check_default_stripe_attr --stripe-index
9062
9063         return 0
9064 }
9065 run_test 204a "Print default stripe attributes ================="
9066
9067 test_204b() {
9068         mkdir -p $DIR/$tdir
9069         $SETSTRIPE --stripe-count 1 $DIR/$tdir
9070
9071         check_default_stripe_attr --stripe-size
9072         check_default_stripe_attr --stripe-index
9073
9074         return 0
9075 }
9076 run_test 204b "Print default stripe size and offset  ==========="
9077
9078 test_204c() {
9079         mkdir -p $DIR/$tdir
9080         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
9081
9082         check_default_stripe_attr --stripe-count
9083         check_default_stripe_attr --stripe-index
9084
9085         return 0
9086 }
9087 run_test 204c "Print default stripe count and offset ==========="
9088
9089 test_204d() {
9090         mkdir -p $DIR/$tdir
9091         $SETSTRIPE --stripe-index 0 $DIR/$tdir
9092
9093         check_default_stripe_attr --stripe-count
9094         check_default_stripe_attr --stripe-size
9095
9096         return 0
9097 }
9098 run_test 204d "Print default stripe count and size ============="
9099
9100 test_204e() {
9101         mkdir -p $DIR/$tdir
9102         $SETSTRIPE -d $DIR/$tdir
9103
9104         check_default_stripe_attr --stripe-count --raw
9105         check_default_stripe_attr --stripe-size --raw
9106         check_default_stripe_attr --stripe-index --raw
9107
9108         return 0
9109 }
9110 run_test 204e "Print raw stripe attributes ================="
9111
9112 test_204f() {
9113         mkdir -p $DIR/$tdir
9114         $SETSTRIPE --stripe-count 1 $DIR/$tdir
9115
9116         check_default_stripe_attr --stripe-size --raw
9117         check_default_stripe_attr --stripe-index --raw
9118
9119         return 0
9120 }
9121 run_test 204f "Print raw stripe size and offset  ==========="
9122
9123 test_204g() {
9124         mkdir -p $DIR/$tdir
9125         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
9126
9127         check_default_stripe_attr --stripe-count --raw
9128         check_default_stripe_attr --stripe-index --raw
9129
9130         return 0
9131 }
9132 run_test 204g "Print raw stripe count and offset ==========="
9133
9134 test_204h() {
9135         mkdir -p $DIR/$tdir
9136         $SETSTRIPE --stripe-index 0 $DIR/$tdir
9137
9138         check_default_stripe_attr --stripe-count --raw
9139         check_default_stripe_attr --stripe-size --raw
9140
9141         return 0
9142 }
9143 run_test 204h "Print raw stripe count and size ============="
9144
9145 # Figure out which job scheduler is being used, if any,
9146 # or use a fake one
9147 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
9148         JOBENV=SLURM_JOB_ID
9149 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
9150         JOBENV=LSB_JOBID
9151 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
9152         JOBENV=PBS_JOBID
9153 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
9154         JOBENV=LOADL_STEP_ID
9155 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
9156         JOBENV=JOB_ID
9157 else
9158         JOBENV=FAKE_JOBID
9159 fi
9160
9161 verify_jobstats() {
9162         local cmd=$1
9163         local target=$2
9164
9165         # clear old jobstats
9166         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
9167         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
9168
9169         # use a new JobID for this test, or we might see an old one
9170         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
9171
9172         JOBVAL=${!JOBENV}
9173         log "Test: $cmd"
9174         log "Using JobID environment variable $JOBENV=$JOBVAL"
9175
9176         if [ $JOBENV = "FAKE_JOBID" ]; then
9177                 FAKE_JOBID=$JOBVAL $cmd
9178         else
9179                 $cmd
9180         fi
9181
9182         if [ "$target" = "mdt" -o "$target" = "both" ]; then
9183                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
9184                 do_facet $FACET lctl get_param mdt.*.job_stats |
9185                         grep $JOBVAL || error "No job stats found on MDT $FACET"
9186         fi
9187         if [ "$target" = "ost" -o "$target" = "both" ]; then
9188                 FACET=ost1
9189                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
9190                         grep $JOBVAL || error "No job stats found on OST $FACET"
9191         fi
9192 }
9193
9194 test_205() { # Job stats
9195         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
9196                 skip "Server doesn't support jobstats" && return 0
9197
9198         local cmd
9199         OLD_JOBENV=`$LCTL get_param -n jobid_var`
9200         if [ $OLD_JOBENV != $JOBENV ]; then
9201                 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$JOBENV
9202                 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
9203                         $JOBENV || return 1
9204         fi
9205
9206         # mkdir
9207         cmd="mkdir $DIR/$tfile"
9208         verify_jobstats "$cmd" "mdt"
9209         # rmdir
9210         cmd="rm -fr $DIR/$tfile"
9211         verify_jobstats "$cmd" "mdt"
9212         # mknod
9213         cmd="mknod $DIR/$tfile c 1 3"
9214         verify_jobstats "$cmd" "mdt"
9215         # unlink
9216         cmd="rm -f $DIR/$tfile"
9217         verify_jobstats "$cmd" "mdt"
9218         # open & close
9219         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
9220         verify_jobstats "$cmd" "mdt"
9221         # setattr
9222         cmd="touch $DIR/$tfile"
9223         verify_jobstats "$cmd" "both"
9224         # write
9225         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
9226         verify_jobstats "$cmd" "ost"
9227         # read
9228         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
9229         verify_jobstats "$cmd" "ost"
9230         # truncate
9231         cmd="$TRUNCATE $DIR/$tfile 0"
9232         verify_jobstats "$cmd" "both"
9233         # rename
9234         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
9235         verify_jobstats "$cmd" "mdt"
9236
9237         # cleanup
9238         rm -f $DIR/jobstats_test_rename
9239
9240         if [ $OLD_JOBENV != $JOBENV ]; then
9241                 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$OLD_JOBENV
9242                 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
9243                         $OLD_JOBENV || return 1
9244         fi
9245 }
9246 run_test 205 "Verify job stats"
9247
9248 # LU-1480, LU-1773 and LU-1657
9249 test_206() {
9250         mkdir -p $DIR/$tdir
9251         lfs setstripe -c -1 $DIR/$tdir
9252 #define OBD_FAIL_LOV_INIT 0x1403
9253         $LCTL set_param fail_loc=0xa0001403
9254         $LCTL set_param fail_val=1
9255         touch $DIR/$tdir/$tfile || true
9256 }
9257 run_test 206 "fail lov_init_raid0() doesn't lbug"
9258
9259 test_212() {
9260         size=`date +%s`
9261         size=$((size % 8192 + 1))
9262         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
9263         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
9264         rm -f $DIR/f212 $DIR/f212.xyz
9265 }
9266 run_test 212 "Sendfile test ============================================"
9267
9268 test_213() {
9269         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
9270         cancel_lru_locks osc
9271         lctl set_param fail_loc=0x8000040f
9272         # generate a read lock
9273         cat $DIR/$tfile > /dev/null
9274         # write to the file, it will try to cancel the above read lock.
9275         cat /etc/hosts >> $DIR/$tfile
9276 }
9277 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
9278
9279 test_214() { # for bug 20133
9280         mkdir -p $DIR/d214p/d214c
9281         for (( i=0; i < 340; i++ )) ; do
9282                 touch $DIR/d214p/d214c/a$i
9283         done
9284
9285         ls -l $DIR/d214p || error "ls -l $DIR/d214p failed"
9286         mv $DIR/d214p/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
9287         ls $DIR/d214c || error "ls $DIR/d214c failed"
9288         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
9289 }
9290 run_test 214 "hash-indexed directory test - bug 20133"
9291
9292 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
9293 create_lnet_proc_files() {
9294         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
9295         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
9296
9297         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
9298         rm -f "$TMP/lnet_$1.sys_tmp"
9299 }
9300
9301 # counterpart of create_lnet_proc_files
9302 remove_lnet_proc_files() {
9303         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
9304 }
9305
9306 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
9307 # 3rd arg as regexp for body
9308 check_lnet_proc_stats() {
9309         local l=$(cat "$TMP/lnet_$1" |wc -l)
9310         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
9311
9312         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
9313 }
9314
9315 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
9316 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
9317 # optional and can be regexp for 2nd line (lnet.routes case)
9318 check_lnet_proc_entry() {
9319         local blp=2            # blp stands for 'position of 1st line of body'
9320         [ "$5" = "" ] || blp=3 # lnet.routes case
9321
9322         local l=$(cat "$TMP/lnet_$1" |wc -l)
9323         # subtracting one from $blp because the body can be empty
9324         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
9325
9326         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
9327                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
9328
9329         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
9330                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
9331
9332         # bail out if any unexpected line happened
9333         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
9334         [ "$?" != 0 ] || error "$2 misformatted"
9335 }
9336
9337 test_215() { # for bugs 18102, 21079, 21517
9338         local N='(0|[1-9][0-9]*)'       # non-negative numeric
9339         local P='[1-9][0-9]*'           # positive numeric
9340         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
9341         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
9342         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
9343         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
9344
9345         local L1 # regexp for 1st line
9346         local L2 # regexp for 2nd line (optional)
9347         local BR # regexp for the rest (body)
9348
9349         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
9350         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
9351         create_lnet_proc_files "stats"
9352         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
9353         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
9354         remove_lnet_proc_files "stats"
9355
9356         # /proc/sys/lnet/routes should look like this:
9357         # Routing disabled/enabled
9358         # net hops state router
9359         # where net is a string like tcp0, hops >= 0, state is up/down,
9360         # router is a string like 192.168.1.1@tcp2
9361         L1="^Routing (disabled|enabled)$"
9362         L2="^net +hops +state +router$"
9363         BR="^$NET +$N +(up|down) +$NID$"
9364         create_lnet_proc_files "routes"
9365         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
9366         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
9367         remove_lnet_proc_files "routes"
9368
9369         # /proc/sys/lnet/routers should look like this:
9370         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
9371         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
9372         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
9373         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
9374         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
9375         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
9376         create_lnet_proc_files "routers"
9377         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
9378         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
9379         remove_lnet_proc_files "routers"
9380
9381         # /proc/sys/lnet/peers should look like this:
9382         # nid refs state last max rtr min tx min queue
9383         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
9384         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
9385         # numeric (0 or >0 or <0), queue >= 0.
9386         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
9387         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
9388         create_lnet_proc_files "peers"
9389         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
9390         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
9391         remove_lnet_proc_files "peers"
9392
9393         # /proc/sys/lnet/buffers  should look like this:
9394         # pages count credits min
9395         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
9396         L1="^pages +count +credits +min$"
9397         BR="^ +$N +$N +$I +$I$"
9398         create_lnet_proc_files "buffers"
9399         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
9400         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
9401         remove_lnet_proc_files "buffers"
9402
9403         # /proc/sys/lnet/nis should look like this:
9404         # nid status alive refs peer rtr max tx min
9405         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
9406         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
9407         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
9408         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
9409         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
9410         create_lnet_proc_files "nis"
9411         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
9412         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
9413         remove_lnet_proc_files "nis"
9414
9415         # can we successfully write to /proc/sys/lnet/stats?
9416         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
9417         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
9418 }
9419 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
9420
9421 test_216() { # bug 20317
9422         remote_ost_nodsh && skip "remote OST with nodsh" && return
9423         local node
9424         local p="$TMP/sanityN-$TESTNAME.parameters"
9425         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
9426         for node in $(osts_nodes); do
9427                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
9428                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
9429                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
9430         done
9431         clear_osc_stats
9432
9433         # agressive lockless i/o settings
9434         for node in $(osts_nodes); do
9435                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
9436         done
9437         lctl set_param -n osc.*.contention_seconds 60
9438
9439         $DIRECTIO write $DIR/$tfile 0 10 4096
9440         $CHECKSTAT -s 40960 $DIR/$tfile
9441
9442         # disable lockless i/o
9443         for node in $(osts_nodes); do
9444                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
9445         done
9446         lctl set_param -n osc.*.contention_seconds 0
9447         clear_osc_stats
9448
9449         dd if=/dev/zero of=$DIR/$tfile count=0
9450         $CHECKSTAT -s 0 $DIR/$tfile
9451
9452         restore_lustre_params <$p
9453         rm -f $p
9454         rm $DIR/$tfile
9455 }
9456 run_test 216 "check lockless direct write works and updates file size and kms correctly"
9457
9458 test_217() { # bug 22430
9459         local node
9460         local nid
9461
9462         for node in $(nodes_list); do
9463                 nid=$(host_nids_address $node $NETTYPE)
9464                 if [[ $nid = *-* ]] ; then
9465                         echo "lctl ping $nid@$NETTYPE"
9466                         lctl ping $nid@$NETTYPE
9467                 else
9468                         echo "skipping $node (no hyphen detected)"
9469                 fi
9470         done
9471 }
9472 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
9473
9474 test_218() {
9475        # do directio so as not to populate the page cache
9476        log "creating a 10 Mb file"
9477        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
9478        log "starting reads"
9479        dd if=$DIR/$tfile of=/dev/null bs=4096 &
9480        log "truncating the file"
9481        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
9482        log "killing dd"
9483        kill %+ || true # reads might have finished
9484        echo "wait until dd is finished"
9485        wait
9486        log "removing the temporary file"
9487        rm -rf $DIR/$tfile || error "tmp file removal failed"
9488 }
9489 run_test 218 "parallel read and truncate should not deadlock ======================="
9490
9491 test_219() {
9492         # write one partial page
9493         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
9494         # set no grant so vvp_io_commit_write will do sync write
9495         $LCTL set_param fail_loc=0x411
9496         # write a full page at the end of file
9497         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
9498
9499         $LCTL set_param fail_loc=0
9500         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
9501         $LCTL set_param fail_loc=0x411
9502         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
9503 }
9504 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
9505
9506 test_220() { #LU-325
9507         remote_ost_nodsh && skip "remote OST with nodsh" && return
9508         local OSTIDX=0
9509
9510         mkdir -p $DIR/$tdir
9511         local OST=$(lfs osts | grep ${OSTIDX}": " | \
9512                 awk '{print $2}' | sed -e 's/_UUID$//')
9513
9514         # on the mdt's osc
9515         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
9516         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
9517                         osc.$mdtosc_proc1.prealloc_last_id)
9518         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
9519                         osc.$mdtosc_proc1.prealloc_next_id)
9520
9521         $LFS df -i
9522
9523         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
9524         #define OBD_FAIL_OST_ENOINO              0x229
9525         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
9526         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
9527         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
9528
9529         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
9530
9531         MDSOBJS=$((last_id - next_id))
9532         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
9533
9534         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
9535         echo "OST still has $count kbytes free"
9536
9537         echo "create $MDSOBJS files @next_id..."
9538         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
9539
9540         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
9541                         osc.$mdtosc_proc1.prealloc_last_id)
9542         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
9543                         osc.$mdtosc_proc1.prealloc_next_id)
9544
9545         echo "after creation, last_id=$last_id2, next_id=$next_id2"
9546         $LFS df -i
9547
9548         echo "cleanup..."
9549
9550         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
9551         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
9552
9553         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
9554         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
9555         echo "unlink $MDSOBJS files @$next_id..."
9556         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
9557 }
9558 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
9559
9560 test_221() {
9561         dd if=`which date` of=$MOUNT/date oflag=sync
9562         chmod +x $MOUNT/date
9563
9564         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
9565         $LCTL set_param fail_loc=0x80001401
9566
9567         $MOUNT/date > /dev/null
9568         rm -f $MOUNT/date
9569 }
9570 run_test 221 "make sure fault and truncate race to not cause OOM"
9571
9572 test_222a () {
9573        rm -rf $DIR/$tdir
9574        mkdir -p $DIR/$tdir
9575        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9576        createmany -o $DIR/$tdir/$tfile 10
9577        cancel_lru_locks mdc
9578        cancel_lru_locks osc
9579        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
9580        $LCTL set_param fail_loc=0x31a
9581        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
9582        $LCTL set_param fail_loc=0
9583        rm -r $DIR/$tdir
9584 }
9585 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
9586
9587 test_222b () {
9588        rm -rf $DIR/$tdir
9589        mkdir -p $DIR/$tdir
9590        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9591        createmany -o $DIR/$tdir/$tfile 10
9592        cancel_lru_locks mdc
9593        cancel_lru_locks osc
9594        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
9595        $LCTL set_param fail_loc=0x31a
9596        rm -r $DIR/$tdir || "AGL for rmdir failed"
9597        $LCTL set_param fail_loc=0
9598 }
9599 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
9600
9601 test_223 () {
9602        rm -rf $DIR/$tdir
9603        mkdir -p $DIR/$tdir
9604        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
9605        createmany -o $DIR/$tdir/$tfile 10
9606        cancel_lru_locks mdc
9607        cancel_lru_locks osc
9608        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
9609        $LCTL set_param fail_loc=0x31b
9610        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
9611        $LCTL set_param fail_loc=0
9612        rm -r $DIR/$tdir
9613 }
9614 run_test 223 "osc reenqueue if without AGL lock granted ======================="
9615
9616 test_224a() { # LU-1039, MRP-303
9617         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
9618         $LCTL set_param fail_loc=0x508
9619         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
9620         $LCTL set_param fail_loc=0
9621         df $DIR
9622 }
9623 run_test 224a "Don't panic on bulk IO failure"
9624
9625 test_224b() { # LU-1039, MRP-303
9626         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
9627         cancel_lru_locks osc
9628         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
9629         $LCTL set_param fail_loc=0x515
9630         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
9631         $LCTL set_param fail_loc=0
9632         df $DIR
9633 }
9634 run_test 224b "Don't panic on bulk IO failure"
9635
9636 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
9637 test_225a () {
9638        if [ -z ${MDSSURVEY} ]; then
9639               skip_env "mds-survey not found" && return
9640        fi
9641        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
9642             { skip "Need MDS version at least 2.2.51"; return; }
9643
9644        local mds=$(facet_host $SINGLEMDS)
9645        local target=$(do_nodes $mds 'lctl dl' | \
9646                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
9647
9648        local cmd1="file_count=1000 thrhi=4"
9649        local cmd2="dir_count=2 layer=mdd stripe_count=0"
9650        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
9651        local cmd="$cmd1 $cmd2 $cmd3"
9652
9653        rm -f ${TMP}/mds_survey*
9654        echo + $cmd
9655        eval $cmd || error "mds-survey with zero-stripe failed"
9656        cat ${TMP}/mds_survey*
9657        rm -f ${TMP}/mds_survey*
9658 }
9659 run_test 225a "Metadata survey sanity with zero-stripe"
9660
9661 test_225b () {
9662        if [ -z ${MDSSURVEY} ]; then
9663               skip_env "mds-survey not found" && return
9664        fi
9665        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
9666             { skip "Need MDS version at least 2.2.51"; return; }
9667
9668        if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
9669               skip_env "Need to mount OST to test" && return
9670        fi
9671
9672        local mds=$(facet_host $SINGLEMDS)
9673        local target=$(do_nodes $mds 'lctl dl' | \
9674                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
9675
9676        local cmd1="file_count=1000 thrhi=4"
9677        local cmd2="dir_count=2 layer=mdd stripe_count=1"
9678        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
9679        local cmd="$cmd1 $cmd2 $cmd3"
9680
9681        rm -f ${TMP}/mds_survey*
9682        echo + $cmd
9683        eval $cmd || error "mds-survey with stripe_count failed"
9684        cat ${TMP}/mds_survey*
9685        rm -f ${TMP}/mds_survey*
9686 }
9687 run_test 225b "Metadata survey sanity with stripe_count = 1"
9688
9689 mcreate_path2fid () {
9690         local mode=$1
9691         local major=$2
9692         local minor=$3
9693         local name=$4
9694         local desc=$5
9695         local path=$DIR/$tdir/$name
9696         local fid
9697         local rc
9698         local fid_path
9699
9700         $MCREATE --mode=$1 --major=$2 --minor=$3 $path || \
9701                 error "error: cannot create $desc"
9702
9703         fid=$($LFS path2fid $path)
9704         rc=$?
9705         [ $rc -ne 0 ] && error "error: cannot get fid of a $desc"
9706
9707         fid_path=$($LFS fid2path $DIR $fid)
9708         rc=$?
9709         [ $rc -ne 0 ] && error "error: cannot get path of a $desc by fid"
9710
9711         [ "$path" == "$fid_path" ] || \
9712                 error "error: fid2path returned \`$fid_path', expected \`$path'"
9713 }
9714
9715 test_226 () {
9716         rm -rf $DIR/$tdir
9717         mkdir -p $DIR/$tdir
9718
9719         mcreate_path2fid 0010666 0 0 fifo "FIFO"
9720         mcreate_path2fid 0020666 1 3 null "character special file (null)"
9721         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
9722         mcreate_path2fid 0040666 0 0 dir "directory"
9723         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
9724         mcreate_path2fid 0100666 0 0 file "regular file"
9725         mcreate_path2fid 0120666 0 0 link "symbolic link"
9726         mcreate_path2fid 0140666 0 0 sock "socket"
9727 }
9728 run_test 226 "call path2fid and fid2path on files of all type"
9729
9730 # LU-1299 Executing or running ldd on a truncated executable does not
9731 # cause an out-of-memory condition.
9732 test_227() {
9733         dd if=`which date` of=$MOUNT/date bs=1k count=1
9734         chmod +x $MOUNT/date
9735
9736         $MOUNT/date > /dev/null
9737         ldd $MOUNT/date > /dev/null
9738         rm -f $MOUNT/date
9739 }
9740 run_test 227 "running truncated executable does not cause OOM"
9741
9742 # LU-1512 try to reuse idle OI blocks
9743 test_228a() {
9744         [ "$FSTYPE" != "ldiskfs" ] && skip "non-ldiskfs backend" && return
9745
9746         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9747         local myDIR=$DIR/$tdir
9748
9749         mkdir -p $myDIR
9750         #define OBD_FAIL_SEQ_EXHAUST             0x1002
9751         $LCTL set_param fail_loc=0x80001002
9752         createmany -o $myDIR/t- 10000
9753         $LCTL set_param fail_loc=0
9754         # The guard is current the largest FID holder
9755         touch $myDIR/guard
9756         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
9757                     tr -d '[')
9758         local IDX=$(($SEQ % 64))
9759
9760         do_facet $SINGLEMDS sync
9761         # Make sure journal flushed.
9762         sleep 6
9763         local blk1=$(do_facet $SINGLEMDS \
9764                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
9765                      grep Blockcount | awk '{print $4}')
9766
9767         # Remove old files, some OI blocks will become idle.
9768         unlinkmany $myDIR/t- 10000
9769         # Create new files, idle OI blocks should be reused.
9770         createmany -o $myDIR/t- 2000
9771         do_facet $SINGLEMDS sync
9772         # Make sure journal flushed.
9773         sleep 6
9774         local blk2=$(do_facet $SINGLEMDS \
9775                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
9776                      grep Blockcount | awk '{print $4}')
9777
9778         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
9779 }
9780 run_test 228a "try to reuse idle OI blocks"
9781
9782 test_228b() {
9783         [ "$FSTYPE" != "ldiskfs" ] && skip "non-ldiskfs backend" && return
9784
9785         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9786         local myDIR=$DIR/$tdir
9787
9788         mkdir -p $myDIR
9789         #define OBD_FAIL_SEQ_EXHAUST             0x1002
9790         $LCTL set_param fail_loc=0x80001002
9791         createmany -o $myDIR/t- 10000
9792         $LCTL set_param fail_loc=0
9793         # The guard is current the largest FID holder
9794         touch $myDIR/guard
9795         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
9796                     tr -d '[')
9797         local IDX=$(($SEQ % 64))
9798
9799         do_facet $SINGLEMDS sync
9800         # Make sure journal flushed.
9801         sleep 6
9802         local blk1=$(do_facet $SINGLEMDS \
9803                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
9804                      grep Blockcount | awk '{print $4}')
9805
9806         # Remove old files, some OI blocks will become idle.
9807         unlinkmany $myDIR/t- 10000
9808
9809         # stop the MDT
9810         stop $SINGLEMDS || error "Fail to stop MDT."
9811         # remount the MDT
9812         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
9813
9814         df $MOUNT || error "Fail to df."
9815         # Create new files, idle OI blocks should be reused.
9816         createmany -o $myDIR/t- 2000
9817         do_facet $SINGLEMDS sync
9818         # Make sure journal flushed.
9819         sleep 6
9820         local blk2=$(do_facet $SINGLEMDS \
9821                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
9822                      grep Blockcount | awk '{print $4}')
9823
9824         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
9825 }
9826 run_test 228b "idle OI blocks can be reused after MDT restart"
9827
9828 #LU-1881
9829 test_228c() {
9830         [ "$FSTYPE" != "ldiskfs" ] && skip "non-ldiskfs backend" && return
9831
9832         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9833         local myDIR=$DIR/$tdir
9834
9835         mkdir -p $myDIR
9836         #define OBD_FAIL_SEQ_EXHAUST             0x1002
9837         $LCTL set_param fail_loc=0x80001002
9838         # 20000 files can guarantee there are index nodes in the OI file
9839         createmany -o $myDIR/t- 20000
9840         $LCTL set_param fail_loc=0
9841         # The guard is current the largest FID holder
9842         touch $myDIR/guard
9843         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
9844                     tr -d '[')
9845         local IDX=$(($SEQ % 64))
9846
9847         do_facet $SINGLEMDS sync
9848         # Make sure journal flushed.
9849         sleep 6
9850         local blk1=$(do_facet $SINGLEMDS \
9851                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
9852                      grep Blockcount | awk '{print $4}')
9853
9854         # Remove old files, some OI blocks will become idle.
9855         unlinkmany $myDIR/t- 20000
9856         rm -f $myDIR/guard
9857         # The OI file should become empty now
9858
9859         # Create new files, idle OI blocks should be reused.
9860         createmany -o $myDIR/t- 2000
9861         do_facet $SINGLEMDS sync
9862         # Make sure journal flushed.
9863         sleep 6
9864         local blk2=$(do_facet $SINGLEMDS \
9865                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
9866                      grep Blockcount | awk '{print $4}')
9867
9868         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
9869 }
9870 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
9871
9872 #
9873 # tests that do cleanup/setup should be run at the end
9874 #
9875
9876 test_900() {
9877         local ls
9878         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
9879         $LCTL set_param fail_loc=0x903
9880         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
9881         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
9882                 echo "clear" > $ls
9883         done
9884         FAIL_ON_ERROR=true cleanup
9885         FAIL_ON_ERROR=true setup
9886 }
9887 run_test 900 "umount should not race with any mgc requeue thread"
9888
9889 complete $SECONDS
9890 check_and_cleanup_lustre
9891 if [ "$I_MOUNTED" != "yes" ]; then
9892         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
9893 fi
9894 exit_status