Whamcloud - gitweb
LU-2826 tests: Re-enable sanity/18
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 4; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19
20 SRCDIR=$(cd $(dirname $0); echo $PWD)
21 export PATH=$PATH:/sbin
22
23 TMP=${TMP:-/tmp}
24
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
27 LFS=${LFS:-lfs}
28 LFIND=${LFIND:-"$LFS find"}
29 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
30 LCTL=${LCTL:-lctl}
31 MCREATE=${MCREATE:-mcreate}
32 OPENFILE=${OPENFILE:-openfile}
33 OPENUNLINK=${OPENUNLINK:-openunlink}
34 export MULTIOP=${MULTIOP:-multiop}
35 READS=${READS:-"reads"}
36 MUNLINK=${MUNLINK:-munlink}
37 SOCKETSERVER=${SOCKETSERVER:-socketserver}
38 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
39 MEMHOG=${MEMHOG:-memhog}
40 DIRECTIO=${DIRECTIO:-directio}
41 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
42 UMOUNT=${UMOUNT:-"umount -d"}
43 STRIPES_PER_OBJ=-1
44 CHECK_GRANT=${CHECK_GRANT:-"yes"}
45 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
46 export PARALLEL=${PARALLEL:-"no"}
47
48 export NAME=${NAME:-local}
49
50 SAVE_PWD=$PWD
51
52 CLEANUP=${CLEANUP:-:}
53 SETUP=${SETUP:-:}
54 TRACE=${TRACE:-""}
55 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
56 . $LUSTRE/tests/test-framework.sh
57 init_test_env $@
58 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
59 init_logging
60
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b"
62
63 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
64 # bug number for skipped test:        LU-1593 LU-2610 LU-2833 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     40      48a     180     184c"
66
67 FAIL_ON_ERROR=false
68
69 cleanup() {
70         echo -n "cln.."
71         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
72         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
73 }
74 setup() {
75         echo -n "mnt.."
76         load_modules
77         setupall || exit 10
78         echo "done"
79 }
80
81 check_kernel_version() {
82         WANT_VER=$1
83         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
84         case $GOT_VER in
85         patchless|patchless_client) return 0;;
86         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
87         esac
88         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
89         return 1
90 }
91
92 check_swap_layouts_support()
93 {
94         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
95                 { skip "Does not support layout lock."; return 0; }
96         return 1
97 }
98
99 if [ "$ONLY" == "cleanup" ]; then
100        sh llmountcleanup.sh
101        exit 0
102 fi
103
104 check_and_setup_lustre
105
106 DIR=${DIR:-$MOUNT}
107 assert_DIR
108
109 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
110     awk '{gsub(/_UUID/,""); print $1}' | head -1)
111 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
112 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
113 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
114 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
115 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
116 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
117
118 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
119 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
120 rm -rf $DIR/[Rdfs][0-9]*
121
122 # $RUNAS_ID may get set incorrectly somewhere else
123 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
124
125 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
126
127 build_test_filter
128
129 if [ "${ONLY}" = "MOUNT" ] ; then
130         echo "Lustre is up, please go on"
131         exit
132 fi
133
134 echo "preparing for tests involving mounts"
135 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
136 touch $EXT2_DEV
137 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
138 echo # add a newline after mke2fs.
139
140 umask 077
141
142 OLDDEBUG="`lctl get_param -n debug 2> /dev/null`"
143 lctl set_param debug=-1 2> /dev/null || true
144 test_0() {
145         touch $DIR/$tfile
146         $CHECKSTAT -t file $DIR/$tfile || error
147         rm $DIR/$tfile
148         $CHECKSTAT -a $DIR/$tfile || error
149 }
150 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
151
152 test_0b() {
153         chmod 0755 $DIR || error
154         $CHECKSTAT -p 0755 $DIR || error
155 }
156 run_test 0b "chmod 0755 $DIR ============================="
157
158 test_0c() {
159     $LCTL get_param mdc.*.import | grep  "state: FULL" || error "import not FULL"
160     $LCTL get_param mdc.*.import | grep  "target: $FSNAME-MDT" || error "bad target"
161 }
162 run_test 0c "check import proc ============================="
163
164 test_1a() {
165         test_mkdir -p $DIR/$tdir
166         test_mkdir -p $DIR/$tdir/d2
167         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
168         $CHECKSTAT -t dir $DIR/$tdir/d2 || error
169 }
170 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
171
172 test_1b() {
173         rmdir $DIR/$tdir/d2
174         rmdir $DIR/$tdir
175         $CHECKSTAT -a $DIR/$tdir || error
176 }
177 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
178
179 test_2a() {
180         test_mkdir $DIR/$tdir
181         touch $DIR/$tdir/$tfile
182         $CHECKSTAT -t file $DIR/$tdir/$tfile || error
183 }
184 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
185
186 test_2b() {
187         rm -r $DIR/$tdir
188         $CHECKSTAT -a $DIR/$tdir || error
189 }
190 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
191
192 test_3a() {
193         test_mkdir -p $DIR/$tdir
194         $CHECKSTAT -t dir $DIR/$tdir || error
195 }
196 run_test 3a "mkdir .../d3 ======================================"
197
198 test_3b() {
199         if [ ! -d $DIR/$tdir ]; then
200                 mkdir $DIR/$tdir
201         fi
202         touch $DIR/$tdir/$tfile
203         $CHECKSTAT -t file $DIR/$tdir/$tfile || error
204 }
205 run_test 3b "touch .../d3/f ===================================="
206
207 test_3c() {
208         rm -r $DIR/$tdir
209         $CHECKSTAT -a $DIR/$tdir || error
210 }
211 run_test 3c "rm -r .../d3 ======================================"
212
213 test_4a() {
214         test_mkdir -p $DIR/$tdir
215         $CHECKSTAT -t dir $DIR/$tdir || error
216 }
217 run_test 4a "mkdir .../d4 ======================================"
218
219 test_4b() {
220         if [ ! -d $DIR/$tdir ]; then
221                 test_mkdir $DIR/$tdir
222         fi
223         test_mkdir $DIR/$tdir/d2
224         mkdir $DIR/$tdir/d2
225         $CHECKSTAT -t dir $DIR/$tdir/d2 || error
226 }
227 run_test 4b "mkdir .../d4/d2 ==================================="
228
229 test_5() {
230         test_mkdir $DIR/$tdir
231         test_mkdir $DIR/$tdir/d2
232         chmod 0707 $DIR/$tdir/d2
233         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error
234 }
235 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
236
237 test_6a() {
238         touch $DIR/$tfile
239         chmod 0666 $DIR/$tfile || error
240         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile || error
241 }
242 run_test 6a "touch .../f6a; chmod .../f6a ======================"
243
244 test_6b() {
245         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
246         if [ ! -f $DIR/$tfile ]; then
247                 touch $DIR/$tfile
248                 chmod 0666 $DIR/$tfile
249         fi
250         $RUNAS chmod 0444 $DIR/$tfile && error
251         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile || error
252 }
253 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
254
255 test_6c() {
256         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
257         touch $DIR/$tfile
258         chown $RUNAS_ID $DIR/$tfile || error
259         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile || error
260 }
261 run_test 6c "touch .../f6c; chown .../f6c ======================"
262
263 test_6d() {
264         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
265         if [ ! -f $DIR/$tfile ]; then
266                 touch $DIR/$tfile
267                 chown $RUNAS_ID $DIR/$tfile
268         fi
269         $RUNAS chown $UID $DIR/$tfile && error
270         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile || error
271 }
272 run_test 6d "$RUNAS chown .../f6c (should return error) =="
273
274 test_6e() {
275         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
276         touch $DIR/$tfile
277         chgrp $RUNAS_ID $DIR/$tfile || error
278         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile || error
279 }
280 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
281
282 test_6f() {
283         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
284         if [ ! -f $DIR/$tfile ]; then
285                 touch $DIR/$tfile
286                 chgrp $RUNAS_ID $DIR/$tfile
287         fi
288         $RUNAS chgrp $UID $DIR/$tfile && error
289         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile || error
290 }
291 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
292
293 test_6g() {
294         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
295         test_mkdir $DIR/$tdir || error
296         chmod 777 $DIR/$tdir || error
297         $RUNAS mkdir $DIR/$tdir/d || error
298         chmod g+s $DIR/$tdir/d || error
299         test_mkdir $DIR/$tdir/d/subdir
300         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir || error
301 }
302 run_test 6g "Is new dir in sgid dir inheriting group?"
303
304 test_6h() { # bug 7331
305         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
306         touch $DIR/$tfile || error "touch failed"
307         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
308         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
309                 error "chown worked"
310         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile || error
311 }
312 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
313
314 test_7a() {
315         test_mkdir $DIR/$tdir
316         $MCREATE $DIR/$tdir/$tfile
317         chmod 0666 $DIR/$tdir/$tfile
318         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile || error
319 }
320 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
321
322 test_7b() {
323         if [ ! -d $DIR/$tdir ]; then
324                 mkdir $DIR/$tdir
325         fi
326         $MCREATE $DIR/$tdir/$tfile
327         echo -n foo > $DIR/$tdir/$tfile
328         [ "`cat $DIR/$tdir/$tfile`" = "foo" ] || error
329         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error
330 }
331 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
332
333 test_8() {
334         test_mkdir $DIR/$tdir
335         touch $DIR/$tdir/$tfile
336         chmod 0666 $DIR/$tdir/$tfile
337         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile || error
338 }
339 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
340
341 test_9() {
342         test_mkdir $DIR/$tdir
343         test_mkdir $DIR/$tdir/d2
344         test_mkdir $DIR/$tdir/d2/d3
345         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error
346 }
347 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
348
349 test_10() {
350         test_mkdir $DIR/$tdir
351         test_mkdir $DIR/$tdir/d2
352         touch $DIR/$tdir/d2/$tfile
353         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile || error
354 }
355 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
356
357 test_11() {
358         test_mkdir $DIR/$tdir
359         test_mkdir $DIR/$tdir/d2
360         chmod 0666 $DIR/$tdir/d2
361         chmod 0705 $DIR/$tdir/d2
362         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 || error
363 }
364 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
365
366 test_12() {
367         test_mkdir $DIR/$tdir
368         touch $DIR/$tdir/$tfile
369         chmod 0666 $DIR/$tdir/$tfile
370         chmod 0654 $DIR/$tdir/$tfile
371         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile || error
372 }
373 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
374
375 test_13() {
376         test_mkdir $DIR/$tdir
377         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
378         >  $DIR/$tdir/$tfile
379         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile || error
380 }
381 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
382
383 test_14() {
384         test_mkdir $DIR/$tdir
385         touch $DIR/$tdir/$tfile
386         rm $DIR/$tdir/$tfile
387         $CHECKSTAT -a $DIR/$tdir/$tfile || error
388 }
389 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
390
391 test_15() {
392         test_mkdir $DIR/$tdir
393         touch $DIR/$tdir/$tfile
394         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
395         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 || error
396 }
397 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
398
399 test_16() {
400         test_mkdir $DIR/$tdir
401         touch $DIR/$tdir/$tfile
402         rm -rf $DIR/$tdir/$tfile
403         $CHECKSTAT -a $DIR/$tdir/$tfile || error
404 }
405 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
406
407 test_17a() {
408         test_mkdir -p $DIR/$tdir
409         touch $DIR/$tdir/$tfile
410         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
411         ls -l $DIR/$tdir
412         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist || error
413         $CHECKSTAT -f -t f $DIR/$tdir/l-exist || error
414         rm -f $DIR/$tdir/l-exist
415         $CHECKSTAT -a $DIR/$tdir/l-exist || error
416 }
417 run_test 17a "symlinks: create, remove (real) =================="
418
419 test_17b() {
420         test_mkdir -p $DIR/$tdir
421         ln -s no-such-file $DIR/$tdir/l-dangle
422         ls -l $DIR/$tdir
423         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle || error
424         $CHECKSTAT -fa $DIR/$tdir/l-dangle || error
425         rm -f $DIR/$tdir/l-dangle
426         $CHECKSTAT -a $DIR/$tdir/l-dangle || error
427 }
428 run_test 17b "symlinks: create, remove (dangling) =============="
429
430 test_17c() { # bug 3440 - don't save failed open RPC for replay
431         test_mkdir -p $DIR/$tdir
432         ln -s foo $DIR/$tdir/$tfile
433         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
434 }
435 run_test 17c "symlinks: open dangling (should return error) ===="
436
437 test_17d() {
438         test_mkdir -p $DIR/$tdir
439         ln -s foo $DIR/$tdir/$tfile
440         touch $DIR/$tdir/$tfile || error "creating to new symlink"
441 }
442 run_test 17d "symlinks: create dangling ========================"
443
444 test_17e() {
445         test_mkdir -p $DIR/$tdir
446         local foo=$DIR/$tdir/$tfile
447         ln -s $foo $foo || error "create symlink failed"
448         ls -l $foo || error "ls -l failed"
449         ls $foo && error "ls not failed" || true
450 }
451 run_test 17e "symlinks: create recursive symlink (should return error) ===="
452
453 test_17f() {
454         test_mkdir -p $DIR/d17f
455         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
456         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
457         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
458         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
459         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
460         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
461         ls -l  $DIR/d17f
462 }
463 run_test 17f "symlinks: long and very long symlink name ========================"
464
465 # str_repeat(S, N) generate a string that is string S repeated N times
466 str_repeat() {
467         local s=$1
468         local n=$2
469         local ret=''
470         while [ $((n -= 1)) -ge 0 ]; do
471                 ret=$ret$s
472         done
473         echo $ret
474 }
475
476 # Long symlinks and LU-2241
477 test_17g() {
478         test_mkdir -p $DIR/$tdir
479         local TESTS="59 60 61 4094 4095"
480
481         # Fix for inode size boundary in 2.1.4
482         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
483                 TESTS="4094 4095"
484
485         # Patch not applied to 2.2 or 2.3 branches
486         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
487         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
488                 TESTS="4094 4095"
489
490         for i in $TESTS; do
491                 local SYMNAME=$(str_repeat 'x' $i)
492                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
493                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
494         done
495 }
496 run_test 17g "symlinks: really long symlink name and inode boundaries"
497
498 test_17h() { #bug 17378
499         remote_mds_nodsh && skip "remote MDS with nodsh" && return
500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
501         local mdt_idx
502         test_mkdir -p $DIR/$tdir
503         if [ $MDSCOUNT -gt 1 ]; then
504                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
505         else
506                 mdt_idx=0
507         fi
508         $SETSTRIPE -c -1 $DIR/$tdir
509 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
510         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
511         touch $DIR/$tdir/$tfile || true
512 }
513 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
514
515 test_17i() { #bug 20018
516         remote_mds_nodsh && skip "remote MDS with nodsh" && return
517         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
518         test_mkdir -p $DIR/$tdir
519         local foo=$DIR/$tdir/$tfile
520         local mdt_idx
521         if [ $MDSCOUNT -gt 1 ]; then
522                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
523         else
524                 mdt_idx=0
525         fi
526         ln -s $foo $foo || error "create symlink failed"
527 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
528         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
529         ls -l $foo && error "error not detected"
530         return 0
531 }
532 run_test 17i "don't panic on short symlink"
533
534 test_17k() { #bug 22301
535         rsync --help | grep -q xattr ||
536                 skip_env "$(rsync --version| head -1) does not support xattrs"
537         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
538         test_mkdir -p $DIR/$tdir
539         test_mkdir -p $DIR/$tdir.new
540         touch $DIR/$tdir/$tfile
541         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
542         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
543                 error "rsync failed with xattrs enabled"
544 }
545 run_test 17k "symlinks: rsync with xattrs enabled ========================="
546
547 test_17l() { # LU-279
548         mkdir -p $DIR/$tdir
549         touch $DIR/$tdir/$tfile
550         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
551         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
552                 # -h to not follow symlinks. -m '' to list all the xattrs.
553                 # grep to remove first line: '# file: $path'.
554                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
555                 do
556                         lgetxattr_size_check $path $xattr ||
557                                 error "lgetxattr_size_check $path $xattr failed"
558                 done
559         done
560 }
561 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
562
563 # LU-1540
564 test_17m() {
565         local short_sym="0123456789"
566         local WDIR=$DIR/${tdir}m
567         local mds_index
568         local devname
569         local cmd
570         local i
571         local rc=0
572
573         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
574         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
575                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
576
577         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
578                 skip "only for ldiskfs MDT" && return 0
579
580         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
581
582         mkdir -p $WDIR
583         long_sym=$short_sym
584         # create a long symlink file
585         for ((i = 0; i < 4; ++i)); do
586                 long_sym=${long_sym}${long_sym}
587         done
588
589         echo "create 512 short and long symlink files under $WDIR"
590         for ((i = 0; i < 256; ++i)); do
591                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
592                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
593         done
594
595         echo "erase them"
596         rm -f $WDIR/*
597         sync
598         wait_delete_completed
599
600         echo "recreate the 512 symlink files with a shorter string"
601         for ((i = 0; i < 512; ++i)); do
602                 # rewrite the symlink file with a shorter string
603                 ln -sf ${long_sym} $WDIR/long-$i
604                 ln -sf ${short_sym} $WDIR/short-$i
605         done
606
607         mds_index=$($LFS getstripe -M $WDIR)
608         mds_index=$((mds_index+1))
609         devname=$(mdsdevname $mds_index)
610         cmd="$E2FSCK -fnvd $devname"
611
612         echo "stop and checking mds${mds_index}: $cmd"
613         # e2fsck should not return error
614         stop mds${mds_index} -f
615         do_facet mds${mds_index} $cmd || rc=$?
616
617         start mds${mds_index} $devname $MDS_MOUNT_OPTS
618         df $MOUNT > /dev/null 2>&1
619         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
620                 "short/long symlink MDT: rc=$rc"
621         return $rc
622 }
623 run_test 17m "run e2fsck against MDT which contains short/long symlink"
624
625 check_fs_consistency_17n() {
626         local mdt_index
627         local devname
628         local cmd
629         local rc=0
630
631         for mdt_index in $(seq 1 $MDSCOUNT); do
632                 devname=$(mdsdevname $mdt_index)
633                 cmd="$E2FSCK -fnvd $devname"
634
635                 echo "stop and checking mds${mdt_index}: $cmd"
636                 # e2fsck should not return error
637                 stop mds${mdt_index}
638                 do_facet mds${mdt_index} $cmd || rc=$?
639
640                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
641                 df $MOUNT > /dev/null 2>&1
642                 [ $rc -ne 0 ] && break
643         done
644         return $rc
645 }
646
647 test_17n() {
648         local i
649
650         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
651         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
652                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
653
654         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
655                 skip "only for ldiskfs MDT" && return 0
656
657         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
658
659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
660
661         mkdir -p $DIR/$tdir
662         for ((i=0; i<10; i++)); do
663                 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
664                         error "create remote dir error $i"
665                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
666                         error "create files under remote dir failed $i"
667         done
668
669         check_fs_consistency_17n || error "e2fsck report error"
670
671         for ((i=0;i<10;i++)); do
672                 rm -rf $DIR/$tdir/remote_dir_${i} ||
673                         error "destroy remote dir error $i"
674         done
675
676         check_fs_consistency_17n || error "e2fsck report error"
677 }
678 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
679
680 test_18() {
681         touch $DIR/f || error "Failed to touch $DIR/f: $?"
682         ls $DIR || error "Failed to ls $DIR: $?"
683 }
684 run_test 18 "touch .../f ; ls ... =============================="
685
686 test_19a() {
687         touch $DIR/f19
688         ls -l $DIR
689         rm $DIR/f19
690         $CHECKSTAT -a $DIR/f19 || error
691 }
692 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
693
694 test_19b() {
695         ls -l $DIR/f19 && error || true
696 }
697 run_test 19b "ls -l .../f19 (should return error) =============="
698
699 test_19c() {
700         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
701         $RUNAS touch $DIR/f19 && error || true
702 }
703 run_test 19c "$RUNAS touch .../f19 (should return error) =="
704
705 test_19d() {
706         cat $DIR/f19 && error || true
707 }
708 run_test 19d "cat .../f19 (should return error) =============="
709
710 test_20() {
711         touch $DIR/f
712         rm $DIR/f
713         log "1 done"
714         touch $DIR/f
715         rm $DIR/f
716         log "2 done"
717         touch $DIR/f
718         rm $DIR/f
719         log "3 done"
720         $CHECKSTAT -a $DIR/f || error
721 }
722 run_test 20 "touch .../f ; ls -l ... ==========================="
723
724 test_21() {
725         test_mkdir $DIR/d21
726         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
727         ln -s dangle $DIR/d21/link
728         echo foo >> $DIR/d21/link
729         cat $DIR/d21/dangle
730         $CHECKSTAT -t link $DIR/d21/link || error
731         $CHECKSTAT -f -t file $DIR/d21/link || error
732 }
733 run_test 21 "write to dangling link ============================"
734
735 test_22() {
736         WDIR=$DIR/$tdir
737         test_mkdir -p $DIR/$tdir
738         chown $RUNAS_ID:$RUNAS_GID $WDIR
739         (cd $WDIR || error "cd $WDIR failed";
740         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
741         $RUNAS tar xf -)
742         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
743         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
744         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
745 }
746 run_test 22 "unpack tar archive as non-root user ==============="
747
748 # was test_23
749 test_23a() {
750         test_mkdir -p $DIR/$tdir
751         local file=$DIR/$tdir/$tfile
752
753         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
754         openfile -f O_CREAT:O_EXCL $file &&
755                 error "$file recreate succeeded" || true
756 }
757 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
758
759 test_23b() { # bug 18988
760         test_mkdir -p $DIR/$tdir
761         local file=$DIR/$tdir/$tfile
762
763         rm -f $file
764         echo foo > $file || error "write filed"
765         echo bar >> $file || error "append filed"
766         $CHECKSTAT -s 8 $file || error "wrong size"
767         rm $file
768 }
769 run_test 23b "O_APPEND check =========================="
770
771 test_24a() {
772         echo '== rename sanity =============================================='
773         echo '-- same directory rename'
774         test_mkdir $DIR/R1
775         touch $DIR/R1/f
776         mv $DIR/R1/f $DIR/R1/g
777         $CHECKSTAT -t file $DIR/R1/g || error
778 }
779 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
780
781 test_24b() {
782         test_mkdir $DIR/R2
783         touch $DIR/R2/{f,g}
784         mv $DIR/R2/f $DIR/R2/g
785         $CHECKSTAT -a $DIR/R2/f || error
786         $CHECKSTAT -t file $DIR/R2/g || error
787 }
788 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
789
790 test_24c() {
791         test_mkdir $DIR/R3
792         test_mkdir $DIR/R3/f
793         mv $DIR/R3/f $DIR/R3/g
794         $CHECKSTAT -a $DIR/R3/f || error
795         $CHECKSTAT -t dir $DIR/R3/g || error
796 }
797 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
798
799 test_24d() {
800         test_mkdir $DIR/R4
801         test_mkdir $DIR/R4/f
802         test_mkdir $DIR/R4/g
803         mrename $DIR/R4/f $DIR/R4/g
804         $CHECKSTAT -a $DIR/R4/f || error
805         $CHECKSTAT -t dir $DIR/R4/g || error
806 }
807 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
808
809 test_24e() {
810         echo '-- cross directory renames --'
811         test_mkdir $DIR/R5a
812         test_mkdir $DIR/R5b
813         touch $DIR/R5a/f
814         mv $DIR/R5a/f $DIR/R5b/g
815         $CHECKSTAT -a $DIR/R5a/f || error
816         $CHECKSTAT -t file $DIR/R5b/g || error
817 }
818 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
819
820 test_24f() {
821         test_mkdir $DIR/R6a
822         test_mkdir $DIR/R6b
823         touch $DIR/R6a/f $DIR/R6b/g
824         mv $DIR/R6a/f $DIR/R6b/g
825         $CHECKSTAT -a $DIR/R6a/f || error
826         $CHECKSTAT -t file $DIR/R6b/g || error
827 }
828 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
829
830 test_24g() {
831         test_mkdir $DIR/R7a
832         test_mkdir $DIR/R7b
833         test_mkdir $DIR/R7a/d
834         mv $DIR/R7a/d $DIR/R7b/e
835         $CHECKSTAT -a $DIR/R7a/d || error
836         $CHECKSTAT -t dir $DIR/R7b/e || error
837 }
838 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
839
840 test_24h() {
841         test_mkdir $DIR/R8a
842         test_mkdir $DIR/R8b
843         test_mkdir $DIR/R8a/d
844         test_mkdir $DIR/R8b/e
845         mrename $DIR/R8a/d $DIR/R8b/e
846         $CHECKSTAT -a $DIR/R8a/d || error
847         $CHECKSTAT -t dir $DIR/R8b/e || error
848 }
849 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
850
851 test_24i() {
852         echo "-- rename error cases"
853         test_mkdir $DIR/R9
854         test_mkdir $DIR/R9/a
855         touch $DIR/R9/f
856         mrename $DIR/R9/f $DIR/R9/a
857         $CHECKSTAT -t file $DIR/R9/f || error
858         $CHECKSTAT -t dir  $DIR/R9/a || error
859         $CHECKSTAT -a $DIR/R9/a/f || error
860 }
861 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
862
863 test_24j() {
864         test_mkdir $DIR/R10
865         mrename $DIR/R10/f $DIR/R10/g
866         $CHECKSTAT -t dir $DIR/R10 || error
867         $CHECKSTAT -a $DIR/R10/f || error
868         $CHECKSTAT -a $DIR/R10/g || error
869 }
870 run_test 24j "source does not exist ============================"
871
872 test_24k() {
873         test_mkdir $DIR/R11a
874         test_mkdir $DIR/R11a/d
875         touch $DIR/R11a/f
876         mv $DIR/R11a/f $DIR/R11a/d
877         $CHECKSTAT -a $DIR/R11a/f || error
878         $CHECKSTAT -t file $DIR/R11a/d/f || error
879 }
880 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
881
882 # bug 2429 - rename foo foo foo creates invalid file
883 test_24l() {
884         f="$DIR/f24l"
885         $MULTIOP $f OcNs || error
886 }
887 run_test 24l "Renaming a file to itself ========================"
888
889 test_24m() {
890         f="$DIR/f24m"
891         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
892         # on ext3 this does not remove either the source or target files
893         # though the "expected" operation would be to remove the source
894         $CHECKSTAT -t file ${f} || error "${f} missing"
895         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
896 }
897 run_test 24m "Renaming a file to a hard link to itself ========="
898
899 test_24n() {
900     f="$DIR/f24n"
901     # this stats the old file after it was renamed, so it should fail
902     touch ${f}
903     $CHECKSTAT ${f}
904     mv ${f} ${f}.rename
905     $CHECKSTAT ${f}.rename
906     $CHECKSTAT -a ${f}
907 }
908 run_test 24n "Statting the old file after renaming (Posix rename 2)"
909
910 test_24o() {
911         check_kernel_version 37 || return 0
912         test_mkdir -p $DIR/d24o
913         rename_many -s random -v -n 10 $DIR/d24o
914 }
915 run_test 24o "rename of files during htree split ==============="
916
917 test_24p() {
918         test_mkdir $DIR/R12a
919         test_mkdir $DIR/R12b
920         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
921         mrename $DIR/R12a $DIR/R12b
922         $CHECKSTAT -a $DIR/R12a || error
923         $CHECKSTAT -t dir $DIR/R12b || error
924         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
925         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
926 }
927 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
928
929 cleanup_multiop_pause() {
930         trap 0
931         kill -USR1 $MULTIPID
932 }
933
934 test_24q() {
935         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
936         test_mkdir $DIR/R13a
937         test_mkdir $DIR/R13b
938         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
939         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
940         MULTIPID=$!
941
942         trap cleanup_multiop_pause EXIT
943         mrename $DIR/R13a $DIR/R13b
944         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
945         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
946         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
947         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
948         cleanup_multiop_pause
949         wait $MULTIPID || error "multiop close failed"
950 }
951 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
952
953 test_24r() { #bug 3789
954         test_mkdir $DIR/R14a
955         test_mkdir $DIR/R14a/b
956         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
957         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
958         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
959 }
960 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
961
962 test_24s() {
963         test_mkdir $DIR/R15a
964         test_mkdir $DIR/R15a/b
965         test_mkdir $DIR/R15a/b/c
966         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
967         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
968         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
969 }
970 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
971 test_24t() {
972         test_mkdir $DIR/R16a
973         test_mkdir $DIR/R16a/b
974         test_mkdir $DIR/R16a/b/c
975         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
976         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
977         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
978 }
979 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
980
981 test_24u() { # bug12192
982         rm -rf $DIR/$tfile
983         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
984         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
985 }
986 run_test 24u "create stripe file"
987
988 page_size() {
989         getconf PAGE_SIZE
990 }
991
992 simple_cleanup_common() {
993         trap 0
994         rm -rf $DIR/$tdir
995         wait_delete_completed
996 }
997
998 max_pages_per_rpc() {
999         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -1
1000 }
1001
1002 test_24v() {
1003         local NRFILES=100000
1004         local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
1005         [ $FREE_INODES -lt $NRFILES ] && \
1006                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1007                 return
1008
1009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1010         trap simple_cleanup_common EXIT
1011
1012         mkdir -p $DIR/$tdir
1013         createmany -m $DIR/$tdir/$tfile $NRFILES
1014
1015         cancel_lru_locks mdc
1016         lctl set_param mdc.*.stats clear
1017
1018         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1019
1020         # LU-5 large readdir
1021         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1022         #               8 bytes for name(filename is mostly 5 in this test) +
1023         #               8 bytes for luda_type
1024         # take into account of overhead in lu_dirpage header and end mark in
1025         # each page, plus one in RPC_NUM calculation.
1026         DIRENT_SIZE=48
1027         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1028         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1029         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats | \
1030                                 awk '/^mds_readpage/ {print $2}')
1031         [ $mds_readpage -gt $RPC_NUM ] && \
1032                 error "large readdir doesn't take effect"
1033
1034         simple_cleanup_common
1035 }
1036 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1037
1038 test_24w() { # bug21506
1039         SZ1=234852
1040         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1041         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1042         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1043         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1044         [ "$SZ1" = "$SZ2" ] || \
1045                 error "Error reading at the end of the file $tfile"
1046 }
1047 run_test 24w "Reading a file larger than 4Gb"
1048
1049 test_24x() {
1050         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1052         local MDTIDX=1
1053         local remote_dir=$DIR/$tdir/remote_dir
1054
1055         mkdir -p $DIR/$tdir
1056         $LFS mkdir -i $MDTIDX $remote_dir ||
1057                 error "create remote directory failed"
1058
1059         mkdir -p $DIR/$tdir/src_dir
1060         touch $DIR/$tdir/src_file
1061         mkdir -p $remote_dir/tgt_dir
1062         touch $remote_dir/tgt_file
1063
1064         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1065                 error "rename dir cross MDT works!"
1066
1067         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1068                 error "rename file cross MDT works!"
1069
1070         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1071                 error "ln file cross MDT should not work!"
1072
1073         rm -rf $DIR/$tdir || error "Can not delete directories"
1074 }
1075 run_test 24x "cross rename/link should be failed"
1076
1077 test_24y() {
1078         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1080         local MDTIDX=1
1081         local remote_dir=$DIR/$tdir/remote_dir
1082
1083         mkdir -p $DIR/$tdir
1084         $LFS mkdir -i $MDTIDX $remote_dir ||
1085                    error "create remote directory failed"
1086
1087         mkdir -p $remote_dir/src_dir
1088         touch $remote_dir/src_file
1089         mkdir -p $remote_dir/tgt_dir
1090         touch $remote_dir/tgt_file
1091
1092         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1093                 error "rename subdir in the same remote dir failed!"
1094
1095         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1096                 error "rename files in the same remote dir failed!"
1097
1098         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1099                 error "link files in the same remote dir failed!"
1100
1101         rm -rf $DIR/$tdir || error "Can not delete directories"
1102 }
1103 run_test 24y "rename/link on the same dir should succeed"
1104
1105 test_24z() {
1106         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1108         local MDTIDX=1
1109         local remote_src=$DIR/$tdir/remote_dir
1110         local remote_tgt=$DIR/$tdir/remote_tgt
1111
1112         mkdir -p $DIR/$tdir
1113         $LFS mkdir -i $MDTIDX $remote_src ||
1114                    error "create remote directory failed"
1115
1116         $LFS mkdir -i $MDTIDX $remote_tgt ||
1117                    error "create remote directory failed"
1118
1119         mrename $remote_src $remote_tgt &&
1120                 error "rename remote dirs should not work!"
1121
1122         rm -rf $DIR/$tdir || error "Can not delete directories"
1123 }
1124 run_test 24z "rename one remote dir to another remote dir should fail"
1125
1126 test_25a() {
1127         echo '== symlink sanity ============================================='
1128
1129         test_mkdir $DIR/d25
1130         ln -s d25 $DIR/s25
1131         touch $DIR/s25/foo || error
1132 }
1133 run_test 25a "create file in symlinked directory ==============="
1134
1135 test_25b() {
1136         [ ! -d $DIR/d25 ] && test_25a
1137         $CHECKSTAT -t file $DIR/s25/foo || error
1138 }
1139 run_test 25b "lookup file in symlinked directory ==============="
1140
1141 test_26a() {
1142         test_mkdir $DIR/d26
1143         test_mkdir $DIR/d26/d26-2
1144         ln -s d26/d26-2 $DIR/s26
1145         touch $DIR/s26/foo || error
1146 }
1147 run_test 26a "multiple component symlink ======================="
1148
1149 test_26b() {
1150         test_mkdir -p $DIR/d26b/d26-2
1151         ln -s d26b/d26-2/foo $DIR/s26-2
1152         touch $DIR/s26-2 || error
1153 }
1154 run_test 26b "multiple component symlink at end of lookup ======"
1155
1156 test_26c() {
1157         test_mkdir $DIR/d26.2
1158         touch $DIR/d26.2/foo
1159         ln -s d26.2 $DIR/s26.2-1
1160         ln -s s26.2-1 $DIR/s26.2-2
1161         ln -s s26.2-2 $DIR/s26.2-3
1162         chmod 0666 $DIR/s26.2-3/foo
1163 }
1164 run_test 26c "chain of symlinks ================================"
1165
1166 # recursive symlinks (bug 439)
1167 test_26d() {
1168         ln -s d26-3/foo $DIR/d26-3
1169 }
1170 run_test 26d "create multiple component recursive symlink ======"
1171
1172 test_26e() {
1173         [ ! -h $DIR/d26-3 ] && test_26d
1174         rm $DIR/d26-3
1175 }
1176 run_test 26e "unlink multiple component recursive symlink ======"
1177
1178 # recursive symlinks (bug 7022)
1179 test_26f() {
1180         test_mkdir -p $DIR/$tdir
1181         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1182         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1183         test_mkdir -p lndir bar1      || error "mkdir lndir/bar1 failed"
1184         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1185         cd $tfile                || error "cd $tfile failed"
1186         ln -s .. dotdot          || error "ln dotdot failed"
1187         ln -s dotdot/lndir lndir || error "ln lndir failed"
1188         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1189         output=`ls $tfile/$tfile/lndir/bar1`
1190         [ "$output" = bar1 ] && error "unexpected output"
1191         rm -r $tfile             || error "rm $tfile failed"
1192         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1193 }
1194 run_test 26f "rm -r of a directory which has recursive symlink ="
1195
1196 test_27a() {
1197         echo '== stripe sanity =============================================='
1198         test_mkdir -p $DIR/d27 || error "mkdir failed"
1199         $GETSTRIPE $DIR/d27
1200         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1201         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1202         pass
1203         log "== test_27a: write to one stripe file ========================="
1204         cp /etc/hosts $DIR/d27/f0 || error
1205 }
1206 run_test 27a "one stripe file =================================="
1207
1208 test_27b() {
1209         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1210         test_mkdir -p $DIR/d27
1211         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1212         $GETSTRIPE -c $DIR/d27/f01
1213         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1214                 error "two-stripe file doesn't have two stripes"
1215 }
1216 run_test 27b "create two stripe file"
1217
1218 test_27c() {
1219         [ -f $DIR/d27/f01 ] || skip "test_27b not run" && return
1220
1221         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1222 }
1223 run_test 27c "write to two stripe file"
1224
1225 test_27d() {
1226         test_mkdir -p $DIR/d27
1227         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1228         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1229         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1230 }
1231 run_test 27d "create file with default settings ================"
1232
1233 test_27e() {
1234         test_mkdir -p $DIR/d27
1235         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1236         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1237         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1238 }
1239 run_test 27e "setstripe existing file (should return error) ======"
1240
1241 test_27f() {
1242         test_mkdir -p $DIR/d27
1243         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1244         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
1245         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1246 }
1247 run_test 27f "setstripe with bad stripe size (should return error)"
1248
1249 test_27g() {
1250         test_mkdir -p $DIR/d27
1251         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1252         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1253                 error "$DIR/d27/fnone has object"
1254 }
1255 run_test 27g "$GETSTRIPE with no objects"
1256
1257 test_27i() {
1258         touch $DIR/d27/fsome || error "touch failed"
1259         [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
1260 }
1261 run_test 27i "$GETSTRIPE with some objects"
1262
1263 test_27j() {
1264         test_mkdir -p $DIR/d27
1265         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1266 }
1267 run_test 27j "setstripe with bad stripe offset (should return error)"
1268
1269 test_27k() { # bug 2844
1270         test_mkdir -p $DIR/d27
1271         FILE=$DIR/d27/f27k
1272         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1273         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1274         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1275         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1276         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1277         dd if=/dev/zero of=$FILE bs=4k count=1
1278         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1279         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1280 }
1281 run_test 27k "limit i_blksize for broken user apps ============="
1282
1283 test_27l() {
1284         test_mkdir -p $DIR/d27
1285         mcreate $DIR/f27l || error "creating file"
1286         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1287                 error "setstripe should have failed" || true
1288 }
1289 run_test 27l "check setstripe permissions (should return error)"
1290
1291 test_27m() {
1292         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1293                 return
1294         if [ $ORIGFREE -gt $MAXFREE ]; then
1295                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1296                 return
1297         fi
1298         trap simple_cleanup_common EXIT
1299         test_mkdir -p $DIR/$tdir
1300         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1301         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1302                 error "dd should fill OST0"
1303         i=2
1304         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1305                 i=`expr $i + 1`
1306                 [ $i -gt 256 ] && break
1307         done
1308         i=`expr $i + 1`
1309         touch $DIR/$tdir/f27m_$i
1310         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1311                 error "OST0 was full but new created file still use it"
1312         i=`expr $i + 1`
1313         touch $DIR/$tdir/f27m_$i
1314         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1315                 error "OST0 was full but new created file still use it"
1316         simple_cleanup_common
1317 }
1318 run_test 27m "create file while OST0 was full =================="
1319
1320 sleep_maxage() {
1321         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1322         sleep $DELAY
1323 }
1324
1325 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1326 # if the OST isn't full anymore.
1327 reset_enospc() {
1328         local OSTIDX=${1:-""}
1329
1330         local list=$(comma_list $(osts_nodes))
1331         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1332
1333         do_nodes $list lctl set_param fail_loc=0
1334         sync    # initiate all OST_DESTROYs from MDS to OST
1335         sleep_maxage
1336 }
1337
1338 exhaust_precreations() {
1339         local OSTIDX=$1
1340         local FAILLOC=$2
1341         local FAILIDX=${3:-$OSTIDX}
1342
1343         test_mkdir -p $DIR/$tdir
1344         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1345         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1346
1347         local OST=$(ostname_from_index $OSTIDX)
1348         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1349                           sed -e 's/_UUID$//;s/^.*-//')
1350
1351         # on the mdt's osc
1352         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1353         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1354         osc.$mdtosc_proc1.prealloc_last_id)
1355         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1356         osc.$mdtosc_proc1.prealloc_next_id)
1357
1358         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1359         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1360
1361         test_mkdir -p $DIR/$tdir/${OST}
1362         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1363 #define OBD_FAIL_OST_ENOSPC              0x215
1364         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1365         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1366         echo "Creating to objid $last_id on ost $OST..."
1367         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1368         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1369         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1370         sleep_maxage
1371 }
1372
1373 exhaust_all_precreations() {
1374         local i
1375         for (( i=0; i < OSTCOUNT; i++ )) ; do
1376                 exhaust_precreations $i $1 -1
1377         done
1378 }
1379
1380 test_27n() {
1381         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1383         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1384         remote_ost_nodsh && skip "remote OST with nodsh" && return
1385
1386         reset_enospc
1387         rm -f $DIR/$tdir/$tfile
1388         exhaust_precreations 0 0x80000215
1389         $SETSTRIPE -c -1 $DIR/$tdir
1390         touch $DIR/$tdir/$tfile || error
1391         $GETSTRIPE $DIR/$tdir/$tfile
1392         reset_enospc
1393 }
1394 run_test 27n "create file with some full OSTs =================="
1395
1396 test_27o() {
1397         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1398         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1399         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1400         remote_ost_nodsh && skip "remote OST with nodsh" && return
1401
1402         reset_enospc
1403         rm -f $DIR/$tdir/$tfile
1404         exhaust_all_precreations 0x215
1405
1406         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1407
1408         reset_enospc
1409         rm -rf $DIR/$tdir/*
1410 }
1411 run_test 27o "create file with all full OSTs (should error) ===="
1412
1413 test_27p() {
1414         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1415         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1416         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1417         remote_ost_nodsh && skip "remote OST with nodsh" && return
1418
1419         reset_enospc
1420         rm -f $DIR/$tdir/$tfile
1421         test_mkdir -p $DIR/$tdir
1422
1423         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1424         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1425         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1426
1427         exhaust_precreations 0 0x80000215
1428         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1429         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1430         $GETSTRIPE $DIR/$tdir/$tfile
1431
1432         reset_enospc
1433 }
1434 run_test 27p "append to a truncated file with some full OSTs ==="
1435
1436 test_27q() {
1437         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1439         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1440         remote_ost_nodsh && skip "remote OST with nodsh" && return
1441
1442         reset_enospc
1443         rm -f $DIR/$tdir/$tfile
1444
1445         test_mkdir -p $DIR/$tdir
1446         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1447         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1448         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1449
1450         exhaust_all_precreations 0x215
1451
1452         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1453         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1454
1455         reset_enospc
1456 }
1457 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1458
1459 test_27r() {
1460         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1461         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1462         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1463         remote_ost_nodsh && skip "remote OST with nodsh" && return
1464
1465         reset_enospc
1466         rm -f $DIR/$tdir/$tfile
1467         exhaust_precreations 0 0x80000215
1468
1469         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1470
1471         reset_enospc
1472 }
1473 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1474
1475 test_27s() { # bug 10725
1476         test_mkdir -p $DIR/$tdir
1477         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1478         local stripe_count=0
1479         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1480         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1481                 error "stripe width >= 2^32 succeeded" || true
1482
1483 }
1484 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1485
1486 test_27t() { # bug 10864
1487         WDIR=`pwd`
1488         WLFS=`which lfs`
1489         cd $DIR
1490         touch $tfile
1491         $WLFS getstripe $tfile
1492         cd $WDIR
1493 }
1494 run_test 27t "check that utils parse path correctly"
1495
1496 test_27u() { # bug 4900
1497         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1498         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1499
1500 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1501         do_facet $SINGLEMDS lctl set_param fail_loc=0x139
1502         test_mkdir -p $DIR/$tdir
1503         rm -rf $DIR/$tdir/*
1504         createmany -o $DIR/$tdir/t- 1000
1505         do_facet $SINGLEMDS lctl set_param fail_loc=0
1506
1507         TLOG=$DIR/$tfile.getstripe
1508         $GETSTRIPE $DIR/$tdir > $TLOG
1509         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1510         unlinkmany $DIR/$tdir/t- 1000
1511         [ $OBJS -gt 0 ] && \
1512                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1513 }
1514 run_test 27u "skip object creation on OSC w/o objects =========="
1515
1516 test_27v() { # bug 4900
1517         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1520         remote_ost_nodsh && skip "remote OST with nodsh" && return
1521
1522         exhaust_all_precreations 0x215
1523         reset_enospc
1524
1525         test_mkdir -p $DIR/$tdir
1526         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1527
1528         touch $DIR/$tdir/$tfile
1529         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1530         # all except ost1
1531         for (( i=1; i < OSTCOUNT; i++ )); do
1532                 do_facet ost$i lctl set_param fail_loc=0x705
1533         done
1534         local START=`date +%s`
1535         createmany -o $DIR/$tdir/$tfile 32
1536
1537         local FINISH=`date +%s`
1538         local TIMEOUT=`lctl get_param -n timeout`
1539         local PROCESS=$((FINISH - START))
1540         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1541                error "$FINISH - $START >= $TIMEOUT / 2"
1542         sleep $((TIMEOUT / 2 - PROCESS))
1543         reset_enospc
1544 }
1545 run_test 27v "skip object creation on slow OST ================="
1546
1547 test_27w() { # bug 10997
1548         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1549         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1550         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1551                 error "stripe size $size != 65536" || true
1552         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1553                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1554 }
1555 run_test 27w "check $SETSTRIPE -S option"
1556
1557 test_27wa() {
1558         [ "$OSTCOUNT" -lt "2" ] &&
1559                 skip_env "skipping multiple stripe count/offset test" && return
1560
1561         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1562         for i in $(seq 1 $OSTCOUNT); do
1563                 offset=$((i - 1))
1564                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1565                         error "setstripe -c $i -i $offset failed"
1566                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1567                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1568                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1569                 [ $index -ne $offset ] &&
1570                         error "stripe offset $index != $offset" || true
1571         done
1572 }
1573 run_test 27wa "check $SETSTRIPE -c -i options"
1574
1575 test_27x() {
1576         remote_ost_nodsh && skip "remote OST with nodsh" && return
1577         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1579         OFFSET=$(($OSTCOUNT - 1))
1580         OSTIDX=0
1581         local OST=$(ostname_from_index $OSTIDX)
1582
1583         test_mkdir -p $DIR/$tdir
1584         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1585         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1586         sleep_maxage
1587         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1588         for i in `seq 0 $OFFSET`; do
1589                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1590                 error "OST0 was degraded but new created file still use it"
1591         done
1592         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1593 }
1594 run_test 27x "create files while OST0 is degraded"
1595
1596 test_27y() {
1597         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1598         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1599         remote_ost_nodsh && skip "remote OST with nodsh" && return
1600         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1601
1602         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1603         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1604             osc.$mdtosc.prealloc_last_id)
1605         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1606             osc.$mdtosc.prealloc_next_id)
1607         local fcount=$((last_id - next_id))
1608         [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1609         [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1610
1611         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1612                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1613         local OST_DEACTIVE_IDX=-1
1614         local OSC
1615         local OSTIDX
1616         local OST
1617
1618         for OSC in $MDS_OSCS; do
1619                 OST=$(osc_to_ost $OSC)
1620                 OSTIDX=$(index_from_ostuuid $OST)
1621                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1622                         OST_DEACTIVE_IDX=$OSTIDX
1623                 fi
1624                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1625                         echo $OSC "is Deactivated:"
1626                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1627                 fi
1628         done
1629
1630         OSTIDX=$(index_from_ostuuid $OST)
1631         mkdir -p $DIR/$tdir
1632         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1633
1634         for OSC in $MDS_OSCS; do
1635                 OST=$(osc_to_ost $OSC)
1636                 OSTIDX=$(index_from_ostuuid $OST)
1637                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1638                         echo $OST "is degraded:"
1639                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1640                                                 obdfilter.$OST.degraded=1
1641                 fi
1642         done
1643
1644         sleep_maxage
1645         createmany -o $DIR/$tdir/$tfile $fcount
1646
1647         for OSC in $MDS_OSCS; do
1648                 OST=$(osc_to_ost $OSC)
1649                 OSTIDX=$(index_from_ostuuid $OST)
1650                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1651                         echo $OST "is recovered from degraded:"
1652                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1653                                                 obdfilter.$OST.degraded=0
1654                 else
1655                         do_facet $SINGLEMDS lctl --device %$OSC activate
1656                 fi
1657         done
1658
1659         # all osp devices get activated, hence -1 stripe count restored
1660         local stripecnt=0
1661
1662         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1663         # devices get activated.
1664         sleep_maxage
1665         $SETSTRIPE -c -1 $DIR/$tfile
1666         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1667         rm -f $DIR/$tfile
1668         [ $stripecnt -ne $OSTCOUNT ] &&
1669                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1670         return 0
1671 }
1672 run_test 27y "create files while OST0 is degraded and the rest inactive"
1673
1674 check_seq_oid()
1675 {
1676         log "check file $1"
1677
1678         lmm_count=$($GETSTRIPE -c $1)
1679         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1680         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1681
1682         local old_ifs="$IFS"
1683         IFS=$'[:]'
1684         fid=($($LFS path2fid $1))
1685         IFS="$old_ifs"
1686
1687         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1688         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1689
1690         # compare lmm_seq and lu_fid->f_seq
1691         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1692         # compare lmm_object_id and lu_fid->oid
1693         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1694
1695         # check the trusted.fid attribute of the OST objects of the file
1696         local have_obdidx=false
1697         local stripe_nr=0
1698         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1699                 # skip lines up to and including "obdidx"
1700                 [ -z "$obdidx" ] && break
1701                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1702                 $have_obdidx || continue
1703
1704                 local ost=$((obdidx + 1))
1705                 local dev=$(ostdevname $ost)
1706
1707                 if [ $(facet_fstype ost$ost) != ldiskfs ]; then
1708                         echo "Currently only works with ldiskfs-based OSTs"
1709                         continue
1710                 fi
1711
1712                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1713
1714                 #don't unmount/remount the OSTs if we don't need to do that
1715                 #local dir=$(facet_mntpt ost$ost)
1716                 #stop ost$dev
1717                 #do_facet ost$dev mount -t $FSTYPE $dev $dir $OST_MOUNT_OPTS ||
1718                 #       { error "mounting $dev as $FSTYPE failed"; return 3; }
1719                 #local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid)
1720                 #local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
1721                 seq=$(echo $seq | sed -e "s/^0x//g")
1722                 if [ $seq == 0 ]; then
1723                         oid_hex=$(echo $oid)
1724                 else
1725                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1726                 fi
1727                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1728                 local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1729                            $dev 2>/dev/null" | grep "parent=")
1730
1731                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1732
1733                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1734
1735                 #do_facet ost$ost umount -d $dir
1736                 #start ost$ost $dev $OST_MOUNT_OPTS
1737
1738                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1739                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1740                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1741                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1742                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1743                 local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1744
1745                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1746                 [ $ff_pseq = $lmm_seq ] ||
1747                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1748                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1749                 [ $ff_poid = $lmm_oid ] ||
1750                         error "FF parent OID $ff_poid != $lmm_oid"
1751                 [ $ff_pstripe = $stripe_nr ] ||
1752                         error "FF stripe $ff_pstripe != $stripe_nr"
1753
1754                 stripe_nr=$((stripe_nr + 1))
1755         done
1756 }
1757
1758 test_27z() {
1759         remote_ost_nodsh && skip "remote OST with nodsh" && return
1760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1761         test_mkdir -p $DIR/$tdir
1762
1763         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1764                 { error "setstripe -c -1 failed"; return 1; }
1765         # We need to send a write to every object to get parent FID info set.
1766         # This _should_ also work for setattr, but does not currently.
1767         # touch $DIR/$tdir/$tfile-1 ||
1768         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1769                 { error "dd $tfile-1 failed"; return 2; }
1770         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1771                 { error "setstripe -c -1 failed"; return 3; }
1772         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1773                 { error "dd $tfile-2 failed"; return 4; }
1774
1775         # make sure write RPCs have been sent to OSTs
1776         sync; sleep 5; sync
1777
1778         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1779         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1780 }
1781 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1782
1783 test_27A() { # b=19102
1784         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1785         local restore_size=$($GETSTRIPE -S $MOUNT)
1786         local restore_count=$($GETSTRIPE -c $MOUNT)
1787         local restore_offset=$($GETSTRIPE -i $MOUNT)
1788         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1789         local default_size=$($GETSTRIPE -S $MOUNT)
1790         local default_count=$($GETSTRIPE -c $MOUNT)
1791         local default_offset=$($GETSTRIPE -i $MOUNT)
1792         local dsize=$((1024 * 1024))
1793         [ $default_size -eq $dsize ] ||
1794                 error "stripe size $default_size != $dsize"
1795         [ $default_count -eq 1 ] || error "stripe count $default_count != 1"
1796         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1797         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1798 }
1799 run_test 27A "check filesystem-wide default LOV EA values"
1800
1801 test_27B() { # LU-2523
1802         test_mkdir -p $DIR/$tdir
1803         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1804         touch $DIR/$tdir/f0
1805         # open f1 with O_LOV_DELAY_CREATE
1806         # rename f0 onto f1
1807         # call setstripe ioctl on open file descriptor for f1
1808         # close
1809         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1810                 $DIR/$tdir/f0
1811
1812         rm -f $DIR/$tdir/f1
1813         # open f1 with O_LOV_DELAY_CREATE
1814         # unlink f1
1815         # call setstripe ioctl on open file descriptor for f1
1816         # close
1817         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1818
1819         # Allow multiop to fail in imitation of NFS's busted semantics.
1820         true
1821 }
1822 run_test 27B "call setstripe on open unlinked file/rename victim"
1823
1824 test_27C() { #LU-2871
1825         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1826
1827         declare -a ost_idx
1828         local index
1829         local i
1830         local j
1831
1832         test_mkdir -p $DIR/$tdir
1833         cd $DIR/$tdir
1834         for i in $(seq 0 $((OSTCOUNT - 1))); do
1835                 # set stripe across all OSTs starting from OST$i
1836                 $SETSTRIPE -i $i -c -1 $tfile$i
1837                 # get striping information
1838                 ost_idx=($($GETSTRIPE $tfile$i |
1839                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1840                 echo ${ost_idx[@]}
1841                 # check the layout
1842                 for j in $(seq 0 $((OSTCOUNT - 1))); do
1843                         index=$(((i + j) % OSTCOUNT))
1844                         [ ${ost_idx[$j]} -eq $index ] || error
1845                 done
1846         done
1847 }
1848 run_test 27C "check full striping across all OSTs"
1849
1850 # createtest also checks that device nodes are created and
1851 # then visible correctly (#2091)
1852 test_28() { # bug 2091
1853         test_mkdir $DIR/d28
1854         $CREATETEST $DIR/d28/ct || error
1855 }
1856 run_test 28 "create/mknod/mkdir with bad file types ============"
1857
1858 test_29() {
1859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1860         cancel_lru_locks mdc
1861         test_mkdir $DIR/d29
1862         touch $DIR/d29/foo
1863         log 'first d29'
1864         ls -l $DIR/d29
1865
1866         declare -i LOCKCOUNTORIG=0
1867         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1868                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1869         done
1870         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1871
1872         declare -i LOCKUNUSEDCOUNTORIG=0
1873         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1874                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1875         done
1876
1877         log 'second d29'
1878         ls -l $DIR/d29
1879         log 'done'
1880
1881         declare -i LOCKCOUNTCURRENT=0
1882         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1883                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1884         done
1885
1886         declare -i LOCKUNUSEDCOUNTCURRENT=0
1887         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1888                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1889         done
1890
1891         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1892                 lctl set_param -n ldlm.dump_namespaces ""
1893                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1894                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1895                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1896                 return 2
1897         fi
1898         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1899                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1900                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1901                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1902                 return 3
1903         fi
1904 }
1905 run_test 29 "IT_GETATTR regression  ============================"
1906
1907 test_30a() { # was test_30
1908         cp `which ls` $DIR || cp /bin/ls $DIR
1909         $DIR/ls / || error
1910         rm $DIR/ls
1911 }
1912 run_test 30a "execute binary from Lustre (execve) =============="
1913
1914 test_30b() {
1915         cp `which ls` $DIR || cp /bin/ls $DIR
1916         chmod go+rx $DIR/ls
1917         $RUNAS $DIR/ls / || error
1918         rm $DIR/ls
1919 }
1920 run_test 30b "execute binary from Lustre as non-root ==========="
1921
1922 test_30c() { # b=22376
1923         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1924         cp `which ls` $DIR || cp /bin/ls $DIR
1925         chmod a-rw $DIR/ls
1926         cancel_lru_locks mdc
1927         cancel_lru_locks osc
1928         $RUNAS $DIR/ls / || error
1929         rm -f $DIR/ls
1930 }
1931 run_test 30c "execute binary from Lustre without read perms ===="
1932
1933 test_31a() {
1934         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1935         $CHECKSTAT -a $DIR/f31 || error
1936 }
1937 run_test 31a "open-unlink file =================================="
1938
1939 test_31b() {
1940         touch $DIR/f31 || error
1941         ln $DIR/f31 $DIR/f31b || error
1942         $MULTIOP $DIR/f31b Ouc || error
1943         $CHECKSTAT -t file $DIR/f31 || error
1944 }
1945 run_test 31b "unlink file with multiple links while open ======="
1946
1947 test_31c() {
1948         touch $DIR/f31 || error
1949         ln $DIR/f31 $DIR/f31c || error
1950         multiop_bg_pause $DIR/f31 O_uc || return 1
1951         MULTIPID=$!
1952         $MULTIOP $DIR/f31c Ouc
1953         kill -USR1 $MULTIPID
1954         wait $MULTIPID
1955 }
1956 run_test 31c "open-unlink file with multiple links ============="
1957
1958 test_31d() {
1959         opendirunlink $DIR/d31d $DIR/d31d || error
1960         $CHECKSTAT -a $DIR/d31d || error
1961 }
1962 run_test 31d "remove of open directory ========================="
1963
1964 test_31e() { # bug 2904
1965         check_kernel_version 34 || return 0
1966         openfilleddirunlink $DIR/d31e || error
1967 }
1968 run_test 31e "remove of open non-empty directory ==============="
1969
1970 test_31f() { # bug 4554
1971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1972         set -vx
1973         test_mkdir $DIR/d31f
1974         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1975         cp /etc/hosts $DIR/d31f
1976         ls -l $DIR/d31f
1977         $GETSTRIPE $DIR/d31f/hosts
1978         multiop_bg_pause $DIR/d31f D_c || return 1
1979         MULTIPID=$!
1980
1981         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1982         test_mkdir $DIR/d31f
1983         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1984         cp /etc/hosts $DIR/d31f
1985         ls -l $DIR/d31f
1986         $GETSTRIPE $DIR/d31f/hosts
1987         multiop_bg_pause $DIR/d31f D_c || return 1
1988         MULTIPID2=$!
1989
1990         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1991         wait $MULTIPID || error "first opendir $MULTIPID failed"
1992
1993         sleep 6
1994
1995         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1996         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1997         set +vx
1998 }
1999 run_test 31f "remove of open directory with open-unlink file ==="
2000
2001 test_31g() {
2002         echo "-- cross directory link --"
2003         test_mkdir $DIR/d31ga
2004         test_mkdir $DIR/d31gb
2005         touch $DIR/d31ga/f
2006         ln $DIR/d31ga/f $DIR/d31gb/g
2007         $CHECKSTAT -t file $DIR/d31ga/f || error "source"
2008         [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
2009         $CHECKSTAT -t file $DIR/d31gb/g || error "target"
2010         [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
2011 }
2012 run_test 31g "cross directory link==============="
2013
2014 test_31h() {
2015         echo "-- cross directory link --"
2016         test_mkdir $DIR/d31h
2017         test_mkdir $DIR/d31h/dir
2018         touch $DIR/d31h/f
2019         ln $DIR/d31h/f $DIR/d31h/dir/g
2020         $CHECKSTAT -t file $DIR/d31h/f || error "source"
2021         [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
2022         $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
2023         [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
2024 }
2025 run_test 31h "cross directory link under child==============="
2026
2027 test_31i() {
2028         echo "-- cross directory link --"
2029         test_mkdir $DIR/d31i
2030         test_mkdir $DIR/d31i/dir
2031         touch $DIR/d31i/dir/f
2032         ln $DIR/d31i/dir/f $DIR/d31i/g
2033         $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
2034         [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
2035         $CHECKSTAT -t file $DIR/d31i/g || error "target"
2036         [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
2037 }
2038 run_test 31i "cross directory link under parent==============="
2039
2040
2041 test_31j() {
2042         test_mkdir $DIR/d31j
2043         test_mkdir $DIR/d31j/dir1
2044         ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
2045         link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
2046         mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
2047         mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
2048         return 0
2049 }
2050 run_test 31j "link for directory==============="
2051
2052
2053 test_31k() {
2054         test_mkdir $DIR/d31k
2055         touch $DIR/d31k/s
2056         touch $DIR/d31k/exist
2057         mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
2058         mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
2059         mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
2060         mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
2061         mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
2062         mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
2063         mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
2064         return 0
2065 }
2066 run_test 31k "link to file: the same, non-existing, dir==============="
2067
2068 test_31m() {
2069         test_mkdir $DIR/d31m
2070         touch $DIR/d31m/s
2071         test_mkdir $DIR/d31m2
2072         touch $DIR/d31m2/exist
2073         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2074         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2075         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2076         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2077         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2078         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2079         return 0
2080 }
2081 run_test 31m "link to file: the same, non-existing, dir==============="
2082
2083 test_31n() {
2084         [ -e /proc/self/fd/173 ] && echo "skipping, fd 173 is in use" && return
2085         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2086         nlink=$(stat --format=%h $DIR/$tfile)
2087         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2088         exec 173<$DIR/$tfile
2089         trap "exec 173<&-" EXIT
2090         nlink=$(stat --dereference --format=%h /proc/self/fd/173)
2091         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2092         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2093         nlink=$(stat --dereference --format=%h /proc/self/fd/173)
2094         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2095         exec 173<&-
2096 }
2097 run_test 31n "check link count of unlinked file"
2098
2099 cleanup_test32_mount() {
2100         trap 0
2101         $UMOUNT $DIR/$tdir/ext2-mountpoint
2102 }
2103
2104 test_32a() {
2105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2106         echo "== more mountpoints and symlinks ================="
2107         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2108         trap cleanup_test32_mount EXIT
2109         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2110         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2111         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2112         cleanup_test32_mount
2113 }
2114 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2115
2116 test_32b() {
2117         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2118         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2119         trap cleanup_test32_mount EXIT
2120         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2121         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2122         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2123         cleanup_test32_mount
2124 }
2125 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2126
2127 test_32c() {
2128         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2129         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2130         trap cleanup_test32_mount EXIT
2131         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2132         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2133         test_mkdir -p $DIR/$tdir/d2/test_dir
2134         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2135         cleanup_test32_mount
2136 }
2137 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2138
2139 test_32d() {
2140         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2141         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2142         trap cleanup_test32_mount EXIT
2143         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2144         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2145         test_mkdir -p $DIR/$tdir/d2/test_dir
2146         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2147         cleanup_test32_mount
2148 }
2149 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2150
2151 test_32e() {
2152         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2153         test_mkdir -p $DIR/d32e/tmp
2154         TMP_DIR=$DIR/d32e/tmp
2155         ln -s $DIR/d32e $TMP_DIR/symlink11
2156         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2157         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2158         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2159 }
2160 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2161
2162 test_32f() {
2163         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2164         test_mkdir -p $DIR/d32f/tmp
2165         TMP_DIR=$DIR/d32f/tmp
2166         ln -s $DIR/d32f $TMP_DIR/symlink11
2167         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2168         ls $DIR/d32f/tmp/symlink11  || error
2169         ls $DIR/d32f/symlink01 || error
2170 }
2171 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2172
2173 test_32g() {
2174         TMP_DIR=$DIR/$tdir/tmp
2175         test_mkdir -p $DIR/$tdir/tmp
2176         test_mkdir $DIR/${tdir}2
2177         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2178         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2179         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2180         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2181         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2182         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2183 }
2184 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2185
2186 test_32h() {
2187         rm -fr $DIR/$tdir $DIR/${tdir}2
2188         TMP_DIR=$DIR/$tdir/tmp
2189         test_mkdir -p $DIR/$tdir/tmp
2190         test_mkdir $DIR/${tdir}2
2191         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2192         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2193         ls $TMP_DIR/symlink12 || error
2194         ls $DIR/$tdir/symlink02  || error
2195 }
2196 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2197
2198 test_32i() {
2199         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2200         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2201         trap cleanup_test32_mount EXIT
2202         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2203         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2204         touch $DIR/$tdir/test_file
2205         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2206         cleanup_test32_mount
2207 }
2208 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2209
2210 test_32j() {
2211         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2212         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2213         trap cleanup_test32_mount EXIT
2214         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2215         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2216         touch $DIR/$tdir/test_file
2217         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2218         cleanup_test32_mount
2219 }
2220 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2221
2222 test_32k() {
2223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2224         rm -fr $DIR/$tdir
2225         trap cleanup_test32_mount EXIT
2226         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2227         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2228         test_mkdir -p $DIR/$tdir/d2
2229         touch $DIR/$tdir/d2/test_file || error
2230         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2231         cleanup_test32_mount
2232 }
2233 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2234
2235 test_32l() {
2236         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2237         rm -fr $DIR/$tdir
2238         trap cleanup_test32_mount EXIT
2239         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2240         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2241         test_mkdir -p $DIR/$tdir/d2
2242         touch $DIR/$tdir/d2/test_file
2243         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2244         cleanup_test32_mount
2245 }
2246 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2247
2248 test_32m() {
2249         rm -fr $DIR/d32m
2250         test_mkdir -p $DIR/d32m/tmp
2251         TMP_DIR=$DIR/d32m/tmp
2252         ln -s $DIR $TMP_DIR/symlink11
2253         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2254         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2255         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2256 }
2257 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2258
2259 test_32n() {
2260         rm -fr $DIR/d32n
2261         test_mkdir -p $DIR/d32n/tmp
2262         TMP_DIR=$DIR/d32n/tmp
2263         ln -s $DIR $TMP_DIR/symlink11
2264         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2265         ls -l $DIR/d32n/tmp/symlink11  || error
2266         ls -l $DIR/d32n/symlink01 || error
2267 }
2268 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2269
2270 test_32o() {
2271         rm -fr $DIR/d32o $DIR/$tfile
2272         touch $DIR/$tfile
2273         test_mkdir -p $DIR/d32o/tmp
2274         TMP_DIR=$DIR/d32o/tmp
2275         ln -s $DIR/$tfile $TMP_DIR/symlink12
2276         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2277         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2278         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2279         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2280         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2281 }
2282 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2283
2284 test_32p() {
2285     log 32p_1
2286         rm -fr $DIR/d32p
2287     log 32p_2
2288         rm -f $DIR/$tfile
2289     log 32p_3
2290         touch $DIR/$tfile
2291     log 32p_4
2292         test_mkdir -p $DIR/d32p/tmp
2293     log 32p_5
2294         TMP_DIR=$DIR/d32p/tmp
2295     log 32p_6
2296         ln -s $DIR/$tfile $TMP_DIR/symlink12
2297     log 32p_7
2298         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2299     log 32p_8
2300         cat $DIR/d32p/tmp/symlink12 || error
2301     log 32p_9
2302         cat $DIR/d32p/symlink02 || error
2303     log 32p_10
2304 }
2305 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2306
2307 cleanup_testdir_mount() {
2308         trap 0
2309         $UMOUNT $DIR/$tdir
2310 }
2311
2312 test_32q() {
2313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2314         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2315         trap cleanup_testdir_mount EXIT
2316         test_mkdir -p $DIR/$tdir
2317         touch $DIR/$tdir/under_the_mount
2318         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2319         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2320         cleanup_testdir_mount
2321 }
2322 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2323
2324 test_32r() {
2325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2326         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2327         trap cleanup_testdir_mount EXIT
2328         test_mkdir -p $DIR/$tdir
2329         touch $DIR/$tdir/under_the_mount
2330         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2331         ls $DIR/$tdir | grep -q under_the_mount && error || true
2332         cleanup_testdir_mount
2333 }
2334 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2335
2336 test_33aa() {
2337         rm -f $DIR/$tfile
2338         touch $DIR/$tfile
2339         chmod 444 $DIR/$tfile
2340         chown $RUNAS_ID $DIR/$tfile
2341         log 33_1
2342         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2343         log 33_2
2344 }
2345 run_test 33aa "write file with mode 444 (should return error) ===="
2346
2347 test_33a() {
2348         rm -fr $DIR/d33
2349         test_mkdir -p $DIR/d33
2350         chown $RUNAS_ID $DIR/d33
2351         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2352         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2353                 error "open RDWR" || true
2354 }
2355 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2356
2357 test_33b() {
2358         rm -fr $DIR/d33
2359         test_mkdir -p $DIR/d33
2360         chown $RUNAS_ID $DIR/d33
2361         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2362 }
2363 run_test 33b "test open file with malformed flags (No panic and return error)"
2364
2365 test_33c() {
2366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2367         local ostnum
2368         local ostname
2369         local write_bytes
2370         local all_zeros
2371
2372         remote_ost_nodsh && skip "remote OST with nodsh" && return
2373         all_zeros=:
2374         rm -fr $DIR/d33
2375         test_mkdir -p $DIR/d33
2376         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2377
2378         sync
2379         for ostnum in $(seq $OSTCOUNT); do
2380                 # test-framework's OST numbering is one-based, while Lustre's
2381                 # is zero-based
2382                 ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
2383                 # Parsing llobdstat's output sucks; we could grep the /proc
2384                 # path, but that's likely to not be as portable as using the
2385                 # llobdstat utility.  So we parse lctl output instead.
2386                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2387                         obdfilter/$ostname/stats |
2388                         awk '/^write_bytes/ {print $7}' )
2389                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2390                 if (( ${write_bytes:-0} > 0 ))
2391                 then
2392                         all_zeros=false
2393                         break;
2394                 fi
2395         done
2396
2397         $all_zeros || return 0
2398
2399         # Write four bytes
2400         echo foo > $DIR/d33/bar
2401         # Really write them
2402         sync
2403
2404         # Total up write_bytes after writing.  We'd better find non-zeros.
2405         for ostnum in $(seq $OSTCOUNT); do
2406                 ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
2407                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2408                         obdfilter/$ostname/stats |
2409                         awk '/^write_bytes/ {print $7}' )
2410                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2411                 if (( ${write_bytes:-0} > 0 ))
2412                 then
2413                         all_zeros=false
2414                         break;
2415                 fi
2416         done
2417
2418         if $all_zeros
2419         then
2420                 for ostnum in $(seq $OSTCOUNT); do
2421                         ostname=$(printf "$FSNAME-OST%.4d" $((ostnum - 1)))
2422                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2423                         do_facet ost$ostnum lctl get_param -n \
2424                                 obdfilter/$ostname/stats
2425                 done
2426                 error "OST not keeping write_bytes stats (b22312)"
2427         fi
2428 }
2429 run_test 33c "test llobdstat and write_bytes"
2430
2431 test_33d() {
2432         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2434         local MDTIDX=1
2435         local remote_dir=$DIR/$tdir/remote_dir
2436
2437         mkdir -p $DIR/$tdir
2438         $LFS mkdir -i $MDTIDX $remote_dir ||
2439                 error "create remote directory failed"
2440
2441         touch $remote_dir/$tfile
2442         chmod 444 $remote_dir/$tfile
2443         chown $RUNAS_ID $remote_dir/$tfile
2444
2445         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2446
2447         chown $RUNAS_ID $remote_dir
2448         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2449                                         error "create" || true
2450         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2451                                     error "open RDWR" || true
2452         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2453                                     error "create" || true
2454 }
2455 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2456
2457 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2458 test_34a() {
2459         rm -f $DIR/f34
2460         $MCREATE $DIR/f34 || error
2461         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2462         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2463         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2464         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2465 }
2466 run_test 34a "truncate file that has not been opened ==========="
2467
2468 test_34b() {
2469         [ ! -f $DIR/f34 ] && test_34a
2470         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2471         $OPENFILE -f O_RDONLY $DIR/f34
2472         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2473         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2474 }
2475 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2476
2477 test_34c() {
2478         [ ! -f $DIR/f34 ] && test_34a
2479         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2480         $OPENFILE -f O_RDWR $DIR/f34
2481         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2482         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2483 }
2484 run_test 34c "O_RDWR opening file-with-size works =============="
2485
2486 test_34d() {
2487         [ ! -f $DIR/f34 ] && test_34a
2488         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2489         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2490         rm $DIR/f34
2491 }
2492 run_test 34d "write to sparse file ============================="
2493
2494 test_34e() {
2495         rm -f $DIR/f34e
2496         $MCREATE $DIR/f34e || error
2497         $TRUNCATE $DIR/f34e 1000 || error
2498         $CHECKSTAT -s 1000 $DIR/f34e || error
2499         $OPENFILE -f O_RDWR $DIR/f34e
2500         $CHECKSTAT -s 1000 $DIR/f34e || error
2501 }
2502 run_test 34e "create objects, some with size and some without =="
2503
2504 test_34f() { # bug 6242, 6243
2505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2506         SIZE34F=48000
2507         rm -f $DIR/f34f
2508         $MCREATE $DIR/f34f || error
2509         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2510         dd if=$DIR/f34f of=$TMP/f34f
2511         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2512         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2513         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2514         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2515         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2516 }
2517 run_test 34f "read from a file with no objects until EOF ======="
2518
2519 test_34g() {
2520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2521         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2522         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2523         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2524         cancel_lru_locks osc
2525         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2526                 error "wrong size after lock cancel"
2527
2528         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2529         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2530                 error "expanding truncate failed"
2531         cancel_lru_locks osc
2532         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2533                 error "wrong expanded size after lock cancel"
2534 }
2535 run_test 34g "truncate long file ==============================="
2536
2537 test_34h() {
2538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2539         local gid=10
2540         local sz=1000
2541
2542         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2543         sync # Flush the cache so that multiop below does not block on cache
2544              # flush when getting the group lock
2545         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2546         MULTIPID=$!
2547         sleep 2
2548
2549         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2550                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2551                 kill -9 $MULTIPID
2552         fi
2553         wait $MULTIPID
2554         local nsz=`stat -c %s $DIR/$tfile`
2555         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2556 }
2557 run_test 34h "ftruncate file under grouplock should not block"
2558
2559 test_35a() {
2560         cp /bin/sh $DIR/f35a
2561         chmod 444 $DIR/f35a
2562         chown $RUNAS_ID $DIR/f35a
2563         $RUNAS $DIR/f35a && error || true
2564         rm $DIR/f35a
2565 }
2566 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2567
2568 test_36a() {
2569         rm -f $DIR/f36
2570         utime $DIR/f36 || error
2571 }
2572 run_test 36a "MDS utime check (mknod, utime) ==================="
2573
2574 test_36b() {
2575         echo "" > $DIR/f36
2576         utime $DIR/f36 || error
2577 }
2578 run_test 36b "OST utime check (open, utime) ===================="
2579
2580 test_36c() {
2581         rm -f $DIR/d36/f36
2582         test_mkdir $DIR/d36
2583         chown $RUNAS_ID $DIR/d36
2584         $RUNAS utime $DIR/d36/f36 || error
2585 }
2586 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2587
2588 test_36d() {
2589         [ ! -d $DIR/d36 ] && test_36c
2590         echo "" > $DIR/d36/f36
2591         $RUNAS utime $DIR/d36/f36 || error
2592 }
2593 run_test 36d "non-root OST utime check (open, utime) ==========="
2594
2595 test_36e() {
2596         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2597         test_mkdir -p $DIR/$tdir
2598         touch $DIR/$tdir/$tfile
2599         $RUNAS utime $DIR/$tdir/$tfile && \
2600                 error "utime worked, expected failure" || true
2601 }
2602 run_test 36e "utime on non-owned file (should return error) ===="
2603
2604 subr_36fh() {
2605         local fl="$1"
2606         local LANG_SAVE=$LANG
2607         local LC_LANG_SAVE=$LC_LANG
2608         export LANG=C LC_LANG=C # for date language
2609
2610         DATESTR="Dec 20  2000"
2611         test_mkdir -p $DIR/$tdir
2612         lctl set_param fail_loc=$fl
2613         date; date +%s
2614         cp /etc/hosts $DIR/$tdir/$tfile
2615         sync & # write RPC generated with "current" inode timestamp, but delayed
2616         sleep 1
2617         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2618         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2619         cancel_lru_locks osc
2620         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2621         date; date +%s
2622         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2623                 echo "BEFORE: $LS_BEFORE" && \
2624                 echo "AFTER : $LS_AFTER" && \
2625                 echo "WANT  : $DATESTR" && \
2626                 error "$DIR/$tdir/$tfile timestamps changed" || true
2627
2628         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2629 }
2630
2631 test_36f() {
2632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2633         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2634         subr_36fh "0x80000214"
2635 }
2636 run_test 36f "utime on file racing with OST BRW write =========="
2637
2638 test_36g() {
2639         remote_ost_nodsh && skip "remote OST with nodsh" && return
2640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2641         local fmd_max_age
2642         local fmd_before
2643         local fmd_after
2644
2645         test_mkdir -p $DIR/$tdir
2646         fmd_max_age=$(do_facet ost1 \
2647                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2648                 head -n 1")
2649
2650         fmd_before=$(do_facet ost1 \
2651                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2652         touch $DIR/$tdir/$tfile
2653         sleep $((fmd_max_age + 12))
2654         fmd_after=$(do_facet ost1 \
2655                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2656
2657         echo "fmd_before: $fmd_before"
2658         echo "fmd_after: $fmd_after"
2659         [ "$fmd_after" -gt "$fmd_before" ] && \
2660                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2661                 error "fmd didn't expire after ping" || true
2662 }
2663 run_test 36g "filter mod data cache expiry ====================="
2664
2665 test_36h() {
2666         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2667         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2668         subr_36fh "0x80000227"
2669 }
2670 run_test 36h "utime on file racing with OST BRW write =========="
2671
2672 # test_37 - duplicate with tests 32q 32r
2673
2674 test_38() {
2675         local file=$DIR/$tfile
2676         touch $file
2677         openfile -f O_DIRECTORY $file
2678         local RC=$?
2679         local ENOTDIR=20
2680         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2681         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2682 }
2683 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2684
2685 test_39() {
2686         touch $DIR/$tfile
2687         touch $DIR/${tfile}2
2688 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2689 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2690 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2691         sleep 2
2692         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2693         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2694                 echo "mtime"
2695                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2696                 echo "atime"
2697                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2698                 echo "ctime"
2699                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2700                 error "O_TRUNC didn't change timestamps"
2701         fi
2702 }
2703 run_test 39 "mtime changed on create ==========================="
2704
2705 test_39b() {
2706         test_mkdir -p $DIR/$tdir
2707         cp -p /etc/passwd $DIR/$tdir/fopen
2708         cp -p /etc/passwd $DIR/$tdir/flink
2709         cp -p /etc/passwd $DIR/$tdir/funlink
2710         cp -p /etc/passwd $DIR/$tdir/frename
2711         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2712
2713         sleep 1
2714         echo "aaaaaa" >> $DIR/$tdir/fopen
2715         echo "aaaaaa" >> $DIR/$tdir/flink
2716         echo "aaaaaa" >> $DIR/$tdir/funlink
2717         echo "aaaaaa" >> $DIR/$tdir/frename
2718
2719         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2720         local link_new=`stat -c %Y $DIR/$tdir/flink`
2721         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2722         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2723
2724         cat $DIR/$tdir/fopen > /dev/null
2725         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2726         rm -f $DIR/$tdir/funlink2
2727         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2728
2729         for (( i=0; i < 2; i++ )) ; do
2730                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2731                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2732                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2733                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2734
2735                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2736                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2737                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2738                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2739
2740                 cancel_lru_locks osc
2741                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2742         done
2743 }
2744 run_test 39b "mtime change on open, link, unlink, rename  ======"
2745
2746 # this should be set to past
2747 TEST_39_MTIME=`date -d "1 year ago" +%s`
2748
2749 # bug 11063
2750 test_39c() {
2751         touch $DIR1/$tfile
2752         sleep 2
2753         local mtime0=`stat -c %Y $DIR1/$tfile`
2754
2755         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2756         local mtime1=`stat -c %Y $DIR1/$tfile`
2757         [ "$mtime1" = $TEST_39_MTIME ] || \
2758                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2759
2760         local d1=`date +%s`
2761         echo hello >> $DIR1/$tfile
2762         local d2=`date +%s`
2763         local mtime2=`stat -c %Y $DIR1/$tfile`
2764         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2765                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2766
2767         mv $DIR1/$tfile $DIR1/$tfile-1
2768
2769         for (( i=0; i < 2; i++ )) ; do
2770                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2771                 [ "$mtime2" = "$mtime3" ] || \
2772                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2773
2774                 cancel_lru_locks osc
2775                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2776         done
2777 }
2778 run_test 39c "mtime change on rename ==========================="
2779
2780 # bug 21114
2781 test_39d() {
2782         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2783         touch $DIR1/$tfile
2784
2785         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2786
2787         for (( i=0; i < 2; i++ )) ; do
2788                 local mtime=`stat -c %Y $DIR1/$tfile`
2789                 [ $mtime = $TEST_39_MTIME ] || \
2790                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2791
2792                 cancel_lru_locks osc
2793                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2794         done
2795 }
2796 run_test 39d "create, utime, stat =============================="
2797
2798 # bug 21114
2799 test_39e() {
2800         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2801         touch $DIR1/$tfile
2802         local mtime1=`stat -c %Y $DIR1/$tfile`
2803
2804         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2805
2806         for (( i=0; i < 2; i++ )) ; do
2807                 local mtime2=`stat -c %Y $DIR1/$tfile`
2808                 [ $mtime2 = $TEST_39_MTIME ] || \
2809                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2810
2811                 cancel_lru_locks osc
2812                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2813         done
2814 }
2815 run_test 39e "create, stat, utime, stat ========================"
2816
2817 # bug 21114
2818 test_39f() {
2819         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2820         touch $DIR1/$tfile
2821         mtime1=`stat -c %Y $DIR1/$tfile`
2822
2823         sleep 2
2824         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2825
2826         for (( i=0; i < 2; i++ )) ; do
2827                 local mtime2=`stat -c %Y $DIR1/$tfile`
2828                 [ $mtime2 = $TEST_39_MTIME ] || \
2829                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2830
2831                 cancel_lru_locks osc
2832                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2833         done
2834 }
2835 run_test 39f "create, stat, sleep, utime, stat ================="
2836
2837 # bug 11063
2838 test_39g() {
2839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2840         echo hello >> $DIR1/$tfile
2841         local mtime1=`stat -c %Y $DIR1/$tfile`
2842
2843         sleep 2
2844         chmod o+r $DIR1/$tfile
2845
2846         for (( i=0; i < 2; i++ )) ; do
2847                 local mtime2=`stat -c %Y $DIR1/$tfile`
2848                 [ "$mtime1" = "$mtime2" ] || \
2849                         error "lost mtime: $mtime2, should be $mtime1"
2850
2851                 cancel_lru_locks osc
2852                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2853         done
2854 }
2855 run_test 39g "write, chmod, stat ==============================="
2856
2857 # bug 11063
2858 test_39h() {
2859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2860         touch $DIR1/$tfile
2861         sleep 1
2862
2863         local d1=`date`
2864         echo hello >> $DIR1/$tfile
2865         local mtime1=`stat -c %Y $DIR1/$tfile`
2866
2867         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2868         local d2=`date`
2869         if [ "$d1" != "$d2" ]; then
2870                 echo "write and touch not within one second"
2871         else
2872                 for (( i=0; i < 2; i++ )) ; do
2873                         local mtime2=`stat -c %Y $DIR1/$tfile`
2874                         [ "$mtime2" = $TEST_39_MTIME ] || \
2875                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2876
2877                         cancel_lru_locks osc
2878                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2879                 done
2880         fi
2881 }
2882 run_test 39h "write, utime within one second, stat ============="
2883
2884 test_39i() {
2885         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2886         touch $DIR1/$tfile
2887         sleep 1
2888
2889         echo hello >> $DIR1/$tfile
2890         local mtime1=`stat -c %Y $DIR1/$tfile`
2891
2892         mv $DIR1/$tfile $DIR1/$tfile-1
2893
2894         for (( i=0; i < 2; i++ )) ; do
2895                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2896
2897                 [ "$mtime1" = "$mtime2" ] || \
2898                         error "lost mtime: $mtime2, should be $mtime1"
2899
2900                 cancel_lru_locks osc
2901                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2902         done
2903 }
2904 run_test 39i "write, rename, stat =============================="
2905
2906 test_39j() {
2907         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2908         start_full_debug_logging
2909         touch $DIR1/$tfile
2910         sleep 1
2911
2912         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
2913         lctl set_param fail_loc=0x80000412
2914         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
2915                 error "multiop failed"
2916         local multipid=$!
2917         local mtime1=`stat -c %Y $DIR1/$tfile`
2918
2919         mv $DIR1/$tfile $DIR1/$tfile-1
2920
2921         kill -USR1 $multipid
2922         wait $multipid || error "multiop close failed"
2923
2924         for (( i=0; i < 2; i++ )) ; do
2925                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2926                 [ "$mtime1" = "$mtime2" ] ||
2927                         error "mtime is lost on close: $mtime2, " \
2928                               "should be $mtime1"
2929
2930                 cancel_lru_locks osc
2931                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2932         done
2933         lctl set_param fail_loc=0
2934         stop_full_debug_logging
2935 }
2936 run_test 39j "write, rename, close, stat ======================="
2937
2938 test_39k() {
2939         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2940         touch $DIR1/$tfile
2941         sleep 1
2942
2943         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
2944         local multipid=$!
2945         local mtime1=`stat -c %Y $DIR1/$tfile`
2946
2947         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2948
2949         kill -USR1 $multipid
2950         wait $multipid || error "multiop close failed"
2951
2952         for (( i=0; i < 2; i++ )) ; do
2953                 local mtime2=`stat -c %Y $DIR1/$tfile`
2954
2955                 [ "$mtime2" = $TEST_39_MTIME ] || \
2956                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
2957
2958                 cancel_lru_locks osc
2959                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2960         done
2961 }
2962 run_test 39k "write, utime, close, stat ========================"
2963
2964 # this should be set to future
2965 TEST_39_ATIME=`date -d "1 year" +%s`
2966
2967 test_39l() {
2968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2969         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2970         local atime_diff=$(do_facet $SINGLEMDS \
2971                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
2972         rm -rf $DIR/$tdir
2973         mkdir -p $DIR/$tdir
2974
2975         # test setting directory atime to future
2976         touch -a -d @$TEST_39_ATIME $DIR/$tdir
2977         local atime=$(stat -c %X $DIR/$tdir)
2978         [ "$atime" = $TEST_39_ATIME ] || \
2979                 error "atime is not set to future: $atime, $TEST_39_ATIME"
2980
2981         # test setting directory atime from future to now
2982         local d1=$(date +%s)
2983         ls $DIR/$tdir
2984         local d2=$(date +%s)
2985
2986         cancel_lru_locks mdc
2987         atime=$(stat -c %X $DIR/$tdir)
2988         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
2989                 error "atime is not updated from future: $atime, $d1<atime<$d2"
2990
2991         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
2992         sleep 3
2993
2994         # test setting directory atime when now > dir atime + atime_diff
2995         d1=$(date +%s)
2996         ls $DIR/$tdir
2997         d2=$(date +%s)
2998         cancel_lru_locks mdc
2999         atime=$(stat -c %X $DIR/$tdir)
3000         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3001                 error "atime is not updated  : $atime, should be $d2"
3002
3003         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3004         sleep 3
3005
3006         # test not setting directory atime when now < dir atime + atime_diff
3007         ls $DIR/$tdir
3008         cancel_lru_locks mdc
3009         atime=$(stat -c %X $DIR/$tdir)
3010         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3011                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3012
3013         do_facet $SINGLEMDS \
3014                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3015 }
3016 run_test 39l "directory atime update ==========================="
3017
3018 test_39m() {
3019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3020         touch $DIR1/$tfile
3021         sleep 2
3022         local far_past_mtime=$(date -d "May 29 1953" +%s)
3023         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3024
3025         touch -m -d @$far_past_mtime $DIR1/$tfile
3026         touch -a -d @$far_past_atime $DIR1/$tfile
3027
3028         for (( i=0; i < 2; i++ )) ; do
3029                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3030                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3031                         error "atime or mtime set incorrectly"
3032
3033                 cancel_lru_locks osc
3034                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3035         done
3036 }
3037 run_test 39m "test atime and mtime before 1970"
3038
3039 test_40() {
3040         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
3041         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
3042         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
3043 }
3044 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3045
3046 test_41() {
3047         # bug 1553
3048         small_write $DIR/f41 18
3049 }
3050 run_test 41 "test small file write + fstat ====================="
3051
3052 count_ost_writes() {
3053         lctl get_param -n osc.*.stats |
3054             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
3055 }
3056
3057 # decent default
3058 WRITEBACK_SAVE=500
3059 DIRTY_RATIO_SAVE=40
3060 MAX_DIRTY_RATIO=50
3061 BG_DIRTY_RATIO_SAVE=10
3062 MAX_BG_DIRTY_RATIO=25
3063
3064 start_writeback() {
3065         trap 0
3066         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3067         # dirty_ratio, dirty_background_ratio
3068         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3069                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3070                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3071                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3072         else
3073                 # if file not here, we are a 2.4 kernel
3074                 kill -CONT `pidof kupdated`
3075         fi
3076 }
3077
3078 stop_writeback() {
3079         # setup the trap first, so someone cannot exit the test at the
3080         # exact wrong time and mess up a machine
3081         trap start_writeback EXIT
3082         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3083         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3084                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3085                 sysctl -w vm.dirty_writeback_centisecs=0
3086                 sysctl -w vm.dirty_writeback_centisecs=0
3087                 # save and increase /proc/sys/vm/dirty_ratio
3088                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3089                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3090                 # save and increase /proc/sys/vm/dirty_background_ratio
3091                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3092                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3093         else
3094                 # if file not here, we are a 2.4 kernel
3095                 kill -STOP `pidof kupdated`
3096         fi
3097 }
3098
3099 # ensure that all stripes have some grant before we test client-side cache
3100 setup_test42() {
3101         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3102                 dd if=/dev/zero of=$i bs=4k count=1
3103                 rm $i
3104         done
3105 }
3106
3107 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3108 # file truncation, and file removal.
3109 test_42a() {
3110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3111         setup_test42
3112         cancel_lru_locks osc
3113         stop_writeback
3114         sync; sleep 1; sync # just to be safe
3115         BEFOREWRITES=`count_ost_writes`
3116         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3117         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3118         AFTERWRITES=`count_ost_writes`
3119         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3120                 error "$BEFOREWRITES < $AFTERWRITES"
3121         start_writeback
3122 }
3123 run_test 42a "ensure that we don't flush on close =============="
3124
3125 test_42b() {
3126         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3127         setup_test42
3128         cancel_lru_locks osc
3129         stop_writeback
3130         sync
3131         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3132         BEFOREWRITES=`count_ost_writes`
3133         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3134         AFTERWRITES=`count_ost_writes`
3135         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3136                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3137         fi
3138         BEFOREWRITES=`count_ost_writes`
3139         sync || error "sync: $?"
3140         AFTERWRITES=`count_ost_writes`
3141         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3142                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3143         fi
3144         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3145         start_writeback
3146         return 0
3147 }
3148 run_test 42b "test destroy of file with cached dirty data ======"
3149
3150 # if these tests just want to test the effect of truncation,
3151 # they have to be very careful.  consider:
3152 # - the first open gets a {0,EOF}PR lock
3153 # - the first write conflicts and gets a {0, count-1}PW
3154 # - the rest of the writes are under {count,EOF}PW
3155 # - the open for truncate tries to match a {0,EOF}PR
3156 #   for the filesize and cancels the PWs.
3157 # any number of fixes (don't get {0,EOF} on open, match
3158 # composite locks, do smarter file size management) fix
3159 # this, but for now we want these tests to verify that
3160 # the cancellation with truncate intent works, so we
3161 # start the file with a full-file pw lock to match against
3162 # until the truncate.
3163 trunc_test() {
3164         test=$1
3165         file=$DIR/$test
3166         offset=$2
3167         cancel_lru_locks osc
3168         stop_writeback
3169         # prime the file with 0,EOF PW to match
3170         touch $file
3171         $TRUNCATE $file 0
3172         sync; sync
3173         # now the real test..
3174         dd if=/dev/zero of=$file bs=1024 count=100
3175         BEFOREWRITES=`count_ost_writes`
3176         $TRUNCATE $file $offset
3177         cancel_lru_locks osc
3178         AFTERWRITES=`count_ost_writes`
3179         start_writeback
3180 }
3181
3182 test_42c() {
3183         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3184         trunc_test 42c 1024
3185         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3186             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3187         rm $file
3188 }
3189 run_test 42c "test partial truncate of file with cached dirty data"
3190
3191 test_42d() {
3192         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3193         trunc_test 42d 0
3194         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3195             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3196         rm $file
3197 }
3198 run_test 42d "test complete truncate of file with cached dirty data"
3199
3200 test_42e() { # bug22074
3201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3202         local TDIR=$DIR/${tdir}e
3203         local pagesz=$(page_size)
3204         local pages=16 # hardcoded 16 pages, don't change it.
3205         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3206         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3207         local max_dirty_mb
3208         local warmup_files
3209
3210         test_mkdir -p $DIR/${tdir}e
3211         $SETSTRIPE -c 1 $TDIR
3212         createmany -o $TDIR/f $files
3213
3214         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3215
3216         # we assume that with $OSTCOUNT files, at least one of them will
3217         # be allocated on OST0.
3218         warmup_files=$((OSTCOUNT * max_dirty_mb))
3219         createmany -o $TDIR/w $warmup_files
3220
3221         # write a large amount of data into one file and sync, to get good
3222         # avail_grant number from OST.
3223         for ((i=0; i<$warmup_files; i++)); do
3224                 idx=$($GETSTRIPE -i $TDIR/w$i)
3225                 [ $idx -ne 0 ] && continue
3226                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3227                 break
3228         done
3229         [ $i -gt $warmup_files ] && error "OST0 is still cold"
3230         sync
3231         $LCTL get_param $proc_osc0/cur_dirty_bytes
3232         $LCTL get_param $proc_osc0/cur_grant_bytes
3233
3234         # create as much dirty pages as we can while not to trigger the actual
3235         # RPCs directly. but depends on the env, VFS may trigger flush during this
3236         # period, hopefully we are good.
3237         for ((i=0; i<$warmup_files; i++)); do
3238                 idx=$($GETSTRIPE -i $TDIR/w$i)
3239                 [ $idx -ne 0 ] && continue
3240                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3241         done
3242         $LCTL get_param $proc_osc0/cur_dirty_bytes
3243         $LCTL get_param $proc_osc0/cur_grant_bytes
3244
3245         # perform the real test
3246         $LCTL set_param $proc_osc0/rpc_stats 0
3247         for ((;i<$files; i++)); do
3248                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3249                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3250         done
3251         sync
3252         $LCTL get_param $proc_osc0/rpc_stats
3253
3254         local percent=0
3255         local have_ppr=false
3256         $LCTL get_param $proc_osc0/rpc_stats |
3257                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3258                         # skip lines until we are at the RPC histogram data
3259                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3260                         $have_ppr || continue
3261
3262                         # we only want the percent stat for < 16 pages
3263                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
3264
3265                         percent=$((percent + WPCT))
3266                         if [ $percent -gt 15 ]; then
3267                                 error "less than 16-pages write RPCs" \
3268                                       "$percent% > 15%"
3269                                 break
3270                         fi
3271                 done
3272         rm -rf $TDIR
3273 }
3274 run_test 42e "verify sub-RPC writes are not done synchronously"
3275
3276 test_43() {
3277         test_mkdir -p $DIR/$tdir
3278         cp -p /bin/ls $DIR/$tdir/$tfile
3279         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3280         pid=$!
3281         # give multiop a chance to open
3282         sleep 1
3283
3284         $DIR/$tdir/$tfile && error || true
3285         kill -USR1 $pid
3286 }
3287 run_test 43 "execution of file opened for write should return -ETXTBSY"
3288
3289 test_43a() {
3290         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3291         test_mkdir -p $DIR/$tdir
3292         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3293                         cp -p multiop $DIR/$tdir/multiop
3294         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/test43.junk O_c ||
3295                         return 1
3296         MULTIOP_PID=$!
3297         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3298         kill -USR1 $MULTIOP_PID || return 2
3299         wait $MULTIOP_PID || return 3
3300         rm $TMP/test43.junk
3301 }
3302 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3303
3304 test_43b() {
3305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3306         test_mkdir -p $DIR/$tdir
3307         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3308                         cp -p multiop $DIR/$tdir/multiop
3309         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/test43.junk O_c ||
3310                         return 1
3311         MULTIOP_PID=$!
3312         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3313         kill -USR1 $MULTIOP_PID || return 2
3314         wait $MULTIOP_PID || return 3
3315         rm $TMP/test43.junk
3316 }
3317 run_test 43b "truncate of file being executed should return -ETXTBSY"
3318
3319 test_43c() {
3320         local testdir="$DIR/$tdir"
3321         test_mkdir -p $DIR/$tdir
3322         cp $SHELL $testdir/
3323         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3324                 ( cd $testdir && md5sum -c)
3325 }
3326 run_test 43c "md5sum of copy into lustre========================"
3327
3328 test_44() {
3329         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
3330         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3331         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3332 }
3333 run_test 44 "zero length read from a sparse stripe ============="
3334
3335 test_44a() {
3336     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
3337                          awk '{print $2}'`
3338     [ -z "$nstripe" ] && skip "can't get stripe info" && return
3339     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
3340     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
3341                       awk '{print $2}'`
3342     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
3343         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
3344     fi
3345
3346     OFFSETS="0 $((stride/2)) $((stride-1))"
3347     for offset in $OFFSETS ; do
3348       for i in `seq 0 $((nstripe-1))`; do
3349         local GLOBALOFFSETS=""
3350         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
3351         local myfn=$DIR/d44a-$size
3352         echo "--------writing $myfn at $size"
3353         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
3354         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3355         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3356                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3357
3358         for j in `seq 0 $((nstripe-1))`; do
3359             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
3360             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
3361             GLOBALOFFSETS="$GLOBALOFFSETS $size"
3362         done
3363         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3364                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3365         rm -f $myfn
3366       done
3367     done
3368 }
3369 run_test 44a "test sparse pwrite ==============================="
3370
3371 dirty_osc_total() {
3372         tot=0
3373         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3374                 tot=$(($tot + $d))
3375         done
3376         echo $tot
3377 }
3378 do_dirty_record() {
3379         before=`dirty_osc_total`
3380         echo executing "\"$*\""
3381         eval $*
3382         after=`dirty_osc_total`
3383         echo before $before, after $after
3384 }
3385 test_45() {
3386         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3387         f="$DIR/f45"
3388         # Obtain grants from OST if it supports it
3389         echo blah > ${f}_grant
3390         stop_writeback
3391         sync
3392         do_dirty_record "echo blah > $f"
3393         [ $before -eq $after ] && error "write wasn't cached"
3394         do_dirty_record "> $f"
3395         [ $before -gt $after ] || error "truncate didn't lower dirty count"
3396         do_dirty_record "echo blah > $f"
3397         [ $before -eq $after ] && error "write wasn't cached"
3398         do_dirty_record "sync"
3399         [ $before -gt $after ] || error "writeback didn't lower dirty count"
3400         do_dirty_record "echo blah > $f"
3401         [ $before -eq $after ] && error "write wasn't cached"
3402         do_dirty_record "cancel_lru_locks osc"
3403         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
3404         start_writeback
3405 }
3406 run_test 45 "osc io page accounting ============================"
3407
3408 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3409 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3410 # objects offset and an assert hit when an rpc was built with 1023's mapped
3411 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3412 test_46() {
3413         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3414         f="$DIR/f46"
3415         stop_writeback
3416         sync
3417         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3418         sync
3419         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3420         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3421         sync
3422         start_writeback
3423 }
3424 run_test 46 "dirtying a previously written page ================"
3425
3426 # test_47 is removed "Device nodes check" is moved to test_28
3427
3428 test_48a() { # bug 2399
3429         check_kernel_version 34 || return 0
3430         test_mkdir -p $DIR/$tdir
3431         cd $DIR/$tdir
3432         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3433         test_mkdir $DIR/$tdir || error "recreate directory failed"
3434         touch foo || error "'touch foo' failed after recreating cwd"
3435         test_mkdir $DIR/$tdir/bar ||
3436                      error "'mkdir foo' failed after recreating cwd"
3437         if check_kernel_version 44; then
3438                 touch .foo || error "'touch .foo' failed after recreating cwd"
3439                 test_mkdir $DIR/$tdir/.bar ||
3440                               error "'mkdir .foo' failed after recreating cwd"
3441         fi
3442         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3443         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3444         cd . || error "'cd .' failed after recreating cwd"
3445         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3446         rmdir . && error "'rmdir .' worked after recreating cwd"
3447         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3448         cd .. || error "'cd ..' failed after recreating cwd"
3449 }
3450 run_test 48a "Access renamed working dir (should return errors)="
3451
3452 test_48b() { # bug 2399
3453         check_kernel_version 34 || return 0
3454         rm -rf $DIR/$tdir
3455         test_mkdir -p $DIR/$tdir
3456         cd $DIR/$tdir
3457         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3458         touch foo && error "'touch foo' worked after removing cwd"
3459         test_mkdir $DIR/$tdir/foo &&
3460                      error "'mkdir foo' worked after removing cwd"
3461         if check_kernel_version 44; then
3462                 touch .foo && error "'touch .foo' worked after removing cwd"
3463                 test_mkdir $DIR/$tdir/.foo &&
3464                               error "'mkdir .foo' worked after removing cwd"
3465         fi
3466         ls . > /dev/null && error "'ls .' worked after removing cwd"
3467         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3468         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3469         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3470         rmdir . && error "'rmdir .' worked after removing cwd"
3471         ln -s . foo && error "'ln -s .' worked after removing cwd"
3472         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3473 }
3474 run_test 48b "Access removed working dir (should return errors)="
3475
3476 test_48c() { # bug 2350
3477         check_kernel_version 36 || return 0
3478         #lctl set_param debug=-1
3479         #set -vx
3480         rm -rf $DIR/$tdir
3481         test_mkdir -p $DIR/$tdir/dir
3482         cd $DIR/$tdir/dir
3483         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3484         $TRACE touch foo && error "touch foo worked after removing cwd"
3485         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3486         if check_kernel_version 44; then
3487                 touch .foo && error "touch .foo worked after removing cwd"
3488                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3489         fi
3490         $TRACE ls . && error "'ls .' worked after removing cwd"
3491         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3492         is_patchless || ( $TRACE cd . &&
3493                         error "'cd .' worked after removing cwd" )
3494         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3495         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3496         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3497         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3498 }
3499 run_test 48c "Access removed working subdir (should return errors)"
3500
3501 test_48d() { # bug 2350
3502         check_kernel_version 36 || return 0
3503         #lctl set_param debug=-1
3504         #set -vx
3505         rm -rf $DIR/$tdir
3506         test_mkdir -p $DIR/$tdir/dir
3507         cd $DIR/$tdir/dir
3508         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3509         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3510         $TRACE touch foo && error "'touch foo' worked after removing parent"
3511         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3512         if check_kernel_version 44; then
3513                 touch .foo && error "'touch .foo' worked after removing parent"
3514                 test_mkdir .foo &&
3515                               error "mkdir .foo worked after removing parent"
3516         fi
3517         $TRACE ls . && error "'ls .' worked after removing parent"
3518         $TRACE ls .. && error "'ls ..' worked after removing parent"
3519         is_patchless || ( $TRACE cd . &&
3520                         error "'cd .' worked after recreate parent" )
3521         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3522         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3523         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3524         is_patchless || ( $TRACE cd .. &&
3525                         error "'cd ..' worked after removing parent" || true )
3526 }
3527 run_test 48d "Access removed parent subdir (should return errors)"
3528
3529 test_48e() { # bug 4134
3530         check_kernel_version 41 || return 0
3531         #lctl set_param debug=-1
3532         #set -vx
3533         rm -rf $DIR/$tdir
3534         test_mkdir -p $DIR/$tdir/dir
3535         cd $DIR/$tdir/dir
3536         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3537         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3538         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3539         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3540         # On a buggy kernel addition of "touch foo" after cd .. will
3541         # produce kernel oops in lookup_hash_it
3542         touch ../foo && error "'cd ..' worked after recreate parent"
3543         cd $DIR
3544         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3545 }
3546 run_test 48e "Access to recreated parent subdir (should return errors)"
3547
3548 test_49() { # LU-1030
3549         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3550         # get ost1 size - lustre-OST0000
3551         ost1_size=$(do_facet ost1 lfs df |grep ${ost1_svc} |awk '{print $4}')
3552         # write 800M at maximum
3553         [ $ost1_size -gt 819200 ] && ost1_size=819200
3554
3555         lfs setstripe -c 1 -i 0 $DIR/$tfile
3556         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3557         local dd_pid=$!
3558
3559         # change max_pages_per_rpc while writing the file
3560         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3561         local orig_mppc=`$LCTL get_param -n $osc1_mppc`
3562         # loop until dd process exits
3563         while ps ax -opid | grep -wq $dd_pid; do
3564                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3565                 sleep $((RANDOM % 5 + 1))
3566         done
3567         # restore original max_pages_per_rpc
3568         $LCTL set_param $osc1_mppc=$orig_mppc
3569         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3570 }
3571 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3572
3573 test_50() {
3574         # bug 1485
3575         test_mkdir $DIR/$tdir
3576         cd $DIR/$tdir
3577         ls /proc/$$/cwd || error
3578 }
3579 run_test 50 "special situations: /proc symlinks  ==============="
3580
3581 test_51a() {    # was test_51
3582         # bug 1516 - create an empty entry right after ".." then split dir
3583         test_mkdir -p $DIR/$tdir
3584         touch $DIR/$tdir/foo
3585         $MCREATE $DIR/$tdir/bar
3586         rm $DIR/$tdir/foo
3587         createmany -m $DIR/$tdir/longfile 201
3588         FNUM=202
3589         while [ `ls -sd $DIR/$tdir | awk '{ print $1 }'` -eq 4 ]; do
3590                 $MCREATE $DIR/$tdir/longfile$FNUM
3591                 FNUM=$(($FNUM + 1))
3592                 echo -n "+"
3593         done
3594         echo
3595         ls -l $DIR/$tdir > /dev/null || error
3596 }
3597 run_test 51a "special situations: split htree with empty entry =="
3598
3599 export NUMTEST=70000
3600 test_51b() {
3601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3602         local BASE=$DIR/$tdir
3603
3604         # cleanup the directory
3605         rm -fr $BASE
3606
3607         test_mkdir -p $BASE
3608
3609         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3610         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3611         [ $numfree -lt 21000 ] && skip "not enough free inodes ($numfree)" &&
3612                 return
3613
3614         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3615                 echo "reduced count to $NUMTEST due to inodes"
3616
3617         # need to check free space for the directories as well
3618         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3619         numfree=$((blkfree / 4))
3620         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3621                 echo "reduced count to $NUMTEST due to blocks"
3622
3623         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3624                 echo "failed" > $BASE/fnum
3625 }
3626 run_test 51b "exceed 64k subdirectory nlink limit"
3627
3628 test_51ba() { # LU-993
3629         local BASE=$DIR/$tdir
3630         # unlink all but 100 subdirectories, then check it still works
3631         local LEFT=100
3632         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3633
3634         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3635         local DELETE=$((NUMTEST - LEFT))
3636
3637         # continue on to run this test even if 51b didn't finish,
3638         # just to delete the many subdirectories created.
3639         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3640
3641         # for ldiskfs the nlink count should be 1, but this is OSD specific
3642         # and so this is listed for informational purposes only
3643         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3644         unlinkmany -d $BASE/d $DELETE
3645         RC=$?
3646
3647         if [ $RC -ne 0 ]; then
3648                 if [ "$NUMPREV" == "failed" ]; then
3649                         skip "previous setup failed"
3650                         return 0
3651                 else
3652                         error "unlink of first $DELETE subdirs failed"
3653                         return $RC
3654                 fi
3655         fi
3656
3657         echo "nlink between: $(stat -c %h $BASE)"
3658         # trim the first line of ls output
3659         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3660         [ $FOUND -ne $LEFT ] &&
3661                 error "can't find subdirs: found only $FOUND/$LEFT"
3662
3663         unlinkmany -d $BASE/d $DELETE $LEFT ||
3664                 error "unlink of second $LEFT subdirs failed"
3665         # regardless of whether the backing filesystem tracks nlink accurately
3666         # or not, the nlink count shouldn't be more than "." and ".." here
3667         local AFTER=$(stat -c %h $BASE)
3668         [ $AFTER -gt 2 ] && error "nlink after: $AFTER > 2" ||
3669                 echo "nlink after: $AFTER"
3670 }
3671 run_test 51ba "verify nlink for many subdirectory cleanup"
3672
3673 test_51d() {
3674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3675         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3676         test_mkdir -p $DIR/$tdir
3677         createmany -o $DIR/$tdir/t- 1000
3678         $GETSTRIPE $DIR/$tdir > $TMP/files
3679         for N in `seq 0 $((OSTCOUNT - 1))`; do
3680             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3681             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3682             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3683         done
3684         unlinkmany $DIR/$tdir/t- 1000
3685
3686         NLAST=0
3687         for N in `seq 1 $((OSTCOUNT - 1))`; do
3688             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3689                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3690             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3691                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3692
3693             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3694                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3695             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3696                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3697             NLAST=$N
3698         done
3699 }
3700 run_test 51d "check object distribution ===================="
3701
3702 test_52a() {
3703         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
3704         test_mkdir -p $DIR/$tdir
3705         touch $DIR/$tdir/foo
3706         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
3707         echo bar >> $DIR/$tdir/foo || error "append bar failed"
3708         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3709         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3710         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3711                                         error "link worked"
3712         echo foo >> $DIR/$tdir/foo || error "append foo failed"
3713         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3714         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
3715                                                      error "lsattr"
3716         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
3717         cp -r $DIR/$tdir /tmp/
3718         rm -fr $DIR/$tdir || error "cleanup rm failed"
3719 }
3720 run_test 52a "append-only flag test (should return errors) ====="
3721
3722 test_52b() {
3723         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
3724         test_mkdir -p $DIR/$tdir
3725         touch $DIR/$tdir/foo
3726         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
3727         cat test > $DIR/$tdir/foo && error "cat test worked"
3728         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3729         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3730         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3731                                         error "link worked"
3732         echo foo >> $DIR/$tdir/foo && error "echo worked"
3733         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3734         [ -f $DIR/$tdir/foo ] || error
3735         [ -f $DIR/$tdir/foo_ren ] && error
3736         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
3737                                                         error "lsattr"
3738         chattr -i $DIR/$tdir/foo || error "chattr failed"
3739
3740         rm -fr $DIR/$tdir || error
3741 }
3742 run_test 52b "immutable flag test (should return errors) ======="
3743
3744 test_53() {
3745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3746         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3747         remote_ost_nodsh && skip "remote OST with nodsh" && return
3748
3749         local param
3750         local ostname
3751         local mds_last
3752         local ost_last
3753         local ostnum
3754         local node
3755
3756         # only test MDT0000
3757         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3758         for value in $(do_facet $SINGLEMDS lctl get_param osc.$mdtosc.prealloc_last_id) ; do
3759                 param=`echo ${value[0]} | cut -d "=" -f1`
3760                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
3761                 mds_last=$(do_facet $SINGLEMDS lctl get_param -n $param)
3762                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
3763                 node=$(facet_active_host ost$((ostnum+1)))
3764                 param="obdfilter.$ostname.last_id"
3765                 ost_last=$(do_node $node lctl get_param -n $param | head -n 1)
3766                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3767                 if [ $ost_last != $mds_last ]; then
3768                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
3769                 fi
3770         done
3771 }
3772 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
3773
3774 test_54a() {
3775         [ ! -f "$SOCKETSERVER" ] && skip_env "no socketserver, skipping" && return
3776         [ ! -f "$SOCKETCLIENT" ] && skip_env "no socketclient, skipping" && return
3777         $SOCKETSERVER $DIR/socket
3778         $SOCKETCLIENT $DIR/socket || error
3779         $MUNLINK $DIR/socket
3780 }
3781 run_test 54a "unix domain socket test =========================="
3782
3783 test_54b() {
3784         f="$DIR/f54b"
3785         mknod $f c 1 3
3786         chmod 0666 $f
3787         dd if=/dev/zero of=$f bs=`page_size` count=1
3788 }
3789 run_test 54b "char device works in lustre ======================"
3790
3791 find_loop_dev() {
3792         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
3793         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
3794         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
3795
3796         for i in `seq 3 7`; do
3797                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
3798                 LOOPDEV=$LOOPBASE$i
3799                 LOOPNUM=$i
3800                 break
3801         done
3802 }
3803
3804 test_54c() {
3805         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3806         tfile="$DIR/f54c"
3807         tdir="$DIR/d54c"
3808         loopdev="$DIR/loop54c"
3809
3810         find_loop_dev
3811         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
3812         mknod $loopdev b 7 $LOOPNUM
3813         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
3814         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
3815         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
3816         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
3817         test_mkdir -p $tdir
3818         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
3819         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
3820         df $tdir
3821         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
3822         $UMOUNT $tdir
3823         losetup -d $loopdev
3824         rm $loopdev
3825 }
3826 run_test 54c "block device works in lustre ====================="
3827
3828 test_54d() {
3829         f="$DIR/f54d"
3830         string="aaaaaa"
3831         mknod $f p
3832         [ "$string" = `echo $string > $f | cat $f` ] || error
3833 }
3834 run_test 54d "fifo device works in lustre ======================"
3835
3836 test_54e() {
3837         check_kernel_version 46 || return 0
3838         f="$DIR/f54e"
3839         string="aaaaaa"
3840         cp -aL /dev/console $f
3841         echo $string > $f || error
3842 }
3843 run_test 54e "console/tty device works in lustre ======================"
3844
3845 #The test_55 used to be iopen test and it was removed by bz#24037.
3846 #run_test 55 "check iopen_connect_dentry() ======================"
3847
3848 test_56a() {    # was test_56
3849         rm -rf $DIR/$tdir
3850         $SETSTRIPE -d $DIR
3851         test_mkdir $DIR/$tdir
3852         test_mkdir $DIR/$tdir/dir
3853         NUMFILES=3
3854         NUMFILESx2=$(($NUMFILES * 2))
3855         for i in `seq 1 $NUMFILES` ; do
3856                 touch $DIR/$tdir/file$i
3857                 touch $DIR/$tdir/dir/file$i
3858         done
3859
3860         # test lfs getstripe with --recursive
3861         FILENUM=`$GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx`
3862         [ $FILENUM -eq $NUMFILESx2 ] ||
3863                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
3864         FILENUM=`$GETSTRIPE $DIR/$tdir | grep -c obdidx`
3865         [ $FILENUM -eq $NUMFILES ] ||
3866                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
3867         echo "$GETSTRIPE --recursive passed."
3868
3869         # test lfs getstripe with file instead of dir
3870         FILENUM=`$GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx`
3871         [ $FILENUM  -eq 1 ] || error \
3872                  "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
3873         echo "$GETSTRIPE file1 passed."
3874
3875         #test lfs getstripe with --verbose
3876         [ `$GETSTRIPE --verbose $DIR/$tdir |
3877                         grep -c lmm_magic` -eq $NUMFILES ] ||
3878                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
3879         [ `$GETSTRIPE $DIR/$tdir | grep -c lmm_magic` -eq 0 ] ||
3880             error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
3881         echo "$GETSTRIPE --verbose passed."
3882
3883         #test lfs getstripe with --obd
3884         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
3885                                         grep -q "unknown obduuid" ||
3886                 error "$GETSTRIPE --obd wrong_uuid should return error message"
3887
3888         [  "$OSTCOUNT" -lt 2 ] &&
3889                 skip_env "skipping other $GETSTRIPE --obd test" && return
3890
3891         OSTIDX=1
3892         OBDUUID=$(ostuuid_from_index $OSTIDX)
3893         FILENUM=`$GETSTRIPE -ir $DIR/$tdir | grep -x $OSTIDX | wc -l`
3894         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l`
3895         [ $FOUND -eq $FILENUM ] ||
3896                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
3897         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
3898                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
3899                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
3900                 error "$GETSTRIPE --obd: should not show file on other obd"
3901         echo "$GETSTRIPE --obd passed"
3902 }
3903 run_test 56a "check $GETSTRIPE"
3904
3905 NUMFILES=3
3906 NUMDIRS=3
3907 setup_56() {
3908         local LOCAL_NUMFILES="$1"
3909         local LOCAL_NUMDIRS="$2"
3910         local MKDIR_PARAMS="$3"
3911
3912         if [ ! -d "$TDIR" ] ; then
3913                 test_mkdir -p $TDIR
3914                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
3915                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3916                         touch $TDIR/file$i
3917                 done
3918                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3919                         test_mkdir $TDIR/dir$i
3920                         for j in `seq 1 $LOCAL_NUMFILES` ; do
3921                                 touch $TDIR/dir$i/file$j
3922                         done
3923                 done
3924         fi
3925 }
3926
3927 setup_56_special() {
3928         LOCAL_NUMFILES=$1
3929         LOCAL_NUMDIRS=$2
3930         setup_56 $1 $2
3931         if [ ! -e "$TDIR/loop1b" ] ; then
3932                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3933                         mknod $TDIR/loop${i}b b 7 $i
3934                         mknod $TDIR/null${i}c c 1 3
3935                         ln -s $TDIR/file1 $TDIR/link${i}l
3936                 done
3937                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3938                         mknod $TDIR/dir$i/loop${i}b b 7 $i
3939                         mknod $TDIR/dir$i/null${i}c c 1 3
3940                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
3941                 done
3942         fi
3943 }
3944
3945 test_56g() {
3946         $SETSTRIPE -d $DIR
3947
3948         TDIR=$DIR/${tdir}g
3949         setup_56 $NUMFILES $NUMDIRS
3950
3951         EXPECTED=$(($NUMDIRS + 2))
3952         # test lfs find with -name
3953         for i in $(seq 1 $NUMFILES) ; do
3954                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
3955                 [ $NUMS -eq $EXPECTED ] ||
3956                         error "lfs find -name \"*$i\" $TDIR wrong: "\
3957                               "found $NUMS, expected $EXPECTED"
3958         done
3959 }
3960 run_test 56g "check lfs find -name ============================="
3961
3962 test_56h() {
3963         $SETSTRIPE -d $DIR
3964
3965         TDIR=$DIR/${tdir}g
3966         setup_56 $NUMFILES $NUMDIRS
3967
3968         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
3969         # test lfs find with ! -name
3970         for i in $(seq 1 $NUMFILES) ; do
3971                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
3972                 [ $NUMS -eq $EXPECTED ] ||
3973                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
3974                               "found $NUMS, expected $EXPECTED"
3975         done
3976 }
3977 run_test 56h "check lfs find ! -name ============================="
3978
3979 test_56i() {
3980        tdir=${tdir}i
3981        test_mkdir -p $DIR/$tdir
3982        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
3983        CMD="$LFIND -ost $UUID $DIR/$tdir"
3984        OUT=$($CMD)
3985        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
3986 }
3987 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
3988
3989 test_56j() {
3990         TDIR=$DIR/${tdir}g
3991         setup_56_special $NUMFILES $NUMDIRS
3992
3993         EXPECTED=$((NUMDIRS + 1))
3994         CMD="$LFIND -type d $TDIR"
3995         NUMS=$($CMD | wc -l)
3996         [ $NUMS -eq $EXPECTED ] ||
3997                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
3998 }
3999 run_test 56j "check lfs find -type d ============================="
4000
4001 test_56k() {
4002         TDIR=$DIR/${tdir}g
4003         setup_56_special $NUMFILES $NUMDIRS
4004
4005         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4006         CMD="$LFIND -type f $TDIR"
4007         NUMS=$($CMD | wc -l)
4008         [ $NUMS -eq $EXPECTED ] ||
4009                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4010 }
4011 run_test 56k "check lfs find -type f ============================="
4012
4013 test_56l() {
4014         TDIR=$DIR/${tdir}g
4015         setup_56_special $NUMFILES $NUMDIRS
4016
4017         EXPECTED=$((NUMDIRS + NUMFILES))
4018         CMD="$LFIND -type b $TDIR"
4019         NUMS=$($CMD | wc -l)
4020         [ $NUMS -eq $EXPECTED ] ||
4021                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4022 }
4023 run_test 56l "check lfs find -type b ============================="
4024
4025 test_56m() {
4026         TDIR=$DIR/${tdir}g
4027         setup_56_special $NUMFILES $NUMDIRS
4028
4029         EXPECTED=$((NUMDIRS + NUMFILES))
4030         CMD="$LFIND -type c $TDIR"
4031         NUMS=$($CMD | wc -l)
4032         [ $NUMS -eq $EXPECTED ] ||
4033                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4034 }
4035 run_test 56m "check lfs find -type c ============================="
4036
4037 test_56n() {
4038         TDIR=$DIR/${tdir}g
4039         setup_56_special $NUMFILES $NUMDIRS
4040
4041         EXPECTED=$((NUMDIRS + NUMFILES))
4042         CMD="$LFIND -type l $TDIR"
4043         NUMS=$($CMD | wc -l)
4044         [ $NUMS -eq $EXPECTED ] ||
4045                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4046 }
4047 run_test 56n "check lfs find -type l ============================="
4048
4049 test_56o() {
4050         TDIR=$DIR/${tdir}o
4051         setup_56 $NUMFILES $NUMDIRS
4052
4053         utime $TDIR/file1 > /dev/null || error "utime (1)"
4054         utime $TDIR/file2 > /dev/null || error "utime (2)"
4055         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4056         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4057         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4058         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4059
4060         EXPECTED=4
4061         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4062         [ $NUMS -eq $EXPECTED ] || \
4063                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4064
4065         EXPECTED=12
4066         CMD="$LFIND -mtime 0 $TDIR"
4067         NUMS=$($CMD | wc -l)
4068         [ $NUMS -eq $EXPECTED ] ||
4069                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4070 }
4071 run_test 56o "check lfs find -mtime for old files =========================="
4072
4073 test_56p() {
4074         [ $RUNAS_ID -eq $UID ] &&
4075                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4076
4077         TDIR=$DIR/${tdir}p
4078         setup_56 $NUMFILES $NUMDIRS
4079
4080         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4081         EXPECTED=$NUMFILES
4082         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4083         NUMS=$($CMD | wc -l)
4084         [ $NUMS -eq $EXPECTED ] || \
4085                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4086
4087         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4088         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4089         NUMS=$($CMD | wc -l)
4090         [ $NUMS -eq $EXPECTED ] || \
4091                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4092 }
4093 run_test 56p "check lfs find -uid and ! -uid ==============================="
4094
4095 test_56q() {
4096         [ $RUNAS_ID -eq $UID ] &&
4097                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4098
4099         TDIR=$DIR/${tdir}q
4100         setup_56 $NUMFILES $NUMDIRS
4101
4102         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4103
4104         EXPECTED=$NUMFILES
4105         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4106         NUMS=$($CMD | wc -l)
4107         [ $NUMS -eq $EXPECTED ] ||
4108                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4109
4110         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4111         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4112         NUMS=$($CMD | wc -l)
4113         [ $NUMS -eq $EXPECTED ] ||
4114                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4115 }
4116 run_test 56q "check lfs find -gid and ! -gid ==============================="
4117
4118 test_56r() {
4119         TDIR=$DIR/${tdir}r
4120         setup_56 $NUMFILES $NUMDIRS
4121
4122         EXPECTED=12
4123         CMD="$LFIND -size 0 -type f $TDIR"
4124         NUMS=$($CMD | wc -l)
4125         [ $NUMS -eq $EXPECTED ] ||
4126                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4127         EXPECTED=0
4128         CMD="$LFIND ! -size 0 -type f $TDIR"
4129         NUMS=$($CMD | wc -l)
4130         [ $NUMS -eq $EXPECTED ] ||
4131                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4132         echo "test" > $TDIR/$tfile
4133         echo "test2" > $TDIR/$tfile.2 && sync
4134         EXPECTED=1
4135         CMD="$LFIND -size 5 -type f $TDIR"
4136         NUMS=$($CMD | wc -l)
4137         [ $NUMS -eq $EXPECTED ] ||
4138                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4139         EXPECTED=1
4140         CMD="$LFIND -size +5 -type f $TDIR"
4141         NUMS=$($CMD | wc -l)
4142         [ $NUMS -eq $EXPECTED ] ||
4143                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4144         EXPECTED=2
4145         CMD="$LFIND -size +0 -type f $TDIR"
4146         NUMS=$($CMD | wc -l)
4147         [ $NUMS -eq $EXPECTED ] ||
4148                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4149         EXPECTED=2
4150         CMD="$LFIND ! -size -5 -type f $TDIR"
4151         NUMS=$($CMD | wc -l)
4152         [ $NUMS -eq $EXPECTED ] ||
4153                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4154         EXPECTED=12
4155         CMD="$LFIND -size -5 -type f $TDIR"
4156         NUMS=$($CMD | wc -l)
4157         [ $NUMS -eq $EXPECTED ] ||
4158                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4159 }
4160 run_test 56r "check lfs find -size works =========================="
4161
4162 test_56s() { # LU-611
4163         TDIR=$DIR/${tdir}s
4164         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4165
4166         if [ $OSTCOUNT -gt 1 ]; then
4167                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4168                 ONESTRIPE=4
4169                 EXTRA=4
4170         else
4171                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4172                 EXTRA=0
4173         fi
4174
4175         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4176         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4177         NUMS=$($CMD | wc -l)
4178         [ $NUMS -eq $EXPECTED ] ||
4179                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4180
4181         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4182         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4183         NUMS=$($CMD | wc -l)
4184         [ $NUMS -eq $EXPECTED ] ||
4185                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4186
4187         EXPECTED=$ONESTRIPE
4188         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4189         NUMS=$($CMD | wc -l)
4190         [ $NUMS -eq $EXPECTED ] ||
4191                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4192
4193         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4194         NUMS=$($CMD | wc -l)
4195         [ $NUMS -eq $EXPECTED ] ||
4196                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4197
4198         EXPECTED=0
4199         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4200         NUMS=$($CMD | wc -l)
4201         [ $NUMS -eq $EXPECTED ] ||
4202                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4203 }
4204 run_test 56s "check lfs find -stripe-count works"
4205
4206 test_56t() { # LU-611
4207         TDIR=$DIR/${tdir}t
4208         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4209
4210         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4211
4212         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4213         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4214         NUMS=$($CMD | wc -l)
4215         [ $NUMS -eq $EXPECTED ] ||
4216                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4217
4218         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4219         NUMS=$($CMD | wc -l)
4220         [ $NUMS -eq $EXPECTED ] ||
4221                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4222
4223         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4224         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4225         NUMS=$($CMD | wc -l)
4226         [ $NUMS -eq $EXPECTED ] ||
4227                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4228
4229         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4230         NUMS=$($CMD | wc -l)
4231         [ $NUMS -eq $EXPECTED ] ||
4232                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4233
4234         EXPECTED=4
4235         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4236         NUMS=$($CMD | wc -l)
4237         [ $NUMS -eq $EXPECTED ] ||
4238                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4239
4240         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4241         NUMS=$($CMD | wc -l)
4242         [ $NUMS -eq $EXPECTED ] ||
4243                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4244
4245         EXPECTED=0
4246         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4247         NUMS=$($CMD | wc -l)
4248         [ $NUMS -eq $EXPECTED ] ||
4249                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4250 }
4251 run_test 56t "check lfs find -stripe-size works"
4252
4253 test_56u() { # LU-611
4254         TDIR=$DIR/${tdir}u
4255         setup_56 $NUMFILES $NUMDIRS "-i 0"
4256
4257         if [ $OSTCOUNT -gt 1 ]; then
4258                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4259                 ONESTRIPE=4
4260         else
4261                 ONESTRIPE=0
4262         fi
4263
4264         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4265         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4266         NUMS=$($CMD | wc -l)
4267         [ $NUMS -eq $EXPECTED ] ||
4268                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4269
4270         EXPECTED=$ONESTRIPE
4271         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4272         NUMS=$($CMD | wc -l)
4273         [ $NUMS -eq $EXPECTED ] ||
4274                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4275
4276         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4277         NUMS=$($CMD | wc -l)
4278         [ $NUMS -eq $EXPECTED ] ||
4279                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4280
4281         EXPECTED=0
4282         # This should produce an error and not return any files
4283         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4284         NUMS=$($CMD 2>/dev/null | wc -l)
4285         [ $NUMS -eq $EXPECTED ] ||
4286                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4287
4288         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4289         CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4290         NUMS=$($CMD | wc -l)
4291         [ $NUMS -eq $EXPECTED ] ||
4292                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4293 }
4294 run_test 56u "check lfs find -stripe-index works"
4295
4296 test_56v() {
4297     local MDT_IDX=0
4298
4299     TDIR=$DIR/${tdir}v
4300     rm -rf $TDIR
4301     setup_56 $NUMFILES $NUMDIRS
4302
4303     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4304     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4305
4306     for file in $($LFIND -mdt $UUID $TDIR); do
4307         file_mdt_idx=$($GETSTRIPE -M $file)
4308         [ $file_mdt_idx -eq $MDT_IDX ] ||
4309             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4310     done
4311 }
4312 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4313
4314 # Get and check the actual stripe count of one file.
4315 # Usage: check_stripe_count <file> <expected_stripe_count>
4316 check_stripe_count() {
4317     local file=$1
4318     local expected=$2
4319     local actual
4320
4321     [[ -z "$file" || -z "$expected" ]] &&
4322         error "check_stripe_count: invalid argument!"
4323
4324     local cmd="$GETSTRIPE -c $file"
4325     actual=$($cmd) || error "$cmd failed"
4326     actual=${actual%% *}
4327
4328     if [[ $actual -ne $expected ]]; then
4329         [[ $expected -eq -1 ]] ||
4330             error "$cmd wrong: found $actual, expected $expected"
4331         [[ $actual -eq $OSTCOUNT ]] ||
4332             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4333     fi
4334 }
4335
4336 test_56w() {
4337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4338         TDIR=$DIR/${tdir}w
4339
4340     rm -rf $TDIR || error "remove $TDIR failed"
4341     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4342
4343     local stripe_size
4344     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4345         error "$GETSTRIPE -S -d $TDIR failed"
4346     stripe_size=${stripe_size%% *}
4347
4348     local file_size=$((stripe_size * OSTCOUNT))
4349     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4350     local required_space=$((file_num * file_size))
4351     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4352     [[ $free_space -le $((required_space / 1024)) ]] &&
4353         skip_env "need at least $required_space bytes free space," \
4354                  "have $free_space kbytes" && return
4355
4356     local dd_bs=65536
4357     local dd_count=$((file_size / dd_bs))
4358
4359     # write data into the files
4360     local i
4361     local j
4362     local file
4363     for i in $(seq 1 $NUMFILES); do
4364         file=$TDIR/file$i
4365         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4366             error "write data into $file failed"
4367     done
4368     for i in $(seq 1 $NUMDIRS); do
4369         for j in $(seq 1 $NUMFILES); do
4370             file=$TDIR/dir$i/file$j
4371             yes | dd bs=$dd_bs count=$dd_count of=$file \
4372                 >/dev/null 2>&1 ||
4373                 error "write data into $file failed"
4374         done
4375     done
4376
4377     local expected=-1
4378     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4379
4380     # lfs_migrate file
4381     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4382     echo "$cmd"
4383     eval $cmd || error "$cmd failed"
4384
4385     check_stripe_count $TDIR/file1 $expected
4386
4387     # lfs_migrate dir
4388     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4389     echo "$cmd"
4390     eval $cmd || error "$cmd failed"
4391
4392     for j in $(seq 1 $NUMFILES); do
4393         check_stripe_count $TDIR/dir1/file$j $expected
4394     done
4395
4396     # lfs_migrate works with lfs find
4397     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4398          $LFS_MIGRATE -y -c $expected"
4399     echo "$cmd"
4400     eval $cmd || error "$cmd failed"
4401
4402     for i in $(seq 2 $NUMFILES); do
4403         check_stripe_count $TDIR/file$i $expected
4404     done
4405     for i in $(seq 2 $NUMDIRS); do
4406         for j in $(seq 1 $NUMFILES); do
4407             check_stripe_count $TDIR/dir$i/file$j $expected
4408         done
4409     done
4410 }
4411 run_test 56w "check lfs_migrate -c stripe_count works"
4412
4413 test_56x() {
4414         check_swap_layouts_support && return 0
4415         [ "$OSTCOUNT" -lt "2" ] &&
4416                 skip_env "need 2 OST, skipping test" && return
4417
4418         local dir0=$DIR/$tdir/$testnum
4419         mkdir -p $dir0 || error "creating dir $dir0"
4420
4421         local ref1=/etc/passwd
4422         local file1=$dir0/file1
4423
4424         $SETSTRIPE -c 2 $file1
4425         cp $ref1 $file1
4426         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4427         stripe=$($GETSTRIPE -c $file1)
4428         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4429         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4430
4431         # clean up
4432         rm -f $file1
4433 }
4434 run_test 56x "lfs migration support"
4435
4436 test_57a() {
4437         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4438         # note test will not do anything if MDS is not local
4439         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4440                 skip "Only applicable to ldiskfs-based MDTs"
4441                 return
4442         fi
4443
4444         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4445         local MNTDEV="osd*.*MDT*.mntdev"
4446         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4447         [ -z "$DEV" ] && error "can't access $MNTDEV"
4448         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4449                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4450                         error "can't access $DEV"
4451                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
4452                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
4453                 rm $TMP/t57a.dump
4454         done
4455 }
4456 run_test 57a "verify MDS filesystem created with large inodes =="
4457
4458 test_57b() {
4459         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4460         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4461                 skip "Only applicable to ldiskfs-based MDTs"
4462                 return
4463         fi
4464
4465         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4466         local dir=$DIR/d57b
4467
4468         local FILECOUNT=100
4469         local FILE1=$dir/f1
4470         local FILEN=$dir/f$FILECOUNT
4471
4472         rm -rf $dir || error "removing $dir"
4473         test_mkdir -p $dir || error "creating $dir"
4474         local num=$(get_mds_dir $dir)
4475         local mymds=mds$num
4476
4477         echo "mcreating $FILECOUNT files"
4478         createmany -m $dir/f 1 $FILECOUNT || \
4479                 error "creating files in $dir"
4480
4481         # verify that files do not have EAs yet
4482         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4483         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4484
4485         sync
4486         sleep 1
4487         df $dir  #make sure we get new statfs data
4488         local MDSFREE=$(do_facet $mymds \
4489                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4490         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4491         echo "opening files to create objects/EAs"
4492         local FILE
4493         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4494                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4495         done
4496
4497         # verify that files have EAs now
4498         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4499         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4500
4501         sleep 1  #make sure we get new statfs data
4502         df $dir
4503         local MDSFREE2=$(do_facet $mymds \
4504                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4505         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4506         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
4507                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4508                         error "MDC before $MDCFREE != after $MDCFREE2"
4509                 else
4510                         echo "MDC before $MDCFREE != after $MDCFREE2"
4511                         echo "unable to confirm if MDS has large inodes"
4512                 fi
4513         fi
4514         rm -rf $dir
4515 }
4516 run_test 57b "default LOV EAs are stored inside large inodes ==="
4517
4518 test_58() {
4519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4520         [ -z "$(which wiretest 2>/dev/null)" ] &&
4521                         skip_env "could not find wiretest" && return
4522         wiretest
4523 }
4524 run_test 58 "verify cross-platform wire constants =============="
4525
4526 test_59() {
4527         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4528         echo "touch 130 files"
4529         createmany -o $DIR/f59- 130
4530         echo "rm 130 files"
4531         unlinkmany $DIR/f59- 130
4532         sync
4533         # wait for commitment of removal
4534         wait_delete_completed
4535 }
4536 run_test 59 "verify cancellation of llog records async ========="
4537
4538 TEST60_HEAD="test_60 run $RANDOM"
4539 test_60a() {
4540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4541         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4542         [ ! -f run-llog.sh ] && skip_env "missing subtest run-llog.sh" && return
4543         log "$TEST60_HEAD - from kernel mode"
4544         do_facet mgs sh run-llog.sh
4545 }
4546 run_test 60a "llog sanity tests run from kernel module =========="
4547
4548 test_60b() { # bug 6411
4549         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4550         dmesg > $DIR/$tfile
4551         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4552                                  /llog.test/ {
4553                                          if (marker)
4554                                                  from_marker++
4555                                          from_begin++
4556                                  }
4557                                  END {
4558                                          if (marker)
4559                                                  print from_marker
4560                                          else
4561                                                  print from_begin
4562                                  }"`
4563         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
4564 }
4565 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4566
4567 test_60c() {
4568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4569         echo "create 5000 files"
4570         createmany -o $DIR/f60c- 5000
4571 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4572         lctl set_param fail_loc=0x80000137
4573         unlinkmany $DIR/f60c- 5000
4574         lctl set_param fail_loc=0
4575 }
4576 run_test 60c "unlink file when mds full"
4577
4578 test_60d() {
4579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4580         SAVEPRINTK=$(lctl get_param -n printk)
4581
4582         # verify "lctl mark" is even working"
4583         MESSAGE="test message ID $RANDOM $$"
4584         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4585         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4586
4587         lctl set_param printk=0 || error "set lnet.printk failed"
4588         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4589         MESSAGE="new test message ID $RANDOM $$"
4590         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4591         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4592         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4593
4594         lctl set_param -n printk="$SAVEPRINTK"
4595 }
4596 run_test 60d "test printk console message masking"
4597
4598 test_61() {
4599         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4600         f="$DIR/f61"
4601         dd if=/dev/zero of=$f bs=`page_size` count=1
4602         cancel_lru_locks osc
4603         $MULTIOP $f OSMWUc || error
4604         sync
4605 }
4606 run_test 61 "mmap() writes don't make sync hang ================"
4607
4608 # bug 2330 - insufficient obd_match error checking causes LBUG
4609 test_62() {
4610         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4611         f="$DIR/f62"
4612         echo foo > $f
4613         cancel_lru_locks osc
4614         lctl set_param fail_loc=0x405
4615         cat $f && error "cat succeeded, expect -EIO"
4616         lctl set_param fail_loc=0
4617 }
4618 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4619 # match every page all of the time.
4620 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4621
4622 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4623 test_63a() {    # was test_63
4624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4625         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4626         lctl set_param -n osc.*.max_dirty_mb 0
4627         for i in `seq 10` ; do
4628                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4629                 sleep 5
4630                 kill $!
4631                 sleep 1
4632         done
4633
4634         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
4635         rm -f $DIR/f63 || true
4636 }
4637 run_test 63a "Verify oig_wait interruption does not crash ======="
4638
4639 # bug 2248 - async write errors didn't return to application on sync
4640 # bug 3677 - async write errors left page locked
4641 test_63b() {
4642         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4643         debugsave
4644         lctl set_param debug=-1
4645
4646         # ensure we have a grant to do async writes
4647         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4648         rm $DIR/$tfile
4649
4650         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4651         lctl set_param fail_loc=0x80000406
4652         $MULTIOP $DIR/$tfile Owy && \
4653                 error "sync didn't return ENOMEM"
4654         sync; sleep 2; sync     # do a real sync this time to flush page
4655         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4656                 error "locked page left in cache after async error" || true
4657         debugrestore
4658 }
4659 run_test 63b "async write errors should be returned to fsync ==="
4660
4661 test_64a () {
4662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4663         df $DIR
4664         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4665 }
4666 run_test 64a "verify filter grant calculations (in kernel) ====="
4667
4668 test_64b () {
4669         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4670         [ ! -f oos.sh ] && skip_env "missing subtest oos.sh" && return
4671         sh oos.sh $MOUNT
4672 }
4673 run_test 64b "check out-of-space detection on client ==========="
4674
4675 test_64c() {
4676         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
4677 }
4678 run_test 64c "verify grant shrink ========================------"
4679
4680 # bug 1414 - set/get directories' stripe info
4681 test_65a() {
4682         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4683         test_mkdir -p $DIR/$tdir
4684         touch $DIR/$tdir/f1
4685         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
4686 }
4687 run_test 65a "directory with no stripe info ===================="
4688
4689 test_65b() {
4690         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4691         test_mkdir -p $DIR/$tdir
4692         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4693                                                 error "setstripe"
4694         touch $DIR/$tdir/f2
4695         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
4696 }
4697 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4698
4699 test_65c() {
4700         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4701         if [ $OSTCOUNT -gt 1 ]; then
4702                 test_mkdir -p $DIR/$tdir
4703                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4704                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
4705                 touch $DIR/$tdir/f3
4706                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
4707         fi
4708 }
4709 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4710
4711 test_65d() {
4712         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4713         test_mkdir -p $DIR/$tdir
4714         if [ $STRIPECOUNT -le 0 ]; then
4715                 sc=1
4716         elif [ $STRIPECOUNT -gt 2000 ]; then
4717 #LOV_MAX_STRIPE_COUNT is 2000
4718                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
4719         else
4720                 sc=$(($STRIPECOUNT - 1))
4721         fi
4722         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
4723         touch $DIR/$tdir/f4 $DIR/$tdir/f5
4724         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
4725                                                 error "lverify failed"
4726 }
4727 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
4728
4729 test_65e() {
4730         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4731         test_mkdir -p $DIR/$tdir
4732
4733         $SETSTRIPE $DIR/$tdir || error "setstripe"
4734         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
4735                                         error "no stripe info failed"
4736         touch $DIR/$tdir/f6
4737         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
4738 }
4739 run_test 65e "directory setstripe defaults ======================="
4740
4741 test_65f() {
4742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4743         test_mkdir -p $DIR/${tdir}f
4744         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
4745 }
4746 run_test 65f "dir setstripe permission (should return error) ==="
4747
4748 test_65g() {
4749         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4750         test_mkdir -p $DIR/$tdir
4751         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4752                                                         error "setstripe"
4753         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
4754         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
4755                 error "delete default stripe failed"
4756 }
4757 run_test 65g "directory setstripe -d ==========================="
4758
4759 test_65h() {
4760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4761         test_mkdir -p $DIR/$tdir
4762         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4763                                                         error "setstripe"
4764         test_mkdir -p $DIR/$tdir/dd1
4765         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
4766                 error "stripe info inherit failed"
4767 }
4768 run_test 65h "directory stripe info inherit ===================="
4769
4770 test_65i() { # bug6367
4771         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4772         $SETSTRIPE -S 65536 -c -1 $MOUNT
4773 }
4774 run_test 65i "set non-default striping on root directory (bug 6367)="
4775
4776 test_65ia() { # bug12836
4777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4778         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
4779 }
4780 run_test 65ia "getstripe on -1 default directory striping"
4781
4782 test_65ib() { # bug12836
4783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4784         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
4785 }
4786 run_test 65ib "getstripe -v on -1 default directory striping"
4787
4788 test_65ic() { # bug12836
4789         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4790         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
4791 }
4792 run_test 65ic "new find on -1 default directory striping"
4793
4794 test_65j() { # bug6367
4795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4796         sync; sleep 1
4797         # if we aren't already remounting for each test, do so for this test
4798         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
4799                 cleanup || error "failed to unmount"
4800                 setup
4801         fi
4802         $SETSTRIPE -d $MOUNT || error "setstripe failed"
4803 }
4804 run_test 65j "set default striping on root directory (bug 6367)="
4805
4806 test_65k() { # bug11679
4807         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4808         [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
4809         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4810
4811     echo "Check OST status: "
4812     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
4813               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
4814
4815     for OSC in $MDS_OSCS; do
4816         echo $OSC "is activate"
4817         do_facet $SINGLEMDS lctl --device %$OSC activate
4818     done
4819
4820     mkdir -p $DIR/$tdir
4821     for INACTIVE_OSC in $MDS_OSCS; do
4822         echo "Deactivate: " $INACTIVE_OSC
4823         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
4824         for STRIPE_OSC in $MDS_OSCS; do
4825             OST=`osc_to_ost $STRIPE_OSC`
4826             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
4827                  awk -F: /$OST/'{ print $1 }' | head -n 1`
4828
4829             [ -f $DIR/$tdir/$IDX ] && continue
4830             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
4831             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
4832             RC=$?
4833             [ $RC -ne 0 ] && error "setstripe should have succeeded"
4834         done
4835         rm -f $DIR/$tdir/*
4836         echo $INACTIVE_OSC "is Activate."
4837         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
4838     done
4839 }
4840 run_test 65k "validate manual striping works properly with deactivated OSCs"
4841
4842 test_65l() { # bug 12836
4843         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4844         test_mkdir -p $DIR/$tdir/test_dir
4845         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
4846         $LFS find -mtime -1 $DIR/$tdir >/dev/null
4847 }
4848 run_test 65l "lfs find on -1 stripe dir ========================"
4849
4850 # bug 2543 - update blocks count on client
4851 test_66() {
4852         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4853         COUNT=${COUNT:-8}
4854         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
4855         sync; sync_all_data; sync; sync_all_data
4856         cancel_lru_locks osc
4857         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
4858         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
4859 }
4860 run_test 66 "update inode blocks count on client ==============="
4861
4862 LLOOP=
4863 LLITELOOPLOAD=
4864 cleanup_68() {
4865         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4866         trap 0
4867         if [ ! -z "$LLOOP" ]; then
4868                 if swapon -s | grep -q $LLOOP; then
4869                         swapoff $LLOOP || error "swapoff failed"
4870                 fi
4871
4872                 $LCTL blockdev_detach $LLOOP || error "detach failed"
4873                 rm -f $LLOOP
4874                 unset LLOOP
4875         fi
4876         if [ ! -z "$LLITELOOPLOAD" ]; then
4877                 rmmod llite_lloop
4878                 unset LLITELOOPLOAD
4879         fi
4880         rm -f $DIR/f68*
4881 }
4882
4883 meminfo() {
4884         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
4885 }
4886
4887 swap_used() {
4888         swapon -s | awk '($1 == "'$1'") { print $4 }'
4889 }
4890
4891 # test case for lloop driver, basic function
4892 test_68a() {
4893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4894         [ "$UID" != 0 ] && skip_env "must run as root" && return
4895         llite_lloop_enabled || \
4896                 { skip_env "llite_lloop module disabled" && return; }
4897
4898         trap cleanup_68 EXIT
4899
4900         if ! module_loaded llite_lloop; then
4901                 if load_module llite/llite_lloop; then
4902                         LLITELOOPLOAD=yes
4903                 else
4904                         skip_env "can't find module llite_lloop"
4905                         return
4906                 fi
4907         fi
4908
4909         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4910         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
4911         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
4912
4913         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
4914         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
4915
4916         cleanup_68
4917 }
4918 run_test 68a "lloop driver - basic test ========================"
4919
4920 # excercise swapping to lustre by adding a high priority swapfile entry
4921 # and then consuming memory until it is used.
4922 test_68b() {  # was test_68
4923         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4924         [ "$UID" != 0 ] && skip_env "must run as root" && return
4925         lctl get_param -n devices | grep -q obdfilter && \
4926                 skip "local OST" && return
4927
4928         grep -q llite_lloop /proc/modules
4929         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
4930
4931         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
4932                 skip "can't reliably test swap with TCP" && return
4933
4934         MEMTOTAL=`meminfo MemTotal`
4935         NR_BLOCKS=$((MEMTOTAL>>8))
4936         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
4937
4938         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4939         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
4940         mkswap $DIR/f68b
4941
4942         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
4943
4944         trap cleanup_68 EXIT
4945
4946         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
4947
4948         echo "before: `swapon -s | grep $LLOOP`"
4949         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
4950         echo "after: `swapon -s | grep $LLOOP`"
4951         SWAPUSED=`swap_used $LLOOP`
4952
4953         cleanup_68
4954
4955         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
4956 }
4957 run_test 68b "support swapping to Lustre ========================"
4958
4959 # bug5265, obdfilter oa2dentry return -ENOENT
4960 # #define OBD_FAIL_OST_ENOENT 0x217
4961 test_69() {
4962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4963         remote_ost_nodsh && skip "remote OST with nodsh" && return
4964
4965         f="$DIR/$tfile"
4966         $SETSTRIPE -c 1 -i 0 $f
4967
4968         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
4969
4970         do_facet ost1 lctl set_param fail_loc=0x217
4971         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
4972         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
4973
4974         do_facet ost1 lctl set_param fail_loc=0
4975         $DIRECTIO write $f 0 2 || error "write error"
4976
4977         cancel_lru_locks osc
4978         $DIRECTIO read $f 0 1 || error "read error"
4979
4980         do_facet ost1 lctl set_param fail_loc=0x217
4981         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
4982
4983         do_facet ost1 lctl set_param fail_loc=0
4984         rm -f $f
4985 }
4986 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
4987
4988 test_71() {
4989     test_mkdir -p $DIR/$tdir
4990     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
4991 }
4992 run_test 71 "Running dbench on lustre (don't segment fault) ===="
4993
4994 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
4995         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4996         check_kernel_version 43 || return 0
4997         [ "$RUNAS_ID" = "$UID" ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4998
4999         # Check that testing environment is properly set up. Skip if not
5000         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5001                 skip_env "User $RUNAS_ID does not exist - skipping"
5002                 return 0
5003         }
5004         # We had better clear the $DIR to get enough space for dd
5005         rm -rf $DIR/*
5006         touch $DIR/f72
5007         chmod 777 $DIR/f72
5008         chmod ug+s $DIR/f72
5009         $RUNAS dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
5010         # See if we are still setuid/sgid
5011         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
5012         # Now test that MDS is updated too
5013         cancel_lru_locks mdc
5014         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
5015         rm -f $DIR/f72
5016 }
5017 run_test 72a "Test that remove suid works properly (bug5695) ===="
5018
5019 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5020         local perm
5021
5022         [ "$RUNAS_ID" = "$UID" ] && \
5023                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5024         [ "$RUNAS_ID" -eq 0 ] && \
5025                 skip_env "RUNAS_ID = 0 -- skipping" && return
5026
5027         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5028         # Check that testing environment is properly set up. Skip if not
5029         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5030                 skip_env "User $RUNAS_ID does not exist - skipping"
5031                 return 0
5032         }
5033         touch $DIR/${tfile}-f{g,u}
5034         test_mkdir $DIR/${tfile}-dg
5035         test_mkdir $DIR/${tfile}-du
5036         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5037         chmod g+s $DIR/${tfile}-{f,d}g
5038         chmod u+s $DIR/${tfile}-{f,d}u
5039         for perm in 777 2777 4777; do
5040                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5041                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5042                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5043                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5044         done
5045         true
5046 }
5047 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5048
5049 # bug 3462 - multiple simultaneous MDC requests
5050 test_73() {
5051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5052         test_mkdir $DIR/d73-1
5053         test_mkdir $DIR/d73-2
5054         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5055         pid1=$!
5056
5057         lctl set_param fail_loc=0x80000129
5058         $MULTIOP $DIR/d73-1/f73-2 Oc &
5059         sleep 1
5060         lctl set_param fail_loc=0
5061
5062         $MULTIOP $DIR/d73-2/f73-3 Oc &
5063         pid3=$!
5064
5065         kill -USR1 $pid1
5066         wait $pid1 || return 1
5067
5068         sleep 25
5069
5070         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5071         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5072         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5073
5074         rm -rf $DIR/d73-*
5075 }
5076 run_test 73 "multiple MDC requests (should not deadlock)"
5077
5078 test_74a() { # bug 6149, 6184
5079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5080         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5081         #
5082         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5083         # will spin in a tight reconnection loop
5084         touch $DIR/f74a
5085         lctl set_param fail_loc=0x8000030e
5086         # get any lock that won't be difficult - lookup works.
5087         ls $DIR/f74a
5088         lctl set_param fail_loc=0
5089         true
5090         rm -f $DIR/f74a
5091 }
5092 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5093
5094 test_74b() { # bug 13310
5095         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5096         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5097         #
5098         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5099         # will spin in a tight reconnection loop
5100         lctl set_param fail_loc=0x8000030e
5101         # get a "difficult" lock
5102         touch $DIR/f74b
5103         lctl set_param fail_loc=0
5104         true
5105         rm -f $DIR/f74b
5106 }
5107 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5108
5109 test_74c() {
5110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5111 #define OBD_FAIL_LDLM_NEW_LOCK
5112         lctl set_param fail_loc=0x80000319
5113         touch $DIR/$tfile && error "Touch successful"
5114         true
5115 }
5116 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5117
5118 num_inodes() {
5119         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5120 }
5121
5122 get_inode_slab_tunables() {
5123         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5124 }
5125
5126 set_inode_slab_tunables() {
5127         echo "lustre_inode_cache $1" > /proc/slabinfo
5128 }
5129
5130 test_76() { # Now for bug 20433, added originally in bug 1443
5131         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5132         local SLAB_SETTINGS=`get_inode_slab_tunables`
5133         local CPUS=`getconf _NPROCESSORS_ONLN`
5134         # we cannot set limit below 1 which means 1 inode in each
5135         # per-cpu cache is still allowed
5136         set_inode_slab_tunables "1 1 0"
5137         cancel_lru_locks osc
5138         BEFORE_INODES=`num_inodes`
5139         echo "before inodes: $BEFORE_INODES"
5140         local COUNT=1000
5141         [ "$SLOW" = "no" ] && COUNT=100
5142         for i in `seq $COUNT`; do
5143                 touch $DIR/$tfile
5144                 rm -f $DIR/$tfile
5145         done
5146         cancel_lru_locks osc
5147         AFTER_INODES=`num_inodes`
5148         echo "after inodes: $AFTER_INODES"
5149         local wait=0
5150         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
5151                 sleep 2
5152                 AFTER_INODES=`num_inodes`
5153                 wait=$((wait+2))
5154                 echo "wait $wait seconds inodes: $AFTER_INODES"
5155                 if [ $wait -gt 30 ]; then
5156                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5157                 fi
5158         done
5159         set_inode_slab_tunables "$SLAB_SETTINGS"
5160 }
5161 run_test 76 "confirm clients recycle inodes properly ===="
5162
5163
5164 export ORIG_CSUM=""
5165 set_checksums()
5166 {
5167         # Note: in sptlrpc modes which enable its own bulk checksum, the
5168         # original crc32_le bulk checksum will be automatically disabled,
5169         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5170         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5171         # In this case set_checksums() will not be no-op, because sptlrpc
5172         # bulk checksum will be enabled all through the test.
5173
5174         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5175         lctl set_param -n osc.*.checksums $1
5176         return 0
5177 }
5178
5179 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5180                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5181 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5182 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5183 set_checksum_type()
5184 {
5185         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5186         log "set checksum type to $1"
5187         return 0
5188 }
5189 F77_TMP=$TMP/f77-temp
5190 F77SZ=8
5191 setup_f77() {
5192         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5193                 error "error writing to $F77_TMP"
5194 }
5195
5196 test_77a() { # bug 10889
5197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5198         $GSS && skip "could not run with gss" && return
5199         [ ! -f $F77_TMP ] && setup_f77
5200         set_checksums 1
5201         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5202         set_checksums 0
5203         rm -f $DIR/$tfile
5204 }
5205 run_test 77a "normal checksum read/write operation ============="
5206
5207 test_77b() { # bug 10889
5208         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5209         $GSS && skip "could not run with gss" && return
5210         [ ! -f $F77_TMP ] && setup_f77
5211         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5212         lctl set_param fail_loc=0x80000409
5213         set_checksums 1
5214         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
5215                 error "dd error: $?"
5216         lctl set_param fail_loc=0
5217         set_checksums 0
5218 }
5219 run_test 77b "checksum error on client write ===================="
5220
5221 test_77c() { # bug 10889
5222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5223         $GSS && skip "could not run with gss" && return
5224         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
5225         set_checksums 1
5226         for algo in $CKSUM_TYPES; do
5227                 cancel_lru_locks osc
5228                 set_checksum_type $algo
5229                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5230                 lctl set_param fail_loc=0x80000408
5231                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
5232                 lctl set_param fail_loc=0
5233         done
5234         set_checksums 0
5235         set_checksum_type $ORIG_CSUM_TYPE
5236         rm -f $DIR/f77b
5237 }
5238 run_test 77c "checksum error on client read ==================="
5239
5240 test_77d() { # bug 10889
5241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5242         $GSS && skip "could not run with gss" && return
5243         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5244         lctl set_param fail_loc=0x80000409
5245         set_checksums 1
5246         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
5247                 error "direct write: rc=$?"
5248         lctl set_param fail_loc=0
5249         set_checksums 0
5250 }
5251 run_test 77d "checksum error on OST direct write ==============="
5252
5253 test_77e() { # bug 10889
5254         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5255         $GSS && skip "could not run with gss" && return
5256         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
5257         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5258         lctl set_param fail_loc=0x80000408
5259         set_checksums 1
5260         cancel_lru_locks osc
5261         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
5262                 error "direct read: rc=$?"
5263         lctl set_param fail_loc=0
5264         set_checksums 0
5265 }
5266 run_test 77e "checksum error on OST direct read ================"
5267
5268 test_77f() { # bug 10889
5269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5270         $GSS && skip "could not run with gss" && return
5271         set_checksums 1
5272         for algo in $CKSUM_TYPES; do
5273                 cancel_lru_locks osc
5274                 set_checksum_type $algo
5275                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5276                 lctl set_param fail_loc=0x409
5277                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
5278                         error "direct write succeeded"
5279                 lctl set_param fail_loc=0
5280         done
5281         set_checksum_type $ORIG_CSUM_TYPE
5282         set_checksums 0
5283 }
5284 run_test 77f "repeat checksum error on write (expect error) ===="
5285
5286 test_77g() { # bug 10889
5287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5288         $GSS && skip "could not run with gss" && return
5289         remote_ost_nodsh && skip "remote OST with nodsh" && return
5290
5291         [ ! -f $F77_TMP ] && setup_f77
5292
5293         $SETSTRIPE -c 1 -i 0 $DIR/f77g
5294         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5295         do_facet ost1 lctl set_param fail_loc=0x8000021a
5296         set_checksums 1
5297         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
5298                 error "write error: rc=$?"
5299         do_facet ost1 lctl set_param fail_loc=0
5300         set_checksums 0
5301 }
5302 run_test 77g "checksum error on OST write ======================"
5303
5304 test_77h() { # bug 10889
5305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5306         $GSS && skip "could not run with gss" && return
5307         remote_ost_nodsh && skip "remote OST with nodsh" && return
5308
5309         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
5310         cancel_lru_locks osc
5311         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5312         do_facet ost1 lctl set_param fail_loc=0x8000021b
5313         set_checksums 1
5314         cmp $F77_TMP $DIR/f77g || error "file compare failed"
5315         do_facet ost1 lctl set_param fail_loc=0
5316         set_checksums 0
5317 }
5318 run_test 77h "checksum error on OST read ======================="
5319
5320 test_77i() { # bug 13805
5321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5322         $GSS && skip "could not run with gss" && return
5323         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5324         lctl set_param fail_loc=0x40b
5325         remount_client $MOUNT
5326         lctl set_param fail_loc=0
5327         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5328                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5329                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5330                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5331         done
5332         remount_client $MOUNT
5333 }
5334 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
5335
5336 test_77j() { # bug 13805
5337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5338         $GSS && skip "could not run with gss" && return
5339         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5340         lctl set_param fail_loc=0x40c
5341         remount_client $MOUNT
5342         lctl set_param fail_loc=0
5343         sleep 2 # wait async osc connect to finish
5344         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5345                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5346                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5347                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5348         done
5349         remount_client $MOUNT
5350 }
5351 run_test 77j "client only supporting ADLER32 ===================="
5352
5353 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5354 rm -f $F77_TMP
5355 unset F77_TMP
5356
5357 test_78() { # bug 10901
5358         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5359         remote_ost || { skip_env "local OST" && return; }
5360
5361         NSEQ=5
5362         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5363         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5364         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5365         echo "MemTotal: $MEMTOTAL"
5366 # reserve 256MB of memory for the kernel and other running processes,
5367 # and then take 1/2 of the remaining memory for the read/write buffers.
5368     if [ $MEMTOTAL -gt 512 ] ;then
5369         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5370     else
5371         # for those poor memory-starved high-end clusters...
5372         MEMTOTAL=$((MEMTOTAL / 2))
5373     fi
5374         echo "Mem to use for directio: $MEMTOTAL"
5375         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
5376         [ $F78SIZE -gt 512 ] && F78SIZE=512
5377         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
5378         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
5379         echo "Smallest OST: $SMALLESTOST"
5380         [ $SMALLESTOST -lt 10240 ] && \
5381                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5382
5383         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
5384                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5385
5386         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5387         echo "File size: $F78SIZE"
5388         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5389         for i in `seq 1 $NSEQ`
5390         do
5391                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5392                 echo directIO rdwr round $i of $NSEQ
5393                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5394         done
5395
5396         rm -f $DIR/$tfile
5397 }
5398 run_test 78 "handle large O_DIRECT writes correctly ============"
5399
5400 test_79() { # bug 12743
5401         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5402         wait_delete_completed
5403
5404         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5405         BKFREE=$(calc_osc_kbytes kbytesfree)
5406         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5407
5408         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5409         DFTOTAL=`echo $STRING | cut -d, -f1`
5410         DFUSED=`echo $STRING  | cut -d, -f2`
5411         DFAVAIL=`echo $STRING | cut -d, -f3`
5412         DFFREE=$(($DFTOTAL - $DFUSED))
5413
5414         ALLOWANCE=$((64 * $OSTCOUNT))
5415
5416         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5417            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5418                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5419         fi
5420         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5421            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5422                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5423         fi
5424         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5425            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5426                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5427         fi
5428 }
5429 run_test 79 "df report consistency check ======================="
5430
5431 test_80() { # bug 10718
5432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5433         # relax strong synchronous semantics for slow backends like ZFS
5434         local soc="obdfilter.*.sync_on_lock_cancel"
5435         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5436         local hosts=
5437         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5438                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5439                           facet_active_host $host; done | sort -u)
5440                 do_nodes $hosts lctl set_param $soc=never
5441         fi
5442
5443         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5444         sync; sleep 1; sync
5445         local BEFORE=`date +%s`
5446         cancel_lru_locks osc
5447         local AFTER=`date +%s`
5448         local DIFF=$((AFTER-BEFORE))
5449         if [ $DIFF -gt 1 ] ; then
5450                 error "elapsed for 1M@1T = $DIFF"
5451         fi
5452
5453         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5454
5455         rm -f $DIR/$tfile
5456 }
5457 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5458
5459 test_81a() { # LU-456
5460         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5461         remote_ost_nodsh && skip "remote OST with nodsh" && return
5462         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5463         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5464         do_facet ost1 lctl set_param fail_loc=0x80000228
5465
5466         # write should trigger a retry and success
5467         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5468         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5469         RC=$?
5470         if [ $RC -ne 0 ] ; then
5471                 error "write should success, but failed for $RC"
5472         fi
5473 }
5474 run_test 81a "OST should retry write when get -ENOSPC ==============="
5475
5476 test_81b() { # LU-456
5477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5478         remote_ost_nodsh && skip "remote OST with nodsh" && return
5479         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5480         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5481         do_facet ost1 lctl set_param fail_loc=0x228
5482
5483         # write should retry several times and return -ENOSPC finally
5484         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5485         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5486         RC=$?
5487         ENOSPC=28
5488         if [ $RC -ne $ENOSPC ] ; then
5489                 error "dd should fail for -ENOSPC, but succeed."
5490         fi
5491 }
5492 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5493
5494 test_82() { # LU-1031
5495         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5496         local gid1=14091995
5497         local gid2=16022000
5498
5499         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5500         local MULTIPID1=$!
5501         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5502         local MULTIPID2=$!
5503         kill -USR1 $MULTIPID2
5504         sleep 2
5505         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5506                 error "First grouplock does not block second one"
5507         else
5508                 echo "Second grouplock blocks first one"
5509         fi
5510         kill -USR1 $MULTIPID1
5511         wait $MULTIPID1
5512         wait $MULTIPID2
5513 }
5514 run_test 82 "Basic grouplock test ==============================="
5515
5516 test_99a() {
5517         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && \
5518             return
5519         test_mkdir -p $DIR/d99cvsroot
5520         chown $RUNAS_ID $DIR/d99cvsroot
5521         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5522         cd $TMP
5523
5524         $RUNAS cvs -d $DIR/d99cvsroot init || error
5525         cd $oldPWD
5526 }
5527 run_test 99a "cvs init ========================================="
5528
5529 test_99b() {
5530         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5531         [ ! -d $DIR/d99cvsroot ] && test_99a
5532         cd /etc/init.d
5533         # some versions of cvs import exit(1) when asked to import links or
5534         # files they can't read.  ignore those files.
5535         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5536                         ! -perm +4 -printf '-I %f\n')
5537         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5538                 d99reposname vtag rtag
5539 }
5540 run_test 99b "cvs import ======================================="
5541
5542 test_99c() {
5543         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5544         [ ! -d $DIR/d99cvsroot ] && test_99b
5545         cd $DIR
5546         test_mkdir -p $DIR/d99reposname
5547         chown $RUNAS_ID $DIR/d99reposname
5548         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5549 }
5550 run_test 99c "cvs checkout ====================================="
5551
5552 test_99d() {
5553         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5554         [ ! -d $DIR/d99cvsroot ] && test_99c
5555         cd $DIR/d99reposname
5556         $RUNAS touch foo99
5557         $RUNAS cvs add -m 'addmsg' foo99
5558 }
5559 run_test 99d "cvs add =========================================="
5560
5561 test_99e() {
5562         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5563         [ ! -d $DIR/d99cvsroot ] && test_99c
5564         cd $DIR/d99reposname
5565         $RUNAS cvs update
5566 }
5567 run_test 99e "cvs update ======================================="
5568
5569 test_99f() {
5570         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5571         [ ! -d $DIR/d99cvsroot ] && test_99d
5572         cd $DIR/d99reposname
5573         $RUNAS cvs commit -m 'nomsg' foo99
5574     rm -fr $DIR/d99cvsroot
5575 }
5576 run_test 99f "cvs commit ======================================="
5577
5578 test_100() {
5579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5580         [ "$NETTYPE" = tcp ] || \
5581                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5582                         return ; }
5583
5584         remote_ost_nodsh && skip "remote OST with nodsh" && return
5585         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5586         remote_servers || \
5587                 { skip "useless for local single node setup" && return; }
5588
5589         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5590                 [ "$PROT" != "tcp" ] && continue
5591                 RPORT=$(echo $REMOTE | cut -d: -f2)
5592                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5593
5594                 rc=0
5595                 LPORT=`echo $LOCAL | cut -d: -f2`
5596                 if [ $LPORT -ge 1024 ]; then
5597                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5598                         netstat -tna
5599                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5600                 fi
5601         done
5602         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5603 }
5604 run_test 100 "check local port using privileged port ==========="
5605
5606 function get_named_value()
5607 {
5608     local tag
5609
5610     tag=$1
5611     while read ;do
5612         line=$REPLY
5613         case $line in
5614         $tag*)
5615             echo $line | sed "s/^$tag[ ]*//"
5616             break
5617             ;;
5618         esac
5619     done
5620 }
5621
5622 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
5623                    awk '/^max_cached_mb/ { print $2 }')
5624
5625 cleanup_101a() {
5626         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5627         trap 0
5628 }
5629
5630 test_101a() {
5631         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5632         local s
5633         local discard
5634         local nreads=10000
5635         local cache_limit=32
5636
5637         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5638         trap cleanup_101a EXIT
5639         $LCTL set_param -n llite.*.read_ahead_stats 0
5640         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5641
5642         #
5643         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5644         #
5645         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5646         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5647
5648         discard=0
5649         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
5650                 get_named_value 'read but discarded' | cut -d" " -f1`; do
5651                         discard=$(($discard + $s))
5652         done
5653         cleanup_101a
5654
5655         if [ $(($discard * 10)) -gt $nreads ] ;then
5656                 $LCTL get_param osc.*-osc*.rpc_stats
5657                 $LCTL get_param llite.*.read_ahead_stats
5658                 error "too many ($discard) discarded pages"
5659         fi
5660         rm -f $DIR/$tfile || true
5661 }
5662 run_test 101a "check read-ahead for random reads ================"
5663
5664 setup_test101bc() {
5665         test_mkdir -p $DIR/$tdir
5666         STRIPE_SIZE=1048576
5667         STRIPE_COUNT=$OSTCOUNT
5668         STRIPE_OFFSET=0
5669
5670         local list=$(comma_list $(osts_nodes))
5671         set_osd_param $list '' read_cache_enable 0
5672         set_osd_param $list '' writethrough_cache_enable 0
5673
5674         trap cleanup_test101bc EXIT
5675         # prepare the read-ahead file
5676         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5677
5678         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
5679 }
5680
5681 cleanup_test101bc() {
5682         trap 0
5683         rm -rf $DIR/$tdir
5684         rm -f $DIR/$tfile
5685
5686         local list=$(comma_list $(osts_nodes))
5687         set_osd_param $list '' read_cache_enable 1
5688         set_osd_param $list '' writethrough_cache_enable 1
5689 }
5690
5691 calc_total() {
5692         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5693 }
5694
5695 ra_check_101() {
5696         local READ_SIZE=$1
5697         local STRIPE_SIZE=1048576
5698         local RA_INC=1048576
5699         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5700         local FILE_LENGTH=$((64*100))
5701         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5702                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5703         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5704                         get_named_value 'read but discarded' | \
5705                         cut -d" " -f1 | calc_total`
5706         if [ $DISCARD -gt $discard_limit ]; then
5707                 $LCTL get_param llite.*.read_ahead_stats
5708                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5709         else
5710                 echo "Read-ahead success for size ${READ_SIZE}"
5711         fi
5712 }
5713
5714 test_101b() {
5715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5716         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5717         local STRIPE_SIZE=1048576
5718         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5719         local FILE_LENGTH=$((STRIPE_SIZE*100))
5720         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
5721         # prepare the read-ahead file
5722         setup_test101bc
5723         cancel_lru_locks osc
5724         for BIDX in 2 4 8 16 32 64 128 256
5725         do
5726                 local BSIZE=$((BIDX*4096))
5727                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5728                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5729                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5730                 $LCTL set_param -n llite.*.read_ahead_stats 0
5731                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5732                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5733                 cancel_lru_locks osc
5734                 ra_check_101 $BSIZE
5735         done
5736         cleanup_test101bc
5737         true
5738 }
5739 run_test 101b "check stride-io mode read-ahead ================="
5740
5741 test_101c() {
5742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5743         local STRIPE_SIZE=1048576
5744         local FILE_LENGTH=$((STRIPE_SIZE*100))
5745         local nreads=10000
5746         local osc
5747
5748     setup_test101bc
5749
5750     cancel_lru_locks osc
5751     $LCTL set_param osc.*.rpc_stats 0
5752     $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
5753     for osc in $($LCTL get_param -N osc.*); do
5754         if [ "$osc" == "osc.num_refs" ]; then
5755             continue
5756         fi
5757
5758         local lines=$($LCTL get_param -n ${osc}.rpc_stats | wc | awk '{print $1}')
5759         if [ $lines -le 20 ]; then
5760             continue
5761         fi
5762
5763         local rpc4k=$($LCTL get_param -n ${osc}.rpc_stats |
5764                                      awk '$1 == "1:" { print $2; exit; }')
5765         local rpc8k=$($LCTL get_param -n ${osc}.rpc_stats |
5766                                      awk '$1 == "2:" { print $2; exit; }')
5767         local rpc16k=$($LCTL get_param -n ${osc}.rpc_stats |
5768                                      awk '$1 == "4:" { print $2; exit; }')
5769         local rpc32k=$($LCTL get_param -n ${osc}.rpc_stats |
5770                                      awk '$1 == "8:" { print $2; exit; }')
5771
5772         [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
5773         [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
5774         [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
5775         [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
5776         echo "${osc} rpc check passed!"
5777     done
5778     cleanup_test101bc
5779     true
5780 }
5781 run_test 101c "check stripe_size aligned read-ahead ================="
5782
5783 set_read_ahead() {
5784    $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
5785    $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
5786 }
5787
5788 test_101d() {
5789         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5790         local file=$DIR/$tfile
5791         local size=${FILESIZE_101c:-500}
5792         local ra_MB=${READAHEAD_MB:-40}
5793
5794         local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5795         [ $space -gt $((size * 1024)) ] ||
5796                 { skip "Need free space ${size}M, have $space" && return; }
5797
5798     echo Creating ${size}M test file $file
5799     dd if=/dev/zero of=$file bs=1M count=$size || error "dd failed"
5800     echo Cancel LRU locks on lustre client to flush the client cache
5801     cancel_lru_locks osc
5802
5803     echo Disable read-ahead
5804     local old_READAHEAD=$(set_read_ahead 0)
5805
5806     echo Reading the test file $file with read-ahead disabled
5807     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5808
5809     echo Cancel LRU locks on lustre client to flush the client cache
5810     cancel_lru_locks osc
5811     echo Enable read-ahead with ${ra_MB}MB
5812     set_read_ahead $ra_MB
5813
5814     echo Reading the test file $file with read-ahead enabled
5815     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5816
5817     echo read-ahead disabled time read $time_ra_OFF
5818     echo read-ahead enabled  time read $time_ra_ON
5819
5820         set_read_ahead $old_READAHEAD
5821         rm -f $file
5822         wait_delete_completed
5823
5824     [ $time_ra_ON -lt $time_ra_OFF ] ||
5825         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
5826                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
5827 }
5828 run_test 101d "file read with and without read-ahead enabled  ================="
5829
5830 test_101e() {
5831         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5832     local file=$DIR/$tfile
5833     local size=500  #KB
5834     local count=100
5835     local blksize=1024
5836
5837     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5838     local need_space=$((count * size))
5839     [ $space -gt $need_space ] ||
5840         { skip_env "Need free space $need_space, have $space" && return; }
5841
5842     echo Creating $count ${size}K test files
5843     for ((i = 0; i < $count; i++)); do
5844         dd if=/dev/zero of=${file}_${i} bs=$blksize count=$size 2>/dev/null
5845     done
5846
5847     echo Cancel LRU locks on lustre client to flush the client cache
5848     cancel_lru_locks osc
5849
5850     echo Reset readahead stats
5851     $LCTL set_param -n llite.*.read_ahead_stats 0
5852
5853     for ((i = 0; i < $count; i++)); do
5854         dd if=${file}_${i} of=/dev/null bs=$blksize count=$size 2>/dev/null
5855     done
5856
5857     local miss=$($LCTL get_param -n llite.*.read_ahead_stats | \
5858           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5859
5860     for ((i = 0; i < $count; i++)); do
5861         rm -rf ${file}_${i} 2>/dev/null
5862     done
5863
5864     #10000 means 20% reads are missing in readahead
5865     [ $miss -lt 10000 ] ||  error "misses too much for small reads"
5866 }
5867 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
5868
5869 cleanup_test101f() {
5870     trap 0
5871     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
5872     rm -rf $DIR/$tfile 2>/dev/null
5873 }
5874
5875 test_101f() {
5876         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5877     local file=$DIR/$tfile
5878     local nreads=1000
5879
5880     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
5881     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
5882     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
5883     trap cleanup_test101f EXIT
5884
5885     echo Cancel LRU locks on lustre client to flush the client cache
5886     cancel_lru_locks osc
5887
5888     echo Reset readahead stats
5889     $LCTL set_param -n llite.*.read_ahead_stats 0
5890     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
5891     # readahead should read in 2M file on second read, so only miss
5892     # 2 pages.
5893     echo Random 4K reads on 2M file for 1000 times
5894     $READS -f $file -s 2097152 -b 4096 -n $nreads
5895
5896     echo checking missing pages
5897     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
5898           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5899
5900     [ $miss -lt 3 ] || error "misses too much pages!"
5901     cleanup_test101f
5902 }
5903 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
5904
5905 setup_test102() {
5906         test_mkdir -p $DIR/$tdir
5907         chown $RUNAS_ID $DIR/$tdir
5908         STRIPE_SIZE=65536
5909         STRIPE_OFFSET=1
5910         STRIPE_COUNT=$OSTCOUNT
5911         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
5912
5913         trap cleanup_test102 EXIT
5914         cd $DIR
5915         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
5916         cd $DIR/$tdir
5917         for num in 1 2 3 4; do
5918                 for count in $(seq 1 $STRIPE_COUNT); do
5919                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
5920                                 local size=`expr $STRIPE_SIZE \* $num`
5921                                 local file=file"$num-$idx-$count"
5922                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
5923                         done
5924                 done
5925         done
5926
5927         cd $DIR
5928         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
5929 }
5930
5931 cleanup_test102() {
5932         trap 0
5933         rm -f $TMP/f102.tar
5934         rm -rf $DIR/d0.sanity/d102
5935 }
5936
5937 test_102a() {
5938         local testfile=$DIR/xattr_testfile
5939
5940         touch $testfile
5941
5942         [ "$UID" != 0 ] && skip_env "must run as root" && return
5943         [ -z "`lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr`" ] &&
5944                 skip_env "must have user_xattr" && return
5945
5946         [ -z "$(which setfattr 2>/dev/null)" ] &&
5947                 skip_env "could not find setfattr" && return
5948
5949         echo "set/get xattr..."
5950         setfattr -n trusted.name1 -v value1 $testfile || error
5951         getfattr -n trusted.name1 $testfile 2> /dev/null |
5952           grep "trusted.name1=.value1" ||
5953                 error "$testfile missing trusted.name1=value1"
5954
5955         setfattr -n user.author1 -v author1 $testfile || error
5956         getfattr -n user.author1 $testfile 2> /dev/null |
5957           grep "user.author1=.author1" ||
5958                 error "$testfile missing trusted.author1=author1"
5959
5960         echo "listxattr..."
5961         setfattr -n trusted.name2 -v value2 $testfile ||
5962                 error "$testfile unable to set trusted.name2"
5963         setfattr -n trusted.name3 -v value3 $testfile ||
5964                 error "$testfile unable to set trusted.name3"
5965         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
5966             grep "trusted.name" | wc -l) -eq 3 ] ||
5967                 error "$testfile missing 3 trusted.name xattrs"
5968
5969         setfattr -n user.author2 -v author2 $testfile ||
5970                 error "$testfile unable to set user.author2"
5971         setfattr -n user.author3 -v author3 $testfile ||
5972                 error "$testfile unable to set user.author3"
5973         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
5974             grep "user.author" | wc -l) -eq 3 ] ||
5975                 error "$testfile missing 3 user.author xattrs"
5976
5977         echo "remove xattr..."
5978         setfattr -x trusted.name1 $testfile ||
5979                 error "$testfile error deleting trusted.name1"
5980         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
5981                 error "$testfile did not delete trusted.name1 xattr"
5982
5983         setfattr -x user.author1 $testfile ||
5984                 error "$testfile error deleting user.author1"
5985         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
5986                 error "$testfile did not delete trusted.name1 xattr"
5987
5988         # b10667: setting lustre special xattr be silently discarded
5989         echo "set lustre special xattr ..."
5990         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
5991                 error "$testfile allowed setting trusted.lov"
5992 }
5993 run_test 102a "user xattr test =================================="
5994
5995 test_102b() {
5996         # b10930: get/set/list trusted.lov xattr
5997         echo "get/set/list trusted.lov xattr ..."
5998         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
5999         local testfile=$DIR/$tfile
6000         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6001                 error "setstripe failed"
6002         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6003                 error "getstripe failed"
6004         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
6005         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
6006
6007         local testfile2=${testfile}2
6008         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
6009                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
6010
6011         $MCREATE $testfile2
6012         setfattr -n trusted.lov -v $value $testfile2
6013         local stripe_size=$($GETSTRIPE -S $testfile2)
6014         local stripe_count=$($GETSTRIPE -c $testfile2)
6015         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6016         [ $stripe_count -eq $STRIPECOUNT ] ||
6017                 error "stripe count $stripe_count != $STRIPECOUNT"
6018         rm -f $DIR/$tfile
6019 }
6020 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6021
6022 test_102c() {
6023         # b10930: get/set/list lustre.lov xattr
6024         echo "get/set/list lustre.lov xattr ..."
6025         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6026         test_mkdir -p $DIR/$tdir
6027         chown $RUNAS_ID $DIR/$tdir
6028         local testfile=$DIR/$tdir/$tfile
6029         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6030                 error "setstripe failed"
6031         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6032                 error "getstripe failed"
6033         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6034         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6035
6036         local testfile2=${testfile}2
6037         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6038                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6039
6040         $RUNAS $MCREATE $testfile2
6041         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6042         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6043         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6044         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6045         [ $stripe_count -eq $STRIPECOUNT ] ||
6046                 error "stripe count $stripe_count != $STRIPECOUNT"
6047 }
6048 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6049
6050 compare_stripe_info1() {
6051         local stripe_index_all_zero=true
6052
6053         for num in 1 2 3 4; do
6054                 for count in $(seq 1 $STRIPE_COUNT); do
6055                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6056                                 local size=$((STRIPE_SIZE * num))
6057                                 local file=file"$num-$offset-$count"
6058                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6059                                 [ $stripe_size -ne $size ] &&
6060                                     error "$file: size $stripe_size != $size"
6061                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6062                                 # allow fewer stripes to be created, ORI-601
6063                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
6064                                     error "$file: count $stripe_count != $count"
6065                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6066                                 [ $stripe_index -ne 0 ] &&
6067                                         stripe_index_all_zero=false
6068                         done
6069                 done
6070         done
6071         $stripe_index_all_zero &&
6072                 error "all files are being extracted starting from OST index 0"
6073         return 0
6074 }
6075
6076 find_lustre_tar() {
6077         [ -n "$(which tar 2>/dev/null)" ] &&
6078                 strings $(which tar) | grep -q "lustre" && echo tar
6079 }
6080
6081 test_102d() {
6082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6083         # b10930: tar test for trusted.lov xattr
6084         TAR=$(find_lustre_tar)
6085         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6086         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6087         setup_test102
6088         test_mkdir -p $DIR/d102d
6089         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6090         cd $DIR/d102d/$tdir
6091         compare_stripe_info1
6092 }
6093 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6094
6095 test_102f() {
6096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6097         # b10930: tar test for trusted.lov xattr
6098         TAR=$(find_lustre_tar)
6099         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6100         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6101         setup_test102
6102         test_mkdir -p $DIR/d102f
6103         cd $DIR
6104         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6105         cd $DIR/d102f/$tdir
6106         compare_stripe_info1
6107 }
6108 run_test 102f "tar copy files, not keep osts ==========="
6109
6110 grow_xattr() {
6111         local xsize=${1:-1024}  # in bytes
6112         local file=$DIR/$tfile
6113
6114         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6115                 skip "must have user_xattr" && return 0
6116         [ -z "$(which setfattr 2>/dev/null)" ] &&
6117                 skip_env "could not find setfattr" && return 0
6118         [ -z "$(which getfattr 2>/dev/null)" ] &&
6119                 skip_env "could not find getfattr" && return 0
6120
6121         touch $file
6122
6123         local value="$(generate_string $xsize)"
6124
6125         local xbig=trusted.big
6126         log "save $xbig on $file"
6127         setfattr -n $xbig -v $value $file ||
6128                 error "saving $xbig on $file failed"
6129
6130         local orig=$(get_xattr_value $xbig $file)
6131         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6132
6133         local xsml=trusted.sml
6134         log "save $xsml on $file"
6135         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6136
6137         local new=$(get_xattr_value $xbig $file)
6138         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6139
6140         log "grow $xsml on $file"
6141         setfattr -n $xsml -v "$value" $file ||
6142                 error "growing $xsml on $file failed"
6143
6144         new=$(get_xattr_value $xbig $file)
6145         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6146         log "$xbig still valid after growing $xsml"
6147
6148         rm -f $file
6149 }
6150
6151 test_102h() { # bug 15777
6152         grow_xattr 1024
6153 }
6154 run_test 102h "grow xattr from inside inode to external block"
6155
6156 test_102ha() {
6157         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6158         grow_xattr $(max_xattr_size)
6159 }
6160 run_test 102ha "grow xattr from inside inode to external inode"
6161
6162 test_102i() { # bug 17038
6163         touch $DIR/$tfile
6164         ln -s $DIR/$tfile $DIR/${tfile}link
6165         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
6166         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"
6167         rm -f $DIR/$tfile $DIR/${tfile}link
6168 }
6169 run_test 102i "lgetxattr test on symbolic link ============"
6170
6171 test_102j() {
6172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6173         TAR=$(find_lustre_tar)
6174         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6175         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6176         setup_test102 "$RUNAS"
6177         test_mkdir -p $DIR/d102j
6178         chown $RUNAS_ID $DIR/d102j
6179         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6180         cd $DIR/d102j/$tdir
6181         compare_stripe_info1 "$RUNAS"
6182 }
6183 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6184
6185 test_102k() {
6186         touch $DIR/$tfile
6187         # b22187 just check that does not crash for regular file.
6188         setfattr -n trusted.lov $DIR/$tfile
6189         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6190         local test_kdir=$DIR/d102k
6191         test_mkdir $test_kdir
6192         local default_size=`$GETSTRIPE -S $test_kdir`
6193         local default_count=`$GETSTRIPE -c $test_kdir`
6194         local default_offset=`$GETSTRIPE -i $test_kdir`
6195         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $test_kdir ||
6196                 error 'dir setstripe failed'
6197         setfattr -n trusted.lov $test_kdir
6198         local stripe_size=`$GETSTRIPE -S $test_kdir`
6199         local stripe_count=`$GETSTRIPE -c $test_kdir`
6200         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6201         [ $stripe_size -eq $default_size ] ||
6202                 error "stripe size $stripe_size != $default_size"
6203         [ $stripe_count -eq $default_count ] ||
6204                 error "stripe count $stripe_count != $default_count"
6205         [ $stripe_offset -eq $default_offset ] ||
6206                 error "stripe offset $stripe_offset != $default_offset"
6207         rm -rf $DIR/$tfile $test_kdir
6208 }
6209 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6210
6211 test_102l() {
6212         # LU-532 trusted. xattr is invisible to non-root
6213         local testfile=$DIR/$tfile
6214
6215         touch $testfile
6216
6217         echo "listxattr as user..."
6218         chown $RUNAS_ID $testfile
6219         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6220             grep -q "trusted" &&
6221                 error "$testfile trusted xattrs are user visible"
6222
6223         return 0;
6224 }
6225 run_test 102l "listxattr filter test =================================="
6226
6227 cleanup_test102
6228
6229 run_acl_subtest()
6230 {
6231     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6232     return $?
6233 }
6234
6235 test_103 () {
6236     [ "$UID" != 0 ] && skip_env "must run as root" && return
6237     [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
6238     [ -z "$(which setfacl 2>/dev/null)" ] && skip_env "could not find setfacl" && return
6239     $GSS && skip "could not run under gss" && return
6240
6241     declare -a identity_old
6242
6243         for num in $(seq $MDSCOUNT); do
6244                 switch_identity $num true || identity_old[$num]=$?
6245         done
6246
6247     SAVE_UMASK=`umask`
6248     umask 0022
6249     cd $DIR
6250
6251     echo "performing cp ..."
6252     run_acl_subtest cp || error
6253     echo "performing getfacl-noacl..."
6254     run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6255     echo "performing misc..."
6256     run_acl_subtest misc || error  "misc test failed"
6257     echo "performing permissions..."
6258     run_acl_subtest permissions || error "permissions failed"
6259     echo "performing setfacl..."
6260     run_acl_subtest setfacl || error  "setfacl test failed"
6261
6262     # inheritance test got from HP
6263     echo "performing inheritance..."
6264     cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6265     chmod +x make-tree || error "chmod +x failed"
6266     run_acl_subtest inheritance || error "inheritance test failed"
6267     rm -f make-tree
6268
6269         echo "LU-974 ignore umask when acl is enabled..."
6270         run_acl_subtest 974 || error "LU-974 test failed"
6271         if [ $MDSCOUNT -ge 2 ]; then
6272                 run_acl_subtest 974_remote ||
6273                         error "LU-974 test failed under remote dir"
6274         fi
6275
6276     echo "LU-2561 newly created file is same size as directory..."
6277     run_acl_subtest 2561 || error "LU-2561 test failed"
6278
6279     cd $SAVE_PWD
6280     umask $SAVE_UMASK
6281
6282         for num in $(seq $MDSCOUNT); do
6283                 if [ "${identity_old[$num]}" = 1 ]; then
6284                         switch_identity $num false || identity_old[$num]=$?
6285                 fi
6286         done
6287 }
6288 run_test 103 "acl test ========================================="
6289
6290 test_104a() {
6291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6292         touch $DIR/$tfile
6293         lfs df || error "lfs df failed"
6294         lfs df -ih || error "lfs df -ih failed"
6295         lfs df -h $DIR || error "lfs df -h $DIR failed"
6296         lfs df -i $DIR || error "lfs df -i $DIR failed"
6297         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6298         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6299
6300         OSC=`lctl dl |grep OST0000-osc-[^M] |awk '{print $4}'`
6301         lctl --device %$OSC deactivate
6302         lfs df || error "lfs df with deactivated OSC failed"
6303         lctl --device %$OSC activate
6304         # wait the osc back to normal
6305         wait_osc_import_state client ost FULL
6306
6307         lfs df || error "lfs df with reactivated OSC failed"
6308         rm -f $DIR/$tfile
6309 }
6310 run_test 104a "lfs df [-ih] [path] test ========================="
6311
6312 test_104b() {
6313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6314         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6315         chmod 666 /dev/obd
6316         denied_cnt=$((`$RUNAS $LFS check servers 2>&1 | grep "Permission denied" | wc -l`))
6317         if [ $denied_cnt -ne 0 ];
6318         then
6319                     error "lfs check servers test failed"
6320         fi
6321 }
6322 run_test 104b "$RUNAS lfs check servers test ===================="
6323
6324 test_105a() {
6325         # doesn't work on 2.4 kernels
6326         touch $DIR/$tfile
6327         if [ -n "`mount | grep \"$MOUNT.*flock\" | grep -v noflock`" ]; then
6328                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6329         else
6330                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6331         fi
6332         rm -f $DIR/$tfile
6333 }
6334 run_test 105a "flock when mounted without -o flock test ========"
6335
6336 test_105b() {
6337         touch $DIR/$tfile
6338         if [ -n "`mount | grep \"$MOUNT.*flock\" | grep -v noflock`" ]; then
6339                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6340         else
6341                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6342         fi
6343         rm -f $DIR/$tfile
6344 }
6345 run_test 105b "fcntl when mounted without -o flock test ========"
6346
6347 test_105c() {
6348         touch $DIR/$tfile
6349         if [ -n "`mount | grep \"$MOUNT.*flock\" | grep -v noflock`" ]; then
6350                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6351         else
6352                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6353         fi
6354         rm -f $DIR/$tfile
6355 }
6356 run_test 105c "lockf when mounted without -o flock test ========"
6357
6358 test_105d() { # bug 15924
6359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6360         test_mkdir -p $DIR/$tdir
6361         [ -z "`mount | grep \"$MOUNT.*flock\" | grep -v noflock`" ] && \
6362                 skip "mount w/o flock enabled" && return
6363         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6364         $LCTL set_param fail_loc=0x80000315
6365         flocks_test 2 $DIR/$tdir
6366 }
6367 run_test 105d "flock race (should not freeze) ========"
6368
6369 test_105e() { # bug 22660 && 22040
6370         [ -z "`mount | grep \"$MOUNT.*flock\" | grep -v noflock`" ] && \
6371                 skip "mount w/o flock enabled" && return
6372         touch $DIR/$tfile
6373         flocks_test 3 $DIR/$tfile
6374 }
6375 run_test 105e "Two conflicting flocks from same process ======="
6376
6377 test_106() { #bug 10921
6378         test_mkdir -p $DIR/$tdir
6379         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6380         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6381 }
6382 run_test 106 "attempt exec of dir followed by chown of that dir"
6383
6384 test_107() {
6385         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6386         CDIR=`pwd`
6387         cd $DIR
6388
6389         local file=core
6390         rm -f $file
6391
6392         local save_pattern=$(sysctl -n kernel.core_pattern)
6393         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6394         sysctl -w kernel.core_pattern=$file
6395         sysctl -w kernel.core_uses_pid=0
6396
6397         ulimit -c unlimited
6398         sleep 60 &
6399         SLEEPPID=$!
6400
6401         sleep 1
6402
6403         kill -s 11 $SLEEPPID
6404         wait $SLEEPPID
6405         if [ -e $file ]; then
6406                 size=`stat -c%s $file`
6407                 [ $size -eq 0 ] && error "Fail to create core file $file"
6408         else
6409                 error "Fail to create core file $file"
6410         fi
6411         rm -f $file
6412         sysctl -w kernel.core_pattern=$save_pattern
6413         sysctl -w kernel.core_uses_pid=$save_uses_pid
6414         cd $CDIR
6415 }
6416 run_test 107 "Coredump on SIG"
6417
6418 test_110() {
6419         test_mkdir -p $DIR/$tdir
6420         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6421                 error "mkdir with 255 char failed"
6422         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6423                 error "mkdir with 256 char should fail, but did not"
6424         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
6425                 error "create with 255 char failed"
6426         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
6427                 error "create with 256 char should fail, but did not"
6428
6429         ls -l $DIR/$tdir
6430         rm -rf $DIR/$tdir
6431 }
6432 run_test 110 "filename length checking"
6433
6434 test_115() {
6435         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6436         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6437             cut -c11-20)
6438         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
6439             return
6440         echo "Starting with $OSTIO_pre threads"
6441
6442         NUMTEST=20000
6443         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6444         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
6445         echo "$NUMTEST creates/unlinks"
6446         test_mkdir -p $DIR/$tdir
6447         createmany -o $DIR/$tdir/$tfile $NUMTEST
6448         unlinkmany $DIR/$tdir/$tfile $NUMTEST
6449
6450         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6451             cut -c11-20)
6452
6453         # don't return an error
6454         [ $OSTIO_post == $OSTIO_pre ] && echo \
6455             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
6456             echo "This may be fine, depending on what ran before this test" &&
6457             echo "and how fast this system is." && return
6458
6459         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
6460 }
6461 run_test 115 "verify dynamic thread creation===================="
6462
6463 free_min_max () {
6464         wait_delete_completed
6465         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
6466         echo OST kbytes available: ${AVAIL[@]}
6467         MAXI=0; MAXV=${AVAIL[0]}
6468         MINI=0; MINV=${AVAIL[0]}
6469         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
6470             #echo OST $i: ${AVAIL[i]}kb
6471             if [ ${AVAIL[i]} -gt $MAXV ]; then
6472                 MAXV=${AVAIL[i]}; MAXI=$i
6473             fi
6474             if [ ${AVAIL[i]} -lt $MINV ]; then
6475                 MINV=${AVAIL[i]}; MINI=$i
6476             fi
6477         done
6478         echo Min free space: OST $MINI: $MINV
6479         echo Max free space: OST $MAXI: $MAXV
6480 }
6481
6482 test_116a() { # was previously test_116()
6483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6484         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
6485
6486         echo -n "Free space priority "
6487         lctl get_param -n lov.*-clilov-*.qos_prio_free
6488         declare -a AVAIL
6489         free_min_max
6490         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI, skip" &&\
6491                 return
6492
6493         # generate uneven OSTs
6494         test_mkdir -p $DIR/$tdir/OST${MINI}
6495         declare -i FILL
6496         FILL=$(($MINV / 4))
6497         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
6498         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
6499         i=0
6500         while [ $FILL -gt 0 ]; do
6501             i=$(($i + 1))
6502             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
6503             FILL=$(($FILL - 2048))
6504             echo -n .
6505         done
6506         FILL=$(($MINV / 4))
6507         sync
6508         sleep_maxage
6509
6510         free_min_max
6511         DIFF=$(($MAXV - $MINV))
6512         DIFF2=$(($DIFF * 100 / $MINV))
6513         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
6514         if [ $DIFF2 -gt 20 ]; then
6515             echo "ok"
6516         else
6517             echo "failed - QOS mode won't be used"
6518             error_ignore "QOS imbalance criteria not met"
6519             return
6520         fi
6521
6522         MINI1=$MINI; MINV1=$MINV
6523         MAXI1=$MAXI; MAXV1=$MAXV
6524
6525         # now fill using QOS
6526         echo writing a bunch of files to QOS-assigned OSTs
6527         $SETSTRIPE -c 1 $DIR/$tdir
6528         i=0
6529         while [ $FILL -gt 0 ]; do
6530             i=$(($i + 1))
6531             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
6532             FILL=$(($FILL - 200))
6533             echo -n .
6534         done
6535         echo "wrote $i 200k files"
6536         sync
6537         sleep_maxage
6538
6539         echo "Note: free space may not be updated, so measurements might be off"
6540         free_min_max
6541         DIFF2=$(($MAXV - $MINV))
6542         echo "free space delta: orig $DIFF final $DIFF2"
6543         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6544         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6545         echo "Wrote $DIFF to smaller OST $MINI1"
6546         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6547         echo "Wrote $DIFF2 to larger OST $MAXI1"
6548         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
6549
6550         # Figure out which files were written where
6551         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6552                awk '/'$MINI1': / {print $2; exit}')
6553         echo $UUID
6554         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
6555         echo "$MINC files created on smaller OST $MINI1"
6556         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6557                awk '/'$MAXI1': / {print $2; exit}')
6558         echo $UUID
6559         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
6560         echo "$MAXC files created on larger OST $MAXI1"
6561         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
6562         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
6563
6564         rm -rf $DIR/$tdir
6565 }
6566 run_test 116a "stripe QOS: free space balance ==================="
6567
6568 test_116b() { # LU-2093
6569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6570 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
6571         local old_rr
6572         old_rr=$(do_facet $SINGLEMDS lctl get_param -n lov.*mdtlov*.qos_threshold_rr)
6573         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr 0
6574         mkdir -p $DIR/$tdir
6575         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
6576         createmany -o $DIR/$tdir/f- 20 || error "can't create"
6577         do_facet $SINGLEMDS lctl set_param fail_loc=0
6578         rm -rf $DIR/$tdir
6579         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr $old_rr
6580 }
6581 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
6582
6583 test_117() # bug 10891
6584 {
6585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6586         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
6587         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
6588         lctl set_param fail_loc=0x21e
6589         > $DIR/$tfile || error "truncate failed"
6590         lctl set_param fail_loc=0
6591         echo "Truncate succeeded."
6592         rm -f $DIR/$tfile
6593 }
6594 run_test 117 "verify fsfilt_extend =========="
6595
6596 NO_SLOW_RESENDCOUNT=4
6597 export OLD_RESENDCOUNT=""
6598 set_resend_count () {
6599         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
6600         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
6601         lctl set_param -n $PROC_RESENDCOUNT $1
6602         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
6603 }
6604
6605 # for reduce test_118* time (b=14842)
6606 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
6607
6608 # Reset async IO behavior after error case
6609 reset_async() {
6610         FILE=$DIR/reset_async
6611
6612         # Ensure all OSCs are cleared
6613         $SETSTRIPE -c -1 $FILE
6614         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
6615         sync
6616         rm $FILE
6617 }
6618
6619 test_118a() #bug 11710
6620 {
6621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6622         reset_async
6623
6624         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6625         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6626         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6627
6628         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6629                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6630                 return 1;
6631         fi
6632         rm -f $DIR/$tfile
6633 }
6634 run_test 118a "verify O_SYNC works =========="
6635
6636 test_118b()
6637 {
6638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6639         remote_ost_nodsh && skip "remote OST with nodsh" && return
6640
6641         reset_async
6642
6643         #define OBD_FAIL_OST_ENOENT 0x217
6644         set_nodes_failloc "$(osts_nodes)" 0x217
6645         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6646         RC=$?
6647         set_nodes_failloc "$(osts_nodes)" 0
6648         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6649         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6650                     grep -c writeback)
6651
6652         if [[ $RC -eq 0 ]]; then
6653                 error "Must return error due to dropped pages, rc=$RC"
6654                 return 1;
6655         fi
6656
6657         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6658                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6659                 return 1;
6660         fi
6661
6662         echo "Dirty pages not leaked on ENOENT"
6663
6664         # Due to the above error the OSC will issue all RPCs syncronously
6665         # until a subsequent RPC completes successfully without error.
6666         $MULTIOP $DIR/$tfile Ow4096yc
6667         rm -f $DIR/$tfile
6668
6669         return 0
6670 }
6671 run_test 118b "Reclaim dirty pages on fatal error =========="
6672
6673 test_118c()
6674 {
6675         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6676
6677         # for 118c, restore the original resend count, LU-1940
6678         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
6679                                 set_resend_count $OLD_RESENDCOUNT
6680         remote_ost_nodsh && skip "remote OST with nodsh" && return
6681
6682         reset_async
6683
6684         #define OBD_FAIL_OST_EROFS               0x216
6685         set_nodes_failloc "$(osts_nodes)" 0x216
6686
6687         # multiop should block due to fsync until pages are written
6688         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6689         MULTIPID=$!
6690         sleep 1
6691
6692         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6693                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6694         fi
6695
6696         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6697                     grep -c writeback)
6698         if [[ $WRITEBACK -eq 0 ]]; then
6699                 error "No page in writeback, writeback=$WRITEBACK"
6700         fi
6701
6702         set_nodes_failloc "$(osts_nodes)" 0
6703         wait $MULTIPID
6704         RC=$?
6705         if [[ $RC -ne 0 ]]; then
6706                 error "Multiop fsync failed, rc=$RC"
6707         fi
6708
6709         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6710         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6711                     grep -c writeback)
6712         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6713                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6714         fi
6715
6716         rm -f $DIR/$tfile
6717         echo "Dirty pages flushed via fsync on EROFS"
6718         return 0
6719 }
6720 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
6721
6722 # continue to use small resend count to reduce test_118* time (b=14842)
6723 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
6724
6725 test_118d()
6726 {
6727         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6728         remote_ost_nodsh && skip "remote OST with nodsh" && return
6729
6730         reset_async
6731
6732         #define OBD_FAIL_OST_BRW_PAUSE_BULK
6733         set_nodes_failloc "$(osts_nodes)" 0x214
6734         # multiop should block due to fsync until pages are written
6735         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6736         MULTIPID=$!
6737         sleep 1
6738
6739         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6740                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6741         fi
6742
6743         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6744                     grep -c writeback)
6745         if [[ $WRITEBACK -eq 0 ]]; then
6746                 error "No page in writeback, writeback=$WRITEBACK"
6747         fi
6748
6749         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
6750         set_nodes_failloc "$(osts_nodes)" 0
6751
6752         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6753         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6754                     grep -c writeback)
6755         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6756                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6757         fi
6758
6759         rm -f $DIR/$tfile
6760         echo "Dirty pages gaurenteed flushed via fsync"
6761         return 0
6762 }
6763 run_test 118d "Fsync validation inject a delay of the bulk =========="
6764
6765 test_118f() {
6766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6767         reset_async
6768
6769         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
6770         lctl set_param fail_loc=0x8000040a
6771
6772         # Should simulate EINVAL error which is fatal
6773         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6774         RC=$?
6775         if [[ $RC -eq 0 ]]; then
6776                 error "Must return error due to dropped pages, rc=$RC"
6777         fi
6778
6779         lctl set_param fail_loc=0x0
6780
6781         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6782         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6783         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6784                     grep -c writeback)
6785         if [[ $LOCKED -ne 0 ]]; then
6786                 error "Locked pages remain in cache, locked=$LOCKED"
6787         fi
6788
6789         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6790                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6791         fi
6792
6793         rm -f $DIR/$tfile
6794         echo "No pages locked after fsync"
6795
6796         reset_async
6797         return 0
6798 }
6799 run_test 118f "Simulate unrecoverable OSC side error =========="
6800
6801 test_118g() {
6802         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6803         reset_async
6804
6805         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
6806         lctl set_param fail_loc=0x406
6807
6808         # simulate local -ENOMEM
6809         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6810         RC=$?
6811
6812         lctl set_param fail_loc=0
6813         if [[ $RC -eq 0 ]]; then
6814                 error "Must return error due to dropped pages, rc=$RC"
6815         fi
6816
6817         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6818         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6819         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6820                         grep -c writeback)
6821         if [[ $LOCKED -ne 0 ]]; then
6822                 error "Locked pages remain in cache, locked=$LOCKED"
6823         fi
6824
6825         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6826                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6827         fi
6828
6829         rm -f $DIR/$tfile
6830         echo "No pages locked after fsync"
6831
6832         reset_async
6833         return 0
6834 }
6835 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
6836
6837 test_118h() {
6838         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6839         remote_ost_nodsh && skip "remote OST with nodsh" && return
6840
6841         reset_async
6842
6843         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6844         set_nodes_failloc "$(osts_nodes)" 0x20e
6845         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6846         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6847         RC=$?
6848
6849         set_nodes_failloc "$(osts_nodes)" 0
6850         if [[ $RC -eq 0 ]]; then
6851                 error "Must return error due to dropped pages, rc=$RC"
6852         fi
6853
6854         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6855         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6856         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6857                     grep -c writeback)
6858         if [[ $LOCKED -ne 0 ]]; then
6859                 error "Locked pages remain in cache, locked=$LOCKED"
6860         fi
6861
6862         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6863                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6864         fi
6865
6866         rm -f $DIR/$tfile
6867         echo "No pages locked after fsync"
6868
6869         return 0
6870 }
6871 run_test 118h "Verify timeout in handling recoverables errors  =========="
6872
6873 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
6874
6875 test_118i() {
6876         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6877         remote_ost_nodsh && skip "remote OST with nodsh" && return
6878
6879         reset_async
6880
6881         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6882         set_nodes_failloc "$(osts_nodes)" 0x20e
6883
6884         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6885         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6886         PID=$!
6887         sleep 5
6888         set_nodes_failloc "$(osts_nodes)" 0
6889
6890         wait $PID
6891         RC=$?
6892         if [[ $RC -ne 0 ]]; then
6893                 error "got error, but should be not, rc=$RC"
6894         fi
6895
6896         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6897         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6898         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6899         if [[ $LOCKED -ne 0 ]]; then
6900                 error "Locked pages remain in cache, locked=$LOCKED"
6901         fi
6902
6903         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6904                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6905         fi
6906
6907         rm -f $DIR/$tfile
6908         echo "No pages locked after fsync"
6909
6910         return 0
6911 }
6912 run_test 118i "Fix error before timeout in recoverable error  =========="
6913
6914 [ "$SLOW" = "no" ] && set_resend_count 4
6915
6916 test_118j() {
6917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6918         remote_ost_nodsh && skip "remote OST with nodsh" && return
6919
6920         reset_async
6921
6922         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
6923         set_nodes_failloc "$(osts_nodes)" 0x220
6924
6925         # return -EIO from OST
6926         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6927         RC=$?
6928         set_nodes_failloc "$(osts_nodes)" 0x0
6929         if [[ $RC -eq 0 ]]; then
6930                 error "Must return error due to dropped pages, rc=$RC"
6931         fi
6932
6933         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6934         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6935         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6936         if [[ $LOCKED -ne 0 ]]; then
6937                 error "Locked pages remain in cache, locked=$LOCKED"
6938         fi
6939
6940         # in recoverable error on OST we want resend and stay until it finished
6941         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6942                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6943         fi
6944
6945         rm -f $DIR/$tfile
6946         echo "No pages locked after fsync"
6947
6948         return 0
6949 }
6950 run_test 118j "Simulate unrecoverable OST side error =========="
6951
6952 test_118k()
6953 {
6954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6955         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
6956
6957         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6958         set_nodes_failloc "$(osts_nodes)" 0x20e
6959         test_mkdir -p $DIR/$tdir
6960
6961         for ((i=0;i<10;i++)); do
6962                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
6963                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
6964                 SLEEPPID=$!
6965                 sleep 0.500s
6966                 kill $SLEEPPID
6967                 wait $SLEEPPID
6968         done
6969
6970         set_nodes_failloc "$(osts_nodes)" 0
6971         rm -rf $DIR/$tdir
6972 }
6973 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
6974
6975 test_118l()
6976 {
6977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6978         # LU-646
6979         test_mkdir -p $DIR/$tdir
6980         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
6981         rm -rf $DIR/$tdir
6982 }
6983 run_test 118l "fsync dir ========="
6984
6985 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
6986
6987 test_119a() # bug 11737
6988 {
6989         BSIZE=$((512 * 1024))
6990         directio write $DIR/$tfile 0 1 $BSIZE
6991         # We ask to read two blocks, which is more than a file size.
6992         # directio will indicate an error when requested and actual
6993         # sizes aren't equeal (a normal situation in this case) and
6994         # print actual read amount.
6995         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
6996         if [ "$NOB" != "$BSIZE" ]; then
6997                 error "read $NOB bytes instead of $BSIZE"
6998         fi
6999         rm -f $DIR/$tfile
7000 }
7001 run_test 119a "Short directIO read must return actual read amount"
7002
7003 test_119b() # bug 11737
7004 {
7005         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7006
7007         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7008         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7009         sync
7010         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7011                 error "direct read failed"
7012         rm -f $DIR/$tfile
7013 }
7014 run_test 119b "Sparse directIO read must return actual read amount"
7015
7016 test_119c() # bug 13099
7017 {
7018         BSIZE=1048576
7019         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7020         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7021         rm -f $DIR/$tfile
7022 }
7023 run_test 119c "Testing for direct read hitting hole"
7024
7025 test_119d() # bug 15950
7026 {
7027         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7028         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7029         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7030         BSIZE=1048576
7031         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7032         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7033         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7034         lctl set_param fail_loc=0x40d
7035         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7036         pid_dio=$!
7037         sleep 1
7038         cat $DIR/$tfile > /dev/null &
7039         lctl set_param fail_loc=0
7040         pid_reads=$!
7041         wait $pid_dio
7042         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7043         sleep 2
7044         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7045         error "the read rpcs have not completed in 2s"
7046         rm -f $DIR/$tfile
7047         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7048 }
7049 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7050
7051 test_120a() {
7052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7053         test_mkdir -p $DIR/$tdir
7054         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7055                skip "no early lock cancel on server" && return 0
7056         lru_resize_disable mdc
7057         lru_resize_disable osc
7058         cancel_lru_locks mdc
7059         stat $DIR/$tdir > /dev/null
7060         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7061         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7062         test_mkdir $DIR/$tdir/d1
7063         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7064         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7065         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7066         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7067         lru_resize_enable mdc
7068         lru_resize_enable osc
7069 }
7070 run_test 120a "Early Lock Cancel: mkdir test"
7071
7072 test_120b() {
7073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7074         test_mkdir -p $DIR/$tdir
7075         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7076                skip "no early lock cancel on server" && return 0
7077         lru_resize_disable mdc
7078         lru_resize_disable osc
7079         cancel_lru_locks mdc
7080         stat $DIR/$tdir > /dev/null
7081         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7082         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7083         touch $DIR/$tdir/f1
7084         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7085         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7086         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7087         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7088         lru_resize_enable mdc
7089         lru_resize_enable osc
7090 }
7091 run_test 120b "Early Lock Cancel: create test"
7092
7093 test_120c() {
7094         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7095         test_mkdir -p $DIR/$tdir
7096         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7097                skip "no early lock cancel on server" && return 0
7098         lru_resize_disable mdc
7099         lru_resize_disable osc
7100         test_mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
7101         touch $DIR/$tdir/d1/f1
7102         cancel_lru_locks mdc
7103         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7104         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7105         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7106         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7107         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7108         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7109         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7110         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7111         lru_resize_enable mdc
7112         lru_resize_enable osc
7113 }
7114 run_test 120c "Early Lock Cancel: link test"
7115
7116 test_120d() {
7117         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7118         test_mkdir -p $DIR/$tdir
7119         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7120                skip "no early lock cancel on server" && return 0
7121         lru_resize_disable mdc
7122         lru_resize_disable osc
7123         touch $DIR/$tdir
7124         cancel_lru_locks mdc
7125         stat $DIR/$tdir > /dev/null
7126         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7127         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7128         chmod a+x $DIR/$tdir
7129         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7130         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7131         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7132         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7133         lru_resize_enable mdc
7134         lru_resize_enable osc
7135 }
7136 run_test 120d "Early Lock Cancel: setattr test"
7137
7138 test_120e() {
7139         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7140         test_mkdir -p $DIR/$tdir
7141         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7142                skip "no early lock cancel on server" && return 0
7143         lru_resize_disable mdc
7144         lru_resize_disable osc
7145         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7146         cancel_lru_locks mdc
7147         cancel_lru_locks osc
7148         dd if=$DIR/$tdir/f1 of=/dev/null
7149         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7150         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7151               awk '/ldlm_cancel/ {print $2}'`
7152         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7153               awk '/ldlm_bl_callback/ {print $2}'`
7154         unlink $DIR/$tdir/f1
7155         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7156               awk '/ldlm_cancel/ {print $2}'`
7157         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7158               awk '/ldlm_bl_callback/ {print $2}'`
7159         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7160         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7161         lru_resize_enable mdc
7162         lru_resize_enable osc
7163 }
7164 run_test 120e "Early Lock Cancel: unlink test"
7165
7166 test_120f() {
7167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7168         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7169                skip "no early lock cancel on server" && return 0
7170         test_mkdir -p $DIR/$tdir
7171         lru_resize_disable mdc
7172         lru_resize_disable osc
7173         test_mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
7174         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7175         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7176         cancel_lru_locks mdc
7177         cancel_lru_locks osc
7178         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7179         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7180         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7181         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7182               awk '/ldlm_cancel/ {print $2}'`
7183         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7184               awk '/ldlm_bl_callback/ {print $2}'`
7185         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7186         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7187               awk '/ldlm_cancel/ {print $2}'`
7188         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7189               awk '/ldlm_bl_callback/ {print $2}'`
7190         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7191         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7192         lru_resize_enable mdc
7193         lru_resize_enable osc
7194 }
7195 run_test 120f "Early Lock Cancel: rename test"
7196
7197 test_120g() {
7198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7199         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7200                skip "no early lock cancel on server" && return 0
7201         lru_resize_disable mdc
7202         lru_resize_disable osc
7203         count=10000
7204         echo create $count files
7205         test_mkdir -p $DIR/$tdir
7206         cancel_lru_locks mdc
7207         cancel_lru_locks osc
7208         t0=`date +%s`
7209
7210         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7211               awk '/ldlm_cancel/ {print $2}'`
7212         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7213               awk '/ldlm_bl_callback/ {print $2}'`
7214         createmany -o $DIR/$tdir/f $count
7215         sync
7216         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7217               awk '/ldlm_cancel/ {print $2}'`
7218         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7219               awk '/ldlm_bl_callback/ {print $2}'`
7220         t1=`date +%s`
7221         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7222         echo rm $count files
7223         rm -r $DIR/$tdir
7224         sync
7225         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7226               awk '/ldlm_cancel/ {print $2}'`
7227         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7228               awk '/ldlm_bl_callback/ {print $2}'`
7229         t2=`date +%s`
7230         echo total: $count removes in $((t2-t1))
7231         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7232         sleep 2
7233         # wait for commitment of removal
7234         lru_resize_enable mdc
7235         lru_resize_enable osc
7236 }
7237 run_test 120g "Early Lock Cancel: performance test"
7238
7239 test_121() { #bug #10589
7240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7241         rm -rf $DIR/$tfile
7242         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7243 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7244         lctl set_param fail_loc=0x310
7245         cancel_lru_locks osc > /dev/null
7246         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7247         lctl set_param fail_loc=0
7248         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
7249 }
7250 run_test 121 "read cancel race ========="
7251
7252 test_123a() { # was test 123, statahead(bug 11401)
7253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7254         SLOWOK=0
7255         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7256             log "testing on UP system. Performance may be not as good as expected."
7257                         SLOWOK=1
7258         fi
7259
7260         rm -rf $DIR/$tdir
7261         test_mkdir -p $DIR/$tdir
7262         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
7263         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7264         MULT=10
7265         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7266                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7267
7268                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7269                 lctl set_param -n llite.*.statahead_max 0
7270                 lctl get_param llite.*.statahead_max
7271                 cancel_lru_locks mdc
7272                 cancel_lru_locks osc
7273                 stime=`date +%s`
7274                 time ls -l $DIR/$tdir | wc -l
7275                 etime=`date +%s`
7276                 delta=$((etime - stime))
7277                 log "ls $i files without statahead: $delta sec"
7278                 lctl set_param llite.*.statahead_max=$max
7279
7280                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7281                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7282                 cancel_lru_locks mdc
7283                 cancel_lru_locks osc
7284                 stime=`date +%s`
7285                 time ls -l $DIR/$tdir | wc -l
7286                 etime=`date +%s`
7287                 delta_sa=$((etime - stime))
7288                 log "ls $i files with statahead: $delta_sa sec"
7289                 lctl get_param -n llite.*.statahead_stats
7290                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7291
7292                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
7293                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
7294
7295                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7296                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7297                     lctl set_param -n llite.*.statahead_max 0
7298                     lctl get_param llite.*.statahead_max
7299                     cancel_lru_locks mdc
7300                     cancel_lru_locks osc
7301                     stime=`date +%s`
7302                     time ls -l $DIR/$tdir | wc -l
7303                     etime=`date +%s`
7304                     delta=$((etime - stime))
7305                     log "ls $i files again without statahead: $delta sec"
7306                     lctl set_param llite.*.statahead_max=$max
7307                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7308                         if [  $SLOWOK -eq 0 ]; then
7309                                 error "ls $i files is slower with statahead!"
7310                         else
7311                                 log "ls $i files is slower with statahead!"
7312                         fi
7313                         break
7314                     fi
7315                 fi
7316
7317                 [ $delta -gt 20 ] && break
7318                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7319                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7320         done
7321         log "ls done"
7322
7323         stime=`date +%s`
7324         rm -r $DIR/$tdir
7325         sync
7326         etime=`date +%s`
7327         delta=$((etime - stime))
7328         log "rm -r $DIR/$tdir/: $delta seconds"
7329         log "rm done"
7330         lctl get_param -n llite.*.statahead_stats
7331 }
7332 run_test 123a "verify statahead work"
7333
7334 test_123b () { # statahead(bug 15027)
7335         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7336         test_mkdir -p $DIR/$tdir
7337         createmany -o $DIR/$tdir/$tfile-%d 1000
7338
7339         cancel_lru_locks mdc
7340         cancel_lru_locks osc
7341
7342 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
7343         lctl set_param fail_loc=0x80000803
7344         ls -lR $DIR/$tdir > /dev/null
7345         log "ls done"
7346         lctl set_param fail_loc=0x0
7347         lctl get_param -n llite.*.statahead_stats
7348         rm -r $DIR/$tdir
7349         sync
7350
7351 }
7352 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
7353
7354 test_124a() {
7355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7356         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7357                skip "no lru resize on server" && return 0
7358         local NR=2000
7359         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
7360
7361         log "create $NR files at $DIR/$tdir"
7362         createmany -o $DIR/$tdir/f $NR ||
7363                 error "failed to create $NR files in $DIR/$tdir"
7364
7365         cancel_lru_locks mdc
7366         ls -l $DIR/$tdir > /dev/null
7367
7368         local NSDIR=""
7369         local LRU_SIZE=0
7370         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
7371                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
7372                 LRU_SIZE=$(lctl get_param -n $PARAM)
7373                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
7374                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
7375                                                 log "NSDIR=$NSDIR"
7376                         log "NS=$(basename $NSDIR)"
7377                         break
7378                 fi
7379         done
7380
7381         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
7382                 skip "Not enough cached locks created!"
7383                 return 0
7384         fi
7385         log "LRU=$LRU_SIZE"
7386
7387         local SLEEP=30
7388
7389         # We know that lru resize allows one client to hold $LIMIT locks
7390         # for 10h. After that locks begin to be killed by client.
7391         local MAX_HRS=10
7392         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
7393                 log "LIMIT=$LIMIT"
7394
7395         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
7396         # killing locks. Some time was spent for creating locks. This means
7397         # that up to the moment of sleep finish we must have killed some of
7398         # them (10-100 locks). This depends on how fast ther were created.
7399         # Many of them were touched in almost the same moment and thus will
7400         # be killed in groups.
7401         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
7402
7403         # Use $LRU_SIZE_B here to take into account real number of locks
7404         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
7405         local LRU_SIZE_B=$LRU_SIZE
7406         log "LVF=$LVF"
7407         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
7408                 log "OLD_LVF=$OLD_LVF"
7409         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
7410
7411         # Let's make sure that we really have some margin. Client checks
7412         # cached locks every 10 sec.
7413         SLEEP=$((SLEEP+20))
7414         log "Sleep ${SLEEP} sec"
7415         local SEC=0
7416         while ((SEC<$SLEEP)); do
7417                 echo -n "..."
7418                 sleep 5
7419                 SEC=$((SEC+5))
7420                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
7421                 echo -n "$LRU_SIZE"
7422         done
7423         echo ""
7424         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
7425         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
7426
7427         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
7428                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
7429                 unlinkmany $DIR/$tdir/f $NR
7430                 return
7431         }
7432
7433         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
7434         log "unlink $NR files at $DIR/$tdir"
7435         unlinkmany $DIR/$tdir/f $NR
7436 }
7437 run_test 124a "lru resize ======================================="
7438
7439 get_max_pool_limit()
7440 {
7441         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
7442         local max=0
7443         for l in $limit; do
7444                 if test $l -gt $max; then
7445                         max=$l
7446                 fi
7447         done
7448         echo $max
7449 }
7450
7451 test_124b() {
7452         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7453         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7454                skip "no lru resize on server" && return 0
7455
7456         LIMIT=`get_max_pool_limit`
7457
7458         NR=$(($(default_lru_size)*20))
7459         if [ $NR -gt $LIMIT ]; then
7460                 log "Limit lock number by $LIMIT locks"
7461                 NR=$LIMIT
7462         fi
7463         lru_resize_disable mdc
7464         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
7465                 error "failed to create $DIR/$tdir/disable_lru_resize"
7466
7467         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
7468         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
7469         cancel_lru_locks mdc
7470         stime=`date +%s`
7471         PID=""
7472         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7473         PID="$PID $!"
7474         sleep 2
7475         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7476         PID="$PID $!"
7477         sleep 2
7478         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7479         PID="$PID $!"
7480         wait $PID
7481         etime=`date +%s`
7482         nolruresize_delta=$((etime-stime))
7483         log "ls -la time: $nolruresize_delta seconds"
7484         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7485         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
7486
7487         lru_resize_enable mdc
7488         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
7489                 error "failed to create $DIR/$tdir/enable_lru_resize"
7490
7491         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
7492         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
7493         cancel_lru_locks mdc
7494         stime=`date +%s`
7495         PID=""
7496         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7497         PID="$PID $!"
7498         sleep 2
7499         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7500         PID="$PID $!"
7501         sleep 2
7502         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7503         PID="$PID $!"
7504         wait $PID
7505         etime=`date +%s`
7506         lruresize_delta=$((etime-stime))
7507         log "ls -la time: $lruresize_delta seconds"
7508         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7509
7510         if [ $lruresize_delta -gt $nolruresize_delta ]; then
7511                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
7512         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
7513                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
7514         else
7515                 log "lru resize performs the same with no lru resize"
7516         fi
7517         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
7518 }
7519 run_test 124b "lru resize (performance test) ======================="
7520
7521 test_125() { # 13358
7522         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7523         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
7524         test_mkdir -p $DIR/d125 || error "mkdir failed"
7525         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
7526         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
7527         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
7528 }
7529 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
7530
7531 test_126() { # bug 12829/13455
7532         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7533         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
7534         $GSS && skip "must run as gss disabled" && return
7535
7536         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
7537         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
7538         rm -f $DIR/$tfile
7539         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
7540 }
7541 run_test 126 "check that the fsgid provided by the client is taken into account"
7542
7543 test_127a() { # bug 15521
7544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7545         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
7546         $LCTL set_param osc.*.stats=0
7547         FSIZE=$((2048 * 1024))
7548         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7549         cancel_lru_locks osc
7550         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
7551
7552         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
7553         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7554                 echo "got $COUNT $NAME"
7555                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
7556                 eval $NAME=$COUNT || error "Wrong proc format"
7557
7558                 case $NAME in
7559                         read_bytes|write_bytes)
7560                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
7561                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
7562                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
7563                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
7564                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
7565                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
7566                                 error "sumsquare is too small: $SUMSQ"
7567                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
7568                                 error "sumsquare is too big: $SUMSQ"
7569                         ;;
7570                         *) ;;
7571                 esac
7572         done < $DIR/${tfile}.tmp
7573
7574         #check that we actually got some stats
7575         [ "$read_bytes" ] || error "Missing read_bytes stats"
7576         [ "$write_bytes" ] || error "Missing write_bytes stats"
7577         [ "$read_bytes" != 0 ] || error "no read done"
7578         [ "$write_bytes" != 0 ] || error "no write done"
7579 }
7580 run_test 127a "verify the client stats are sane"
7581
7582 test_127b() { # bug LU-333
7583         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7584         $LCTL set_param llite.*.stats=0
7585         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
7586         # perform 2 reads and writes so MAX is different from SUM.
7587         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7588         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7589         cancel_lru_locks osc
7590         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7591         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7592
7593         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
7594         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7595                 echo "got $COUNT $NAME"
7596                 eval $NAME=$COUNT || error "Wrong proc format"
7597
7598         case $NAME in
7599                 read_bytes)
7600                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7601                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7602                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7603                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7604                         ;;
7605                 write_bytes)
7606                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7607                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7608                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7609                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7610                         ;;
7611                         *) ;;
7612                 esac
7613         done < $TMP/${tfile}.tmp
7614
7615         #check that we actually got some stats
7616         [ "$read_bytes" ] || error "Missing read_bytes stats"
7617         [ "$write_bytes" ] || error "Missing write_bytes stats"
7618         [ "$read_bytes" != 0 ] || error "no read done"
7619         [ "$write_bytes" != 0 ] || error "no write done"
7620 }
7621 run_test 127b "verify the llite client stats are sane"
7622
7623 test_128() { # bug 15212
7624         touch $DIR/$tfile
7625         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
7626                 find $DIR/$tfile
7627                 find $DIR/$tfile
7628         EOF
7629
7630         result=$(grep error $TMP/$tfile.log)
7631         rm -f $DIR/$tfile
7632         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
7633 }
7634 run_test 128 "interactive lfs for 2 consecutive find's"
7635
7636 set_dir_limits () {
7637         local mntdev
7638         local canondev
7639         local node
7640
7641         local LDPROC=/proc/fs/ldiskfs
7642         local facets=$(get_facets MDS)
7643
7644         for facet in ${facets//,/ }; do
7645                 canondev=$(ldiskfs_canon \
7646                            *.$(convert_facet2label $facet).mntdev $facet)
7647                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
7648                                                 LDPROC=/sys/fs/ldiskfs
7649                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
7650         done
7651 }
7652
7653 test_129() {
7654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7655         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
7656                 skip "Only applicable to ldiskfs-based MDTs"
7657                 return
7658         fi
7659         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7660
7661         EFBIG=27
7662         MAX=16384
7663
7664         set_dir_limits $MAX
7665         test_mkdir -p $DIR/$tdir
7666
7667         local I=0
7668         local J=0
7669         while [ ! $I -gt $((MAX * MDSCOUNT)) ]; do
7670                 $MULTIOP $DIR/$tdir/$J Oc
7671                 rc=$?
7672                 if [ $rc -eq $EFBIG ]; then
7673                         set_dir_limits 0
7674                         echo "return code $rc received as expected"
7675                         return 0
7676                 elif [ $rc -ne 0 ]; then
7677                         set_dir_limits 0
7678                         error_exit "return code $rc received instead of expected $EFBIG"
7679                 fi
7680                 J=$((J+1))
7681                 I=$(stat -c%s "$DIR/$tdir")
7682         done
7683
7684         set_dir_limits 0
7685         error "exceeded dir size limit $MAX x $MDSCOUNT $((MAX * MDSCOUNT)) : $I bytes"
7686 }
7687 run_test 129 "test directory size limit ========================"
7688
7689 OLDIFS="$IFS"
7690 cleanup_130() {
7691         trap 0
7692         IFS="$OLDIFS"
7693 }
7694
7695 test_130a() {
7696         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7697         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
7698                 return
7699
7700         trap cleanup_130 EXIT RETURN
7701
7702         local fm_file=$DIR/$tfile
7703         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
7704         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
7705                 error "dd failed for $fm_file"
7706
7707         # LU-1795: test filefrag/FIEMAP once, even if unsupported
7708         filefrag -ves $fm_file
7709         RC=$?
7710         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7711                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7712         [ $RC != 0 ] && error "filefrag $fm_file failed"
7713
7714         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
7715                       grep -v "ext:" | grep -v "found")
7716         lun=$($GETSTRIPE -i $fm_file)
7717
7718         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
7719         IFS=$'\n'
7720         tot_len=0
7721         for line in $filefrag_op
7722         do
7723                 frag_lun=`echo $line | cut -d: -f5`
7724                 ext_len=`echo $line | cut -d: -f4`
7725                 if (( $frag_lun != $lun )); then
7726                         cleanup_130
7727                         error "FIEMAP on 1-stripe file($fm_file) failed"
7728                         return
7729                 fi
7730                 (( tot_len += ext_len ))
7731         done
7732
7733         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
7734                 cleanup_130
7735                 error "FIEMAP on 1-stripe file($fm_file) failed;"
7736                 return
7737         fi
7738
7739         cleanup_130
7740
7741         echo "FIEMAP on single striped file succeeded"
7742 }
7743 run_test 130a "FIEMAP (1-stripe file)"
7744
7745 test_130b() {
7746         [ "$OSTCOUNT" -lt "2" ] &&
7747                 skip_env "skipping FIEMAP on 2-stripe file test" && return
7748
7749         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7750         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
7751                 return
7752
7753         trap cleanup_130 EXIT RETURN
7754
7755         local fm_file=$DIR/$tfile
7756         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7757         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7758                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7759
7760         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
7761                 error "dd failed on $fm_file"
7762
7763         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7764         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
7765                       grep -v "ext:" | grep -v "found")
7766
7767         last_lun=$(echo $filefrag_op | cut -d: -f5)
7768
7769         IFS=$'\n'
7770         tot_len=0
7771         num_luns=1
7772         for line in $filefrag_op
7773         do
7774                 frag_lun=`echo $line | cut -d: -f5`
7775                 ext_len=`echo $line | cut -d: -f4`
7776                 if (( $frag_lun != $last_lun )); then
7777                         if (( tot_len != 1024 )); then
7778                                 cleanup_130
7779                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
7780                                 return
7781                         else
7782                                 (( num_luns += 1 ))
7783                                 tot_len=0
7784                         fi
7785                 fi
7786                 (( tot_len += ext_len ))
7787                 last_lun=$frag_lun
7788         done
7789         if (( num_luns != 2 || tot_len != 1024 )); then
7790                 cleanup_130
7791                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7792                 return
7793         fi
7794
7795         cleanup_130
7796
7797         echo "FIEMAP on 2-stripe file succeeded"
7798 }
7799 run_test 130b "FIEMAP (2-stripe file)"
7800
7801 test_130c() {
7802         [ "$OSTCOUNT" -lt "2" ] &&
7803                 skip_env "skipping FIEMAP on 2-stripe file" && return
7804
7805         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7806         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
7807                 return
7808
7809         trap cleanup_130 EXIT RETURN
7810
7811         local fm_file=$DIR/$tfile
7812         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7813         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7814                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7815
7816         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
7817
7818         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7819         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7820
7821         last_lun=`echo $filefrag_op | cut -d: -f5`
7822
7823         IFS=$'\n'
7824         tot_len=0
7825         num_luns=1
7826         for line in $filefrag_op
7827         do
7828                 frag_lun=`echo $line | cut -d: -f5`
7829                 ext_len=`echo $line | cut -d: -f4`
7830                 if (( $frag_lun != $last_lun )); then
7831                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
7832                         if (( logical != 512 )); then
7833                                 cleanup_130
7834                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
7835                                 return
7836                         fi
7837                         if (( tot_len != 512 )); then
7838                                 cleanup_130
7839                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7840                                 return
7841                         else
7842                                 (( num_luns += 1 ))
7843                                 tot_len=0
7844                         fi
7845                 fi
7846                 (( tot_len += ext_len ))
7847                 last_lun=$frag_lun
7848         done
7849         if (( num_luns != 2 || tot_len != 512 )); then
7850                 cleanup_130
7851                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7852                 return
7853         fi
7854
7855         cleanup_130
7856
7857         echo "FIEMAP on 2-stripe file with hole succeeded"
7858 }
7859 run_test 130c "FIEMAP (2-stripe file with hole)"
7860
7861 test_130d() {
7862         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
7863
7864         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7865         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7866
7867         trap cleanup_130 EXIT RETURN
7868
7869         local fm_file=$DIR/$tfile
7870         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
7871         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7872                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7873         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
7874
7875         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7876         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7877
7878         last_lun=`echo $filefrag_op | cut -d: -f5`
7879
7880         IFS=$'\n'
7881         tot_len=0
7882         num_luns=1
7883         for line in $filefrag_op
7884         do
7885                 frag_lun=`echo $line | cut -d: -f5`
7886                 ext_len=`echo $line | cut -d: -f4`
7887                 if (( $frag_lun != $last_lun )); then
7888                         if (( tot_len != 1024 )); then
7889                                 cleanup_130
7890                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7891                                 return
7892                         else
7893                                 (( num_luns += 1 ))
7894                                 tot_len=0
7895                         fi
7896                 fi
7897                 (( tot_len += ext_len ))
7898                 last_lun=$frag_lun
7899         done
7900         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
7901                 cleanup_130
7902                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7903                 return
7904         fi
7905
7906         cleanup_130
7907
7908         echo "FIEMAP on N-stripe file succeeded"
7909 }
7910 run_test 130d "FIEMAP (N-stripe file)"
7911
7912 test_130e() {
7913         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
7914
7915         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7916         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7917
7918         trap cleanup_130 EXIT RETURN
7919
7920         local fm_file=$DIR/$tfile
7921         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
7922         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7923                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7924
7925         NUM_BLKS=512
7926         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
7927         for ((i = 0; i < $NUM_BLKS; i++))
7928         do
7929                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
7930         done
7931
7932         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7933         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
7934
7935         last_lun=`echo $filefrag_op | cut -d: -f5`
7936
7937         IFS=$'\n'
7938         tot_len=0
7939         num_luns=1
7940         for line in $filefrag_op
7941         do
7942                 frag_lun=`echo $line | cut -d: -f5`
7943                 ext_len=`echo $line | cut -d: -f4`
7944                 if (( $frag_lun != $last_lun )); then
7945                         if (( tot_len != $EXPECTED_LEN )); then
7946                                 cleanup_130
7947                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
7948                                 return
7949                         else
7950                                 (( num_luns += 1 ))
7951                                 tot_len=0
7952                         fi
7953                 fi
7954                 (( tot_len += ext_len ))
7955                 last_lun=$frag_lun
7956         done
7957         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
7958                 cleanup_130
7959                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7960                 return
7961         fi
7962
7963         cleanup_130
7964
7965         echo "FIEMAP with continuation calls succeeded"
7966 }
7967 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
7968
7969 # Test for writev/readv
7970 test_131a() {
7971         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
7972         error "writev test failed"
7973         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
7974         error "readv failed"
7975         rm -f $DIR/$tfile
7976 }
7977 run_test 131a "test iov's crossing stripe boundary for writev/readv"
7978
7979 test_131b() {
7980         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
7981         error "append writev test failed"
7982         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
7983         error "append writev test failed"
7984         rm -f $DIR/$tfile
7985 }
7986 run_test 131b "test append writev"
7987
7988 test_131c() {
7989         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
7990         error "NOT PASS"
7991 }
7992 run_test 131c "test read/write on file w/o objects"
7993
7994 test_131d() {
7995         rwv -f $DIR/$tfile -w -n 1 1572864
7996         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
7997         if [ "$NOB" != 1572864 ]; then
7998                 error "Short read filed: read $NOB bytes instead of 1572864"
7999         fi
8000         rm -f $DIR/$tfile
8001 }
8002 run_test 131d "test short read"
8003
8004 test_131e() {
8005         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8006         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8007         error "read hitting hole failed"
8008         rm -f $DIR/$tfile
8009 }
8010 run_test 131e "test read hitting hole"
8011
8012 get_ost_param() {
8013         local token=$1
8014         local gl_sum=0
8015         for node in $(osts_nodes); do
8016                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8017                 [ x$gl = x"" ] && gl=0
8018                 gl_sum=$((gl_sum + gl))
8019         done
8020         echo $gl_sum
8021 }
8022
8023 som_mode_switch() {
8024         local som=$1
8025         local gl1=$2
8026         local gl2=$3
8027
8028         if [ x$som = x"enabled" ]; then
8029                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8030                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8031                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8032         else
8033                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8034                 MOUNTOPT="$MOUNTOPT,som_preview"
8035                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8036         fi
8037
8038         # do remount to make new mount-conf parameters actual
8039         echo remounting...
8040         sync
8041         stopall
8042         setupall
8043 }
8044
8045 test_132() { #1028, SOM
8046         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8047         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8048         local num=$(get_mds_dir $DIR)
8049         local mymds=mds${num}
8050         local MOUNTOPT_SAVE=$MOUNTOPT
8051
8052         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8053         cancel_lru_locks osc
8054
8055         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8056
8057         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8058         stat $DIR/$tfile >/dev/null
8059         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8060         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8061         rm $DIR/$tfile
8062         som_mode_switch $som1 $gl1 $gl2
8063
8064         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8065         cancel_lru_locks osc
8066
8067         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8068         if [ $som1 == $som2 ]; then
8069             error "som is still "$som2
8070             if [ x$som2 = x"enabled" ]; then
8071                 som2="disabled"
8072             else
8073                 som2="enabled"
8074             fi
8075         fi
8076
8077         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8078         stat $DIR/$tfile >/dev/null
8079         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8080         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8081         som_mode_switch $som2 $gl1 $gl2
8082         MOUNTOPT=$MOUNTOPT_SAVE
8083 }
8084 run_test 132 "som avoids glimpse rpc"
8085
8086 check_stats() {
8087         local res
8088         local count
8089         case $1 in
8090         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8091                  ;;
8092         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8093                  ;;
8094         *) error "Wrong argument $1" ;;
8095         esac
8096         echo $res
8097         count=`echo $res | awk '{print $2}'`
8098         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8099         # if the argument $3 is zero, it means any stat increment is ok.
8100         if [ $3 -gt 0 ] ; then
8101                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
8102         fi
8103 }
8104
8105 test_133a() {
8106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8107         remote_ost_nodsh && skip "remote OST with nodsh" && return
8108         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8109
8110         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8111                 { skip "MDS doesn't support rename stats"; return; }
8112         local testdir=$DIR/${tdir}/stats_testdir
8113         mkdir -p $DIR/${tdir}
8114
8115         # clear stats.
8116         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8117         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8118
8119         # verify mdt stats first.
8120         mkdir ${testdir} || error "mkdir failed"
8121         check_stats $SINGLEMDS "mkdir" 1
8122         touch ${testdir}/${tfile} || "touch failed"
8123         check_stats $SINGLEMDS "open" 1
8124         check_stats $SINGLEMDS "close" 1
8125         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8126         check_stats $SINGLEMDS "mknod" 1
8127         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8128         check_stats $SINGLEMDS "unlink" 1
8129         rm -f ${testdir}/${tfile} || error "file remove failed"
8130         check_stats $SINGLEMDS "unlink" 2
8131
8132         # remove working dir and check mdt stats again.
8133         rmdir ${testdir} || error "rmdir failed"
8134         check_stats $SINGLEMDS "rmdir" 1
8135
8136         local testdir1=$DIR/${tdir}/stats_testdir1
8137         mkdir -p ${testdir}
8138         mkdir -p ${testdir1}
8139         touch ${testdir1}/test1
8140         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8141         check_stats $SINGLEMDS "crossdir_rename" 1
8142
8143         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8144         check_stats $SINGLEMDS "samedir_rename" 1
8145
8146         rm -rf $DIR/${tdir}
8147 }
8148 run_test 133a "Verifying MDT stats ========================================"
8149
8150 test_133b() {
8151         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8152         remote_ost_nodsh && skip "remote OST with nodsh" && return
8153         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8154         local testdir=$DIR/${tdir}/stats_testdir
8155         mkdir -p ${testdir} || error "mkdir failed"
8156         touch ${testdir}/${tfile} || "touch failed"
8157         cancel_lru_locks mdc
8158
8159         # clear stats.
8160         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8161         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8162
8163         # extra mdt stats verification.
8164         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8165         check_stats $SINGLEMDS "setattr" 1
8166         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8167         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8168         then            # LU-1740
8169                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8170                 check_stats $SINGLEMDS "getattr" 1
8171         fi
8172         $LFS df || error "lfs failed"
8173         check_stats $SINGLEMDS "statfs" 1
8174
8175         rm -rf $DIR/${tdir}
8176 }
8177 run_test 133b "Verifying extra MDT stats =================================="
8178
8179 test_133c() {
8180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8181         remote_ost_nodsh && skip "remote OST with nodsh" && return
8182         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8183         local testdir=$DIR/${tdir}/stats_testdir
8184         test_mkdir -p ${testdir} || error "mkdir failed"
8185
8186         # verify obdfilter stats.
8187         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8188         sync
8189         cancel_lru_locks osc
8190         wait_delete_completed
8191
8192         # clear stats.
8193         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8194         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8195
8196         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8197         sync
8198         cancel_lru_locks osc
8199         check_stats ost "write" 1
8200
8201         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8202         check_stats ost "read" 1
8203
8204         > ${testdir}/${tfile} || error "truncate failed"
8205         check_stats ost "punch" 1
8206
8207         rm -f ${testdir}/${tfile} || error "file remove failed"
8208         wait_delete_completed
8209         check_stats ost "destroy" 1
8210
8211         rm -rf $DIR/${tdir}
8212 }
8213 run_test 133c "Verifying OST stats ========================================"
8214
8215 order_2() {
8216     local value=$1
8217     local orig=$value
8218     local order=1
8219
8220     while [ $value -ge 2 ]; do
8221         order=$((order*2))
8222         value=$((value/2))
8223     done
8224
8225     if [ $orig -gt $order ]; then
8226         order=$((order*2))
8227     fi
8228     echo $order
8229 }
8230
8231 size_in_KMGT() {
8232     local value=$1
8233     local size=('K' 'M' 'G' 'T');
8234     local i=0
8235     local size_string=$value
8236
8237     while [ $value -ge 1024 ]; do
8238         if [ $i -gt 3 ]; then
8239             #T is the biggest unit we get here, if that is bigger,
8240             #just return XXXT
8241             size_string=${value}T
8242             break
8243         fi
8244         value=$((value >> 10))
8245         if [ $value -lt 1024 ]; then
8246             size_string=${value}${size[$i]}
8247             break
8248         fi
8249         i=$((i + 1))
8250     done
8251
8252     echo $size_string
8253 }
8254
8255 get_rename_size() {
8256     local size=$1
8257     local context=${2:-.}
8258     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8259                 grep -A1 $context |
8260                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8261     echo $sample
8262 }
8263
8264 test_133d() {
8265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8266     remote_ost_nodsh && skip "remote OST with nodsh" && return
8267     remote_mds_nodsh && skip "remote MDS with nodsh" && return
8268     do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8269         { skip "MDS doesn't support rename stats"; return; }
8270
8271     local testdir1=$DIR/${tdir}/stats_testdir1
8272     local testdir2=$DIR/${tdir}/stats_testdir2
8273
8274     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8275
8276     test_mkdir -p ${testdir1} || error "mkdir failed"
8277     test_mkdir -p ${testdir2} || error "mkdir failed"
8278
8279     createmany -o $testdir1/test 512 || error "createmany failed"
8280
8281         # check samedir rename size
8282         mv ${testdir1}/test0 ${testdir1}/test_0
8283
8284         local testdir1_size=$(ls -l $DIR/${tdir} |
8285                 awk '/stats_testdir1/ {print $5}')
8286         local testdir2_size=$(ls -l $DIR/${tdir} |
8287                 awk '/stats_testdir2/ {print $5}')
8288
8289         testdir1_size=$(order_2 $testdir1_size)
8290         testdir2_size=$(order_2 $testdir2_size)
8291
8292         testdir1_size=$(size_in_KMGT $testdir1_size)
8293         testdir2_size=$(size_in_KMGT $testdir2_size)
8294
8295         echo "source rename dir size: ${testdir1_size}"
8296         echo "target rename dir size: ${testdir2_size}"
8297
8298     local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
8299     eval $cmd || error "$cmd failed"
8300     local samedir=$($cmd | grep 'same_dir')
8301     local same_sample=$(get_rename_size $testdir1_size)
8302     [ -z "$samedir" ] && error "samedir_rename_size count error"
8303     [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
8304     echo "Check same dir rename stats success"
8305
8306     do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8307
8308     # check crossdir rename size
8309     mv ${testdir1}/test_0 ${testdir2}/test_0
8310
8311         testdir1_size=$(ls -l $DIR/${tdir} |
8312                 awk '/stats_testdir1/ {print $5}')
8313         testdir2_size=$(ls -l $DIR/${tdir} |
8314                 awk '/stats_testdir2/ {print $5}')
8315
8316         testdir1_size=$(order_2 $testdir1_size)
8317         testdir2_size=$(order_2 $testdir2_size)
8318
8319         testdir1_size=$(size_in_KMGT $testdir1_size)
8320         testdir2_size=$(size_in_KMGT $testdir2_size)
8321
8322         echo "source rename dir size: ${testdir1_size}"
8323         echo "target rename dir size: ${testdir2_size}"
8324
8325     eval $cmd || error "$cmd failed"
8326     local crossdir=$($cmd | grep 'crossdir')
8327     local src_sample=$(get_rename_size $testdir1_size crossdir_src)
8328     local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
8329     [ -z "$crossdir" ] && error "crossdir_rename_size count error"
8330     [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
8331     [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
8332     echo "Check cross dir rename stats success"
8333     rm -rf $DIR/${tdir}
8334 }
8335 run_test 133d "Verifying rename_stats ========================================"
8336
8337 test_133e() {
8338         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8339         local testdir=$DIR/${tdir}/stats_testdir
8340         local ctr f0 f1 bs=32768 count=42 sum
8341
8342         remote_ost_nodsh && skip "remote OST with nodsh" && return
8343         mkdir -p ${testdir} || error "mkdir failed"
8344
8345         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8346
8347         for ctr in {write,read}_bytes; do
8348                 sync
8349                 cancel_lru_locks osc
8350
8351                 do_facet ost1 $LCTL set_param -n \
8352                         "obdfilter.*.exports.clear=clear"
8353
8354                 if [ $ctr = write_bytes ]; then
8355                         f0=/dev/zero
8356                         f1=${testdir}/${tfile}
8357                 else
8358                         f0=${testdir}/${tfile}
8359                         f1=/dev/null
8360                 fi
8361
8362                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
8363                         error "dd failed"
8364                 sync
8365                 cancel_lru_locks osc
8366
8367                 sum=$(do_facet ost1 $LCTL get_param \
8368                                 "obdfilter.*.exports.*.stats" | \
8369                           awk -v ctr=$ctr '\
8370                                 BEGIN { sum = 0 }
8371                                 $1 == ctr { sum += $7 }
8372                                 END { print sum }')
8373
8374                 if ((sum != bs * count)); then
8375                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
8376                 fi
8377         done
8378
8379         rm -rf $DIR/${tdir}
8380 }
8381 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
8382
8383 test_133f() {
8384         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8385         local facet
8386
8387         # First without trusting modes.
8388         find $proc_dirs \
8389                 -exec cat '{}' \; &> /dev/null
8390
8391         # Second verifying readability.
8392         find $proc_dirs \
8393                 -type f \
8394                 -readable \
8395                 -exec cat '{}' \; > /dev/null ||
8396                         error "proc file read failed"
8397
8398         for facet in $SINGLEMDS ost1; do
8399                 do_facet $facet find $proc_dirs \
8400                         -not -name req_history \
8401                         -exec cat '{}' \\\; &> /dev/null
8402
8403             do_facet $facet     find $proc_dirs \
8404                         -not -name req_history \
8405                         -type f \
8406                         -readable \
8407                         -exec cat '{}' \\\; > /dev/null ||
8408                                 error "proc file read failed"
8409         done
8410 }
8411 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
8412
8413 test_140() { #bug-17379
8414         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8415         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
8416         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
8417         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
8418
8419         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
8420         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
8421         local i=0
8422         while i=`expr $i + 1`; do
8423                 test_mkdir -p $i || error "Creating dir $i"
8424                 cd $i || error "Changing to $i"
8425                 ln -s ../stat stat || error "Creating stat symlink"
8426                 # Read the symlink until ELOOP present,
8427                 # not LBUGing the system is considered success,
8428                 # we didn't overrun the stack.
8429                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
8430                 [ $ret -ne 0 ] && {
8431                         if [ $ret -eq 40 ]; then
8432                                 break  # -ELOOP
8433                         else
8434                                 error "Open stat symlink"
8435                                 return
8436                         fi
8437                 }
8438         done
8439         i=`expr $i - 1`
8440         echo "The symlink depth = $i"
8441         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
8442                                         error "Invalid symlink depth"
8443
8444         # Test recursive symlink
8445         ln -s symlink_self symlink_self
8446         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
8447         echo "open symlink_self returns $ret"
8448         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
8449 }
8450 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
8451
8452 test_150() {
8453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8454         local TF="$TMP/$tfile"
8455
8456         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8457         cp $TF $DIR/$tfile
8458         cancel_lru_locks osc
8459         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
8460         remount_client $MOUNT
8461         df -P $MOUNT
8462         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
8463
8464         $TRUNCATE $TF 6000
8465         $TRUNCATE $DIR/$tfile 6000
8466         cancel_lru_locks osc
8467         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
8468
8469         echo "12345" >>$TF
8470         echo "12345" >>$DIR/$tfile
8471         cancel_lru_locks osc
8472         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
8473
8474         echo "12345" >>$TF
8475         echo "12345" >>$DIR/$tfile
8476         cancel_lru_locks osc
8477         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
8478
8479         rm -f $TF
8480         true
8481 }
8482 run_test 150 "truncate/append tests"
8483
8484 function roc_hit() {
8485         local list=$(comma_list $(osts_nodes))
8486         #debug temp debug for LU-2902: lets see what values we get back
8487         echo $(get_osd_param $list '' stats) 1>&2
8488         echo $(get_osd_param $list '' stats |
8489                awk '/'cache_hit'/ {sum+=$2} END {print sum}')
8490 }
8491
8492 function set_cache() {
8493         local on=1
8494
8495         if [ "$2" == "off" ]; then
8496                 on=0;
8497         fi
8498         local list=$(comma_list $(osts_nodes))
8499         set_osd_param $list '' $1_cache_enable $on
8500
8501         cancel_lru_locks osc
8502 }
8503
8504 test_151() {
8505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8506         remote_ost_nodsh && skip "remote OST with nodsh" && return
8507
8508         local CPAGES=3
8509         local list=$(comma_list $(osts_nodes))
8510
8511         # check whether obdfilter is cache capable at all
8512         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
8513                 echo "not cache-capable obdfilter"
8514                 return 0
8515         fi
8516
8517         # check cache is enabled on all obdfilters
8518         if get_osd_param $list '' read_cache_enable | grep 0; then
8519                 echo "oss cache is disabled"
8520                 return 0
8521         fi
8522
8523         set_osd_param $list '' writethrough_cache_enable 1
8524
8525         # check write cache is enabled on all obdfilters
8526         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
8527                 echo "oss write cache is NOT enabled"
8528                 return 0
8529         fi
8530
8531 #define OBD_FAIL_OBD_NO_LRU  0x609
8532         do_nodes $list $LCTL set_param fail_loc=0x609
8533
8534         # pages should be in the case right after write
8535         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
8536                 error "dd failed"
8537
8538         local BEFORE=`roc_hit`
8539         cancel_lru_locks osc
8540         cat $DIR/$tfile >/dev/null
8541         local AFTER=`roc_hit`
8542
8543         do_nodes $list $LCTL set_param fail_loc=0
8544
8545         if ! let "AFTER - BEFORE == CPAGES"; then
8546                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8547         fi
8548
8549         # the following read invalidates the cache
8550         cancel_lru_locks osc
8551         set_osd_param $list '' read_cache_enable 0
8552         cat $DIR/$tfile >/dev/null
8553
8554         # now data shouldn't be found in the cache
8555         BEFORE=`roc_hit`
8556         cancel_lru_locks osc
8557         cat $DIR/$tfile >/dev/null
8558         AFTER=`roc_hit`
8559         if let "AFTER - BEFORE != 0"; then
8560                 error "IN CACHE: before: $BEFORE, after: $AFTER"
8561         fi
8562
8563         set_osd_param $list '' read_cache_enable 1
8564         rm -f $DIR/$tfile
8565 }
8566 run_test 151 "test cache on oss and controls ==============================="
8567
8568 test_152() {
8569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8570         local TF="$TMP/$tfile"
8571
8572         # simulate ENOMEM during write
8573 #define OBD_FAIL_OST_NOMEM      0x226
8574         lctl set_param fail_loc=0x80000226
8575         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8576         cp $TF $DIR/$tfile
8577         sync || error "sync failed"
8578         lctl set_param fail_loc=0
8579
8580         # discard client's cache
8581         cancel_lru_locks osc
8582
8583         # simulate ENOMEM during read
8584         lctl set_param fail_loc=0x80000226
8585         cmp $TF $DIR/$tfile || error "cmp failed"
8586         lctl set_param fail_loc=0
8587
8588         rm -f $TF
8589 }
8590 run_test 152 "test read/write with enomem ============================"
8591
8592 test_153() {
8593         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
8594 }
8595 run_test 153 "test if fdatasync does not crash ======================="
8596
8597 dot_lustre_fid_permission_check() {
8598         local fid=$1
8599         local ffid=$MOUNT/.lustre/fid/$fid
8600         local test_dir=$2
8601
8602         echo "stat fid $fid"
8603         stat $ffid > /dev/null || error "stat $ffid failed."
8604         echo "touch fid $fid"
8605         touch $ffid || error "touch $ffid failed."
8606         echo "write to fid $fid"
8607         cat /etc/hosts > $ffid || error "write $ffid failed."
8608         echo "read fid $fid"
8609         diff /etc/hosts $ffid || error "read $ffid failed."
8610         echo "append write to fid $fid"
8611         cat /etc/hosts >> $ffid || error "append write $ffid failed."
8612         echo "rename fid $fid"
8613         mv $ffid $test_dir/$tfile.1 &&
8614                 error "rename $ffid to $tfile.1 should fail."
8615         touch $test_dir/$tfile.1
8616         mv $test_dir/$tfile.1 $ffid &&
8617                 error "rename $tfile.1 to $ffid should fail."
8618         rm -f $test_dir/$tfile.1
8619         echo "truncate fid $fid"
8620         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
8621         echo "link fid $fid"
8622         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
8623         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
8624                 echo "setfacl fid $fid"
8625                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
8626                 echo "getfacl fid $fid"
8627                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
8628         fi
8629         echo "unlink fid $fid"
8630         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
8631         echo "mknod fid $fid"
8632         mknod $ffid c 1 3 && error "mknod $ffid should fail."
8633
8634         fid=[0xf00000400:0x1:0x0]
8635         ffid=$MOUNT/.lustre/fid/$fid
8636
8637         echo "stat non-exist fid $fid"
8638         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
8639         echo "write to non-exist fid $fid"
8640         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
8641         echo "link new fid $fid"
8642         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
8643
8644         mkdir -p $test_dir/$tdir
8645         touch $test_dir/$tdir/$tfile
8646         fid=$($LFS path2fid $test_dir/$tdir)
8647         rc=$?
8648         [ $rc -ne 0 ] &&
8649                 error "error: could not get fid for $test_dir/$dir/$tfile."
8650
8651         ffid=$MOUNT/.lustre/fid/$fid
8652
8653         echo "ls $fid"
8654         ls $ffid > /dev/null || error "ls $ffid failed."
8655         echo "touch $fid/$tfile.1"
8656         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
8657
8658         echo "touch $MOUNT/.lustre/fid/$tfile"
8659         touch $MOUNT/.lustre/fid/$tfile && \
8660                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
8661
8662         echo "setxattr to $MOUNT/.lustre/fid"
8663         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid &&
8664                 error "setxattr should fail."
8665
8666         echo "listxattr for $MOUNT/.lustre/fid"
8667         getfattr -d -m "^trusted" $MOUNT/.lustre/fid &&
8668                 error "listxattr should fail."
8669
8670         echo "delxattr from $MOUNT/.lustre/fid"
8671         setfattr -x trusted.name1 $MOUNT/.lustre/fid &&
8672                 error "delxattr should fail."
8673
8674         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
8675         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
8676                 error "touch invalid fid should fail."
8677
8678         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
8679         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
8680                 error "touch non-normal fid should fail."
8681
8682         echo "rename $tdir to $MOUNT/.lustre/fid"
8683         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
8684                 error "rename to $MOUNT/.lustre/fid should fail."
8685
8686         echo "rename .lustre to itself"
8687         fid=$($LFS path2fid $MOUNT)
8688         mrename $MOUNT/.lustre $MOUNT/.lustre/fid/$fid/.lustre &&
8689                 error "rename .lustre to itself should fail."
8690
8691         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
8692         fid=$($LFS path2fid $test_dir/$tfile-2)
8693         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
8694         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
8695                 error "create lov data thru .lustre should fail."
8696         echo "cp /etc/passwd $test_dir/$tfile-2"
8697         cp /etc/passwd $test_dir/$tfile-2 ||
8698                 error "copy to $test_dir/$tfile-2 failed."
8699         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
8700         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
8701                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
8702
8703         rm -rf $test_dir/tfile.lnk
8704         rm -rf $test_dir/$tfile-2
8705 }
8706
8707 test_154a() {
8708         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8709         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
8710                 { skip "Need MDS version at least 2.2.51"; return 0; }
8711
8712         cp /etc/hosts $DIR/$tfile
8713
8714         fid=$($LFS path2fid $DIR/$tfile)
8715         rc=$?
8716         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
8717
8718         dot_lustre_fid_permission_check "$fid" $DIR ||
8719                 error "dot lustre permission check $fid failed"
8720
8721         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
8722         chmod 777 $MOUNT/.lustre && error ".lustre is not allowed to be chmod"
8723
8724         touch $MOUNT/.lustre/file &&
8725                 error "creation is not allowed under .lustre"
8726
8727         mkdir $MOUNT/.lustre/dir &&
8728                 error "mkdir is not allowed under .lustre"
8729
8730         rm -rf $DIR/$tfile
8731 }
8732 run_test 154a "Open-by-FID"
8733
8734 test_154b() {
8735         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8736         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
8737                 { skip "Need MDS version at least 2.2.51"; return 0; }
8738
8739         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
8740
8741         local remote_dir=$DIR/$tdir/remote_dir
8742         local MDTIDX=1
8743         local rc=0
8744
8745         mkdir -p $DIR/$tdir
8746         $LFS mkdir -i $MDTIDX $remote_dir ||
8747                 error "create remote directory failed"
8748
8749         cp /etc/hosts $remote_dir/$tfile
8750
8751         fid=$($LFS path2fid $remote_dir/$tfile)
8752         rc=$?
8753         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
8754
8755         dot_lustre_fid_permission_check "$fid" $remote_dir ||
8756                 error "dot lustre permission check $fid failed"
8757         rm -rf $DIR/$tdir
8758 }
8759 run_test 154b "Open-by-FID for remote directory"
8760
8761 test_155_small_load() {
8762     local temp=$TMP/$tfile
8763     local file=$DIR/$tfile
8764
8765     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
8766         error "dd of=$temp bs=6096 count=1 failed"
8767     cp $temp $file
8768     cancel_lru_locks osc
8769     cmp $temp $file || error "$temp $file differ"
8770
8771     $TRUNCATE $temp 6000
8772     $TRUNCATE $file 6000
8773     cmp $temp $file || error "$temp $file differ (truncate1)"
8774
8775     echo "12345" >>$temp
8776     echo "12345" >>$file
8777     cmp $temp $file || error "$temp $file differ (append1)"
8778
8779     echo "12345" >>$temp
8780     echo "12345" >>$file
8781     cmp $temp $file || error "$temp $file differ (append2)"
8782
8783     rm -f $temp $file
8784     true
8785 }
8786
8787 test_155_big_load() {
8788     remote_ost_nodsh && skip "remote OST with nodsh" && return
8789     local temp=$TMP/$tfile
8790     local file=$DIR/$tfile
8791
8792     free_min_max
8793     local cache_size=$(do_facet ost$((MAXI+1)) \
8794         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
8795     local large_file_size=$((cache_size * 2))
8796
8797     echo "OSS cache size: $cache_size KB"
8798     echo "Large file size: $large_file_size KB"
8799
8800     [ $MAXV -le $large_file_size ] && \
8801         skip_env "max available OST size needs > $large_file_size KB" && \
8802         return 0
8803
8804     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
8805
8806     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
8807         error "dd of=$temp bs=$large_file_size count=1k failed"
8808     cp $temp $file
8809     ls -lh $temp $file
8810     cancel_lru_locks osc
8811     cmp $temp $file || error "$temp $file differ"
8812
8813     rm -f $temp $file
8814     true
8815 }
8816
8817 test_155a() {
8818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8819         set_cache read on
8820         set_cache writethrough on
8821         test_155_small_load
8822 }
8823 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
8824
8825 test_155b() {
8826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8827         set_cache read on
8828         set_cache writethrough off
8829         test_155_small_load
8830 }
8831 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
8832
8833 test_155c() {
8834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8835         set_cache read off
8836         set_cache writethrough on
8837         test_155_small_load
8838 }
8839 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
8840
8841 test_155d() {
8842         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8843         set_cache read off
8844         set_cache writethrough off
8845         test_155_small_load
8846 }
8847 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
8848
8849 test_155e() {
8850         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8851         set_cache read on
8852         set_cache writethrough on
8853         test_155_big_load
8854 }
8855 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
8856
8857 test_155f() {
8858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8859         set_cache read on
8860         set_cache writethrough off
8861         test_155_big_load
8862 }
8863 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
8864
8865 test_155g() {
8866         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8867         set_cache read off
8868         set_cache writethrough on
8869         test_155_big_load
8870 }
8871 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
8872
8873 test_155h() {
8874         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8875         set_cache read off
8876         set_cache writethrough off
8877         test_155_big_load
8878 }
8879 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
8880
8881 test_156() {
8882         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8883         local CPAGES=3
8884         local BEFORE
8885         local AFTER
8886         local file="$DIR/$tfile"
8887
8888         [ "$(facet_fstype ost1)" = "zfs" ] &&
8889                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
8890                 return
8891
8892     log "Turn on read and write cache"
8893     set_cache read on
8894     set_cache writethrough on
8895
8896     log "Write data and read it back."
8897     log "Read should be satisfied from the cache."
8898     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8899     BEFORE=`roc_hit`
8900     cancel_lru_locks osc
8901     cat $file >/dev/null
8902     AFTER=`roc_hit`
8903     if ! let "AFTER - BEFORE == CPAGES"; then
8904         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8905     else
8906         log "cache hits:: before: $BEFORE, after: $AFTER"
8907     fi
8908
8909     log "Read again; it should be satisfied from the cache."
8910     BEFORE=$AFTER
8911     cancel_lru_locks osc
8912     cat $file >/dev/null
8913     AFTER=`roc_hit`
8914     if ! let "AFTER - BEFORE == CPAGES"; then
8915         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8916     else
8917         log "cache hits:: before: $BEFORE, after: $AFTER"
8918     fi
8919
8920
8921     log "Turn off the read cache and turn on the write cache"
8922     set_cache read off
8923     set_cache writethrough on
8924
8925     log "Read again; it should be satisfied from the cache."
8926     BEFORE=`roc_hit`
8927     cancel_lru_locks osc
8928     cat $file >/dev/null
8929     AFTER=`roc_hit`
8930     if ! let "AFTER - BEFORE == CPAGES"; then
8931         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8932     else
8933         log "cache hits:: before: $BEFORE, after: $AFTER"
8934     fi
8935
8936     log "Read again; it should not be satisfied from the cache."
8937     BEFORE=$AFTER
8938     cancel_lru_locks osc
8939     cat $file >/dev/null
8940     AFTER=`roc_hit`
8941     if ! let "AFTER - BEFORE == 0"; then
8942         error "IN CACHE: before: $BEFORE, after: $AFTER"
8943     else
8944         log "cache hits:: before: $BEFORE, after: $AFTER"
8945     fi
8946
8947     log "Write data and read it back."
8948     log "Read should be satisfied from the cache."
8949     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8950     BEFORE=`roc_hit`
8951     cancel_lru_locks osc
8952     cat $file >/dev/null
8953     AFTER=`roc_hit`
8954     if ! let "AFTER - BEFORE == CPAGES"; then
8955         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8956     else
8957         log "cache hits:: before: $BEFORE, after: $AFTER"
8958     fi
8959
8960     log "Read again; it should not be satisfied from the cache."
8961     BEFORE=$AFTER
8962     cancel_lru_locks osc
8963     cat $file >/dev/null
8964     AFTER=`roc_hit`
8965     if ! let "AFTER - BEFORE == 0"; then
8966         error "IN CACHE: before: $BEFORE, after: $AFTER"
8967     else
8968         log "cache hits:: before: $BEFORE, after: $AFTER"
8969     fi
8970
8971
8972     log "Turn off read and write cache"
8973     set_cache read off
8974     set_cache writethrough off
8975
8976     log "Write data and read it back"
8977     log "It should not be satisfied from the cache."
8978     rm -f $file
8979     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8980     cancel_lru_locks osc
8981     BEFORE=`roc_hit`
8982     cat $file >/dev/null
8983     AFTER=`roc_hit`
8984     if ! let "AFTER - BEFORE == 0"; then
8985         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
8986     else
8987         log "cache hits:: before: $BEFORE, after: $AFTER"
8988     fi
8989
8990
8991     log "Turn on the read cache and turn off the write cache"
8992     set_cache read on
8993     set_cache writethrough off
8994
8995     log "Write data and read it back"
8996     log "It should not be satisfied from the cache."
8997     rm -f $file
8998     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
8999     BEFORE=`roc_hit`
9000     cancel_lru_locks osc
9001     cat $file >/dev/null
9002     AFTER=`roc_hit`
9003     if ! let "AFTER - BEFORE == 0"; then
9004         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9005     else
9006         log "cache hits:: before: $BEFORE, after: $AFTER"
9007     fi
9008
9009     log "Read again; it should be satisfied from the cache."
9010     BEFORE=`roc_hit`
9011     cancel_lru_locks osc
9012     cat $file >/dev/null
9013     AFTER=`roc_hit`
9014     if ! let "AFTER - BEFORE == CPAGES"; then
9015         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9016     else
9017         log "cache hits:: before: $BEFORE, after: $AFTER"
9018     fi
9019
9020     rm -f $file
9021 }
9022 run_test 156 "Verification of tunables ============================"
9023
9024 #Changelogs
9025 err17935 () {
9026     if [ $MDSCOUNT -gt 1 ]; then
9027         error_ignore 17935 $*
9028     else
9029         error $*
9030     fi
9031 }
9032
9033 changelog_chmask()
9034 {
9035     MASK=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_mask |\
9036            grep -c $1)
9037
9038     if [ $MASK -eq 1 ]; then
9039         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="-$1"
9040     else
9041         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="+$1"
9042     fi
9043 }
9044
9045 test_160() {
9046         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9047     remote_mds_nodsh && skip "remote MDS with nodsh" && return
9048     [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9049         { skip "Need MDS version at least 2.2.0"; return; }
9050     USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9051     echo "Registered as changelog user $USER"
9052     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
9053         grep -q $USER || error "User $USER not found in changelog_users"
9054
9055     # change something
9056     test_mkdir -p $DIR/$tdir/pics/2008/zachy
9057     touch $DIR/$tdir/pics/2008/zachy/timestamp
9058     cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9059     mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9060     ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9061     ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9062     rm $DIR/$tdir/pics/desktop.jpg
9063
9064     $LFS changelog $MDT0 | tail -5
9065
9066     echo "verifying changelog mask"
9067     changelog_chmask "MKDIR"
9068     changelog_chmask "CLOSE"
9069
9070     test_mkdir -p $DIR/$tdir/pics/zach/sofia
9071     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9072
9073     changelog_chmask "MKDIR"
9074     changelog_chmask "CLOSE"
9075
9076     test_mkdir -p $DIR/$tdir/pics/2008/sofia
9077     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9078
9079     $LFS changelog $MDT0
9080     MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9081     CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9082     [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9083     [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9084
9085     # verify contents
9086     echo "verifying target fid"
9087     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
9088         tail -1 | awk '{print $6}')
9089     fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9090     [ "$fidc" == "t=$fidf" ] || \
9091         err17935 "fid in changelog $fidc != file fid $fidf"
9092     echo "verifying parent fid"
9093     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
9094         tail -1 | awk '{print $7}')
9095     fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9096     [ "$fidc" == "p=$fidf" ] || \
9097         err17935 "pfid in changelog $fidc != dir fid $fidf"
9098
9099     USER_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
9100         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
9101     $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9102     USER_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
9103         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
9104     echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9105     [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \
9106         err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2"
9107
9108     MIN_REC=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_users | \
9109         awk 'min == "" || $2 < min {min = $2}; END {print min}')
9110     FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
9111     echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9112     [ $FIRST_REC == $(($MIN_REC + 1)) ] || \
9113         err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC"
9114
9115     echo "verifying user deregister"
9116     do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9117     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
9118         grep -q $USER && error "User $USER still found in changelog_users"
9119
9120     USERS=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
9121         mdd.$MDT0.changelog_users | wc -l) - 2 ))
9122     if [ $USERS -eq 0 ]; then
9123         LAST_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
9124             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
9125         touch $DIR/$tdir/chloe
9126         LAST_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
9127             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
9128         echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2"
9129         [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
9130     else
9131         echo "$USERS other changelog users; can't verify off"
9132     fi
9133 }
9134 run_test 160 "changelog sanity"
9135
9136 test_161a() {
9137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9138     test_mkdir -p $DIR/$tdir
9139     cp /etc/hosts $DIR/$tdir/$tfile
9140     test_mkdir $DIR/$tdir/foo1
9141     test_mkdir $DIR/$tdir/foo2
9142     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
9143     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
9144     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
9145     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
9146         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
9147         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9148                 $LFS fid2path $DIR $FID
9149                 err17935 "bad link ea"
9150         fi
9151     # middle
9152     rm $DIR/$tdir/foo2/zachary
9153     # last
9154     rm $DIR/$tdir/foo2/thor
9155     # first
9156     rm $DIR/$tdir/$tfile
9157     # rename
9158     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
9159     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
9160         then
9161         $LFS fid2path $DIR $FID
9162         err17935 "bad link rename"
9163     fi
9164     rm $DIR/$tdir/foo2/maggie
9165
9166     # overflow the EA
9167     local longname=filename_avg_len_is_thirty_two_
9168     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
9169         error "failed to hardlink many files"
9170     links=$($LFS fid2path $DIR $FID | wc -l)
9171     echo -n "${links}/1000 links in link EA"
9172     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9173     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
9174         error "failed to unlink many hardlinks"
9175 }
9176 run_test 161a "link ea sanity"
9177
9178 test_161b() {
9179         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9180         [ $MDSCOUNT -lt 2 ] &&
9181                 skip "skipping remote directory test" && return
9182         local MDTIDX=1
9183         local remote_dir=$DIR/$tdir/remote_dir
9184
9185         mkdir -p $DIR/$tdir
9186         $LFS mkdir -i $MDTIDX $remote_dir ||
9187                 error "create remote directory failed"
9188
9189         cp /etc/hosts $remote_dir/$tfile
9190         mkdir -p $remote_dir/foo1
9191         mkdir -p $remote_dir/foo2
9192         ln $remote_dir/$tfile $remote_dir/foo1/sofia
9193         ln $remote_dir/$tfile $remote_dir/foo2/zachary
9194         ln $remote_dir/$tfile $remote_dir/foo1/luna
9195         ln $remote_dir/$tfile $remote_dir/foo2/thor
9196
9197         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
9198                      tr -d ']')
9199         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9200                 $LFS fid2path $DIR $FID
9201                 err17935 "bad link ea"
9202         fi
9203         # middle
9204         rm $remote_dir/foo2/zachary
9205         # last
9206         rm $remote_dir/foo2/thor
9207         # first
9208         rm $remote_dir/$tfile
9209         # rename
9210         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
9211         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
9212         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
9213                 $LFS fid2path $DIR $FID
9214                 err17935 "bad link rename"
9215         fi
9216         rm $remote_dir/foo2/maggie
9217
9218         # overflow the EA
9219         local longname=filename_avg_len_is_thirty_two_
9220         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
9221                 error "failed to hardlink many files"
9222         links=$($LFS fid2path $DIR $FID | wc -l)
9223         echo -n "${links}/1000 links in link EA"
9224         [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9225         unlinkmany $remote_dir/foo2/$longname 1000 ||
9226         error "failed to unlink many hardlinks"
9227 }
9228 run_test 161b "link ea sanity under remote directory"
9229
9230 check_path() {
9231     local expected=$1
9232     shift
9233     local fid=$2
9234
9235     local path=$(${LFS} fid2path $*)
9236     RC=$?
9237
9238     if [ $RC -ne 0 ]; then
9239         err17935 "path looked up of $expected failed. Error $RC"
9240         return $RC
9241     elif [ "${path}" != "${expected}" ]; then
9242         err17935 "path looked up \"${path}\" instead of \"${expected}\""
9243         return 2
9244     fi
9245     echo "fid $fid resolves to path $path (expected $expected)"
9246 }
9247
9248 test_162() {
9249         # Make changes to filesystem
9250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9251         test_mkdir -p $DIR/$tdir/d2
9252         touch $DIR/$tdir/d2/$tfile
9253         touch $DIR/$tdir/d2/x1
9254         touch $DIR/$tdir/d2/x2
9255         test_mkdir -p $DIR/$tdir/d2/a/b/c
9256         test_mkdir -p $DIR/$tdir/d2/p/q/r
9257         # regular file
9258         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
9259         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
9260
9261         # softlink
9262         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
9263         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
9264         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
9265
9266         # softlink to wrong file
9267         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
9268         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
9269         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
9270
9271         # hardlink
9272         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
9273         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
9274         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
9275         # fid2path dir/fsname should both work
9276         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
9277         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
9278
9279         # hardlink count: check that there are 2 links
9280         # Doesnt work with CMD yet: 17935
9281         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
9282                 err17935 "expected 2 links"
9283
9284         # hardlink indexing: remove the first link
9285         rm $DIR/$tdir/d2/p/q/r/hlink
9286         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
9287
9288         return 0
9289 }
9290 run_test 162 "path lookup sanity"
9291
9292 test_163() {
9293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9294         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9295         copytool --test $FSNAME || { skip "copytool not runnable: $?" && return; }
9296         copytool $FSNAME &
9297         sleep 1
9298         local uuid=$($LCTL get_param -n mdc.${FSNAME}-MDT0000-mdc-*.uuid)
9299         # this proc file is temporary and linux-only
9300         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT0000.mdccomm=$uuid ||\
9301          error "kernel->userspace send failed"
9302         kill -INT $!
9303 }
9304 run_test 163 "kernel <-> userspace comms"
9305
9306 test_169() {
9307         # do directio so as not to populate the page cache
9308         log "creating a 10 Mb file"
9309         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
9310         log "starting reads"
9311         dd if=$DIR/$tfile of=/dev/null bs=4096 &
9312         log "truncating the file"
9313         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
9314         log "killing dd"
9315         kill %+ || true # reads might have finished
9316         echo "wait until dd is finished"
9317         wait
9318         log "removing the temporary file"
9319         rm -rf $DIR/$tfile || error "tmp file removal failed"
9320 }
9321 run_test 169 "parallel read and truncate should not deadlock"
9322
9323 test_170() {
9324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9325         $LCTL clear     # bug 18514
9326         $LCTL debug_daemon start $TMP/${tfile}_log_good
9327         touch $DIR/$tfile
9328         $LCTL debug_daemon stop
9329         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
9330                error "sed failed to read log_good"
9331
9332         $LCTL debug_daemon start $TMP/${tfile}_log_good
9333         rm -rf $DIR/$tfile
9334         $LCTL debug_daemon stop
9335
9336         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
9337                error "lctl df log_bad failed"
9338
9339         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
9340         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
9341
9342         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
9343         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
9344
9345         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
9346                 error "bad_line good_line1 good_line2 are empty"
9347
9348         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
9349         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
9350         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
9351
9352         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
9353         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
9354         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
9355
9356         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
9357                 error "bad_line_new good_line_new are empty"
9358
9359         local expected_good=$((good_line1 + good_line2*2))
9360
9361         rm -f $TMP/${tfile}*
9362         # LU-231, short malformed line may not be counted into bad lines
9363         if [ $bad_line -ne $bad_line_new ] &&
9364                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
9365                 error "expected $bad_line bad lines, but got $bad_line_new"
9366                 return 1
9367         fi
9368
9369         if [ $expected_good -ne $good_line_new ]; then
9370                 error "expected $expected_good good lines, but got $good_line_new"
9371                 return 2
9372         fi
9373         true
9374 }
9375 run_test 170 "test lctl df to handle corrupted log ====================="
9376
9377 test_171() { # bug20592
9378         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9379 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
9380         $LCTL set_param fail_loc=0x50e
9381         $LCTL set_param fail_val=3000
9382         multiop_bg_pause $DIR/$tfile O_s || true
9383         local MULTIPID=$!
9384         kill -USR1 $MULTIPID
9385         # cause log dump
9386         sleep 3
9387         wait $MULTIPID
9388         if dmesg | grep "recursive fault"; then
9389                 error "caught a recursive fault"
9390         fi
9391         $LCTL set_param fail_loc=0
9392         true
9393 }
9394 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
9395
9396 # it would be good to share it with obdfilter-survey/libecho code
9397 setup_obdecho_osc () {
9398         local rc=0
9399         local ost_nid=$1
9400         local obdfilter_name=$2
9401         echo "Creating new osc for $obdfilter_name on $ost_nid"
9402         # make sure we can find loopback nid
9403         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
9404
9405         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
9406                            ${obdfilter_name}_osc_UUID || rc=2; }
9407         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
9408                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
9409         return $rc
9410 }
9411
9412 cleanup_obdecho_osc () {
9413         local obdfilter_name=$1
9414         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
9415         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
9416         return 0
9417 }
9418
9419 obdecho_create_test() {
9420         local OBD=$1
9421         local node=$2
9422         local rc=0
9423         local id
9424         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
9425         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
9426                            rc=2; }
9427         if [ $rc -eq 0 ]; then
9428             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
9429             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
9430         fi
9431         echo "New object id is $id"
9432         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec test_brw 10 w v 64 $id" ||
9433                            rc=4; }
9434         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
9435                                         "cleanup" || rc=5; }
9436         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
9437                                         "detach" || rc=6; }
9438         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
9439         return $rc
9440 }
9441
9442 test_180a() {
9443         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9444         remote_ost_nodsh && skip "remote OST with nodsh" && return
9445         local rc=0
9446         local rmmod_local=0
9447
9448         if ! module_loaded obdecho; then
9449             load_module obdecho/obdecho
9450             rmmod_local=1
9451         fi
9452
9453         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
9454         local host=$(lctl get_param -n osc.$osc.import |
9455                              awk '/current_connection:/ {print $2}' )
9456         local target=$(lctl get_param -n osc.$osc.import |
9457                              awk '/target:/ {print $2}' )
9458         target=${target%_UUID}
9459
9460         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
9461         [ $rc -eq 0 ] && { obdecho_create_test ${target}_osc client || rc=2; }
9462         [[ -n $target ]] && cleanup_obdecho_osc $target
9463         [ $rmmod_local -eq 1 ] && rmmod obdecho
9464         return $rc
9465 }
9466 run_test 180a "test obdecho on osc"
9467
9468 test_180b() {
9469         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9470         remote_ost_nodsh && skip "remote OST with nodsh" && return
9471         local rc=0
9472         local rmmod_remote=0
9473
9474         do_facet ost1 "lsmod | grep -q obdecho || "                      \
9475                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
9476                       "modprobe obdecho; }" && rmmod_remote=1
9477         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
9478         [[ -n $target ]] && { obdecho_create_test $target ost1 || rc=1; }
9479         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
9480         return $rc
9481 }
9482 run_test 180b "test obdecho directly on obdfilter"
9483
9484 test_181() { # bug 22177
9485         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9486         # create enough files to index the directory
9487         createmany -o $DIR/$tdir/foobar 4000
9488         # print attributes for debug purpose
9489         lsattr -d .
9490         # open dir
9491         multiop_bg_pause $DIR/$tdir D_Sc || return 1
9492         MULTIPID=$!
9493         # remove the files & current working dir
9494         unlinkmany $DIR/$tdir/foobar 4000
9495         rmdir $DIR/$tdir
9496         kill -USR1 $MULTIPID
9497         wait $MULTIPID
9498         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
9499         return 0
9500 }
9501 run_test 181 "Test open-unlinked dir ========================"
9502
9503 test_182() {
9504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9505         # disable MDC RPC lock wouldn't crash client
9506         local fcount=1000
9507         local tcount=4
9508
9509         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9510 #define OBD_FAIL_MDC_RPCS_SEM           0x804
9511         $LCTL set_param fail_loc=0x804
9512
9513         for (( i=0; i < $tcount; i++ )) ; do
9514                 mkdir $DIR/$tdir/$i
9515                 createmany -o $DIR/$tdir/$i/f- $fcount &
9516         done
9517         wait
9518
9519         for (( i=0; i < $tcount; i++ )) ; do
9520                 unlinkmany $DIR/$tdir/$i/f- $fcount &
9521         done
9522         wait
9523
9524         rm -rf $DIR/$tdir
9525
9526         $LCTL set_param fail_loc=0
9527 }
9528 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
9529
9530 test_183() { # LU-2275
9531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9532         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9533         echo aaa > $DIR/$tdir/$tfile
9534
9535 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
9536         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
9537
9538         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
9539         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
9540
9541         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
9542
9543         # Flush negative dentry cache
9544         touch $DIR/$tdir/$tfile
9545
9546         # We are not checking for any leaked references here, they'll
9547         # become evident next time we do cleanup with module unload.
9548         rm -rf $DIR/$tdir
9549 }
9550 run_test 183 "No crash or request leak in case of strange dispositions ========"
9551
9552 # test suite 184 is for LU-2016, LU-2017
9553 test_184a() {
9554         check_swap_layouts_support && return 0
9555
9556         dir0=$DIR/$tdir/$testnum
9557         test_mkdir -p $dir0 || error "creating dir $dir0"
9558         ref1=/etc/passwd
9559         ref2=/etc/group
9560         file1=$dir0/f1
9561         file2=$dir0/f2
9562         $SETSTRIPE -c1 $file1
9563         cp $ref1 $file1
9564         $SETSTRIPE -c2 $file2
9565         cp $ref2 $file2
9566         gen1=$($GETSTRIPE -g $file1)
9567         gen2=$($GETSTRIPE -g $file2)
9568
9569         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
9570         gen=$($GETSTRIPE -g $file1)
9571         [[ $gen1 != $gen ]] ||
9572                 "Layout generation on $file1 does not change"
9573         gen=$($GETSTRIPE -g $file2)
9574         [[ $gen2 != $gen ]] ||
9575                 "Layout generation on $file2 does not change"
9576
9577         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
9578         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
9579 }
9580 run_test 184a "Basic layout swap"
9581
9582 test_184b() {
9583         check_swap_layouts_support && return 0
9584
9585         dir0=$DIR/$tdir/$testnum
9586         mkdir -p $dir0 || error "creating dir $dir0"
9587         file1=$dir0/f1
9588         file2=$dir0/f2
9589         file3=$dir0/f3
9590         dir1=$dir0/d1
9591         dir2=$dir0/d2
9592         mkdir $dir1 $dir2
9593         $SETSTRIPE -c1 $file1
9594         $SETSTRIPE -c2 $file2
9595         $SETSTRIPE -c1 $file3
9596         chown $RUNAS_ID $file3
9597         gen1=$($GETSTRIPE -g $file1)
9598         gen2=$($GETSTRIPE -g $file2)
9599
9600         $LFS swap_layouts $dir1 $dir2 &&
9601                 error "swap of directories layouts should fail"
9602         $LFS swap_layouts $dir1 $file1 &&
9603                 error "swap of directory and file layouts should fail"
9604         $RUNAS $LFS swap_layouts $file1 $file2 &&
9605                 error "swap of file we cannot write should fail"
9606         $LFS swap_layouts $file1 $file3 &&
9607                 error "swap of file with different owner should fail"
9608         /bin/true # to clear error code
9609 }
9610 run_test 184b "Forbidden layout swap (will generate errors)"
9611
9612 test_184c() {
9613         check_swap_layouts_support && return 0
9614
9615         local dir0=$DIR/$tdir/$testnum
9616         mkdir -p $dir0 || error "creating dir $dir0"
9617
9618         local ref1=$dir0/ref1
9619         local ref2=$dir0/ref2
9620         local file1=$dir0/file1
9621         local file2=$dir0/file2
9622         # create a file large enough for the concurent test
9623         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
9624         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
9625         echo "ref file size: ref1(`stat -c %s $ref1`), ref2(`stat -c %s $ref2`)"
9626
9627         cp $ref2 $file2
9628         dd if=$ref1 of=$file1 bs=16k &
9629         local DD_PID=$!
9630
9631         # Make sure dd starts to copy file
9632         while [ ! -f $file1 ]; do sleep 0.1; done
9633
9634         $LFS swap_layouts $file1 $file2
9635         local rc=$?
9636         wait $DD_PID
9637         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
9638         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
9639
9640         # how many bytes copied before swapping layout
9641         local copied=`stat -c %s $file2`
9642         local remaining=`stat -c %s $ref1`
9643         remaining=$((remaining - copied))
9644         echo "Copied $copied bytes before swapping layout..."
9645
9646         cmp -n $copied $file1 $ref2 | grep differ &&
9647                 error "Content mismatch [0, $copied) of ref2 and file1"
9648         cmp -n $copied $file2 $ref1 ||
9649                 error "Content mismatch [0, $copied) of ref1 and file2"
9650         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
9651                 error "Content mismatch [$copied, EOF) of ref1 and file1"
9652
9653         # clean up
9654         rm -f $ref1 $ref2 $file1 $file2
9655 }
9656 run_test 184c "Concurrent write and layout swap"
9657
9658 test_185() { # LU-2441
9659         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9660         touch $DIR/$tdir/spoo
9661         local mtime1=$(stat -c "%Y" $DIR/$tdir)
9662         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
9663                 error "cannot create/write a volatile file"
9664         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
9665                 error "FID is still valid after close"
9666
9667         multiop_bg_pause $DIR/$tdir vVw4096_c
9668         local multi_pid=$!
9669
9670         local OLD_IFS=$IFS
9671         IFS=":"
9672         local fidv=($fid)
9673         IFS=$OLD_IFS
9674         # assume that the next FID for this client is sequential, since stdout
9675         # is unfortunately eaten by multiop_bg_pause
9676         local n=$((${fidv[1]} + 1))
9677         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
9678         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
9679                 error "FID is missing before close"
9680         kill -USR1 $multi_pid
9681         # 1 second delay, so if mtime change we will see it
9682         sleep 1
9683         local mtime2=$(stat -c "%Y" $DIR/$tdir)
9684         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
9685 }
9686 run_test 185 "Volatile file support"
9687
9688 # OST pools tests
9689 check_file_in_pool()
9690 {
9691         local file=$1
9692         local pool=$2
9693         local tlist="$3"
9694         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
9695         for i in $res
9696         do
9697                 for t in $tlist ; do
9698                         [ "$i" -eq "$t" ] && continue 2
9699                 done
9700
9701                 echo "pool list: $tlist"
9702                 echo "striping: $res"
9703                 error_noexit "$file not allocated in $pool"
9704                 return 1
9705         done
9706         return 0
9707 }
9708
9709 pool_add() {
9710         echo "Creating new pool"
9711         local pool=$1
9712
9713         create_pool $FSNAME.$pool ||
9714                 { error_noexit "No pool created, result code $?"; return 1; }
9715         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
9716                 { error_noexit "$pool not in lfs pool_list"; return 2; }
9717 }
9718
9719 pool_add_targets() {
9720         echo "Adding targets to pool"
9721         local pool=$1
9722         local first=$2
9723         local last=$3
9724         local step=${4:-1}
9725
9726         local list=$(seq $first $step $last)
9727
9728         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
9729         do_facet mgs $LCTL pool_add \
9730                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
9731         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
9732                         | sort -u | tr '\n' ' ' " "$t" || { 
9733                 error_noexit "Add to pool failed"
9734                 return 1
9735         }
9736         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
9737         local addcount=$(((last - first) / step + 1))
9738         [ $lfscount -eq $addcount ] || {
9739                 error_noexit "lfs pool_list bad ost count" \
9740                                                 "$lfscount != $addcount"
9741                 return 2
9742         }
9743 }
9744
9745 pool_set_dir() {
9746         local pool=$1
9747         local tdir=$2
9748         echo "Setting pool on directory $tdir"
9749
9750         $SETSTRIPE -c 2 -p $pool $tdir && return 0
9751
9752         error_noexit "Cannot set pool $pool to $tdir"
9753         return 1
9754 }
9755
9756 pool_check_dir() {
9757         local pool=$1
9758         local tdir=$2
9759         echo "Checking pool on directory $tdir"
9760
9761         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
9762         [ "$res" = "$pool" ] && return 0
9763
9764         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
9765         return 1
9766 }
9767
9768 pool_dir_rel_path() {
9769         echo "Testing relative path works well"
9770         local pool=$1
9771         local tdir=$2
9772         local root=$3
9773
9774         mkdir -p $root/$tdir/$tdir
9775         cd $root/$tdir
9776         pool_set_dir $pool $tdir          || return 1
9777         pool_set_dir $pool ./$tdir        || return 2
9778         pool_set_dir $pool ../$tdir       || return 3
9779         pool_set_dir $pool ../$tdir/$tdir || return 4
9780         rm -rf $tdir; cd - > /dev/null
9781 }
9782
9783 pool_alloc_files() {
9784         echo "Checking files allocation from directory pool"
9785         local pool=$1
9786         local tdir=$2
9787         local count=$3
9788         local tlist="$4"
9789
9790         local failed=0
9791         for i in $(seq -w 1 $count)
9792         do
9793                 local file=$tdir/file-$i
9794                 touch $file
9795                 check_file_in_pool $file $pool "$tlist" || \
9796                         failed=$((failed + 1))
9797         done
9798         [ "$failed" = 0 ] && return 0
9799
9800         error_noexit "$failed files not allocated in $pool"
9801         return 1
9802 }
9803
9804 pool_create_files() {
9805         echo "Creating files in pool"
9806         local pool=$1
9807         local tdir=$2
9808         local count=$3
9809         local tlist="$4"
9810
9811         mkdir -p $tdir
9812         local failed=0
9813         for i in $(seq -w 1 $count)
9814         do
9815                 local file=$tdir/spoo-$i
9816                 $SETSTRIPE -p $pool $file
9817                 check_file_in_pool $file $pool "$tlist" || \
9818                         failed=$((failed + 1))
9819         done
9820         [ "$failed" = 0 ] && return 0
9821
9822         error_noexit "$failed files not allocated in $pool"
9823         return 1
9824 }
9825
9826 pool_lfs_df() {
9827         echo "Checking 'lfs df' output"
9828         local pool=$1
9829
9830         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
9831                         tr '\n' ' ')
9832         local res=$($LFS df --pool $FSNAME.$pool |
9833                         awk '{print $1}' |
9834                         grep "$FSNAME-OST" |
9835                         tr '\n' ' ')
9836         [ "$res" = "$t" ] && return 0
9837
9838         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
9839         return 1
9840 }
9841
9842 pool_file_rel_path() {
9843         echo "Creating files in a pool with relative pathname"
9844         local pool=$1
9845         local tdir=$2
9846
9847         mkdir -p $tdir ||
9848                 { error_noexit "unable to create $tdir"; return 1 ; }
9849         local file="/..$tdir/$tfile-1"
9850         $SETSTRIPE -p $pool $file ||
9851                 { error_noexit "unable to create $file" ; return 2 ; }
9852
9853         cd $tdir
9854         $SETSTRIPE -p $pool $tfile-2 || {
9855                 error_noexit "unable to create $tfile-2 in $tdir"
9856                 return 3
9857         }
9858 }
9859
9860 pool_remove_first_target() {
9861         echo "Removing first target from a pool"
9862         local pool=$1
9863
9864         local pname="lov.$FSNAME-*.pools.$pool"
9865         local t=$($LCTL get_param -n $pname | head -1)
9866         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9867         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
9868                 error_noexit "$t not removed from $FSNAME.$pool"
9869                 return 1
9870         }
9871 }
9872
9873 pool_remove_all_targets() {
9874         echo "Removing all targets from pool"
9875         local pool=$1
9876         local file=$2
9877         local pname="lov.$FSNAME-*.pools.$pool"
9878         for t in $($LCTL get_param -n $pname | sort -u)
9879         do
9880                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9881         done
9882         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
9883                 error_noexit "Pool $FSNAME.$pool cannot be drained"
9884                 return 1
9885         }
9886         # striping on an empty/nonexistant pool should fall back 
9887         # to "pool of everything"
9888         touch $file || {
9889                 error_noexit "failed to use fallback striping for empty pool"
9890                 return 2
9891         }
9892         # setstripe on an empty pool should fail
9893         $SETSTRIPE -p $pool $file 2>/dev/null && {
9894                 error_noexit "expected failure when creating file" \
9895                                                         "with empty pool"
9896                 return 3
9897         }
9898         return 0
9899 }
9900
9901 pool_remove() {
9902         echo "Destroying pool"
9903         local pool=$1
9904         local file=$2
9905
9906         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
9907
9908         sleep 2
9909         # striping on an empty/nonexistant pool should fall back 
9910         # to "pool of everything"
9911         touch $file || {
9912                 error_noexit "failed to use fallback striping for missing pool"
9913                 return 1
9914         }
9915         # setstripe on an empty pool should fail
9916         $SETSTRIPE -p $pool $file 2>/dev/null && {
9917                 error_noexit "expected failure when creating file" \
9918                                                         "with missing pool"
9919                 return 2
9920         }
9921
9922         # get param should return err once pool is gone
9923         if wait_update $HOSTNAME "lctl get_param -n \
9924                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
9925         then
9926                 remove_pool_from_list $FSNAME.$pool
9927                 return 0
9928         fi
9929         error_noexit "Pool $FSNAME.$pool is not destroyed"
9930         return 3
9931 }
9932
9933 test_200() {
9934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9935         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
9936
9937         local POOL=${POOL:-cea1}
9938         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
9939         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
9940         # Pool OST targets
9941         local first_ost=0
9942         local last_ost=$(($OSTCOUNT - 1))
9943         local ost_step=2
9944         local ost_list=$(seq $first_ost $ost_step $last_ost)
9945         local ost_range="$first_ost $last_ost $ost_step"
9946         local test_path=$POOL_ROOT/$POOL_DIR_NAME
9947         local file_dir=$POOL_ROOT/file_tst
9948
9949         local rc=0
9950         while : ; do
9951                 # former test_200a test_200b
9952                 pool_add $POOL                          || { rc=$? ; break; }
9953                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
9954                 # former test_200c test_200d
9955                 mkdir -p $test_path
9956                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
9957                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
9958                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
9959                                                         || { rc=$? ; break; }
9960                 # former test_200e test_200f
9961                 local files=$((OSTCOUNT*3))
9962                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
9963                                                         || { rc=$? ; break; }
9964                 pool_create_files $POOL $file_dir $files "$ost_list" \
9965                                                         || { rc=$? ; break; }
9966                 # former test_200g test_200h
9967                 pool_lfs_df $POOL                       || { rc=$? ; break; }
9968                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
9969
9970                 # former test_201a test_201b test_201c
9971                 pool_remove_first_target $POOL          || { rc=$? ; break; }
9972
9973                 local f=$test_path/$tfile
9974                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
9975                 pool_remove $POOL $f                    || { rc=$? ; break; }
9976                 break
9977         done
9978
9979         cleanup_pools
9980         return $rc
9981 }
9982 run_test 200 "OST pools"
9983
9984 # usage: default_attr <count | size | offset>
9985 default_attr() {
9986         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
9987 }
9988
9989 # usage: check_default_stripe_attr
9990 check_default_stripe_attr() {
9991         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
9992         case $1 in
9993         --stripe-count|--count)
9994                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
9995         --stripe-size|--size)
9996                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
9997         --stripe-index|--index)
9998                 EXPECTED=-1;;
9999         *)
10000                 error "unknown getstripe attr '$1'"
10001         esac
10002
10003         [ $ACTUAL != $EXPECTED ] &&
10004                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
10005 }
10006
10007 test_204a() {
10008         test_mkdir -p $DIR/$tdir
10009         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
10010
10011         check_default_stripe_attr --stripe-count
10012         check_default_stripe_attr --stripe-size
10013         check_default_stripe_attr --stripe-index
10014
10015         return 0
10016 }
10017 run_test 204a "Print default stripe attributes ================="
10018
10019 test_204b() {
10020         test_mkdir -p $DIR/$tdir
10021         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10022
10023         check_default_stripe_attr --stripe-size
10024         check_default_stripe_attr --stripe-index
10025
10026         return 0
10027 }
10028 run_test 204b "Print default stripe size and offset  ==========="
10029
10030 test_204c() {
10031         test_mkdir -p $DIR/$tdir
10032         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10033
10034         check_default_stripe_attr --stripe-count
10035         check_default_stripe_attr --stripe-index
10036
10037         return 0
10038 }
10039 run_test 204c "Print default stripe count and offset ==========="
10040
10041 test_204d() {
10042         test_mkdir -p $DIR/$tdir
10043         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10044
10045         check_default_stripe_attr --stripe-count
10046         check_default_stripe_attr --stripe-size
10047
10048         return 0
10049 }
10050 run_test 204d "Print default stripe count and size ============="
10051
10052 test_204e() {
10053         test_mkdir -p $DIR/$tdir
10054         $SETSTRIPE -d $DIR/$tdir
10055
10056         check_default_stripe_attr --stripe-count --raw
10057         check_default_stripe_attr --stripe-size --raw
10058         check_default_stripe_attr --stripe-index --raw
10059
10060         return 0
10061 }
10062 run_test 204e "Print raw stripe attributes ================="
10063
10064 test_204f() {
10065         test_mkdir -p $DIR/$tdir
10066         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10067
10068         check_default_stripe_attr --stripe-size --raw
10069         check_default_stripe_attr --stripe-index --raw
10070
10071         return 0
10072 }
10073 run_test 204f "Print raw stripe size and offset  ==========="
10074
10075 test_204g() {
10076         test_mkdir -p $DIR/$tdir
10077         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10078
10079         check_default_stripe_attr --stripe-count --raw
10080         check_default_stripe_attr --stripe-index --raw
10081
10082         return 0
10083 }
10084 run_test 204g "Print raw stripe count and offset ==========="
10085
10086 test_204h() {
10087         test_mkdir -p $DIR/$tdir
10088         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10089
10090         check_default_stripe_attr --stripe-count --raw
10091         check_default_stripe_attr --stripe-size --raw
10092
10093         return 0
10094 }
10095 run_test 204h "Print raw stripe count and size ============="
10096
10097 # Figure out which job scheduler is being used, if any,
10098 # or use a fake one
10099 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
10100         JOBENV=SLURM_JOB_ID
10101 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
10102         JOBENV=LSB_JOBID
10103 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
10104         JOBENV=PBS_JOBID
10105 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
10106         JOBENV=LOADL_STEP_ID
10107 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
10108         JOBENV=JOB_ID
10109 else
10110         JOBENV=FAKE_JOBID
10111 fi
10112
10113 verify_jobstats() {
10114         local cmd=$1
10115         local target=$2
10116
10117         # clear old jobstats
10118         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
10119         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
10120
10121         # use a new JobID for this test, or we might see an old one
10122         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
10123
10124         JOBVAL=${!JOBENV}
10125         log "Test: $cmd"
10126         log "Using JobID environment variable $JOBENV=$JOBVAL"
10127
10128         if [ $JOBENV = "FAKE_JOBID" ]; then
10129                 FAKE_JOBID=$JOBVAL $cmd
10130         else
10131                 $cmd
10132         fi
10133
10134         if [ "$target" = "mdt" -o "$target" = "both" ]; then
10135                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
10136                 do_facet $FACET lctl get_param mdt.*.job_stats |
10137                         grep $JOBVAL || error "No job stats found on MDT $FACET"
10138         fi
10139         if [ "$target" = "ost" -o "$target" = "both" ]; then
10140                 FACET=ost1
10141                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
10142                         grep $JOBVAL || error "No job stats found on OST $FACET"
10143         fi
10144 }
10145
10146 jobstats_set() {
10147         trap 0
10148         NEW_JOBENV=${1:-$OLD_JOBENV}
10149         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
10150         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
10151 }
10152
10153 test_205() { # Job stats
10154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10155         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
10156                 skip "Server doesn't support jobstats" && return 0
10157
10158         local cmd
10159         OLD_JOBENV=`$LCTL get_param -n jobid_var`
10160         if [ $OLD_JOBENV != $JOBENV ]; then
10161                 jobstats_set $JOBENV
10162                 trap jobstats_set EXIT
10163         fi
10164
10165         # mkdir
10166         cmd="mkdir $DIR/$tfile"
10167         verify_jobstats "$cmd" "mdt"
10168         # rmdir
10169         cmd="rm -fr $DIR/$tfile"
10170         verify_jobstats "$cmd" "mdt"
10171         # mknod
10172         cmd="mknod $DIR/$tfile c 1 3"
10173         verify_jobstats "$cmd" "mdt"
10174         # unlink
10175         cmd="rm -f $DIR/$tfile"
10176         verify_jobstats "$cmd" "mdt"
10177         # open & close
10178         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
10179         verify_jobstats "$cmd" "mdt"
10180         # setattr
10181         cmd="touch $DIR/$tfile"
10182         verify_jobstats "$cmd" "both"
10183         # write
10184         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
10185         verify_jobstats "$cmd" "ost"
10186         # read
10187         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
10188         verify_jobstats "$cmd" "ost"
10189         # truncate
10190         cmd="$TRUNCATE $DIR/$tfile 0"
10191         verify_jobstats "$cmd" "both"
10192         # rename
10193         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
10194         verify_jobstats "$cmd" "mdt"
10195
10196         # cleanup
10197         rm -f $DIR/jobstats_test_rename
10198
10199         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
10200 }
10201 run_test 205 "Verify job stats"
10202
10203 # LU-1480, LU-1773 and LU-1657
10204 test_206() {
10205         mkdir -p $DIR/$tdir
10206         lfs setstripe -c -1 $DIR/$tdir
10207 #define OBD_FAIL_LOV_INIT 0x1403
10208         $LCTL set_param fail_loc=0xa0001403
10209         $LCTL set_param fail_val=1
10210         touch $DIR/$tdir/$tfile || true
10211 }
10212 run_test 206 "fail lov_init_raid0() doesn't lbug"
10213
10214 test_207a() {
10215         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
10216         local fsz=`stat -c %s $DIR/$tfile`
10217         cancel_lru_locks mdc
10218
10219         # do not return layout in getattr intent
10220 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
10221         $LCTL set_param fail_loc=0x170
10222         local sz=`stat -c %s $DIR/$tfile`
10223
10224         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
10225
10226         rm -rf $DIR/$tfile
10227 }
10228 run_test 207a "can refresh layout at glimpse"
10229
10230 test_207b() {
10231         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
10232         local cksum=`md5sum $DIR/$tfile`
10233         local fsz=`stat -c %s $DIR/$tfile`
10234         cancel_lru_locks mdc
10235         cancel_lru_locks osc
10236
10237         # do not return layout in getattr intent
10238 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
10239         $LCTL set_param fail_loc=0x171
10240
10241         # it will refresh layout after the file is opened but before read issues
10242         echo checksum is "$cksum"
10243         echo "$cksum" |md5sum -c --quiet || error "file differs"
10244
10245         rm -rf $DIR/$tfile
10246 }
10247 run_test 207b "can refresh layout at open"
10248
10249 test_212() {
10250         size=`date +%s`
10251         size=$((size % 8192 + 1))
10252         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
10253         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
10254         rm -f $DIR/f212 $DIR/f212.xyz
10255 }
10256 run_test 212 "Sendfile test ============================================"
10257
10258 test_213() {
10259         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
10260         cancel_lru_locks osc
10261         lctl set_param fail_loc=0x8000040f
10262         # generate a read lock
10263         cat $DIR/$tfile > /dev/null
10264         # write to the file, it will try to cancel the above read lock.
10265         cat /etc/hosts >> $DIR/$tfile
10266 }
10267 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
10268
10269 test_214() { # for bug 20133
10270         test_mkdir -p $DIR/d214p/d214c
10271         for (( i=0; i < 340; i++ )) ; do
10272                 touch $DIR/d214p/d214c/a$i
10273         done
10274
10275         ls -l $DIR/d214p || error "ls -l $DIR/d214p failed"
10276         mv $DIR/d214p/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
10277         ls $DIR/d214c || error "ls $DIR/d214c failed"
10278         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
10279 }
10280 run_test 214 "hash-indexed directory test - bug 20133"
10281
10282 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
10283 create_lnet_proc_files() {
10284         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
10285         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
10286
10287         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
10288         rm -f "$TMP/lnet_$1.sys_tmp"
10289 }
10290
10291 # counterpart of create_lnet_proc_files
10292 remove_lnet_proc_files() {
10293         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
10294 }
10295
10296 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
10297 # 3rd arg as regexp for body
10298 check_lnet_proc_stats() {
10299         local l=$(cat "$TMP/lnet_$1" |wc -l)
10300         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
10301
10302         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
10303 }
10304
10305 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
10306 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
10307 # optional and can be regexp for 2nd line (lnet.routes case)
10308 check_lnet_proc_entry() {
10309         local blp=2            # blp stands for 'position of 1st line of body'
10310         [ "$5" = "" ] || blp=3 # lnet.routes case
10311
10312         local l=$(cat "$TMP/lnet_$1" |wc -l)
10313         # subtracting one from $blp because the body can be empty
10314         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
10315
10316         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
10317                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
10318
10319         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
10320                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
10321
10322         # bail out if any unexpected line happened
10323         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
10324         [ "$?" != 0 ] || error "$2 misformatted"
10325 }
10326
10327 test_215() { # for bugs 18102, 21079, 21517
10328         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10329         local N='(0|[1-9][0-9]*)'       # non-negative numeric
10330         local P='[1-9][0-9]*'           # positive numeric
10331         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
10332         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
10333         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
10334         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
10335
10336         local L1 # regexp for 1st line
10337         local L2 # regexp for 2nd line (optional)
10338         local BR # regexp for the rest (body)
10339
10340         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
10341         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
10342         create_lnet_proc_files "stats"
10343         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
10344         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
10345         remove_lnet_proc_files "stats"
10346
10347         # /proc/sys/lnet/routes should look like this:
10348         # Routing disabled/enabled
10349         # net hops state router
10350         # where net is a string like tcp0, hops >= 0, state is up/down,
10351         # router is a string like 192.168.1.1@tcp2
10352         L1="^Routing (disabled|enabled)$"
10353         L2="^net +hops +state +router$"
10354         BR="^$NET +$N +(up|down) +$NID$"
10355         create_lnet_proc_files "routes"
10356         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
10357         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
10358         remove_lnet_proc_files "routes"
10359
10360         # /proc/sys/lnet/routers should look like this:
10361         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
10362         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
10363         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
10364         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
10365         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
10366         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
10367         create_lnet_proc_files "routers"
10368         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
10369         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
10370         remove_lnet_proc_files "routers"
10371
10372         # /proc/sys/lnet/peers should look like this:
10373         # nid refs state last max rtr min tx min queue
10374         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
10375         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
10376         # numeric (0 or >0 or <0), queue >= 0.
10377         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
10378         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
10379         create_lnet_proc_files "peers"
10380         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
10381         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
10382         remove_lnet_proc_files "peers"
10383
10384         # /proc/sys/lnet/buffers  should look like this:
10385         # pages count credits min
10386         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
10387         L1="^pages +count +credits +min$"
10388         BR="^ +$N +$N +$I +$I$"
10389         create_lnet_proc_files "buffers"
10390         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
10391         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
10392         remove_lnet_proc_files "buffers"
10393
10394         # /proc/sys/lnet/nis should look like this:
10395         # nid status alive refs peer rtr max tx min
10396         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
10397         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
10398         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
10399         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
10400         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
10401         create_lnet_proc_files "nis"
10402         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
10403         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
10404         remove_lnet_proc_files "nis"
10405
10406         # can we successfully write to /proc/sys/lnet/stats?
10407         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
10408         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
10409 }
10410 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
10411
10412 test_216() { # bug 20317
10413         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10414         remote_ost_nodsh && skip "remote OST with nodsh" && return
10415         local node
10416         local p="$TMP/sanityN-$TESTNAME.parameters"
10417         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
10418         for node in $(osts_nodes); do
10419                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
10420                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
10421                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
10422         done
10423         clear_osc_stats
10424
10425         # agressive lockless i/o settings
10426         for node in $(osts_nodes); do
10427                 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'
10428         done
10429         lctl set_param -n osc.*.contention_seconds 60
10430
10431         $DIRECTIO write $DIR/$tfile 0 10 4096
10432         $CHECKSTAT -s 40960 $DIR/$tfile
10433
10434         # disable lockless i/o
10435         for node in $(osts_nodes); do
10436                 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'
10437         done
10438         lctl set_param -n osc.*.contention_seconds 0
10439         clear_osc_stats
10440
10441         dd if=/dev/zero of=$DIR/$tfile count=0
10442         $CHECKSTAT -s 0 $DIR/$tfile
10443
10444         restore_lustre_params <$p
10445         rm -f $p
10446         rm $DIR/$tfile
10447 }
10448 run_test 216 "check lockless direct write works and updates file size and kms correctly"
10449
10450 test_217() { # bug 22430
10451         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10452         local node
10453         local nid
10454
10455         for node in $(nodes_list); do
10456                 nid=$(host_nids_address $node $NETTYPE)
10457                 if [[ $nid = *-* ]] ; then
10458                         echo "lctl ping $nid@$NETTYPE"
10459                         lctl ping $nid@$NETTYPE
10460                 else
10461                         echo "skipping $node (no hyphen detected)"
10462                 fi
10463         done
10464 }
10465 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
10466
10467 test_218() {
10468        # do directio so as not to populate the page cache
10469        log "creating a 10 Mb file"
10470        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10471        log "starting reads"
10472        dd if=$DIR/$tfile of=/dev/null bs=4096 &
10473        log "truncating the file"
10474        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10475        log "killing dd"
10476        kill %+ || true # reads might have finished
10477        echo "wait until dd is finished"
10478        wait
10479        log "removing the temporary file"
10480        rm -rf $DIR/$tfile || error "tmp file removal failed"
10481 }
10482 run_test 218 "parallel read and truncate should not deadlock ======================="
10483
10484 test_219() {
10485         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10486         # write one partial page
10487         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
10488         # set no grant so vvp_io_commit_write will do sync write
10489         $LCTL set_param fail_loc=0x411
10490         # write a full page at the end of file
10491         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
10492
10493         $LCTL set_param fail_loc=0
10494         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
10495         $LCTL set_param fail_loc=0x411
10496         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
10497 }
10498 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
10499
10500 test_220() { #LU-325
10501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10502         remote_ost_nodsh && skip "remote OST with nodsh" && return
10503         local OSTIDX=0
10504
10505         test_mkdir -p $DIR/$tdir
10506         local OST=$(lfs osts | grep ${OSTIDX}": " | \
10507                 awk '{print $2}' | sed -e 's/_UUID$//')
10508
10509         # on the mdt's osc
10510         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
10511         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
10512                         osc.$mdtosc_proc1.prealloc_last_id)
10513         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
10514                         osc.$mdtosc_proc1.prealloc_next_id)
10515
10516         $LFS df -i
10517
10518         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
10519         #define OBD_FAIL_OST_ENOINO              0x229
10520         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
10521         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
10522         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
10523
10524         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
10525
10526         MDSOBJS=$((last_id - next_id))
10527         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
10528
10529         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
10530         echo "OST still has $count kbytes free"
10531
10532         echo "create $MDSOBJS files @next_id..."
10533         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
10534
10535         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
10536                         osc.$mdtosc_proc1.prealloc_last_id)
10537         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
10538                         osc.$mdtosc_proc1.prealloc_next_id)
10539
10540         echo "after creation, last_id=$last_id2, next_id=$next_id2"
10541         $LFS df -i
10542
10543         echo "cleanup..."
10544
10545         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
10546         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
10547
10548         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
10549         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
10550         echo "unlink $MDSOBJS files @$next_id..."
10551         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
10552 }
10553 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
10554
10555 test_221() {
10556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10557         dd if=`which date` of=$MOUNT/date oflag=sync
10558         chmod +x $MOUNT/date
10559
10560         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
10561         $LCTL set_param fail_loc=0x80001401
10562
10563         $MOUNT/date > /dev/null
10564         rm -f $MOUNT/date
10565 }
10566 run_test 221 "make sure fault and truncate race to not cause OOM"
10567
10568 test_222a () {
10569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10570        rm -rf $DIR/$tdir
10571        test_mkdir -p $DIR/$tdir
10572        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
10573        createmany -o $DIR/$tdir/$tfile 10
10574        cancel_lru_locks mdc
10575        cancel_lru_locks osc
10576        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
10577        $LCTL set_param fail_loc=0x31a
10578        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
10579        $LCTL set_param fail_loc=0
10580        rm -r $DIR/$tdir
10581 }
10582 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
10583
10584 test_222b () {
10585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10586        rm -rf $DIR/$tdir
10587        test_mkdir -p $DIR/$tdir
10588        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
10589        createmany -o $DIR/$tdir/$tfile 10
10590        cancel_lru_locks mdc
10591        cancel_lru_locks osc
10592        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
10593        $LCTL set_param fail_loc=0x31a
10594        rm -r $DIR/$tdir || "AGL for rmdir failed"
10595        $LCTL set_param fail_loc=0
10596 }
10597 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
10598
10599 test_223 () {
10600         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10601        rm -rf $DIR/$tdir
10602        test_mkdir -p $DIR/$tdir
10603        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
10604        createmany -o $DIR/$tdir/$tfile 10
10605        cancel_lru_locks mdc
10606        cancel_lru_locks osc
10607        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
10608        $LCTL set_param fail_loc=0x31b
10609        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
10610        $LCTL set_param fail_loc=0
10611        rm -r $DIR/$tdir
10612 }
10613 run_test 223 "osc reenqueue if without AGL lock granted ======================="
10614
10615 test_224a() { # LU-1039, MRP-303
10616         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10617         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
10618         $LCTL set_param fail_loc=0x508
10619         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
10620         $LCTL set_param fail_loc=0
10621         df $DIR
10622 }
10623 run_test 224a "Don't panic on bulk IO failure"
10624
10625 test_224b() { # LU-1039, MRP-303
10626         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10627         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
10628         cancel_lru_locks osc
10629         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
10630         $LCTL set_param fail_loc=0x515
10631         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
10632         $LCTL set_param fail_loc=0
10633         df $DIR
10634 }
10635 run_test 224b "Don't panic on bulk IO failure"
10636
10637 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
10638 test_225a () {
10639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10640        if [ -z ${MDSSURVEY} ]; then
10641               skip_env "mds-survey not found" && return
10642        fi
10643        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
10644             { skip "Need MDS version at least 2.2.51"; return; }
10645
10646        local mds=$(facet_host $SINGLEMDS)
10647        local target=$(do_nodes $mds 'lctl dl' | \
10648                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
10649
10650        local cmd1="file_count=1000 thrhi=4"
10651        local cmd2="dir_count=2 layer=mdd stripe_count=0"
10652        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
10653        local cmd="$cmd1 $cmd2 $cmd3"
10654
10655        rm -f ${TMP}/mds_survey*
10656        echo + $cmd
10657        eval $cmd || error "mds-survey with zero-stripe failed"
10658        cat ${TMP}/mds_survey*
10659        rm -f ${TMP}/mds_survey*
10660 }
10661 run_test 225a "Metadata survey sanity with zero-stripe"
10662
10663 test_225b () {
10664         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10665        if [ -z ${MDSSURVEY} ]; then
10666               skip_env "mds-survey not found" && return
10667        fi
10668        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
10669             { skip "Need MDS version at least 2.2.51"; return; }
10670
10671        if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
10672               skip_env "Need to mount OST to test" && return
10673        fi
10674
10675        local mds=$(facet_host $SINGLEMDS)
10676        local target=$(do_nodes $mds 'lctl dl' | \
10677                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
10678
10679        local cmd1="file_count=1000 thrhi=4"
10680        local cmd2="dir_count=2 layer=mdd stripe_count=1"
10681        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
10682        local cmd="$cmd1 $cmd2 $cmd3"
10683
10684        rm -f ${TMP}/mds_survey*
10685        echo + $cmd
10686        eval $cmd || error "mds-survey with stripe_count failed"
10687        cat ${TMP}/mds_survey*
10688        rm -f ${TMP}/mds_survey*
10689 }
10690 run_test 225b "Metadata survey sanity with stripe_count = 1"
10691
10692 mcreate_path2fid () {
10693         local mode=$1
10694         local major=$2
10695         local minor=$3
10696         local name=$4
10697         local desc=$5
10698         local path=$DIR/$tdir/$name
10699         local fid
10700         local rc
10701         local fid_path
10702
10703         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
10704                 error "cannot create $desc"
10705
10706         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
10707         rc=$?
10708         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
10709
10710         fid_path=$($LFS fid2path $MOUNT $fid)
10711         rc=$?
10712         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
10713
10714         [ "$path" == "$fid_path" ] ||
10715                 error "fid2path returned $fid_path, expected $path"
10716
10717         echo "pass with $path and $fid"
10718 }
10719
10720 test_226a () {
10721         rm -rf $DIR/$tdir
10722         mkdir -p $DIR/$tdir
10723
10724         mcreate_path2fid 0010666 0 0 fifo "FIFO"
10725         mcreate_path2fid 0020666 1 3 null "character special file (null)"
10726         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
10727         mcreate_path2fid 0040666 0 0 dir "directory"
10728         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
10729         mcreate_path2fid 0100666 0 0 file "regular file"
10730         mcreate_path2fid 0120666 0 0 link "symbolic link"
10731         mcreate_path2fid 0140666 0 0 sock "socket"
10732 }
10733 run_test 226a "call path2fid and fid2path on files of all type"
10734
10735 test_226b () {
10736         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10737         rm -rf $DIR/$tdir
10738         local MDTIDX=1
10739
10740         mkdir -p $DIR/$tdir
10741         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
10742                 error "create remote directory failed"
10743         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
10744         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
10745                                 "character special file (null)"
10746         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
10747                                 "character special file (no device)"
10748         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
10749         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
10750                                 "block special file (loop)"
10751         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
10752         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
10753         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
10754 }
10755 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
10756
10757 # LU-1299 Executing or running ldd on a truncated executable does not
10758 # cause an out-of-memory condition.
10759 test_227() {
10760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10761         dd if=`which date` of=$MOUNT/date bs=1k count=1
10762         chmod +x $MOUNT/date
10763
10764         $MOUNT/date > /dev/null
10765         ldd $MOUNT/date > /dev/null
10766         rm -f $MOUNT/date
10767 }
10768 run_test 227 "running truncated executable does not cause OOM"
10769
10770 # LU-1512 try to reuse idle OI blocks
10771 test_228a() {
10772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10773         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
10774                 skip "non-ldiskfs backend" && return
10775
10776         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10777         local myDIR=$DIR/$tdir
10778
10779         mkdir -p $myDIR
10780         #define OBD_FAIL_SEQ_EXHAUST             0x1002
10781         $LCTL set_param fail_loc=0x80001002
10782         createmany -o $myDIR/t- 10000
10783         $LCTL set_param fail_loc=0
10784         # The guard is current the largest FID holder
10785         touch $myDIR/guard
10786         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
10787                     tr -d '[')
10788         local IDX=$(($SEQ % 64))
10789
10790         do_facet $SINGLEMDS sync
10791         # Make sure journal flushed.
10792         sleep 6
10793         local blk1=$(do_facet $SINGLEMDS \
10794                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10795                      grep Blockcount | awk '{print $4}')
10796
10797         # Remove old files, some OI blocks will become idle.
10798         unlinkmany $myDIR/t- 10000
10799         # Create new files, idle OI blocks should be reused.
10800         createmany -o $myDIR/t- 2000
10801         do_facet $SINGLEMDS sync
10802         # Make sure journal flushed.
10803         sleep 6
10804         local blk2=$(do_facet $SINGLEMDS \
10805                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10806                      grep Blockcount | awk '{print $4}')
10807
10808         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
10809 }
10810 run_test 228a "try to reuse idle OI blocks"
10811
10812 test_228b() {
10813         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10814         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
10815                 skip "non-ldiskfs backend" && return
10816
10817         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10818         local myDIR=$DIR/$tdir
10819
10820         mkdir -p $myDIR
10821         #define OBD_FAIL_SEQ_EXHAUST             0x1002
10822         $LCTL set_param fail_loc=0x80001002
10823         createmany -o $myDIR/t- 10000
10824         $LCTL set_param fail_loc=0
10825         # The guard is current the largest FID holder
10826         touch $myDIR/guard
10827         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
10828                     tr -d '[')
10829         local IDX=$(($SEQ % 64))
10830
10831         do_facet $SINGLEMDS sync
10832         # Make sure journal flushed.
10833         sleep 6
10834         local blk1=$(do_facet $SINGLEMDS \
10835                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10836                      grep Blockcount | awk '{print $4}')
10837
10838         # Remove old files, some OI blocks will become idle.
10839         unlinkmany $myDIR/t- 10000
10840
10841         # stop the MDT
10842         stop $SINGLEMDS || error "Fail to stop MDT."
10843         # remount the MDT
10844         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10845
10846         df $MOUNT || error "Fail to df."
10847         # Create new files, idle OI blocks should be reused.
10848         createmany -o $myDIR/t- 2000
10849         do_facet $SINGLEMDS sync
10850         # Make sure journal flushed.
10851         sleep 6
10852         local blk2=$(do_facet $SINGLEMDS \
10853                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10854                      grep Blockcount | awk '{print $4}')
10855
10856         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
10857 }
10858 run_test 228b "idle OI blocks can be reused after MDT restart"
10859
10860 #LU-1881
10861 test_228c() {
10862         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10863         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
10864                 skip "non-ldiskfs backend" && return
10865
10866         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10867         local myDIR=$DIR/$tdir
10868
10869         mkdir -p $myDIR
10870         #define OBD_FAIL_SEQ_EXHAUST             0x1002
10871         $LCTL set_param fail_loc=0x80001002
10872         # 20000 files can guarantee there are index nodes in the OI file
10873         createmany -o $myDIR/t- 20000
10874         $LCTL set_param fail_loc=0
10875         # The guard is current the largest FID holder
10876         touch $myDIR/guard
10877         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
10878                     tr -d '[')
10879         local IDX=$(($SEQ % 64))
10880
10881         do_facet $SINGLEMDS sync
10882         # Make sure journal flushed.
10883         sleep 6
10884         local blk1=$(do_facet $SINGLEMDS \
10885                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10886                      grep Blockcount | awk '{print $4}')
10887
10888         # Remove old files, some OI blocks will become idle.
10889         unlinkmany $myDIR/t- 20000
10890         rm -f $myDIR/guard
10891         # The OI file should become empty now
10892
10893         # Create new files, idle OI blocks should be reused.
10894         createmany -o $myDIR/t- 2000
10895         do_facet $SINGLEMDS sync
10896         # Make sure journal flushed.
10897         sleep 6
10898         local blk2=$(do_facet $SINGLEMDS \
10899                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10900                      grep Blockcount | awk '{print $4}')
10901
10902         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
10903 }
10904 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
10905
10906 test_230a() {
10907         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10908         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10909         local MDTIDX=1
10910
10911         mkdir -p $DIR/$tdir/test_230_local
10912         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
10913         [ $mdt_idx -ne 0 ] &&
10914                 error "create local directory on wrong MDT $mdt_idx"
10915
10916         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
10917                         error "create remote directory failed"
10918         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
10919         [ $mdt_idx -ne $MDTIDX ] &&
10920                 error "create remote directory on wrong MDT $mdt_idx"
10921
10922         createmany -o $DIR/$tdir/test_230/t- 10 ||
10923                 error "create files on remote directory failed"
10924         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
10925         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
10926         rm -r $DIR/$tdir || error "unlink remote directory failed"
10927 }
10928 run_test 230a "Create remote directory and files under the remote directory"
10929
10930 test_230b() {
10931         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10932         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10933         local MDTIDX=1
10934         local remote_dir=$DIR/$tdir/remote_dir
10935         local rc=0
10936
10937         mkdir -p $DIR/$tdir
10938         $LFS mkdir -i $MDTIDX $remote_dir ||
10939                 error "create remote directory failed"
10940
10941         $LFS mkdir -i 0 $remote_dir/new_dir &&
10942                 error "nested remote directory create succeed!"
10943
10944         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=1
10945         $LFS mkdir -i 0 $remote_dir/new_dir || rc=$?
10946         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=0
10947
10948         [ $rc -ne 0 ] &&
10949            error "create remote directory failed after set enable_remote_dir"
10950
10951         rm -rf $remote_dir || error "first unlink remote directory failed"
10952
10953         $RUNAS -G$RUNAS_GID $LFS mkdir -i $MDTIDX $DIR/$tfile &&
10954                                                         error "chown worked"
10955
10956         do_facet mds$MDTIDX lctl set_param \
10957                                 mdt.*.enable_remote_dir_gid=$RUNAS_GID
10958         $LFS mkdir -i $MDTIDX $remote_dir || rc=$?
10959         do_facet mds$MDTIDX lctl set_param mdt.*.enable_remote_dir_gid=0
10960
10961         [ $rc -ne 0 ] &&
10962            error "create remote dir failed after set enable_remote_dir_gid"
10963
10964         rm -r $DIR/$tdir || error "second unlink remote directory failed"
10965 }
10966 run_test 230b "nested remote directory should be failed"
10967
10968 test_231a()
10969 {
10970         # For simplicity this test assumes that max_pages_per_rpc
10971         # is the same across all OSCs
10972         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -1)
10973         local bulk_size=$((max_pages * 4096))
10974
10975         mkdir -p $DIR/$tdir
10976
10977         # clear the OSC stats
10978         $LCTL set_param osc.*.stats=0 &>/dev/null
10979
10980         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
10981         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
10982                 oflag=direct &>/dev/null || error "dd failed"
10983
10984         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
10985         if [ x$nrpcs != "x1" ]; then
10986                 error "found $nrpc ost_write RPCs, not 1 as expected"
10987         fi
10988
10989         # Drop the OSC cache, otherwise we will read from it
10990         cancel_lru_locks osc
10991
10992         # clear the OSC stats
10993         $LCTL set_param osc.*.stats=0 &>/dev/null
10994
10995         # Client reads $bulk_size.
10996         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
10997                 iflag=direct &>/dev/null || error "dd failed"
10998
10999         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
11000         if [ x$nrpcs != "x1" ]; then
11001                 error "found $nrpc ost_read RPCs, not 1 as expected"
11002         fi
11003 }
11004 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
11005
11006 test_231b() {
11007         mkdir -p $DIR/$tdir
11008         local i
11009         for i in {0..1023}; do
11010                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
11011                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
11012                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
11013         done
11014         sync
11015 }
11016 run_test 231b "must not assert on fully utilized OST request buffer"
11017
11018 test_232() {
11019         mkdir -p $DIR/$tdir
11020         #define OBD_FAIL_LDLM_OST_LVB            0x31c
11021         $LCTL set_param fail_loc=0x31c
11022
11023         # ignore dd failure
11024         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
11025
11026         $LCTL set_param fail_loc=0
11027         umount_client $MOUNT || error "umount failed"
11028         mount_client $MOUNT || error "mount failed"
11029 }
11030 run_test 232 "failed lock should not block umount"
11031
11032 #
11033 # tests that do cleanup/setup should be run at the end
11034 #
11035
11036 test_900() {
11037         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11038         local ls
11039         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
11040         $LCTL set_param fail_loc=0x903
11041         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
11042         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
11043                 echo "clear" > $ls
11044         done
11045         FAIL_ON_ERROR=true cleanup
11046         FAIL_ON_ERROR=true setup
11047 }
11048 run_test 900 "umount should not race with any mgc requeue thread"
11049
11050 complete $SECONDS
11051 check_and_cleanup_lustre
11052 if [ "$I_MOUNTED" != "yes" ]; then
11053         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
11054 fi
11055 exit_status