Whamcloud - gitweb
LU-2687 test: add b2_4 zfs image for conf-sanity test_32a
[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_0a() {
145         touch $DIR/$tfile
146         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
147         rm $DIR/$tfile
148         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
149 }
150 run_test 0a "touch; rm ====================="
151
152 test_0b() {
153         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
154         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
155 }
156 run_test 0b "chmod 0755 $DIR ============================="
157
158 test_0c() {
159         $LCTL get_param mdc.*.import | grep "state: FULL" ||
160                 error "import not FULL"
161         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
162                 error "bad target"
163 }
164 run_test 0c "check import proc ============================="
165
166 test_1() {
167         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
168         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
169         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
170         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
171         rmdir $DIR/$tdir/d2
172         rmdir $DIR/$tdir
173         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
174 }
175 run_test 1 "mkdir; remkdir; rmdir =============================="
176
177 test_2() {
178         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
179         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
180         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
181         rm -r $DIR/$tdir
182         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
183 }
184 run_test 2 "mkdir; touch; rmdir; check file ===================="
185
186 test_3() {
187         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
189         touch $DIR/$tdir/$tfile
190         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
191         rm -r $DIR/$tdir
192         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
193 }
194 run_test 3 "mkdir; touch; rmdir; check dir ====================="
195
196 test_5() {
197         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
198         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
199         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
200         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
201         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
202 }
203 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
204
205 test_6a() {
206         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
207         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
208         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
209                 error "$tfile does not have perm 0666 or UID $UID"
210         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
211         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
212                 error "$tfile should be 0666 and owned by UID $UID"
213 }
214 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
215
216 test_6c() {
217         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
218         touch $DIR/$tfile
219         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
220         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
221                 error "$tfile should be owned by UID $RUNAS_ID"
222         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
223         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
224                 error "$tfile should be owned by UID $RUNAS_ID"
225 }
226 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
227
228 test_6e() {
229         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
230         touch $DIR/$tfile
231         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
232         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
233                 error "$tfile should be owned by GID $UID"
234         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
235         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
236                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
237 }
238 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
239
240 test_6g() {
241         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
242         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
243         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
244         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
245         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
246         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
247         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
248                 error "$tdir/d/subdir should be GID $RUNAS_GID"
249 }
250 run_test 6g "Is new dir in sgid dir inheriting group?"
251
252 test_6h() { # bug 7331
253         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
254         touch $DIR/$tfile || error "touch failed"
255         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
256         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
257                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
258         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
259                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
260 }
261 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
262
263 test_7a() {
264         test_mkdir $DIR/$tdir
265         $MCREATE $DIR/$tdir/$tfile
266         chmod 0666 $DIR/$tdir/$tfile
267         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
268                 error "$tdir/$tfile should be mode 0666"
269 }
270 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
271
272 test_7b() {
273         if [ ! -d $DIR/$tdir ]; then
274                 mkdir $DIR/$tdir
275         fi
276         $MCREATE $DIR/$tdir/$tfile
277         echo -n foo > $DIR/$tdir/$tfile
278         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
279         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
280 }
281 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
282
283 test_8() {
284         test_mkdir $DIR/$tdir
285         touch $DIR/$tdir/$tfile
286         chmod 0666 $DIR/$tdir/$tfile
287         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
288                 error "$tfile mode not 0666"
289 }
290 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
291
292 test_9() {
293         test_mkdir $DIR/$tdir
294         test_mkdir $DIR/$tdir/d2
295         test_mkdir $DIR/$tdir/d2/d3
296         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
297 }
298 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
299
300 test_10() {
301         test_mkdir $DIR/$tdir
302         test_mkdir $DIR/$tdir/d2
303         touch $DIR/$tdir/d2/$tfile
304         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
305                 error "$tdir/d2/$tfile not a file"
306 }
307 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
308
309 test_11() {
310         test_mkdir $DIR/$tdir
311         test_mkdir $DIR/$tdir/d2
312         chmod 0666 $DIR/$tdir/d2
313         chmod 0705 $DIR/$tdir/d2
314         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
315                 error "$tdir/d2 mode not 0705"
316 }
317 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
318
319 test_12() {
320         test_mkdir $DIR/$tdir
321         touch $DIR/$tdir/$tfile
322         chmod 0666 $DIR/$tdir/$tfile
323         chmod 0654 $DIR/$tdir/$tfile
324         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
325                 error "$tdir/d2 mode not 0654"
326 }
327 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
328
329 test_13() {
330         test_mkdir $DIR/$tdir
331         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
332         >  $DIR/$tdir/$tfile
333         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
334                 error "$tdir/$tfile size not 0 after truncate"
335 }
336 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
337
338 test_14() {
339         test_mkdir $DIR/$tdir
340         touch $DIR/$tdir/$tfile
341         rm $DIR/$tdir/$tfile
342         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
343 }
344 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
345
346 test_15() {
347         test_mkdir $DIR/$tdir
348         touch $DIR/$tdir/$tfile
349         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
350         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
351                 error "$tdir/${tfile_2} not a file after rename"
352 }
353 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
354
355 test_16() {
356         test_mkdir $DIR/$tdir
357         touch $DIR/$tdir/$tfile
358         rm -rf $DIR/$tdir/$tfile
359         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
360 }
361 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
362
363 test_17a() {
364         test_mkdir -p $DIR/$tdir
365         touch $DIR/$tdir/$tfile
366         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
367         ls -l $DIR/$tdir
368         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
369                 error "$tdir/l-exist not a symlink"
370         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
371                 error "$tdir/l-exist not referencing a file"
372         rm -f $DIR/$tdir/l-exist
373         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
374 }
375 run_test 17a "symlinks: create, remove (real) =================="
376
377 test_17b() {
378         test_mkdir -p $DIR/$tdir
379         ln -s no-such-file $DIR/$tdir/l-dangle
380         ls -l $DIR/$tdir
381         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
382                 error "$tdir/l-dangle not referencing no-such-file"
383         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
384                 error "$tdir/l-dangle not referencing non-existent file"
385         rm -f $DIR/$tdir/l-dangle
386         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
387 }
388 run_test 17b "symlinks: create, remove (dangling) =============="
389
390 test_17c() { # bug 3440 - don't save failed open RPC for replay
391         test_mkdir -p $DIR/$tdir
392         ln -s foo $DIR/$tdir/$tfile
393         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
394 }
395 run_test 17c "symlinks: open dangling (should return error) ===="
396
397 test_17d() {
398         test_mkdir -p $DIR/$tdir
399         ln -s foo $DIR/$tdir/$tfile
400         touch $DIR/$tdir/$tfile || error "creating to new symlink"
401 }
402 run_test 17d "symlinks: create dangling ========================"
403
404 test_17e() {
405         test_mkdir -p $DIR/$tdir
406         local foo=$DIR/$tdir/$tfile
407         ln -s $foo $foo || error "create symlink failed"
408         ls -l $foo || error "ls -l failed"
409         ls $foo && error "ls not failed" || true
410 }
411 run_test 17e "symlinks: create recursive symlink (should return error) ===="
412
413 test_17f() {
414         test_mkdir -p $DIR/d17f
415         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
416         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
417         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
418         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
419         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
420         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
421         ls -l  $DIR/d17f
422 }
423 run_test 17f "symlinks: long and very long symlink name ========================"
424
425 # str_repeat(S, N) generate a string that is string S repeated N times
426 str_repeat() {
427         local s=$1
428         local n=$2
429         local ret=''
430         while [ $((n -= 1)) -ge 0 ]; do
431                 ret=$ret$s
432         done
433         echo $ret
434 }
435
436 # Long symlinks and LU-2241
437 test_17g() {
438         test_mkdir -p $DIR/$tdir
439         local TESTS="59 60 61 4094 4095"
440
441         # Fix for inode size boundary in 2.1.4
442         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
443                 TESTS="4094 4095"
444
445         # Patch not applied to 2.2 or 2.3 branches
446         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
447         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
448                 TESTS="4094 4095"
449
450         # skip long symlink name for rhel6.5.
451         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
452         grep -q '6.5' /etc/redhat-release && TESTS="59 60 61 4062 4063"
453
454         for i in $TESTS; do
455                 local SYMNAME=$(str_repeat 'x' $i)
456                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
457                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
458         done
459 }
460 run_test 17g "symlinks: really long symlink name and inode boundaries"
461
462 test_17h() { #bug 17378
463         remote_mds_nodsh && skip "remote MDS with nodsh" && return
464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
465         local mdt_idx
466         test_mkdir -p $DIR/$tdir
467         if [ $MDSCOUNT -gt 1 ]; then
468                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
469         else
470                 mdt_idx=0
471         fi
472         $SETSTRIPE -c -1 $DIR/$tdir
473 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
474         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
475         touch $DIR/$tdir/$tfile || true
476 }
477 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
478
479 test_17i() { #bug 20018
480         remote_mds_nodsh && skip "remote MDS with nodsh" && return
481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
482         test_mkdir -p $DIR/$tdir
483         local foo=$DIR/$tdir/$tfile
484         local mdt_idx
485         if [ $MDSCOUNT -gt 1 ]; then
486                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
487         else
488                 mdt_idx=0
489         fi
490         ln -s $foo $foo || error "create symlink failed"
491 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
492         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
493         ls -l $foo && error "error not detected"
494         return 0
495 }
496 run_test 17i "don't panic on short symlink"
497
498 test_17k() { #bug 22301
499         rsync --help | grep -q xattr ||
500                 skip_env "$(rsync --version| head -1) does not support xattrs"
501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
502         test_mkdir -p $DIR/$tdir
503         test_mkdir -p $DIR/$tdir.new
504         touch $DIR/$tdir/$tfile
505         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
506         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
507                 error "rsync failed with xattrs enabled"
508 }
509 run_test 17k "symlinks: rsync with xattrs enabled ========================="
510
511 test_17l() { # LU-279
512         mkdir -p $DIR/$tdir
513         touch $DIR/$tdir/$tfile
514         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
515         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
516                 # -h to not follow symlinks. -m '' to list all the xattrs.
517                 # grep to remove first line: '# file: $path'.
518                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
519                 do
520                         lgetxattr_size_check $path $xattr ||
521                                 error "lgetxattr_size_check $path $xattr failed"
522                 done
523         done
524 }
525 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
526
527 # LU-1540
528 test_17m() {
529         local short_sym="0123456789"
530         local WDIR=$DIR/${tdir}m
531         local mds_index
532         local devname
533         local cmd
534         local i
535         local rc=0
536
537         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
538         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
539                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
540
541         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
542                 skip "only for ldiskfs MDT" && return 0
543
544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
545
546         mkdir -p $WDIR
547         long_sym=$short_sym
548         # create a long symlink file
549         for ((i = 0; i < 4; ++i)); do
550                 long_sym=${long_sym}${long_sym}
551         done
552
553         echo "create 512 short and long symlink files under $WDIR"
554         for ((i = 0; i < 256; ++i)); do
555                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
556                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
557         done
558
559         echo "erase them"
560         rm -f $WDIR/*
561         sync
562         wait_delete_completed
563
564         echo "recreate the 512 symlink files with a shorter string"
565         for ((i = 0; i < 512; ++i)); do
566                 # rewrite the symlink file with a shorter string
567                 ln -sf ${long_sym} $WDIR/long-$i
568                 ln -sf ${short_sym} $WDIR/short-$i
569         done
570
571         mds_index=$($LFS getstripe -M $WDIR)
572         mds_index=$((mds_index+1))
573         devname=$(mdsdevname $mds_index)
574         cmd="$E2FSCK -fnvd $devname"
575
576         echo "stop and checking mds${mds_index}: $cmd"
577         # e2fsck should not return error
578         stop mds${mds_index}
579         do_facet mds${mds_index} $cmd || rc=$?
580
581         start mds${mds_index} $devname $MDS_MOUNT_OPTS
582         df $MOUNT > /dev/null 2>&1
583         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
584                 "short/long symlink MDT: rc=$rc"
585         return $rc
586 }
587 run_test 17m "run e2fsck against MDT which contains short/long symlink"
588
589 check_fs_consistency_17n() {
590         local mdt_index
591         local devname
592         local cmd
593         local rc=0
594
595         for mdt_index in $(seq 1 $MDSCOUNT); do
596                 devname=$(mdsdevname $mdt_index)
597                 cmd="$E2FSCK -fnvd $devname"
598
599                 echo "stop and checking mds${mdt_index}: $cmd"
600                 # e2fsck should not return error
601                 stop mds${mdt_index}
602                 do_facet mds${mdt_index} $cmd || rc=$?
603
604                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
605                 df $MOUNT > /dev/null 2>&1
606                 [ $rc -ne 0 ] && break
607         done
608         return $rc
609 }
610
611 test_17n() {
612         local i
613
614         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
615         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
616                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
617
618         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
619                 skip "only for ldiskfs MDT" && return 0
620
621         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
622
623         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
624
625         mkdir -p $DIR/$tdir
626         for ((i=0; i<10; i++)); do
627                 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
628                         error "create remote dir error $i"
629                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
630                         error "create files under remote dir failed $i"
631         done
632
633         check_fs_consistency_17n || error "e2fsck report error"
634
635         for ((i=0;i<10;i++)); do
636                 rm -rf $DIR/$tdir/remote_dir_${i} ||
637                         error "destroy remote dir error $i"
638         done
639
640         check_fs_consistency_17n || error "e2fsck report error"
641 }
642 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
643
644 test_17o() {
645         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ]] &&
646                 skip "Need MDS version at least 2.3.64" && return
647
648         local WDIR=$DIR/${tdir}o
649         local mdt_index
650         local mdtdevname
651         local rc=0
652
653         mkdir -p $WDIR
654         mdt_index=$($LFS getstripe -M $WDIR)
655         mdt_index=$((mdt_index+1))
656         mdtdevname=$(mdsdevname $mdt_index)
657
658         touch $WDIR/$tfile
659         stop mds${mdt_index}
660         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
661
662         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
663         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
664         ls -l $WDIR/$tfile && rc=1
665         do_facet mds${mdt_index} lctl set_param fail_loc=0
666         [[ $rc -ne 0 ]] && error "stat file should fail"
667         true
668 }
669 run_test 17o "stat file with incompat LMA feature"
670
671 test_18() {
672         touch $DIR/f || error "Failed to touch $DIR/f: $?"
673         ls $DIR || error "Failed to ls $DIR: $?"
674 }
675 run_test 18 "touch .../f ; ls ... =============================="
676
677 test_19a() {
678         touch $DIR/$tfile
679         ls -l $DIR
680         rm $DIR/$tfile
681         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
682 }
683 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
684
685 test_19b() {
686         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
687 }
688 run_test 19b "ls -l .../f19 (should return error) =============="
689
690 test_19c() {
691         [ $RUNAS_ID -eq $UID ] &&
692                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
693         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
694 }
695 run_test 19c "$RUNAS touch .../f19 (should return error) =="
696
697 test_19d() {
698         cat $DIR/f19 && error || true
699 }
700 run_test 19d "cat .../f19 (should return error) =============="
701
702 test_20() {
703         touch $DIR/$tfile
704         rm $DIR/$tfile
705         log "1 done"
706         touch $DIR/$tfile
707         rm $DIR/$tfile
708         log "2 done"
709         touch $DIR/$tfile
710         rm $DIR/$tfile
711         log "3 done"
712         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
713 }
714 run_test 20 "touch .../f ; ls -l ... ==========================="
715
716 test_21() {
717         test_mkdir -p $DIR/$tdir
718         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
719         ln -s dangle $DIR/$tdir/link
720         echo foo >> $DIR/$tdir/link
721         cat $DIR/$tdir/dangle
722         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
723         $CHECKSTAT -f -t file $DIR/$tdir/link ||
724                 error "$tdir/link not linked to a file"
725 }
726 run_test 21 "write to dangling link ============================"
727
728 test_22() {
729         WDIR=$DIR/$tdir
730         test_mkdir -p $DIR/$tdir
731         chown $RUNAS_ID:$RUNAS_GID $WDIR
732         (cd $WDIR || error "cd $WDIR failed";
733         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
734         $RUNAS tar xf -)
735         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
736         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
737         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
738 }
739 run_test 22 "unpack tar archive as non-root user ==============="
740
741 # was test_23
742 test_23a() {
743         test_mkdir -p $DIR/$tdir
744         local file=$DIR/$tdir/$tfile
745
746         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
747         openfile -f O_CREAT:O_EXCL $file &&
748                 error "$file recreate succeeded" || true
749 }
750 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
751
752 test_23b() { # bug 18988
753         test_mkdir -p $DIR/$tdir
754         local file=$DIR/$tdir/$tfile
755
756         rm -f $file
757         echo foo > $file || error "write filed"
758         echo bar >> $file || error "append filed"
759         $CHECKSTAT -s 8 $file || error "wrong size"
760         rm $file
761 }
762 run_test 23b "O_APPEND check =========================="
763
764 # rename sanity
765 test_24a() {
766         echo '-- same directory rename'
767         test_mkdir $DIR/$tdir
768         touch $DIR/$tdir/$tfile.1
769         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
770         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
771 }
772 run_test 24a "rename file to non-existent target"
773
774 test_24b() {
775         test_mkdir $DIR/$tdir
776         touch $DIR/$tdir/$tfile.{1,2}
777         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
778         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
779         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
780 }
781 run_test 24b "rename file to existing target"
782
783 test_24c() {
784         test_mkdir $DIR/$tdir
785         test_mkdir $DIR/$tdir/d$testnum.1
786         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
787         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
788         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
789 }
790 run_test 24c "rename directory to non-existent target"
791
792 test_24d() {
793         test_mkdir $DIR/$tdir
794         test_mkdir $DIR/$tdir/d$testnum.1
795         test_mkdir $DIR/$tdir/d$testnum.2
796         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
797         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
798         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
799 }
800 run_test 24d "rename directory to existing target"
801
802 test_24e() {
803         echo '-- cross directory renames --'
804         test_mkdir $DIR/R5a
805         test_mkdir $DIR/R5b
806         touch $DIR/R5a/f
807         mv $DIR/R5a/f $DIR/R5b/g
808         $CHECKSTAT -a $DIR/R5a/f || error
809         $CHECKSTAT -t file $DIR/R5b/g || error
810 }
811 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
812
813 test_24f() {
814         test_mkdir $DIR/R6a
815         test_mkdir $DIR/R6b
816         touch $DIR/R6a/f $DIR/R6b/g
817         mv $DIR/R6a/f $DIR/R6b/g
818         $CHECKSTAT -a $DIR/R6a/f || error
819         $CHECKSTAT -t file $DIR/R6b/g || error
820 }
821 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
822
823 test_24g() {
824         test_mkdir $DIR/R7a
825         test_mkdir $DIR/R7b
826         test_mkdir $DIR/R7a/d
827         mv $DIR/R7a/d $DIR/R7b/e
828         $CHECKSTAT -a $DIR/R7a/d || error
829         $CHECKSTAT -t dir $DIR/R7b/e || error
830 }
831 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
832
833 test_24h() {
834         test_mkdir $DIR/R8a
835         test_mkdir $DIR/R8b
836         test_mkdir $DIR/R8a/d
837         test_mkdir $DIR/R8b/e
838         mrename $DIR/R8a/d $DIR/R8b/e
839         $CHECKSTAT -a $DIR/R8a/d || error
840         $CHECKSTAT -t dir $DIR/R8b/e || error
841 }
842 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
843
844 test_24i() {
845         echo "-- rename error cases"
846         test_mkdir $DIR/R9
847         test_mkdir $DIR/R9/a
848         touch $DIR/R9/f
849         mrename $DIR/R9/f $DIR/R9/a
850         $CHECKSTAT -t file $DIR/R9/f || error
851         $CHECKSTAT -t dir  $DIR/R9/a || error
852         $CHECKSTAT -a $DIR/R9/a/f || error
853 }
854 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
855
856 test_24j() {
857         test_mkdir $DIR/R10
858         mrename $DIR/R10/f $DIR/R10/g
859         $CHECKSTAT -t dir $DIR/R10 || error
860         $CHECKSTAT -a $DIR/R10/f || error
861         $CHECKSTAT -a $DIR/R10/g || error
862 }
863 run_test 24j "source does not exist ============================"
864
865 test_24k() {
866         test_mkdir $DIR/R11a
867         test_mkdir $DIR/R11a/d
868         touch $DIR/R11a/f
869         mv $DIR/R11a/f $DIR/R11a/d
870         $CHECKSTAT -a $DIR/R11a/f || error
871         $CHECKSTAT -t file $DIR/R11a/d/f || error
872 }
873 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
874
875 # bug 2429 - rename foo foo foo creates invalid file
876 test_24l() {
877         f="$DIR/f24l"
878         $MULTIOP $f OcNs || error
879 }
880 run_test 24l "Renaming a file to itself ========================"
881
882 test_24m() {
883         f="$DIR/f24m"
884         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
885         # on ext3 this does not remove either the source or target files
886         # though the "expected" operation would be to remove the source
887         $CHECKSTAT -t file ${f} || error "${f} missing"
888         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
889 }
890 run_test 24m "Renaming a file to a hard link to itself ========="
891
892 test_24n() {
893     f="$DIR/f24n"
894     # this stats the old file after it was renamed, so it should fail
895     touch ${f}
896     $CHECKSTAT ${f}
897     mv ${f} ${f}.rename
898     $CHECKSTAT ${f}.rename
899     $CHECKSTAT -a ${f}
900 }
901 run_test 24n "Statting the old file after renaming (Posix rename 2)"
902
903 test_24o() {
904         check_kernel_version 37 || return 0
905         test_mkdir -p $DIR/d24o
906         rename_many -s random -v -n 10 $DIR/d24o
907 }
908 run_test 24o "rename of files during htree split ==============="
909
910 test_24p() {
911         test_mkdir $DIR/R12a
912         test_mkdir $DIR/R12b
913         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
914         mrename $DIR/R12a $DIR/R12b
915         $CHECKSTAT -a $DIR/R12a || error
916         $CHECKSTAT -t dir $DIR/R12b || error
917         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
918         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
919 }
920 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
921
922 cleanup_multiop_pause() {
923         trap 0
924         kill -USR1 $MULTIPID
925 }
926
927 test_24q() {
928         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
929         test_mkdir $DIR/R13a
930         test_mkdir $DIR/R13b
931         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
932         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
933         MULTIPID=$!
934
935         trap cleanup_multiop_pause EXIT
936         mrename $DIR/R13a $DIR/R13b
937         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
938         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
939         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
940         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
941         cleanup_multiop_pause
942         wait $MULTIPID || error "multiop close failed"
943 }
944 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
945
946 test_24r() { #bug 3789
947         test_mkdir $DIR/R14a
948         test_mkdir $DIR/R14a/b
949         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
950         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
951         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
952 }
953 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
954
955 test_24s() {
956         test_mkdir $DIR/R15a
957         test_mkdir $DIR/R15a/b
958         test_mkdir $DIR/R15a/b/c
959         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
960         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
961         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
962 }
963 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
964 test_24t() {
965         test_mkdir $DIR/R16a
966         test_mkdir $DIR/R16a/b
967         test_mkdir $DIR/R16a/b/c
968         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
969         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
970         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
971 }
972 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
973
974 test_24u() { # bug12192
975         rm -rf $DIR/$tfile
976         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
977         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
978 }
979 run_test 24u "create stripe file"
980
981 page_size() {
982         getconf PAGE_SIZE
983 }
984
985 simple_cleanup_common() {
986         trap 0
987         rm -rf $DIR/$tdir
988         wait_delete_completed
989 }
990
991 max_pages_per_rpc() {
992         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -1
993 }
994
995 test_24v() {
996         local NRFILES=100000
997         local FREE_INODES=$(mdt_free_inodes 0)
998         [ $FREE_INODES -lt $NRFILES ] && \
999                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1000                 return
1001
1002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1003         trap simple_cleanup_common EXIT
1004
1005         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1006         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1007
1008         mkdir -p $DIR/$tdir
1009         createmany -m $DIR/$tdir/$tfile $NRFILES
1010
1011         cancel_lru_locks mdc
1012         lctl set_param mdc.*.stats clear
1013
1014         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1015
1016         # LU-5 large readdir
1017         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1018         #               8 bytes for name(filename is mostly 5 in this test) +
1019         #               8 bytes for luda_type
1020         # take into account of overhead in lu_dirpage header and end mark in
1021         # each page, plus one in RPC_NUM calculation.
1022         DIRENT_SIZE=48
1023         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1024         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1025         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats | \
1026                                 awk '/^mds_readpage/ {print $2}')
1027         [ $mds_readpage -gt $RPC_NUM ] && \
1028                 error "large readdir doesn't take effect"
1029
1030         simple_cleanup_common
1031 }
1032 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1033
1034 test_24w() { # bug21506
1035         SZ1=234852
1036         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1037         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1038         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1039         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1040         [ "$SZ1" = "$SZ2" ] || \
1041                 error "Error reading at the end of the file $tfile"
1042 }
1043 run_test 24w "Reading a file larger than 4Gb"
1044
1045 test_24x() {
1046         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1047         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1048         local MDTIDX=1
1049         local remote_dir=$DIR/$tdir/remote_dir
1050
1051         mkdir -p $DIR/$tdir
1052         $LFS mkdir -i $MDTIDX $remote_dir ||
1053                 error "create remote directory failed"
1054
1055         mkdir -p $DIR/$tdir/src_dir
1056         touch $DIR/$tdir/src_file
1057         mkdir -p $remote_dir/tgt_dir
1058         touch $remote_dir/tgt_file
1059
1060         mrename $remote_dir $DIR/ &&
1061                 error "rename dir cross MDT works!"
1062
1063         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1064                 error "rename dir cross MDT works!"
1065
1066         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1067                 error "rename file cross MDT works!"
1068
1069         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1070                 error "ln file cross MDT should not work!"
1071
1072         rm -rf $DIR/$tdir || error "Can not delete directories"
1073 }
1074 run_test 24x "cross rename/link should be failed"
1075
1076 test_24y() {
1077         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1078         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1079         local MDTIDX=1
1080         local remote_dir=$DIR/$tdir/remote_dir
1081
1082         mkdir -p $DIR/$tdir
1083         $LFS mkdir -i $MDTIDX $remote_dir ||
1084                    error "create remote directory failed"
1085
1086         mkdir -p $remote_dir/src_dir
1087         touch $remote_dir/src_file
1088         mkdir -p $remote_dir/tgt_dir
1089         touch $remote_dir/tgt_file
1090
1091         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1092                 error "rename subdir in the same remote dir failed!"
1093
1094         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1095                 error "rename files in the same remote dir failed!"
1096
1097         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1098                 error "link files in the same remote dir failed!"
1099
1100         rm -rf $DIR/$tdir || error "Can not delete directories"
1101 }
1102 run_test 24y "rename/link on the same dir should succeed"
1103
1104 test_24z() {
1105         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1107         local MDTIDX=1
1108         local remote_src=$DIR/$tdir/remote_dir
1109         local remote_tgt=$DIR/$tdir/remote_tgt
1110
1111         mkdir -p $DIR/$tdir
1112         $LFS mkdir -i $MDTIDX $remote_src ||
1113                    error "create remote directory failed"
1114
1115         $LFS mkdir -i $MDTIDX $remote_tgt ||
1116                    error "create remote directory failed"
1117
1118         mrename $remote_src $remote_tgt &&
1119                 error "rename remote dirs should not work!"
1120
1121         # If target dir does not exists, it should succeed
1122         rm -rf $remote_tgt
1123         mrename $remote_src $remote_tgt ||
1124                 error "rename remote dirs(tgt dir does not exists) failed!"
1125
1126         rm -rf $DIR/$tdir || error "Can not delete directories"
1127 }
1128 run_test 24z "rename one remote dir to another remote dir should fail"
1129
1130 test_24A() { # LU-3182
1131         local NFILES=5000
1132
1133         rm -rf $DIR/$tdir
1134         mkdir -p $DIR/$tdir
1135         createmany -m $DIR/$tdir/$tfile $NFILES
1136         local t=`ls $DIR/$tdir | wc -l`
1137         local u=`ls $DIR/$tdir | sort -u | wc -l`
1138         if [ $t -ne $NFILES -o $u -ne $NFILES ] ; then
1139                 error "Expected $NFILES files, got $t ($u unique)"
1140         fi
1141
1142         rm -rf $DIR/$tdir || error "Can not delete directories"
1143 }
1144 run_test 24A "readdir() returns correct number of entries."
1145
1146 test_25a() {
1147         echo '== symlink sanity ============================================='
1148
1149         test_mkdir $DIR/d25
1150         ln -s d25 $DIR/s25
1151         touch $DIR/s25/foo || error
1152 }
1153 run_test 25a "create file in symlinked directory ==============="
1154
1155 test_25b() {
1156         [ ! -d $DIR/d25 ] && test_25a
1157         $CHECKSTAT -t file $DIR/s25/foo || error
1158 }
1159 run_test 25b "lookup file in symlinked directory ==============="
1160
1161 test_26a() {
1162         test_mkdir $DIR/d26
1163         test_mkdir $DIR/d26/d26-2
1164         ln -s d26/d26-2 $DIR/s26
1165         touch $DIR/s26/foo || error
1166 }
1167 run_test 26a "multiple component symlink ======================="
1168
1169 test_26b() {
1170         test_mkdir -p $DIR/d26b/d26-2
1171         ln -s d26b/d26-2/foo $DIR/s26-2
1172         touch $DIR/s26-2 || error
1173 }
1174 run_test 26b "multiple component symlink at end of lookup ======"
1175
1176 test_26c() {
1177         test_mkdir $DIR/d26.2
1178         touch $DIR/d26.2/foo
1179         ln -s d26.2 $DIR/s26.2-1
1180         ln -s s26.2-1 $DIR/s26.2-2
1181         ln -s s26.2-2 $DIR/s26.2-3
1182         chmod 0666 $DIR/s26.2-3/foo
1183 }
1184 run_test 26c "chain of symlinks ================================"
1185
1186 # recursive symlinks (bug 439)
1187 test_26d() {
1188         ln -s d26-3/foo $DIR/d26-3
1189 }
1190 run_test 26d "create multiple component recursive symlink ======"
1191
1192 test_26e() {
1193         [ ! -h $DIR/d26-3 ] && test_26d
1194         rm $DIR/d26-3
1195 }
1196 run_test 26e "unlink multiple component recursive symlink ======"
1197
1198 # recursive symlinks (bug 7022)
1199 test_26f() {
1200         test_mkdir -p $DIR/$tdir
1201         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1202         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1203         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1204         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1205         cd $tfile                || error "cd $tfile failed"
1206         ln -s .. dotdot          || error "ln dotdot failed"
1207         ln -s dotdot/lndir lndir || error "ln lndir failed"
1208         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1209         output=`ls $tfile/$tfile/lndir/bar1`
1210         [ "$output" = bar1 ] && error "unexpected output"
1211         rm -r $tfile             || error "rm $tfile failed"
1212         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1213 }
1214 run_test 26f "rm -r of a directory which has recursive symlink ="
1215
1216 test_27a() {
1217         echo '== stripe sanity =============================================='
1218         test_mkdir -p $DIR/d27 || error "mkdir failed"
1219         $GETSTRIPE $DIR/d27
1220         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1221         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1222         pass
1223         log "== test_27a: write to one stripe file ========================="
1224         cp /etc/hosts $DIR/d27/f0 || error
1225 }
1226 run_test 27a "one stripe file =================================="
1227
1228 test_27b() {
1229         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1230         test_mkdir -p $DIR/d27
1231         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1232         $GETSTRIPE -c $DIR/d27/f01
1233         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1234                 error "two-stripe file doesn't have two stripes"
1235
1236         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1237 }
1238 run_test 27b "create and write to two stripe file"
1239
1240 test_27d() {
1241         test_mkdir -p $DIR/d27
1242         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1243         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1244         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1245 }
1246 run_test 27d "create file with default settings ================"
1247
1248 test_27e() {
1249         test_mkdir -p $DIR/d27
1250         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1251         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1252         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1253 }
1254 run_test 27e "setstripe existing file (should return error) ======"
1255
1256 test_27f() {
1257         test_mkdir -p $DIR/d27
1258         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1259         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1260         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1261 }
1262 run_test 27f "setstripe with bad stripe size (should return error)"
1263
1264 test_27g() {
1265         test_mkdir -p $DIR/d27
1266         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1267         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1268                 error "$DIR/d27/fnone has object"
1269 }
1270 run_test 27g "$GETSTRIPE with no objects"
1271
1272 test_27i() {
1273         touch $DIR/d27/fsome || error "touch failed"
1274         [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
1275 }
1276 run_test 27i "$GETSTRIPE with some objects"
1277
1278 test_27j() {
1279         test_mkdir -p $DIR/d27
1280         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1281 }
1282 run_test 27j "setstripe with bad stripe offset (should return error)"
1283
1284 test_27k() { # bug 2844
1285         test_mkdir -p $DIR/d27
1286         FILE=$DIR/d27/f27k
1287         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1288         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1289         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1290         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1291         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1292         dd if=/dev/zero of=$FILE bs=4k count=1
1293         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1294         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1295 }
1296 run_test 27k "limit i_blksize for broken user apps ============="
1297
1298 test_27l() {
1299         test_mkdir -p $DIR/d27
1300         mcreate $DIR/f27l || error "creating file"
1301         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1302                 error "setstripe should have failed" || true
1303 }
1304 run_test 27l "check setstripe permissions (should return error)"
1305
1306 test_27m() {
1307         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1308                 return
1309         if [ $ORIGFREE -gt $MAXFREE ]; then
1310                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1311                 return
1312         fi
1313         trap simple_cleanup_common EXIT
1314         test_mkdir -p $DIR/$tdir
1315         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1316         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1317                 error "dd should fill OST0"
1318         i=2
1319         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1320                 i=`expr $i + 1`
1321                 [ $i -gt 256 ] && break
1322         done
1323         i=`expr $i + 1`
1324         touch $DIR/$tdir/f27m_$i
1325         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1326                 error "OST0 was full but new created file still use it"
1327         i=`expr $i + 1`
1328         touch $DIR/$tdir/f27m_$i
1329         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1330                 error "OST0 was full but new created file still use it"
1331         simple_cleanup_common
1332 }
1333 run_test 27m "create file while OST0 was full =================="
1334
1335 sleep_maxage() {
1336         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1337         sleep $DELAY
1338 }
1339
1340 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1341 # if the OST isn't full anymore.
1342 reset_enospc() {
1343         local OSTIDX=${1:-""}
1344
1345         local list=$(comma_list $(osts_nodes))
1346         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1347
1348         do_nodes $list lctl set_param fail_loc=0
1349         sync    # initiate all OST_DESTROYs from MDS to OST
1350         sleep_maxage
1351 }
1352
1353 exhaust_precreations() {
1354         local OSTIDX=$1
1355         local FAILLOC=$2
1356         local FAILIDX=${3:-$OSTIDX}
1357
1358         test_mkdir -p $DIR/$tdir
1359         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1360         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1361
1362         local OST=$(ostname_from_index $OSTIDX)
1363         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1364                           sed -e 's/_UUID$//;s/^.*-//')
1365
1366         # on the mdt's osc
1367         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1368         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1369                         osc.$mdtosc_proc1.prealloc_last_id)
1370         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1371                         osc.$mdtosc_proc1.prealloc_next_id)
1372
1373         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1374         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1375
1376         test_mkdir -p $DIR/$tdir/${OST}
1377         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1378 #define OBD_FAIL_OST_ENOSPC              0x215
1379         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1380         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1381         echo "Creating to objid $last_id on ost $OST..."
1382         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1383         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1384         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1385         sleep_maxage
1386 }
1387
1388 exhaust_all_precreations() {
1389         local i
1390         for (( i=0; i < OSTCOUNT; i++ )) ; do
1391                 exhaust_precreations $i $1 -1
1392         done
1393 }
1394
1395 test_27n() {
1396         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1397         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1398         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1399         remote_ost_nodsh && skip "remote OST with nodsh" && return
1400
1401         reset_enospc
1402         rm -f $DIR/$tdir/$tfile
1403         exhaust_precreations 0 0x80000215
1404         $SETSTRIPE -c -1 $DIR/$tdir
1405         touch $DIR/$tdir/$tfile || error
1406         $GETSTRIPE $DIR/$tdir/$tfile
1407         reset_enospc
1408 }
1409 run_test 27n "create file with some full OSTs =================="
1410
1411 test_27o() {
1412         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1413         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1414         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1415         remote_ost_nodsh && skip "remote OST with nodsh" && return
1416
1417         reset_enospc
1418         rm -f $DIR/$tdir/$tfile
1419         exhaust_all_precreations 0x215
1420
1421         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1422
1423         reset_enospc
1424         rm -rf $DIR/$tdir/*
1425 }
1426 run_test 27o "create file with all full OSTs (should error) ===="
1427
1428 test_27p() {
1429         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1430         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1431         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1432         remote_ost_nodsh && skip "remote OST with nodsh" && return
1433
1434         reset_enospc
1435         rm -f $DIR/$tdir/$tfile
1436         test_mkdir -p $DIR/$tdir
1437
1438         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1439         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1440         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1441
1442         exhaust_precreations 0 0x80000215
1443         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1444         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1445         $GETSTRIPE $DIR/$tdir/$tfile
1446
1447         reset_enospc
1448 }
1449 run_test 27p "append to a truncated file with some full OSTs ==="
1450
1451 test_27q() {
1452         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1454         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1455         remote_ost_nodsh && skip "remote OST with nodsh" && return
1456
1457         reset_enospc
1458         rm -f $DIR/$tdir/$tfile
1459
1460         test_mkdir -p $DIR/$tdir
1461         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1462         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1463         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1464
1465         exhaust_all_precreations 0x215
1466
1467         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1468         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1469
1470         reset_enospc
1471 }
1472 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1473
1474 test_27r() {
1475         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1476         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1477         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1478         remote_ost_nodsh && skip "remote OST with nodsh" && return
1479
1480         reset_enospc
1481         rm -f $DIR/$tdir/$tfile
1482         exhaust_precreations 0 0x80000215
1483
1484         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1485
1486         reset_enospc
1487 }
1488 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1489
1490 test_27s() { # bug 10725
1491         test_mkdir -p $DIR/$tdir
1492         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1493         local stripe_count=0
1494         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1495         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1496                 error "stripe width >= 2^32 succeeded" || true
1497
1498 }
1499 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1500
1501 test_27t() { # bug 10864
1502         WDIR=`pwd`
1503         WLFS=`which lfs`
1504         cd $DIR
1505         touch $tfile
1506         $WLFS getstripe $tfile
1507         cd $WDIR
1508 }
1509 run_test 27t "check that utils parse path correctly"
1510
1511 test_27u() { # bug 4900
1512         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1513         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1514         local index
1515         local list=$(comma_list $(mdts_nodes))
1516
1517 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1518         do_nodes $list $LCTL set_param fail_loc=0x139
1519         test_mkdir -p $DIR/$tdir
1520         rm -rf $DIR/$tdir/*
1521         createmany -o $DIR/$tdir/t- 1000
1522         do_nodes $list $LCTL set_param fail_loc=0
1523
1524         TLOG=$DIR/$tfile.getstripe
1525         $GETSTRIPE $DIR/$tdir > $TLOG
1526         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1527         unlinkmany $DIR/$tdir/t- 1000
1528         [ $OBJS -gt 0 ] && \
1529                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1530 }
1531 run_test 27u "skip object creation on OSC w/o objects =========="
1532
1533 test_27v() { # bug 4900
1534         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1536         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1537         remote_ost_nodsh && skip "remote OST with nodsh" && return
1538
1539         exhaust_all_precreations 0x215
1540         reset_enospc
1541
1542         test_mkdir -p $DIR/$tdir
1543         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1544
1545         touch $DIR/$tdir/$tfile
1546         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1547         # all except ost1
1548         for (( i=1; i < OSTCOUNT; i++ )); do
1549                 do_facet ost$i lctl set_param fail_loc=0x705
1550         done
1551         local START=`date +%s`
1552         createmany -o $DIR/$tdir/$tfile 32
1553
1554         local FINISH=`date +%s`
1555         local TIMEOUT=`lctl get_param -n timeout`
1556         local PROCESS=$((FINISH - START))
1557         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1558                error "$FINISH - $START >= $TIMEOUT / 2"
1559         sleep $((TIMEOUT / 2 - PROCESS))
1560         reset_enospc
1561 }
1562 run_test 27v "skip object creation on slow OST ================="
1563
1564 test_27w() { # bug 10997
1565         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1566         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1567         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1568                 error "stripe size $size != 65536" || true
1569         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1570                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1571 }
1572 run_test 27w "check $SETSTRIPE -S option"
1573
1574 test_27wa() {
1575         [ "$OSTCOUNT" -lt "2" ] &&
1576                 skip_env "skipping multiple stripe count/offset test" && return
1577
1578         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1579         for i in $(seq 1 $OSTCOUNT); do
1580                 offset=$((i - 1))
1581                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1582                         error "setstripe -c $i -i $offset failed"
1583                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1584                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1585                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1586                 [ $index -ne $offset ] &&
1587                         error "stripe offset $index != $offset" || true
1588         done
1589 }
1590 run_test 27wa "check $SETSTRIPE -c -i options"
1591
1592 test_27x() {
1593         remote_ost_nodsh && skip "remote OST with nodsh" && return
1594         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1595         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1596         OFFSET=$(($OSTCOUNT - 1))
1597         OSTIDX=0
1598         local OST=$(ostname_from_index $OSTIDX)
1599
1600         test_mkdir -p $DIR/$tdir
1601         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1602         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1603         sleep_maxage
1604         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1605         for i in `seq 0 $OFFSET`; do
1606                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1607                 error "OST0 was degraded but new created file still use it"
1608         done
1609         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1610 }
1611 run_test 27x "create files while OST0 is degraded"
1612
1613 test_27y() {
1614         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1615         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1616         remote_ost_nodsh && skip "remote OST with nodsh" && return
1617         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1618
1619         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1620         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1621             osc.$mdtosc.prealloc_last_id)
1622         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1623             osc.$mdtosc.prealloc_next_id)
1624         local fcount=$((last_id - next_id))
1625         [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1626         [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1627
1628         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1629                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1630         local OST_DEACTIVE_IDX=-1
1631         local OSC
1632         local OSTIDX
1633         local OST
1634
1635         for OSC in $MDS_OSCS; do
1636                 OST=$(osc_to_ost $OSC)
1637                 OSTIDX=$(index_from_ostuuid $OST)
1638                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1639                         OST_DEACTIVE_IDX=$OSTIDX
1640                 fi
1641                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1642                         echo $OSC "is Deactivated:"
1643                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1644                 fi
1645         done
1646
1647         OSTIDX=$(index_from_ostuuid $OST)
1648         mkdir -p $DIR/$tdir
1649         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1650
1651         for OSC in $MDS_OSCS; do
1652                 OST=$(osc_to_ost $OSC)
1653                 OSTIDX=$(index_from_ostuuid $OST)
1654                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1655                         echo $OST "is degraded:"
1656                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1657                                                 obdfilter.$OST.degraded=1
1658                 fi
1659         done
1660
1661         sleep_maxage
1662         createmany -o $DIR/$tdir/$tfile $fcount
1663
1664         for OSC in $MDS_OSCS; do
1665                 OST=$(osc_to_ost $OSC)
1666                 OSTIDX=$(index_from_ostuuid $OST)
1667                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1668                         echo $OST "is recovered from degraded:"
1669                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1670                                                 obdfilter.$OST.degraded=0
1671                 else
1672                         do_facet $SINGLEMDS lctl --device %$OSC activate
1673                 fi
1674         done
1675
1676         # all osp devices get activated, hence -1 stripe count restored
1677         local stripecnt=0
1678
1679         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1680         # devices get activated.
1681         sleep_maxage
1682         $SETSTRIPE -c -1 $DIR/$tfile
1683         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1684         rm -f $DIR/$tfile
1685         [ $stripecnt -ne $OSTCOUNT ] &&
1686                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1687         return 0
1688 }
1689 run_test 27y "create files while OST0 is degraded and the rest inactive"
1690
1691 check_seq_oid()
1692 {
1693         log "check file $1"
1694
1695         lmm_count=$($GETSTRIPE -c $1)
1696         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1697         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1698
1699         local old_ifs="$IFS"
1700         IFS=$'[:]'
1701         fid=($($LFS path2fid $1))
1702         IFS="$old_ifs"
1703
1704         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1705         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1706
1707         # compare lmm_seq and lu_fid->f_seq
1708         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1709         # compare lmm_object_id and lu_fid->oid
1710         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1711
1712         # check the trusted.fid attribute of the OST objects of the file
1713         local have_obdidx=false
1714         local stripe_nr=0
1715         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1716                 # skip lines up to and including "obdidx"
1717                 [ -z "$obdidx" ] && break
1718                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1719                 $have_obdidx || continue
1720
1721                 local ost=$((obdidx + 1))
1722                 local dev=$(ostdevname $ost)
1723                 local oid_hex
1724
1725                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1726
1727                 seq=$(echo $seq | sed -e "s/^0x//g")
1728                 if [ $seq == 0 ]; then
1729                         oid_hex=$(echo $oid)
1730                 else
1731                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1732                 fi
1733                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1734
1735                 local ff
1736                 #
1737                 # Don't unmount/remount the OSTs if we don't need to do that.
1738                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1739                 # update too, until that use mount/ll_decode_filter_fid/mount.
1740                 # Re-enable when debugfs will understand new filter_fid.
1741                 #
1742                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1743                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1744                                 $dev 2>/dev/null" | grep "parent=")
1745                 else
1746                         stop ost$ost
1747                         mount_fstype ost$ost
1748                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1749                                 $(facet_mntpt ost$ost)/$obj_file)
1750                         unmount_fstype ost$ost
1751                         start ost$ost $dev $OST_MOUNT_OPTS
1752                 fi
1753
1754                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1755
1756                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1757
1758                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1759                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1760                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1761                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1762                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1763                 local ff_pstripe
1764                 if echo $ff_parent | grep -q 'stripe='; then
1765                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1766                 else
1767                         #
1768                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1769                         # into f_ver in this case.  See the comment on
1770                         # ff_parent.
1771                         #
1772                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1773                                 sed -e 's/\]//')
1774                 fi
1775
1776                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1777                 [ $ff_pseq = $lmm_seq ] ||
1778                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1779                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1780                 [ $ff_poid = $lmm_oid ] ||
1781                         error "FF parent OID $ff_poid != $lmm_oid"
1782                 (($ff_pstripe == $stripe_nr)) ||
1783                         error "FF stripe $ff_pstripe != $stripe_nr"
1784
1785                 stripe_nr=$((stripe_nr + 1))
1786         done
1787 }
1788
1789 test_27z() {
1790         remote_ost_nodsh && skip "remote OST with nodsh" && return
1791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1792         test_mkdir -p $DIR/$tdir
1793
1794         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1795                 { error "setstripe -c -1 failed"; return 1; }
1796         # We need to send a write to every object to get parent FID info set.
1797         # This _should_ also work for setattr, but does not currently.
1798         # touch $DIR/$tdir/$tfile-1 ||
1799         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1800                 { error "dd $tfile-1 failed"; return 2; }
1801         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1802                 { error "setstripe -c -1 failed"; return 3; }
1803         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1804                 { error "dd $tfile-2 failed"; return 4; }
1805
1806         # make sure write RPCs have been sent to OSTs
1807         sync; sleep 5; sync
1808
1809         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1810         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1811 }
1812 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1813
1814 test_27A() { # b=19102
1815         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1816         local restore_size=$($GETSTRIPE -S $MOUNT)
1817         local restore_count=$($GETSTRIPE -c $MOUNT)
1818         local restore_offset=$($GETSTRIPE -i $MOUNT)
1819         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1820         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1821                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1822         local default_size=$($GETSTRIPE -S $MOUNT)
1823         local default_offset=$($GETSTRIPE -i $MOUNT)
1824         local dsize=$((1024 * 1024))
1825         [ $default_size -eq $dsize ] ||
1826                 error "stripe size $default_size != $dsize"
1827         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1828         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1829 }
1830 run_test 27A "check filesystem-wide default LOV EA values"
1831
1832 test_27B() { # LU-2523
1833         test_mkdir -p $DIR/$tdir
1834         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1835         touch $DIR/$tdir/f0
1836         # open f1 with O_LOV_DELAY_CREATE
1837         # rename f0 onto f1
1838         # call setstripe ioctl on open file descriptor for f1
1839         # close
1840         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1841                 $DIR/$tdir/f0
1842
1843         rm -f $DIR/$tdir/f1
1844         # open f1 with O_LOV_DELAY_CREATE
1845         # unlink f1
1846         # call setstripe ioctl on open file descriptor for f1
1847         # close
1848         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1849
1850         # Allow multiop to fail in imitation of NFS's busted semantics.
1851         true
1852 }
1853 run_test 27B "call setstripe on open unlinked file/rename victim"
1854
1855 test_27C() { #LU-2871
1856         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1857
1858         declare -a ost_idx
1859         local index
1860         local found
1861         local i
1862         local j
1863
1864         test_mkdir -p $DIR/$tdir
1865         cd $DIR/$tdir
1866         for i in $(seq 0 $((OSTCOUNT - 1))); do
1867                 # set stripe across all OSTs starting from OST$i
1868                 $SETSTRIPE -i $i -c -1 $tfile$i
1869                 # get striping information
1870                 ost_idx=($($GETSTRIPE $tfile$i |
1871                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1872                 echo ${ost_idx[@]}
1873
1874                 # check the layout
1875                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1876                         error "${#ost_idx[@]} != $OSTCOUNT"
1877
1878                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1879                         found=0
1880                         for j in $(echo ${ost_idx[@]}); do
1881                                 if [ $index -eq $j ]; then
1882                                         found=1
1883                                         break
1884                                 fi
1885                         done
1886                         [ $found = 1 ] ||
1887                                 error "Can not find $index in ${ost_idx[@]}"
1888                 done
1889         done
1890 }
1891 run_test 27C "check full striping across all OSTs"
1892
1893 # createtest also checks that device nodes are created and
1894 # then visible correctly (#2091)
1895 test_28() { # bug 2091
1896         test_mkdir $DIR/d28
1897         $CREATETEST $DIR/d28/ct || error
1898 }
1899 run_test 28 "create/mknod/mkdir with bad file types ============"
1900
1901 test_29() {
1902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1903         cancel_lru_locks mdc
1904         test_mkdir $DIR/d29
1905         touch $DIR/d29/foo
1906         log 'first d29'
1907         ls -l $DIR/d29
1908
1909         declare -i LOCKCOUNTORIG=0
1910         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1911                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1912         done
1913         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1914
1915         declare -i LOCKUNUSEDCOUNTORIG=0
1916         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1917                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1918         done
1919
1920         log 'second d29'
1921         ls -l $DIR/d29
1922         log 'done'
1923
1924         declare -i LOCKCOUNTCURRENT=0
1925         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1926                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1927         done
1928
1929         declare -i LOCKUNUSEDCOUNTCURRENT=0
1930         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1931                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1932         done
1933
1934         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1935                 lctl set_param -n ldlm.dump_namespaces ""
1936                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1937                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1938                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1939                 return 2
1940         fi
1941         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1942                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1943                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1944                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1945                 return 3
1946         fi
1947 }
1948 run_test 29 "IT_GETATTR regression  ============================"
1949
1950 test_30a() { # was test_30
1951         cp `which ls` $DIR || cp /bin/ls $DIR
1952         $DIR/ls / || error
1953         rm $DIR/ls
1954 }
1955 run_test 30a "execute binary from Lustre (execve) =============="
1956
1957 test_30b() {
1958         cp `which ls` $DIR || cp /bin/ls $DIR
1959         chmod go+rx $DIR/ls
1960         $RUNAS $DIR/ls / || error
1961         rm $DIR/ls
1962 }
1963 run_test 30b "execute binary from Lustre as non-root ==========="
1964
1965 test_30c() { # b=22376
1966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1967         cp `which ls` $DIR || cp /bin/ls $DIR
1968         chmod a-rw $DIR/ls
1969         cancel_lru_locks mdc
1970         cancel_lru_locks osc
1971         $RUNAS $DIR/ls / || error
1972         rm -f $DIR/ls
1973 }
1974 run_test 30c "execute binary from Lustre without read perms ===="
1975
1976 test_31a() {
1977         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1978         $CHECKSTAT -a $DIR/f31 || error
1979 }
1980 run_test 31a "open-unlink file =================================="
1981
1982 test_31b() {
1983         touch $DIR/f31 || error
1984         ln $DIR/f31 $DIR/f31b || error
1985         $MULTIOP $DIR/f31b Ouc || error
1986         $CHECKSTAT -t file $DIR/f31 || error
1987 }
1988 run_test 31b "unlink file with multiple links while open ======="
1989
1990 test_31c() {
1991         touch $DIR/f31 || error
1992         ln $DIR/f31 $DIR/f31c || error
1993         multiop_bg_pause $DIR/f31 O_uc || return 1
1994         MULTIPID=$!
1995         $MULTIOP $DIR/f31c Ouc
1996         kill -USR1 $MULTIPID
1997         wait $MULTIPID
1998 }
1999 run_test 31c "open-unlink file with multiple links ============="
2000
2001 test_31d() {
2002         opendirunlink $DIR/d31d $DIR/d31d || error
2003         $CHECKSTAT -a $DIR/d31d || error
2004 }
2005 run_test 31d "remove of open directory ========================="
2006
2007 test_31e() { # bug 2904
2008         check_kernel_version 34 || return 0
2009         openfilleddirunlink $DIR/d31e || error
2010 }
2011 run_test 31e "remove of open non-empty directory ==============="
2012
2013 test_31f() { # bug 4554
2014         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2015         set -vx
2016         test_mkdir $DIR/d31f
2017         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2018         cp /etc/hosts $DIR/d31f
2019         ls -l $DIR/d31f
2020         $GETSTRIPE $DIR/d31f/hosts
2021         multiop_bg_pause $DIR/d31f D_c || return 1
2022         MULTIPID=$!
2023
2024         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2025         test_mkdir $DIR/d31f
2026         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2027         cp /etc/hosts $DIR/d31f
2028         ls -l $DIR/d31f
2029         $GETSTRIPE $DIR/d31f/hosts
2030         multiop_bg_pause $DIR/d31f D_c || return 1
2031         MULTIPID2=$!
2032
2033         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2034         wait $MULTIPID || error "first opendir $MULTIPID failed"
2035
2036         sleep 6
2037
2038         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2039         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2040         set +vx
2041 }
2042 run_test 31f "remove of open directory with open-unlink file ==="
2043
2044 test_31g() {
2045         echo "-- cross directory link --"
2046         test_mkdir $DIR/d31ga
2047         test_mkdir $DIR/d31gb
2048         touch $DIR/d31ga/f
2049         ln $DIR/d31ga/f $DIR/d31gb/g
2050         $CHECKSTAT -t file $DIR/d31ga/f || error "source"
2051         [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
2052         $CHECKSTAT -t file $DIR/d31gb/g || error "target"
2053         [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
2054 }
2055 run_test 31g "cross directory link==============="
2056
2057 test_31h() {
2058         echo "-- cross directory link --"
2059         test_mkdir $DIR/d31h
2060         test_mkdir $DIR/d31h/dir
2061         touch $DIR/d31h/f
2062         ln $DIR/d31h/f $DIR/d31h/dir/g
2063         $CHECKSTAT -t file $DIR/d31h/f || error "source"
2064         [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
2065         $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
2066         [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
2067 }
2068 run_test 31h "cross directory link under child==============="
2069
2070 test_31i() {
2071         echo "-- cross directory link --"
2072         test_mkdir $DIR/d31i
2073         test_mkdir $DIR/d31i/dir
2074         touch $DIR/d31i/dir/f
2075         ln $DIR/d31i/dir/f $DIR/d31i/g
2076         $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
2077         [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
2078         $CHECKSTAT -t file $DIR/d31i/g || error "target"
2079         [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
2080 }
2081 run_test 31i "cross directory link under parent==============="
2082
2083
2084 test_31j() {
2085         test_mkdir $DIR/d31j
2086         test_mkdir $DIR/d31j/dir1
2087         ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
2088         link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
2089         mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
2090         mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
2091         return 0
2092 }
2093 run_test 31j "link for directory==============="
2094
2095
2096 test_31k() {
2097         test_mkdir $DIR/d31k
2098         touch $DIR/d31k/s
2099         touch $DIR/d31k/exist
2100         mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
2101         mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
2102         mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
2103         mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
2104         mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
2105         mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
2106         mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
2107         return 0
2108 }
2109 run_test 31k "link to file: the same, non-existing, dir==============="
2110
2111 test_31m() {
2112         test_mkdir $DIR/d31m
2113         touch $DIR/d31m/s
2114         test_mkdir $DIR/d31m2
2115         touch $DIR/d31m2/exist
2116         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2117         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2118         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2119         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2120         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2121         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2122         return 0
2123 }
2124 run_test 31m "link to file: the same, non-existing, dir==============="
2125
2126 test_31n() {
2127         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2128         nlink=$(stat --format=%h $DIR/$tfile)
2129         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2130         local fd=$(free_fd)
2131         local cmd="exec $fd<$DIR/$tfile"
2132         eval $cmd
2133         cmd="exec $fd<&-"
2134         trap "eval $cmd" EXIT
2135         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2136         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2137         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2138         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2139         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2140         eval $cmd
2141 }
2142 run_test 31n "check link count of unlinked file"
2143
2144 link_one() {
2145         local TEMPNAME=$(mktemp $1_XXXXXX)
2146         mlink $TEMPNAME $1 2> /dev/null &&
2147                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2148         munlink $TEMPNAME
2149 }
2150
2151 test_31o() { # LU-2901
2152         mkdir -p $DIR/$tdir
2153         for LOOP in $(seq 100); do
2154                 rm -f $DIR/$tdir/$tfile*
2155                 for THREAD in $(seq 8); do
2156                         link_one $DIR/$tdir/$tfile.$LOOP &
2157                 done
2158                 wait
2159                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2160                 [ $LINKS -gt 1 ] && ls $DIR/$tdir &&
2161                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2162                         break || true
2163         done
2164 }
2165 run_test 31o "duplicate hard links with same filename"
2166
2167 cleanup_test32_mount() {
2168         trap 0
2169         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2170 }
2171
2172 test_32a() {
2173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2174         echo "== more mountpoints and symlinks ================="
2175         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2176         trap cleanup_test32_mount EXIT
2177         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2178         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2179         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2180         cleanup_test32_mount
2181 }
2182 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2183
2184 test_32b() {
2185         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2186         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2187         trap cleanup_test32_mount EXIT
2188         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2189         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2190         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2191         cleanup_test32_mount
2192 }
2193 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2194
2195 test_32c() {
2196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2197         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2198         trap cleanup_test32_mount EXIT
2199         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2200         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2201         test_mkdir -p $DIR/$tdir/d2/test_dir
2202         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2203         cleanup_test32_mount
2204 }
2205 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2206
2207 test_32d() {
2208         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2209         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2210         trap cleanup_test32_mount EXIT
2211         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2212         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2213         test_mkdir -p $DIR/$tdir/d2/test_dir
2214         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2215         cleanup_test32_mount
2216 }
2217 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2218
2219 test_32e() {
2220         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2221         test_mkdir -p $DIR/d32e/tmp
2222         TMP_DIR=$DIR/d32e/tmp
2223         ln -s $DIR/d32e $TMP_DIR/symlink11
2224         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2225         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2226         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2227 }
2228 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2229
2230 test_32f() {
2231         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2232         test_mkdir -p $DIR/d32f/tmp
2233         TMP_DIR=$DIR/d32f/tmp
2234         ln -s $DIR/d32f $TMP_DIR/symlink11
2235         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2236         ls $DIR/d32f/tmp/symlink11  || error
2237         ls $DIR/d32f/symlink01 || error
2238 }
2239 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2240
2241 test_32g() {
2242         TMP_DIR=$DIR/$tdir/tmp
2243         test_mkdir -p $DIR/$tdir/tmp
2244         test_mkdir $DIR/${tdir}2
2245         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2246         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2247         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2248         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2249         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2250         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2251 }
2252 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2253
2254 test_32h() {
2255         rm -fr $DIR/$tdir $DIR/${tdir}2
2256         TMP_DIR=$DIR/$tdir/tmp
2257         test_mkdir -p $DIR/$tdir/tmp
2258         test_mkdir $DIR/${tdir}2
2259         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2260         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2261         ls $TMP_DIR/symlink12 || error
2262         ls $DIR/$tdir/symlink02  || error
2263 }
2264 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2265
2266 test_32i() {
2267         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2268         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2269         trap cleanup_test32_mount EXIT
2270         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2271         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2272         touch $DIR/$tdir/test_file
2273         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2274         cleanup_test32_mount
2275 }
2276 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2277
2278 test_32j() {
2279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2280         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2281         trap cleanup_test32_mount EXIT
2282         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2283         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2284         touch $DIR/$tdir/test_file
2285         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2286         cleanup_test32_mount
2287 }
2288 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2289
2290 test_32k() {
2291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2292         rm -fr $DIR/$tdir
2293         trap cleanup_test32_mount EXIT
2294         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2295         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2296         test_mkdir -p $DIR/$tdir/d2
2297         touch $DIR/$tdir/d2/test_file || error
2298         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2299         cleanup_test32_mount
2300 }
2301 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2302
2303 test_32l() {
2304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2305         rm -fr $DIR/$tdir
2306         trap cleanup_test32_mount EXIT
2307         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2308         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2309         test_mkdir -p $DIR/$tdir/d2
2310         touch $DIR/$tdir/d2/test_file
2311         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2312         cleanup_test32_mount
2313 }
2314 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2315
2316 test_32m() {
2317         rm -fr $DIR/d32m
2318         test_mkdir -p $DIR/d32m/tmp
2319         TMP_DIR=$DIR/d32m/tmp
2320         ln -s $DIR $TMP_DIR/symlink11
2321         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2322         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2323         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2324 }
2325 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2326
2327 test_32n() {
2328         rm -fr $DIR/d32n
2329         test_mkdir -p $DIR/d32n/tmp
2330         TMP_DIR=$DIR/d32n/tmp
2331         ln -s $DIR $TMP_DIR/symlink11
2332         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2333         ls -l $DIR/d32n/tmp/symlink11  || error
2334         ls -l $DIR/d32n/symlink01 || error
2335 }
2336 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2337
2338 test_32o() {
2339         rm -fr $DIR/d32o $DIR/$tfile
2340         touch $DIR/$tfile
2341         test_mkdir -p $DIR/d32o/tmp
2342         TMP_DIR=$DIR/d32o/tmp
2343         ln -s $DIR/$tfile $TMP_DIR/symlink12
2344         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2345         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2346         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2347         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2348         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2349 }
2350 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2351
2352 test_32p() {
2353     log 32p_1
2354         rm -fr $DIR/d32p
2355     log 32p_2
2356         rm -f $DIR/$tfile
2357     log 32p_3
2358         touch $DIR/$tfile
2359     log 32p_4
2360         test_mkdir -p $DIR/d32p/tmp
2361     log 32p_5
2362         TMP_DIR=$DIR/d32p/tmp
2363     log 32p_6
2364         ln -s $DIR/$tfile $TMP_DIR/symlink12
2365     log 32p_7
2366         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2367     log 32p_8
2368         cat $DIR/d32p/tmp/symlink12 || error
2369     log 32p_9
2370         cat $DIR/d32p/symlink02 || error
2371     log 32p_10
2372 }
2373 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2374
2375 cleanup_testdir_mount() {
2376         trap 0
2377         $UMOUNT -d $DIR/$tdir
2378 }
2379
2380 test_32q() {
2381         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2382         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2383         trap cleanup_testdir_mount EXIT
2384         test_mkdir -p $DIR/$tdir
2385         touch $DIR/$tdir/under_the_mount
2386         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2387         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2388         cleanup_testdir_mount
2389 }
2390 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2391
2392 test_32r() {
2393         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2394         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2395         trap cleanup_testdir_mount EXIT
2396         test_mkdir -p $DIR/$tdir
2397         touch $DIR/$tdir/under_the_mount
2398         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2399         ls $DIR/$tdir | grep -q under_the_mount && error || true
2400         cleanup_testdir_mount
2401 }
2402 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2403
2404 test_33aa() {
2405         rm -f $DIR/$tfile
2406         touch $DIR/$tfile
2407         chmod 444 $DIR/$tfile
2408         chown $RUNAS_ID $DIR/$tfile
2409         log 33_1
2410         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2411         log 33_2
2412 }
2413 run_test 33aa "write file with mode 444 (should return error) ===="
2414
2415 test_33a() {
2416         rm -fr $DIR/d33
2417         test_mkdir -p $DIR/d33
2418         chown $RUNAS_ID $DIR/d33
2419         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2420         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2421                 error "open RDWR" || true
2422 }
2423 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2424
2425 test_33b() {
2426         rm -fr $DIR/d33
2427         test_mkdir -p $DIR/d33
2428         chown $RUNAS_ID $DIR/d33
2429         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2430 }
2431 run_test 33b "test open file with malformed flags (No panic and return error)"
2432
2433 test_33c() {
2434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2435         local ostnum
2436         local ostname
2437         local write_bytes
2438         local all_zeros
2439
2440         remote_ost_nodsh && skip "remote OST with nodsh" && return
2441         all_zeros=:
2442         rm -fr $DIR/d33
2443         test_mkdir -p $DIR/d33
2444         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2445
2446         sync
2447         for ostnum in $(seq $OSTCOUNT); do
2448                 # test-framework's OST numbering is one-based, while Lustre's
2449                 # is zero-based
2450                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2451                 # Parsing llobdstat's output sucks; we could grep the /proc
2452                 # path, but that's likely to not be as portable as using the
2453                 # llobdstat utility.  So we parse lctl output instead.
2454                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2455                         obdfilter/$ostname/stats |
2456                         awk '/^write_bytes/ {print $7}' )
2457                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2458                 if (( ${write_bytes:-0} > 0 ))
2459                 then
2460                         all_zeros=false
2461                         break;
2462                 fi
2463         done
2464
2465         $all_zeros || return 0
2466
2467         # Write four bytes
2468         echo foo > $DIR/d33/bar
2469         # Really write them
2470         sync
2471
2472         # Total up write_bytes after writing.  We'd better find non-zeros.
2473         for ostnum in $(seq $OSTCOUNT); do
2474                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2475                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2476                         obdfilter/$ostname/stats |
2477                         awk '/^write_bytes/ {print $7}' )
2478                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2479                 if (( ${write_bytes:-0} > 0 ))
2480                 then
2481                         all_zeros=false
2482                         break;
2483                 fi
2484         done
2485
2486         if $all_zeros
2487         then
2488                 for ostnum in $(seq $OSTCOUNT); do
2489                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2490                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2491                         do_facet ost$ostnum lctl get_param -n \
2492                                 obdfilter/$ostname/stats
2493                 done
2494                 error "OST not keeping write_bytes stats (b22312)"
2495         fi
2496 }
2497 run_test 33c "test llobdstat and write_bytes"
2498
2499 test_33d() {
2500         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2502         local MDTIDX=1
2503         local remote_dir=$DIR/$tdir/remote_dir
2504
2505         mkdir -p $DIR/$tdir
2506         $LFS mkdir -i $MDTIDX $remote_dir ||
2507                 error "create remote directory failed"
2508
2509         touch $remote_dir/$tfile
2510         chmod 444 $remote_dir/$tfile
2511         chown $RUNAS_ID $remote_dir/$tfile
2512
2513         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2514
2515         chown $RUNAS_ID $remote_dir
2516         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2517                                         error "create" || true
2518         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2519                                     error "open RDWR" || true
2520         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2521                                     error "create" || true
2522 }
2523 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2524
2525 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2526 test_34a() {
2527         rm -f $DIR/f34
2528         $MCREATE $DIR/f34 || error
2529         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2530         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2531         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2532         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2533 }
2534 run_test 34a "truncate file that has not been opened ==========="
2535
2536 test_34b() {
2537         [ ! -f $DIR/f34 ] && test_34a
2538         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2539         $OPENFILE -f O_RDONLY $DIR/f34
2540         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2541         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2542 }
2543 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2544
2545 test_34c() {
2546         [ ! -f $DIR/f34 ] && test_34a
2547         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2548         $OPENFILE -f O_RDWR $DIR/f34
2549         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2550         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2551 }
2552 run_test 34c "O_RDWR opening file-with-size works =============="
2553
2554 test_34d() {
2555         [ ! -f $DIR/f34 ] && test_34a
2556         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2557         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2558         rm $DIR/f34
2559 }
2560 run_test 34d "write to sparse file ============================="
2561
2562 test_34e() {
2563         rm -f $DIR/f34e
2564         $MCREATE $DIR/f34e || error
2565         $TRUNCATE $DIR/f34e 1000 || error
2566         $CHECKSTAT -s 1000 $DIR/f34e || error
2567         $OPENFILE -f O_RDWR $DIR/f34e
2568         $CHECKSTAT -s 1000 $DIR/f34e || error
2569 }
2570 run_test 34e "create objects, some with size and some without =="
2571
2572 test_34f() { # bug 6242, 6243
2573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2574         SIZE34F=48000
2575         rm -f $DIR/f34f
2576         $MCREATE $DIR/f34f || error
2577         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2578         dd if=$DIR/f34f of=$TMP/f34f
2579         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2580         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2581         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2582         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2583         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2584 }
2585 run_test 34f "read from a file with no objects until EOF ======="
2586
2587 test_34g() {
2588         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2589         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2590         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2591         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2592         cancel_lru_locks osc
2593         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2594                 error "wrong size after lock cancel"
2595
2596         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2597         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2598                 error "expanding truncate failed"
2599         cancel_lru_locks osc
2600         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2601                 error "wrong expanded size after lock cancel"
2602 }
2603 run_test 34g "truncate long file ==============================="
2604
2605 test_34h() {
2606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2607         local gid=10
2608         local sz=1000
2609
2610         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2611         sync # Flush the cache so that multiop below does not block on cache
2612              # flush when getting the group lock
2613         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2614         MULTIPID=$!
2615
2616         # Since just timed wait is not good enough, let's do a sync write
2617         # that way we are sure enough time for a roundtrip + processing
2618         # passed + 2 seconds of extra margin.
2619         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2620         rm $DIR/${tfile}-1
2621         sleep 2
2622
2623         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2624                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2625                 kill -9 $MULTIPID
2626         fi
2627         wait $MULTIPID
2628         local nsz=`stat -c %s $DIR/$tfile`
2629         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2630 }
2631 run_test 34h "ftruncate file under grouplock should not block"
2632
2633 test_35a() {
2634         cp /bin/sh $DIR/f35a
2635         chmod 444 $DIR/f35a
2636         chown $RUNAS_ID $DIR/f35a
2637         $RUNAS $DIR/f35a && error || true
2638         rm $DIR/f35a
2639 }
2640 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2641
2642 test_36a() {
2643         rm -f $DIR/f36
2644         utime $DIR/f36 || error
2645 }
2646 run_test 36a "MDS utime check (mknod, utime) ==================="
2647
2648 test_36b() {
2649         echo "" > $DIR/f36
2650         utime $DIR/f36 || error
2651 }
2652 run_test 36b "OST utime check (open, utime) ===================="
2653
2654 test_36c() {
2655         rm -f $DIR/d36/f36
2656         test_mkdir $DIR/d36
2657         chown $RUNAS_ID $DIR/d36
2658         $RUNAS utime $DIR/d36/f36 || error
2659 }
2660 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2661
2662 test_36d() {
2663         [ ! -d $DIR/d36 ] && test_36c
2664         echo "" > $DIR/d36/f36
2665         $RUNAS utime $DIR/d36/f36 || error
2666 }
2667 run_test 36d "non-root OST utime check (open, utime) ==========="
2668
2669 test_36e() {
2670         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2671         test_mkdir -p $DIR/$tdir
2672         touch $DIR/$tdir/$tfile
2673         $RUNAS utime $DIR/$tdir/$tfile && \
2674                 error "utime worked, expected failure" || true
2675 }
2676 run_test 36e "utime on non-owned file (should return error) ===="
2677
2678 subr_36fh() {
2679         local fl="$1"
2680         local LANG_SAVE=$LANG
2681         local LC_LANG_SAVE=$LC_LANG
2682         export LANG=C LC_LANG=C # for date language
2683
2684         DATESTR="Dec 20  2000"
2685         test_mkdir -p $DIR/$tdir
2686         lctl set_param fail_loc=$fl
2687         date; date +%s
2688         cp /etc/hosts $DIR/$tdir/$tfile
2689         sync & # write RPC generated with "current" inode timestamp, but delayed
2690         sleep 1
2691         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2692         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2693         cancel_lru_locks osc
2694         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2695         date; date +%s
2696         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2697                 echo "BEFORE: $LS_BEFORE" && \
2698                 echo "AFTER : $LS_AFTER" && \
2699                 echo "WANT  : $DATESTR" && \
2700                 error "$DIR/$tdir/$tfile timestamps changed" || true
2701
2702         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2703 }
2704
2705 test_36f() {
2706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2707         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2708         subr_36fh "0x80000214"
2709 }
2710 run_test 36f "utime on file racing with OST BRW write =========="
2711
2712 test_36g() {
2713         remote_ost_nodsh && skip "remote OST with nodsh" && return
2714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2715         local fmd_max_age
2716         local fmd_before
2717         local fmd_after
2718
2719         test_mkdir -p $DIR/$tdir
2720         fmd_max_age=$(do_facet ost1 \
2721                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2722                 head -n 1")
2723
2724         fmd_before=$(do_facet ost1 \
2725                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2726         touch $DIR/$tdir/$tfile
2727         sleep $((fmd_max_age + 12))
2728         fmd_after=$(do_facet ost1 \
2729                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2730
2731         echo "fmd_before: $fmd_before"
2732         echo "fmd_after: $fmd_after"
2733         [ "$fmd_after" -gt "$fmd_before" ] && \
2734                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2735                 error "fmd didn't expire after ping" || true
2736 }
2737 run_test 36g "filter mod data cache expiry ====================="
2738
2739 test_36h() {
2740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2741         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2742         subr_36fh "0x80000227"
2743 }
2744 run_test 36h "utime on file racing with OST BRW write =========="
2745
2746 # test_37 - duplicate with tests 32q 32r
2747
2748 test_38() {
2749         local file=$DIR/$tfile
2750         touch $file
2751         openfile -f O_DIRECTORY $file
2752         local RC=$?
2753         local ENOTDIR=20
2754         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2755         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2756 }
2757 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2758
2759 test_39() {
2760         touch $DIR/$tfile
2761         touch $DIR/${tfile}2
2762 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2763 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2764 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2765         sleep 2
2766         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2767         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2768                 echo "mtime"
2769                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2770                 echo "atime"
2771                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2772                 echo "ctime"
2773                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2774                 error "O_TRUNC didn't change timestamps"
2775         fi
2776 }
2777 run_test 39 "mtime changed on create ==========================="
2778
2779 test_39b() {
2780         test_mkdir -p $DIR/$tdir
2781         cp -p /etc/passwd $DIR/$tdir/fopen
2782         cp -p /etc/passwd $DIR/$tdir/flink
2783         cp -p /etc/passwd $DIR/$tdir/funlink
2784         cp -p /etc/passwd $DIR/$tdir/frename
2785         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2786
2787         sleep 1
2788         echo "aaaaaa" >> $DIR/$tdir/fopen
2789         echo "aaaaaa" >> $DIR/$tdir/flink
2790         echo "aaaaaa" >> $DIR/$tdir/funlink
2791         echo "aaaaaa" >> $DIR/$tdir/frename
2792
2793         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2794         local link_new=`stat -c %Y $DIR/$tdir/flink`
2795         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2796         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2797
2798         cat $DIR/$tdir/fopen > /dev/null
2799         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2800         rm -f $DIR/$tdir/funlink2
2801         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2802
2803         for (( i=0; i < 2; i++ )) ; do
2804                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2805                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2806                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2807                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2808
2809                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2810                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2811                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2812                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2813
2814                 cancel_lru_locks osc
2815                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2816         done
2817 }
2818 run_test 39b "mtime change on open, link, unlink, rename  ======"
2819
2820 # this should be set to past
2821 TEST_39_MTIME=`date -d "1 year ago" +%s`
2822
2823 # bug 11063
2824 test_39c() {
2825         touch $DIR1/$tfile
2826         sleep 2
2827         local mtime0=`stat -c %Y $DIR1/$tfile`
2828
2829         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2830         local mtime1=`stat -c %Y $DIR1/$tfile`
2831         [ "$mtime1" = $TEST_39_MTIME ] || \
2832                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2833
2834         local d1=`date +%s`
2835         echo hello >> $DIR1/$tfile
2836         local d2=`date +%s`
2837         local mtime2=`stat -c %Y $DIR1/$tfile`
2838         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2839                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2840
2841         mv $DIR1/$tfile $DIR1/$tfile-1
2842
2843         for (( i=0; i < 2; i++ )) ; do
2844                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2845                 [ "$mtime2" = "$mtime3" ] || \
2846                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2847
2848                 cancel_lru_locks osc
2849                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2850         done
2851 }
2852 run_test 39c "mtime change on rename ==========================="
2853
2854 # bug 21114
2855 test_39d() {
2856         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2857         touch $DIR1/$tfile
2858
2859         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2860
2861         for (( i=0; i < 2; i++ )) ; do
2862                 local mtime=`stat -c %Y $DIR1/$tfile`
2863                 [ $mtime = $TEST_39_MTIME ] || \
2864                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2865
2866                 cancel_lru_locks osc
2867                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2868         done
2869 }
2870 run_test 39d "create, utime, stat =============================="
2871
2872 # bug 21114
2873 test_39e() {
2874         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2875         touch $DIR1/$tfile
2876         local mtime1=`stat -c %Y $DIR1/$tfile`
2877
2878         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2879
2880         for (( i=0; i < 2; i++ )) ; do
2881                 local mtime2=`stat -c %Y $DIR1/$tfile`
2882                 [ $mtime2 = $TEST_39_MTIME ] || \
2883                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2884
2885                 cancel_lru_locks osc
2886                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2887         done
2888 }
2889 run_test 39e "create, stat, utime, stat ========================"
2890
2891 # bug 21114
2892 test_39f() {
2893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2894         touch $DIR1/$tfile
2895         mtime1=`stat -c %Y $DIR1/$tfile`
2896
2897         sleep 2
2898         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2899
2900         for (( i=0; i < 2; i++ )) ; do
2901                 local mtime2=`stat -c %Y $DIR1/$tfile`
2902                 [ $mtime2 = $TEST_39_MTIME ] || \
2903                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2904
2905                 cancel_lru_locks osc
2906                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2907         done
2908 }
2909 run_test 39f "create, stat, sleep, utime, stat ================="
2910
2911 # bug 11063
2912 test_39g() {
2913         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2914         echo hello >> $DIR1/$tfile
2915         local mtime1=`stat -c %Y $DIR1/$tfile`
2916
2917         sleep 2
2918         chmod o+r $DIR1/$tfile
2919
2920         for (( i=0; i < 2; i++ )) ; do
2921                 local mtime2=`stat -c %Y $DIR1/$tfile`
2922                 [ "$mtime1" = "$mtime2" ] || \
2923                         error "lost mtime: $mtime2, should be $mtime1"
2924
2925                 cancel_lru_locks osc
2926                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2927         done
2928 }
2929 run_test 39g "write, chmod, stat ==============================="
2930
2931 # bug 11063
2932 test_39h() {
2933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2934         touch $DIR1/$tfile
2935         sleep 1
2936
2937         local d1=`date`
2938         echo hello >> $DIR1/$tfile
2939         local mtime1=`stat -c %Y $DIR1/$tfile`
2940
2941         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2942         local d2=`date`
2943         if [ "$d1" != "$d2" ]; then
2944                 echo "write and touch not within one second"
2945         else
2946                 for (( i=0; i < 2; i++ )) ; do
2947                         local mtime2=`stat -c %Y $DIR1/$tfile`
2948                         [ "$mtime2" = $TEST_39_MTIME ] || \
2949                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2950
2951                         cancel_lru_locks osc
2952                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2953                 done
2954         fi
2955 }
2956 run_test 39h "write, utime within one second, stat ============="
2957
2958 test_39i() {
2959         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2960         touch $DIR1/$tfile
2961         sleep 1
2962
2963         echo hello >> $DIR1/$tfile
2964         local mtime1=`stat -c %Y $DIR1/$tfile`
2965
2966         mv $DIR1/$tfile $DIR1/$tfile-1
2967
2968         for (( i=0; i < 2; i++ )) ; do
2969                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2970
2971                 [ "$mtime1" = "$mtime2" ] || \
2972                         error "lost mtime: $mtime2, should be $mtime1"
2973
2974                 cancel_lru_locks osc
2975                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2976         done
2977 }
2978 run_test 39i "write, rename, stat =============================="
2979
2980 test_39j() {
2981         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2982         start_full_debug_logging
2983         touch $DIR1/$tfile
2984         sleep 1
2985
2986         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
2987         lctl set_param fail_loc=0x80000412
2988         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
2989                 error "multiop failed"
2990         local multipid=$!
2991         local mtime1=`stat -c %Y $DIR1/$tfile`
2992
2993         mv $DIR1/$tfile $DIR1/$tfile-1
2994
2995         kill -USR1 $multipid
2996         wait $multipid || error "multiop close failed"
2997
2998         for (( i=0; i < 2; i++ )) ; do
2999                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3000                 [ "$mtime1" = "$mtime2" ] ||
3001                         error "mtime is lost on close: $mtime2, " \
3002                               "should be $mtime1"
3003
3004                 cancel_lru_locks osc
3005                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3006         done
3007         lctl set_param fail_loc=0
3008         stop_full_debug_logging
3009 }
3010 run_test 39j "write, rename, close, stat ======================="
3011
3012 test_39k() {
3013         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3014         touch $DIR1/$tfile
3015         sleep 1
3016
3017         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3018         local multipid=$!
3019         local mtime1=`stat -c %Y $DIR1/$tfile`
3020
3021         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3022
3023         kill -USR1 $multipid
3024         wait $multipid || error "multiop close failed"
3025
3026         for (( i=0; i < 2; i++ )) ; do
3027                 local mtime2=`stat -c %Y $DIR1/$tfile`
3028
3029                 [ "$mtime2" = $TEST_39_MTIME ] || \
3030                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3031
3032                 cancel_lru_locks osc
3033                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3034         done
3035 }
3036 run_test 39k "write, utime, close, stat ========================"
3037
3038 # this should be set to future
3039 TEST_39_ATIME=`date -d "1 year" +%s`
3040
3041 test_39l() {
3042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3043         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3044         local atime_diff=$(do_facet $SINGLEMDS \
3045                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3046         rm -rf $DIR/$tdir
3047         mkdir -p $DIR/$tdir
3048
3049         # test setting directory atime to future
3050         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3051         local atime=$(stat -c %X $DIR/$tdir)
3052         [ "$atime" = $TEST_39_ATIME ] || \
3053                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3054
3055         # test setting directory atime from future to now
3056         local d1=$(date +%s)
3057         ls $DIR/$tdir
3058         local d2=$(date +%s)
3059
3060         cancel_lru_locks mdc
3061         atime=$(stat -c %X $DIR/$tdir)
3062         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3063                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3064
3065         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3066         sleep 3
3067
3068         # test setting directory atime when now > dir atime + atime_diff
3069         d1=$(date +%s)
3070         ls $DIR/$tdir
3071         d2=$(date +%s)
3072         cancel_lru_locks mdc
3073         atime=$(stat -c %X $DIR/$tdir)
3074         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3075                 error "atime is not updated  : $atime, should be $d2"
3076
3077         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3078         sleep 3
3079
3080         # test not setting directory atime when now < dir atime + atime_diff
3081         ls $DIR/$tdir
3082         cancel_lru_locks mdc
3083         atime=$(stat -c %X $DIR/$tdir)
3084         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3085                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3086
3087         do_facet $SINGLEMDS \
3088                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3089 }
3090 run_test 39l "directory atime update ==========================="
3091
3092 test_39m() {
3093         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3094         touch $DIR1/$tfile
3095         sleep 2
3096         local far_past_mtime=$(date -d "May 29 1953" +%s)
3097         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3098
3099         touch -m -d @$far_past_mtime $DIR1/$tfile
3100         touch -a -d @$far_past_atime $DIR1/$tfile
3101
3102         for (( i=0; i < 2; i++ )) ; do
3103                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3104                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3105                         error "atime or mtime set incorrectly"
3106
3107                 cancel_lru_locks osc
3108                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3109         done
3110 }
3111 run_test 39m "test atime and mtime before 1970"
3112
3113 test_39n() { # LU-3832
3114         local atime_diff=$(do_facet $SINGLEMDS \
3115                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3116         local atime0
3117         local atime1
3118         local atime2
3119
3120         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3121
3122         rm -rf $DIR/$tfile
3123         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3124         atime0=$(stat -c %X $DIR/$tfile)
3125
3126         sleep 5
3127         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3128         atime1=$(stat -c %X $DIR/$tfile)
3129
3130         sleep 5
3131         cancel_lru_locks mdc
3132         cancel_lru_locks osc
3133         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3134         atime2=$(stat -c %X $DIR/$tfile)
3135
3136         do_facet $SINGLEMDS \
3137                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3138
3139         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3140         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3141 }
3142 run_test 39n "check that O_NOATIME is honored"
3143
3144 test_39o() {
3145         TESTDIR=$DIR/$tdir/$tfile
3146         [ -e $TESTDIR ] && rm -rf $TESTDIR
3147         test_mkdir -p $TESTDIR
3148         cd $TESTDIR
3149         links1=2
3150         ls
3151         mkdir a b
3152         ls
3153         links2=$(stat -c %h .)
3154         [ $(($links1 + 2)) != $links2 ] &&
3155                 error "wrong links count $(($links1 + 2)) != $links2"
3156         rmdir b
3157         links3=$(stat -c %h .)
3158         [ $(($links1 + 1)) != $links3 ] &&
3159                 error "wrong links count $links1 != $links3"
3160         return 0
3161 }
3162 run_test 39o "directory cached attributes updated after create ========"
3163
3164 test_39p() {
3165         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3166         local MDTIDX=1
3167         TESTDIR=$DIR/$tdir/$tfile
3168         [ -e $TESTDIR ] && rm -rf $TESTDIR
3169         mkdir -p $TESTDIR
3170         cd $TESTDIR
3171         links1=2
3172         ls
3173         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3174         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3175         ls
3176         links2=$(stat -c %h .)
3177         [ $(($links1 + 2)) != $links2 ] &&
3178                 error "wrong links count $(($links1 + 2)) != $links2"
3179         rmdir remote_dir2
3180         links3=$(stat -c %h .)
3181         [ $(($links1 + 1)) != $links3 ] &&
3182                 error "wrong links count $links1 != $links3"
3183         return 0
3184 }
3185 run_test 39p "remote directory cached attributes updated after create ========"
3186
3187
3188 test_40() {
3189         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3190         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3191                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3192         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3193                 error "$tfile is not 4096 bytes in size"
3194 }
3195 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3196
3197 test_41() {
3198         # bug 1553
3199         small_write $DIR/f41 18
3200 }
3201 run_test 41 "test small file write + fstat ====================="
3202
3203 count_ost_writes() {
3204         lctl get_param -n osc.*.stats |
3205             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
3206 }
3207
3208 # decent default
3209 WRITEBACK_SAVE=500
3210 DIRTY_RATIO_SAVE=40
3211 MAX_DIRTY_RATIO=50
3212 BG_DIRTY_RATIO_SAVE=10
3213 MAX_BG_DIRTY_RATIO=25
3214
3215 start_writeback() {
3216         trap 0
3217         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3218         # dirty_ratio, dirty_background_ratio
3219         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3220                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3221                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3222                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3223         else
3224                 # if file not here, we are a 2.4 kernel
3225                 kill -CONT `pidof kupdated`
3226         fi
3227 }
3228
3229 stop_writeback() {
3230         # setup the trap first, so someone cannot exit the test at the
3231         # exact wrong time and mess up a machine
3232         trap start_writeback EXIT
3233         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3234         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3235                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3236                 sysctl -w vm.dirty_writeback_centisecs=0
3237                 sysctl -w vm.dirty_writeback_centisecs=0
3238                 # save and increase /proc/sys/vm/dirty_ratio
3239                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3240                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3241                 # save and increase /proc/sys/vm/dirty_background_ratio
3242                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3243                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3244         else
3245                 # if file not here, we are a 2.4 kernel
3246                 kill -STOP `pidof kupdated`
3247         fi
3248 }
3249
3250 # ensure that all stripes have some grant before we test client-side cache
3251 setup_test42() {
3252         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3253                 dd if=/dev/zero of=$i bs=4k count=1
3254                 rm $i
3255         done
3256 }
3257
3258 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3259 # file truncation, and file removal.
3260 test_42a() {
3261         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3262         setup_test42
3263         cancel_lru_locks osc
3264         stop_writeback
3265         sync; sleep 1; sync # just to be safe
3266         BEFOREWRITES=`count_ost_writes`
3267         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3268         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3269         AFTERWRITES=`count_ost_writes`
3270         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3271                 error "$BEFOREWRITES < $AFTERWRITES"
3272         start_writeback
3273 }
3274 run_test 42a "ensure that we don't flush on close =============="
3275
3276 test_42b() {
3277         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3278         setup_test42
3279         cancel_lru_locks osc
3280         stop_writeback
3281         sync
3282         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3283         BEFOREWRITES=`count_ost_writes`
3284         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3285         AFTERWRITES=`count_ost_writes`
3286         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3287                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3288         fi
3289         BEFOREWRITES=`count_ost_writes`
3290         sync || error "sync: $?"
3291         AFTERWRITES=`count_ost_writes`
3292         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3293                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3294         fi
3295         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3296         start_writeback
3297         return 0
3298 }
3299 run_test 42b "test destroy of file with cached dirty data ======"
3300
3301 # if these tests just want to test the effect of truncation,
3302 # they have to be very careful.  consider:
3303 # - the first open gets a {0,EOF}PR lock
3304 # - the first write conflicts and gets a {0, count-1}PW
3305 # - the rest of the writes are under {count,EOF}PW
3306 # - the open for truncate tries to match a {0,EOF}PR
3307 #   for the filesize and cancels the PWs.
3308 # any number of fixes (don't get {0,EOF} on open, match
3309 # composite locks, do smarter file size management) fix
3310 # this, but for now we want these tests to verify that
3311 # the cancellation with truncate intent works, so we
3312 # start the file with a full-file pw lock to match against
3313 # until the truncate.
3314 trunc_test() {
3315         test=$1
3316         file=$DIR/$test
3317         offset=$2
3318         cancel_lru_locks osc
3319         stop_writeback
3320         # prime the file with 0,EOF PW to match
3321         touch $file
3322         $TRUNCATE $file 0
3323         sync; sync
3324         # now the real test..
3325         dd if=/dev/zero of=$file bs=1024 count=100
3326         BEFOREWRITES=`count_ost_writes`
3327         $TRUNCATE $file $offset
3328         cancel_lru_locks osc
3329         AFTERWRITES=`count_ost_writes`
3330         start_writeback
3331 }
3332
3333 test_42c() {
3334         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3335         trunc_test 42c 1024
3336         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3337             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3338         rm $file
3339 }
3340 run_test 42c "test partial truncate of file with cached dirty data"
3341
3342 test_42d() {
3343         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3344         trunc_test 42d 0
3345         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3346             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3347         rm $file
3348 }
3349 run_test 42d "test complete truncate of file with cached dirty data"
3350
3351 test_42e() { # bug22074
3352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3353         local TDIR=$DIR/${tdir}e
3354         local pagesz=$(page_size)
3355         local pages=16 # hardcoded 16 pages, don't change it.
3356         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3357         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3358         local max_dirty_mb
3359         local warmup_files
3360
3361         test_mkdir -p $DIR/${tdir}e
3362         $SETSTRIPE -c 1 $TDIR
3363         createmany -o $TDIR/f $files
3364
3365         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3366
3367         # we assume that with $OSTCOUNT files, at least one of them will
3368         # be allocated on OST0.
3369         warmup_files=$((OSTCOUNT * max_dirty_mb))
3370         createmany -o $TDIR/w $warmup_files
3371
3372         # write a large amount of data into one file and sync, to get good
3373         # avail_grant number from OST.
3374         for ((i=0; i<$warmup_files; i++)); do
3375                 idx=$($GETSTRIPE -i $TDIR/w$i)
3376                 [ $idx -ne 0 ] && continue
3377                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3378                 break
3379         done
3380         [ $i -gt $warmup_files ] && error "OST0 is still cold"
3381         sync
3382         $LCTL get_param $proc_osc0/cur_dirty_bytes
3383         $LCTL get_param $proc_osc0/cur_grant_bytes
3384
3385         # create as much dirty pages as we can while not to trigger the actual
3386         # RPCs directly. but depends on the env, VFS may trigger flush during this
3387         # period, hopefully we are good.
3388         for ((i=0; i<$warmup_files; i++)); do
3389                 idx=$($GETSTRIPE -i $TDIR/w$i)
3390                 [ $idx -ne 0 ] && continue
3391                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3392         done
3393         $LCTL get_param $proc_osc0/cur_dirty_bytes
3394         $LCTL get_param $proc_osc0/cur_grant_bytes
3395
3396         # perform the real test
3397         $LCTL set_param $proc_osc0/rpc_stats 0
3398         for ((;i<$files; i++)); do
3399                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3400                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3401         done
3402         sync
3403         $LCTL get_param $proc_osc0/rpc_stats
3404
3405         local percent=0
3406         local have_ppr=false
3407         $LCTL get_param $proc_osc0/rpc_stats |
3408                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3409                         # skip lines until we are at the RPC histogram data
3410                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3411                         $have_ppr || continue
3412
3413                         # we only want the percent stat for < 16 pages
3414                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
3415
3416                         percent=$((percent + WPCT))
3417                         if [ $percent -gt 15 ]; then
3418                                 error "less than 16-pages write RPCs" \
3419                                       "$percent% > 15%"
3420                                 break
3421                         fi
3422                 done
3423         rm -rf $TDIR
3424 }
3425 run_test 42e "verify sub-RPC writes are not done synchronously"
3426
3427 test_43() {
3428         test_mkdir -p $DIR/$tdir
3429         cp -p /bin/ls $DIR/$tdir/$tfile
3430         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3431         pid=$!
3432         # give multiop a chance to open
3433         sleep 1
3434
3435         $DIR/$tdir/$tfile && error || true
3436         kill -USR1 $pid
3437 }
3438 run_test 43 "execution of file opened for write should return -ETXTBSY"
3439
3440 test_43a() {
3441         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3442         test_mkdir -p $DIR/$tdir
3443         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3444                         cp -p multiop $DIR/$tdir/multiop
3445         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3446                         return 1
3447         MULTIOP_PID=$!
3448         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3449         kill -USR1 $MULTIOP_PID || return 2
3450         wait $MULTIOP_PID || return 3
3451         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3452 }
3453 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3454
3455 test_43b() {
3456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3457         test_mkdir -p $DIR/$tdir
3458         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3459                         cp -p multiop $DIR/$tdir/multiop
3460         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3461                         return 1
3462         MULTIOP_PID=$!
3463         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3464         kill -USR1 $MULTIOP_PID || return 2
3465         wait $MULTIOP_PID || return 3
3466         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3467 }
3468 run_test 43b "truncate of file being executed should return -ETXTBSY"
3469
3470 test_43c() {
3471         local testdir="$DIR/$tdir"
3472         test_mkdir -p $DIR/$tdir
3473         cp $SHELL $testdir/
3474         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3475                 ( cd $testdir && md5sum -c)
3476 }
3477 run_test 43c "md5sum of copy into lustre========================"
3478
3479 test_44() {
3480         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
3481         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3482         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3483 }
3484 run_test 44 "zero length read from a sparse stripe ============="
3485
3486 test_44a() {
3487     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
3488                          awk '{print $2}'`
3489     [ -z "$nstripe" ] && skip "can't get stripe info" && return
3490     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
3491     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
3492                       awk '{print $2}'`
3493     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
3494         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
3495     fi
3496
3497     OFFSETS="0 $((stride/2)) $((stride-1))"
3498     for offset in $OFFSETS ; do
3499       for i in `seq 0 $((nstripe-1))`; do
3500         local GLOBALOFFSETS=""
3501         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
3502         local myfn=$DIR/d44a-$size
3503         echo "--------writing $myfn at $size"
3504         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
3505         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3506         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3507                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3508
3509         for j in `seq 0 $((nstripe-1))`; do
3510             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
3511             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
3512             GLOBALOFFSETS="$GLOBALOFFSETS $size"
3513         done
3514         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3515                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3516         rm -f $myfn
3517       done
3518     done
3519 }
3520 run_test 44a "test sparse pwrite ==============================="
3521
3522 dirty_osc_total() {
3523         tot=0
3524         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3525                 tot=$(($tot + $d))
3526         done
3527         echo $tot
3528 }
3529 do_dirty_record() {
3530         before=`dirty_osc_total`
3531         echo executing "\"$*\""
3532         eval $*
3533         after=`dirty_osc_total`
3534         echo before $before, after $after
3535 }
3536 test_45() {
3537         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3538         f="$DIR/f45"
3539         # Obtain grants from OST if it supports it
3540         echo blah > ${f}_grant
3541         stop_writeback
3542         sync
3543         do_dirty_record "echo blah > $f"
3544         [ $before -eq $after ] && error "write wasn't cached"
3545         do_dirty_record "> $f"
3546         [ $before -gt $after ] || error "truncate didn't lower dirty count"
3547         do_dirty_record "echo blah > $f"
3548         [ $before -eq $after ] && error "write wasn't cached"
3549         do_dirty_record "sync"
3550         [ $before -gt $after ] || error "writeback didn't lower dirty count"
3551         do_dirty_record "echo blah > $f"
3552         [ $before -eq $after ] && error "write wasn't cached"
3553         do_dirty_record "cancel_lru_locks osc"
3554         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
3555         start_writeback
3556 }
3557 run_test 45 "osc io page accounting ============================"
3558
3559 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3560 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3561 # objects offset and an assert hit when an rpc was built with 1023's mapped
3562 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3563 test_46() {
3564         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3565         f="$DIR/f46"
3566         stop_writeback
3567         sync
3568         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3569         sync
3570         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3571         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3572         sync
3573         start_writeback
3574 }
3575 run_test 46 "dirtying a previously written page ================"
3576
3577 # test_47 is removed "Device nodes check" is moved to test_28
3578
3579 test_48a() { # bug 2399
3580         check_kernel_version 34 || return 0
3581         test_mkdir -p $DIR/$tdir
3582         cd $DIR/$tdir
3583         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3584         test_mkdir $DIR/$tdir || error "recreate directory failed"
3585         touch foo || error "'touch foo' failed after recreating cwd"
3586         test_mkdir $DIR/$tdir/bar ||
3587                      error "'mkdir foo' failed after recreating cwd"
3588         if check_kernel_version 44; then
3589                 touch .foo || error "'touch .foo' failed after recreating cwd"
3590                 test_mkdir $DIR/$tdir/.bar ||
3591                               error "'mkdir .foo' failed after recreating cwd"
3592         fi
3593         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3594         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3595         cd . || error "'cd .' failed after recreating cwd"
3596         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3597         rmdir . && error "'rmdir .' worked after recreating cwd"
3598         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3599         cd .. || error "'cd ..' failed after recreating cwd"
3600 }
3601 run_test 48a "Access renamed working dir (should return errors)="
3602
3603 test_48b() { # bug 2399
3604         check_kernel_version 34 || return 0
3605         rm -rf $DIR/$tdir
3606         test_mkdir -p $DIR/$tdir
3607         cd $DIR/$tdir
3608         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3609         touch foo && error "'touch foo' worked after removing cwd"
3610         test_mkdir $DIR/$tdir/foo &&
3611                      error "'mkdir foo' worked after removing cwd"
3612         if check_kernel_version 44; then
3613                 touch .foo && error "'touch .foo' worked after removing cwd"
3614                 test_mkdir $DIR/$tdir/.foo &&
3615                               error "'mkdir .foo' worked after removing cwd"
3616         fi
3617         ls . > /dev/null && error "'ls .' worked after removing cwd"
3618         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3619         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3620         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3621         rmdir . && error "'rmdir .' worked after removing cwd"
3622         ln -s . foo && error "'ln -s .' worked after removing cwd"
3623         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3624 }
3625 run_test 48b "Access removed working dir (should return errors)="
3626
3627 test_48c() { # bug 2350
3628         check_kernel_version 36 || return 0
3629         #lctl set_param debug=-1
3630         #set -vx
3631         rm -rf $DIR/$tdir
3632         test_mkdir -p $DIR/$tdir/dir
3633         cd $DIR/$tdir/dir
3634         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3635         $TRACE touch foo && error "touch foo worked after removing cwd"
3636         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3637         if check_kernel_version 44; then
3638                 touch .foo && error "touch .foo worked after removing cwd"
3639                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3640         fi
3641         $TRACE ls . && error "'ls .' worked after removing cwd"
3642         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3643         is_patchless || ( $TRACE cd . &&
3644                         error "'cd .' worked after removing cwd" )
3645         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3646         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3647         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3648         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3649 }
3650 run_test 48c "Access removed working subdir (should return errors)"
3651
3652 test_48d() { # bug 2350
3653         check_kernel_version 36 || return 0
3654         #lctl set_param debug=-1
3655         #set -vx
3656         rm -rf $DIR/$tdir
3657         test_mkdir -p $DIR/$tdir/dir
3658         cd $DIR/$tdir/dir
3659         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3660         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3661         $TRACE touch foo && error "'touch foo' worked after removing parent"
3662         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3663         if check_kernel_version 44; then
3664                 touch .foo && error "'touch .foo' worked after removing parent"
3665                 test_mkdir .foo &&
3666                               error "mkdir .foo worked after removing parent"
3667         fi
3668         $TRACE ls . && error "'ls .' worked after removing parent"
3669         $TRACE ls .. && error "'ls ..' worked after removing parent"
3670         is_patchless || ( $TRACE cd . &&
3671                         error "'cd .' worked after recreate parent" )
3672         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3673         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3674         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3675         is_patchless || ( $TRACE cd .. &&
3676                         error "'cd ..' worked after removing parent" || true )
3677 }
3678 run_test 48d "Access removed parent subdir (should return errors)"
3679
3680 test_48e() { # bug 4134
3681         check_kernel_version 41 || return 0
3682         #lctl set_param debug=-1
3683         #set -vx
3684         rm -rf $DIR/$tdir
3685         test_mkdir -p $DIR/$tdir/dir
3686         cd $DIR/$tdir/dir
3687         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3688         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3689         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3690         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3691         # On a buggy kernel addition of "touch foo" after cd .. will
3692         # produce kernel oops in lookup_hash_it
3693         touch ../foo && error "'cd ..' worked after recreate parent"
3694         cd $DIR
3695         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3696 }
3697 run_test 48e "Access to recreated parent subdir (should return errors)"
3698
3699 test_49() { # LU-1030
3700         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3701         # get ost1 size - lustre-OST0000
3702         ost1_size=$(do_facet ost1 lfs df |grep ${ost1_svc} |awk '{print $4}')
3703         # write 800M at maximum
3704         [ $ost1_size -gt 819200 ] && ost1_size=819200
3705
3706         lfs setstripe -c 1 -i 0 $DIR/$tfile
3707         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3708         local dd_pid=$!
3709
3710         # change max_pages_per_rpc while writing the file
3711         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3712         local orig_mppc=`$LCTL get_param -n $osc1_mppc`
3713         # loop until dd process exits
3714         while ps ax -opid | grep -wq $dd_pid; do
3715                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3716                 sleep $((RANDOM % 5 + 1))
3717         done
3718         # restore original max_pages_per_rpc
3719         $LCTL set_param $osc1_mppc=$orig_mppc
3720         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3721 }
3722 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3723
3724 test_50() {
3725         # bug 1485
3726         test_mkdir $DIR/$tdir
3727         cd $DIR/$tdir
3728         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3729 }
3730 run_test 50 "special situations: /proc symlinks  ==============="
3731
3732 test_51a() {    # was test_51
3733         # bug 1516 - create an empty entry right after ".." then split dir
3734         test_mkdir -p $DIR/$tdir
3735         touch $DIR/$tdir/foo
3736         $MCREATE $DIR/$tdir/bar
3737         rm $DIR/$tdir/foo
3738         createmany -m $DIR/$tdir/longfile 201
3739         FNUM=202
3740         while [ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]; do
3741                 $MCREATE $DIR/$tdir/longfile$FNUM
3742                 FNUM=$(($FNUM + 1))
3743                 echo -n "+"
3744         done
3745         echo
3746         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3747 }
3748 run_test 51a "special situations: split htree with empty entry =="
3749
3750 export NUMTEST=70000
3751 test_51b() {
3752         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3753         local BASE=$DIR/d${base}.${TESTSUITE}
3754
3755         # cleanup the directory
3756         rm -fr $BASE
3757
3758         test_mkdir -p $BASE
3759
3760         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3761         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3762         [ $numfree -lt 21000 ] && skip "not enough free inodes ($numfree)" &&
3763                 return
3764
3765         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3766                 echo "reduced count to $NUMTEST due to inodes"
3767
3768         # need to check free space for the directories as well
3769         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3770         numfree=$((blkfree / 4))
3771         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3772                 echo "reduced count to $NUMTEST due to blocks"
3773
3774         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3775                 echo "failed" > $BASE/fnum
3776 }
3777 run_test 51b "exceed 64k subdirectory nlink limit"
3778
3779 test_51ba() { # LU-993
3780         local BASE=$DIR/d${base}.${TESTSUITE}
3781         # unlink all but 100 subdirectories, then check it still works
3782         local LEFT=100
3783         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3784
3785         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3786         local DELETE=$((NUMTEST - LEFT))
3787
3788         # continue on to run this test even if 51b didn't finish,
3789         # just to delete the many subdirectories created.
3790         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3791
3792         # for ldiskfs the nlink count should be 1, but this is OSD specific
3793         # and so this is listed for informational purposes only
3794         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3795         unlinkmany -d $BASE/d $DELETE
3796         RC=$?
3797
3798         if [ $RC -ne 0 ]; then
3799                 if [ "$NUMPREV" == "failed" ]; then
3800                         skip "previous setup failed"
3801                         return 0
3802                 else
3803                         error "unlink of first $DELETE subdirs failed"
3804                         return $RC
3805                 fi
3806         fi
3807
3808         echo "nlink between: $(stat -c %h $BASE)"
3809         # trim the first line of ls output
3810         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3811         [ $FOUND -ne $LEFT ] &&
3812                 error "can't find subdirs: found only $FOUND/$LEFT"
3813
3814         unlinkmany -d $BASE/d $DELETE $LEFT ||
3815                 error "unlink of second $LEFT subdirs failed"
3816         # regardless of whether the backing filesystem tracks nlink accurately
3817         # or not, the nlink count shouldn't be more than "." and ".." here
3818         local AFTER=$(stat -c %h $BASE)
3819         [ $AFTER -gt 2 ] && error "nlink after: $AFTER > 2" ||
3820                 echo "nlink after: $AFTER"
3821 }
3822 run_test 51ba "verify nlink for many subdirectory cleanup"
3823
3824 test_51d() {
3825         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3826         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3827         test_mkdir -p $DIR/$tdir
3828         createmany -o $DIR/$tdir/t- 1000
3829         $GETSTRIPE $DIR/$tdir > $TMP/files
3830         for N in `seq 0 $((OSTCOUNT - 1))`; do
3831             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3832             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3833             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3834         done
3835         unlinkmany $DIR/$tdir/t- 1000
3836
3837         NLAST=0
3838         for N in `seq 1 $((OSTCOUNT - 1))`; do
3839             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3840                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3841             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3842                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3843
3844             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3845                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3846             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3847                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3848             NLAST=$N
3849         done
3850 }
3851 run_test 51d "check object distribution ===================="
3852
3853 test_52a() {
3854         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
3855         test_mkdir -p $DIR/$tdir
3856         touch $DIR/$tdir/foo
3857         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
3858         echo bar >> $DIR/$tdir/foo || error "append bar failed"
3859         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3860         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3861         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3862                                         error "link worked"
3863         echo foo >> $DIR/$tdir/foo || error "append foo failed"
3864         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3865         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
3866                                                      error "lsattr"
3867         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
3868         cp -r $DIR/$tdir /tmp/
3869         rm -fr $DIR/$tdir || error "cleanup rm failed"
3870 }
3871 run_test 52a "append-only flag test (should return errors) ====="
3872
3873 test_52b() {
3874         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
3875         test_mkdir -p $DIR/$tdir
3876         touch $DIR/$tdir/foo
3877         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
3878         cat test > $DIR/$tdir/foo && error "cat test worked"
3879         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3880         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3881         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3882                                         error "link worked"
3883         echo foo >> $DIR/$tdir/foo && error "echo worked"
3884         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3885         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
3886         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
3887         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
3888                                                         error "lsattr"
3889         chattr -i $DIR/$tdir/foo || error "chattr failed"
3890
3891         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
3892 }
3893 run_test 52b "immutable flag test (should return errors) ======="
3894
3895 test_53() {
3896         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3897         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3898         remote_ost_nodsh && skip "remote OST with nodsh" && return
3899
3900         local param
3901         local param_seq
3902         local ostname
3903         local mds_last
3904         local mds_last_seq
3905         local ost_last
3906         local ost_last_seq
3907         local ost_last_id
3908         local ostnum
3909         local node
3910         local found=false
3911         local support_last_seq=true
3912
3913         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
3914                 support_last_seq=false
3915
3916         # only test MDT0000
3917         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3918         local value
3919         for value in $(do_facet $SINGLEMDS \
3920                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
3921                 param=$(echo ${value[0]} | cut -d "=" -f1)
3922                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
3923
3924                 if $support_last_seq; then
3925                         param_seq=$(echo $param |
3926                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
3927                         mds_last_seq=$(do_facet $SINGLEMDS \
3928                                        $LCTL get_param -n $param_seq)
3929                 fi
3930                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
3931
3932                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
3933                 node=$(facet_active_host ost$((ostnum+1)))
3934                 param="obdfilter.$ostname.last_id"
3935                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
3936                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
3937                         ost_last_id=$ost_last
3938
3939                         if $support_last_seq; then
3940                                 ost_last_id=$(echo $ost_last |
3941                                               awk -F':' '{print $2}' |
3942                                               sed -e "s/^0x//g")
3943                                 ost_last_seq=$(echo $ost_last |
3944                                                awk -F':' '{print $1}')
3945                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
3946                         fi
3947
3948                         if [[ $ost_last_id != $mds_last ]]; then
3949                                 error "$ost_last_id != $mds_last"
3950                         else
3951                                 found=true
3952                                 break
3953                         fi
3954                 done
3955         done
3956         $found || error "can not match last_seq/last_id for $mdtosc"
3957         return 0
3958 }
3959 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
3960
3961 test_54a() {
3962         $SOCKETSERVER $DIR/socket ||
3963                 error "$SOCKETSERVER $DIR/socket failed: $?"
3964         $SOCKETCLIENT $DIR/socket ||
3965                 error "$SOCKETCLIENT $DIR/socket failed: $?"
3966         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
3967 }
3968 run_test 54a "unix domain socket test =========================="
3969
3970 test_54b() {
3971         f="$DIR/f54b"
3972         mknod $f c 1 3
3973         chmod 0666 $f
3974         dd if=/dev/zero of=$f bs=$(page_size) count=1
3975 }
3976 run_test 54b "char device works in lustre ======================"
3977
3978 find_loop_dev() {
3979         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
3980         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
3981         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
3982
3983         for i in $(seq 3 7); do
3984                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
3985                 LOOPDEV=$LOOPBASE$i
3986                 LOOPNUM=$i
3987                 break
3988         done
3989 }
3990
3991 test_54c() {
3992         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3993         tfile="$DIR/f54c"
3994         tdir="$DIR/d54c"
3995         loopdev="$DIR/loop54c"
3996
3997         find_loop_dev
3998         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
3999         mknod $loopdev b 7 $LOOPNUM
4000         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
4001         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
4002         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
4003         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4004         test_mkdir -p $tdir
4005         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
4006         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
4007         df $tdir
4008         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
4009         $UMOUNT -d $tdir
4010         losetup -d $loopdev
4011         rm $loopdev
4012 }
4013 run_test 54c "block device works in lustre ====================="
4014
4015 test_54d() {
4016         f="$DIR/f54d"
4017         string="aaaaaa"
4018         mknod $f p
4019         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4020 }
4021 run_test 54d "fifo device works in lustre ======================"
4022
4023 test_54e() {
4024         check_kernel_version 46 || return 0
4025         f="$DIR/f54e"
4026         string="aaaaaa"
4027         cp -aL /dev/console $f
4028         echo $string > $f || error "echo $string to $f failed"
4029 }
4030 run_test 54e "console/tty device works in lustre ======================"
4031
4032 #The test_55 used to be iopen test and it was removed by bz#24037.
4033 #run_test 55 "check iopen_connect_dentry() ======================"
4034
4035 test_56a() {    # was test_56
4036         rm -rf $DIR/$tdir
4037         $SETSTRIPE -d $DIR
4038         test_mkdir -p $DIR/$tdir/dir
4039         NUMFILES=3
4040         NUMFILESx2=$(($NUMFILES * 2))
4041         for i in `seq 1 $NUMFILES` ; do
4042                 touch $DIR/$tdir/file$i
4043                 touch $DIR/$tdir/dir/file$i
4044         done
4045
4046         # test lfs getstripe with --recursive
4047         FILENUM=`$GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx`
4048         [ $FILENUM -eq $NUMFILESx2 ] ||
4049                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4050         FILENUM=`$GETSTRIPE $DIR/$tdir | grep -c obdidx`
4051         [ $FILENUM -eq $NUMFILES ] ||
4052                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4053         echo "$GETSTRIPE --recursive passed."
4054
4055         # test lfs getstripe with file instead of dir
4056         FILENUM=`$GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx`
4057         [ $FILENUM  -eq 1 ] || error \
4058                  "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4059         echo "$GETSTRIPE file1 passed."
4060
4061         #test lfs getstripe with --verbose
4062         [ `$GETSTRIPE --verbose $DIR/$tdir |
4063                         grep -c lmm_magic` -eq $NUMFILES ] ||
4064                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4065         [ `$GETSTRIPE $DIR/$tdir | grep -c lmm_magic` -eq 0 ] ||
4066             error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4067         echo "$GETSTRIPE --verbose passed."
4068
4069         #test lfs getstripe with --obd
4070         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4071                                         grep -q "unknown obduuid" ||
4072                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4073
4074         [  "$OSTCOUNT" -lt 2 ] &&
4075                 skip_env "skipping other $GETSTRIPE --obd test" && return
4076
4077         OSTIDX=1
4078         OBDUUID=$(ostuuid_from_index $OSTIDX)
4079         FILENUM=`$GETSTRIPE -ir $DIR/$tdir | grep -x $OSTIDX | wc -l`
4080         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l`
4081         [ $FOUND -eq $FILENUM ] ||
4082                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4083         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4084                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4085                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
4086                 error "$GETSTRIPE --obd: should not show file on other obd"
4087         echo "$GETSTRIPE --obd passed"
4088 }
4089 run_test 56a "check $GETSTRIPE"
4090
4091 NUMFILES=3
4092 NUMDIRS=3
4093 setup_56() {
4094         local LOCAL_NUMFILES="$1"
4095         local LOCAL_NUMDIRS="$2"
4096         local MKDIR_PARAMS="$3"
4097
4098         if [ ! -d "$TDIR" ] ; then
4099                 test_mkdir -p $TDIR
4100                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4101                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4102                         touch $TDIR/file$i
4103                 done
4104                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4105                         test_mkdir $TDIR/dir$i
4106                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4107                                 touch $TDIR/dir$i/file$j
4108                         done
4109                 done
4110         fi
4111 }
4112
4113 setup_56_special() {
4114         LOCAL_NUMFILES=$1
4115         LOCAL_NUMDIRS=$2
4116         setup_56 $1 $2
4117         if [ ! -e "$TDIR/loop1b" ] ; then
4118                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4119                         mknod $TDIR/loop${i}b b 7 $i
4120                         mknod $TDIR/null${i}c c 1 3
4121                         ln -s $TDIR/file1 $TDIR/link${i}l
4122                 done
4123                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4124                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4125                         mknod $TDIR/dir$i/null${i}c c 1 3
4126                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4127                 done
4128         fi
4129 }
4130
4131 test_56g() {
4132         $SETSTRIPE -d $DIR
4133
4134         TDIR=$DIR/${tdir}g
4135         setup_56 $NUMFILES $NUMDIRS
4136
4137         EXPECTED=$(($NUMDIRS + 2))
4138         # test lfs find with -name
4139         for i in $(seq 1 $NUMFILES) ; do
4140                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4141                 [ $NUMS -eq $EXPECTED ] ||
4142                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4143                               "found $NUMS, expected $EXPECTED"
4144         done
4145 }
4146 run_test 56g "check lfs find -name ============================="
4147
4148 test_56h() {
4149         $SETSTRIPE -d $DIR
4150
4151         TDIR=$DIR/${tdir}g
4152         setup_56 $NUMFILES $NUMDIRS
4153
4154         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4155         # test lfs find with ! -name
4156         for i in $(seq 1 $NUMFILES) ; do
4157                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4158                 [ $NUMS -eq $EXPECTED ] ||
4159                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4160                               "found $NUMS, expected $EXPECTED"
4161         done
4162 }
4163 run_test 56h "check lfs find ! -name ============================="
4164
4165 test_56i() {
4166        tdir=${tdir}i
4167        test_mkdir -p $DIR/$tdir
4168        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4169        CMD="$LFIND -ost $UUID $DIR/$tdir"
4170        OUT=$($CMD)
4171        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4172 }
4173 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4174
4175 test_56j() {
4176         TDIR=$DIR/${tdir}g
4177         setup_56_special $NUMFILES $NUMDIRS
4178
4179         EXPECTED=$((NUMDIRS + 1))
4180         CMD="$LFIND -type d $TDIR"
4181         NUMS=$($CMD | wc -l)
4182         [ $NUMS -eq $EXPECTED ] ||
4183                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4184 }
4185 run_test 56j "check lfs find -type d ============================="
4186
4187 test_56k() {
4188         TDIR=$DIR/${tdir}g
4189         setup_56_special $NUMFILES $NUMDIRS
4190
4191         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4192         CMD="$LFIND -type f $TDIR"
4193         NUMS=$($CMD | wc -l)
4194         [ $NUMS -eq $EXPECTED ] ||
4195                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4196 }
4197 run_test 56k "check lfs find -type f ============================="
4198
4199 test_56l() {
4200         TDIR=$DIR/${tdir}g
4201         setup_56_special $NUMFILES $NUMDIRS
4202
4203         EXPECTED=$((NUMDIRS + NUMFILES))
4204         CMD="$LFIND -type b $TDIR"
4205         NUMS=$($CMD | wc -l)
4206         [ $NUMS -eq $EXPECTED ] ||
4207                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4208 }
4209 run_test 56l "check lfs find -type b ============================="
4210
4211 test_56m() {
4212         TDIR=$DIR/${tdir}g
4213         setup_56_special $NUMFILES $NUMDIRS
4214
4215         EXPECTED=$((NUMDIRS + NUMFILES))
4216         CMD="$LFIND -type c $TDIR"
4217         NUMS=$($CMD | wc -l)
4218         [ $NUMS -eq $EXPECTED ] ||
4219                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4220 }
4221 run_test 56m "check lfs find -type c ============================="
4222
4223 test_56n() {
4224         TDIR=$DIR/${tdir}g
4225         setup_56_special $NUMFILES $NUMDIRS
4226
4227         EXPECTED=$((NUMDIRS + NUMFILES))
4228         CMD="$LFIND -type l $TDIR"
4229         NUMS=$($CMD | wc -l)
4230         [ $NUMS -eq $EXPECTED ] ||
4231                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4232 }
4233 run_test 56n "check lfs find -type l ============================="
4234
4235 test_56o() {
4236         TDIR=$DIR/${tdir}o
4237         setup_56 $NUMFILES $NUMDIRS
4238
4239         utime $TDIR/file1 > /dev/null || error "utime (1)"
4240         utime $TDIR/file2 > /dev/null || error "utime (2)"
4241         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4242         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4243         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4244         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4245
4246         EXPECTED=4
4247         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4248         [ $NUMS -eq $EXPECTED ] || \
4249                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4250
4251         EXPECTED=12
4252         CMD="$LFIND -mtime 0 $TDIR"
4253         NUMS=$($CMD | wc -l)
4254         [ $NUMS -eq $EXPECTED ] ||
4255                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4256 }
4257 run_test 56o "check lfs find -mtime for old files =========================="
4258
4259 test_56p() {
4260         [ $RUNAS_ID -eq $UID ] &&
4261                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4262
4263         TDIR=$DIR/${tdir}p
4264         setup_56 $NUMFILES $NUMDIRS
4265
4266         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4267         EXPECTED=$NUMFILES
4268         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4269         NUMS=$($CMD | wc -l)
4270         [ $NUMS -eq $EXPECTED ] || \
4271                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4272
4273         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4274         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4275         NUMS=$($CMD | wc -l)
4276         [ $NUMS -eq $EXPECTED ] || \
4277                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4278 }
4279 run_test 56p "check lfs find -uid and ! -uid ==============================="
4280
4281 test_56q() {
4282         [ $RUNAS_ID -eq $UID ] &&
4283                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4284
4285         TDIR=$DIR/${tdir}q
4286         setup_56 $NUMFILES $NUMDIRS
4287
4288         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4289
4290         EXPECTED=$NUMFILES
4291         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4292         NUMS=$($CMD | wc -l)
4293         [ $NUMS -eq $EXPECTED ] ||
4294                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4295
4296         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4297         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4298         NUMS=$($CMD | wc -l)
4299         [ $NUMS -eq $EXPECTED ] ||
4300                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4301 }
4302 run_test 56q "check lfs find -gid and ! -gid ==============================="
4303
4304 test_56r() {
4305         TDIR=$DIR/${tdir}r
4306         setup_56 $NUMFILES $NUMDIRS
4307
4308         EXPECTED=12
4309         CMD="$LFIND -size 0 -type f $TDIR"
4310         NUMS=$($CMD | wc -l)
4311         [ $NUMS -eq $EXPECTED ] ||
4312                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4313         EXPECTED=0
4314         CMD="$LFIND ! -size 0 -type f $TDIR"
4315         NUMS=$($CMD | wc -l)
4316         [ $NUMS -eq $EXPECTED ] ||
4317                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4318         echo "test" > $TDIR/$tfile
4319         echo "test2" > $TDIR/$tfile.2 && sync
4320         EXPECTED=1
4321         CMD="$LFIND -size 5 -type f $TDIR"
4322         NUMS=$($CMD | wc -l)
4323         [ $NUMS -eq $EXPECTED ] ||
4324                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4325         EXPECTED=1
4326         CMD="$LFIND -size +5 -type f $TDIR"
4327         NUMS=$($CMD | wc -l)
4328         [ $NUMS -eq $EXPECTED ] ||
4329                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4330         EXPECTED=2
4331         CMD="$LFIND -size +0 -type f $TDIR"
4332         NUMS=$($CMD | wc -l)
4333         [ $NUMS -eq $EXPECTED ] ||
4334                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4335         EXPECTED=2
4336         CMD="$LFIND ! -size -5 -type f $TDIR"
4337         NUMS=$($CMD | wc -l)
4338         [ $NUMS -eq $EXPECTED ] ||
4339                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4340         EXPECTED=12
4341         CMD="$LFIND -size -5 -type f $TDIR"
4342         NUMS=$($CMD | wc -l)
4343         [ $NUMS -eq $EXPECTED ] ||
4344                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4345 }
4346 run_test 56r "check lfs find -size works =========================="
4347
4348 test_56s() { # LU-611
4349         TDIR=$DIR/${tdir}s
4350         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4351
4352         if [ $OSTCOUNT -gt 1 ]; then
4353                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4354                 ONESTRIPE=4
4355                 EXTRA=4
4356         else
4357                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4358                 EXTRA=0
4359         fi
4360
4361         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4362         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4363         NUMS=$($CMD | wc -l)
4364         [ $NUMS -eq $EXPECTED ] ||
4365                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4366
4367         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4368         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4369         NUMS=$($CMD | wc -l)
4370         [ $NUMS -eq $EXPECTED ] ||
4371                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4372
4373         EXPECTED=$ONESTRIPE
4374         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4375         NUMS=$($CMD | wc -l)
4376         [ $NUMS -eq $EXPECTED ] ||
4377                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4378
4379         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4380         NUMS=$($CMD | wc -l)
4381         [ $NUMS -eq $EXPECTED ] ||
4382                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4383
4384         EXPECTED=0
4385         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4386         NUMS=$($CMD | wc -l)
4387         [ $NUMS -eq $EXPECTED ] ||
4388                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4389 }
4390 run_test 56s "check lfs find -stripe-count works"
4391
4392 test_56t() { # LU-611
4393         TDIR=$DIR/${tdir}t
4394         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4395
4396         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4397
4398         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4399         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4400         NUMS=$($CMD | wc -l)
4401         [ $NUMS -eq $EXPECTED ] ||
4402                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4403
4404         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4405         NUMS=$($CMD | wc -l)
4406         [ $NUMS -eq $EXPECTED ] ||
4407                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4408
4409         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4410         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4411         NUMS=$($CMD | wc -l)
4412         [ $NUMS -eq $EXPECTED ] ||
4413                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4414
4415         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4416         NUMS=$($CMD | wc -l)
4417         [ $NUMS -eq $EXPECTED ] ||
4418                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4419
4420         EXPECTED=4
4421         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4422         NUMS=$($CMD | wc -l)
4423         [ $NUMS -eq $EXPECTED ] ||
4424                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4425
4426         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4427         NUMS=$($CMD | wc -l)
4428         [ $NUMS -eq $EXPECTED ] ||
4429                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4430
4431         EXPECTED=0
4432         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4433         NUMS=$($CMD | wc -l)
4434         [ $NUMS -eq $EXPECTED ] ||
4435                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4436 }
4437 run_test 56t "check lfs find -stripe-size works"
4438
4439 test_56u() { # LU-611
4440         TDIR=$DIR/${tdir}u
4441         setup_56 $NUMFILES $NUMDIRS "-i 0"
4442
4443         if [ $OSTCOUNT -gt 1 ]; then
4444                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4445                 ONESTRIPE=4
4446         else
4447                 ONESTRIPE=0
4448         fi
4449
4450         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4451         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4452         NUMS=$($CMD | wc -l)
4453         [ $NUMS -eq $EXPECTED ] ||
4454                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4455
4456         EXPECTED=$ONESTRIPE
4457         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4458         NUMS=$($CMD | wc -l)
4459         [ $NUMS -eq $EXPECTED ] ||
4460                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4461
4462         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4463         NUMS=$($CMD | wc -l)
4464         [ $NUMS -eq $EXPECTED ] ||
4465                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4466
4467         EXPECTED=0
4468         # This should produce an error and not return any files
4469         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4470         NUMS=$($CMD 2>/dev/null | wc -l)
4471         [ $NUMS -eq $EXPECTED ] ||
4472                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4473
4474         if [ $OSTCOUNT -gt 1 ]; then
4475                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4476                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4477                 NUMS=$($CMD | wc -l)
4478                 [ $NUMS -eq $EXPECTED ] ||
4479                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4480         fi
4481 }
4482 run_test 56u "check lfs find -stripe-index works"
4483
4484 test_56v() {
4485     local MDT_IDX=0
4486
4487     TDIR=$DIR/${tdir}v
4488     rm -rf $TDIR
4489     setup_56 $NUMFILES $NUMDIRS
4490
4491     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4492     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4493
4494     for file in $($LFIND -mdt $UUID $TDIR); do
4495         file_mdt_idx=$($GETSTRIPE -M $file)
4496         [ $file_mdt_idx -eq $MDT_IDX ] ||
4497             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4498     done
4499 }
4500 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4501
4502 # Get and check the actual stripe count of one file.
4503 # Usage: check_stripe_count <file> <expected_stripe_count>
4504 check_stripe_count() {
4505     local file=$1
4506     local expected=$2
4507     local actual
4508
4509     [[ -z "$file" || -z "$expected" ]] &&
4510         error "check_stripe_count: invalid argument!"
4511
4512     local cmd="$GETSTRIPE -c $file"
4513     actual=$($cmd) || error "$cmd failed"
4514     actual=${actual%% *}
4515
4516     if [[ $actual -ne $expected ]]; then
4517         [[ $expected -eq -1 ]] ||
4518             error "$cmd wrong: found $actual, expected $expected"
4519         [[ $actual -eq $OSTCOUNT ]] ||
4520             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4521     fi
4522 }
4523
4524 test_56w() {
4525         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4526         TDIR=$DIR/${tdir}w
4527
4528     rm -rf $TDIR || error "remove $TDIR failed"
4529     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4530
4531     local stripe_size
4532     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4533         error "$GETSTRIPE -S -d $TDIR failed"
4534     stripe_size=${stripe_size%% *}
4535
4536     local file_size=$((stripe_size * OSTCOUNT))
4537     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4538     local required_space=$((file_num * file_size))
4539     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4540     [[ $free_space -le $((required_space / 1024)) ]] &&
4541         skip_env "need at least $required_space bytes free space," \
4542                  "have $free_space kbytes" && return
4543
4544     local dd_bs=65536
4545     local dd_count=$((file_size / dd_bs))
4546
4547     # write data into the files
4548     local i
4549     local j
4550     local file
4551     for i in $(seq 1 $NUMFILES); do
4552         file=$TDIR/file$i
4553         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4554             error "write data into $file failed"
4555     done
4556     for i in $(seq 1 $NUMDIRS); do
4557         for j in $(seq 1 $NUMFILES); do
4558             file=$TDIR/dir$i/file$j
4559             yes | dd bs=$dd_bs count=$dd_count of=$file \
4560                 >/dev/null 2>&1 ||
4561                 error "write data into $file failed"
4562         done
4563     done
4564
4565     local expected=-1
4566     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4567
4568     # lfs_migrate file
4569     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4570     echo "$cmd"
4571     eval $cmd || error "$cmd failed"
4572
4573     check_stripe_count $TDIR/file1 $expected
4574
4575     # lfs_migrate dir
4576     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4577     echo "$cmd"
4578     eval $cmd || error "$cmd failed"
4579
4580     for j in $(seq 1 $NUMFILES); do
4581         check_stripe_count $TDIR/dir1/file$j $expected
4582     done
4583
4584     # lfs_migrate works with lfs find
4585     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4586          $LFS_MIGRATE -y -c $expected"
4587     echo "$cmd"
4588     eval $cmd || error "$cmd failed"
4589
4590     for i in $(seq 2 $NUMFILES); do
4591         check_stripe_count $TDIR/file$i $expected
4592     done
4593     for i in $(seq 2 $NUMDIRS); do
4594         for j in $(seq 1 $NUMFILES); do
4595             check_stripe_count $TDIR/dir$i/file$j $expected
4596         done
4597     done
4598 }
4599 run_test 56w "check lfs_migrate -c stripe_count works"
4600
4601 test_56x() {
4602         check_swap_layouts_support && return 0
4603         [ "$OSTCOUNT" -lt "2" ] &&
4604                 skip_env "need 2 OST, skipping test" && return
4605
4606         local dir0=$DIR/$tdir/$testnum
4607         mkdir -p $dir0 || error "creating dir $dir0"
4608
4609         local ref1=/etc/passwd
4610         local file1=$dir0/file1
4611
4612         $SETSTRIPE -c 2 $file1
4613         cp $ref1 $file1
4614         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4615         stripe=$($GETSTRIPE -c $file1)
4616         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4617         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4618
4619         # clean up
4620         rm -f $file1
4621 }
4622 run_test 56x "lfs migration support"
4623
4624 test_56y() {
4625         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4626                 skip "No HSM support on MDS of $(get_lustre_version)," \
4627                          "need 2.4.53 at least" && return
4628         local res=""
4629
4630         local dir0=$DIR/$tdir/$testnum
4631         mkdir -p $dir0 || error "creating dir $dir0"
4632         local f1=$dir0/file1
4633         local f2=$dir0/file2
4634
4635         touch $f1 || error "creating std file $f1"
4636         $MULTIOP $f2 H2c || error "creating released file $f2"
4637
4638         # a directory can be raid0, so ask only for files
4639         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4640         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4641
4642         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4643         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4644
4645         # only files can be released, so no need to force file search
4646         res=$($LFIND $dir0 -L released)
4647         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4648
4649         res=$($LFIND $dir0 \! -L released)
4650         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4651
4652 }
4653 run_test 56y "lfs find -L raid0|released"
4654
4655 test_57a() {
4656         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4657         # note test will not do anything if MDS is not local
4658         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4659                 skip "Only applicable to ldiskfs-based MDTs"
4660                 return
4661         fi
4662
4663         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4664         local MNTDEV="osd*.*MDT*.mntdev"
4665         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4666         [ -z "$DEV" ] && error "can't access $MNTDEV"
4667         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4668                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4669                         error "can't access $DEV"
4670                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
4671                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
4672                 rm $TMP/t57a.dump
4673         done
4674 }
4675 run_test 57a "verify MDS filesystem created with large inodes =="
4676
4677 test_57b() {
4678         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4679         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4680                 skip "Only applicable to ldiskfs-based MDTs"
4681                 return
4682         fi
4683
4684         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4685         local dir=$DIR/d57b
4686
4687         local FILECOUNT=100
4688         local FILE1=$dir/f1
4689         local FILEN=$dir/f$FILECOUNT
4690
4691         rm -rf $dir || error "removing $dir"
4692         test_mkdir -p $dir || error "creating $dir"
4693         local num=$(get_mds_dir $dir)
4694         local mymds=mds$num
4695
4696         echo "mcreating $FILECOUNT files"
4697         createmany -m $dir/f 1 $FILECOUNT || \
4698                 error "creating files in $dir"
4699
4700         # verify that files do not have EAs yet
4701         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4702         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4703
4704         sync
4705         sleep 1
4706         df $dir  #make sure we get new statfs data
4707         local MDSFREE=$(do_facet $mymds \
4708                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4709         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4710         echo "opening files to create objects/EAs"
4711         local FILE
4712         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4713                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4714         done
4715
4716         # verify that files have EAs now
4717         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4718         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4719
4720         sleep 1  #make sure we get new statfs data
4721         df $dir
4722         local MDSFREE2=$(do_facet $mymds \
4723                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4724         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4725         if [ "$MDCFREE2" -lt "$((MDCFREE - 16))" ]; then
4726                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4727                         error "MDC before $MDCFREE != after $MDCFREE2"
4728                 else
4729                         echo "MDC before $MDCFREE != after $MDCFREE2"
4730                         echo "unable to confirm if MDS has large inodes"
4731                 fi
4732         fi
4733         rm -rf $dir
4734 }
4735 run_test 57b "default LOV EAs are stored inside large inodes ==="
4736
4737 test_58() {
4738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4739         [ -z "$(which wiretest 2>/dev/null)" ] &&
4740                         skip_env "could not find wiretest" && return
4741         wiretest
4742 }
4743 run_test 58 "verify cross-platform wire constants =============="
4744
4745 test_59() {
4746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4747         echo "touch 130 files"
4748         createmany -o $DIR/f59- 130
4749         echo "rm 130 files"
4750         unlinkmany $DIR/f59- 130
4751         sync
4752         # wait for commitment of removal
4753         wait_delete_completed
4754 }
4755 run_test 59 "verify cancellation of llog records async ========="
4756
4757 TEST60_HEAD="test_60 run $RANDOM"
4758 test_60a() {
4759         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4760         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4761         do_facet mgs "! which run-llog.sh &> /dev/null" &&
4762                 skip_env "missing subtest run-llog.sh" && return
4763         log "$TEST60_HEAD - from kernel mode"
4764         do_facet mgs sh run-llog.sh
4765 }
4766 run_test 60a "llog sanity tests run from kernel module =========="
4767
4768 test_60b() { # bug 6411
4769         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4770         dmesg > $DIR/$tfile
4771         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4772                                  /llog.test/ {
4773                                          if (marker)
4774                                                  from_marker++
4775                                          from_begin++
4776                                  }
4777                                  END {
4778                                          if (marker)
4779                                                  print from_marker
4780                                          else
4781                                                  print from_begin
4782                                  }"`
4783         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
4784 }
4785 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4786
4787 test_60c() {
4788         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4789         echo "create 5000 files"
4790         createmany -o $DIR/f60c- 5000
4791 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4792         lctl set_param fail_loc=0x80000137
4793         unlinkmany $DIR/f60c- 5000
4794         lctl set_param fail_loc=0
4795 }
4796 run_test 60c "unlink file when mds full"
4797
4798 test_60d() {
4799         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4800         SAVEPRINTK=$(lctl get_param -n printk)
4801
4802         # verify "lctl mark" is even working"
4803         MESSAGE="test message ID $RANDOM $$"
4804         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4805         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4806
4807         lctl set_param printk=0 || error "set lnet.printk failed"
4808         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4809         MESSAGE="new test message ID $RANDOM $$"
4810         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4811         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4812         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4813
4814         lctl set_param -n printk="$SAVEPRINTK"
4815 }
4816 run_test 60d "test printk console message masking"
4817
4818 test_61() {
4819         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4820         f="$DIR/f61"
4821         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
4822         cancel_lru_locks osc
4823         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
4824         sync
4825 }
4826 run_test 61 "mmap() writes don't make sync hang ================"
4827
4828 # bug 2330 - insufficient obd_match error checking causes LBUG
4829 test_62() {
4830         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4831         f="$DIR/f62"
4832         echo foo > $f
4833         cancel_lru_locks osc
4834         lctl set_param fail_loc=0x405
4835         cat $f && error "cat succeeded, expect -EIO"
4836         lctl set_param fail_loc=0
4837 }
4838 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4839 # match every page all of the time.
4840 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4841
4842 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4843 test_63a() {    # was test_63
4844         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4845         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4846         lctl set_param -n osc.*.max_dirty_mb 0
4847         for i in `seq 10` ; do
4848                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4849                 sleep 5
4850                 kill $!
4851                 sleep 1
4852         done
4853
4854         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
4855         rm -f $DIR/f63 || true
4856 }
4857 run_test 63a "Verify oig_wait interruption does not crash ======="
4858
4859 # bug 2248 - async write errors didn't return to application on sync
4860 # bug 3677 - async write errors left page locked
4861 test_63b() {
4862         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4863         debugsave
4864         lctl set_param debug=-1
4865
4866         # ensure we have a grant to do async writes
4867         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4868         rm $DIR/$tfile
4869
4870         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4871         lctl set_param fail_loc=0x80000406
4872         $MULTIOP $DIR/$tfile Owy && \
4873                 error "sync didn't return ENOMEM"
4874         sync; sleep 2; sync     # do a real sync this time to flush page
4875         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4876                 error "locked page left in cache after async error" || true
4877         debugrestore
4878 }
4879 run_test 63b "async write errors should be returned to fsync ==="
4880
4881 test_64a () {
4882         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4883         df $DIR
4884         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4885 }
4886 run_test 64a "verify filter grant calculations (in kernel) ====="
4887
4888 test_64b () {
4889         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4890         sh oos.sh $MOUNT || error "oos.sh failed: $?"
4891 }
4892 run_test 64b "check out-of-space detection on client ==========="
4893
4894 test_64c() {
4895         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
4896 }
4897 run_test 64c "verify grant shrink ========================------"
4898
4899 # bug 1414 - set/get directories' stripe info
4900 test_65a() {
4901         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4902         test_mkdir -p $DIR/$tdir
4903         touch $DIR/$tdir/f1
4904         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
4905 }
4906 run_test 65a "directory with no stripe info ===================="
4907
4908 test_65b() {
4909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4910         test_mkdir -p $DIR/$tdir
4911         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4912                                                 error "setstripe"
4913         touch $DIR/$tdir/f2
4914         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
4915 }
4916 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4917
4918 test_65c() {
4919         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4920         if [ $OSTCOUNT -gt 1 ]; then
4921                 test_mkdir -p $DIR/$tdir
4922                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4923                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
4924                 touch $DIR/$tdir/f3
4925                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
4926         fi
4927 }
4928 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4929
4930 test_65d() {
4931         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4932         test_mkdir -p $DIR/$tdir
4933         if [ $STRIPECOUNT -le 0 ]; then
4934                 sc=1
4935         elif [ $STRIPECOUNT -gt 2000 ]; then
4936 #LOV_MAX_STRIPE_COUNT is 2000
4937                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
4938         else
4939                 sc=$(($STRIPECOUNT - 1))
4940         fi
4941         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
4942         touch $DIR/$tdir/f4 $DIR/$tdir/f5
4943         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
4944                                                 error "lverify failed"
4945 }
4946 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
4947
4948 test_65e() {
4949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4950         test_mkdir -p $DIR/$tdir
4951
4952         $SETSTRIPE $DIR/$tdir || error "setstripe"
4953         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
4954                                         error "no stripe info failed"
4955         touch $DIR/$tdir/f6
4956         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
4957 }
4958 run_test 65e "directory setstripe defaults ======================="
4959
4960 test_65f() {
4961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4962         test_mkdir -p $DIR/${tdir}f
4963         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
4964 }
4965 run_test 65f "dir setstripe permission (should return error) ==="
4966
4967 test_65g() {
4968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4969         test_mkdir -p $DIR/$tdir
4970         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4971                                                         error "setstripe"
4972         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
4973         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
4974                 error "delete default stripe failed"
4975 }
4976 run_test 65g "directory setstripe -d ==========================="
4977
4978 test_65h() {
4979         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4980         test_mkdir -p $DIR/$tdir
4981         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4982                                                         error "setstripe"
4983         test_mkdir -p $DIR/$tdir/dd1
4984         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
4985                 error "stripe info inherit failed"
4986 }
4987 run_test 65h "directory stripe info inherit ===================="
4988
4989 test_65i() { # bug6367
4990         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4991         $SETSTRIPE -S 65536 -c -1 $MOUNT
4992 }
4993 run_test 65i "set non-default striping on root directory (bug 6367)="
4994
4995 test_65ia() { # bug12836
4996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4997         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
4998 }
4999 run_test 65ia "getstripe on -1 default directory striping"
5000
5001 test_65ib() { # bug12836
5002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5003         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5004 }
5005 run_test 65ib "getstripe -v on -1 default directory striping"
5006
5007 test_65ic() { # bug12836
5008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5009         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5010 }
5011 run_test 65ic "new find on -1 default directory striping"
5012
5013 test_65j() { # bug6367
5014         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5015         sync; sleep 1
5016         # if we aren't already remounting for each test, do so for this test
5017         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5018                 cleanup || error "failed to unmount"
5019                 setup
5020         fi
5021         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5022 }
5023 run_test 65j "set default striping on root directory (bug 6367)="
5024
5025 test_65k() { # bug11679
5026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5027         [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
5028         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5029
5030     echo "Check OST status: "
5031     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5032               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5033
5034     for OSC in $MDS_OSCS; do
5035         echo $OSC "is activate"
5036         do_facet $SINGLEMDS lctl --device %$OSC activate
5037     done
5038
5039     mkdir -p $DIR/$tdir
5040     for INACTIVE_OSC in $MDS_OSCS; do
5041         echo "Deactivate: " $INACTIVE_OSC
5042         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5043         for STRIPE_OSC in $MDS_OSCS; do
5044             OST=`osc_to_ost $STRIPE_OSC`
5045             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5046                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5047
5048             [ -f $DIR/$tdir/$IDX ] && continue
5049             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5050             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5051             RC=$?
5052             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5053         done
5054         rm -f $DIR/$tdir/*
5055         echo $INACTIVE_OSC "is Activate."
5056         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5057     done
5058 }
5059 run_test 65k "validate manual striping works properly with deactivated OSCs"
5060
5061 test_65l() { # bug 12836
5062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5063         test_mkdir -p $DIR/$tdir/test_dir
5064         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5065         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5066 }
5067 run_test 65l "lfs find on -1 stripe dir ========================"
5068
5069 # bug 2543 - update blocks count on client
5070 test_66() {
5071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5072         COUNT=${COUNT:-8}
5073         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5074         sync; sync_all_data; sync; sync_all_data
5075         cancel_lru_locks osc
5076         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5077         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5078 }
5079 run_test 66 "update inode blocks count on client ==============="
5080
5081 LLOOP=
5082 LLITELOOPLOAD=
5083 cleanup_68() {
5084         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5085         trap 0
5086         if [ ! -z "$LLOOP" ]; then
5087                 if swapon -s | grep -q $LLOOP; then
5088                         swapoff $LLOOP || error "swapoff failed"
5089                 fi
5090
5091                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5092                 rm -f $LLOOP
5093                 unset LLOOP
5094         fi
5095         if [ ! -z "$LLITELOOPLOAD" ]; then
5096                 rmmod llite_lloop
5097                 unset LLITELOOPLOAD
5098         fi
5099         rm -f $DIR/f68*
5100 }
5101
5102 meminfo() {
5103         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5104 }
5105
5106 swap_used() {
5107         swapon -s | awk '($1 == "'$1'") { print $4 }'
5108 }
5109
5110 # test case for lloop driver, basic function
5111 test_68a() {
5112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5113         [ "$UID" != 0 ] && skip_env "must run as root" && return
5114         llite_lloop_enabled || \
5115                 { skip_env "llite_lloop module disabled" && return; }
5116
5117         trap cleanup_68 EXIT
5118
5119         if ! module_loaded llite_lloop; then
5120                 if load_module llite/llite_lloop; then
5121                         LLITELOOPLOAD=yes
5122                 else
5123                         skip_env "can't find module llite_lloop"
5124                         return
5125                 fi
5126         fi
5127
5128         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5129         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5130         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5131
5132         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5133         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5134
5135         cleanup_68
5136 }
5137 run_test 68a "lloop driver - basic test ========================"
5138
5139 # excercise swapping to lustre by adding a high priority swapfile entry
5140 # and then consuming memory until it is used.
5141 test_68b() {  # was test_68
5142         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5143         [ "$UID" != 0 ] && skip_env "must run as root" && return
5144         lctl get_param -n devices | grep -q obdfilter && \
5145                 skip "local OST" && return
5146
5147         grep -q llite_lloop /proc/modules
5148         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5149
5150         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5151                 skip "can't reliably test swap with TCP" && return
5152
5153         MEMTOTAL=`meminfo MemTotal`
5154         NR_BLOCKS=$((MEMTOTAL>>8))
5155         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5156
5157         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5158         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5159         mkswap $DIR/f68b
5160
5161         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5162
5163         trap cleanup_68 EXIT
5164
5165         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5166
5167         echo "before: `swapon -s | grep $LLOOP`"
5168         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5169         echo "after: `swapon -s | grep $LLOOP`"
5170         SWAPUSED=`swap_used $LLOOP`
5171
5172         cleanup_68
5173
5174         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5175 }
5176 run_test 68b "support swapping to Lustre ========================"
5177
5178 # bug5265, obdfilter oa2dentry return -ENOENT
5179 # #define OBD_FAIL_OST_ENOENT 0x217
5180 test_69() {
5181         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5182         remote_ost_nodsh && skip "remote OST with nodsh" && return
5183
5184         f="$DIR/$tfile"
5185         $SETSTRIPE -c 1 -i 0 $f
5186
5187         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5188
5189         do_facet ost1 lctl set_param fail_loc=0x217
5190         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5191         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5192
5193         do_facet ost1 lctl set_param fail_loc=0
5194         $DIRECTIO write $f 0 2 || error "write error"
5195
5196         cancel_lru_locks osc
5197         $DIRECTIO read $f 0 1 || error "read error"
5198
5199         do_facet ost1 lctl set_param fail_loc=0x217
5200         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5201
5202         do_facet ost1 lctl set_param fail_loc=0
5203         rm -f $f
5204 }
5205 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5206
5207 test_71() {
5208     test_mkdir -p $DIR/$tdir
5209     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5210 }
5211 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5212
5213 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5214         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5215         [ "$RUNAS_ID" = "$UID" ] &&
5216                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5217
5218         # Check that testing environment is properly set up. Skip if not
5219         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5220                 skip_env "User $RUNAS_ID does not exist - skipping"
5221                 return 0
5222         }
5223         # We had better clear the $DIR to get enough space for dd
5224         rm -rf $DIR/*
5225         touch $DIR/$tfile
5226         chmod 777 $DIR/$tfile
5227         chmod ug+s $DIR/$tfile
5228         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5229                 error "$RUNAS dd $DIR/$tfile failed"
5230         # See if we are still setuid/sgid
5231         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5232                 error "S/gid is not dropped on write"
5233         # Now test that MDS is updated too
5234         cancel_lru_locks mdc
5235         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5236                 error "S/gid is not dropped on MDS"
5237         rm -f $DIR/$tfile
5238 }
5239 run_test 72a "Test that remove suid works properly (bug5695) ===="
5240
5241 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5242         local perm
5243
5244         [ "$RUNAS_ID" = "$UID" ] && \
5245                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5246         [ "$RUNAS_ID" -eq 0 ] && \
5247                 skip_env "RUNAS_ID = 0 -- skipping" && return
5248
5249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5250         # Check that testing environment is properly set up. Skip if not
5251         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5252                 skip_env "User $RUNAS_ID does not exist - skipping"
5253                 return 0
5254         }
5255         touch $DIR/${tfile}-f{g,u}
5256         test_mkdir $DIR/${tfile}-dg
5257         test_mkdir $DIR/${tfile}-du
5258         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5259         chmod g+s $DIR/${tfile}-{f,d}g
5260         chmod u+s $DIR/${tfile}-{f,d}u
5261         for perm in 777 2777 4777; do
5262                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5263                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5264                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5265                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5266         done
5267         true
5268 }
5269 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5270
5271 # bug 3462 - multiple simultaneous MDC requests
5272 test_73() {
5273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5274         test_mkdir $DIR/d73-1
5275         test_mkdir $DIR/d73-2
5276         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5277         pid1=$!
5278
5279         lctl set_param fail_loc=0x80000129
5280         $MULTIOP $DIR/d73-1/f73-2 Oc &
5281         sleep 1
5282         lctl set_param fail_loc=0
5283
5284         $MULTIOP $DIR/d73-2/f73-3 Oc &
5285         pid3=$!
5286
5287         kill -USR1 $pid1
5288         wait $pid1 || return 1
5289
5290         sleep 25
5291
5292         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5293         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5294         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5295
5296         rm -rf $DIR/d73-*
5297 }
5298 run_test 73 "multiple MDC requests (should not deadlock)"
5299
5300 test_74a() { # bug 6149, 6184
5301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5302         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5303         #
5304         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5305         # will spin in a tight reconnection loop
5306         touch $DIR/f74a
5307         lctl set_param fail_loc=0x8000030e
5308         # get any lock that won't be difficult - lookup works.
5309         ls $DIR/f74a
5310         lctl set_param fail_loc=0
5311         true
5312         rm -f $DIR/f74a
5313 }
5314 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5315
5316 test_74b() { # bug 13310
5317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5318         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5319         #
5320         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5321         # will spin in a tight reconnection loop
5322         lctl set_param fail_loc=0x8000030e
5323         # get a "difficult" lock
5324         touch $DIR/f74b
5325         lctl set_param fail_loc=0
5326         true
5327         rm -f $DIR/f74b
5328 }
5329 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5330
5331 test_74c() {
5332         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5333 #define OBD_FAIL_LDLM_NEW_LOCK
5334         lctl set_param fail_loc=0x80000319
5335         touch $DIR/$tfile && error "Touch successful"
5336         true
5337 }
5338 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5339
5340 num_inodes() {
5341         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5342 }
5343
5344 get_inode_slab_tunables() {
5345         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5346 }
5347
5348 set_inode_slab_tunables() {
5349         echo "lustre_inode_cache $1" > /proc/slabinfo
5350 }
5351
5352 test_76() { # Now for bug 20433, added originally in bug 1443
5353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5354         local SLAB_SETTINGS=`get_inode_slab_tunables`
5355         local CPUS=`getconf _NPROCESSORS_ONLN`
5356         # we cannot set limit below 1 which means 1 inode in each
5357         # per-cpu cache is still allowed
5358         set_inode_slab_tunables "1 1 0"
5359         cancel_lru_locks osc
5360         BEFORE_INODES=`num_inodes`
5361         echo "before inodes: $BEFORE_INODES"
5362         local COUNT=1000
5363         [ "$SLOW" = "no" ] && COUNT=100
5364         for i in `seq $COUNT`; do
5365                 touch $DIR/$tfile
5366                 rm -f $DIR/$tfile
5367         done
5368         cancel_lru_locks osc
5369         AFTER_INODES=`num_inodes`
5370         echo "after inodes: $AFTER_INODES"
5371         local wait=0
5372         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
5373                 sleep 2
5374                 AFTER_INODES=`num_inodes`
5375                 wait=$((wait+2))
5376                 echo "wait $wait seconds inodes: $AFTER_INODES"
5377                 if [ $wait -gt 30 ]; then
5378                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5379                 fi
5380         done
5381         set_inode_slab_tunables "$SLAB_SETTINGS"
5382 }
5383 run_test 76 "confirm clients recycle inodes properly ===="
5384
5385
5386 export ORIG_CSUM=""
5387 set_checksums()
5388 {
5389         # Note: in sptlrpc modes which enable its own bulk checksum, the
5390         # original crc32_le bulk checksum will be automatically disabled,
5391         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5392         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5393         # In this case set_checksums() will not be no-op, because sptlrpc
5394         # bulk checksum will be enabled all through the test.
5395
5396         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5397         lctl set_param -n osc.*.checksums $1
5398         return 0
5399 }
5400
5401 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5402                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5403 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5404 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5405 set_checksum_type()
5406 {
5407         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5408         log "set checksum type to $1"
5409         return 0
5410 }
5411 F77_TMP=$TMP/f77-temp
5412 F77SZ=8
5413 setup_f77() {
5414         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5415                 error "error writing to $F77_TMP"
5416 }
5417
5418 test_77a() { # bug 10889
5419         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5420         $GSS && skip "could not run with gss" && return
5421         [ ! -f $F77_TMP ] && setup_f77
5422         set_checksums 1
5423         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5424         set_checksums 0
5425         rm -f $DIR/$tfile
5426 }
5427 run_test 77a "normal checksum read/write operation"
5428
5429 test_77b() { # bug 10889
5430         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5431         $GSS && skip "could not run with gss" && return
5432         [ ! -f $F77_TMP ] && setup_f77
5433         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5434         $LCTL set_param fail_loc=0x80000409
5435         set_checksums 1
5436
5437         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5438                 error "dd error: $?"
5439         $LCTL set_param fail_loc=0
5440
5441         for algo in $CKSUM_TYPES; do
5442                 cancel_lru_locks osc
5443                 set_checksum_type $algo
5444                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5445                 $LCTL set_param fail_loc=0x80000408
5446                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5447                 $LCTL set_param fail_loc=0
5448         done
5449         set_checksums 0
5450         set_checksum_type $ORIG_CSUM_TYPE
5451         rm -f $DIR/$tfile
5452 }
5453 run_test 77b "checksum error on client write, read"
5454
5455 test_77d() { # bug 10889
5456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5457         $GSS && skip "could not run with gss" && return
5458         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5459         $LCTL set_param fail_loc=0x80000409
5460         set_checksums 1
5461         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5462                 error "direct write: rc=$?"
5463         $LCTL set_param fail_loc=0
5464         set_checksums 0
5465
5466         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5467         $LCTL set_param fail_loc=0x80000408
5468         set_checksums 1
5469         cancel_lru_locks osc
5470         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5471                 error "direct read: rc=$?"
5472         $LCTL set_param fail_loc=0
5473         set_checksums 0
5474 }
5475 run_test 77d "checksum error on OST direct write, read"
5476
5477 test_77f() { # bug 10889
5478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5479         $GSS && skip "could not run with gss" && return
5480         set_checksums 1
5481         for algo in $CKSUM_TYPES; do
5482                 cancel_lru_locks osc
5483                 set_checksum_type $algo
5484                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5485                 $LCTL set_param fail_loc=0x409
5486                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5487                         error "direct write succeeded"
5488                 $LCTL set_param fail_loc=0
5489         done
5490         set_checksum_type $ORIG_CSUM_TYPE
5491         set_checksums 0
5492 }
5493 run_test 77f "repeat checksum error on write (expect error)"
5494
5495 test_77g() { # bug 10889
5496         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5497         $GSS && skip "could not run with gss" && return
5498         remote_ost_nodsh && skip "remote OST with nodsh" && return
5499
5500         [ ! -f $F77_TMP ] && setup_f77
5501
5502         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5503         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5504         do_facet ost1 lctl set_param fail_loc=0x8000021a
5505         set_checksums 1
5506         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5507                 error "write error: rc=$?"
5508         do_facet ost1 lctl set_param fail_loc=0
5509         set_checksums 0
5510
5511         cancel_lru_locks osc
5512         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5513         do_facet ost1 lctl set_param fail_loc=0x8000021b
5514         set_checksums 1
5515         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5516         do_facet ost1 lctl set_param fail_loc=0
5517         set_checksums 0
5518 }
5519 run_test 77g "checksum error on OST write, read"
5520
5521 test_77i() { # bug 13805
5522         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5523         $GSS && skip "could not run with gss" && return
5524         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5525         lctl set_param fail_loc=0x40b
5526         remount_client $MOUNT
5527         lctl set_param fail_loc=0
5528         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5529                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5530                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5531                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5532         done
5533         remount_client $MOUNT
5534 }
5535 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5536
5537 test_77j() { # bug 13805
5538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5539         $GSS && skip "could not run with gss" && return
5540         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5541         lctl set_param fail_loc=0x40c
5542         remount_client $MOUNT
5543         lctl set_param fail_loc=0
5544         sleep 2 # wait async osc connect to finish
5545         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5546                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5547                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5548                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5549         done
5550         remount_client $MOUNT
5551 }
5552 run_test 77j "client only supporting ADLER32"
5553
5554 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5555 rm -f $F77_TMP
5556 unset F77_TMP
5557
5558 test_78() { # bug 10901
5559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5560         remote_ost || { skip_env "local OST" && return; }
5561
5562         NSEQ=5
5563         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5564         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5565         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5566         echo "MemTotal: $MEMTOTAL"
5567 # reserve 256MB of memory for the kernel and other running processes,
5568 # and then take 1/2 of the remaining memory for the read/write buffers.
5569     if [ $MEMTOTAL -gt 512 ] ;then
5570         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5571     else
5572         # for those poor memory-starved high-end clusters...
5573         MEMTOTAL=$((MEMTOTAL / 2))
5574     fi
5575         echo "Mem to use for directio: $MEMTOTAL"
5576         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
5577         [ $F78SIZE -gt 512 ] && F78SIZE=512
5578         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
5579         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
5580         echo "Smallest OST: $SMALLESTOST"
5581         [ $SMALLESTOST -lt 10240 ] && \
5582                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5583
5584         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
5585                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5586
5587         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5588         echo "File size: $F78SIZE"
5589         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5590         for i in `seq 1 $NSEQ`
5591         do
5592                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5593                 echo directIO rdwr round $i of $NSEQ
5594                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5595         done
5596
5597         rm -f $DIR/$tfile
5598 }
5599 run_test 78 "handle large O_DIRECT writes correctly ============"
5600
5601 test_79() { # bug 12743
5602         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5603         wait_delete_completed
5604
5605         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5606         BKFREE=$(calc_osc_kbytes kbytesfree)
5607         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5608
5609         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5610         DFTOTAL=`echo $STRING | cut -d, -f1`
5611         DFUSED=`echo $STRING  | cut -d, -f2`
5612         DFAVAIL=`echo $STRING | cut -d, -f3`
5613         DFFREE=$(($DFTOTAL - $DFUSED))
5614
5615         ALLOWANCE=$((64 * $OSTCOUNT))
5616
5617         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5618            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5619                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5620         fi
5621         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5622            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5623                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5624         fi
5625         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5626            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5627                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5628         fi
5629 }
5630 run_test 79 "df report consistency check ======================="
5631
5632 test_80() { # bug 10718
5633         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5634         # relax strong synchronous semantics for slow backends like ZFS
5635         local soc="obdfilter.*.sync_on_lock_cancel"
5636         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5637         local hosts=
5638         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5639                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5640                           facet_active_host $host; done | sort -u)
5641                 do_nodes $hosts lctl set_param $soc=never
5642         fi
5643
5644         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5645         sync; sleep 1; sync
5646         local BEFORE=`date +%s`
5647         cancel_lru_locks osc
5648         local AFTER=`date +%s`
5649         local DIFF=$((AFTER-BEFORE))
5650         if [ $DIFF -gt 1 ] ; then
5651                 error "elapsed for 1M@1T = $DIFF"
5652         fi
5653
5654         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5655
5656         rm -f $DIR/$tfile
5657 }
5658 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5659
5660 test_81a() { # LU-456
5661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5662         remote_ost_nodsh && skip "remote OST with nodsh" && return
5663         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5664         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5665         do_facet ost1 lctl set_param fail_loc=0x80000228
5666
5667         # write should trigger a retry and success
5668         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5669         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5670         RC=$?
5671         if [ $RC -ne 0 ] ; then
5672                 error "write should success, but failed for $RC"
5673         fi
5674 }
5675 run_test 81a "OST should retry write when get -ENOSPC ==============="
5676
5677 test_81b() { # LU-456
5678         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5679         remote_ost_nodsh && skip "remote OST with nodsh" && return
5680         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5681         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5682         do_facet ost1 lctl set_param fail_loc=0x228
5683
5684         # write should retry several times and return -ENOSPC finally
5685         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5686         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5687         RC=$?
5688         ENOSPC=28
5689         if [ $RC -ne $ENOSPC ] ; then
5690                 error "dd should fail for -ENOSPC, but succeed."
5691         fi
5692 }
5693 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5694
5695 test_82() { # LU-1031
5696         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5697         local gid1=14091995
5698         local gid2=16022000
5699
5700         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5701         local MULTIPID1=$!
5702         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5703         local MULTIPID2=$!
5704         kill -USR1 $MULTIPID2
5705         sleep 2
5706         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5707                 error "First grouplock does not block second one"
5708         else
5709                 echo "Second grouplock blocks first one"
5710         fi
5711         kill -USR1 $MULTIPID1
5712         wait $MULTIPID1
5713         wait $MULTIPID2
5714 }
5715 run_test 82 "Basic grouplock test ==============================="
5716
5717 test_99a() {
5718         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
5719                 return
5720         test_mkdir -p $DIR/d99cvsroot
5721         chown $RUNAS_ID $DIR/d99cvsroot
5722         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5723         cd $TMP
5724
5725         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
5726         cd $oldPWD
5727 }
5728 run_test 99a "cvs init ========================================="
5729
5730 test_99b() {
5731         [ -z "$(which cvs 2>/dev/null)" ] &&
5732                 skip_env "could not find cvs" && return
5733         [ ! -d $DIR/d99cvsroot ] && test_99a
5734         cd /etc/init.d
5735         # some versions of cvs import exit(1) when asked to import links or
5736         # files they can't read.  ignore those files.
5737         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5738                         ! -perm +4 -printf '-I %f\n')
5739         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5740                 d99reposname vtag rtag
5741 }
5742 run_test 99b "cvs import ======================================="
5743
5744 test_99c() {
5745         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5746         [ ! -d $DIR/d99cvsroot ] && test_99b
5747         cd $DIR
5748         test_mkdir -p $DIR/d99reposname
5749         chown $RUNAS_ID $DIR/d99reposname
5750         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5751 }
5752 run_test 99c "cvs checkout ====================================="
5753
5754 test_99d() {
5755         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5756         [ ! -d $DIR/d99cvsroot ] && test_99c
5757         cd $DIR/d99reposname
5758         $RUNAS touch foo99
5759         $RUNAS cvs add -m 'addmsg' foo99
5760 }
5761 run_test 99d "cvs add =========================================="
5762
5763 test_99e() {
5764         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5765         [ ! -d $DIR/d99cvsroot ] && test_99c
5766         cd $DIR/d99reposname
5767         $RUNAS cvs update
5768 }
5769 run_test 99e "cvs update ======================================="
5770
5771 test_99f() {
5772         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5773         [ ! -d $DIR/d99cvsroot ] && test_99d
5774         cd $DIR/d99reposname
5775         $RUNAS cvs commit -m 'nomsg' foo99
5776     rm -fr $DIR/d99cvsroot
5777 }
5778 run_test 99f "cvs commit ======================================="
5779
5780 test_100() {
5781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5782         [ "$NETTYPE" = tcp ] || \
5783                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5784                         return ; }
5785
5786         remote_ost_nodsh && skip "remote OST with nodsh" && return
5787         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5788         remote_servers || \
5789                 { skip "useless for local single node setup" && return; }
5790
5791         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5792                 [ "$PROT" != "tcp" ] && continue
5793                 RPORT=$(echo $REMOTE | cut -d: -f2)
5794                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5795
5796                 rc=0
5797                 LPORT=`echo $LOCAL | cut -d: -f2`
5798                 if [ $LPORT -ge 1024 ]; then
5799                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5800                         netstat -tna
5801                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5802                 fi
5803         done
5804         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5805 }
5806 run_test 100 "check local port using privileged port ==========="
5807
5808 function get_named_value()
5809 {
5810     local tag
5811
5812     tag=$1
5813     while read ;do
5814         line=$REPLY
5815         case $line in
5816         $tag*)
5817             echo $line | sed "s/^$tag[ ]*//"
5818             break
5819             ;;
5820         esac
5821     done
5822 }
5823
5824 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
5825                    awk '/^max_cached_mb/ { print $2 }')
5826
5827 cleanup_101a() {
5828         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5829         trap 0
5830 }
5831
5832 test_101a() {
5833         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5834         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
5835         local s
5836         local discard
5837         local nreads=10000
5838         local cache_limit=32
5839
5840         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5841         trap cleanup_101a EXIT
5842         $LCTL set_param -n llite.*.read_ahead_stats 0
5843         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5844
5845         #
5846         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5847         #
5848         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5849         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5850
5851         discard=0
5852         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
5853                 get_named_value 'read but discarded' | cut -d" " -f1`; do
5854                         discard=$(($discard + $s))
5855         done
5856         cleanup_101a
5857
5858         if [ $(($discard * 10)) -gt $nreads ] ;then
5859                 $LCTL get_param osc.*-osc*.rpc_stats
5860                 $LCTL get_param llite.*.read_ahead_stats
5861                 error "too many ($discard) discarded pages"
5862         fi
5863         rm -f $DIR/$tfile || true
5864 }
5865 run_test 101a "check read-ahead for random reads ================"
5866
5867 setup_test101bc() {
5868         test_mkdir -p $DIR/$tdir
5869         STRIPE_SIZE=1048576
5870         STRIPE_COUNT=$OSTCOUNT
5871         STRIPE_OFFSET=0
5872
5873         local list=$(comma_list $(osts_nodes))
5874         set_osd_param $list '' read_cache_enable 0
5875         set_osd_param $list '' writethrough_cache_enable 0
5876
5877         trap cleanup_test101bc EXIT
5878         # prepare the read-ahead file
5879         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5880
5881         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
5882 }
5883
5884 cleanup_test101bc() {
5885         trap 0
5886         rm -rf $DIR/$tdir
5887         rm -f $DIR/$tfile
5888
5889         local list=$(comma_list $(osts_nodes))
5890         set_osd_param $list '' read_cache_enable 1
5891         set_osd_param $list '' writethrough_cache_enable 1
5892 }
5893
5894 calc_total() {
5895         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5896 }
5897
5898 ra_check_101() {
5899         local READ_SIZE=$1
5900         local STRIPE_SIZE=1048576
5901         local RA_INC=1048576
5902         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5903         local FILE_LENGTH=$((64*100))
5904         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5905                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5906         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5907                         get_named_value 'read but discarded' | \
5908                         cut -d" " -f1 | calc_total`
5909         if [ $DISCARD -gt $discard_limit ]; then
5910                 $LCTL get_param llite.*.read_ahead_stats
5911                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5912         else
5913                 echo "Read-ahead success for size ${READ_SIZE}"
5914         fi
5915 }
5916
5917 test_101b() {
5918         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5919         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5920         local STRIPE_SIZE=1048576
5921         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5922         local FILE_LENGTH=$((STRIPE_SIZE*100))
5923         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
5924         # prepare the read-ahead file
5925         setup_test101bc
5926         cancel_lru_locks osc
5927         for BIDX in 2 4 8 16 32 64 128 256
5928         do
5929                 local BSIZE=$((BIDX*4096))
5930                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5931                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5932                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5933                 $LCTL set_param -n llite.*.read_ahead_stats 0
5934                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5935                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5936                 cancel_lru_locks osc
5937                 ra_check_101 $BSIZE
5938         done
5939         cleanup_test101bc
5940         true
5941 }
5942 run_test 101b "check stride-io mode read-ahead ================="
5943
5944 test_101c() {
5945         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5946         local STRIPE_SIZE=1048576
5947         local FILE_LENGTH=$((STRIPE_SIZE*100))
5948         local nreads=10000
5949         local osc_rpc_stats
5950
5951         setup_test101bc
5952
5953         cancel_lru_locks osc
5954         $LCTL set_param osc.*.rpc_stats 0
5955         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
5956         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
5957                 local stats=$($LCTL get_param -n $osc_rpc_stats)
5958                 local lines=$(echo "$stats" | awk 'END {print NR;}')
5959                 local size
5960
5961                 if [ $lines -le 20 ]; then
5962                         continue
5963                 fi
5964                 for size in 1 2 4 8; do
5965                         local rpc=$(echo "$stats" |
5966                                     awk '($1 == "'$size':") {print $2; exit; }')
5967                         [ $rpc != 0 ] &&
5968                                 error "Small $((size*4))k read IO $rpc !"
5969                 done
5970                 echo "$osc_rpc_stats check passed!"
5971         done
5972         cleanup_test101bc
5973         true
5974 }
5975 run_test 101c "check stripe_size aligned read-ahead ================="
5976
5977 set_read_ahead() {
5978         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
5979         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
5980 }
5981
5982 test_101d() {
5983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5984         local file=$DIR/$tfile
5985         local sz_MB=${FILESIZE_101d:-500}
5986         local ra_MB=${READAHEAD_MB:-40}
5987
5988         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
5989         [ $free_MB -lt $sz_MB ] &&
5990                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
5991
5992         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
5993         $SETSTRIPE -c -1 $file || error "setstripe failed"
5994
5995         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
5996         echo Cancel LRU locks on lustre client to flush the client cache
5997         cancel_lru_locks osc
5998
5999         echo Disable read-ahead
6000         local old_READAHEAD=$(set_read_ahead 0)
6001
6002         echo Reading the test file $file with read-ahead disabled
6003         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6004
6005         echo Cancel LRU locks on lustre client to flush the client cache
6006         cancel_lru_locks osc
6007         echo Enable read-ahead with ${ra_MB}MB
6008         set_read_ahead $ra_MB
6009
6010         echo Reading the test file $file with read-ahead enabled
6011         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6012
6013         echo "read-ahead disabled time read $raOFF"
6014         echo "read-ahead enabled  time read $raON"
6015
6016         set_read_ahead $old_READAHEAD
6017         rm -f $file
6018         wait_delete_completed
6019
6020         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6021                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6022 }
6023 run_test 101d "file read with and without read-ahead enabled"
6024
6025 test_101e() {
6026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6027         local file=$DIR/$tfile
6028         local size_KB=500  #KB
6029         local count=100
6030         local bsize=1024
6031
6032         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6033         local need_KB=$((count * size_KB))
6034         [ $free_KB -le $need_KB ] &&
6035                 skip_env "Need free space $need_KB, have $free_KB" && return
6036
6037         echo "Creating $count ${size_KB}K test files"
6038         for ((i = 0; i < $count; i++)); do
6039                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6040         done
6041
6042         echo "Cancel LRU locks on lustre client to flush the client cache"
6043         cancel_lru_locks osc
6044
6045         echo "Reset readahead stats"
6046         $LCTL set_param -n llite.*.read_ahead_stats 0
6047
6048         for ((i = 0; i < $count; i++)); do
6049                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6050         done
6051
6052         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6053                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6054
6055         for ((i = 0; i < $count; i++)); do
6056                 rm -rf $file.$i 2>/dev/null
6057         done
6058
6059         #10000 means 20% reads are missing in readahead
6060         [ $miss -lt 10000 ] ||  error "misses too much for small reads"
6061 }
6062 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6063
6064 cleanup_test101f() {
6065     trap 0
6066     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6067     rm -rf $DIR/$tfile 2>/dev/null
6068 }
6069
6070 test_101f() {
6071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6072     local file=$DIR/$tfile
6073     local nreads=1000
6074
6075     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6076     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6077     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6078     trap cleanup_test101f EXIT
6079
6080     echo Cancel LRU locks on lustre client to flush the client cache
6081     cancel_lru_locks osc
6082
6083     echo Reset readahead stats
6084     $LCTL set_param -n llite.*.read_ahead_stats 0
6085     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6086     # readahead should read in 2M file on second read, so only miss
6087     # 2 pages.
6088     echo Random 4K reads on 2M file for 1000 times
6089     $READS -f $file -s 2097152 -b 4096 -n $nreads
6090
6091     echo checking missing pages
6092     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6093           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6094
6095     [ $miss -lt 3 ] || error "misses too much pages!"
6096     cleanup_test101f
6097 }
6098 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6099
6100 setup_test102() {
6101         test_mkdir -p $DIR/$tdir
6102         chown $RUNAS_ID $DIR/$tdir
6103         STRIPE_SIZE=65536
6104         STRIPE_OFFSET=1
6105         STRIPE_COUNT=$OSTCOUNT
6106         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
6107
6108         trap cleanup_test102 EXIT
6109         cd $DIR
6110         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6111         cd $DIR/$tdir
6112         for num in 1 2 3 4; do
6113                 for count in $(seq 1 $STRIPE_COUNT); do
6114                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6115                                 local size=`expr $STRIPE_SIZE \* $num`
6116                                 local file=file"$num-$idx-$count"
6117                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6118                         done
6119                 done
6120         done
6121
6122         cd $DIR
6123         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6124 }
6125
6126 cleanup_test102() {
6127         trap 0
6128         rm -f $TMP/f102.tar
6129         rm -rf $DIR/d0.sanity/d102
6130 }
6131
6132 test_102a() {
6133         local testfile=$DIR/xattr_testfile
6134
6135         touch $testfile
6136
6137         [ "$UID" != 0 ] && skip_env "must run as root" && return
6138         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6139                 skip_env "must have user_xattr" && return
6140
6141         [ -z "$(which setfattr 2>/dev/null)" ] &&
6142                 skip_env "could not find setfattr" && return
6143
6144         echo "set/get xattr..."
6145         setfattr -n trusted.name1 -v value1 $testfile ||
6146                 error "setfattr -n trusted.name1=value1 $testfile failed"
6147         getfattr -n trusted.name1 $testfile 2> /dev/null |
6148           grep "trusted.name1=.value1" ||
6149                 error "$testfile missing trusted.name1=value1"
6150
6151         setfattr -n user.author1 -v author1 $testfile ||
6152                 error "setfattr -n user.author1=author1 $testfile failed"
6153         getfattr -n user.author1 $testfile 2> /dev/null |
6154           grep "user.author1=.author1" ||
6155                 error "$testfile missing trusted.author1=author1"
6156
6157         echo "listxattr..."
6158         setfattr -n trusted.name2 -v value2 $testfile ||
6159                 error "$testfile unable to set trusted.name2"
6160         setfattr -n trusted.name3 -v value3 $testfile ||
6161                 error "$testfile unable to set trusted.name3"
6162         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6163             grep "trusted.name" | wc -l) -eq 3 ] ||
6164                 error "$testfile missing 3 trusted.name xattrs"
6165
6166         setfattr -n user.author2 -v author2 $testfile ||
6167                 error "$testfile unable to set user.author2"
6168         setfattr -n user.author3 -v author3 $testfile ||
6169                 error "$testfile unable to set user.author3"
6170         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6171             grep "user.author" | wc -l) -eq 3 ] ||
6172                 error "$testfile missing 3 user.author xattrs"
6173
6174         echo "remove xattr..."
6175         setfattr -x trusted.name1 $testfile ||
6176                 error "$testfile error deleting trusted.name1"
6177         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6178                 error "$testfile did not delete trusted.name1 xattr"
6179
6180         setfattr -x user.author1 $testfile ||
6181                 error "$testfile error deleting user.author1"
6182         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6183                 error "$testfile did not delete trusted.name1 xattr"
6184
6185         # b10667: setting lustre special xattr be silently discarded
6186         echo "set lustre special xattr ..."
6187         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6188                 error "$testfile allowed setting trusted.lov"
6189 }
6190 run_test 102a "user xattr test =================================="
6191
6192 test_102b() {
6193         # b10930: get/set/list trusted.lov xattr
6194         echo "get/set/list trusted.lov xattr ..."
6195         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6196         local testfile=$DIR/$tfile
6197         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6198                 error "setstripe failed"
6199         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6200                 error "getstripe failed"
6201         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
6202         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
6203
6204         local testfile2=${testfile}2
6205         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
6206                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
6207
6208         $MCREATE $testfile2
6209         setfattr -n trusted.lov -v $value $testfile2
6210         local stripe_size=$($GETSTRIPE -S $testfile2)
6211         local stripe_count=$($GETSTRIPE -c $testfile2)
6212         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6213         [ $stripe_count -eq $STRIPECOUNT ] ||
6214                 error "stripe count $stripe_count != $STRIPECOUNT"
6215         rm -f $DIR/$tfile
6216 }
6217 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6218
6219 test_102c() {
6220         # b10930: get/set/list lustre.lov xattr
6221         echo "get/set/list lustre.lov xattr ..."
6222         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6223         test_mkdir -p $DIR/$tdir
6224         chown $RUNAS_ID $DIR/$tdir
6225         local testfile=$DIR/$tdir/$tfile
6226         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6227                 error "setstripe failed"
6228         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6229                 error "getstripe failed"
6230         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6231         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6232
6233         local testfile2=${testfile}2
6234         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6235                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6236
6237         $RUNAS $MCREATE $testfile2
6238         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6239         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6240         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6241         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6242         [ $stripe_count -eq $STRIPECOUNT ] ||
6243                 error "stripe count $stripe_count != $STRIPECOUNT"
6244 }
6245 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6246
6247 compare_stripe_info1() {
6248         local stripe_index_all_zero=true
6249
6250         for num in 1 2 3 4; do
6251                 for count in $(seq 1 $STRIPE_COUNT); do
6252                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6253                                 local size=$((STRIPE_SIZE * num))
6254                                 local file=file"$num-$offset-$count"
6255                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6256                                 [ $stripe_size -ne $size ] &&
6257                                     error "$file: size $stripe_size != $size"
6258                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6259                                 # allow fewer stripes to be created, ORI-601
6260                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
6261                                     error "$file: count $stripe_count != $count"
6262                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6263                                 [ $stripe_index -ne 0 ] &&
6264                                         stripe_index_all_zero=false
6265                         done
6266                 done
6267         done
6268         $stripe_index_all_zero &&
6269                 error "all files are being extracted starting from OST index 0"
6270         return 0
6271 }
6272
6273 find_lustre_tar() {
6274         [ -n "$(which tar 2>/dev/null)" ] &&
6275                 strings $(which tar) | grep -q "lustre" && echo tar
6276 }
6277
6278 test_102d() {
6279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6280         # b10930: tar test for trusted.lov xattr
6281         TAR=$(find_lustre_tar)
6282         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6283         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6284         setup_test102
6285         test_mkdir -p $DIR/d102d
6286         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6287         cd $DIR/d102d/$tdir
6288         compare_stripe_info1
6289 }
6290 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6291
6292 test_102f() {
6293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6294         # b10930: tar test for trusted.lov xattr
6295         TAR=$(find_lustre_tar)
6296         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6297         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6298         setup_test102
6299         test_mkdir -p $DIR/d102f
6300         cd $DIR
6301         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6302         cd $DIR/d102f/$tdir
6303         compare_stripe_info1
6304 }
6305 run_test 102f "tar copy files, not keep osts ==========="
6306
6307 grow_xattr() {
6308         local xsize=${1:-1024}  # in bytes
6309         local file=$DIR/$tfile
6310
6311         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6312                 skip "must have user_xattr" && return 0
6313         [ -z "$(which setfattr 2>/dev/null)" ] &&
6314                 skip_env "could not find setfattr" && return 0
6315         [ -z "$(which getfattr 2>/dev/null)" ] &&
6316                 skip_env "could not find getfattr" && return 0
6317
6318         touch $file
6319
6320         local value="$(generate_string $xsize)"
6321
6322         local xbig=trusted.big
6323         log "save $xbig on $file"
6324         setfattr -n $xbig -v $value $file ||
6325                 error "saving $xbig on $file failed"
6326
6327         local orig=$(get_xattr_value $xbig $file)
6328         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6329
6330         local xsml=trusted.sml
6331         log "save $xsml on $file"
6332         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6333
6334         local new=$(get_xattr_value $xbig $file)
6335         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6336
6337         log "grow $xsml on $file"
6338         setfattr -n $xsml -v "$value" $file ||
6339                 error "growing $xsml on $file failed"
6340
6341         new=$(get_xattr_value $xbig $file)
6342         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6343         log "$xbig still valid after growing $xsml"
6344
6345         rm -f $file
6346 }
6347
6348 test_102h() { # bug 15777
6349         grow_xattr 1024
6350 }
6351 run_test 102h "grow xattr from inside inode to external block"
6352
6353 test_102ha() {
6354         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6355         grow_xattr $(max_xattr_size)
6356 }
6357 run_test 102ha "grow xattr from inside inode to external inode"
6358
6359 test_102i() { # bug 17038
6360         touch $DIR/$tfile
6361         ln -s $DIR/$tfile $DIR/${tfile}link
6362         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
6363         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"
6364         rm -f $DIR/$tfile $DIR/${tfile}link
6365 }
6366 run_test 102i "lgetxattr test on symbolic link ============"
6367
6368 test_102j() {
6369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6370         TAR=$(find_lustre_tar)
6371         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6372         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6373         setup_test102 "$RUNAS"
6374         test_mkdir -p $DIR/d102j
6375         chown $RUNAS_ID $DIR/d102j
6376         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6377         cd $DIR/d102j/$tdir
6378         compare_stripe_info1 "$RUNAS"
6379 }
6380 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6381
6382 test_102k() {
6383         touch $DIR/$tfile
6384         # b22187 just check that does not crash for regular file.
6385         setfattr -n trusted.lov $DIR/$tfile
6386         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6387         local test_kdir=$DIR/d102k
6388         test_mkdir $test_kdir
6389         local default_size=`$GETSTRIPE -S $test_kdir`
6390         local default_count=`$GETSTRIPE -c $test_kdir`
6391         local default_offset=`$GETSTRIPE -i $test_kdir`
6392         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6393                 error 'dir setstripe failed'
6394         setfattr -n trusted.lov $test_kdir
6395         local stripe_size=`$GETSTRIPE -S $test_kdir`
6396         local stripe_count=`$GETSTRIPE -c $test_kdir`
6397         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6398         [ $stripe_size -eq $default_size ] ||
6399                 error "stripe size $stripe_size != $default_size"
6400         [ $stripe_count -eq $default_count ] ||
6401                 error "stripe count $stripe_count != $default_count"
6402         [ $stripe_offset -eq $default_offset ] ||
6403                 error "stripe offset $stripe_offset != $default_offset"
6404         rm -rf $DIR/$tfile $test_kdir
6405 }
6406 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6407
6408 test_102l() {
6409         # LU-532 trusted. xattr is invisible to non-root
6410         local testfile=$DIR/$tfile
6411
6412         touch $testfile
6413
6414         echo "listxattr as user..."
6415         chown $RUNAS_ID $testfile
6416         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6417             grep -q "trusted" &&
6418                 error "$testfile trusted xattrs are user visible"
6419
6420         return 0;
6421 }
6422 run_test 102l "listxattr size test =================================="
6423
6424 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6425         local path=$DIR/$tfile
6426         touch $path
6427
6428         listxattr_size_check $path || error "listattr_size_check $path failed"
6429 }
6430 run_test 102m "Ensure listxattr fails on small bufffer ========"
6431
6432 cleanup_test102
6433
6434 getxattr() { # getxattr path name
6435         # Return the base64 encoding of the value of xattr name on path.
6436         local path=$1
6437         local name=$2
6438
6439         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6440         # file: $path
6441         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6442         #
6443         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6444
6445         getfattr --absolute-names --encoding=base64 --name=$name $path |
6446                 awk -F= -v name=$name '$1 == name {
6447                         print substr($0, index($0, "=") + 1);
6448         }'
6449 }
6450
6451 test_102n() { # LU-4101 mdt: protect internal xattrs
6452         local file0=$DIR/$tfile.0
6453         local file1=$DIR/$tfile.1
6454         local xattr0=$TMP/$tfile.0
6455         local xattr1=$TMP/$tfile.1
6456         local name
6457         local value
6458
6459         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6460         then
6461                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6462                 return
6463         fi
6464
6465         rm -rf $file0 $file1 $xattr0 $xattr1
6466         touch $file0 $file1
6467
6468         # Get 'before' xattrs of $file1.
6469         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6470
6471         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6472                 # Try to copy xattr from $file0 to $file1.
6473                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6474
6475                 setfattr --name=trusted.$name --value="$value" $file1 ||
6476                         error "setxattr 'trusted.$name' failed"
6477
6478                 # Try to set a garbage xattr.
6479                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6480
6481                 setfattr --name=trusted.$name --value="$value" $file1 ||
6482                         error "setxattr 'trusted.$name' failed"
6483
6484                 # Try to remove the xattr from $file1. We don't care if this
6485                 # appears to succeed or fail, we just don't want there to be
6486                 # any changes or crashes.
6487                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6488         done
6489
6490         # Get 'after' xattrs of file1.
6491         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6492
6493         if ! diff $xattr0 $xattr1; then
6494                 error "before and after xattrs of '$file1' differ"
6495         fi
6496
6497         rm -rf $file0 $file1 $xattr0 $xattr1
6498
6499         return 0
6500 }
6501 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6502
6503 run_acl_subtest()
6504 {
6505     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6506     return $?
6507 }
6508
6509 test_103 () {
6510         [ "$UID" != 0 ] && skip_env "must run as root" && return
6511         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6512                 skip "must have acl enabled" && return
6513         [ -z "$(which setfacl 2>/dev/null)" ] &&
6514                 skip_env "could not find setfacl" && return
6515         $GSS && skip "could not run under gss" && return
6516
6517         declare -a identity_old
6518
6519         for num in $(seq $MDSCOUNT); do
6520                 switch_identity $num true || identity_old[$num]=$?
6521         done
6522
6523         SAVE_UMASK=$(umask)
6524         umask 0022
6525         cd $DIR
6526
6527         echo "performing cp ..."
6528         run_acl_subtest cp || error "run_acl_subtest cp failed"
6529         echo "performing getfacl-noacl..."
6530         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6531         echo "performing misc..."
6532         run_acl_subtest misc || error  "misc test failed"
6533         echo "performing permissions..."
6534         run_acl_subtest permissions || error "permissions failed"
6535         echo "performing setfacl..."
6536         run_acl_subtest setfacl || error  "setfacl test failed"
6537
6538         # inheritance test got from HP
6539         echo "performing inheritance..."
6540         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6541         chmod +x make-tree || error "chmod +x failed"
6542         run_acl_subtest inheritance || error "inheritance test failed"
6543         rm -f make-tree
6544
6545         echo "LU-974 ignore umask when acl is enabled..."
6546         run_acl_subtest 974 || error "LU-974 umask test failed"
6547         if [ $MDSCOUNT -ge 2 ]; then
6548                 run_acl_subtest 974_remote ||
6549                         error "LU-974 umask test failed under remote dir"
6550         fi
6551
6552         echo "LU-2561 newly created file is same size as directory..."
6553         run_acl_subtest 2561 || error "LU-2561 test failed"
6554
6555         cd $SAVE_PWD
6556         umask $SAVE_UMASK
6557
6558         for num in $(seq $MDSCOUNT); do
6559                 if [ "${identity_old[$num]}" = 1 ]; then
6560                         switch_identity $num false || identity_old[$num]=$?
6561                 fi
6562         done
6563 }
6564 run_test 103 "acl test ========================================="
6565
6566 test_104a() {
6567         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6568         touch $DIR/$tfile
6569         lfs df || error "lfs df failed"
6570         lfs df -ih || error "lfs df -ih failed"
6571         lfs df -h $DIR || error "lfs df -h $DIR failed"
6572         lfs df -i $DIR || error "lfs df -i $DIR failed"
6573         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6574         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6575
6576         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6577         lctl --device %$OSC deactivate
6578         lfs df || error "lfs df with deactivated OSC failed"
6579         lctl --device %$OSC activate
6580         # wait the osc back to normal
6581         wait_osc_import_state client ost FULL
6582
6583         lfs df || error "lfs df with reactivated OSC failed"
6584         rm -f $DIR/$tfile
6585 }
6586 run_test 104a "lfs df [-ih] [path] test ========================="
6587
6588 test_104b() {
6589         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6590         [ $RUNAS_ID -eq $UID ] &&
6591                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6592         chmod 666 /dev/obd
6593         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6594                         grep "Permission denied" | wc -l)))
6595         if [ $denied_cnt -ne 0 ]; then
6596                 error "lfs check servers test failed"
6597         fi
6598 }
6599 run_test 104b "$RUNAS lfs check servers test ===================="
6600
6601 test_105a() {
6602         # doesn't work on 2.4 kernels
6603         touch $DIR/$tfile
6604         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6605                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6606         else
6607                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6608         fi
6609         rm -f $DIR/$tfile
6610 }
6611 run_test 105a "flock when mounted without -o flock test ========"
6612
6613 test_105b() {
6614         touch $DIR/$tfile
6615         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6616                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6617         else
6618                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6619         fi
6620         rm -f $DIR/$tfile
6621 }
6622 run_test 105b "fcntl when mounted without -o flock test ========"
6623
6624 test_105c() {
6625         touch $DIR/$tfile
6626         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6627                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6628         else
6629                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6630         fi
6631         rm -f $DIR/$tfile
6632 }
6633 run_test 105c "lockf when mounted without -o flock test ========"
6634
6635 test_105d() { # bug 15924
6636         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6637         test_mkdir -p $DIR/$tdir
6638         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6639                 skip "mount w/o flock enabled" && return
6640         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6641         $LCTL set_param fail_loc=0x80000315
6642         flocks_test 2 $DIR/$tdir
6643 }
6644 run_test 105d "flock race (should not freeze) ========"
6645
6646 test_105e() { # bug 22660 && 22040
6647         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6648                 skip "mount w/o flock enabled" && return
6649         touch $DIR/$tfile
6650         flocks_test 3 $DIR/$tfile
6651 }
6652 run_test 105e "Two conflicting flocks from same process ======="
6653
6654 test_106() { #bug 10921
6655         test_mkdir -p $DIR/$tdir
6656         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6657         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6658 }
6659 run_test 106 "attempt exec of dir followed by chown of that dir"
6660
6661 test_107() {
6662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6663         CDIR=`pwd`
6664         cd $DIR
6665
6666         local file=core
6667         rm -f $file
6668
6669         local save_pattern=$(sysctl -n kernel.core_pattern)
6670         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6671         sysctl -w kernel.core_pattern=$file
6672         sysctl -w kernel.core_uses_pid=0
6673
6674         ulimit -c unlimited
6675         sleep 60 &
6676         SLEEPPID=$!
6677
6678         sleep 1
6679
6680         kill -s 11 $SLEEPPID
6681         wait $SLEEPPID
6682         if [ -e $file ]; then
6683                 size=`stat -c%s $file`
6684                 [ $size -eq 0 ] && error "Fail to create core file $file"
6685         else
6686                 error "Fail to create core file $file"
6687         fi
6688         rm -f $file
6689         sysctl -w kernel.core_pattern=$save_pattern
6690         sysctl -w kernel.core_uses_pid=$save_uses_pid
6691         cd $CDIR
6692 }
6693 run_test 107 "Coredump on SIG"
6694
6695 test_110() {
6696         test_mkdir -p $DIR/$tdir
6697         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6698                 error "mkdir with 255 char failed"
6699         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6700                 error "mkdir with 256 char should fail, but did not"
6701         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
6702                 error "create with 255 char failed"
6703         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
6704                 error "create with 256 char should fail, but did not"
6705
6706         ls -l $DIR/$tdir
6707         rm -rf $DIR/$tdir
6708 }
6709 run_test 110 "filename length checking"
6710
6711 test_115() {
6712         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6713         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6714             cut -c11-20)
6715         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
6716             return
6717         echo "Starting with $OSTIO_pre threads"
6718
6719         NUMTEST=20000
6720         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6721         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
6722         echo "$NUMTEST creates/unlinks"
6723         test_mkdir -p $DIR/$tdir
6724         createmany -o $DIR/$tdir/$tfile $NUMTEST
6725         unlinkmany $DIR/$tdir/$tfile $NUMTEST
6726
6727         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6728             cut -c11-20)
6729
6730         # don't return an error
6731         [ $OSTIO_post == $OSTIO_pre ] && echo \
6732             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
6733             echo "This may be fine, depending on what ran before this test" &&
6734             echo "and how fast this system is." && return
6735
6736         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
6737 }
6738 run_test 115 "verify dynamic thread creation===================="
6739
6740 free_min_max () {
6741         wait_delete_completed
6742         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
6743         echo OST kbytes available: ${AVAIL[@]}
6744         MAXI=0; MAXV=${AVAIL[0]}
6745         MINI=0; MINV=${AVAIL[0]}
6746         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
6747             #echo OST $i: ${AVAIL[i]}kb
6748             if [ ${AVAIL[i]} -gt $MAXV ]; then
6749                 MAXV=${AVAIL[i]}; MAXI=$i
6750             fi
6751             if [ ${AVAIL[i]} -lt $MINV ]; then
6752                 MINV=${AVAIL[i]}; MINI=$i
6753             fi
6754         done
6755         echo Min free space: OST $MINI: $MINV
6756         echo Max free space: OST $MAXI: $MAXV
6757 }
6758
6759 test_116a() { # was previously test_116()
6760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6761         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
6762
6763         echo -n "Free space priority "
6764         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
6765                 head -1
6766         declare -a AVAIL
6767         free_min_max
6768
6769         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
6770         trap simple_cleanup_common EXIT
6771
6772         # Check if we need to generate uneven OSTs
6773         test_mkdir -p $DIR/$tdir/OST${MINI}
6774         local FILL=$(($MINV / 4))
6775         local DIFF=$(($MAXV - $MINV))
6776         local DIFF2=$(($DIFF * 100 / $MINV))
6777
6778         local threshold=$(do_facet $SINGLEMDS \
6779                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -1)
6780         threshold=${threshold%%%}
6781         echo -n "Check for uneven OSTs: "
6782         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
6783
6784         if [ $DIFF2 -gt $threshold ]; then
6785                 echo "ok"
6786                 echo "Don't need to fill OST$MINI"
6787         else
6788                 # generate uneven OSTs. Write 2% over the QOS threshold value
6789                 echo "no"
6790                 DIFF=$(($threshold - $DIFF2 + 2))
6791                 DIFF2=$(( ($MINV * $DIFF)/100 ))
6792                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
6793                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
6794                         error "setstripe failed"
6795                 DIFF=$(($DIFF2 / 2048))
6796                 i=0
6797                 while [ $i -lt $DIFF ]; do
6798                         i=$(($i + 1))
6799                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
6800                                 bs=2M count=1 2>/dev/null
6801                         echo -n .
6802                 done
6803                 echo .
6804                 sync
6805                 sleep_maxage
6806                 free_min_max
6807         fi
6808
6809         DIFF=$(($MAXV - $MINV))
6810         DIFF2=$(($DIFF * 100 / $MINV))
6811         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
6812         if [ $DIFF2 -gt $threshold ]; then
6813                 echo "ok"
6814         else
6815                 echo "failed - QOS mode won't be used"
6816                 skip "QOS imbalance criteria not met"
6817                 simple_cleanup_common
6818                 return
6819         fi
6820
6821         MINI1=$MINI; MINV1=$MINV
6822         MAXI1=$MAXI; MAXV1=$MAXV
6823
6824         # now fill using QOS
6825         $SETSTRIPE -c 1 $DIR/$tdir
6826         FILL=$(($FILL / 200))
6827         if [ $FILL -gt 600 ]; then
6828                 FILL=600
6829         fi
6830         echo "writing $FILL files to QOS-assigned OSTs"
6831         i=0
6832         while [ $i -lt $FILL ]; do
6833                 i=$(($i + 1))
6834                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
6835                         count=1 2>/dev/null
6836                 echo -n .
6837         done
6838         echo "wrote $i 200k files"
6839         sync
6840         sleep_maxage
6841
6842         echo "Note: free space may not be updated, so measurements might be off"
6843         free_min_max
6844         DIFF2=$(($MAXV - $MINV))
6845         echo "free space delta: orig $DIFF final $DIFF2"
6846         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6847         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6848         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
6849         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6850         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
6851         FILL=$(($DIFF2 * 100 / $DIFF - 100))
6852         [ $DIFF -gt 0 ] &&
6853                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
6854
6855         # Figure out which files were written where
6856         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6857                   awk '/'$MINI1': / {print $2; exit}')
6858         echo $UUID
6859         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6860         echo "$MINC files created on smaller OST $MINI1"
6861         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6862                   awk '/'$MAXI1': / {print $2; exit}')
6863         echo $UUID
6864         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6865         echo "$MAXC files created on larger OST $MAXI1"
6866         FILL=$(($MAXC * 100 / $MINC - 100))
6867         [ $MINC -gt 0 ] &&
6868                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
6869         [ $MAXC -gt $MINC ] ||
6870                 error_ignore LU-9 "stripe QOS didn't balance free space"
6871         simple_cleanup_common
6872 }
6873 run_test 116a "stripe QOS: free space balance ==================="
6874
6875 test_116b() { # LU-2093
6876         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6877 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
6878         local old_rr
6879         old_rr=$(do_facet $SINGLEMDS lctl get_param -n lov.*mdtlov*.qos_threshold_rr)
6880         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr 0
6881         mkdir -p $DIR/$tdir
6882         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
6883         createmany -o $DIR/$tdir/f- 20 || error "can't create"
6884         do_facet $SINGLEMDS lctl set_param fail_loc=0
6885         rm -rf $DIR/$tdir
6886         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr $old_rr
6887 }
6888 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
6889
6890 test_117() # bug 10891
6891 {
6892         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6893         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
6894         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
6895         lctl set_param fail_loc=0x21e
6896         > $DIR/$tfile || error "truncate failed"
6897         lctl set_param fail_loc=0
6898         echo "Truncate succeeded."
6899         rm -f $DIR/$tfile
6900 }
6901 run_test 117 "verify osd extend =========="
6902
6903 NO_SLOW_RESENDCOUNT=4
6904 export OLD_RESENDCOUNT=""
6905 set_resend_count () {
6906         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
6907         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
6908         lctl set_param -n $PROC_RESENDCOUNT $1
6909         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
6910 }
6911
6912 # for reduce test_118* time (b=14842)
6913 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
6914
6915 # Reset async IO behavior after error case
6916 reset_async() {
6917         FILE=$DIR/reset_async
6918
6919         # Ensure all OSCs are cleared
6920         $SETSTRIPE -c -1 $FILE
6921         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
6922         sync
6923         rm $FILE
6924 }
6925
6926 test_118a() #bug 11710
6927 {
6928         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6929         reset_async
6930
6931         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6932         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6933         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6934
6935         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6936                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6937                 return 1;
6938         fi
6939         rm -f $DIR/$tfile
6940 }
6941 run_test 118a "verify O_SYNC works =========="
6942
6943 test_118b()
6944 {
6945         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6946         remote_ost_nodsh && skip "remote OST with nodsh" && return
6947
6948         reset_async
6949
6950         #define OBD_FAIL_OST_ENOENT 0x217
6951         set_nodes_failloc "$(osts_nodes)" 0x217
6952         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6953         RC=$?
6954         set_nodes_failloc "$(osts_nodes)" 0
6955         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6956         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6957                     grep -c writeback)
6958
6959         if [[ $RC -eq 0 ]]; then
6960                 error "Must return error due to dropped pages, rc=$RC"
6961                 return 1;
6962         fi
6963
6964         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6965                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6966                 return 1;
6967         fi
6968
6969         echo "Dirty pages not leaked on ENOENT"
6970
6971         # Due to the above error the OSC will issue all RPCs syncronously
6972         # until a subsequent RPC completes successfully without error.
6973         $MULTIOP $DIR/$tfile Ow4096yc
6974         rm -f $DIR/$tfile
6975
6976         return 0
6977 }
6978 run_test 118b "Reclaim dirty pages on fatal error =========="
6979
6980 test_118c()
6981 {
6982         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6983
6984         # for 118c, restore the original resend count, LU-1940
6985         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
6986                                 set_resend_count $OLD_RESENDCOUNT
6987         remote_ost_nodsh && skip "remote OST with nodsh" && return
6988
6989         reset_async
6990
6991         #define OBD_FAIL_OST_EROFS               0x216
6992         set_nodes_failloc "$(osts_nodes)" 0x216
6993
6994         # multiop should block due to fsync until pages are written
6995         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6996         MULTIPID=$!
6997         sleep 1
6998
6999         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7000                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7001         fi
7002
7003         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7004                     grep -c writeback)
7005         if [[ $WRITEBACK -eq 0 ]]; then
7006                 error "No page in writeback, writeback=$WRITEBACK"
7007         fi
7008
7009         set_nodes_failloc "$(osts_nodes)" 0
7010         wait $MULTIPID
7011         RC=$?
7012         if [[ $RC -ne 0 ]]; then
7013                 error "Multiop fsync failed, rc=$RC"
7014         fi
7015
7016         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7017         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7018                     grep -c writeback)
7019         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7020                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7021         fi
7022
7023         rm -f $DIR/$tfile
7024         echo "Dirty pages flushed via fsync on EROFS"
7025         return 0
7026 }
7027 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7028
7029 # continue to use small resend count to reduce test_118* time (b=14842)
7030 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7031
7032 test_118d()
7033 {
7034         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7035         remote_ost_nodsh && skip "remote OST with nodsh" && return
7036
7037         reset_async
7038
7039         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7040         set_nodes_failloc "$(osts_nodes)" 0x214
7041         # multiop should block due to fsync until pages are written
7042         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7043         MULTIPID=$!
7044         sleep 1
7045
7046         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7047                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7048         fi
7049
7050         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7051                     grep -c writeback)
7052         if [[ $WRITEBACK -eq 0 ]]; then
7053                 error "No page in writeback, writeback=$WRITEBACK"
7054         fi
7055
7056         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7057         set_nodes_failloc "$(osts_nodes)" 0
7058
7059         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7060         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7061                     grep -c writeback)
7062         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7063                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7064         fi
7065
7066         rm -f $DIR/$tfile
7067         echo "Dirty pages gaurenteed flushed via fsync"
7068         return 0
7069 }
7070 run_test 118d "Fsync validation inject a delay of the bulk =========="
7071
7072 test_118f() {
7073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7074         reset_async
7075
7076         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7077         lctl set_param fail_loc=0x8000040a
7078
7079         # Should simulate EINVAL error which is fatal
7080         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7081         RC=$?
7082         if [[ $RC -eq 0 ]]; then
7083                 error "Must return error due to dropped pages, rc=$RC"
7084         fi
7085
7086         lctl set_param fail_loc=0x0
7087
7088         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7089         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7090         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7091                     grep -c writeback)
7092         if [[ $LOCKED -ne 0 ]]; then
7093                 error "Locked pages remain in cache, locked=$LOCKED"
7094         fi
7095
7096         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7097                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7098         fi
7099
7100         rm -f $DIR/$tfile
7101         echo "No pages locked after fsync"
7102
7103         reset_async
7104         return 0
7105 }
7106 run_test 118f "Simulate unrecoverable OSC side error =========="
7107
7108 test_118g() {
7109         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7110         reset_async
7111
7112         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7113         lctl set_param fail_loc=0x406
7114
7115         # simulate local -ENOMEM
7116         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7117         RC=$?
7118
7119         lctl set_param fail_loc=0
7120         if [[ $RC -eq 0 ]]; then
7121                 error "Must return error due to dropped pages, rc=$RC"
7122         fi
7123
7124         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7125         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7126         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7127                         grep -c writeback)
7128         if [[ $LOCKED -ne 0 ]]; then
7129                 error "Locked pages remain in cache, locked=$LOCKED"
7130         fi
7131
7132         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7133                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7134         fi
7135
7136         rm -f $DIR/$tfile
7137         echo "No pages locked after fsync"
7138
7139         reset_async
7140         return 0
7141 }
7142 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7143
7144 test_118h() {
7145         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7146         remote_ost_nodsh && skip "remote OST with nodsh" && return
7147
7148         reset_async
7149
7150         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7151         set_nodes_failloc "$(osts_nodes)" 0x20e
7152         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7153         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7154         RC=$?
7155
7156         set_nodes_failloc "$(osts_nodes)" 0
7157         if [[ $RC -eq 0 ]]; then
7158                 error "Must return error due to dropped pages, rc=$RC"
7159         fi
7160
7161         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7162         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7163         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7164                     grep -c writeback)
7165         if [[ $LOCKED -ne 0 ]]; then
7166                 error "Locked pages remain in cache, locked=$LOCKED"
7167         fi
7168
7169         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7170                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7171         fi
7172
7173         rm -f $DIR/$tfile
7174         echo "No pages locked after fsync"
7175
7176         return 0
7177 }
7178 run_test 118h "Verify timeout in handling recoverables errors  =========="
7179
7180 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7181
7182 test_118i() {
7183         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7184         remote_ost_nodsh && skip "remote OST with nodsh" && return
7185
7186         reset_async
7187
7188         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7189         set_nodes_failloc "$(osts_nodes)" 0x20e
7190
7191         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7192         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7193         PID=$!
7194         sleep 5
7195         set_nodes_failloc "$(osts_nodes)" 0
7196
7197         wait $PID
7198         RC=$?
7199         if [[ $RC -ne 0 ]]; then
7200                 error "got error, but should be not, rc=$RC"
7201         fi
7202
7203         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7204         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7205         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7206         if [[ $LOCKED -ne 0 ]]; then
7207                 error "Locked pages remain in cache, locked=$LOCKED"
7208         fi
7209
7210         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7211                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7212         fi
7213
7214         rm -f $DIR/$tfile
7215         echo "No pages locked after fsync"
7216
7217         return 0
7218 }
7219 run_test 118i "Fix error before timeout in recoverable error  =========="
7220
7221 [ "$SLOW" = "no" ] && set_resend_count 4
7222
7223 test_118j() {
7224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7225         remote_ost_nodsh && skip "remote OST with nodsh" && return
7226
7227         reset_async
7228
7229         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7230         set_nodes_failloc "$(osts_nodes)" 0x220
7231
7232         # return -EIO from OST
7233         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7234         RC=$?
7235         set_nodes_failloc "$(osts_nodes)" 0x0
7236         if [[ $RC -eq 0 ]]; then
7237                 error "Must return error due to dropped pages, rc=$RC"
7238         fi
7239
7240         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7241         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7242         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7243         if [[ $LOCKED -ne 0 ]]; then
7244                 error "Locked pages remain in cache, locked=$LOCKED"
7245         fi
7246
7247         # in recoverable error on OST we want resend and stay until it finished
7248         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7249                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7250         fi
7251
7252         rm -f $DIR/$tfile
7253         echo "No pages locked after fsync"
7254
7255         return 0
7256 }
7257 run_test 118j "Simulate unrecoverable OST side error =========="
7258
7259 test_118k()
7260 {
7261         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7262         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7263
7264         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7265         set_nodes_failloc "$(osts_nodes)" 0x20e
7266         test_mkdir -p $DIR/$tdir
7267
7268         for ((i=0;i<10;i++)); do
7269                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7270                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7271                 SLEEPPID=$!
7272                 sleep 0.500s
7273                 kill $SLEEPPID
7274                 wait $SLEEPPID
7275         done
7276
7277         set_nodes_failloc "$(osts_nodes)" 0
7278         rm -rf $DIR/$tdir
7279 }
7280 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7281
7282 test_118l()
7283 {
7284         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7285         # LU-646
7286         test_mkdir -p $DIR/$tdir
7287         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7288         rm -rf $DIR/$tdir
7289 }
7290 run_test 118l "fsync dir ========="
7291
7292 test_118m() # LU-3066
7293 {
7294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7295         test_mkdir -p $DIR/$tdir
7296         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7297         rm -rf $DIR/$tdir
7298 }
7299 run_test 118m "fdatasync dir ========="
7300
7301 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7302
7303 test_119a() # bug 11737
7304 {
7305         BSIZE=$((512 * 1024))
7306         directio write $DIR/$tfile 0 1 $BSIZE
7307         # We ask to read two blocks, which is more than a file size.
7308         # directio will indicate an error when requested and actual
7309         # sizes aren't equeal (a normal situation in this case) and
7310         # print actual read amount.
7311         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7312         if [ "$NOB" != "$BSIZE" ]; then
7313                 error "read $NOB bytes instead of $BSIZE"
7314         fi
7315         rm -f $DIR/$tfile
7316 }
7317 run_test 119a "Short directIO read must return actual read amount"
7318
7319 test_119b() # bug 11737
7320 {
7321         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7322
7323         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7324         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7325         sync
7326         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7327                 error "direct read failed"
7328         rm -f $DIR/$tfile
7329 }
7330 run_test 119b "Sparse directIO read must return actual read amount"
7331
7332 test_119c() # bug 13099
7333 {
7334         BSIZE=1048576
7335         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7336         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7337         rm -f $DIR/$tfile
7338 }
7339 run_test 119c "Testing for direct read hitting hole"
7340
7341 test_119d() # bug 15950
7342 {
7343         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7344         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7345         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7346         BSIZE=1048576
7347         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7348         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7349         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7350         lctl set_param fail_loc=0x40d
7351         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7352         pid_dio=$!
7353         sleep 1
7354         cat $DIR/$tfile > /dev/null &
7355         lctl set_param fail_loc=0
7356         pid_reads=$!
7357         wait $pid_dio
7358         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7359         sleep 2
7360         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7361         error "the read rpcs have not completed in 2s"
7362         rm -f $DIR/$tfile
7363         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7364 }
7365 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7366
7367 test_120a() {
7368         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7369         test_mkdir -p $DIR/$tdir
7370         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7371                skip "no early lock cancel on server" && return 0
7372
7373         lru_resize_disable mdc
7374         lru_resize_disable osc
7375         cancel_lru_locks mdc
7376         # asynchronous object destroy at MDT could cause bl ast to client
7377         cancel_lru_locks osc
7378
7379         stat $DIR/$tdir > /dev/null
7380         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7381         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7382         test_mkdir $DIR/$tdir/d1
7383         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7384         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7385         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7386         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7387         lru_resize_enable mdc
7388         lru_resize_enable osc
7389 }
7390 run_test 120a "Early Lock Cancel: mkdir test"
7391
7392 test_120b() {
7393         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7394         test_mkdir -p $DIR/$tdir
7395         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7396                skip "no early lock cancel on server" && return 0
7397         lru_resize_disable mdc
7398         lru_resize_disable osc
7399         cancel_lru_locks mdc
7400         stat $DIR/$tdir > /dev/null
7401         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7402         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7403         touch $DIR/$tdir/f1
7404         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7405         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7406         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7407         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7408         lru_resize_enable mdc
7409         lru_resize_enable osc
7410 }
7411 run_test 120b "Early Lock Cancel: create test"
7412
7413 test_120c() {
7414         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7415         test_mkdir -p $DIR/$tdir
7416         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7417                skip "no early lock cancel on server" && return 0
7418         lru_resize_disable mdc
7419         lru_resize_disable osc
7420         test_mkdir -p $DIR/$tdir/d1
7421         test_mkdir -p $DIR/$tdir/d2
7422         touch $DIR/$tdir/d1/f1
7423         cancel_lru_locks mdc
7424         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7425         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7426         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7427         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7428         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7429         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7430         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7431         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7432         lru_resize_enable mdc
7433         lru_resize_enable osc
7434 }
7435 run_test 120c "Early Lock Cancel: link test"
7436
7437 test_120d() {
7438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7439         test_mkdir -p $DIR/$tdir
7440         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7441                skip "no early lock cancel on server" && return 0
7442         lru_resize_disable mdc
7443         lru_resize_disable osc
7444         touch $DIR/$tdir
7445         cancel_lru_locks mdc
7446         stat $DIR/$tdir > /dev/null
7447         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7448         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7449         chmod a+x $DIR/$tdir
7450         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7451         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7452         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7453         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7454         lru_resize_enable mdc
7455         lru_resize_enable osc
7456 }
7457 run_test 120d "Early Lock Cancel: setattr test"
7458
7459 test_120e() {
7460         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7461         test_mkdir -p $DIR/$tdir
7462         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7463                skip "no early lock cancel on server" && return 0
7464         lru_resize_disable mdc
7465         lru_resize_disable osc
7466         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7467         cancel_lru_locks mdc
7468         cancel_lru_locks osc
7469         dd if=$DIR/$tdir/f1 of=/dev/null
7470         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7471         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7472               awk '/ldlm_cancel/ {print $2}'`
7473         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7474               awk '/ldlm_bl_callback/ {print $2}'`
7475         unlink $DIR/$tdir/f1
7476         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7477               awk '/ldlm_cancel/ {print $2}'`
7478         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7479               awk '/ldlm_bl_callback/ {print $2}'`
7480         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7481         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7482         lru_resize_enable mdc
7483         lru_resize_enable osc
7484 }
7485 run_test 120e "Early Lock Cancel: unlink test"
7486
7487 test_120f() {
7488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7489         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7490                skip "no early lock cancel on server" && return 0
7491         test_mkdir -p $DIR/$tdir
7492         lru_resize_disable mdc
7493         lru_resize_disable osc
7494         test_mkdir -p $DIR/$tdir/d1
7495         test_mkdir -p $DIR/$tdir/d2
7496         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7497         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7498         cancel_lru_locks mdc
7499         cancel_lru_locks osc
7500         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7501         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7502         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7503         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7504               awk '/ldlm_cancel/ {print $2}'`
7505         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7506               awk '/ldlm_bl_callback/ {print $2}'`
7507         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7508         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7509               awk '/ldlm_cancel/ {print $2}'`
7510         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7511               awk '/ldlm_bl_callback/ {print $2}'`
7512         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7513         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7514         lru_resize_enable mdc
7515         lru_resize_enable osc
7516 }
7517 run_test 120f "Early Lock Cancel: rename test"
7518
7519 test_120g() {
7520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7521         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7522                skip "no early lock cancel on server" && return 0
7523         lru_resize_disable mdc
7524         lru_resize_disable osc
7525         count=10000
7526         echo create $count files
7527         test_mkdir -p $DIR/$tdir
7528         cancel_lru_locks mdc
7529         cancel_lru_locks osc
7530         t0=`date +%s`
7531
7532         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7533               awk '/ldlm_cancel/ {print $2}'`
7534         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7535               awk '/ldlm_bl_callback/ {print $2}'`
7536         createmany -o $DIR/$tdir/f $count
7537         sync
7538         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7539               awk '/ldlm_cancel/ {print $2}'`
7540         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7541               awk '/ldlm_bl_callback/ {print $2}'`
7542         t1=`date +%s`
7543         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7544         echo rm $count files
7545         rm -r $DIR/$tdir
7546         sync
7547         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7548               awk '/ldlm_cancel/ {print $2}'`
7549         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7550               awk '/ldlm_bl_callback/ {print $2}'`
7551         t2=`date +%s`
7552         echo total: $count removes in $((t2-t1))
7553         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7554         sleep 2
7555         # wait for commitment of removal
7556         lru_resize_enable mdc
7557         lru_resize_enable osc
7558 }
7559 run_test 120g "Early Lock Cancel: performance test"
7560
7561 test_121() { #bug #10589
7562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7563         rm -rf $DIR/$tfile
7564         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7565 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7566         lctl set_param fail_loc=0x310
7567         cancel_lru_locks osc > /dev/null
7568         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7569         lctl set_param fail_loc=0
7570         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
7571 }
7572 run_test 121 "read cancel race ========="
7573
7574 test_123a() { # was test 123, statahead(bug 11401)
7575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7576         SLOWOK=0
7577         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7578             log "testing on UP system. Performance may be not as good as expected."
7579                         SLOWOK=1
7580         fi
7581
7582         rm -rf $DIR/$tdir
7583         test_mkdir -p $DIR/$tdir
7584         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
7585         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7586         MULT=10
7587         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7588                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7589
7590                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7591                 lctl set_param -n llite.*.statahead_max 0
7592                 lctl get_param llite.*.statahead_max
7593                 cancel_lru_locks mdc
7594                 cancel_lru_locks osc
7595                 stime=`date +%s`
7596                 time ls -l $DIR/$tdir | wc -l
7597                 etime=`date +%s`
7598                 delta=$((etime - stime))
7599                 log "ls $i files without statahead: $delta sec"
7600                 lctl set_param llite.*.statahead_max=$max
7601
7602                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7603                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7604                 cancel_lru_locks mdc
7605                 cancel_lru_locks osc
7606                 stime=`date +%s`
7607                 time ls -l $DIR/$tdir | wc -l
7608                 etime=`date +%s`
7609                 delta_sa=$((etime - stime))
7610                 log "ls $i files with statahead: $delta_sa sec"
7611                 lctl get_param -n llite.*.statahead_stats
7612                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7613
7614                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
7615                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
7616
7617                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7618                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7619                     lctl set_param -n llite.*.statahead_max 0
7620                     lctl get_param llite.*.statahead_max
7621                     cancel_lru_locks mdc
7622                     cancel_lru_locks osc
7623                     stime=`date +%s`
7624                     time ls -l $DIR/$tdir | wc -l
7625                     etime=`date +%s`
7626                     delta=$((etime - stime))
7627                     log "ls $i files again without statahead: $delta sec"
7628                     lctl set_param llite.*.statahead_max=$max
7629                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7630                         if [  $SLOWOK -eq 0 ]; then
7631                                 error "ls $i files is slower with statahead!"
7632                         else
7633                                 log "ls $i files is slower with statahead!"
7634                         fi
7635                         break
7636                     fi
7637                 fi
7638
7639                 [ $delta -gt 20 ] && break
7640                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7641                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7642         done
7643         log "ls done"
7644
7645         stime=`date +%s`
7646         rm -r $DIR/$tdir
7647         sync
7648         etime=`date +%s`
7649         delta=$((etime - stime))
7650         log "rm -r $DIR/$tdir/: $delta seconds"
7651         log "rm done"
7652         lctl get_param -n llite.*.statahead_stats
7653 }
7654 run_test 123a "verify statahead work"
7655
7656 test_123b () { # statahead(bug 15027)
7657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7658         test_mkdir -p $DIR/$tdir
7659         createmany -o $DIR/$tdir/$tfile-%d 1000
7660
7661         cancel_lru_locks mdc
7662         cancel_lru_locks osc
7663
7664 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
7665         lctl set_param fail_loc=0x80000803
7666         ls -lR $DIR/$tdir > /dev/null
7667         log "ls done"
7668         lctl set_param fail_loc=0x0
7669         lctl get_param -n llite.*.statahead_stats
7670         rm -r $DIR/$tdir
7671         sync
7672
7673 }
7674 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
7675
7676 test_124a() {
7677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7678         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7679                skip "no lru resize on server" && return 0
7680         local NR=2000
7681         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
7682
7683         log "create $NR files at $DIR/$tdir"
7684         createmany -o $DIR/$tdir/f $NR ||
7685                 error "failed to create $NR files in $DIR/$tdir"
7686
7687         cancel_lru_locks mdc
7688         ls -l $DIR/$tdir > /dev/null
7689
7690         local NSDIR=""
7691         local LRU_SIZE=0
7692         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
7693                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
7694                 LRU_SIZE=$(lctl get_param -n $PARAM)
7695                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
7696                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
7697                                                 log "NSDIR=$NSDIR"
7698                         log "NS=$(basename $NSDIR)"
7699                         break
7700                 fi
7701         done
7702
7703         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
7704                 skip "Not enough cached locks created!"
7705                 return 0
7706         fi
7707         log "LRU=$LRU_SIZE"
7708
7709         local SLEEP=30
7710
7711         # We know that lru resize allows one client to hold $LIMIT locks
7712         # for 10h. After that locks begin to be killed by client.
7713         local MAX_HRS=10
7714         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
7715                 log "LIMIT=$LIMIT"
7716
7717         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
7718         # killing locks. Some time was spent for creating locks. This means
7719         # that up to the moment of sleep finish we must have killed some of
7720         # them (10-100 locks). This depends on how fast ther were created.
7721         # Many of them were touched in almost the same moment and thus will
7722         # be killed in groups.
7723         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
7724
7725         # Use $LRU_SIZE_B here to take into account real number of locks
7726         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
7727         local LRU_SIZE_B=$LRU_SIZE
7728         log "LVF=$LVF"
7729         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
7730                 log "OLD_LVF=$OLD_LVF"
7731         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
7732
7733         # Let's make sure that we really have some margin. Client checks
7734         # cached locks every 10 sec.
7735         SLEEP=$((SLEEP+20))
7736         log "Sleep ${SLEEP} sec"
7737         local SEC=0
7738         while ((SEC<$SLEEP)); do
7739                 echo -n "..."
7740                 sleep 5
7741                 SEC=$((SEC+5))
7742                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
7743                 echo -n "$LRU_SIZE"
7744         done
7745         echo ""
7746         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
7747         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
7748
7749         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
7750                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
7751                 unlinkmany $DIR/$tdir/f $NR
7752                 return
7753         }
7754
7755         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
7756         log "unlink $NR files at $DIR/$tdir"
7757         unlinkmany $DIR/$tdir/f $NR
7758 }
7759 run_test 124a "lru resize ======================================="
7760
7761 get_max_pool_limit()
7762 {
7763         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
7764         local max=0
7765         for l in $limit; do
7766                 if test $l -gt $max; then
7767                         max=$l
7768                 fi
7769         done
7770         echo $max
7771 }
7772
7773 test_124b() {
7774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7775         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7776                skip "no lru resize on server" && return 0
7777
7778         LIMIT=`get_max_pool_limit`
7779
7780         NR=$(($(default_lru_size)*20))
7781         if [ $NR -gt $LIMIT ]; then
7782                 log "Limit lock number by $LIMIT locks"
7783                 NR=$LIMIT
7784         fi
7785         lru_resize_disable mdc
7786         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
7787                 error "failed to create $DIR/$tdir/disable_lru_resize"
7788
7789         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
7790         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
7791         cancel_lru_locks mdc
7792         stime=`date +%s`
7793         PID=""
7794         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7795         PID="$PID $!"
7796         sleep 2
7797         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7798         PID="$PID $!"
7799         sleep 2
7800         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7801         PID="$PID $!"
7802         wait $PID
7803         etime=`date +%s`
7804         nolruresize_delta=$((etime-stime))
7805         log "ls -la time: $nolruresize_delta seconds"
7806         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7807         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
7808
7809         lru_resize_enable mdc
7810         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
7811                 error "failed to create $DIR/$tdir/enable_lru_resize"
7812
7813         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
7814         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
7815         cancel_lru_locks mdc
7816         stime=`date +%s`
7817         PID=""
7818         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7819         PID="$PID $!"
7820         sleep 2
7821         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7822         PID="$PID $!"
7823         sleep 2
7824         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7825         PID="$PID $!"
7826         wait $PID
7827         etime=`date +%s`
7828         lruresize_delta=$((etime-stime))
7829         log "ls -la time: $lruresize_delta seconds"
7830         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7831
7832         if [ $lruresize_delta -gt $nolruresize_delta ]; then
7833                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
7834         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
7835                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
7836         else
7837                 log "lru resize performs the same with no lru resize"
7838         fi
7839         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
7840 }
7841 run_test 124b "lru resize (performance test) ======================="
7842
7843 test_125() { # 13358
7844         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7845         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
7846         test_mkdir -p $DIR/d125 || error "mkdir failed"
7847         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
7848         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
7849         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
7850 }
7851 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
7852
7853 test_126() { # bug 12829/13455
7854         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7855         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
7856         $GSS && skip "must run as gss disabled" && return
7857
7858         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
7859         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
7860         rm -f $DIR/$tfile
7861         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
7862 }
7863 run_test 126 "check that the fsgid provided by the client is taken into account"
7864
7865 test_127a() { # bug 15521
7866         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7867         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
7868         $LCTL set_param osc.*.stats=0
7869         FSIZE=$((2048 * 1024))
7870         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7871         cancel_lru_locks osc
7872         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
7873
7874         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
7875         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7876                 echo "got $COUNT $NAME"
7877                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
7878                 eval $NAME=$COUNT || error "Wrong proc format"
7879
7880                 case $NAME in
7881                         read_bytes|write_bytes)
7882                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
7883                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
7884                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
7885                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
7886                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
7887                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
7888                                 error "sumsquare is too small: $SUMSQ"
7889                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
7890                                 error "sumsquare is too big: $SUMSQ"
7891                         ;;
7892                         *) ;;
7893                 esac
7894         done < $DIR/${tfile}.tmp
7895
7896         #check that we actually got some stats
7897         [ "$read_bytes" ] || error "Missing read_bytes stats"
7898         [ "$write_bytes" ] || error "Missing write_bytes stats"
7899         [ "$read_bytes" != 0 ] || error "no read done"
7900         [ "$write_bytes" != 0 ] || error "no write done"
7901 }
7902 run_test 127a "verify the client stats are sane"
7903
7904 test_127b() { # bug LU-333
7905         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7906         $LCTL set_param llite.*.stats=0
7907         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
7908         # perform 2 reads and writes so MAX is different from SUM.
7909         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7910         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7911         cancel_lru_locks osc
7912         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7913         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7914
7915         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
7916         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7917                 echo "got $COUNT $NAME"
7918                 eval $NAME=$COUNT || error "Wrong proc format"
7919
7920         case $NAME in
7921                 read_bytes)
7922                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7923                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7924                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7925                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7926                         ;;
7927                 write_bytes)
7928                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7929                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7930                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7931                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7932                         ;;
7933                         *) ;;
7934                 esac
7935         done < $TMP/${tfile}.tmp
7936
7937         #check that we actually got some stats
7938         [ "$read_bytes" ] || error "Missing read_bytes stats"
7939         [ "$write_bytes" ] || error "Missing write_bytes stats"
7940         [ "$read_bytes" != 0 ] || error "no read done"
7941         [ "$write_bytes" != 0 ] || error "no write done"
7942 }
7943 run_test 127b "verify the llite client stats are sane"
7944
7945 test_128() { # bug 15212
7946         touch $DIR/$tfile
7947         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
7948                 find $DIR/$tfile
7949                 find $DIR/$tfile
7950         EOF
7951
7952         result=$(grep error $TMP/$tfile.log)
7953         rm -f $DIR/$tfile
7954         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
7955 }
7956 run_test 128 "interactive lfs for 2 consecutive find's"
7957
7958 set_dir_limits () {
7959         local mntdev
7960         local canondev
7961         local node
7962
7963         local LDPROC=/proc/fs/ldiskfs
7964         local facets=$(get_facets MDS)
7965
7966         for facet in ${facets//,/ }; do
7967                 canondev=$(ldiskfs_canon \
7968                            *.$(convert_facet2label $facet).mntdev $facet)
7969                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
7970                                                 LDPROC=/sys/fs/ldiskfs
7971                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
7972         done
7973 }
7974
7975 test_129() {
7976         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7977         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
7978                 skip "Only applicable to ldiskfs-based MDTs"
7979                 return
7980         fi
7981         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7982
7983         ENOSPC=28
7984         EFBIG=27
7985
7986         rm -rf $DIR/$tdir
7987         test_mkdir -p $DIR/$tdir
7988
7989         # block size of mds1
7990         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7991         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
7992         local MAX=$((MDSBLOCKSIZE * 3))
7993         set_dir_limits $MAX
7994         local I=$(stat -c%s "$DIR/$tdir")
7995         local J=0
7996         while [ ! $I -gt $MAX ]; do
7997                 $MULTIOP $DIR/$tdir/$J Oc
7998                 rc=$?
7999                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8000                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8001                 #and EFBIG for previous versions
8002                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8003                         set_dir_limits 0
8004                         echo "return code $rc received as expected"
8005                         multiop $DIR/$tdir/$J Oc ||
8006                                 error_exit "multiop failed w/o dir size limit"
8007
8008                         I=$(stat -c%s "$DIR/$tdir")
8009
8010                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8011                                         $(version_code 2.4.51) ]
8012                         then
8013                                 [ $I -eq $MAX ] && return 0
8014                         else
8015                                 [ $I -gt $MAX ] && return 0
8016                         fi
8017                         error_exit "current dir size $I, previous limit $MAX"
8018                 elif [ $rc -ne 0 ]; then
8019                         set_dir_limits 0
8020                         error_exit "return code $rc received instead of expected " \
8021                                    "$EFBIG or $ENOSPC, files in dir $I"
8022                 fi
8023                 J=$((J+1))
8024                 I=$(stat -c%s "$DIR/$tdir")
8025         done
8026
8027         set_dir_limits 0
8028         error "exceeded dir size limit $MAX x $MDSCOUNT $MAX : $I bytes"
8029 }
8030 run_test 129 "test directory size limit ========================"
8031
8032 OLDIFS="$IFS"
8033 cleanup_130() {
8034         trap 0
8035         IFS="$OLDIFS"
8036 }
8037
8038 test_130a() {
8039         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8040         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8041                 return
8042
8043         trap cleanup_130 EXIT RETURN
8044
8045         local fm_file=$DIR/$tfile
8046         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8047         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8048                 error "dd failed for $fm_file"
8049
8050         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8051         filefrag -ves $fm_file
8052         RC=$?
8053         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8054                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8055         [ $RC != 0 ] && error "filefrag $fm_file failed"
8056
8057         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8058                       grep -v "ext:" | grep -v "found")
8059         lun=$($GETSTRIPE -i $fm_file)
8060
8061         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8062         IFS=$'\n'
8063         tot_len=0
8064         for line in $filefrag_op
8065         do
8066                 frag_lun=`echo $line | cut -d: -f5`
8067                 ext_len=`echo $line | cut -d: -f4`
8068                 if (( $frag_lun != $lun )); then
8069                         cleanup_130
8070                         error "FIEMAP on 1-stripe file($fm_file) failed"
8071                         return
8072                 fi
8073                 (( tot_len += ext_len ))
8074         done
8075
8076         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8077                 cleanup_130
8078                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8079                 return
8080         fi
8081
8082         cleanup_130
8083
8084         echo "FIEMAP on single striped file succeeded"
8085 }
8086 run_test 130a "FIEMAP (1-stripe file)"
8087
8088 test_130b() {
8089         [ "$OSTCOUNT" -lt "2" ] &&
8090                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8091
8092         [ "$OSTCOUNT" -ge "10" ] &&
8093                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8094
8095         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8096         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8097                 return
8098
8099         trap cleanup_130 EXIT RETURN
8100
8101         local fm_file=$DIR/$tfile
8102         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8103         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8104                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8105
8106         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8107                 error "dd failed on $fm_file"
8108
8109         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8110         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8111                       grep -v "ext:" | grep -v "found")
8112
8113         last_lun=$(echo $filefrag_op | cut -d: -f5)
8114
8115         IFS=$'\n'
8116         tot_len=0
8117         num_luns=1
8118         for line in $filefrag_op
8119         do
8120                 frag_lun=`echo $line | cut -d: -f5`
8121                 ext_len=`echo $line | cut -d: -f4`
8122                 if (( $frag_lun != $last_lun )); then
8123                         if (( tot_len != 1024 )); then
8124                                 cleanup_130
8125                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8126                                 return
8127                         else
8128                                 (( num_luns += 1 ))
8129                                 tot_len=0
8130                         fi
8131                 fi
8132                 (( tot_len += ext_len ))
8133                 last_lun=$frag_lun
8134         done
8135         if (( num_luns != 2 || tot_len != 1024 )); then
8136                 cleanup_130
8137                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8138                 return
8139         fi
8140
8141         cleanup_130
8142
8143         echo "FIEMAP on 2-stripe file succeeded"
8144 }
8145 run_test 130b "FIEMAP (2-stripe file)"
8146
8147 test_130c() {
8148         [ "$OSTCOUNT" -lt "2" ] &&
8149                 skip_env "skipping FIEMAP on 2-stripe file" && return
8150
8151         [ "$OSTCOUNT" -ge "10" ] &&
8152                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8153
8154         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8155         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8156                 return
8157
8158         trap cleanup_130 EXIT RETURN
8159
8160         local fm_file=$DIR/$tfile
8161         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8162         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8163                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8164
8165         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8166
8167         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8168         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8169
8170         last_lun=`echo $filefrag_op | cut -d: -f5`
8171
8172         IFS=$'\n'
8173         tot_len=0
8174         num_luns=1
8175         for line in $filefrag_op
8176         do
8177                 frag_lun=`echo $line | cut -d: -f5`
8178                 ext_len=`echo $line | cut -d: -f4`
8179                 if (( $frag_lun != $last_lun )); then
8180                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8181                         if (( logical != 512 )); then
8182                                 cleanup_130
8183                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8184                                 return
8185                         fi
8186                         if (( tot_len != 512 )); then
8187                                 cleanup_130
8188                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8189                                 return
8190                         else
8191                                 (( num_luns += 1 ))
8192                                 tot_len=0
8193                         fi
8194                 fi
8195                 (( tot_len += ext_len ))
8196                 last_lun=$frag_lun
8197         done
8198         if (( num_luns != 2 || tot_len != 512 )); then
8199                 cleanup_130
8200                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8201                 return
8202         fi
8203
8204         cleanup_130
8205
8206         echo "FIEMAP on 2-stripe file with hole succeeded"
8207 }
8208 run_test 130c "FIEMAP (2-stripe file with hole)"
8209
8210 test_130d() {
8211         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8212
8213         [ "$OSTCOUNT" -ge "10" ] &&
8214                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8215
8216         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8217         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8218
8219         trap cleanup_130 EXIT RETURN
8220
8221         local fm_file=$DIR/$tfile
8222         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8223         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8224                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8225
8226         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8227         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8228                 error "dd failed on $fm_file"
8229
8230         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8231         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8232                 grep -v "ext:" | grep -v "found"`
8233
8234         last_lun=`echo $filefrag_op | cut -d: -f5`
8235
8236         IFS=$'\n'
8237         tot_len=0
8238         num_luns=1
8239         for line in $filefrag_op
8240         do
8241                 frag_lun=`echo $line | cut -d: -f5`
8242                 ext_len=`echo $line | cut -d: -f4`
8243                 if (( $frag_lun != $last_lun )); then
8244                         if (( tot_len != 1024 )); then
8245                                 cleanup_130
8246                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8247                                 return
8248                         else
8249                                 (( num_luns += 1 ))
8250                                 tot_len=0
8251                         fi
8252                 fi
8253                 (( tot_len += ext_len ))
8254                 last_lun=$frag_lun
8255         done
8256         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8257                 cleanup_130
8258                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8259                 return
8260         fi
8261
8262         cleanup_130
8263
8264         echo "FIEMAP on N-stripe file succeeded"
8265 }
8266 run_test 130d "FIEMAP (N-stripe file)"
8267
8268 test_130e() {
8269         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8270
8271         [ "$OSTCOUNT" -ge "10" ] &&
8272                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8273
8274         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8275         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8276
8277         trap cleanup_130 EXIT RETURN
8278
8279         local fm_file=$DIR/$tfile
8280         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8281         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8282                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8283
8284         NUM_BLKS=512
8285         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8286         for ((i = 0; i < $NUM_BLKS; i++))
8287         do
8288                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8289         done
8290
8291         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8292         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8293
8294         last_lun=`echo $filefrag_op | cut -d: -f5`
8295
8296         IFS=$'\n'
8297         tot_len=0
8298         num_luns=1
8299         for line in $filefrag_op
8300         do
8301                 frag_lun=`echo $line | cut -d: -f5`
8302                 ext_len=`echo $line | cut -d: -f4`
8303                 if (( $frag_lun != $last_lun )); then
8304                         if (( tot_len != $EXPECTED_LEN )); then
8305                                 cleanup_130
8306                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8307                                 return
8308                         else
8309                                 (( num_luns += 1 ))
8310                                 tot_len=0
8311                         fi
8312                 fi
8313                 (( tot_len += ext_len ))
8314                 last_lun=$frag_lun
8315         done
8316         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8317                 cleanup_130
8318                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8319                 return
8320         fi
8321
8322         cleanup_130
8323
8324         echo "FIEMAP with continuation calls succeeded"
8325 }
8326 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8327
8328 # Test for writev/readv
8329 test_131a() {
8330         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8331         error "writev test failed"
8332         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8333         error "readv failed"
8334         rm -f $DIR/$tfile
8335 }
8336 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8337
8338 test_131b() {
8339         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8340         error "append writev test failed"
8341         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8342         error "append writev test failed"
8343         rm -f $DIR/$tfile
8344 }
8345 run_test 131b "test append writev"
8346
8347 test_131c() {
8348         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8349         error "NOT PASS"
8350 }
8351 run_test 131c "test read/write on file w/o objects"
8352
8353 test_131d() {
8354         rwv -f $DIR/$tfile -w -n 1 1572864
8355         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8356         if [ "$NOB" != 1572864 ]; then
8357                 error "Short read filed: read $NOB bytes instead of 1572864"
8358         fi
8359         rm -f $DIR/$tfile
8360 }
8361 run_test 131d "test short read"
8362
8363 test_131e() {
8364         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8365         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8366         error "read hitting hole failed"
8367         rm -f $DIR/$tfile
8368 }
8369 run_test 131e "test read hitting hole"
8370
8371 get_ost_param() {
8372         local token=$1
8373         local gl_sum=0
8374         for node in $(osts_nodes); do
8375                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8376                 [ x$gl = x"" ] && gl=0
8377                 gl_sum=$((gl_sum + gl))
8378         done
8379         echo $gl_sum
8380 }
8381
8382 som_mode_switch() {
8383         local som=$1
8384         local gl1=$2
8385         local gl2=$3
8386
8387         if [ x$som = x"enabled" ]; then
8388                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8389                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8390                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8391         else
8392                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8393                 MOUNTOPT="$MOUNTOPT,som_preview"
8394                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8395         fi
8396
8397         # do remount to make new mount-conf parameters actual
8398         echo remounting...
8399         sync
8400         stopall
8401         setupall
8402 }
8403
8404 test_132() { #1028, SOM
8405         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8406         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8407         local num=$(get_mds_dir $DIR)
8408         local mymds=mds${num}
8409         local MOUNTOPT_SAVE=$MOUNTOPT
8410
8411         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8412         cancel_lru_locks osc
8413
8414         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8415
8416         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8417         stat $DIR/$tfile >/dev/null
8418         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8419         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8420         rm $DIR/$tfile
8421         som_mode_switch $som1 $gl1 $gl2
8422
8423         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8424         cancel_lru_locks osc
8425
8426         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8427         if [ $som1 == $som2 ]; then
8428             error "som is still "$som2
8429             if [ x$som2 = x"enabled" ]; then
8430                 som2="disabled"
8431             else
8432                 som2="enabled"
8433             fi
8434         fi
8435
8436         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8437         stat $DIR/$tfile >/dev/null
8438         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8439         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8440         som_mode_switch $som2 $gl1 $gl2
8441         MOUNTOPT=$MOUNTOPT_SAVE
8442 }
8443 run_test 132 "som avoids glimpse rpc"
8444
8445 check_stats() {
8446         local res
8447         local count
8448         case $1 in
8449         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8450                  ;;
8451         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8452                  ;;
8453         *) error "Wrong argument $1" ;;
8454         esac
8455         echo $res
8456         count=`echo $res | awk '{print $2}'`
8457         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8458         # if the argument $3 is zero, it means any stat increment is ok.
8459         if [ $3 -gt 0 ] ; then
8460                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
8461         fi
8462 }
8463
8464 test_133a() {
8465         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8466         remote_ost_nodsh && skip "remote OST with nodsh" && return
8467         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8468
8469         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8470                 { skip "MDS doesn't support rename stats"; return; }
8471         local testdir=$DIR/${tdir}/stats_testdir
8472         mkdir -p $DIR/${tdir}
8473
8474         # clear stats.
8475         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8476         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8477
8478         # verify mdt stats first.
8479         mkdir ${testdir} || error "mkdir failed"
8480         check_stats $SINGLEMDS "mkdir" 1
8481         touch ${testdir}/${tfile} || "touch failed"
8482         check_stats $SINGLEMDS "open" 1
8483         check_stats $SINGLEMDS "close" 1
8484         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8485         check_stats $SINGLEMDS "mknod" 1
8486         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8487         check_stats $SINGLEMDS "unlink" 1
8488         rm -f ${testdir}/${tfile} || error "file remove failed"
8489         check_stats $SINGLEMDS "unlink" 2
8490
8491         # remove working dir and check mdt stats again.
8492         rmdir ${testdir} || error "rmdir failed"
8493         check_stats $SINGLEMDS "rmdir" 1
8494
8495         local testdir1=$DIR/${tdir}/stats_testdir1
8496         mkdir -p ${testdir}
8497         mkdir -p ${testdir1}
8498         touch ${testdir1}/test1
8499         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8500         check_stats $SINGLEMDS "crossdir_rename" 1
8501
8502         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8503         check_stats $SINGLEMDS "samedir_rename" 1
8504
8505         rm -rf $DIR/${tdir}
8506 }
8507 run_test 133a "Verifying MDT stats ========================================"
8508
8509 test_133b() {
8510         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8511         remote_ost_nodsh && skip "remote OST with nodsh" && return
8512         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8513         local testdir=$DIR/${tdir}/stats_testdir
8514         mkdir -p ${testdir} || error "mkdir failed"
8515         touch ${testdir}/${tfile} || "touch failed"
8516         cancel_lru_locks mdc
8517
8518         # clear stats.
8519         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8520         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8521
8522         # extra mdt stats verification.
8523         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8524         check_stats $SINGLEMDS "setattr" 1
8525         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8526         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8527         then            # LU-1740
8528                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8529                 check_stats $SINGLEMDS "getattr" 1
8530         fi
8531         $LFS df || error "lfs failed"
8532         check_stats $SINGLEMDS "statfs" 1
8533
8534         rm -rf $DIR/${tdir}
8535 }
8536 run_test 133b "Verifying extra MDT stats =================================="
8537
8538 test_133c() {
8539         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8540         remote_ost_nodsh && skip "remote OST with nodsh" && return
8541         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8542         local testdir=$DIR/${tdir}/stats_testdir
8543         test_mkdir -p ${testdir} || error "mkdir failed"
8544
8545         # verify obdfilter stats.
8546         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8547         sync
8548         cancel_lru_locks osc
8549         wait_delete_completed
8550
8551         # clear stats.
8552         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8553         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8554
8555         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8556         sync
8557         cancel_lru_locks osc
8558         check_stats ost "write" 1
8559
8560         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8561         check_stats ost "read" 1
8562
8563         > ${testdir}/${tfile} || error "truncate failed"
8564         check_stats ost "punch" 1
8565
8566         rm -f ${testdir}/${tfile} || error "file remove failed"
8567         wait_delete_completed
8568         check_stats ost "destroy" 1
8569
8570         rm -rf $DIR/${tdir}
8571 }
8572 run_test 133c "Verifying OST stats ========================================"
8573
8574 order_2() {
8575     local value=$1
8576     local orig=$value
8577     local order=1
8578
8579     while [ $value -ge 2 ]; do
8580         order=$((order*2))
8581         value=$((value/2))
8582     done
8583
8584     if [ $orig -gt $order ]; then
8585         order=$((order*2))
8586     fi
8587     echo $order
8588 }
8589
8590 size_in_KMGT() {
8591     local value=$1
8592     local size=('K' 'M' 'G' 'T');
8593     local i=0
8594     local size_string=$value
8595
8596     while [ $value -ge 1024 ]; do
8597         if [ $i -gt 3 ]; then
8598             #T is the biggest unit we get here, if that is bigger,
8599             #just return XXXT
8600             size_string=${value}T
8601             break
8602         fi
8603         value=$((value >> 10))
8604         if [ $value -lt 1024 ]; then
8605             size_string=${value}${size[$i]}
8606             break
8607         fi
8608         i=$((i + 1))
8609     done
8610
8611     echo $size_string
8612 }
8613
8614 get_rename_size() {
8615     local size=$1
8616     local context=${2:-.}
8617     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8618                 grep -A1 $context |
8619                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8620     echo $sample
8621 }
8622
8623 test_133d() {
8624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8625         remote_ost_nodsh && skip "remote OST with nodsh" && return
8626         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8627         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8628         { skip "MDS doesn't support rename stats"; return; }
8629
8630         local testdir1=$DIR/${tdir}/stats_testdir1
8631         local testdir2=$DIR/${tdir}/stats_testdir2
8632
8633         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8634
8635         mkdir -p ${testdir1} || error "mkdir failed"
8636         mkdir -p ${testdir2} || error "mkdir failed"
8637
8638         createmany -o $testdir1/test 512 || error "createmany failed"
8639
8640         # check samedir rename size
8641         mv ${testdir1}/test0 ${testdir1}/test_0
8642
8643         local testdir1_size=$(ls -l $DIR/${tdir} |
8644                 awk '/stats_testdir1/ {print $5}')
8645         local testdir2_size=$(ls -l $DIR/${tdir} |
8646                 awk '/stats_testdir2/ {print $5}')
8647
8648         testdir1_size=$(order_2 $testdir1_size)
8649         testdir2_size=$(order_2 $testdir2_size)
8650
8651         testdir1_size=$(size_in_KMGT $testdir1_size)
8652         testdir2_size=$(size_in_KMGT $testdir2_size)
8653
8654         echo "source rename dir size: ${testdir1_size}"
8655         echo "target rename dir size: ${testdir2_size}"
8656
8657         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
8658         eval $cmd || error "$cmd failed"
8659         local samedir=$($cmd | grep 'same_dir')
8660         local same_sample=$(get_rename_size $testdir1_size)
8661         [ -z "$samedir" ] && error "samedir_rename_size count error"
8662         [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
8663         echo "Check same dir rename stats success"
8664
8665         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8666
8667         # check crossdir rename size
8668         mv ${testdir1}/test_0 ${testdir2}/test_0
8669
8670         testdir1_size=$(ls -l $DIR/${tdir} |
8671                 awk '/stats_testdir1/ {print $5}')
8672         testdir2_size=$(ls -l $DIR/${tdir} |
8673                 awk '/stats_testdir2/ {print $5}')
8674
8675         testdir1_size=$(order_2 $testdir1_size)
8676         testdir2_size=$(order_2 $testdir2_size)
8677
8678         testdir1_size=$(size_in_KMGT $testdir1_size)
8679         testdir2_size=$(size_in_KMGT $testdir2_size)
8680
8681         echo "source rename dir size: ${testdir1_size}"
8682         echo "target rename dir size: ${testdir2_size}"
8683
8684         eval $cmd || error "$cmd failed"
8685         local crossdir=$($cmd | grep 'crossdir')
8686         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
8687         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
8688         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
8689         [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
8690         [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
8691         echo "Check cross dir rename stats success"
8692         rm -rf $DIR/${tdir}
8693 }
8694 run_test 133d "Verifying rename_stats ========================================"
8695
8696 test_133e() {
8697         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8698         local testdir=$DIR/${tdir}/stats_testdir
8699         local ctr f0 f1 bs=32768 count=42 sum
8700
8701         remote_ost_nodsh && skip "remote OST with nodsh" && return
8702         mkdir -p ${testdir} || error "mkdir failed"
8703
8704         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8705
8706         for ctr in {write,read}_bytes; do
8707                 sync
8708                 cancel_lru_locks osc
8709
8710                 do_facet ost1 $LCTL set_param -n \
8711                         "obdfilter.*.exports.clear=clear"
8712
8713                 if [ $ctr = write_bytes ]; then
8714                         f0=/dev/zero
8715                         f1=${testdir}/${tfile}
8716                 else
8717                         f0=${testdir}/${tfile}
8718                         f1=/dev/null
8719                 fi
8720
8721                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
8722                         error "dd failed"
8723                 sync
8724                 cancel_lru_locks osc
8725
8726                 sum=$(do_facet ost1 $LCTL get_param \
8727                                 "obdfilter.*.exports.*.stats" | \
8728                           awk -v ctr=$ctr '\
8729                                 BEGIN { sum = 0 }
8730                                 $1 == ctr { sum += $7 }
8731                                 END { print sum }')
8732
8733                 if ((sum != bs * count)); then
8734                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
8735                 fi
8736         done
8737
8738         rm -rf $DIR/${tdir}
8739 }
8740 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
8741
8742 test_133f() {
8743         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8744         local facet
8745
8746         # First without trusting modes.
8747         find $proc_dirs \
8748                 -exec cat '{}' \; &> /dev/null
8749
8750         # Second verifying readability.
8751         find $proc_dirs \
8752                 -type f \
8753                 -readable \
8754                 -exec cat '{}' \; > /dev/null ||
8755                         error "proc file read failed"
8756
8757         for facet in $SINGLEMDS ost1; do
8758                 do_facet $facet find $proc_dirs \
8759                         -not -name req_history \
8760                         -exec cat '{}' \\\; &> /dev/null
8761
8762             do_facet $facet     find $proc_dirs \
8763                         -not -name req_history \
8764                         -type f \
8765                         -readable \
8766                         -exec cat '{}' \\\; > /dev/null ||
8767                                 error "proc file read failed"
8768         done
8769 }
8770 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
8771
8772 test_140() { #bug-17379
8773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8774         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
8775         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
8776         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
8777
8778         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
8779         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
8780         local i=0
8781         while i=`expr $i + 1`; do
8782                 test_mkdir -p $i || error "Creating dir $i"
8783                 cd $i || error "Changing to $i"
8784                 ln -s ../stat stat || error "Creating stat symlink"
8785                 # Read the symlink until ELOOP present,
8786                 # not LBUGing the system is considered success,
8787                 # we didn't overrun the stack.
8788                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
8789                 [ $ret -ne 0 ] && {
8790                         if [ $ret -eq 40 ]; then
8791                                 break  # -ELOOP
8792                         else
8793                                 error "Open stat symlink"
8794                                 return
8795                         fi
8796                 }
8797         done
8798         i=`expr $i - 1`
8799         echo "The symlink depth = $i"
8800         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
8801                                         error "Invalid symlink depth"
8802
8803         # Test recursive symlink
8804         ln -s symlink_self symlink_self
8805         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
8806         echo "open symlink_self returns $ret"
8807         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
8808 }
8809 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
8810
8811 test_150() {
8812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8813         local TF="$TMP/$tfile"
8814
8815         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8816         cp $TF $DIR/$tfile
8817         cancel_lru_locks osc
8818         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
8819         remount_client $MOUNT
8820         df -P $MOUNT
8821         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
8822
8823         $TRUNCATE $TF 6000
8824         $TRUNCATE $DIR/$tfile 6000
8825         cancel_lru_locks osc
8826         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
8827
8828         echo "12345" >>$TF
8829         echo "12345" >>$DIR/$tfile
8830         cancel_lru_locks osc
8831         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
8832
8833         echo "12345" >>$TF
8834         echo "12345" >>$DIR/$tfile
8835         cancel_lru_locks osc
8836         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
8837
8838         rm -f $TF
8839         true
8840 }
8841 run_test 150 "truncate/append tests"
8842
8843 #LU-2902 roc_hit was not able to read all values from lproc
8844 function roc_hit_init() {
8845         local list=$(comma_list $(osts_nodes))
8846         local dir=$DIR/$tdir-check
8847         local file=$dir/file
8848         local BEFORE
8849         local AFTER
8850         local idx
8851
8852         test_mkdir -p $dir
8853         #use setstripe to do a write to every ost
8854         for i in $(seq 0 $((OSTCOUNT-1))); do
8855                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
8856                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
8857                 idx=$(printf %04x $i)
8858                 BEFORE=$(get_osd_param $list *OST*$idx stats |
8859                     awk '$1 == "cache_access" {sum += $2} END { print sum }')
8860                 if [ -z "$BEFORE" ]; then
8861                         BEFORE=0
8862                 fi
8863
8864                 cancel_lru_locks osc
8865                 cat $file >/dev/null
8866
8867                 AFTER=$(get_osd_param $list *OST*$idx stats |
8868                     awk '$1 == "cache_access" {sum += $2} END { print sum }')
8869
8870                 echo BEFORE:$BEFORE AFTER:$AFTER
8871                 if ! let "AFTER - BEFORE == 4"; then
8872                         rm -rf $dir
8873                         error "roc_hit is not safe to use"
8874                 fi
8875                 rm $file
8876         done
8877
8878         rm -rf $dir
8879 }
8880
8881 function roc_hit() {
8882         local list=$(comma_list $(osts_nodes))
8883         echo $(get_osd_param $list '' stats |
8884                 awk '$1 == "cache_hit" {sum += $2} END { print sum }')
8885 }
8886
8887 function set_cache() {
8888         local on=1
8889
8890         if [ "$2" == "off" ]; then
8891                 on=0;
8892         fi
8893         local list=$(comma_list $(osts_nodes))
8894         set_osd_param $list '' $1_cache_enable $on
8895
8896         cancel_lru_locks osc
8897 }
8898
8899 test_151() {
8900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8901         remote_ost_nodsh && skip "remote OST with nodsh" && return
8902
8903         local CPAGES=3
8904         local list=$(comma_list $(osts_nodes))
8905
8906         # check whether obdfilter is cache capable at all
8907         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
8908                 echo "not cache-capable obdfilter"
8909                 return 0
8910         fi
8911
8912         # check cache is enabled on all obdfilters
8913         if get_osd_param $list '' read_cache_enable | grep 0; then
8914                 echo "oss cache is disabled"
8915                 return 0
8916         fi
8917
8918         set_osd_param $list '' writethrough_cache_enable 1
8919
8920         # check write cache is enabled on all obdfilters
8921         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
8922                 echo "oss write cache is NOT enabled"
8923                 return 0
8924         fi
8925
8926         roc_hit_init
8927
8928         #define OBD_FAIL_OBD_NO_LRU  0x609
8929         do_nodes $list $LCTL set_param fail_loc=0x609
8930
8931         # pages should be in the case right after write
8932         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
8933                 error "dd failed"
8934
8935         local BEFORE=$(roc_hit)
8936         cancel_lru_locks osc
8937         cat $DIR/$tfile >/dev/null
8938         local AFTER=$(roc_hit)
8939
8940         do_nodes $list $LCTL set_param fail_loc=0
8941
8942         if ! let "AFTER - BEFORE == CPAGES"; then
8943                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8944         fi
8945
8946         # the following read invalidates the cache
8947         cancel_lru_locks osc
8948         set_osd_param $list '' read_cache_enable 0
8949         cat $DIR/$tfile >/dev/null
8950
8951         # now data shouldn't be found in the cache
8952         BEFORE=$(roc_hit)
8953         cancel_lru_locks osc
8954         cat $DIR/$tfile >/dev/null
8955         AFTER=$(roc_hit)
8956         if let "AFTER - BEFORE != 0"; then
8957                 error "IN CACHE: before: $BEFORE, after: $AFTER"
8958         fi
8959
8960         set_osd_param $list '' read_cache_enable 1
8961         rm -f $DIR/$tfile
8962 }
8963 run_test 151 "test cache on oss and controls ==============================="
8964
8965 test_152() {
8966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8967         local TF="$TMP/$tfile"
8968
8969         # simulate ENOMEM during write
8970 #define OBD_FAIL_OST_NOMEM      0x226
8971         lctl set_param fail_loc=0x80000226
8972         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8973         cp $TF $DIR/$tfile
8974         sync || error "sync failed"
8975         lctl set_param fail_loc=0
8976
8977         # discard client's cache
8978         cancel_lru_locks osc
8979
8980         # simulate ENOMEM during read
8981         lctl set_param fail_loc=0x80000226
8982         cmp $TF $DIR/$tfile || error "cmp failed"
8983         lctl set_param fail_loc=0
8984
8985         rm -f $TF
8986 }
8987 run_test 152 "test read/write with enomem ============================"
8988
8989 test_153() {
8990         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
8991 }
8992 run_test 153 "test if fdatasync does not crash ======================="
8993
8994 dot_lustre_fid_permission_check() {
8995         local fid=$1
8996         local ffid=$MOUNT/.lustre/fid/$fid
8997         local test_dir=$2
8998
8999         echo "stat fid $fid"
9000         stat $ffid > /dev/null || error "stat $ffid failed."
9001         echo "touch fid $fid"
9002         touch $ffid || error "touch $ffid failed."
9003         echo "write to fid $fid"
9004         cat /etc/hosts > $ffid || error "write $ffid failed."
9005         echo "read fid $fid"
9006         diff /etc/hosts $ffid || error "read $ffid failed."
9007         echo "append write to fid $fid"
9008         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9009         echo "rename fid $fid"
9010         mv $ffid $test_dir/$tfile.1 &&
9011                 error "rename $ffid to $tfile.1 should fail."
9012         touch $test_dir/$tfile.1
9013         mv $test_dir/$tfile.1 $ffid &&
9014                 error "rename $tfile.1 to $ffid should fail."
9015         rm -f $test_dir/$tfile.1
9016         echo "truncate fid $fid"
9017         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9018         echo "link fid $fid"
9019         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9020         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9021                 echo "setfacl fid $fid"
9022                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9023                 echo "getfacl fid $fid"
9024                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9025         fi
9026         echo "unlink fid $fid"
9027         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9028         echo "mknod fid $fid"
9029         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9030
9031         fid=[0xf00000400:0x1:0x0]
9032         ffid=$MOUNT/.lustre/fid/$fid
9033
9034         echo "stat non-exist fid $fid"
9035         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9036         echo "write to non-exist fid $fid"
9037         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9038         echo "link new fid $fid"
9039         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9040
9041         mkdir -p $test_dir/$tdir
9042         touch $test_dir/$tdir/$tfile
9043         fid=$($LFS path2fid $test_dir/$tdir)
9044         rc=$?
9045         [ $rc -ne 0 ] &&
9046                 error "error: could not get fid for $test_dir/$dir/$tfile."
9047
9048         ffid=$MOUNT/.lustre/fid/$fid
9049
9050         echo "ls $fid"
9051         ls $ffid > /dev/null || error "ls $ffid failed."
9052         echo "touch $fid/$tfile.1"
9053         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9054
9055         echo "touch $MOUNT/.lustre/fid/$tfile"
9056         touch $MOUNT/.lustre/fid/$tfile && \
9057                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9058
9059         echo "setxattr to $MOUNT/.lustre/fid"
9060         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9061
9062         echo "listxattr for $MOUNT/.lustre/fid"
9063         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9064
9065         echo "delxattr from $MOUNT/.lustre/fid"
9066         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9067
9068         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9069         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9070                 error "touch invalid fid should fail."
9071
9072         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9073         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9074                 error "touch non-normal fid should fail."
9075
9076         echo "rename $tdir to $MOUNT/.lustre/fid"
9077         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9078                 error "rename to $MOUNT/.lustre/fid should fail."
9079
9080         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9081         then            # LU-3547
9082                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9083                 local new_obf_mode=777
9084
9085                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9086                 chmod $new_obf_mode $DIR/.lustre/fid ||
9087                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9088
9089                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9090                 [ $obf_mode -eq $new_obf_mode ] ||
9091                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9092
9093                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9094                 chmod $old_obf_mode $DIR/.lustre/fid ||
9095                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9096         fi
9097
9098         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9099         fid=$($LFS path2fid $test_dir/$tfile-2)
9100         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9101         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
9102                 error "create lov data thru .lustre should fail."
9103         echo "cp /etc/passwd $test_dir/$tfile-2"
9104         cp /etc/passwd $test_dir/$tfile-2 ||
9105                 error "copy to $test_dir/$tfile-2 failed."
9106         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9107         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9108                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9109
9110         rm -rf $test_dir/tfile.lnk
9111         rm -rf $test_dir/$tfile-2
9112 }
9113
9114 test_154A() {
9115         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9116                 skip "Need MDS version at least 2.4.1" && return
9117
9118         touch $DIR/$tfile
9119         local FID=$($LFS path2fid $DIR/$tfile)
9120         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9121
9122         # check that we get the same pathname back
9123         local FOUND=$($LFS fid2path $MOUNT $FID)
9124         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9125         [ "$FOUND" != "$DIR/$tfile" ] &&
9126                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9127
9128         rm -rf $DIR/$tfile
9129 }
9130 run_test 154A "lfs path2fid and fid2path basic checks"
9131
9132 test_154a() {
9133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9134         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9135                 { skip "Need MDS version at least 2.2.51"; return 0; }
9136
9137         cp /etc/hosts $DIR/$tfile
9138
9139         fid=$($LFS path2fid $DIR/$tfile)
9140         rc=$?
9141         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9142
9143         dot_lustre_fid_permission_check "$fid" $DIR ||
9144                 error "dot lustre permission check $fid failed"
9145
9146         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9147
9148         touch $MOUNT/.lustre/file &&
9149                 error "creation is not allowed under .lustre"
9150
9151         mkdir $MOUNT/.lustre/dir &&
9152                 error "mkdir is not allowed under .lustre"
9153
9154         rm -rf $DIR/$tfile
9155 }
9156 run_test 154a "Open-by-FID"
9157
9158 test_154b() {
9159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9160         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9161                 { skip "Need MDS version at least 2.2.51"; return 0; }
9162
9163         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9164
9165         local remote_dir=$DIR/$tdir/remote_dir
9166         local MDTIDX=1
9167         local rc=0
9168
9169         mkdir -p $DIR/$tdir
9170         $LFS mkdir -i $MDTIDX $remote_dir ||
9171                 error "create remote directory failed"
9172
9173         cp /etc/hosts $remote_dir/$tfile
9174
9175         fid=$($LFS path2fid $remote_dir/$tfile)
9176         rc=$?
9177         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9178
9179         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9180                 error "dot lustre permission check $fid failed"
9181         rm -rf $DIR/$tdir
9182 }
9183 run_test 154b "Open-by-FID for remote directory"
9184
9185 test_154c() {
9186         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9187                 skip "Need MDS version at least 2.4.1" && return
9188
9189         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9190         local FID1=$($LFS path2fid $DIR/$tfile.1)
9191         local FID2=$($LFS path2fid $DIR/$tfile.2)
9192         local FID3=$($LFS path2fid $DIR/$tfile.3)
9193
9194         local N=1
9195         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9196                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9197                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9198                 local want=FID$N
9199                 [ "$FID" = "${!want}" ] ||
9200                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9201                 N=$((N + 1))
9202         done
9203
9204         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9205                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9206                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9207                 N=$((N + 1))
9208         done
9209 }
9210 run_test 154c "lfs path2fid and fid2path multiple arguments"
9211
9212 test_154d() {
9213         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9214                 skip "Need MDS version at least 2.5.53" && return
9215
9216         if remote_mds; then
9217                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9218         else
9219                 nid="0@lo"
9220         fi
9221         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9222         local fd
9223         local cmd
9224
9225         rm -f $DIR/$tfile
9226         touch $DIR/$tfile
9227
9228         fid=$($LFS path2fid $DIR/$tfile)
9229         # Open the file
9230         fd=$(free_fd)
9231         cmd="exec $fd<$DIR/$tfile"
9232         eval $cmd
9233         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9234         echo $fid_list | grep $fid
9235         rc=$?
9236
9237         cmd="exec $fd>/dev/null"
9238         eval $cmd
9239         if [ $rc -ne 0 ]; then
9240                 error "FID $fid not found in open files list $fid_list"
9241         fi
9242 }
9243 run_test 154d "Verify open file fid"
9244
9245 test_155_small_load() {
9246     local temp=$TMP/$tfile
9247     local file=$DIR/$tfile
9248
9249     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9250         error "dd of=$temp bs=6096 count=1 failed"
9251     cp $temp $file
9252     cancel_lru_locks osc
9253     cmp $temp $file || error "$temp $file differ"
9254
9255     $TRUNCATE $temp 6000
9256     $TRUNCATE $file 6000
9257     cmp $temp $file || error "$temp $file differ (truncate1)"
9258
9259     echo "12345" >>$temp
9260     echo "12345" >>$file
9261     cmp $temp $file || error "$temp $file differ (append1)"
9262
9263     echo "12345" >>$temp
9264     echo "12345" >>$file
9265     cmp $temp $file || error "$temp $file differ (append2)"
9266
9267     rm -f $temp $file
9268     true
9269 }
9270
9271 test_155_big_load() {
9272     remote_ost_nodsh && skip "remote OST with nodsh" && return
9273     local temp=$TMP/$tfile
9274     local file=$DIR/$tfile
9275
9276     free_min_max
9277     local cache_size=$(do_facet ost$((MAXI+1)) \
9278         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9279     local large_file_size=$((cache_size * 2))
9280
9281     echo "OSS cache size: $cache_size KB"
9282     echo "Large file size: $large_file_size KB"
9283
9284     [ $MAXV -le $large_file_size ] && \
9285         skip_env "max available OST size needs > $large_file_size KB" && \
9286         return 0
9287
9288     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9289
9290     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9291         error "dd of=$temp bs=$large_file_size count=1k failed"
9292     cp $temp $file
9293     ls -lh $temp $file
9294     cancel_lru_locks osc
9295     cmp $temp $file || error "$temp $file differ"
9296
9297     rm -f $temp $file
9298     true
9299 }
9300
9301 test_155a() {
9302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9303         set_cache read on
9304         set_cache writethrough on
9305         test_155_small_load
9306 }
9307 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9308
9309 test_155b() {
9310         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9311         set_cache read on
9312         set_cache writethrough off
9313         test_155_small_load
9314 }
9315 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9316
9317 test_155c() {
9318         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9319         set_cache read off
9320         set_cache writethrough on
9321         test_155_small_load
9322 }
9323 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9324
9325 test_155d() {
9326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9327         set_cache read off
9328         set_cache writethrough off
9329         test_155_small_load
9330 }
9331 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9332
9333 test_155e() {
9334         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9335         set_cache read on
9336         set_cache writethrough on
9337         test_155_big_load
9338 }
9339 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9340
9341 test_155f() {
9342         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9343         set_cache read on
9344         set_cache writethrough off
9345         test_155_big_load
9346 }
9347 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9348
9349 test_155g() {
9350         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9351         set_cache read off
9352         set_cache writethrough on
9353         test_155_big_load
9354 }
9355 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9356
9357 test_155h() {
9358         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9359         set_cache read off
9360         set_cache writethrough off
9361         test_155_big_load
9362 }
9363 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9364
9365 test_156() {
9366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9367         local CPAGES=3
9368         local BEFORE
9369         local AFTER
9370         local file="$DIR/$tfile"
9371
9372         [ "$(facet_fstype ost1)" = "zfs" ] &&
9373                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9374                 return
9375
9376         roc_hit_init
9377
9378     log "Turn on read and write cache"
9379     set_cache read on
9380     set_cache writethrough on
9381
9382     log "Write data and read it back."
9383     log "Read should be satisfied from the cache."
9384     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9385     BEFORE=`roc_hit`
9386     cancel_lru_locks osc
9387     cat $file >/dev/null
9388     AFTER=`roc_hit`
9389     if ! let "AFTER - BEFORE == CPAGES"; then
9390         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9391     else
9392         log "cache hits:: before: $BEFORE, after: $AFTER"
9393     fi
9394
9395     log "Read again; it should be satisfied from the cache."
9396     BEFORE=$AFTER
9397     cancel_lru_locks osc
9398     cat $file >/dev/null
9399     AFTER=`roc_hit`
9400     if ! let "AFTER - BEFORE == CPAGES"; then
9401         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9402     else
9403         log "cache hits:: before: $BEFORE, after: $AFTER"
9404     fi
9405
9406
9407     log "Turn off the read cache and turn on the write cache"
9408     set_cache read off
9409     set_cache writethrough on
9410
9411     log "Read again; it should be satisfied from the cache."
9412     BEFORE=`roc_hit`
9413     cancel_lru_locks osc
9414     cat $file >/dev/null
9415     AFTER=`roc_hit`
9416     if ! let "AFTER - BEFORE == CPAGES"; then
9417         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9418     else
9419         log "cache hits:: before: $BEFORE, after: $AFTER"
9420     fi
9421
9422     log "Read again; it should not be satisfied from the cache."
9423     BEFORE=$AFTER
9424     cancel_lru_locks osc
9425     cat $file >/dev/null
9426     AFTER=`roc_hit`
9427     if ! let "AFTER - BEFORE == 0"; then
9428         error "IN CACHE: before: $BEFORE, after: $AFTER"
9429     else
9430         log "cache hits:: before: $BEFORE, after: $AFTER"
9431     fi
9432
9433     log "Write data and read it back."
9434     log "Read should be satisfied from the cache."
9435     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9436     BEFORE=`roc_hit`
9437     cancel_lru_locks osc
9438     cat $file >/dev/null
9439     AFTER=`roc_hit`
9440     if ! let "AFTER - BEFORE == CPAGES"; then
9441         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9442     else
9443         log "cache hits:: before: $BEFORE, after: $AFTER"
9444     fi
9445
9446     log "Read again; it should not be satisfied from the cache."
9447     BEFORE=$AFTER
9448     cancel_lru_locks osc
9449     cat $file >/dev/null
9450     AFTER=`roc_hit`
9451     if ! let "AFTER - BEFORE == 0"; then
9452         error "IN CACHE: before: $BEFORE, after: $AFTER"
9453     else
9454         log "cache hits:: before: $BEFORE, after: $AFTER"
9455     fi
9456
9457
9458     log "Turn off read and write cache"
9459     set_cache read off
9460     set_cache writethrough off
9461
9462     log "Write data and read it back"
9463     log "It should not be satisfied from the cache."
9464     rm -f $file
9465     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9466     cancel_lru_locks osc
9467     BEFORE=`roc_hit`
9468     cat $file >/dev/null
9469     AFTER=`roc_hit`
9470         if ! let "AFTER - BEFORE == 0"; then
9471                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9472         else
9473                 log "cache hits:: before: $BEFORE, after: $AFTER"
9474         fi
9475
9476     log "Turn on the read cache and turn off the write cache"
9477     set_cache read on
9478     set_cache writethrough off
9479
9480     log "Write data and read it back"
9481     log "It should not be satisfied from the cache."
9482     rm -f $file
9483     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9484     BEFORE=`roc_hit`
9485     cancel_lru_locks osc
9486     cat $file >/dev/null
9487     AFTER=`roc_hit`
9488         if ! let "AFTER - BEFORE == 0"; then
9489                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9490         else
9491                 log "cache hits:: before: $BEFORE, after: $AFTER"
9492         fi
9493
9494     log "Read again; it should be satisfied from the cache."
9495     BEFORE=`roc_hit`
9496     cancel_lru_locks osc
9497     cat $file >/dev/null
9498     AFTER=`roc_hit`
9499     if ! let "AFTER - BEFORE == CPAGES"; then
9500         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9501     else
9502         log "cache hits:: before: $BEFORE, after: $AFTER"
9503     fi
9504
9505     rm -f $file
9506 }
9507 run_test 156 "Verification of tunables ============================"
9508
9509 #Changelogs
9510 err17935 () {
9511         if [ $MDSCOUNT -gt 1 ]; then
9512                 error_ignore bz17935 $*
9513         else
9514                 error $*
9515         fi
9516 }
9517
9518 changelog_chmask()
9519 {
9520         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
9521
9522         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
9523
9524         if [ $MASK -eq 1 ]; then
9525                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
9526         else
9527                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
9528         fi
9529 }
9530
9531 changelog_extract_field() {
9532         local mdt=$1
9533         local cltype=$2
9534         local file=$3
9535         local identifier=$4
9536
9537         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
9538                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
9539                 tail -1
9540 }
9541
9542 test_160a() {
9543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9544         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9545         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9546                 { skip "Need MDS version at least 2.2.0"; return; }
9547
9548         local CL_USERS="mdd.$MDT0.changelog_users"
9549         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9550         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9551         echo "Registered as changelog user $USER"
9552         $GET_CL_USERS | grep -q $USER ||
9553                 error "User $USER not found in changelog_users"
9554
9555         # change something
9556         test_mkdir -p $DIR/$tdir/pics/2008/zachy
9557         touch $DIR/$tdir/pics/2008/zachy/timestamp
9558         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9559         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9560         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9561         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9562         rm $DIR/$tdir/pics/desktop.jpg
9563
9564         $LFS changelog $MDT0 | tail -5
9565
9566         echo "verifying changelog mask"
9567         changelog_chmask "MKDIR"
9568         changelog_chmask "CLOSE"
9569
9570         test_mkdir -p $DIR/$tdir/pics/zach/sofia
9571         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9572
9573         changelog_chmask "MKDIR"
9574         changelog_chmask "CLOSE"
9575
9576         test_mkdir -p $DIR/$tdir/pics/2008/sofia
9577         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9578
9579         $LFS changelog $MDT0
9580         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9581         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9582         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9583         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9584
9585         # verify contents
9586         echo "verifying target fid"
9587         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
9588         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9589         [ "$fidc" == "$fidf" ] ||
9590                 err17935 "fid in changelog $fidc != file fid $fidf"
9591         echo "verifying parent fid"
9592         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
9593         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9594         [ "$fidc" == "$fidf" ] ||
9595                 err17935 "pfid in changelog $fidc != dir fid $fidf"
9596
9597         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9598         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9599         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9600         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9601         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
9602                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
9603
9604         MIN_REC=$($GET_CL_USERS |
9605                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
9606         FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
9607         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9608         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
9609                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
9610
9611         # LU-3446 changelog index reset on MDT restart
9612         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9613         CUR_REC1=$($GET_CL_USERS | head -1 | cut -f3 -d' ')
9614         $LFS changelog_clear $MDT0 $USER 0
9615         stop $SINGLEMDS || error "Fail to stop MDT."
9616         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
9617         CUR_REC2=$($GET_CL_USERS | head -1 | cut -f3 -d' ')
9618         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
9619         [ $CUR_REC1 == $CUR_REC2 ] ||
9620                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
9621
9622         echo "verifying user deregister"
9623         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9624         $GET_CL_USERS | grep -q $USER &&
9625                 error "User $USER still in changelog_users"
9626
9627         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
9628         if [ $USERS -eq 0 ]; then
9629                 LAST_REC1=$($GET_CL_USERS | head -1 | cut -f3 -d' ')
9630                 touch $DIR/$tdir/chloe
9631                 LAST_REC2=$($GET_CL_USERS | head -1 | cut -f3 -d' ')
9632                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
9633                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
9634         else
9635                 echo "$USERS other changelog users; can't verify off"
9636         fi
9637 }
9638 run_test 160a "changelog sanity"
9639
9640 test_160b() { # LU-3587
9641         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9642         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9643         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9644                 { skip "Need MDS version at least 2.2.0"; return; }
9645
9646         local CL_USERS="mdd.$MDT0.changelog_users"
9647         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9648         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9649         echo "Registered as changelog user $USER"
9650         $GET_CL_USERS | grep -q $USER ||
9651                 error "User $USER not found in changelog_users"
9652
9653         local LONGNAME1=$(str_repeat a 255)
9654         local LONGNAME2=$(str_repeat b 255)
9655
9656         cd $DIR
9657         echo "creating very long named file"
9658         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
9659         echo "moving very long named file"
9660         mv $LONGNAME1 $LONGNAME2
9661
9662         $LFS changelog $MDT0 | grep RENME
9663
9664         echo "deregistering $USER"
9665         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9666
9667         rm -f $LONGNAME2
9668 }
9669 run_test 160b "Verify that very long rename doesn't crash in changelog"
9670
9671 test_161a() {
9672         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9673     test_mkdir -p $DIR/$tdir
9674     cp /etc/hosts $DIR/$tdir/$tfile
9675     test_mkdir $DIR/$tdir/foo1
9676     test_mkdir $DIR/$tdir/foo2
9677     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
9678     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
9679     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
9680     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
9681         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
9682         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9683                 $LFS fid2path $DIR $FID
9684                 err17935 "bad link ea"
9685         fi
9686     # middle
9687     rm $DIR/$tdir/foo2/zachary
9688     # last
9689     rm $DIR/$tdir/foo2/thor
9690     # first
9691     rm $DIR/$tdir/$tfile
9692     # rename
9693     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
9694     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
9695         then
9696         $LFS fid2path $DIR $FID
9697         err17935 "bad link rename"
9698     fi
9699     rm $DIR/$tdir/foo2/maggie
9700
9701     # overflow the EA
9702     local longname=filename_avg_len_is_thirty_two_
9703     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
9704         error "failed to hardlink many files"
9705     links=$($LFS fid2path $DIR $FID | wc -l)
9706     echo -n "${links}/1000 links in link EA"
9707     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9708     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
9709         error "failed to unlink many hardlinks"
9710 }
9711 run_test 161a "link ea sanity"
9712
9713 test_161b() {
9714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9715         [ $MDSCOUNT -lt 2 ] &&
9716                 skip "skipping remote directory test" && return
9717         local MDTIDX=1
9718         local remote_dir=$DIR/$tdir/remote_dir
9719
9720         mkdir -p $DIR/$tdir
9721         $LFS mkdir -i $MDTIDX $remote_dir ||
9722                 error "create remote directory failed"
9723
9724         cp /etc/hosts $remote_dir/$tfile
9725         mkdir -p $remote_dir/foo1
9726         mkdir -p $remote_dir/foo2
9727         ln $remote_dir/$tfile $remote_dir/foo1/sofia
9728         ln $remote_dir/$tfile $remote_dir/foo2/zachary
9729         ln $remote_dir/$tfile $remote_dir/foo1/luna
9730         ln $remote_dir/$tfile $remote_dir/foo2/thor
9731
9732         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
9733                      tr -d ']')
9734         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9735                 $LFS fid2path $DIR $FID
9736                 err17935 "bad link ea"
9737         fi
9738         # middle
9739         rm $remote_dir/foo2/zachary
9740         # last
9741         rm $remote_dir/foo2/thor
9742         # first
9743         rm $remote_dir/$tfile
9744         # rename
9745         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
9746         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
9747         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
9748                 $LFS fid2path $DIR $FID
9749                 err17935 "bad link rename"
9750         fi
9751         rm $remote_dir/foo2/maggie
9752
9753         # overflow the EA
9754         local longname=filename_avg_len_is_thirty_two_
9755         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
9756                 error "failed to hardlink many files"
9757         links=$($LFS fid2path $DIR $FID | wc -l)
9758         echo -n "${links}/1000 links in link EA"
9759         [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9760         unlinkmany $remote_dir/foo2/$longname 1000 ||
9761         error "failed to unlink many hardlinks"
9762 }
9763 run_test 161b "link ea sanity under remote directory"
9764
9765 test_161c() {
9766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9767         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
9768                 skip "Need MDS version at least 2.1.5" && return
9769
9770         # define CLF_RENAME_LAST 0x0001
9771         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
9772         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9773                 changelog_register -n)
9774         rm -rf $DIR/$tdir
9775         mkdir -p $DIR/$tdir
9776         touch $DIR/$tdir/foo_161c
9777         touch $DIR/$tdir/bar_161c
9778         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9779         $LFS changelog $MDT0 | grep RENME
9780         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
9781                 cut -f5 -d' ')
9782         $LFS changelog_clear $MDT0 $USER 0
9783         if [ x$flags != "x0x1" ]; then
9784                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9785                         $USER
9786                 error "flag $flags is not 0x1"
9787         fi
9788         echo "rename overwrite a target having nlink = 1," \
9789                 "changelog record has flags of $flags"
9790
9791         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
9792         touch $DIR/$tdir/foo_161c
9793         touch $DIR/$tdir/bar_161c
9794         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
9795         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9796         $LFS changelog $MDT0 | grep RENME
9797         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9798         $LFS changelog_clear $MDT0 $USER 0
9799         if [ x$flags != "x0x0" ]; then
9800                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9801                         $USER
9802                 error "flag $flags is not 0x0"
9803         fi
9804         echo "rename overwrite a target having nlink > 1," \
9805                 "changelog record has flags of $flags"
9806
9807         # rename doesn't overwrite a target (changelog flag 0x0)
9808         touch $DIR/$tdir/foo_161c
9809         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
9810         $LFS changelog $MDT0 | grep RENME
9811         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9812         $LFS changelog_clear $MDT0 $USER 0
9813         if [ x$flags != "x0x0" ]; then
9814                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9815                         $USER
9816                 error "flag $flags is not 0x0"
9817         fi
9818         echo "rename doesn't overwrite a target," \
9819                 "changelog record has flags of $flags"
9820
9821         # define CLF_UNLINK_LAST 0x0001
9822         # unlink a file having nlink = 1 (changelog flag 0x1)
9823         rm -f $DIR/$tdir/foo2_161c
9824         $LFS changelog $MDT0 | grep UNLNK
9825         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
9826         $LFS changelog_clear $MDT0 $USER 0
9827         if [ x$flags != "x0x1" ]; then
9828                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9829                         $USER
9830                 error "flag $flags is not 0x1"
9831         fi
9832         echo "unlink a file having nlink = 1," \
9833                 "changelog record has flags of $flags"
9834
9835         # unlink a file having nlink > 1 (changelog flag 0x0)
9836         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
9837         rm -f $DIR/$tdir/foobar_161c
9838         $LFS changelog $MDT0 | grep UNLNK
9839         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
9840         $LFS changelog_clear $MDT0 $USER 0
9841         if [ x$flags != "x0x0" ]; then
9842                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9843                         $USER
9844                 error "flag $flags is not 0x0"
9845         fi
9846         echo "unlink a file having nlink > 1," \
9847                 "changelog record has flags of $flags"
9848         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9849 }
9850 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
9851
9852 check_path() {
9853     local expected=$1
9854     shift
9855     local fid=$2
9856
9857     local path=$(${LFS} fid2path $*)
9858     RC=$?
9859
9860     if [ $RC -ne 0 ]; then
9861         err17935 "path looked up of $expected failed. Error $RC"
9862         return $RC
9863     elif [ "${path}" != "${expected}" ]; then
9864         err17935 "path looked up \"${path}\" instead of \"${expected}\""
9865         return 2
9866     fi
9867     echo "fid $fid resolves to path $path (expected $expected)"
9868 }
9869
9870 test_162() {
9871         # Make changes to filesystem
9872         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9873         test_mkdir -p $DIR/$tdir/d2
9874         touch $DIR/$tdir/d2/$tfile
9875         touch $DIR/$tdir/d2/x1
9876         touch $DIR/$tdir/d2/x2
9877         test_mkdir -p $DIR/$tdir/d2/a/b/c
9878         test_mkdir -p $DIR/$tdir/d2/p/q/r
9879         # regular file
9880         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
9881         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
9882
9883         # softlink
9884         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
9885         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
9886         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
9887
9888         # softlink to wrong file
9889         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
9890         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
9891         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
9892
9893         # hardlink
9894         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
9895         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
9896         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
9897         # fid2path dir/fsname should both work
9898         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
9899         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
9900
9901         # hardlink count: check that there are 2 links
9902         # Doesnt work with CMD yet: 17935
9903         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
9904                 err17935 "expected 2 links"
9905
9906         # hardlink indexing: remove the first link
9907         rm $DIR/$tdir/d2/p/q/r/hlink
9908         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
9909
9910         return 0
9911 }
9912 run_test 162 "path lookup sanity"
9913
9914 test_169() {
9915         # do directio so as not to populate the page cache
9916         log "creating a 10 Mb file"
9917         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
9918         log "starting reads"
9919         dd if=$DIR/$tfile of=/dev/null bs=4096 &
9920         log "truncating the file"
9921         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
9922         log "killing dd"
9923         kill %+ || true # reads might have finished
9924         echo "wait until dd is finished"
9925         wait
9926         log "removing the temporary file"
9927         rm -rf $DIR/$tfile || error "tmp file removal failed"
9928 }
9929 run_test 169 "parallel read and truncate should not deadlock"
9930
9931 test_170() {
9932         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9933         $LCTL clear     # bug 18514
9934         $LCTL debug_daemon start $TMP/${tfile}_log_good
9935         touch $DIR/$tfile
9936         $LCTL debug_daemon stop
9937         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
9938                error "sed failed to read log_good"
9939
9940         $LCTL debug_daemon start $TMP/${tfile}_log_good
9941         rm -rf $DIR/$tfile
9942         $LCTL debug_daemon stop
9943
9944         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
9945                error "lctl df log_bad failed"
9946
9947         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
9948         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
9949
9950         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
9951         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
9952
9953         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
9954                 error "bad_line good_line1 good_line2 are empty"
9955
9956         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
9957         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
9958         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
9959
9960         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
9961         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
9962         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
9963
9964         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
9965                 error "bad_line_new good_line_new are empty"
9966
9967         local expected_good=$((good_line1 + good_line2*2))
9968
9969         rm -f $TMP/${tfile}*
9970         # LU-231, short malformed line may not be counted into bad lines
9971         if [ $bad_line -ne $bad_line_new ] &&
9972                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
9973                 error "expected $bad_line bad lines, but got $bad_line_new"
9974                 return 1
9975         fi
9976
9977         if [ $expected_good -ne $good_line_new ]; then
9978                 error "expected $expected_good good lines, but got $good_line_new"
9979                 return 2
9980         fi
9981         true
9982 }
9983 run_test 170 "test lctl df to handle corrupted log ====================="
9984
9985 test_171() { # bug20592
9986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9987 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
9988         $LCTL set_param fail_loc=0x50e
9989         $LCTL set_param fail_val=3000
9990         multiop_bg_pause $DIR/$tfile O_s || true
9991         local MULTIPID=$!
9992         kill -USR1 $MULTIPID
9993         # cause log dump
9994         sleep 3
9995         wait $MULTIPID
9996         if dmesg | grep "recursive fault"; then
9997                 error "caught a recursive fault"
9998         fi
9999         $LCTL set_param fail_loc=0
10000         true
10001 }
10002 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10003
10004 # it would be good to share it with obdfilter-survey/libecho code
10005 setup_obdecho_osc () {
10006         local rc=0
10007         local ost_nid=$1
10008         local obdfilter_name=$2
10009         echo "Creating new osc for $obdfilter_name on $ost_nid"
10010         # make sure we can find loopback nid
10011         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10012
10013         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10014                            ${obdfilter_name}_osc_UUID || rc=2; }
10015         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10016                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10017         return $rc
10018 }
10019
10020 cleanup_obdecho_osc () {
10021         local obdfilter_name=$1
10022         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10023         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10024         return 0
10025 }
10026
10027 obdecho_test() {
10028         local OBD=$1
10029         local node=$2
10030         local pages=${3:-64}
10031         local rc=0
10032         local id
10033
10034         local count=10
10035         local obd_size=$(get_obd_size $node $OBD)
10036         local page_size=$(get_page_size $node)
10037         if [[ -n "$obd_size" ]]; then
10038                 local new_count=$((obd_size / (pages * page_size / 1024)))
10039                 [[ $new_count -ge $count ]] || count=$new_count
10040         fi
10041
10042         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10043         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10044                            rc=2; }
10045         if [ $rc -eq 0 ]; then
10046             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10047             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10048         fi
10049         echo "New object id is $id"
10050         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10051                            rc=4; }
10052         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10053                            "test_brw $count w v $pages $id" || rc=4; }
10054         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10055                            rc=4; }
10056         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10057                                         "cleanup" || rc=5; }
10058         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10059                                         "detach" || rc=6; }
10060         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10061         return $rc
10062 }
10063
10064 test_180a() {
10065         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10066         remote_ost_nodsh && skip "remote OST with nodsh" && return
10067         local rc=0
10068         local rmmod_local=0
10069
10070         if ! module_loaded obdecho; then
10071             load_module obdecho/obdecho
10072             rmmod_local=1
10073         fi
10074
10075         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10076         local host=$(lctl get_param -n osc.$osc.import |
10077                              awk '/current_connection:/ {print $2}' )
10078         local target=$(lctl get_param -n osc.$osc.import |
10079                              awk '/target:/ {print $2}' )
10080         target=${target%_UUID}
10081
10082         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10083         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10084         [[ -n $target ]] && cleanup_obdecho_osc $target
10085         [ $rmmod_local -eq 1 ] && rmmod obdecho
10086         return $rc
10087 }
10088 run_test 180a "test obdecho on osc"
10089
10090 test_180b() {
10091         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10092         remote_ost_nodsh && skip "remote OST with nodsh" && return
10093         local rc=0
10094         local rmmod_remote=0
10095
10096         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10097                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10098                       "modprobe obdecho; }" && rmmod_remote=1
10099         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10100         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10101         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10102         return $rc
10103 }
10104 run_test 180b "test obdecho directly on obdfilter"
10105
10106 test_180c() { # LU-2598
10107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10108         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10109                 skip "Need MDS version at least 2.4.0" && return
10110
10111         local rc=0
10112         local rmmod_remote=false
10113         local pages=16384 # 64MB bulk I/O RPC size
10114         local target
10115
10116         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10117                 rmmod_remote=true || error "failed to load module obdecho"
10118
10119         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4}'|head -1)
10120         if [[ -n $target ]]; then
10121                 obdecho_test "$target" ost1 "$pages" ||
10122                         rc=${PIPESTATUS[0]}
10123         else
10124                 echo "there is no obdfilter target on ost1"
10125                 rc=2
10126         fi
10127         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10128         return $rc
10129 }
10130 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10131
10132 test_181() { # bug 22177
10133         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10134         # create enough files to index the directory
10135         createmany -o $DIR/$tdir/foobar 4000
10136         # print attributes for debug purpose
10137         lsattr -d .
10138         # open dir
10139         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10140         MULTIPID=$!
10141         # remove the files & current working dir
10142         unlinkmany $DIR/$tdir/foobar 4000
10143         rmdir $DIR/$tdir
10144         kill -USR1 $MULTIPID
10145         wait $MULTIPID
10146         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10147         return 0
10148 }
10149 run_test 181 "Test open-unlinked dir ========================"
10150
10151 test_182() {
10152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10153         # disable MDC RPC lock wouldn't crash client
10154         local fcount=1000
10155         local tcount=4
10156
10157         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10158 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10159         $LCTL set_param fail_loc=0x804
10160
10161         for (( i=0; i < $tcount; i++ )) ; do
10162                 mkdir $DIR/$tdir/$i
10163                 createmany -o $DIR/$tdir/$i/f- $fcount &
10164         done
10165         wait
10166
10167         for (( i=0; i < $tcount; i++ )) ; do
10168                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10169         done
10170         wait
10171
10172         rm -rf $DIR/$tdir
10173
10174         $LCTL set_param fail_loc=0
10175 }
10176 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10177
10178 test_183() { # LU-2275
10179         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10180                 skip "Need MDS version at least 2.3.56" && return
10181
10182         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10183         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10184         echo aaa > $DIR/$tdir/$tfile
10185
10186 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10187         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10188
10189         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10190         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10191
10192         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10193
10194         # Flush negative dentry cache
10195         touch $DIR/$tdir/$tfile
10196
10197         # We are not checking for any leaked references here, they'll
10198         # become evident next time we do cleanup with module unload.
10199         rm -rf $DIR/$tdir
10200 }
10201 run_test 183 "No crash or request leak in case of strange dispositions ========"
10202
10203 # test suite 184 is for LU-2016, LU-2017
10204 test_184a() {
10205         check_swap_layouts_support && return 0
10206
10207         dir0=$DIR/$tdir/$testnum
10208         test_mkdir -p $dir0 || error "creating dir $dir0"
10209         ref1=/etc/passwd
10210         ref2=/etc/group
10211         file1=$dir0/f1
10212         file2=$dir0/f2
10213         $SETSTRIPE -c1 $file1
10214         cp $ref1 $file1
10215         $SETSTRIPE -c2 $file2
10216         cp $ref2 $file2
10217         gen1=$($GETSTRIPE -g $file1)
10218         gen2=$($GETSTRIPE -g $file2)
10219
10220         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10221         gen=$($GETSTRIPE -g $file1)
10222         [[ $gen1 != $gen ]] ||
10223                 "Layout generation on $file1 does not change"
10224         gen=$($GETSTRIPE -g $file2)
10225         [[ $gen2 != $gen ]] ||
10226                 "Layout generation on $file2 does not change"
10227
10228         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10229         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10230 }
10231 run_test 184a "Basic layout swap"
10232
10233 test_184b() {
10234         check_swap_layouts_support && return 0
10235
10236         dir0=$DIR/$tdir/$testnum
10237         mkdir -p $dir0 || error "creating dir $dir0"
10238         file1=$dir0/f1
10239         file2=$dir0/f2
10240         file3=$dir0/f3
10241         dir1=$dir0/d1
10242         dir2=$dir0/d2
10243         mkdir $dir1 $dir2
10244         $SETSTRIPE -c1 $file1
10245         $SETSTRIPE -c2 $file2
10246         $SETSTRIPE -c1 $file3
10247         chown $RUNAS_ID $file3
10248         gen1=$($GETSTRIPE -g $file1)
10249         gen2=$($GETSTRIPE -g $file2)
10250
10251         $LFS swap_layouts $dir1 $dir2 &&
10252                 error "swap of directories layouts should fail"
10253         $LFS swap_layouts $dir1 $file1 &&
10254                 error "swap of directory and file layouts should fail"
10255         $RUNAS $LFS swap_layouts $file1 $file2 &&
10256                 error "swap of file we cannot write should fail"
10257         $LFS swap_layouts $file1 $file3 &&
10258                 error "swap of file with different owner should fail"
10259         /bin/true # to clear error code
10260 }
10261 run_test 184b "Forbidden layout swap (will generate errors)"
10262
10263 test_184c() {
10264         check_swap_layouts_support && return 0
10265
10266         local dir0=$DIR/$tdir/$testnum
10267         mkdir -p $dir0 || error "creating dir $dir0"
10268
10269         local ref1=$dir0/ref1
10270         local ref2=$dir0/ref2
10271         local file1=$dir0/file1
10272         local file2=$dir0/file2
10273         # create a file large enough for the concurent test
10274         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10275         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10276         echo "ref file size: ref1(`stat -c %s $ref1`), ref2(`stat -c %s $ref2`)"
10277
10278         cp $ref2 $file2
10279         dd if=$ref1 of=$file1 bs=16k &
10280         local DD_PID=$!
10281
10282         # Make sure dd starts to copy file
10283         while [ ! -f $file1 ]; do sleep 0.1; done
10284
10285         $LFS swap_layouts $file1 $file2
10286         local rc=$?
10287         wait $DD_PID
10288         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10289         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10290
10291         # how many bytes copied before swapping layout
10292         local copied=`stat -c %s $file2`
10293         local remaining=`stat -c %s $ref1`
10294         remaining=$((remaining - copied))
10295         echo "Copied $copied bytes before swapping layout..."
10296
10297         cmp -n $copied $file1 $ref2 | grep differ &&
10298                 error "Content mismatch [0, $copied) of ref2 and file1"
10299         cmp -n $copied $file2 $ref1 ||
10300                 error "Content mismatch [0, $copied) of ref1 and file2"
10301         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10302                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10303
10304         # clean up
10305         rm -f $ref1 $ref2 $file1 $file2
10306 }
10307 run_test 184c "Concurrent write and layout swap"
10308
10309 test_184d() {
10310         check_swap_layouts_support && return 0
10311
10312         local file1=$DIR/$tdir/$tfile-1
10313         local file2=$DIR/$tdir/$tfile-2
10314         local file3=$DIR/$tdir/$tfile-3
10315         local lovea1
10316         local lovea2
10317
10318         mkdir -p $DIR/$tdir
10319         touch $file1 || error "create $file1 failed"
10320         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10321                 error "create $file2 failed"
10322         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10323                 error "create $file3 failed"
10324         lovea1=$($LFS getstripe $file1 | sed 1d)
10325
10326         $LFS swap_layouts $file2 $file3 ||
10327                 error "swap $file2 $file3 layouts failed"
10328         $LFS swap_layouts $file1 $file2 ||
10329                 error "swap $file1 $file2 layouts failed"
10330
10331         lovea2=$($LFS getstripe $file2 | sed 1d)
10332         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10333
10334         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10335         [ -z $lovea1 ] || error "$file1 shouldn't have lovea"
10336 }
10337 run_test 184d "allow stripeless layouts swap"
10338
10339
10340 test_185() { # LU-2441
10341         # LU-3553 - no volatile file support in old servers
10342         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10343                 { skip "Need MDS version at least 2.3.60"; return 0; }
10344
10345         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10346         touch $DIR/$tdir/spoo
10347         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10348         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10349                 error "cannot create/write a volatile file"
10350         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10351                 error "FID is still valid after close"
10352
10353         multiop_bg_pause $DIR/$tdir vVw4096_c
10354         local multi_pid=$!
10355
10356         local OLD_IFS=$IFS
10357         IFS=":"
10358         local fidv=($fid)
10359         IFS=$OLD_IFS
10360         # assume that the next FID for this client is sequential, since stdout
10361         # is unfortunately eaten by multiop_bg_pause
10362         local n=$((${fidv[1]} + 1))
10363         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10364         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10365                 error "FID is missing before close"
10366         kill -USR1 $multi_pid
10367         # 1 second delay, so if mtime change we will see it
10368         sleep 1
10369         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10370         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10371 }
10372 run_test 185 "Volatile file support"
10373
10374 test_187a() {
10375         local dir0=$DIR/$tdir/$testnum
10376         mkdir -p $dir0 || error "creating dir $dir0"
10377
10378         local file=$dir0/file1
10379         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10380         local dv1=$($LFS data_version $file)
10381         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10382         local dv2=$($LFS data_version $file)
10383         [[ $dv1 != $dv2 ]] ||
10384                 error "data version did not change on write $dv1 == $dv2"
10385
10386         # clean up
10387         rm -f $file1
10388 }
10389 run_test 187a "Test data version change"
10390
10391 test_187b() {
10392         local dir0=$DIR/$tdir/$testnum
10393         mkdir -p $dir0 || error "creating dir $dir0"
10394
10395         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10396         [[ ${DV[0]} != ${DV[1]} ]] ||
10397                 error "data version did not change on write"\
10398                       " ${DV[0]} == ${DV[1]}"
10399
10400         # clean up
10401         rm -f $file1
10402 }
10403 run_test 187b "Test data version change on volatile file"
10404
10405 # OST pools tests
10406 check_file_in_pool()
10407 {
10408         local file=$1
10409         local pool=$2
10410         local tlist="$3"
10411         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
10412         for i in $res
10413         do
10414                 for t in $tlist ; do
10415                         [ "$i" -eq "$t" ] && continue 2
10416                 done
10417
10418                 echo "pool list: $tlist"
10419                 echo "striping: $res"
10420                 error_noexit "$file not allocated in $pool"
10421                 return 1
10422         done
10423         return 0
10424 }
10425
10426 pool_add() {
10427         echo "Creating new pool"
10428         local pool=$1
10429
10430         create_pool $FSNAME.$pool ||
10431                 { error_noexit "No pool created, result code $?"; return 1; }
10432         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
10433                 { error_noexit "$pool not in lfs pool_list"; return 2; }
10434 }
10435
10436 pool_add_targets() {
10437         echo "Adding targets to pool"
10438         local pool=$1
10439         local first=$2
10440         local last=$3
10441         local step=${4:-1}
10442
10443         local list=$(seq $first $step $last)
10444
10445         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10446         do_facet mgs $LCTL pool_add \
10447                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
10448         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
10449                         | sort -u | tr '\n' ' ' " "$t" || { 
10450                 error_noexit "Add to pool failed"
10451                 return 1
10452         }
10453         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
10454         local addcount=$(((last - first) / step + 1))
10455         [ $lfscount -eq $addcount ] || {
10456                 error_noexit "lfs pool_list bad ost count" \
10457                                                 "$lfscount != $addcount"
10458                 return 2
10459         }
10460 }
10461
10462 pool_set_dir() {
10463         local pool=$1
10464         local tdir=$2
10465         echo "Setting pool on directory $tdir"
10466
10467         $SETSTRIPE -c 2 -p $pool $tdir && return 0
10468
10469         error_noexit "Cannot set pool $pool to $tdir"
10470         return 1
10471 }
10472
10473 pool_check_dir() {
10474         local pool=$1
10475         local tdir=$2
10476         echo "Checking pool on directory $tdir"
10477
10478         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
10479         [ "$res" = "$pool" ] && return 0
10480
10481         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10482         return 1
10483 }
10484
10485 pool_dir_rel_path() {
10486         echo "Testing relative path works well"
10487         local pool=$1
10488         local tdir=$2
10489         local root=$3
10490
10491         mkdir -p $root/$tdir/$tdir
10492         cd $root/$tdir
10493         pool_set_dir $pool $tdir          || return 1
10494         pool_set_dir $pool ./$tdir        || return 2
10495         pool_set_dir $pool ../$tdir       || return 3
10496         pool_set_dir $pool ../$tdir/$tdir || return 4
10497         rm -rf $tdir; cd - > /dev/null
10498 }
10499
10500 pool_alloc_files() {
10501         echo "Checking files allocation from directory pool"
10502         local pool=$1
10503         local tdir=$2
10504         local count=$3
10505         local tlist="$4"
10506
10507         local failed=0
10508         for i in $(seq -w 1 $count)
10509         do
10510                 local file=$tdir/file-$i
10511                 touch $file
10512                 check_file_in_pool $file $pool "$tlist" || \
10513                         failed=$((failed + 1))
10514         done
10515         [ "$failed" = 0 ] && return 0
10516
10517         error_noexit "$failed files not allocated in $pool"
10518         return 1
10519 }
10520
10521 pool_create_files() {
10522         echo "Creating files in pool"
10523         local pool=$1
10524         local tdir=$2
10525         local count=$3
10526         local tlist="$4"
10527
10528         mkdir -p $tdir
10529         local failed=0
10530         for i in $(seq -w 1 $count)
10531         do
10532                 local file=$tdir/spoo-$i
10533                 $SETSTRIPE -p $pool $file
10534                 check_file_in_pool $file $pool "$tlist" || \
10535                         failed=$((failed + 1))
10536         done
10537         [ "$failed" = 0 ] && return 0
10538
10539         error_noexit "$failed files not allocated in $pool"
10540         return 1
10541 }
10542
10543 pool_lfs_df() {
10544         echo "Checking 'lfs df' output"
10545         local pool=$1
10546
10547         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10548                         tr '\n' ' ')
10549         local res=$($LFS df --pool $FSNAME.$pool |
10550                         awk '{print $1}' |
10551                         grep "$FSNAME-OST" |
10552                         tr '\n' ' ')
10553         [ "$res" = "$t" ] && return 0
10554
10555         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10556         return 1
10557 }
10558
10559 pool_file_rel_path() {
10560         echo "Creating files in a pool with relative pathname"
10561         local pool=$1
10562         local tdir=$2
10563
10564         mkdir -p $tdir ||
10565                 { error_noexit "unable to create $tdir"; return 1 ; }
10566         local file="/..$tdir/$tfile-1"
10567         $SETSTRIPE -p $pool $file ||
10568                 { error_noexit "unable to create $file" ; return 2 ; }
10569
10570         cd $tdir
10571         $SETSTRIPE -p $pool $tfile-2 || {
10572                 error_noexit "unable to create $tfile-2 in $tdir"
10573                 return 3
10574         }
10575 }
10576
10577 pool_remove_first_target() {
10578         echo "Removing first target from a pool"
10579         local pool=$1
10580
10581         local pname="lov.$FSNAME-*.pools.$pool"
10582         local t=$($LCTL get_param -n $pname | head -1)
10583         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10584         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10585                 error_noexit "$t not removed from $FSNAME.$pool"
10586                 return 1
10587         }
10588 }
10589
10590 pool_remove_all_targets() {
10591         echo "Removing all targets from pool"
10592         local pool=$1
10593         local file=$2
10594         local pname="lov.$FSNAME-*.pools.$pool"
10595         for t in $($LCTL get_param -n $pname | sort -u)
10596         do
10597                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10598         done
10599         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10600                 error_noexit "Pool $FSNAME.$pool cannot be drained"
10601                 return 1
10602         }
10603         # striping on an empty/nonexistant pool should fall back 
10604         # to "pool of everything"
10605         touch $file || {
10606                 error_noexit "failed to use fallback striping for empty pool"
10607                 return 2
10608         }
10609         # setstripe on an empty pool should fail
10610         $SETSTRIPE -p $pool $file 2>/dev/null && {
10611                 error_noexit "expected failure when creating file" \
10612                                                         "with empty pool"
10613                 return 3
10614         }
10615         return 0
10616 }
10617
10618 pool_remove() {
10619         echo "Destroying pool"
10620         local pool=$1
10621         local file=$2
10622
10623         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10624
10625         sleep 2
10626         # striping on an empty/nonexistant pool should fall back 
10627         # to "pool of everything"
10628         touch $file || {
10629                 error_noexit "failed to use fallback striping for missing pool"
10630                 return 1
10631         }
10632         # setstripe on an empty pool should fail
10633         $SETSTRIPE -p $pool $file 2>/dev/null && {
10634                 error_noexit "expected failure when creating file" \
10635                                                         "with missing pool"
10636                 return 2
10637         }
10638
10639         # get param should return err once pool is gone
10640         if wait_update $HOSTNAME "lctl get_param -n \
10641                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10642         then
10643                 remove_pool_from_list $FSNAME.$pool
10644                 return 0
10645         fi
10646         error_noexit "Pool $FSNAME.$pool is not destroyed"
10647         return 3
10648 }
10649
10650 test_200() {
10651         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10652         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
10653
10654         local POOL=${POOL:-cea1}
10655         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
10656         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
10657         # Pool OST targets
10658         local first_ost=0
10659         local last_ost=$(($OSTCOUNT - 1))
10660         local ost_step=2
10661         local ost_list=$(seq $first_ost $ost_step $last_ost)
10662         local ost_range="$first_ost $last_ost $ost_step"
10663         local test_path=$POOL_ROOT/$POOL_DIR_NAME
10664         local file_dir=$POOL_ROOT/file_tst
10665
10666         local rc=0
10667         while : ; do
10668                 # former test_200a test_200b
10669                 pool_add $POOL                          || { rc=$? ; break; }
10670                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
10671                 # former test_200c test_200d
10672                 mkdir -p $test_path
10673                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
10674                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
10675                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
10676                                                         || { rc=$? ; break; }
10677                 # former test_200e test_200f
10678                 local files=$((OSTCOUNT*3))
10679                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
10680                                                         || { rc=$? ; break; }
10681                 pool_create_files $POOL $file_dir $files "$ost_list" \
10682                                                         || { rc=$? ; break; }
10683                 # former test_200g test_200h
10684                 pool_lfs_df $POOL                       || { rc=$? ; break; }
10685                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
10686
10687                 # former test_201a test_201b test_201c
10688                 pool_remove_first_target $POOL          || { rc=$? ; break; }
10689
10690                 local f=$test_path/$tfile
10691                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
10692                 pool_remove $POOL $f                    || { rc=$? ; break; }
10693                 break
10694         done
10695
10696         cleanup_pools
10697         return $rc
10698 }
10699 run_test 200 "OST pools"
10700
10701 # usage: default_attr <count | size | offset>
10702 default_attr() {
10703         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
10704 }
10705
10706 # usage: check_default_stripe_attr
10707 check_default_stripe_attr() {
10708         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
10709         case $1 in
10710         --stripe-count|--count)
10711                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
10712         --stripe-size|--size)
10713                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
10714         --stripe-index|--index)
10715                 EXPECTED=-1;;
10716         *)
10717                 error "unknown getstripe attr '$1'"
10718         esac
10719
10720         [ $ACTUAL != $EXPECTED ] &&
10721                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
10722 }
10723
10724 test_204a() {
10725         test_mkdir -p $DIR/$tdir
10726         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
10727
10728         check_default_stripe_attr --stripe-count
10729         check_default_stripe_attr --stripe-size
10730         check_default_stripe_attr --stripe-index
10731
10732         return 0
10733 }
10734 run_test 204a "Print default stripe attributes ================="
10735
10736 test_204b() {
10737         test_mkdir -p $DIR/$tdir
10738         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10739
10740         check_default_stripe_attr --stripe-size
10741         check_default_stripe_attr --stripe-index
10742
10743         return 0
10744 }
10745 run_test 204b "Print default stripe size and offset  ==========="
10746
10747 test_204c() {
10748         test_mkdir -p $DIR/$tdir
10749         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10750
10751         check_default_stripe_attr --stripe-count
10752         check_default_stripe_attr --stripe-index
10753
10754         return 0
10755 }
10756 run_test 204c "Print default stripe count and offset ==========="
10757
10758 test_204d() {
10759         test_mkdir -p $DIR/$tdir
10760         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10761
10762         check_default_stripe_attr --stripe-count
10763         check_default_stripe_attr --stripe-size
10764
10765         return 0
10766 }
10767 run_test 204d "Print default stripe count and size ============="
10768
10769 test_204e() {
10770         test_mkdir -p $DIR/$tdir
10771         $SETSTRIPE -d $DIR/$tdir
10772
10773         check_default_stripe_attr --stripe-count --raw
10774         check_default_stripe_attr --stripe-size --raw
10775         check_default_stripe_attr --stripe-index --raw
10776
10777         return 0
10778 }
10779 run_test 204e "Print raw stripe attributes ================="
10780
10781 test_204f() {
10782         test_mkdir -p $DIR/$tdir
10783         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10784
10785         check_default_stripe_attr --stripe-size --raw
10786         check_default_stripe_attr --stripe-index --raw
10787
10788         return 0
10789 }
10790 run_test 204f "Print raw stripe size and offset  ==========="
10791
10792 test_204g() {
10793         test_mkdir -p $DIR/$tdir
10794         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10795
10796         check_default_stripe_attr --stripe-count --raw
10797         check_default_stripe_attr --stripe-index --raw
10798
10799         return 0
10800 }
10801 run_test 204g "Print raw stripe count and offset ==========="
10802
10803 test_204h() {
10804         test_mkdir -p $DIR/$tdir
10805         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10806
10807         check_default_stripe_attr --stripe-count --raw
10808         check_default_stripe_attr --stripe-size --raw
10809
10810         return 0
10811 }
10812 run_test 204h "Print raw stripe count and size ============="
10813
10814 # Figure out which job scheduler is being used, if any,
10815 # or use a fake one
10816 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
10817         JOBENV=SLURM_JOB_ID
10818 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
10819         JOBENV=LSB_JOBID
10820 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
10821         JOBENV=PBS_JOBID
10822 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
10823         JOBENV=LOADL_STEP_ID
10824 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
10825         JOBENV=JOB_ID
10826 else
10827         JOBENV=FAKE_JOBID
10828 fi
10829
10830 verify_jobstats() {
10831         local cmd=$1
10832         local target=$2
10833
10834         # clear old jobstats
10835         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
10836         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
10837
10838         # use a new JobID for this test, or we might see an old one
10839         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
10840
10841         JOBVAL=${!JOBENV}
10842         log "Test: $cmd"
10843         log "Using JobID environment variable $JOBENV=$JOBVAL"
10844
10845         if [ $JOBENV = "FAKE_JOBID" ]; then
10846                 FAKE_JOBID=$JOBVAL $cmd
10847         else
10848                 $cmd
10849         fi
10850
10851         if [ "$target" = "mdt" -o "$target" = "both" ]; then
10852                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
10853                 do_facet $FACET lctl get_param mdt.*.job_stats |
10854                         grep $JOBVAL || error "No job stats found on MDT $FACET"
10855         fi
10856         if [ "$target" = "ost" -o "$target" = "both" ]; then
10857                 FACET=ost1
10858                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
10859                         grep $JOBVAL || error "No job stats found on OST $FACET"
10860         fi
10861 }
10862
10863 jobstats_set() {
10864         trap 0
10865         NEW_JOBENV=${1:-$OLD_JOBENV}
10866         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
10867         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
10868 }
10869
10870 test_205() { # Job stats
10871         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10872         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
10873                 skip "Server doesn't support jobstats" && return 0
10874
10875         local cmd
10876         OLD_JOBENV=`$LCTL get_param -n jobid_var`
10877         if [ $OLD_JOBENV != $JOBENV ]; then
10878                 jobstats_set $JOBENV
10879                 trap jobstats_set EXIT
10880         fi
10881
10882         # mkdir
10883         cmd="mkdir $DIR/$tfile"
10884         verify_jobstats "$cmd" "mdt"
10885         # rmdir
10886         cmd="rm -fr $DIR/$tfile"
10887         verify_jobstats "$cmd" "mdt"
10888         # mknod
10889         cmd="mknod $DIR/$tfile c 1 3"
10890         verify_jobstats "$cmd" "mdt"
10891         # unlink
10892         cmd="rm -f $DIR/$tfile"
10893         verify_jobstats "$cmd" "mdt"
10894         # open & close
10895         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
10896         verify_jobstats "$cmd" "mdt"
10897         # setattr
10898         cmd="touch $DIR/$tfile"
10899         verify_jobstats "$cmd" "both"
10900         # write
10901         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
10902         verify_jobstats "$cmd" "ost"
10903         # read
10904         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
10905         verify_jobstats "$cmd" "ost"
10906         # truncate
10907         cmd="$TRUNCATE $DIR/$tfile 0"
10908         verify_jobstats "$cmd" "both"
10909         # rename
10910         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
10911         verify_jobstats "$cmd" "mdt"
10912
10913         # cleanup
10914         rm -f $DIR/jobstats_test_rename
10915
10916         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
10917 }
10918 run_test 205 "Verify job stats"
10919
10920 # LU-1480, LU-1773 and LU-1657
10921 test_206() {
10922         mkdir -p $DIR/$tdir
10923         lfs setstripe -c -1 $DIR/$tdir
10924 #define OBD_FAIL_LOV_INIT 0x1403
10925         $LCTL set_param fail_loc=0xa0001403
10926         $LCTL set_param fail_val=1
10927         touch $DIR/$tdir/$tfile || true
10928 }
10929 run_test 206 "fail lov_init_raid0() doesn't lbug"
10930
10931 test_207a() {
10932         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
10933         local fsz=`stat -c %s $DIR/$tfile`
10934         cancel_lru_locks mdc
10935
10936         # do not return layout in getattr intent
10937 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
10938         $LCTL set_param fail_loc=0x170
10939         local sz=`stat -c %s $DIR/$tfile`
10940
10941         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
10942
10943         rm -rf $DIR/$tfile
10944 }
10945 run_test 207a "can refresh layout at glimpse"
10946
10947 test_207b() {
10948         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
10949         local cksum=`md5sum $DIR/$tfile`
10950         local fsz=`stat -c %s $DIR/$tfile`
10951         cancel_lru_locks mdc
10952         cancel_lru_locks osc
10953
10954         # do not return layout in getattr intent
10955 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
10956         $LCTL set_param fail_loc=0x171
10957
10958         # it will refresh layout after the file is opened but before read issues
10959         echo checksum is "$cksum"
10960         echo "$cksum" |md5sum -c --quiet || error "file differs"
10961
10962         rm -rf $DIR/$tfile
10963 }
10964 run_test 207b "can refresh layout at open"
10965
10966 test_208() {
10967         # FIXME: in this test suite, only RD lease is used. This is okay
10968         # for now as only exclusive open is supported. After generic lease
10969         # is done, this test suite should be revised. - Jinshan
10970
10971         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
10972                 { skip "Need MDS version at least 2.4.52"; return 0; }
10973
10974         echo "==== test 1: verify get lease work"
10975         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
10976
10977         echo "==== test 2: verify lease can be broken by upcoming open"
10978         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
10979         local PID=$!
10980         sleep 1
10981
10982         $MULTIOP $DIR/$tfile oO_RDONLY:c
10983         kill -USR1 $PID && wait $PID || error "break lease error"
10984
10985         echo "==== test 3: verify lease can't be granted if an open already exists"
10986         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
10987         local PID=$!
10988         sleep 1
10989
10990         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
10991         kill -USR1 $PID && wait $PID || error "open file error"
10992
10993         echo "==== test 4: lease can sustain over recovery"
10994         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
10995         PID=$!
10996         sleep 1
10997
10998         fail mds1
10999
11000         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11001
11002         echo "==== test 5: lease broken can't be regained by replay"
11003         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11004         PID=$!
11005         sleep 1
11006
11007         # open file to break lease and then recovery
11008         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11009         fail mds1
11010
11011         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11012
11013         rm -f $DIR/$tfile
11014 }
11015 run_test 208 "Exclusive open"
11016
11017 test_209() {
11018         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11019                 skip_env "must have disp_stripe" && return
11020
11021         touch $DIR/$tfile
11022         sync; sleep 5; sync;
11023
11024         echo 3 > /proc/sys/vm/drop_caches
11025         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11026
11027         # open/close 500 times
11028         for i in $(seq 500); do
11029                 cat $DIR/$tfile
11030         done
11031
11032         echo 3 > /proc/sys/vm/drop_caches
11033         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11034
11035         echo "before: $req_before, after: $req_after"
11036         [ $((req_after - req_before)) -ge 300 ] &&
11037                 error "open/close requests are not freed"
11038         return 0
11039 }
11040 run_test 209 "read-only open/close requests should be freed promptly"
11041
11042 test_212() {
11043         size=`date +%s`
11044         size=$((size % 8192 + 1))
11045         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11046         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11047         rm -f $DIR/f212 $DIR/f212.xyz
11048 }
11049 run_test 212 "Sendfile test ============================================"
11050
11051 test_213() {
11052         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11053         cancel_lru_locks osc
11054         lctl set_param fail_loc=0x8000040f
11055         # generate a read lock
11056         cat $DIR/$tfile > /dev/null
11057         # write to the file, it will try to cancel the above read lock.
11058         cat /etc/hosts >> $DIR/$tfile
11059 }
11060 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11061
11062 test_214() { # for bug 20133
11063         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11064         for (( i=0; i < 340; i++ )) ; do
11065                 touch $DIR/$tdir/d214c/a$i
11066         done
11067
11068         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11069         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11070         ls $DIR/d214c || error "ls $DIR/d214c failed"
11071         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11072         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11073 }
11074 run_test 214 "hash-indexed directory test - bug 20133"
11075
11076 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11077 create_lnet_proc_files() {
11078         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
11079         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11080
11081         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11082         rm -f "$TMP/lnet_$1.sys_tmp"
11083 }
11084
11085 # counterpart of create_lnet_proc_files
11086 remove_lnet_proc_files() {
11087         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11088 }
11089
11090 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11091 # 3rd arg as regexp for body
11092 check_lnet_proc_stats() {
11093         local l=$(cat "$TMP/lnet_$1" |wc -l)
11094         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11095
11096         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11097 }
11098
11099 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11100 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11101 # optional and can be regexp for 2nd line (lnet.routes case)
11102 check_lnet_proc_entry() {
11103         local blp=2            # blp stands for 'position of 1st line of body'
11104         [ "$5" = "" ] || blp=3 # lnet.routes case
11105
11106         local l=$(cat "$TMP/lnet_$1" |wc -l)
11107         # subtracting one from $blp because the body can be empty
11108         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11109
11110         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11111                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11112
11113         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11114                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11115
11116         # bail out if any unexpected line happened
11117         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
11118         [ "$?" != 0 ] || error "$2 misformatted"
11119 }
11120
11121 test_215() { # for bugs 18102, 21079, 21517
11122         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11123         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11124         local P='[1-9][0-9]*'           # positive numeric
11125         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11126         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11127         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11128         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11129
11130         local L1 # regexp for 1st line
11131         local L2 # regexp for 2nd line (optional)
11132         local BR # regexp for the rest (body)
11133
11134         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
11135         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11136         create_lnet_proc_files "stats"
11137         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
11138         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11139         remove_lnet_proc_files "stats"
11140
11141         # /proc/sys/lnet/routes should look like this:
11142         # Routing disabled/enabled
11143         # net hops priority state router
11144         # where net is a string like tcp0, hops > 0, priority >= 0,
11145         # state is up/down,
11146         # router is a string like 192.168.1.1@tcp2
11147         L1="^Routing (disabled|enabled)$"
11148         L2="^net +hops +priority +state +router$"
11149         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11150         create_lnet_proc_files "routes"
11151         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
11152         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11153         remove_lnet_proc_files "routes"
11154
11155         # /proc/sys/lnet/routers should look like this:
11156         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11157         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11158         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11159         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11160         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11161         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11162         create_lnet_proc_files "routers"
11163         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
11164         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11165         remove_lnet_proc_files "routers"
11166
11167         # /proc/sys/lnet/peers should look like this:
11168         # nid refs state last max rtr min tx min queue
11169         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11170         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11171         # numeric (0 or >0 or <0), queue >= 0.
11172         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11173         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11174         create_lnet_proc_files "peers"
11175         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
11176         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11177         remove_lnet_proc_files "peers"
11178
11179         # /proc/sys/lnet/buffers  should look like this:
11180         # pages count credits min
11181         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11182         L1="^pages +count +credits +min$"
11183         BR="^ +$N +$N +$I +$I$"
11184         create_lnet_proc_files "buffers"
11185         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
11186         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11187         remove_lnet_proc_files "buffers"
11188
11189         # /proc/sys/lnet/nis should look like this:
11190         # nid status alive refs peer rtr max tx min
11191         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11192         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11193         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11194         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11195         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11196         create_lnet_proc_files "nis"
11197         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
11198         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11199         remove_lnet_proc_files "nis"
11200
11201         # can we successfully write to /proc/sys/lnet/stats?
11202         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
11203         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11204 }
11205 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
11206
11207 test_216() { # bug 20317
11208         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11209         remote_ost_nodsh && skip "remote OST with nodsh" && return
11210
11211         local node
11212         local facets=$(get_facets OST)
11213         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11214
11215         save_lustre_params client "osc.*.contention_seconds" > $p
11216         save_lustre_params $facets \
11217                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11218         save_lustre_params $facets \
11219                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11220         save_lustre_params $facets \
11221                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11222         clear_osc_stats
11223
11224         # agressive lockless i/o settings
11225         for node in $(osts_nodes); do
11226                 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'
11227         done
11228         lctl set_param -n osc.*.contention_seconds 60
11229
11230         $DIRECTIO write $DIR/$tfile 0 10 4096
11231         $CHECKSTAT -s 40960 $DIR/$tfile
11232
11233         # disable lockless i/o
11234         for node in $(osts_nodes); do
11235                 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'
11236         done
11237         lctl set_param -n osc.*.contention_seconds 0
11238         clear_osc_stats
11239
11240         dd if=/dev/zero of=$DIR/$tfile count=0
11241         $CHECKSTAT -s 0 $DIR/$tfile
11242
11243         restore_lustre_params <$p
11244         rm -f $p
11245         rm $DIR/$tfile
11246 }
11247 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11248
11249 test_217() { # bug 22430
11250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11251         local node
11252         local nid
11253
11254         for node in $(nodes_list); do
11255                 nid=$(host_nids_address $node $NETTYPE)
11256                 if [[ $nid = *-* ]] ; then
11257                         echo "lctl ping $nid@$NETTYPE"
11258                         lctl ping $nid@$NETTYPE
11259                 else
11260                         echo "skipping $node (no hyphen detected)"
11261                 fi
11262         done
11263 }
11264 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11265
11266 test_218() {
11267        # do directio so as not to populate the page cache
11268        log "creating a 10 Mb file"
11269        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11270        log "starting reads"
11271        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11272        log "truncating the file"
11273        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11274        log "killing dd"
11275        kill %+ || true # reads might have finished
11276        echo "wait until dd is finished"
11277        wait
11278        log "removing the temporary file"
11279        rm -rf $DIR/$tfile || error "tmp file removal failed"
11280 }
11281 run_test 218 "parallel read and truncate should not deadlock ======================="
11282
11283 test_219() {
11284         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11285         # write one partial page
11286         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11287         # set no grant so vvp_io_commit_write will do sync write
11288         $LCTL set_param fail_loc=0x411
11289         # write a full page at the end of file
11290         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11291
11292         $LCTL set_param fail_loc=0
11293         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11294         $LCTL set_param fail_loc=0x411
11295         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11296
11297         # LU-4201
11298         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11299         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11300 }
11301 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11302
11303 test_220() { #LU-325
11304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11305         remote_ost_nodsh && skip "remote OST with nodsh" && return
11306         local OSTIDX=0
11307
11308         test_mkdir -p $DIR/$tdir
11309         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11310                 awk '{print $2}' | sed -e 's/_UUID$//')
11311
11312         # on the mdt's osc
11313         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11314         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11315                         osc.$mdtosc_proc1.prealloc_last_id)
11316         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11317                         osc.$mdtosc_proc1.prealloc_next_id)
11318
11319         $LFS df -i
11320
11321         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11322         #define OBD_FAIL_OST_ENOINO              0x229
11323         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11324         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11325         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11326
11327         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11328
11329         MDSOBJS=$((last_id - next_id))
11330         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11331
11332         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11333         echo "OST still has $count kbytes free"
11334
11335         echo "create $MDSOBJS files @next_id..."
11336         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11337
11338         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11339                         osc.$mdtosc_proc1.prealloc_last_id)
11340         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11341                         osc.$mdtosc_proc1.prealloc_next_id)
11342
11343         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11344         $LFS df -i
11345
11346         echo "cleanup..."
11347
11348         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11349         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11350
11351         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11352         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11353         echo "unlink $MDSOBJS files @$next_id..."
11354         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11355 }
11356 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11357
11358 test_221() {
11359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11360         dd if=`which date` of=$MOUNT/date oflag=sync
11361         chmod +x $MOUNT/date
11362
11363         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11364         $LCTL set_param fail_loc=0x80001401
11365
11366         $MOUNT/date > /dev/null
11367         rm -f $MOUNT/date
11368 }
11369 run_test 221 "make sure fault and truncate race to not cause OOM"
11370
11371 test_222a () {
11372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11373        rm -rf $DIR/$tdir
11374        test_mkdir -p $DIR/$tdir
11375        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11376        createmany -o $DIR/$tdir/$tfile 10
11377        cancel_lru_locks mdc
11378        cancel_lru_locks osc
11379        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11380        $LCTL set_param fail_loc=0x31a
11381        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11382        $LCTL set_param fail_loc=0
11383        rm -r $DIR/$tdir
11384 }
11385 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11386
11387 test_222b () {
11388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11389        rm -rf $DIR/$tdir
11390        test_mkdir -p $DIR/$tdir
11391        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11392        createmany -o $DIR/$tdir/$tfile 10
11393        cancel_lru_locks mdc
11394        cancel_lru_locks osc
11395        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11396        $LCTL set_param fail_loc=0x31a
11397        rm -r $DIR/$tdir || "AGL for rmdir failed"
11398        $LCTL set_param fail_loc=0
11399 }
11400 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11401
11402 test_223 () {
11403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11404        rm -rf $DIR/$tdir
11405        test_mkdir -p $DIR/$tdir
11406        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11407        createmany -o $DIR/$tdir/$tfile 10
11408        cancel_lru_locks mdc
11409        cancel_lru_locks osc
11410        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11411        $LCTL set_param fail_loc=0x31b
11412        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11413        $LCTL set_param fail_loc=0
11414        rm -r $DIR/$tdir
11415 }
11416 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11417
11418 test_224a() { # LU-1039, MRP-303
11419         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11420         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11421         $LCTL set_param fail_loc=0x508
11422         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11423         $LCTL set_param fail_loc=0
11424         df $DIR
11425 }
11426 run_test 224a "Don't panic on bulk IO failure"
11427
11428 test_224b() { # LU-1039, MRP-303
11429         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11430         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11431         cancel_lru_locks osc
11432         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11433         $LCTL set_param fail_loc=0x515
11434         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11435         $LCTL set_param fail_loc=0
11436         df $DIR
11437 }
11438 run_test 224b "Don't panic on bulk IO failure"
11439
11440 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11441 test_225a () {
11442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11443         if [ -z ${MDSSURVEY} ]; then
11444               skip_env "mds-survey not found" && return
11445         fi
11446
11447         [ $MDSCOUNT -ge 2 ] &&
11448                 skip "skipping now for more than one MDT" && return
11449
11450        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11451             { skip "Need MDS version at least 2.2.51"; return; }
11452
11453        local mds=$(facet_host $SINGLEMDS)
11454        local target=$(do_nodes $mds 'lctl dl' | \
11455                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11456
11457        local cmd1="file_count=1000 thrhi=4"
11458        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11459        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11460        local cmd="$cmd1 $cmd2 $cmd3"
11461
11462        rm -f ${TMP}/mds_survey*
11463        echo + $cmd
11464        eval $cmd || error "mds-survey with zero-stripe failed"
11465        cat ${TMP}/mds_survey*
11466        rm -f ${TMP}/mds_survey*
11467 }
11468 run_test 225a "Metadata survey sanity with zero-stripe"
11469
11470 test_225b () {
11471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11472
11473         if [ -z ${MDSSURVEY} ]; then
11474               skip_env "mds-survey not found" && return
11475         fi
11476         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11477             { skip "Need MDS version at least 2.2.51"; return; }
11478
11479         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11480               skip_env "Need to mount OST to test" && return
11481         fi
11482
11483         [ $MDSCOUNT -ge 2 ] &&
11484                 skip "skipping now for more than one MDT" && return
11485        local mds=$(facet_host $SINGLEMDS)
11486        local target=$(do_nodes $mds 'lctl dl' | \
11487                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11488
11489        local cmd1="file_count=1000 thrhi=4"
11490        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11491        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11492        local cmd="$cmd1 $cmd2 $cmd3"
11493
11494        rm -f ${TMP}/mds_survey*
11495        echo + $cmd
11496        eval $cmd || error "mds-survey with stripe_count failed"
11497        cat ${TMP}/mds_survey*
11498        rm -f ${TMP}/mds_survey*
11499 }
11500 run_test 225b "Metadata survey sanity with stripe_count = 1"
11501
11502 mcreate_path2fid () {
11503         local mode=$1
11504         local major=$2
11505         local minor=$3
11506         local name=$4
11507         local desc=$5
11508         local path=$DIR/$tdir/$name
11509         local fid
11510         local rc
11511         local fid_path
11512
11513         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11514                 error "cannot create $desc"
11515
11516         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11517         rc=$?
11518         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11519
11520         fid_path=$($LFS fid2path $MOUNT $fid)
11521         rc=$?
11522         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11523
11524         [ "$path" == "$fid_path" ] ||
11525                 error "fid2path returned $fid_path, expected $path"
11526
11527         echo "pass with $path and $fid"
11528 }
11529
11530 test_226a () {
11531         rm -rf $DIR/$tdir
11532         mkdir -p $DIR/$tdir
11533
11534         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11535         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11536         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11537         mcreate_path2fid 0040666 0 0 dir "directory"
11538         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11539         mcreate_path2fid 0100666 0 0 file "regular file"
11540         mcreate_path2fid 0120666 0 0 link "symbolic link"
11541         mcreate_path2fid 0140666 0 0 sock "socket"
11542 }
11543 run_test 226a "call path2fid and fid2path on files of all type"
11544
11545 test_226b () {
11546         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11547         rm -rf $DIR/$tdir
11548         local MDTIDX=1
11549
11550         mkdir -p $DIR/$tdir
11551         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11552                 error "create remote directory failed"
11553         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11554         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11555                                 "character special file (null)"
11556         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11557                                 "character special file (no device)"
11558         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11559         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11560                                 "block special file (loop)"
11561         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11562         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11563         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11564 }
11565 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11566
11567 # LU-1299 Executing or running ldd on a truncated executable does not
11568 # cause an out-of-memory condition.
11569 test_227() {
11570         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11571         dd if=`which date` of=$MOUNT/date bs=1k count=1
11572         chmod +x $MOUNT/date
11573
11574         $MOUNT/date > /dev/null
11575         ldd $MOUNT/date > /dev/null
11576         rm -f $MOUNT/date
11577 }
11578 run_test 227 "running truncated executable does not cause OOM"
11579
11580 # LU-1512 try to reuse idle OI blocks
11581 test_228a() {
11582         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11583         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11584                 skip "non-ldiskfs backend" && return
11585
11586         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11587         local myDIR=$DIR/$tdir
11588
11589         mkdir -p $myDIR
11590         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11591         $LCTL set_param fail_loc=0x80001002
11592         createmany -o $myDIR/t- 10000
11593         $LCTL set_param fail_loc=0
11594         # The guard is current the largest FID holder
11595         touch $myDIR/guard
11596         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11597                     tr -d '[')
11598         local IDX=$(($SEQ % 64))
11599
11600         do_facet $SINGLEMDS sync
11601         # Make sure journal flushed.
11602         sleep 6
11603         local blk1=$(do_facet $SINGLEMDS \
11604                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11605                      grep Blockcount | awk '{print $4}')
11606
11607         # Remove old files, some OI blocks will become idle.
11608         unlinkmany $myDIR/t- 10000
11609         # Create new files, idle OI blocks should be reused.
11610         createmany -o $myDIR/t- 2000
11611         do_facet $SINGLEMDS sync
11612         # Make sure journal flushed.
11613         sleep 6
11614         local blk2=$(do_facet $SINGLEMDS \
11615                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11616                      grep Blockcount | awk '{print $4}')
11617
11618         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11619 }
11620 run_test 228a "try to reuse idle OI blocks"
11621
11622 test_228b() {
11623         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11624         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11625                 skip "non-ldiskfs backend" && return
11626
11627         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11628         local myDIR=$DIR/$tdir
11629
11630         mkdir -p $myDIR
11631         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11632         $LCTL set_param fail_loc=0x80001002
11633         createmany -o $myDIR/t- 10000
11634         $LCTL set_param fail_loc=0
11635         # The guard is current the largest FID holder
11636         touch $myDIR/guard
11637         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11638                     tr -d '[')
11639         local IDX=$(($SEQ % 64))
11640
11641         do_facet $SINGLEMDS sync
11642         # Make sure journal flushed.
11643         sleep 6
11644         local blk1=$(do_facet $SINGLEMDS \
11645                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11646                      grep Blockcount | awk '{print $4}')
11647
11648         # Remove old files, some OI blocks will become idle.
11649         unlinkmany $myDIR/t- 10000
11650
11651         # stop the MDT
11652         stop $SINGLEMDS || error "Fail to stop MDT."
11653         # remount the MDT
11654         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11655
11656         df $MOUNT || error "Fail to df."
11657         # Create new files, idle OI blocks should be reused.
11658         createmany -o $myDIR/t- 2000
11659         do_facet $SINGLEMDS sync
11660         # Make sure journal flushed.
11661         sleep 6
11662         local blk2=$(do_facet $SINGLEMDS \
11663                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11664                      grep Blockcount | awk '{print $4}')
11665
11666         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11667 }
11668 run_test 228b "idle OI blocks can be reused after MDT restart"
11669
11670 #LU-1881
11671 test_228c() {
11672         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11673         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11674                 skip "non-ldiskfs backend" && return
11675
11676         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11677         local myDIR=$DIR/$tdir
11678
11679         mkdir -p $myDIR
11680         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11681         $LCTL set_param fail_loc=0x80001002
11682         # 20000 files can guarantee there are index nodes in the OI file
11683         createmany -o $myDIR/t- 20000
11684         $LCTL set_param fail_loc=0
11685         # The guard is current the largest FID holder
11686         touch $myDIR/guard
11687         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11688                     tr -d '[')
11689         local IDX=$(($SEQ % 64))
11690
11691         do_facet $SINGLEMDS sync
11692         # Make sure journal flushed.
11693         sleep 6
11694         local blk1=$(do_facet $SINGLEMDS \
11695                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11696                      grep Blockcount | awk '{print $4}')
11697
11698         # Remove old files, some OI blocks will become idle.
11699         unlinkmany $myDIR/t- 20000
11700         rm -f $myDIR/guard
11701         # The OI file should become empty now
11702
11703         # Create new files, idle OI blocks should be reused.
11704         createmany -o $myDIR/t- 2000
11705         do_facet $SINGLEMDS sync
11706         # Make sure journal flushed.
11707         sleep 6
11708         local blk2=$(do_facet $SINGLEMDS \
11709                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11710                      grep Blockcount | awk '{print $4}')
11711
11712         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11713 }
11714 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
11715
11716 test_229() { # LU-2482, LU-3448
11717         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
11718                 skip "No HSM support on MDS of $(get_lustre_version)," \
11719                          "need 2.4.53 at least" && return
11720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11721         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
11722
11723         rm -f $DIR/$tfile
11724
11725         # Create a file with a released layout and stripe count 2.
11726         $MULTIOP $DIR/$tfile H2c ||
11727                 error "failed to create file with released layout"
11728
11729         $GETSTRIPE -v $DIR/$tfile
11730
11731         local pattern=$($GETSTRIPE -L $DIR/$tfile)
11732         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
11733
11734         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
11735         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
11736         stat $DIR/$tfile || error "failed to stat released file"
11737
11738         chown $RUNAS_ID $DIR/$tfile ||
11739                 error "chown $RUNAS_ID $DIR/$tfile failed"
11740
11741         chgrp $RUNAS_ID $DIR/$tfile ||
11742                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
11743
11744         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
11745         rm $DIR/$tfile || error "failed to remove released file"
11746 }
11747 run_test 229 "getstripe/stat/rm/attr changes work on released files"
11748
11749 test_230a() {
11750         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11751         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11752         local MDTIDX=1
11753
11754         mkdir -p $DIR/$tdir/test_230_local
11755         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
11756         [ $mdt_idx -ne 0 ] &&
11757                 error "create local directory on wrong MDT $mdt_idx"
11758
11759         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
11760                         error "create remote directory failed"
11761         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
11762         [ $mdt_idx -ne $MDTIDX ] &&
11763                 error "create remote directory on wrong MDT $mdt_idx"
11764
11765         createmany -o $DIR/$tdir/test_230/t- 10 ||
11766                 error "create files on remote directory failed"
11767         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
11768         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
11769         rm -r $DIR/$tdir || error "unlink remote directory failed"
11770 }
11771 run_test 230a "Create remote directory and files under the remote directory"
11772
11773 test_230b() {
11774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11775         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11776         local MDTIDX=1
11777         local remote_dir=$DIR/$tdir/remote_dir
11778         local rc=0
11779
11780         mkdir -p $DIR/$tdir
11781         $LFS mkdir -i $MDTIDX $remote_dir ||
11782                 error "create remote directory failed"
11783
11784         $LFS mkdir -i 0 $remote_dir/new_dir &&
11785                 error "nested remote directory create succeed!"
11786
11787         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=1
11788         $LFS mkdir -i 0 $remote_dir/new_dir || rc=$?
11789         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=0
11790
11791         [ $rc -ne 0 ] &&
11792            error "create remote directory failed after set enable_remote_dir"
11793
11794         rm -rf $remote_dir || error "first unlink remote directory failed"
11795
11796         $RUNAS -G$RUNAS_GID $LFS mkdir -i $MDTIDX $DIR/$tfile &&
11797                                                         error "chown worked"
11798
11799         do_facet mds$MDTIDX lctl set_param \
11800                                 mdt.*.enable_remote_dir_gid=$RUNAS_GID
11801         $LFS mkdir -i $MDTIDX $remote_dir || rc=$?
11802         do_facet mds$MDTIDX lctl set_param mdt.*.enable_remote_dir_gid=0
11803
11804         [ $rc -ne 0 ] &&
11805            error "create remote dir failed after set enable_remote_dir_gid"
11806
11807         rm -r $DIR/$tdir || error "second unlink remote directory failed"
11808 }
11809 run_test 230b "nested remote directory should be failed"
11810
11811 test_231a()
11812 {
11813         # For simplicity this test assumes that max_pages_per_rpc
11814         # is the same across all OSCs
11815         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -1)
11816         local bulk_size=$((max_pages * 4096))
11817
11818         mkdir -p $DIR/$tdir
11819
11820         # clear the OSC stats
11821         $LCTL set_param osc.*.stats=0 &>/dev/null
11822
11823         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
11824         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
11825                 oflag=direct &>/dev/null || error "dd failed"
11826
11827         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
11828         if [ x$nrpcs != "x1" ]; then
11829                 error "found $nrpc ost_write RPCs, not 1 as expected"
11830         fi
11831
11832         # Drop the OSC cache, otherwise we will read from it
11833         cancel_lru_locks osc
11834
11835         # clear the OSC stats
11836         $LCTL set_param osc.*.stats=0 &>/dev/null
11837
11838         # Client reads $bulk_size.
11839         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
11840                 iflag=direct &>/dev/null || error "dd failed"
11841
11842         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
11843         if [ x$nrpcs != "x1" ]; then
11844                 error "found $nrpc ost_read RPCs, not 1 as expected"
11845         fi
11846 }
11847 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
11848
11849 test_231b() {
11850         mkdir -p $DIR/$tdir
11851         local i
11852         for i in {0..1023}; do
11853                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
11854                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
11855                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
11856         done
11857         sync
11858 }
11859 run_test 231b "must not assert on fully utilized OST request buffer"
11860
11861 test_232() {
11862         mkdir -p $DIR/$tdir
11863         #define OBD_FAIL_LDLM_OST_LVB            0x31c
11864         $LCTL set_param fail_loc=0x31c
11865
11866         # ignore dd failure
11867         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
11868
11869         $LCTL set_param fail_loc=0
11870         umount_client $MOUNT || error "umount failed"
11871         mount_client $MOUNT || error "mount failed"
11872 }
11873 run_test 232 "failed lock should not block umount"
11874
11875 test_233a() {
11876         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
11877         { skip "Need MDS version at least 2.3.64"; return; }
11878
11879         local fid=$($LFS path2fid $MOUNT)
11880         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
11881                 error "cannot access $MOUNT using its FID '$fid'"
11882 }
11883 run_test 233a "checking that OBF of the FS root succeeds"
11884
11885 test_233b() {
11886         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
11887         { skip "Need MDS version at least 2.5.90"; return; }
11888
11889         local fid=$($LFS path2fid $MOUNT/.lustre)
11890         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
11891                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
11892
11893         fid=$($LFS path2fid $MOUNT/.lustre/fid)
11894         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
11895                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
11896 }
11897 run_test 233b "checking that OBF of the FS .lustre succeeds"
11898
11899 test_234() {
11900         local p="$TMP/sanityN-$TESTNAME.parameters"
11901         save_lustre_params client "llite.*.xattr_cache" > $p
11902         lctl set_param llite.*.xattr_cache 1 ||
11903                 { skip "xattr cache is not supported"; return 0; }
11904
11905         mkdir -p $DIR/$tdir || error "mkdir failed"
11906         touch $DIR/$tdir/$tfile || error "touch failed"
11907         # OBD_FAIL_LLITE_XATTR_ENOMEM
11908         $LCTL set_param fail_loc=0x1405
11909         if [ ! -f /etc/SuSE-release ]; then
11910                 # attr pre-2.4.44-7 had a bug with rc
11911                 # LU-3703 - SLES clients have older attr
11912                 getfattr -n user.attr $DIR/$tdir/$tfile &&
11913                         error "getfattr should have failed with ENOMEM"
11914         fi
11915         $LCTL set_param fail_loc=0x0
11916         rm -rf $DIR/$tdir
11917
11918         restore_lustre_params < $p
11919         rm -f $p
11920 }
11921 run_test 234 "xattr cache should not crash on ENOMEM"
11922
11923 test_235() {
11924          [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
11925                 skip "Need MDS version at least 2.4.52" && return
11926         flock_deadlock $DIR/$tfile
11927         local RC=$?
11928         case $RC in
11929                 0)
11930                 ;;
11931                 124) error "process hangs on a deadlock"
11932                 ;;
11933                 *) error "error executing flock_deadlock $DIR/$tfile"
11934                 ;;
11935         esac
11936 }
11937 run_test 235 "LU-1715: flock deadlock detection does not work properly"
11938
11939 #LU-2935
11940 test_236() {
11941         check_swap_layouts_support && return 0
11942         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
11943
11944         local ref1=/etc/passwd
11945         local ref2=/etc/group
11946         local file1=$DIR/$tdir/f1
11947         local file2=$DIR/$tdir/f2
11948
11949         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
11950         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
11951         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
11952         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
11953         local fd=$(free_fd)
11954         local cmd="exec $fd<>$file2"
11955         eval $cmd
11956         rm $file2
11957         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
11958                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
11959         cmd="exec $fd>&-"
11960         eval $cmd
11961         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11962
11963         #cleanup
11964         rm -rf $DIR/$tdir
11965 }
11966 run_test 236 "Layout swap on open unlinked file"
11967
11968 # test to verify file handle related system calls
11969 # (name_to_handle_at/open_by_handle_at)
11970 # The new system calls are supported in glibc >= 2.14.
11971
11972 test_237() {
11973         echo "Test file_handle syscalls" > $DIR/$tfile
11974         check_fhandle_syscalls $DIR/$tfile ||
11975                 error "check_fhandle_syscalls failed"
11976 }
11977 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
11978
11979 #
11980 # tests that do cleanup/setup should be run at the end
11981 #
11982
11983 test_900() {
11984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11985         local ls
11986         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
11987         $LCTL set_param fail_loc=0x903
11988         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
11989         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
11990                 echo "clear" > $ls
11991         done
11992         FAIL_ON_ERROR=true cleanup
11993         FAIL_ON_ERROR=true setup
11994 }
11995 run_test 900 "umount should not race with any mgc requeue thread"
11996
11997 complete $SECONDS
11998 check_and_cleanup_lustre
11999 if [ "$I_MOUNTED" != "yes" ]; then
12000         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
12001 fi
12002 exit_status